From d3a23f42c3a985fa9527348a88a0616c2c996c8b Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Wed, 23 Oct 2024 02:15:00 +1100 Subject: [PATCH] Update to Minecraft 1.21.2 By: md_5 --- .../commands/CommandDispatcher.patch | 24 +- .../commands/CommandListenerWrapper.patch | 14 +- .../core/cauldron/CauldronInteraction.patch | 218 ++-- .../core/dispenser/DispenseBehaviorBoat.patch | 31 +- .../DispenseBehaviorProjectile.patch | 13 +- .../dispenser/DispenseBehaviorShears.patch | 10 +- .../EquipmentDispenseItemBehavior.patch} | 25 +- .../core/dispenser/IDispenseBehavior.patch | 77 +- .../MinecartDispenseItemBehavior.patch | 59 ++ .../network/PacketDataSerializer.patch | 4 +- .../network/chat/IChatBaseComponent.patch | 2 +- .../server/AdvancementDataPlayer.patch | 2 +- .../server/AdvancementDataWorld.patch | 11 +- .../minecraft/server/CustomFunctionData.patch | 2 +- .../minecraft/server/DispenserRegistry.patch | 8 +- .../net/minecraft/server/Main.patch | 6 +- .../minecraft/server/MinecraftServer.patch | 157 +-- .../server/commands/CommandGamerule.patch | 4 +- .../server/commands/CommandLoot.patch | 4 +- .../server/commands/CommandSchedule.patch | 6 +- .../commands/CommandSpreadPlayers.patch | 4 +- .../server/commands/CommandSummon.patch | 2 +- .../server/commands/CommandTeleport.patch | 31 +- .../server/dedicated/DedicatedServer.patch | 28 +- .../dedicated/DedicatedServerProperties.patch | 10 +- .../server/level/ChunkMapDistance.patch | 30 +- .../server/level/ChunkProviderServer.patch | 69 +- .../minecraft/server/level/EntityPlayer.patch | 468 +++++---- .../server/level/EntityTrackerEntry.patch | 18 +- .../minecraft/server/level/PlayerChunk.patch | 16 +- .../server/level/PlayerChunkMap.patch | 22 +- .../server/level/PlayerInteractManager.patch | 28 +- .../minecraft/server/level/TicketType.patch | 4 +- .../minecraft/server/level/WorldServer.patch | 163 +-- .../server/network/PlayerConnection.patch | 323 +++--- .../ServerCommonPacketListenerImpl.patch | 18 +- .../minecraft/server/players/PlayerList.patch | 135 ++- .../minecraft/stats/RecipeBookServer.patch | 40 +- .../net/minecraft/util/SpawnUtil.patch | 16 +- .../net/minecraft/util/TickThrottler.patch | 53 + .../util/datafix/DataConverterRegistry.patch | 12 +- .../util/worldupdate/WorldUpgrader.patch | 10 +- .../net/minecraft/world/ChestLock.patch | 35 - .../world/damagesource/DamageSources.patch | 16 +- .../world/effect/HealOrHarmMobEffect.patch | 8 +- .../world/effect/HungerMobEffect.patch | 4 +- .../world/effect/InfestedMobEffect.patch | 8 +- .../world/effect/OozingMobEffect.patch | 2 +- .../world/effect/PoisonMobEffect.patch | 8 +- .../world/effect/RegenerationMobEffect.patch | 4 +- .../world/effect/SaturationMobEffect.patch | 8 +- .../world/entity/ConversionType.patch | 41 + .../net/minecraft/world/entity/Entity.patch | 249 +++-- .../world/entity/EntityAgeable.patch | 8 +- .../world/entity/EntityAreaEffectCloud.patch | 132 +-- .../world/entity/EntityExperienceOrb.patch | 12 +- .../world/entity/EntityInsentient.patch | 114 ++- .../world/entity/EntityLightning.patch | 60 +- .../minecraft/world/entity/EntityLiving.patch | 339 +++---- .../world/entity/EntityTameableAnimal.patch | 4 +- .../minecraft/world/entity/EntityTypes.patch | 78 +- .../world/entity/IEntitySelector.patch | 2 +- .../minecraft/world/entity/Interaction.patch | 6 +- .../minecraft/world/entity/Leashable.patch | 46 +- .../behavior/BehaviorAttackTargetForget.patch | 8 +- .../ai/behavior/BehaviorAttackTargetSet.patch | 4 +- .../behavior/BehaviorFindAdmirableItem.patch | 2 +- .../ai/behavior/PrepareRamNearestTarget.patch | 2 +- .../ai/goal/PathfinderGoalBreakDoor.patch | 2 +- .../ai/goal/PathfinderGoalEatTile.patch | 8 +- .../ai/goal/PathfinderGoalRemoveBlock.patch | 4 +- .../entity/ai/goal/PathfinderGoalTempt.patch | 10 +- .../target/PathfinderGoalDefendVillage.patch | 2 +- ...athfinderGoalNearestAttackableTarget.patch | 2 +- .../entity/ai/sensing/TemptingSensor.patch | 16 +- .../world/entity/ambient/EntityBat.patch | 28 +- .../world/entity/animal/Bucketable.patch | 2 +- .../world/entity/animal/EntityAnimal.patch | 18 +- .../world/entity/animal/EntityBee.patch | 56 +- .../world/entity/animal/EntityCat.patch | 30 +- .../world/entity/animal/EntityChicken.patch | 23 +- .../world/entity/animal/EntityCow.patch | 2 +- .../world/entity/animal/EntityDolphin.patch | 12 +- .../world/entity/animal/EntityFox.patch | 30 +- .../entity/animal/EntityMushroomCow.patch | 71 +- .../world/entity/animal/EntityOcelot.patch | 4 +- .../world/entity/animal/EntityPanda.patch | 25 +- .../world/entity/animal/EntityParrot.patch | 27 +- .../world/entity/animal/EntityPig.patch | 29 +- .../entity/animal/EntityPufferFish.patch | 16 +- .../world/entity/animal/EntityRabbit.patch | 6 +- .../world/entity/animal/EntitySheep.patch | 58 +- .../world/entity/animal/EntitySnowman.patch | 54 +- .../world/entity/animal/EntityTurtle.patch | 26 +- .../world/entity/animal/EntityWolf.patch | 63 +- .../world/entity/animal/allay/Allay.patch | 24 +- .../entity/animal/armadillo/Armadillo.patch | 71 +- .../world/entity/animal/axolotl/Axolotl.patch | 11 +- .../world/entity/animal/camel/Camel.patch | 24 +- .../entity/animal/frog/ShootTongue.patch | 2 +- .../world/entity/animal/frog/Tadpole.patch | 40 +- .../world/entity/animal/goat/Goat.patch | 8 +- .../animal/horse/EntityHorseAbstract.patch | 32 +- .../entity/animal/horse/EntityLlama.patch | 2 +- .../animal/horse/EntityLlamaTrader.patch | 6 +- .../world/entity/animal/sniffer/Sniffer.patch | 30 +- .../boss/enderdragon/EntityEnderCrystal.patch | 10 +- .../boss/enderdragon/EntityEnderDragon.patch | 88 +- .../phases/DragonControllerLandedFlame.patch | 4 +- .../entity/boss/wither/EntityWither.patch | 32 +- .../decoration/BlockAttachedEntity.patch | 67 +- .../entity/decoration/EntityArmorStand.patch | 118 +-- .../entity/decoration/EntityItemFrame.patch | 14 +- .../world/entity/decoration/EntityLeash.patch | 6 +- .../entity/decoration/EntityPainting.patch | 8 +- .../entity/item/EntityFallingBlock.patch | 78 +- .../world/entity/item/EntityItem.patch | 18 +- .../world/entity/item/EntityTNTPrimed.patch | 25 +- .../world/entity/monster/Bogged.patch | 22 +- .../entity/monster/EntityCaveSpider.patch | 2 +- .../world/entity/monster/EntityCreeper.patch | 18 +- .../world/entity/monster/EntityDrowned.patch | 11 - .../world/entity/monster/EntityEnderman.patch | 4 +- .../world/entity/monster/EntityEvoker.patch | 2 +- .../world/entity/monster/EntityGhast.patch | 2 +- .../world/entity/monster/EntityGuardian.patch | 4 +- .../entity/monster/EntityGuardianElder.patch | 6 +- .../monster/EntityIllagerIllusioner.patch | 4 +- .../entity/monster/EntityIllagerWizard.patch | 4 +- .../world/entity/monster/EntityPhantom.patch | 6 +- .../entity/monster/EntityPigZombie.patch | 2 +- .../world/entity/monster/EntityPillager.patch | 4 +- .../world/entity/monster/EntityRavager.patch | 24 +- .../world/entity/monster/EntityShulker.patch | 6 +- .../entity/monster/EntitySilverfish.patch | 8 +- .../world/entity/monster/EntitySkeleton.patch | 14 +- .../monster/EntitySkeletonAbstract.patch | 34 +- .../world/entity/monster/EntitySlime.patch | 29 +- .../world/entity/monster/EntityStrider.patch | 2 +- .../world/entity/monster/EntityVex.patch | 2 +- .../world/entity/monster/EntityWitch.patch | 2 +- .../world/entity/monster/EntityZombie.patch | 124 ++- .../entity/monster/EntityZombieHusk.patch | 2 +- .../entity/monster/EntityZombieVillager.patch | 45 +- .../monster/creaking/CreakingTransient.patch | 20 + .../entity/monster/piglin/EntityPiglin.patch | 22 +- .../monster/piglin/EntityPiglinAbstract.patch | 14 +- .../entity/monster/piglin/PiglinAI.patch | 36 +- .../world/entity/monster/warden/Warden.patch | 8 +- .../world/entity/npc/EntityVillager.patch | 46 +- .../entity/npc/EntityVillagerTrader.patch | 10 +- .../world/entity/npc/InventoryCarrier.patch | 4 +- .../world/entity/npc/MobSpawnerTrader.patch | 8 +- .../world/entity/player/EntityHuman.patch | 188 +--- .../world/entity/player/PlayerInventory.patch | 6 +- .../world/entity/projectile/EntityArrow.patch | 50 +- .../projectile/EntityDragonFireball.patch | 4 +- .../world/entity/projectile/EntityEgg.patch | 6 +- .../entity/projectile/EntityEnderPearl.patch | 66 +- .../entity/projectile/EntityEnderSignal.patch | 8 +- .../entity/projectile/EntityFireball.patch | 16 +- .../projectile/EntityFireballFireball.patch | 2 +- .../entity/projectile/EntityFireworks.patch | 69 +- .../entity/projectile/EntityFishingHook.patch | 33 +- .../projectile/EntityLargeFireball.patch | 12 +- .../entity/projectile/EntityLlamaSpit.patch | 2 +- .../entity/projectile/EntityPotion.patch | 34 +- .../entity/projectile/EntityProjectile.patch | 10 +- .../EntityProjectileThrowable.patch | 2 +- .../projectile/EntityShulkerBullet.patch | 35 +- .../projectile/EntitySmallFireball.patch | 12 +- .../projectile/EntityThrownExpBottle.patch | 4 +- .../projectile/EntityThrownTrident.patch | 20 +- .../world/entity/projectile/IProjectile.patch | 21 +- .../windcharge/AbstractWindCharge.patch | 10 +- .../world/entity/raid/EntityRaider.patch | 24 +- .../minecraft/world/entity/raid/Raid.patch | 24 +- .../{EntityBoat.patch => AbstractBoat.patch} | 54 +- ...hestBoat.patch => AbstractChestBoat.patch} | 12 +- .../vehicle/EntityMinecartAbstract.patch | 142 +-- .../vehicle/EntityMinecartCommandBlock.patch | 2 +- .../vehicle/EntityMinecartContainer.patch | 14 +- .../entity/vehicle/EntityMinecartTNT.patch | 24 +- .../entity/vehicle/NewMinecartBehavior.patch | 70 ++ .../entity/vehicle/OldMinecartBehavior.patch | 70 ++ .../world/entity/vehicle/VehicleEntity.patch | 68 +- .../net/minecraft/world/food/FoodInfo.patch | 22 + .../minecraft/world/food/FoodMetaData.patch | 63 +- .../inventory/AbstractCraftingMenu.patch | 41 + .../minecraft/world/inventory/Container.patch | 29 +- .../world/inventory/ContainerAnvil.patch | 33 +- .../inventory/ContainerAnvilAbstract.patch | 4 +- .../world/inventory/ContainerBeacon.patch | 6 +- .../inventory/ContainerBrewingStand.patch | 10 +- .../inventory/ContainerCartography.patch | 10 +- .../world/inventory/ContainerChest.patch | 16 +- .../world/inventory/ContainerDispenser.patch | 4 +- .../inventory/ContainerEnchantTable.patch | 16 +- .../world/inventory/ContainerFurnace.patch | 33 +- .../world/inventory/ContainerGrindstone.patch | 12 +- .../world/inventory/ContainerHopper.patch | 4 +- .../world/inventory/ContainerHorse.patch | 9 +- .../world/inventory/ContainerLoom.patch | 6 +- .../world/inventory/ContainerMerchant.patch | 6 +- .../world/inventory/ContainerPlayer.patch | 42 +- .../world/inventory/ContainerShulkerBox.patch | 2 +- .../world/inventory/ContainerSmithing.patch | 50 +- .../inventory/ContainerStonecutter.patch | 17 +- .../world/inventory/ContainerWorkbench.patch | 59 +- .../world/inventory/CrafterMenu.patch | 4 +- .../TransientCraftingContainer.patch | 2 +- .../net/minecraft/world/item/ItemBlock.patch | 10 +- .../net/minecraft/world/item/ItemBoat.patch | 49 +- .../net/minecraft/world/item/ItemBucket.patch | 4 +- .../world/item/ItemChorusFruit.patch | 20 - .../net/minecraft/world/item/ItemEgg.patch | 16 +- .../minecraft/world/item/ItemEnderEye.patch | 24 +- .../minecraft/world/item/ItemEnderPearl.patch | 24 +- .../minecraft/world/item/ItemFishingRod.patch | 12 +- .../minecraft/world/item/ItemHanging.patch | 13 +- .../net/minecraft/world/item/ItemLeash.patch | 15 +- .../minecraft/world/item/ItemMilkBucket.patch | 11 - .../minecraft/world/item/ItemMinecart.patch | 78 +- .../minecraft/world/item/ItemMonsterEgg.patch | 2 +- .../net/minecraft/world/item/ItemPotion.patch | 11 - .../world/item/ItemProjectileWeapon.patch | 15 +- .../net/minecraft/world/item/ItemSign.patch | 4 +- .../minecraft/world/item/ItemSnowball.patch | 20 +- .../net/minecraft/world/item/ItemStack.patch | 268 ++--- .../world/item/ItemSuspiciousStew.patch | 18 - .../minecraft/world/item/ItemTrident.patch | 79 +- .../world/item/alchemy/PotionContents.patch | 20 + .../world/item/component/Consumable.patch | 51 + .../item/component/ConsumableListener.patch | 9 + .../item/component/DeathProtection.patch | 22 + .../component/SuspiciousStewEffects.patch | 27 + .../ApplyStatusEffectsConsumeEffect.patch | 31 + .../ClearAllStatusEffectsConsumeEffect.patch | 25 + .../item/consume_effects/ConsumeEffect.patch | 30 + .../RemoveStatusEffectsConsumeEffect.patch | 30 + .../TeleportRandomlyConsumeEffect.patch | 20 + .../world/item/crafting/CraftingManager.patch | 127 +-- .../world/item/crafting/FurnaceRecipe.patch | 16 +- .../world/item/crafting/IRecipe.patch | 6 +- .../world/item/crafting/IRecipeComplex.patch | 42 +- .../world/item/crafting/RecipeBlasting.patch | 16 +- .../world/item/crafting/RecipeCampfire.patch | 16 +- .../world/item/crafting/RecipeHolder.patch | 10 +- .../world/item/crafting/RecipeItemStack.patch | 68 +- .../world/item/crafting/RecipeMap.patch | 56 + .../world/item/crafting/RecipeSmoking.patch | 16 +- .../item/crafting/RecipeStonecutting.patch | 18 +- .../world/item/crafting/ShapedRecipes.patch | 10 +- .../item/crafting/ShapelessRecipes.patch | 10 +- .../crafting/SmithingTransformRecipe.patch | 12 +- .../item/crafting/SmithingTrimRecipe.patch | 10 +- .../world/item/crafting/TransmuteRecipe.patch | 31 + .../effects/SummonEntityEffect.patch | 4 +- .../net/minecraft/world/level/Explosion.patch | 198 ---- .../net/minecraft/world/level/GameRules.patch | 79 +- .../world/level/GeneratorAccess.patch | 4 +- .../minecraft/world/level/IBlockAccess.patch | 8 +- .../world/level/MobSpawnerAbstract.patch | 2 +- .../world/level/ServerExplosion.patch | 193 ++++ .../world/level/SpawnerCreature.patch | 43 +- .../net/minecraft/world/level/World.patch | 32 +- .../level/block/AbstractCandleBlock.patch | 2 +- .../world/level/block/BigDripleafBlock.patch | 14 +- .../minecraft/world/level/block/Block.patch | 32 +- .../world/level/block/BlockBamboo.patch | 6 +- .../level/block/BlockBambooSapling.patch | 2 +- .../world/level/block/BlockBed.patch | 10 +- .../world/level/block/BlockBeehive.patch | 16 +- .../world/level/block/BlockBell.patch | 2 +- .../level/block/BlockButtonAbstract.patch | 8 +- .../world/level/block/BlockCactus.patch | 6 +- .../world/level/block/BlockCake.patch | 2 +- .../world/level/block/BlockCampfire.patch | 22 +- .../world/level/block/BlockChest.patch | 8 +- .../world/level/block/BlockChorusFlower.patch | 26 +- .../world/level/block/BlockCommand.patch | 32 +- .../world/level/block/BlockComposter.patch | 18 +- .../level/block/BlockConcretePowder.patch | 22 +- .../world/level/block/BlockCoral.patch | 2 +- .../world/level/block/BlockCoralFan.patch | 2 +- .../world/level/block/BlockCoralFanWall.patch | 2 +- .../world/level/block/BlockCoralPlant.patch | 2 +- .../world/level/block/BlockCrops.patch | 12 +- .../level/block/BlockDiodeAbstract.patch | 4 +- .../world/level/block/BlockDispenser.patch | 10 +- .../world/level/block/BlockDoor.patch | 6 +- .../world/level/block/BlockEndGateway.patch | 10 +- .../world/level/block/BlockEnderPortal.patch | 28 +- .../world/level/block/BlockFenceGate.patch | 4 +- .../world/level/block/BlockFire.patch | 14 +- .../world/level/block/BlockFireAbstract.patch | 18 +- .../world/level/block/BlockFluids.patch | 4 +- .../world/level/block/BlockIce.patch | 2 +- .../world/level/block/BlockLeaves.patch | 4 +- .../world/level/block/BlockLectern.patch | 2 +- .../world/level/block/BlockLever.patch | 10 +- .../world/level/block/BlockMagma.patch | 2 +- .../level/block/BlockMinecartDetector.patch | 6 +- .../world/level/block/BlockMonsterEggs.patch | 4 +- .../world/level/block/BlockNote.patch | 4 +- .../world/level/block/BlockObserver.patch | 8 +- .../world/level/block/BlockPlant.patch | 24 +- .../world/level/block/BlockPortal.patch | 40 +- .../world/level/block/BlockPoweredRail.patch | 2 +- .../level/block/BlockPumpkinCarved.patch | 6 +- .../level/block/BlockRedstoneComparator.patch | 6 +- .../world/level/block/BlockRedstoneLamp.patch | 8 +- .../world/level/block/BlockRedstoneOre.patch | 2 +- .../level/block/BlockRedstoneTorch.patch | 6 +- .../world/level/block/BlockRedstoneWire.patch | 29 - .../level/block/BlockRespawnAnchor.patch | 8 +- .../world/level/block/BlockSign.patch | 10 +- .../world/level/block/BlockSoil.patch | 38 +- .../world/level/block/BlockSponge.patch | 10 +- .../level/block/BlockSweetBerryBush.patch | 20 +- .../world/level/block/BlockTNT.patch | 18 +- .../world/level/block/BlockTallPlant.patch | 2 +- .../world/level/block/BlockTrapdoor.patch | 4 +- .../world/level/block/BlockTripwire.patch | 4 +- .../world/level/block/BlockTripwireHook.patch | 4 +- .../world/level/block/BlockTurtleEgg.patch | 20 +- .../world/level/block/BlockVine.patch | 2 +- .../world/level/block/BlockWaterLily.patch | 2 +- .../world/level/block/BlockWitherRose.patch | 10 +- .../world/level/block/BlockWitherSkull.patch | 10 +- .../level/block/CeilingHangingSignBlock.patch | 2 +- .../world/level/block/CrafterBlock.patch | 8 +- .../world/level/block/DecoratedPotBlock.patch | 22 +- .../level/block/LayeredCauldronBlock.patch | 43 +- .../world/level/block/LightningRodBlock.patch | 6 +- .../level/block/PointedDripstoneBlock.patch | 32 +- .../world/level/block/PowderSnowBlock.patch | 10 +- .../world/level/block/SculkSensorBlock.patch | 10 +- .../level/block/SculkShriekerBlock.patch | 4 +- .../world/level/block/SculkSpreader.patch | 10 +- .../world/level/block/SculkVeinBlock.patch | 4 +- .../level/block/WallHangingSignBlock.patch | 2 +- .../block/entity/BrushableBlockEntity.patch | 20 +- .../world/level/block/entity/TileEntity.patch | 6 +- .../level/block/entity/TileEntityBeacon.patch | 4 +- .../block/entity/TileEntityBeehive.patch | 38 +- .../block/entity/TileEntityBrewingStand.patch | 14 +- .../block/entity/TileEntityCampfire.patch | 32 +- .../block/entity/TileEntityConduit.patch | 21 +- .../block/entity/TileEntityContainer.patch | 2 +- .../block/entity/TileEntityFurnace.patch | 93 +- .../block/entity/TileEntityJukeBox.patch | 8 +- .../block/entity/TileEntityLectern.patch | 58 +- .../level/block/entity/TileEntitySign.patch | 53 +- .../trialspawner/TrialSpawnerData.patch | 6 +- .../block/entity/vault/VaultBlockEntity.patch | 10 +- .../block/grower/WorldGenTreeProvider.patch | 14 +- .../level/block/piston/BlockPiston.patch | 6 +- .../world/level/block/state/BlockBase.patch | 15 +- .../world/level/border/WorldBorder.patch | 2 +- .../minecraft/world/level/chunk/Chunk.patch | 32 +- .../world/level/chunk/ChunkSection.patch | 16 +- .../world/level/chunk/IChunkAccess.patch | 18 +- .../level/chunk/status/ChunkStatusTasks.patch | 14 +- .../chunk/storage/ChunkRegionLoader.patch | 111 -- .../chunk/storage/SerializableChunkData.patch | 146 +++ .../dimension/end/EnderDragonBattle.patch | 10 +- .../level/levelgen/MobSpawnerPatrol.patch | 2 +- .../level/levelgen/MobSpawnerPhantom.patch | 2 +- .../structure/PersistentStructureLegacy.patch | 2 +- .../levelgen/structure/StructurePiece.patch | 4 +- .../levelgen/structure/StructureStart.patch | 2 +- .../structure/structures/EndCityPieces.patch | 2 +- .../structures/MineshaftPieces.patch | 10 +- .../structures/OceanRuinPieces.patch | 2 +- .../structure/structures/SwampHutPiece.patch | 4 +- .../templatesystem/DefinedStructure.patch | 26 +- .../templatesystem/DefinedStructureInfo.patch | 2 +- .../level/material/FluidTypeFlowing.patch | 72 +- .../world/level/material/FluidTypeLava.patch | 22 +- .../world/level/portal/BlockPortalShape.patch | 143 ++- .../level/portal/DimensionTransition.patch | 47 - .../level/portal/PortalTravelAgent.patch | 4 +- .../level/portal/TeleportTransition.patch | 60 ++ .../DefaultRedstoneWireEvaluator.patch | 32 + .../ExperimentalRedstoneWireEvaluator.patch | 32 + .../level/redstone/NeighborUpdater.patch | 12 +- .../world/level/saveddata/maps/WorldMap.patch | 34 +- .../world/level/storage/Convertable.patch | 8 +- .../world/level/storage/WorldDataServer.patch | 2 +- .../level/storage/loot/LootDataType.patch | 10 +- .../world/level/storage/loot/LootTable.patch | 4 +- .../LootItemConditionSurvivesExplosion.patch | 2 +- paper-server/pom.xml | 107 +- .../org/bukkit/craftbukkit/CraftChunk.java | 28 +- .../craftbukkit/CraftChunkSnapshot.java | 7 +- .../bukkit/craftbukkit/CraftLootTable.java | 28 +- .../org/bukkit/craftbukkit/CraftParticle.java | 15 +- .../craftbukkit/CraftRegionAccessor.java | 10 +- .../org/bukkit/craftbukkit/CraftRegistry.java | 42 +- .../org/bukkit/craftbukkit/CraftServer.java | 103 +- .../org/bukkit/craftbukkit/CraftWorld.java | 54 +- .../java/org/bukkit/craftbukkit/Main.java | 4 +- .../bukkit/craftbukkit/block/CraftBeacon.java | 31 +- .../bukkit/craftbukkit/block/CraftBlock.java | 2 +- .../craftbukkit/block/CraftBlockStates.java | 6 + .../craftbukkit/block/CraftContainer.java | 31 +- .../craftbukkit/block/CraftCreakingHeart.java | 27 + .../craftbukkit/block/CraftFurnace.java | 7 +- .../craftbukkit/block/CraftTrialSpawner.java | 5 +- .../block/data/CraftBlockData.java | 8 +- .../block/data/type/CraftCreakingHeart.java | 19 + .../block/data/type/CraftHangingMoss.java | 19 + .../block/data/type/CraftMossyCarpet.java | 32 + .../block/impl/CraftCreakingHeart.java | 48 + .../impl/CraftEquipableCarvedPumpkin.java | 34 - .../block/impl/CraftHangingMoss.java | 29 + .../block/impl/CraftMossyCarpet.java | 42 + .../command/VanillaCommandWrapper.java | 6 +- .../entity/CraftAbstractArrow.java | 7 +- .../entity/CraftAreaEffectCloud.java | 8 +- .../craftbukkit/entity/CraftArmorStand.java | 10 +- .../bukkit/craftbukkit/entity/CraftArrow.java | 8 +- .../bukkit/craftbukkit/entity/CraftBoat.java | 136 ++- .../craftbukkit/entity/CraftChestBoat.java | 18 +- .../craftbukkit/entity/CraftCreaking.java | 21 + .../entity/CraftCreakingTransient.java | 21 + .../craftbukkit/entity/CraftDolphin.java | 2 +- .../craftbukkit/entity/CraftEntity.java | 11 +- .../entity/CraftEntitySnapshot.java | 5 +- .../craftbukkit/entity/CraftEntityType.java | 14 + .../craftbukkit/entity/CraftEntityTypes.java | 109 +- .../craftbukkit/entity/CraftHumanEntity.java | 46 +- .../craftbukkit/entity/CraftLivingEntity.java | 52 +- .../craftbukkit/entity/CraftMinecartTNT.java | 20 + .../bukkit/craftbukkit/entity/CraftMob.java | 5 +- .../craftbukkit/entity/CraftPlayer.java | 19 +- .../craftbukkit/entity/CraftSalmon.java | 13 + .../bukkit/craftbukkit/entity/CraftSquid.java | 2 +- .../craftbukkit/entity/CraftTNTPrimed.java | 4 +- .../craftbukkit/entity/CraftVillager.java | 3 +- .../bukkit/craftbukkit/entity/CraftWolf.java | 2 +- .../entity/boat/CraftAcaciaBoat.java | 13 + .../entity/boat/CraftAcaciaChestBoat.java | 13 + .../entity/boat/CraftBambooChestRaft.java | 13 + .../entity/boat/CraftBambooRaft.java | 13 + .../entity/boat/CraftBirchBoat.java | 13 + .../entity/boat/CraftBirchChestBoat.java | 13 + .../entity/boat/CraftCherryBoat.java | 13 + .../entity/boat/CraftCherryChestBoat.java | 13 + .../entity/boat/CraftDarkOakBoat.java | 13 + .../entity/boat/CraftDarkOakChestBoat.java | 13 + .../entity/boat/CraftJungleBoat.java | 13 + .../entity/boat/CraftJungleChestBoat.java | 13 + .../entity/boat/CraftMangroveBoat.java | 13 + .../entity/boat/CraftMangroveChestBoat.java | 13 + .../craftbukkit/entity/boat/CraftOakBoat.java | 13 + .../entity/boat/CraftOakChestBoat.java | 13 + .../entity/boat/CraftPaleOakBoat.java | 13 + .../entity/boat/CraftPaleOakChestBoat.java | 13 + .../entity/boat/CraftSpruceBoat.java | 13 + .../entity/boat/CraftSpruceChestBoat.java | 13 + .../craftbukkit/event/CraftEventFactory.java | 14 +- .../generator/CraftLimitedRegion.java | 3 +- .../generator/CustomChunkGenerator.java | 5 +- .../inventory/CraftBlastingRecipe.java | 3 +- .../inventory/CraftCampfireRecipe.java | 3 +- .../inventory/CraftComplexRecipe.java | 3 +- .../inventory/CraftFurnaceRecipe.java | 3 +- .../inventory/CraftItemFactory.java | 7 +- .../craftbukkit/inventory/CraftItemMetas.java | 6 +- .../craftbukkit/inventory/CraftItemStack.java | 15 + .../craftbukkit/inventory/CraftItemType.java | 11 +- .../craftbukkit/inventory/CraftMetaArmor.java | 6 +- .../craftbukkit/inventory/CraftMetaItem.java | 362 ++++++- .../inventory/CraftMetaKnowledgeBook.java | 10 +- .../inventory/CraftMetaOminousBottle.java | 7 +- .../inventory/CraftMetaPotion.java | 42 +- .../craftbukkit/inventory/CraftRecipe.java | 51 +- .../inventory/CraftShapedRecipe.java | 3 +- .../inventory/CraftShapelessRecipe.java | 7 +- .../CraftSmithingTransformRecipe.java | 3 +- .../inventory/CraftSmithingTrimRecipe.java | 3 +- .../inventory/CraftSmokingRecipe.java | 3 +- .../inventory/CraftStonecuttingRecipe.java | 3 +- .../inventory/CraftTransmuteRecipe.java | 40 + .../craftbukkit/inventory/RecipeIterator.java | 2 +- .../components/CraftEquippableComponent.java | 239 +++++ .../components/CraftFoodComponent.java | 167 +-- .../inventory/components/CraftHolderUtil.java | 56 + .../components/CraftToolComponent.java | 36 +- .../components/CraftUseCooldownComponent.java | 99 ++ .../inventory/trim/CraftTrimMaterial.java | 20 +- .../inventory/trim/CraftTrimPattern.java | 20 +- .../inventory/view/CraftEnchantmentView.java | 4 +- .../inventory/view/CraftStonecutterView.java | 7 +- .../craftbukkit/legacy/CraftLegacy.java | 4 +- .../craftbukkit/legacy/FieldRename.java | 2 + .../CraftBlockProjectileSource.java | 9 +- .../craftbukkit/scheduler/CraftScheduler.java | 4 +- .../craftbukkit/structure/CraftPalette.java | 4 +- .../craftbukkit/structure/CraftStructure.java | 3 +- .../craftbukkit/tag/CraftDamageTag.java | 26 + .../org/bukkit/craftbukkit/tag/CraftTag.java | 2 +- .../bukkit/craftbukkit/util/ApiVersion.java | 2 +- .../util/BlockStateListPopulator.java | 4 +- .../craftbukkit/util/CraftMagicNumbers.java | 8 +- .../util/DelegatedGeneratorAccess.java | 957 +++++++++--------- .../src/test/java/org/bukkit/ArtTest.java | 2 +- .../test/java/org/bukkit/EnchantmentTest.java | 2 +- .../test/java/org/bukkit/GameRuleTest.java | 3 +- .../test/java/org/bukkit/ParticleTest.java | 28 + .../test/java/org/bukkit/PerMaterialTest.java | 21 +- .../bukkit/block/banner/PatternTypeTest.java | 4 +- .../craftbukkit/entity/EntityTypesTest.java | 6 +- .../bukkit/craftbukkit/legacy/LegacyTest.java | 6 + .../test/java/org/bukkit/entity/BoatTest.java | 28 - .../bukkit/registry/RegistryClassTest.java | 10 +- .../registry/RegistryConstantsTest.java | 2 +- .../org/bukkit/support/DummyServerHelper.java | 8 +- .../org/bukkit/support/RegistryHelper.java | 40 +- .../provider/RegistriesArgumentProvider.java | 4 +- 522 files changed, 8501 insertions(+), 6477 deletions(-) rename paper-server/nms-patches/net/minecraft/{world/item/ItemArmor.patch => core/dispenser/EquipmentDispenseItemBehavior.patch} (77%) create mode 100644 paper-server/nms-patches/net/minecraft/core/dispenser/MinecartDispenseItemBehavior.patch create mode 100644 paper-server/nms-patches/net/minecraft/util/TickThrottler.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/ChestLock.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/entity/ConversionType.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/entity/monster/EntityDrowned.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/entity/monster/creaking/CreakingTransient.patch rename paper-server/nms-patches/net/minecraft/world/entity/vehicle/{EntityBoat.patch => AbstractBoat.patch} (68%) rename paper-server/nms-patches/net/minecraft/world/entity/vehicle/{ChestBoat.patch => AbstractChestBoat.patch} (88%) create mode 100644 paper-server/nms-patches/net/minecraft/world/entity/vehicle/NewMinecartBehavior.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/entity/vehicle/OldMinecartBehavior.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/food/FoodInfo.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/inventory/AbstractCraftingMenu.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/item/ItemChorusFruit.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/item/ItemMilkBucket.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/item/ItemPotion.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/item/ItemSuspiciousStew.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/item/alchemy/PotionContents.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/item/component/Consumable.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/item/component/ConsumableListener.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/item/component/DeathProtection.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/item/component/SuspiciousStewEffects.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffect.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffect.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/item/consume_effects/ConsumeEffect.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffect.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffect.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeMap.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/item/crafting/TransmuteRecipe.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/level/Explosion.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/level/ServerExplosion.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneWire.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/level/chunk/storage/ChunkRegionLoader.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/level/chunk/storage/SerializableChunkData.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/level/portal/DimensionTransition.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/level/portal/TeleportTransition.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.patch create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreakingHeart.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftCreakingHeart.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftHangingMoss.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftMossyCarpet.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftCreakingHeart.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftEquipableCarvedPumpkin.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftHangingMoss.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftMossyCarpet.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCreaking.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCreakingTransient.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaChestBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooChestRaft.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooRaft.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchChestBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryChestBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakChestBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleChestBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveChestBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakChestBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakChestBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceChestBoat.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftTransmuteRecipe.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftEquippableComponent.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftHolderUtil.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftUseCooldownComponent.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftDamageTag.java delete mode 100644 paper-server/src/test/java/org/bukkit/entity/BoatTest.java diff --git a/paper-server/nms-patches/net/minecraft/commands/CommandDispatcher.patch b/paper-server/nms-patches/net/minecraft/commands/CommandDispatcher.patch index ff91e67a01..8f5612fb5d 100644 --- a/paper-server/nms-patches/net/minecraft/commands/CommandDispatcher.patch +++ b/paper-server/nms-patches/net/minecraft/commands/CommandDispatcher.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/commands/CommandDispatcher.java +++ b/net/minecraft/commands/CommandDispatcher.java -@@ -135,6 +135,14 @@ +@@ -139,6 +139,14 @@ import net.minecraft.world.level.GameRules; import org.slf4j.Logger; @@ -15,7 +15,7 @@ public class CommandDispatcher { private static final ThreadLocal> CURRENT_EXECUTION_CONTEXT = new ThreadLocal(); -@@ -147,6 +155,7 @@ +@@ -151,6 +159,7 @@ private final com.mojang.brigadier.CommandDispatcher dispatcher = new com.mojang.brigadier.CommandDispatcher(); public CommandDispatcher(CommandDispatcher.ServerType commanddispatcher_servertype, CommandBuildContext commandbuildcontext) { @@ -23,7 +23,7 @@ CommandAdvancement.register(this.dispatcher); CommandAttribute.register(this.dispatcher, commandbuildcontext); CommandExecute.register(this.dispatcher, commandbuildcontext); -@@ -247,6 +256,11 @@ +@@ -252,6 +261,11 @@ CommandPublish.register(this.dispatcher); } @@ -35,7 +35,7 @@ this.dispatcher.setConsumer(ExecutionCommandSource.resultConsumer()); } -@@ -257,18 +271,65 @@ +@@ -262,18 +276,65 @@ return new ParseResults(commandcontextbuilder1, parseresults.getReader(), parseresults.getExceptions()); } @@ -95,7 +95,7 @@ + public void performCommand(ParseResults parseresults, String s, String label) { // CraftBukkit CommandListenerWrapper commandlistenerwrapper = (CommandListenerWrapper) parseresults.getContext().getSource(); - commandlistenerwrapper.getServer().getProfiler().push(() -> { + Profiler.get().push(() -> { return "/" + s; }); - ContextChain contextchain = finishParsing(parseresults, s, commandlistenerwrapper); @@ -103,7 +103,7 @@ try { if (contextchain != null) { -@@ -302,7 +363,7 @@ +@@ -307,7 +368,7 @@ } @Nullable @@ -112,7 +112,7 @@ try { validateParseResults(parseresults); return (ContextChain) ContextChain.tryFlatten(parseresults.getContext().build(s)).orElseThrow(() -> { -@@ -313,7 +374,7 @@ +@@ -318,7 +379,7 @@ if (commandsyntaxexception.getInput() != null && commandsyntaxexception.getCursor() >= 0) { int i = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor()); IChatMutableComponent ichatmutablecomponent = IChatBaseComponent.empty().withStyle(EnumChatFormat.GRAY).withStyle((chatmodifier) -> { @@ -121,7 +121,7 @@ }); if (i > 10) { -@@ -363,7 +424,7 @@ +@@ -368,7 +429,7 @@ executioncontext1.close(); } finally { @@ -130,7 +130,7 @@ } } else { consumer.accept(executioncontext); -@@ -372,11 +433,36 @@ +@@ -377,11 +438,36 @@ } public void sendCommands(EntityPlayer entityplayer) { @@ -168,7 +168,7 @@ entityplayer.connection.send(new PacketPlayOutCommands(rootcommandnode)); } -@@ -387,7 +473,7 @@ +@@ -392,7 +478,7 @@ CommandNode commandnode2 = (CommandNode) iterator.next(); if (commandnode2.canUse(commandlistenerwrapper)) { @@ -177,7 +177,7 @@ argumentbuilder.requires((icompletionprovider) -> { return true; -@@ -410,7 +496,7 @@ +@@ -415,7 +501,7 @@ argumentbuilder.redirect((CommandNode) map.get(argumentbuilder.getRedirect())); } @@ -186,7 +186,7 @@ map.put(commandnode2, commandnode3); commandnode1.addChild(commandnode3); -@@ -471,7 +557,7 @@ +@@ -481,7 +567,7 @@ } private HolderLookup.b.a createLookup(final HolderLookup.b holderlookup_b) { diff --git a/paper-server/nms-patches/net/minecraft/commands/CommandListenerWrapper.patch b/paper-server/nms-patches/net/minecraft/commands/CommandListenerWrapper.patch index 092f48ad10..940733b490 100644 --- a/paper-server/nms-patches/net/minecraft/commands/CommandListenerWrapper.patch +++ b/paper-server/nms-patches/net/minecraft/commands/CommandListenerWrapper.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/commands/CommandListenerWrapper.java +++ b/net/minecraft/commands/CommandListenerWrapper.java -@@ -44,6 +44,8 @@ +@@ -46,6 +46,8 @@ import net.minecraft.world.phys.Vec2F; import net.minecraft.world.phys.Vec3D; @@ -9,7 +9,7 @@ public class CommandListenerWrapper implements ExecutionCommandSource, ICompletionProvider { public static final SimpleCommandExceptionType ERROR_NOT_PLAYER = new SimpleCommandExceptionType(IChatBaseComponent.translatable("permissions.requires.player")); -@@ -63,6 +65,7 @@ +@@ -65,6 +67,7 @@ private final Vec2F rotation; private final CommandSigningContext signingContext; private final TaskChainer chatMessageChainer; @@ -17,7 +17,7 @@ public CommandListenerWrapper(ICommandListener icommandlistener, Vec3D vec3d, Vec2F vec2f, WorldServer worldserver, int i, String s, IChatBaseComponent ichatbasecomponent, MinecraftServer minecraftserver, @Nullable Entity entity) { this(icommandlistener, vec3d, vec2f, worldserver, i, s, ichatbasecomponent, minecraftserver, entity, false, CommandResultCallback.EMPTY, ArgumentAnchor.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(minecraftserver)); -@@ -169,9 +172,23 @@ +@@ -171,9 +174,23 @@ @Override public boolean hasPermission(int i) { @@ -41,16 +41,16 @@ public Vec3D getPosition() { return this.worldPosition; } -@@ -300,7 +317,7 @@ +@@ -302,7 +319,7 @@ while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer) iterator.next(); -- if (entityplayer != this.source && this.server.getPlayerList().isOp(entityplayer.getGameProfile())) { -+ if (entityplayer != this.source && entityplayer.getBukkitEntity().hasPermission("minecraft.admin.command_feedback")) { // CraftBukkit +- if (entityplayer.commandSource() != this.source && this.server.getPlayerList().isOp(entityplayer.getGameProfile())) { ++ if (entityplayer.commandSource() != this.source && entityplayer.getBukkitEntity().hasPermission("minecraft.admin.command_feedback")) { // CraftBukkit entityplayer.sendSystemMessage(ichatmutablecomponent); } } -@@ -393,4 +410,10 @@ +@@ -400,4 +417,10 @@ public boolean isSilent() { return this.silent; } diff --git a/paper-server/nms-patches/net/minecraft/core/cauldron/CauldronInteraction.patch b/paper-server/nms-patches/net/minecraft/core/cauldron/CauldronInteraction.patch index 4e271a50a5..d9fb2ed9e8 100644 --- a/paper-server/nms-patches/net/minecraft/core/cauldron/CauldronInteraction.patch +++ b/paper-server/nms-patches/net/minecraft/core/cauldron/CauldronInteraction.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/core/cauldron/CauldronInteraction.java +++ b/net/minecraft/core/cauldron/CauldronInteraction.java -@@ -34,9 +34,15 @@ - import net.minecraft.world.level.block.state.IBlockData; +@@ -36,14 +36,20 @@ import net.minecraft.world.level.gameevent.GameEvent; + import net.minecraft.world.level.material.Fluid; +// CraftBukkit start +import org.bukkit.event.block.CauldronLevelChangeEvent; @@ -11,27 +11,28 @@ public interface CauldronInteraction { Map INTERACTIONS = new Object2ObjectArrayMap(); -+ // CraftBukkit start - decompile error -+ /* - Codec CODEC; - CauldronInteraction.a EMPTY; - CauldronInteraction.a WATER; -@@ -48,6 +54,8 @@ - CauldronInteraction SHULKER_BOX; - CauldronInteraction BANNER; - CauldronInteraction DYED_ITEM; -+ */ +- Codec CODEC; +- CauldronInteraction.a EMPTY; +- CauldronInteraction.a WATER; +- CauldronInteraction.a LAVA; +- CauldronInteraction.a POWDER_SNOW; ++ // CraftBukkit start - decompile errors ++ Codec CODEC = Codec.stringResolver(CauldronInteraction.a::name, CauldronInteraction.INTERACTIONS::get); ++ CauldronInteraction.a EMPTY = newInteractionMap("empty"); ++ CauldronInteraction.a WATER = newInteractionMap("water"); ++ CauldronInteraction.a LAVA = newInteractionMap("lava"); ++ CauldronInteraction.a POWDER_SNOW = newInteractionMap("powder_snow"); + // CraftBukkit end static CauldronInteraction.a newInteractionMap(String s) { Object2ObjectOpenHashMap object2objectopenhashmap = new Object2ObjectOpenHashMap(); -@@ -72,12 +80,17 @@ +@@ -68,12 +74,17 @@ if (potioncontents != null && potioncontents.is(Potions.WATER)) { if (!world.isClientSide) { + // CraftBukkit start + if (!LayeredCauldronBlock.changeLevel(iblockdata, world, blockposition, Blocks.WATER_CAULDRON.defaultBlockState(), entityhuman, CauldronLevelChangeEvent.ChangeReason.BOTTLE_EMPTY)) { -+ return ItemInteractionResult.SUCCESS; ++ return EnumInteractionResult.SUCCESS; + } + // CraftBukkit end Item item = itemstack.getItem(); @@ -44,13 +45,13 @@ world.playSound((EntityHuman) null, blockposition, SoundEffects.BOTTLE_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F); world.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PLACE, blockposition); } -@@ -97,12 +110,17 @@ +@@ -93,12 +104,17 @@ }); map1.put(Items.GLASS_BOTTLE, (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { if (!world.isClientSide) { + // CraftBukkit start + if (!LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition, entityhuman, CauldronLevelChangeEvent.ChangeReason.BOTTLE_FILL)) { -+ return ItemInteractionResult.SUCCESS; ++ return EnumInteractionResult.SUCCESS; + } + // CraftBukkit end Item item = itemstack.getItem(); @@ -63,13 +64,13 @@ world.playSound((EntityHuman) null, blockposition, SoundEffects.BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F); world.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PICKUP, blockposition); } -@@ -117,10 +135,15 @@ +@@ -113,10 +129,15 @@ if (potioncontents != null && potioncontents.is(Potions.WATER)) { if (!world.isClientSide) { + // CraftBukkit start + if (!LayeredCauldronBlock.changeLevel(iblockdata, world, blockposition, iblockdata.cycle(LayeredCauldronBlock.LEVEL), entityhuman, CauldronLevelChangeEvent.ChangeReason.BOTTLE_EMPTY)) { -+ return ItemInteractionResult.SUCCESS; ++ return EnumInteractionResult.SUCCESS; + } + // CraftBukkit end entityhuman.setItemInHand(enumhand, ItemLiquidUtil.createFilledResult(itemstack, entityhuman, new ItemStack(Items.GLASS_BOTTLE))); @@ -80,13 +81,13 @@ world.playSound((EntityHuman) null, blockposition, SoundEffects.BOTTLE_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F); world.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PLACE, blockposition); } -@@ -198,12 +221,17 @@ - return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; +@@ -194,12 +215,17 @@ + return EnumInteractionResult.TRY_WITH_EMPTY_HAND; } else { if (!world.isClientSide) { + // CraftBukkit start + if (!LayeredCauldronBlock.changeLevel(iblockdata, world, blockposition, Blocks.CAULDRON.defaultBlockState(), entityhuman, CauldronLevelChangeEvent.ChangeReason.BUCKET_FILL)) { -+ return ItemInteractionResult.SUCCESS; ++ return EnumInteractionResult.SUCCESS; + } + // CraftBukkit end Item item = itemstack.getItem(); @@ -99,13 +100,13 @@ world.playSound((EntityHuman) null, blockposition, soundeffect, SoundCategory.BLOCKS, 1.0F, 1.0F); world.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PICKUP, blockposition); } -@@ -214,12 +242,17 @@ +@@ -210,12 +236,17 @@ - static ItemInteractionResult emptyBucket(World world, BlockPosition blockposition, EntityHuman entityhuman, EnumHand enumhand, ItemStack itemstack, IBlockData iblockdata, SoundEffect soundeffect) { + static EnumInteractionResult emptyBucket(World world, BlockPosition blockposition, EntityHuman entityhuman, EnumHand enumhand, ItemStack itemstack, IBlockData iblockdata, SoundEffect soundeffect) { if (!world.isClientSide) { + // CraftBukkit start + if (!LayeredCauldronBlock.changeLevel(iblockdata, world, blockposition, iblockdata, entityhuman, CauldronLevelChangeEvent.ChangeReason.BUCKET_EMPTY)) { -+ return ItemInteractionResult.SUCCESS; ++ return EnumInteractionResult.SUCCESS; + } + // CraftBukkit end Item item = itemstack.getItem(); @@ -118,113 +119,74 @@ world.playSound((EntityHuman) null, blockposition, soundeffect, SoundCategory.BLOCKS, 1.0F, 1.0F); world.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PLACE, blockposition); } -@@ -227,76 +260,89 @@ - return ItemInteractionResult.sidedSuccess(world.isClientSide); +@@ -242,11 +273,16 @@ + return EnumInteractionResult.TRY_WITH_EMPTY_HAND; + } else { + if (!world.isClientSide) { ++ // CraftBukkit start ++ if (!LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition, entityhuman, CauldronLevelChangeEvent.ChangeReason.SHULKER_WASH)) { ++ return EnumInteractionResult.SUCCESS; ++ } ++ // CraftBukkit end + ItemStack itemstack1 = itemstack.transmuteCopy(Blocks.SHULKER_BOX, 1); + + entityhuman.setItemInHand(enumhand, ItemLiquidUtil.createFilledResult(itemstack, entityhuman, itemstack1, false)); + entityhuman.awardStat(StatisticList.CLEAN_SHULKER_BOX); +- LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); ++ // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit + } + + return EnumInteractionResult.SUCCESS; +@@ -260,12 +296,17 @@ + return EnumInteractionResult.TRY_WITH_EMPTY_HAND; + } else { + if (!world.isClientSide) { ++ // CraftBukkit start ++ if (!LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition, entityhuman, CauldronLevelChangeEvent.ChangeReason.BANNER_WASH)) { ++ return EnumInteractionResult.SUCCESS; ++ } ++ // CraftBukkit end + ItemStack itemstack1 = itemstack.copyWithCount(1); + + itemstack1.set(DataComponents.BANNER_PATTERNS, bannerpatternlayers.removeLast()); + entityhuman.setItemInHand(enumhand, ItemLiquidUtil.createFilledResult(itemstack, entityhuman, itemstack1, false)); + entityhuman.awardStat(StatisticList.CLEAN_BANNER); +- LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); ++ // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit + } + + return EnumInteractionResult.SUCCESS; +@@ -279,9 +320,14 @@ + return EnumInteractionResult.TRY_WITH_EMPTY_HAND; + } else { + if (!world.isClientSide) { ++ // CraftBukkit start ++ if (!LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition, entityhuman, CauldronLevelChangeEvent.ChangeReason.ARMOR_WASH)) { ++ return EnumInteractionResult.SUCCESS; ++ } ++ // CraftBukkit end + itemstack.remove(DataComponents.DYED_COLOR); + entityhuman.awardStat(StatisticList.CLEAN_ARMOR); +- LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); ++ // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit + } + + return EnumInteractionResult.SUCCESS; +@@ -294,6 +340,8 @@ + return fluid.is(TagsFluid.WATER); } -- static { -- Function function = CauldronInteraction.a::name; -- Map map = CauldronInteraction.INTERACTIONS; -- -- Objects.requireNonNull(map); -- CODEC = Codec.stringResolver(function, map::get); -- EMPTY = newInteractionMap("empty"); -- WATER = newInteractionMap("water"); -- LAVA = newInteractionMap("lava"); -- POWDER_SNOW = newInteractionMap("powder_snow"); -- FILL_WATER = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { + // CraftBukkit start - decompile errors -+ // static { -+ Codec CODEC = Codec.stringResolver(CauldronInteraction.a::name, CauldronInteraction.INTERACTIONS::get); -+ CauldronInteraction.a EMPTY = newInteractionMap("empty"); -+ CauldronInteraction.a WATER = newInteractionMap("water"); -+ CauldronInteraction.a LAVA = newInteractionMap("lava"); -+ CauldronInteraction.a POWDER_SNOW = newInteractionMap("powder_snow"); -+ CauldronInteraction FILL_WATER = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { - return emptyBucket(world, blockposition, entityhuman, enumhand, itemstack, (IBlockData) Blocks.WATER_CAULDRON.defaultBlockState().setValue(LayeredCauldronBlock.LEVEL, 3), SoundEffects.BUCKET_EMPTY); - }; -- FILL_LAVA = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { -+ CauldronInteraction FILL_LAVA = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { - return emptyBucket(world, blockposition, entityhuman, enumhand, itemstack, Blocks.LAVA_CAULDRON.defaultBlockState(), SoundEffects.BUCKET_EMPTY_LAVA); - }; -- FILL_POWDER_SNOW = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { -+ CauldronInteraction FILL_POWDER_SNOW = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { - return emptyBucket(world, blockposition, entityhuman, enumhand, itemstack, (IBlockData) Blocks.POWDER_SNOW_CAULDRON.defaultBlockState().setValue(LayeredCauldronBlock.LEVEL, 3), SoundEffects.BUCKET_EMPTY_POWDER_SNOW); - }; -- SHULKER_BOX = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { -+ CauldronInteraction SHULKER_BOX = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { -+ // CraftBukkit end - Block block = Block.byItem(itemstack.getItem()); - - if (!(block instanceof BlockShulkerBox)) { - return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; - } else { - if (!world.isClientSide) { -+ // CraftBukkit start -+ if (!LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition, entityhuman, CauldronLevelChangeEvent.ChangeReason.SHULKER_WASH)) { -+ return ItemInteractionResult.SUCCESS; -+ } -+ // CraftBukkit end - ItemStack itemstack1 = itemstack.transmuteCopy(Blocks.SHULKER_BOX, 1); - - entityhuman.setItemInHand(enumhand, ItemLiquidUtil.createFilledResult(itemstack, entityhuman, itemstack1, false)); - entityhuman.awardStat(StatisticList.CLEAN_SHULKER_BOX); -- LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); -+ // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit - } - - return ItemInteractionResult.sidedSuccess(world.isClientSide); - } - }; -- BANNER = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { -+ CauldronInteraction BANNER = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { // CraftBukkit - decompile error - BannerPatternLayers bannerpatternlayers = (BannerPatternLayers) itemstack.getOrDefault(DataComponents.BANNER_PATTERNS, BannerPatternLayers.EMPTY); - - if (bannerpatternlayers.layers().isEmpty()) { - return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; - } else { - if (!world.isClientSide) { -+ // CraftBukkit start -+ if (!LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition, entityhuman, CauldronLevelChangeEvent.ChangeReason.BANNER_WASH)) { -+ return ItemInteractionResult.SUCCESS; -+ } -+ // CraftBukkit end - ItemStack itemstack1 = itemstack.copyWithCount(1); - - itemstack1.set(DataComponents.BANNER_PATTERNS, bannerpatternlayers.removeLast()); - entityhuman.setItemInHand(enumhand, ItemLiquidUtil.createFilledResult(itemstack, entityhuman, itemstack1, false)); - entityhuman.awardStat(StatisticList.CLEAN_BANNER); -- LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); -+ // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit - } - - return ItemInteractionResult.sidedSuccess(world.isClientSide); - } - }; -- DYED_ITEM = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { -+ CauldronInteraction DYED_ITEM = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { // CraftBukkit - decompile error - if (!itemstack.is(TagsItem.DYEABLE)) { - return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; - } else if (!itemstack.has(DataComponents.DYED_COLOR)) { - return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; - } else { - if (!world.isClientSide) { -+ // CraftBukkit start -+ if (!LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition, entityhuman, CauldronLevelChangeEvent.ChangeReason.ARMOR_WASH)) { -+ return ItemInteractionResult.SUCCESS; -+ } -+ // CraftBukkit end - itemstack.remove(DataComponents.DYED_COLOR); - entityhuman.awardStat(StatisticList.CLEAN_ARMOR); -- LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); -+ // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit - } - - return ItemInteractionResult.sidedSuccess(world.isClientSide); - } - }; -- } -+ // } // CraftBukkit - decompile error ++ /* + static { + Function function = CauldronInteraction.a::name; + Map map = CauldronInteraction.INTERACTIONS; +@@ -305,6 +353,8 @@ + LAVA = newInteractionMap("lava"); + POWDER_SNOW = newInteractionMap("powder_snow"); + } ++ */ ++ // CraftBukkit end public static record a(String name, Map map) { diff --git a/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorBoat.patch b/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorBoat.patch index e0360bdb4f..9bef9068df 100644 --- a/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorBoat.patch +++ b/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorBoat.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/core/dispenser/DispenseBehaviorBoat.java +++ b/net/minecraft/core/dispenser/DispenseBehaviorBoat.java -@@ -13,6 +13,12 @@ +@@ -12,6 +12,12 @@ import net.minecraft.world.level.block.BlockDispenser; import net.minecraft.world.phys.Vec3D; @@ -12,13 +12,11 @@ + public class DispenseBehaviorBoat extends DispenseBehaviorItem { - private final DispenseBehaviorItem defaultDispenseItemBehavior; -@@ -51,13 +57,41 @@ + private final DispenseBehaviorItem defaultDispenseItemBehavior = new DispenseBehaviorItem(); +@@ -43,14 +49,40 @@ d4 = 0.0D; } -- Object object = this.isChestBoat ? new ChestBoat(worldserver, d1, d2 + d4, d3) : new EntityBoat(worldserver, d1, d2 + d4, d3); -+ // Object object = this.isChestBoat ? new ChestBoat(worldserver, d1, d2 + d4, d3) : new EntityBoat(worldserver, d1, d2 + d4, d3); + // CraftBukkit start + ItemStack itemstack1 = itemstack.split(1); + org.bukkit.block.Block block = CraftBlock.at(worldserver, sourceblock.pos()); @@ -44,17 +42,18 @@ + return itemstack; + } + } -+ -+ EntityBoat object = this.isChestBoat ? new ChestBoat(worldserver, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ()) : new EntityBoat(worldserver, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ()); + // CraftBukkit end + AbstractBoat abstractboat = (AbstractBoat) this.type.create(worldserver, EntitySpawnReason.DISPENSER); + + if (abstractboat != null) { +- abstractboat.setInitialPos(d1, d2 + d4, d3); ++ abstractboat.setInitialPos(event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ()); // CraftBukkit + EntityTypes.createDefaultStackConfig(worldserver, itemstack, (EntityHuman) null).accept(abstractboat); + abstractboat.setYRot(enumdirection.toYRot()); +- worldserver.addFreshEntity(abstractboat); +- itemstack.shrink(1); ++ if (!worldserver.addFreshEntity(abstractboat)) itemstack.grow(1); // CraftBukkit ++ // itemstack.shrink(1); // CraftBukkit - handled during event processing + } - EntityTypes.createDefaultStackConfig(worldserver, itemstack, (EntityHuman) null).accept(object); - ((EntityBoat) object).setVariant(this.type); - ((EntityBoat) object).setYRot(enumdirection.toYRot()); -- worldserver.addFreshEntity((Entity) object); -- itemstack.shrink(1); -+ if (!worldserver.addFreshEntity((Entity) object)) itemstack.grow(1); // CraftBukkit -+ // itemstack.shrink(1); // CraftBukkit - handled during event processing return itemstack; - } - diff --git a/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorProjectile.patch b/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorProjectile.patch index cad1f78630..17073b18f2 100644 --- a/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorProjectile.patch +++ b/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorProjectile.patch @@ -14,11 +14,12 @@ public class DispenseBehaviorProjectile extends DispenseBehaviorItem { private final ProjectileItem projectileItem; -@@ -32,9 +39,38 @@ +@@ -31,8 +38,37 @@ + EnumDirection enumdirection = (EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING); IPosition iposition = this.dispenseConfig.positionFunction().getDispensePosition(sourceblock, enumdirection); - IProjectile iprojectile = this.projectileItem.asProjectile(worldserver, iposition, itemstack, enumdirection); -- this.projectileItem.shoot(iprojectile, (double) enumdirection.getStepX(), (double) enumdirection.getStepY(), (double) enumdirection.getStepZ(), this.dispenseConfig.power(), this.dispenseConfig.uncertainty()); +- IProjectile.spawnProjectileUsingShoot(this.projectileItem.asProjectile(worldserver, iposition, itemstack, enumdirection), worldserver, itemstack, (double) enumdirection.getStepX(), (double) enumdirection.getStepY(), (double) enumdirection.getStepZ(), this.dispenseConfig.power(), this.dispenseConfig.uncertainty()); +- itemstack.shrink(1); + // CraftBukkit start + // this.projectileItem.shoot(iprojectile, (double) enumdirection.getStepX(), (double) enumdirection.getStepY(), (double) enumdirection.getStepZ(), this.dispenseConfig.power(), this.dispenseConfig.uncertainty()); + ItemStack itemstack1 = itemstack.split(1); @@ -46,12 +47,10 @@ + } + } + -+ this.projectileItem.shoot(iprojectile, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), this.dispenseConfig.power(), this.dispenseConfig.uncertainty()); ++ IProjectile iprojectile = IProjectile.spawnProjectileUsingShoot(this.projectileItem.asProjectile(worldserver, iposition, itemstack, enumdirection), worldserver, itemstack, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), this.dispenseConfig.power(), this.dispenseConfig.uncertainty()); + ((Entity) iprojectile).projectileSource = new org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource(sourceblock.blockEntity()); -+ // CraftBukkit end - worldserver.addFreshEntity(iprojectile); -- itemstack.shrink(1); + // itemstack.shrink(1); // CraftBukkit - Handled during event processing ++ // CraftBukkit end return itemstack; } diff --git a/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorShears.patch b/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorShears.patch index ff8376c910..6e0926874b 100644 --- a/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorShears.patch +++ b/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorShears.patch @@ -45,8 +45,8 @@ if (!worldserver.isClientSide()) { BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING)); -- this.setSuccess(tryShearBeehive(worldserver, blockposition) || tryShearLivingEntity(worldserver, blockposition)); -+ this.setSuccess(tryShearBeehive(worldserver, blockposition) || tryShearLivingEntity(worldserver, blockposition, bukkitBlock, craftItem)); // CraftBukkit +- this.setSuccess(tryShearBeehive(worldserver, blockposition) || tryShearLivingEntity(worldserver, blockposition, itemstack)); ++ this.setSuccess(tryShearBeehive(worldserver, blockposition) || tryShearLivingEntity(worldserver, blockposition, itemstack, bukkitBlock, craftItem)); // CraftBukkit if (this.isSuccess()) { itemstack.hurtAndBreak(1, worldserver, (EntityPlayer) null, (item) -> { }); @@ -54,8 +54,8 @@ return false; } -- private static boolean tryShearLivingEntity(WorldServer worldserver, BlockPosition blockposition) { -+ private static boolean tryShearLivingEntity(WorldServer worldserver, BlockPosition blockposition, org.bukkit.block.Block bukkitBlock, CraftItemStack craftItem) { // CraftBukkit - add args +- private static boolean tryShearLivingEntity(WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack) { ++ private static boolean tryShearLivingEntity(WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, org.bukkit.block.Block bukkitBlock, CraftItemStack craftItem) { // CraftBukkit - add args List list = worldserver.getEntitiesOfClass(EntityLiving.class, new AxisAlignedBB(blockposition), IEntitySelector.NO_SPECTATORS); Iterator iterator = list.iterator(); @@ -68,6 +68,6 @@ + continue; + } + // CraftBukkit end - ishearable.shear(SoundCategory.BLOCKS); + ishearable.shear(worldserver, SoundCategory.BLOCKS, itemstack); worldserver.gameEvent((Entity) null, (Holder) GameEvent.SHEAR, blockposition); return true; diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemArmor.patch b/paper-server/nms-patches/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.patch similarity index 77% rename from paper-server/nms-patches/net/minecraft/world/item/ItemArmor.patch rename to paper-server/nms-patches/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.patch index 1c25dc58ce..4052a9e3f3 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemArmor.patch +++ b/paper-server/nms-patches/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.patch @@ -1,28 +1,29 @@ ---- a/net/minecraft/world/item/ItemArmor.java -+++ b/net/minecraft/world/item/ItemArmor.java -@@ -29,6 +29,12 @@ +--- a/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.java ++++ b/net/minecraft/core/dispenser/EquipmentDispenseItemBehavior.java +@@ -10,6 +10,13 @@ import net.minecraft.world.level.block.BlockDispenser; import net.minecraft.world.phys.AxisAlignedBB; +// CraftBukkit start ++import net.minecraft.world.level.World; +import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.event.block.BlockDispenseArmorEvent; +// CraftBukkit end + - public class ItemArmor extends Item implements Equipable { + public class EquipmentDispenseItemBehavior extends DispenseBehaviorItem { - public static final IDispenseBehavior DISPENSE_ITEM_BEHAVIOR = new DispenseBehaviorItem() { -@@ -51,8 +57,34 @@ - EntityLiving entityliving = (EntityLiving) list.get(0); + public static final EquipmentDispenseItemBehavior INSTANCE = new EquipmentDispenseItemBehavior(); +@@ -34,7 +41,34 @@ EnumItemSlot enumitemslot = entityliving.getEquipmentSlotForItem(itemstack); ItemStack itemstack1 = itemstack.split(1); + +- entityliving.setItemSlot(enumitemslot, itemstack1); + // CraftBukkit start + World world = sourceblock.level(); + org.bukkit.block.Block block = CraftBlock.at(world, sourceblock.pos()); + CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1); - -- entityliving.setItemSlot(enumitemslot, itemstack1); ++ + BlockDispenseArmorEvent event = new BlockDispenseArmorEvent(block, craftItem.clone(), (org.bukkit.craftbukkit.entity.CraftLivingEntity) entityliving.getBukkitEntity()); + if (!BlockDispenser.eventFired) { + world.getCraftServer().getPluginManager().callEvent(event); @@ -38,7 +39,7 @@ + // Chain to handler for new item + ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem()); + IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem()); -+ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != ItemArmor.DISPENSE_ITEM_BEHAVIOR) { ++ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != EquipmentDispenseItemBehavior.INSTANCE) { + idispensebehavior.dispense(sourceblock, eventStack); + return true; + } @@ -47,5 +48,5 @@ + entityliving.setItemSlot(enumitemslot, CraftItemStack.asNMSCopy(event.getItem())); + // CraftBukkit end if (entityliving instanceof EntityInsentient) { - ((EntityInsentient) entityliving).setDropChance(enumitemslot, 2.0F); - ((EntityInsentient) entityliving).setPersistenceRequired(); + EntityInsentient entityinsentient = (EntityInsentient) entityliving; + diff --git a/paper-server/nms-patches/net/minecraft/core/dispenser/IDispenseBehavior.patch b/paper-server/nms-patches/net/minecraft/core/dispenser/IDispenseBehavior.patch index 054da80dbc..502a05bc75 100644 --- a/paper-server/nms-patches/net/minecraft/core/dispenser/IDispenseBehavior.patch +++ b/paper-server/nms-patches/net/minecraft/core/dispenser/IDispenseBehavior.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/core/dispenser/IDispenseBehavior.java +++ b/net/minecraft/core/dispenser/IDispenseBehavior.java -@@ -67,6 +67,22 @@ +@@ -63,6 +63,22 @@ import net.minecraft.world.phys.MovingObjectPositionBlock; import org.slf4j.Logger; @@ -23,7 +23,7 @@ public interface IDispenseBehavior { Logger LOGGER = LogUtils.getLogger(); -@@ -94,14 +110,42 @@ +@@ -90,14 +106,42 @@ EnumDirection enumdirection = (EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING); EntityTypes entitytypes = ((ItemMonsterEgg) itemstack.getItem()).getType(itemstack); @@ -55,7 +55,7 @@ + } + try { - entitytypes.spawn(sourceblock.level(), itemstack, (EntityHuman) null, sourceblock.pos().relative(enumdirection), EnumMobSpawn.DISPENSER, enumdirection != EnumDirection.UP, false); + entitytypes.spawn(sourceblock.level(), itemstack, (EntityHuman) null, sourceblock.pos().relative(enumdirection), EntitySpawnReason.DISPENSER, enumdirection != EnumDirection.UP, false); } catch (Exception exception) { - null.LOGGER.error("Error while dispensing spawn egg from dispenser at {}", sourceblock.pos(), exception); + LOGGER.error("Error while dispensing spawn egg from dispenser at {}", sourceblock.pos(), exception); // CraftBukkit - decompile error @@ -68,7 +68,7 @@ sourceblock.level().gameEvent((Entity) null, (Holder) GameEvent.ENTITY_PLACE, sourceblock.pos()); return itemstack; } -@@ -120,13 +164,41 @@ +@@ -116,13 +160,41 @@ EnumDirection enumdirection = (EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING); BlockPosition blockposition = sourceblock.pos().relative(enumdirection); WorldServer worldserver = sourceblock.level(); @@ -103,7 +103,7 @@ Consumer consumer = EntityTypes.appendDefaultStackConfig((entityarmorstand) -> { entityarmorstand.setYRot(enumdirection.toYRot()); }, worldserver, itemstack, (EntityHuman) null); - EntityArmorStand entityarmorstand = (EntityArmorStand) EntityTypes.ARMOR_STAND.spawn(worldserver, consumer, blockposition, EnumMobSpawn.DISPENSER, false, false); + EntityArmorStand entityarmorstand = (EntityArmorStand) EntityTypes.ARMOR_STAND.spawn(worldserver, consumer, blockposition, EntitySpawnReason.DISPENSER, false, false); if (entityarmorstand != null) { - itemstack.shrink(1); @@ -111,7 +111,7 @@ } return itemstack; -@@ -145,7 +217,34 @@ +@@ -141,7 +213,34 @@ }); if (!list.isEmpty()) { @@ -137,7 +137,7 @@ + // Chain to handler for new item + ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem()); + IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem()); -+ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != ItemArmor.DISPENSE_ITEM_BEHAVIOR) { ++ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != EquipmentDispenseItemBehavior.INSTANCE) { + idispensebehavior.dispense(sourceblock, eventStack); + return itemstack; + } @@ -147,44 +147,7 @@ this.setSuccess(true); return itemstack; } else { -@@ -172,7 +271,35 @@ - entityhorseabstract = (EntityHorseAbstract) iterator1.next(); - } while (!entityhorseabstract.isBodyArmorItem(itemstack) || entityhorseabstract.isWearingBodyArmor() || !entityhorseabstract.isTamed()); - -- entityhorseabstract.setBodyArmorItem(itemstack.split(1)); -+ // CraftBukkit start -+ ItemStack itemstack1 = itemstack.split(1); -+ WorldServer world = sourceblock.level(); -+ org.bukkit.block.Block block = CraftBlock.at(world, sourceblock.pos()); -+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1); -+ -+ BlockDispenseArmorEvent event = new BlockDispenseArmorEvent(block, craftItem.clone(), (org.bukkit.craftbukkit.entity.CraftLivingEntity) entityhorseabstract.getBukkitEntity()); -+ if (!BlockDispenser.eventFired) { -+ world.getCraftServer().getPluginManager().callEvent(event); -+ } -+ -+ if (event.isCancelled()) { -+ itemstack.grow(1); -+ return itemstack; -+ } -+ -+ if (!event.getItem().equals(craftItem)) { -+ itemstack.grow(1); -+ // Chain to handler for new item -+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem()); -+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem()); -+ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != ItemArmor.DISPENSE_ITEM_BEHAVIOR) { -+ idispensebehavior.dispense(sourceblock, eventStack); -+ return itemstack; -+ } -+ } -+ -+ entityhorseabstract.setBodyArmorItem(CraftItemStack.asNMSCopy(event.getItem())); -+ // CraftBukkit end - this.setSuccess(true); - return itemstack; - } -@@ -215,9 +342,35 @@ +@@ -166,9 +265,35 @@ } entityhorsechestedabstract = (EntityHorseChestedAbstract) iterator1.next(); @@ -210,7 +173,7 @@ + // Chain to handler for new item + ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem()); + IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem()); -+ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != ItemArmor.DISPENSE_ITEM_BEHAVIOR) { ++ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != EquipmentDispenseItemBehavior.INSTANCE) { + idispensebehavior.dispense(sourceblock, eventStack); + return itemstack; + } @@ -222,7 +185,7 @@ this.setSuccess(true); return itemstack; } -@@ -249,6 +402,38 @@ +@@ -202,6 +327,38 @@ BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING)); WorldServer worldserver = sourceblock.level(); @@ -261,7 +224,7 @@ if (dispensiblecontaineritem.emptyContents((EntityHuman) null, worldserver, blockposition, (MovingObjectPositionBlock) null)) { dispensiblecontaineritem.checkExtraContent((EntityHuman) null, worldserver, itemstack, blockposition); return this.consumeWithRemainder(sourceblock, itemstack, new ItemStack(Items.BUCKET)); -@@ -276,7 +461,7 @@ +@@ -229,7 +386,7 @@ Block block = iblockdata.getBlock(); if (block instanceof IFluidSource ifluidsource) { @@ -270,7 +233,7 @@ if (itemstack1.isEmpty()) { return super.execute(sourceblock, itemstack); -@@ -284,6 +469,32 @@ +@@ -237,6 +394,32 @@ worldserver.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PICKUP, blockposition); Item item = itemstack1.getItem(); @@ -303,7 +266,7 @@ return this.consumeWithRemainder(sourceblock, itemstack, new ItemStack(item)); } } else { -@@ -296,16 +507,44 @@ +@@ -249,16 +432,44 @@ protected ItemStack execute(SourceBlock sourceblock, ItemStack itemstack) { WorldServer worldserver = sourceblock.level(); @@ -351,7 +314,7 @@ BlockTNT.explode(worldserver, blockposition); worldserver.removeBlock(blockposition, false); } else { -@@ -330,12 +569,62 @@ +@@ -283,12 +494,62 @@ this.setSuccess(true); WorldServer worldserver = sourceblock.level(); BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING)); @@ -414,7 +377,7 @@ return itemstack; } -@@ -345,12 +634,41 @@ +@@ -298,12 +559,41 @@ protected ItemStack execute(SourceBlock sourceblock, ItemStack itemstack) { WorldServer worldserver = sourceblock.level(); BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING)); @@ -458,7 +421,7 @@ return itemstack; } }); -@@ -375,6 +693,30 @@ +@@ -314,6 +604,30 @@ EnumDirection enumdirection = (EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING); BlockPosition blockposition = sourceblock.pos().relative(enumdirection); @@ -489,7 +452,7 @@ if (worldserver.isEmptyBlock(blockposition) && BlockWitherSkull.canSpawnMob(worldserver, blockposition, itemstack)) { worldserver.setBlock(blockposition, (IBlockData) Blocks.WITHER_SKELETON_SKULL.defaultBlockState().setValue(BlockSkull.ROTATION, RotationSegment.convertToSegment(enumdirection)), 3); worldserver.gameEvent((Entity) null, (Holder) GameEvent.BLOCK_PLACE, blockposition); -@@ -400,6 +742,30 @@ +@@ -339,6 +653,30 @@ BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING)); BlockPumpkinCarved blockpumpkincarved = (BlockPumpkinCarved) Blocks.CARVED_PUMPKIN; @@ -520,7 +483,7 @@ if (worldserver.isEmptyBlock(blockposition) && blockpumpkincarved.canSpawnGolem(worldserver, blockposition)) { if (!worldserver.isClientSide) { worldserver.setBlock(blockposition, blockpumpkincarved.defaultBlockState(), 3); -@@ -438,6 +804,30 @@ +@@ -377,6 +715,30 @@ BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING)); IBlockData iblockdata = worldserver.getBlockState(blockposition); @@ -551,7 +514,7 @@ if (iblockdata.is(TagsBlock.BEEHIVES, (blockbase_blockdata) -> { return blockbase_blockdata.hasProperty(BlockBeehive.HONEY_LEVEL) && blockbase_blockdata.getBlock() instanceof BlockBeehive; }) && (Integer) iblockdata.getValue(BlockBeehive.HONEY_LEVEL) >= 5) { -@@ -487,6 +877,31 @@ +@@ -426,6 +788,31 @@ this.setSuccess(false); return itemstack; } else { @@ -574,7 +537,7 @@ + // Chain to handler for new item + ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem()); + IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem()); -+ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != ItemArmor.DISPENSE_ITEM_BEHAVIOR) { ++ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != EquipmentDispenseItemBehavior.INSTANCE) { + idispensebehavior.dispense(sourceblock, eventStack); + return itemstack; + } diff --git a/paper-server/nms-patches/net/minecraft/core/dispenser/MinecartDispenseItemBehavior.patch b/paper-server/nms-patches/net/minecraft/core/dispenser/MinecartDispenseItemBehavior.patch new file mode 100644 index 0000000000..5ea81d2ee8 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/core/dispenser/MinecartDispenseItemBehavior.patch @@ -0,0 +1,59 @@ +--- a/net/minecraft/core/dispenser/MinecartDispenseItemBehavior.java ++++ b/net/minecraft/core/dispenser/MinecartDispenseItemBehavior.java +@@ -16,6 +16,12 @@ + import net.minecraft.world.level.block.state.properties.BlockPropertyTrackPosition; + import net.minecraft.world.phys.Vec3D; + ++// CraftBukkit start ++import org.bukkit.craftbukkit.block.CraftBlock; ++import org.bukkit.craftbukkit.inventory.CraftItemStack; ++import org.bukkit.event.block.BlockDispenseEvent; ++// CraftBukkit end ++ + public class MinecartDispenseItemBehavior extends DispenseBehaviorItem { + + private final DispenseBehaviorItem defaultDispenseItemBehavior = new DispenseBehaviorItem(); +@@ -62,11 +68,40 @@ + } + + Vec3D vec3d1 = new Vec3D(d0, d1 + d3, d2); +- EntityMinecartAbstract entityminecartabstract = EntityMinecartAbstract.createMinecart(worldserver, vec3d1.x, vec3d1.y, vec3d1.z, this.entityType, EntitySpawnReason.DISPENSER, itemstack, (EntityHuman) null); ++ // CraftBukkit start ++ // EntityMinecartAbstract entityminecartabstract = EntityMinecartAbstract.createMinecart(worldserver, vec3d1.x, vec3d1.y, vec3d1.z, this.entityType, EntitySpawnReason.DISPENSER, itemstack, (EntityHuman) null); ++ ItemStack itemstack1 = itemstack.split(1); ++ org.bukkit.block.Block block2 = CraftBlock.at(worldserver, sourceblock.pos()); ++ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1); ++ ++ BlockDispenseEvent event = new BlockDispenseEvent(block2, craftItem.clone(), new org.bukkit.util.Vector(vec3d1.x, vec3d1.y, vec3d1.z)); ++ if (!BlockDispenser.eventFired) { ++ worldserver.getCraftServer().getPluginManager().callEvent(event); ++ } ++ ++ if (event.isCancelled()) { ++ itemstack.grow(1); ++ return itemstack; ++ } ++ ++ if (!event.getItem().equals(craftItem)) { ++ itemstack.grow(1); ++ // Chain to handler for new item ++ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem()); ++ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem()); ++ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) { ++ idispensebehavior.dispense(sourceblock, eventStack); ++ return itemstack; ++ } ++ } ++ ++ itemstack1 = CraftItemStack.asNMSCopy(event.getItem()); ++ EntityMinecartAbstract entityminecartabstract = EntityMinecartAbstract.createMinecart(worldserver, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), this.entityType, EntitySpawnReason.DISPENSER, itemstack1, (EntityHuman) null); + + if (entityminecartabstract != null) { +- worldserver.addFreshEntity(entityminecartabstract); +- itemstack.shrink(1); ++ if (!worldserver.addFreshEntity(entityminecartabstract)) itemstack.grow(1); ++ // itemstack.shrink(1); // CraftBukkit - handled during event processing ++ // CraftBukkit end + } + + return itemstack; diff --git a/paper-server/nms-patches/net/minecraft/network/PacketDataSerializer.patch b/paper-server/nms-patches/net/minecraft/network/PacketDataSerializer.patch index 37573090e5..459f097864 100644 --- a/paper-server/nms-patches/net/minecraft/network/PacketDataSerializer.patch +++ b/paper-server/nms-patches/net/minecraft/network/PacketDataSerializer.patch @@ -51,7 +51,7 @@ BitSet bitset = this.readFixedBitSet(ae.length); EnumSet enumset = EnumSet.noneOf(oclass); -@@ -482,7 +482,7 @@ +@@ -498,7 +498,7 @@ } public > T readEnum(Class oclass) { @@ -60,7 +60,7 @@ } public PacketDataSerializer writeEnum(Enum oenum) { -@@ -549,7 +549,7 @@ +@@ -565,7 +565,7 @@ try { NBTCompressedStreamTools.writeAnyTag((NBTBase) nbtbase, new ByteBufOutputStream(bytebuf)); diff --git a/paper-server/nms-patches/net/minecraft/network/chat/IChatBaseComponent.patch b/paper-server/nms-patches/net/minecraft/network/chat/IChatBaseComponent.patch index 95c8733e3c..783abb4db2 100644 --- a/paper-server/nms-patches/net/minecraft/network/chat/IChatBaseComponent.patch +++ b/paper-server/nms-patches/net/minecraft/network/chat/IChatBaseComponent.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/network/chat/IChatBaseComponent.java +++ b/net/minecraft/network/chat/IChatBaseComponent.java -@@ -36,7 +36,22 @@ +@@ -38,7 +38,22 @@ import net.minecraft.util.FormattedString; import net.minecraft.world.level.ChunkCoordIntPair; diff --git a/paper-server/nms-patches/net/minecraft/server/AdvancementDataPlayer.patch b/paper-server/nms-patches/net/minecraft/server/AdvancementDataPlayer.patch index 87812ef579..ef25110a6b 100644 --- a/paper-server/nms-patches/net/minecraft/server/AdvancementDataPlayer.patch +++ b/paper-server/nms-patches/net/minecraft/server/AdvancementDataPlayer.patch @@ -15,4 +15,4 @@ + this.player.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.player.PlayerAdvancementDoneEvent(this.player.getBukkitEntity(), advancementholder.toBukkit())); // CraftBukkit advancementholder.value().rewards().grant(this.player); advancementholder.value().display().ifPresent((advancementdisplay) -> { - if (advancementdisplay.shouldAnnounceChat() && this.player.level().getGameRules().getBoolean(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)) { + if (advancementdisplay.shouldAnnounceChat() && this.player.serverLevel().getGameRules().getBoolean(GameRules.RULE_ANNOUNCE_ADVANCEMENTS)) { diff --git a/paper-server/nms-patches/net/minecraft/server/AdvancementDataWorld.patch b/paper-server/nms-patches/net/minecraft/server/AdvancementDataWorld.patch index be95a05a08..258a729f49 100644 --- a/paper-server/nms-patches/net/minecraft/server/AdvancementDataWorld.patch +++ b/paper-server/nms-patches/net/minecraft/server/AdvancementDataWorld.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/AdvancementDataWorld.java +++ b/net/minecraft/server/AdvancementDataWorld.java -@@ -27,11 +27,15 @@ +@@ -21,10 +21,14 @@ import net.minecraft.util.profiling.GameProfilerFiller; import org.slf4j.Logger; @@ -8,18 +8,17 @@ +import java.util.HashMap; +// CraftBukkit end + - public class AdvancementDataWorld extends ResourceDataJson { + public class AdvancementDataWorld extends ResourceDataJson { private static final Logger LOGGER = LogUtils.getLogger(); - public static final Gson GSON = (new GsonBuilder()).create(); - public Map advancements = Map.of(); + public Map advancements = new HashMap<>(); // CraftBukkit - SPIGOT-7734: mutable private AdvancementTree tree = new AdvancementTree(); private final HolderLookup.a registries; -@@ -55,7 +59,7 @@ - } - +@@ -40,7 +44,7 @@ + this.validate(minecraftkey, advancement); + builder.put(minecraftkey, new AdvancementHolder(minecraftkey, advancement)); }); - this.advancements = builder.buildOrThrow(); + this.advancements = new HashMap<>(builder.buildOrThrow()); // CraftBukkit - SPIGOT-7734: mutable diff --git a/paper-server/nms-patches/net/minecraft/server/CustomFunctionData.patch b/paper-server/nms-patches/net/minecraft/server/CustomFunctionData.patch index 21f7645c6a..419c9c3ea8 100644 --- a/paper-server/nms-patches/net/minecraft/server/CustomFunctionData.patch +++ b/paper-server/nms-patches/net/minecraft/server/CustomFunctionData.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/CustomFunctionData.java +++ b/net/minecraft/server/CustomFunctionData.java -@@ -36,7 +36,7 @@ +@@ -37,7 +37,7 @@ } public CommandDispatcher getDispatcher() { diff --git a/paper-server/nms-patches/net/minecraft/server/DispenserRegistry.patch b/paper-server/nms-patches/net/minecraft/server/DispenserRegistry.patch index 723d6d05b8..5d9a081597 100644 --- a/paper-server/nms-patches/net/minecraft/server/DispenserRegistry.patch +++ b/paper-server/nms-patches/net/minecraft/server/DispenserRegistry.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/server/DispenserRegistry.java +++ b/net/minecraft/server/DispenserRegistry.java -@@ -28,6 +28,12 @@ - import net.minecraft.world.level.block.BlockFire; +@@ -29,6 +29,12 @@ + import net.minecraft.world.level.block.state.BlockBase; import org.slf4j.Logger; +// CraftBukkit start @@ -13,7 +13,7 @@ public class DispenserRegistry { public static final PrintStream STDOUT = System.out; -@@ -39,6 +45,23 @@ +@@ -40,6 +46,23 @@ public static void bootStrap() { if (!DispenserRegistry.isBootstrapped) { @@ -37,7 +37,7 @@ DispenserRegistry.isBootstrapped = true; Instant instant = Instant.now(); -@@ -58,6 +81,69 @@ +@@ -59,6 +82,69 @@ wrapStreams(); DispenserRegistry.bootstrapDuration.set(Duration.between(instant, Instant.now()).toMillis()); } diff --git a/paper-server/nms-patches/net/minecraft/server/Main.patch b/paper-server/nms-patches/net/minecraft/server/Main.patch index 01bf23cac7..43088e1c11 100644 --- a/paper-server/nms-patches/net/minecraft/server/Main.patch +++ b/paper-server/nms-patches/net/minecraft/server/Main.patch @@ -135,7 +135,7 @@ worldstem = (WorldStem) SystemUtils.blockUntilDone((executor) -> { return WorldLoader.load(worldloader_c, (worldloader_a) -> { + worldLoader.set(worldloader_a); // CraftBukkit - IRegistry iregistry = worldloader_a.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM); + IRegistry iregistry = worldloader_a.datapackDimensions().lookupOrThrow(Registries.LEVEL_STEM); if (dynamic1 != null) { @@ -199,7 +248,7 @@ @@ -150,7 +150,7 @@ @@ -207,7 +256,7 @@ DedicatedServerProperties dedicatedserverproperties = dedicatedserversettings.getProperties(); - worldsettings = new WorldSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(), worldloader_a.dataConfiguration()); + worldsettings = new WorldSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(worldloader_a.dataConfiguration().enabledFeatures()), worldloader_a.dataConfiguration()); - worldoptions = optionset.has(optionspec3) ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions; + worldoptions = optionset.has("bonusChest") ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions; // CraftBukkit worlddimensions = dedicatedserverproperties.createDimensions(worldloader_a.datapackWorldgen()); @@ -213,5 +213,5 @@ - Main.LOGGER.info("Forcing world upgrade!"); + Main.LOGGER.info("Forcing world upgrade! {}", convertable_conversionsession.getLevelId()); // CraftBukkit WorldUpgrader worldupgrader = new WorldUpgrader(convertable_conversionsession, datafixer, iregistrycustom, flag, flag1); - IChatBaseComponent ichatbasecomponent = null; + try { diff --git a/paper-server/nms-patches/net/minecraft/server/MinecraftServer.patch b/paper-server/nms-patches/net/minecraft/server/MinecraftServer.patch index 9aa65086eb..fd9dbabc74 100644 --- a/paper-server/nms-patches/net/minecraft/server/MinecraftServer.patch +++ b/paper-server/nms-patches/net/minecraft/server/MinecraftServer.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/MinecraftServer.java +++ b/net/minecraft/server/MinecraftServer.java -@@ -173,13 +173,38 @@ +@@ -180,13 +180,38 @@ import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; @@ -29,7 +29,7 @@ +import org.bukkit.event.server.ServerLoadEvent; +// CraftBukkit end + - public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant implements ServerInfo, ChunkIOErrorReporter, ICommandListener, AutoCloseable { + public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant implements ServerInfo, ChunkIOErrorReporter, ICommandListener { public static final Logger LOGGER = LogUtils.getLogger(); public static final String VANILLA_BRAND = "vanilla"; @@ -40,9 +40,9 @@ private static final int OVERLOADED_TICKS_THRESHOLD = 20; private static final long OVERLOADED_WARNING_INTERVAL_NANOS = 10L * TimeRange.NANOSECONDS_PER_SECOND; private static final int OVERLOADED_TICKS_WARNING_INTERVAL = 100; -@@ -266,6 +291,19 @@ - private volatile boolean isSaving; - private static final AtomicReference fatalException = new AtomicReference(); +@@ -277,6 +302,19 @@ + private final SuppressedExceptionCollector suppressedExceptions; + private final DiscontinuousFrame tickFrame; + // CraftBukkit start + public final WorldLoader.a worldLoader; @@ -60,7 +60,7 @@ public static S spin(Function function) { AtomicReference atomicreference = new AtomicReference(); Thread thread = new Thread(() -> { -@@ -279,14 +317,14 @@ +@@ -290,14 +328,14 @@ thread.setPriority(8); } @@ -76,19 +76,19 @@ + public MinecraftServer(OptionSet options, WorldLoader.a worldLoader, Thread thread, Convertable.ConversionSession convertable_conversionsession, ResourcePackRepository resourcepackrepository, WorldStem worldstem, Proxy proxy, DataFixer datafixer, Services services, WorldLoadListenerFactory worldloadlistenerfactory) { super("Server"); this.metricsRecorder = InactiveMetricsRecorder.INSTANCE; - this.profiler = this.metricsRecorder.getProfiler(); -@@ -309,7 +347,7 @@ - this.customBossEvents = new BossBattleCustomData(); + this.onMetricsRecordingStopped = (methodprofilerresults) -> { +@@ -321,7 +359,7 @@ + this.suppressedExceptions = new SuppressedExceptionCollector(); this.registries = worldstem.registries(); this.worldData = worldstem.worldData(); -- if (!this.registries.compositeAccess().registryOrThrow(Registries.LEVEL_STEM).containsKey(WorldDimension.OVERWORLD)) { -+ if (false && !this.registries.compositeAccess().registryOrThrow(Registries.LEVEL_STEM).containsKey(WorldDimension.OVERWORLD)) { // CraftBukkit - initialised later +- if (!this.registries.compositeAccess().lookupOrThrow(Registries.LEVEL_STEM).containsKey(WorldDimension.OVERWORLD)) { ++ if (false && !this.registries.compositeAccess().lookupOrThrow(Registries.LEVEL_STEM).containsKey(WorldDimension.OVERWORLD)) { // CraftBukkit - initialised later throw new IllegalStateException("Missing Overworld dimension data"); } else { this.proxy = proxy; -@@ -334,6 +372,33 @@ - this.executor = SystemUtils.backgroundExecutor(); - this.potionBrewing = PotionBrewer.bootstrap(this.worldData.enabledFeatures()); +@@ -349,6 +387,33 @@ + this.fuelValues = FuelValues.vanillaBurnTimes(this.registries.compositeAccess(), this.worldData.enabledFeatures()); + this.tickFrame = TracyClient.createDiscontinuousFrame("Server Tick"); } + // CraftBukkit start + this.options = options; @@ -120,7 +120,7 @@ } private void readScoreboard(WorldPersistentData worldpersistentdata) { -@@ -342,7 +407,7 @@ +@@ -357,7 +422,7 @@ protected abstract boolean initServer() throws IOException; @@ -129,7 +129,7 @@ if (!JvmProfiler.INSTANCE.isRunning()) { ; } -@@ -350,12 +415,8 @@ +@@ -365,12 +430,8 @@ boolean flag = false; ProfiledDuration profiledduration = JvmProfiler.INSTANCE.onWorldLoadedStarted(); @@ -143,19 +143,19 @@ if (profiledduration != null) { profiledduration.finish(); } -@@ -372,23 +433,217 @@ +@@ -387,23 +448,217 @@ protected void forceDifficulty() {} - protected void createLevels(WorldLoadListener worldloadlistener) { - IWorldDataServer iworlddataserver = this.worldData.overworldData(); - boolean flag = this.worldData.isDebugWorld(); -- IRegistry iregistry = this.registries.compositeAccess().registryOrThrow(Registries.LEVEL_STEM); +- IRegistry iregistry = this.registries.compositeAccess().lookupOrThrow(Registries.LEVEL_STEM); - WorldOptions worldoptions = this.worldData.worldGenOptions(); - long i = worldoptions.seed(); - long j = BiomeManager.obfuscateSeed(i); - List list = ImmutableList.of(new MobSpawnerPhantom(), new MobSpawnerPatrol(), new MobSpawnerCat(), new VillageSiege(), new MobSpawnerTrader(iworlddataserver)); -- WorldDimension worlddimension = (WorldDimension) iregistry.get(WorldDimension.OVERWORLD); +- WorldDimension worlddimension = (WorldDimension) iregistry.getValue(WorldDimension.OVERWORLD); - WorldServer worldserver = new WorldServer(this, this.executor, this.storageSource, iworlddataserver, World.OVERWORLD, worlddimension, worldloadlistener, flag, j, list, true, (RandomSequences) null); + // CraftBukkit start + private void loadWorld0(String s) { @@ -164,7 +164,7 @@ - this.levels.put(World.OVERWORLD, worldserver); - WorldPersistentData worldpersistentdata = worldserver.getDataStorage(); + IRegistryCustom.Dimension iregistrycustom_dimension = this.registries.compositeAccess(); -+ IRegistry dimensions = iregistrycustom_dimension.registryOrThrow(Registries.LEVEL_STEM); ++ IRegistry dimensions = iregistrycustom_dimension.lookupOrThrow(Registries.LEVEL_STEM); + for (WorldDimension worldDimension : dimensions) { + ResourceKey dimensionKey = dimensions.getResourceKey(worldDimension).get(); @@ -276,7 +276,7 @@ + + WorldDataServer worlddata; + WorldLoader.a worldloader_a = this.worldLoader; -+ IRegistry iregistry = worldloader_a.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM); ++ IRegistry iregistry = worldloader_a.datapackDimensions().lookupOrThrow(Registries.LEVEL_STEM); + if (dynamic != null) { + LevelDataAndDimensions leveldataanddimensions = Convertable.getLevelDataAndDimensions(dynamic, worldloader_a.dataConfiguration(), iregistry, worldloader_a.datapackWorldgen()); + @@ -293,7 +293,7 @@ + } else { + DedicatedServerProperties dedicatedserverproperties = ((DedicatedServer) this).getProperties(); + -+ worldsettings = new WorldSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(), worldloader_a.dataConfiguration()); ++ worldsettings = new WorldSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(worldloader_a.dataConfiguration().enabledFeatures()), worldloader_a.dataConfiguration()); + worldoptions = options.has("bonusChest") ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions; + worlddimensions = dedicatedserverproperties.createDimensions(worldloader_a.datapackWorldgen()); + } @@ -316,7 +316,7 @@ + long i = worldoptions.seed(); + long j = BiomeManager.obfuscateSeed(i); + List list = ImmutableList.of(new MobSpawnerPhantom(), new MobSpawnerPatrol(), new MobSpawnerCat(), new VillageSiege(), new MobSpawnerTrader(iworlddataserver)); -+ WorldDimension worlddimension = (WorldDimension) dimensions.get(dimensionKey); ++ WorldDimension worlddimension = (WorldDimension) dimensions.getValue(dimensionKey); + + org.bukkit.generator.WorldInfo worldInfo = new org.bukkit.craftbukkit.generator.CraftWorldInfo(iworlddataserver, worldSession, org.bukkit.World.Environment.getEnvironment(dimension), worlddimension.type().value()); + if (biomeProvider == null && gen != null) { @@ -375,7 +375,7 @@ if (!iworlddataserver.isInitialized()) { try { -@@ -412,30 +667,8 @@ +@@ -427,30 +682,8 @@ iworlddataserver.setInitialized(true); } @@ -407,7 +407,7 @@ private static void setInitialSpawn(WorldServer worldserver, IWorldDataServer iworlddataserver, boolean flag, boolean flag1) { if (flag1) { -@@ -443,6 +676,21 @@ +@@ -458,6 +691,21 @@ } else { ChunkProviderServer chunkproviderserver = worldserver.getChunkSource(); ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(chunkproviderserver.randomState().sampler().findSpawnPosition()); @@ -428,8 +428,8 @@ + // CraftBukkit end int i = chunkproviderserver.getGenerator().getSpawnHeight(worldserver); - if (i < worldserver.getMinBuildHeight()) { -@@ -501,8 +749,11 @@ + if (i < worldserver.getMinY()) { +@@ -516,8 +764,11 @@ iworlddataserver.setGameType(EnumGamemode.SPECTATOR); } @@ -443,7 +443,7 @@ MinecraftServer.LOGGER.info("Preparing start region for dimension {}", worldserver.dimension().location()); BlockPosition blockposition = worldserver.getSharedSpawnPos(); -@@ -512,20 +763,22 @@ +@@ -527,20 +778,22 @@ this.nextTickTimeNanos = SystemUtils.getNanos(); worldserver.setDefaultSpawnPos(blockposition, worldserver.getSharedSpawnAngle()); @@ -474,7 +474,7 @@ ForcedChunk forcedchunk = (ForcedChunk) worldserver1.getDataStorage().get(ForcedChunk.factory(), "chunks"); if (forcedchunk != null) { -@@ -540,10 +793,17 @@ +@@ -555,10 +808,17 @@ } } @@ -488,14 +488,14 @@ - this.updateMobSpawningFlags(); + // CraftBukkit start + // this.updateMobSpawningFlags(); -+ worldserver.setSpawnSettings(this.isSpawningMonsters(), this.isSpawningAnimals()); ++ worldserver.setSpawnSettings(this.isSpawningMonsters()); + + this.forceTicks = false; + // CraftBukkit end } public EnumGamemode getDefaultGameType() { -@@ -573,12 +833,16 @@ +@@ -588,12 +848,16 @@ worldserver.save((IProgressUpdate) null, flag1, worldserver.noSave && !flag2); } @@ -512,7 +512,7 @@ if (flag1) { Iterator iterator1 = this.getAllLevels().iterator(); -@@ -613,18 +877,40 @@ +@@ -628,18 +892,40 @@ this.stopServer(); } @@ -553,7 +553,7 @@ } MinecraftServer.LOGGER.info("Saving worlds"); -@@ -712,7 +998,7 @@ +@@ -727,7 +1013,7 @@ } this.nextTickTimeNanos = SystemUtils.getNanos(); @@ -562,7 +562,7 @@ this.status = this.buildServerStatus(); while (this.running) { -@@ -729,6 +1015,7 @@ +@@ -744,6 +1030,7 @@ if (j > MinecraftServer.OVERLOADED_THRESHOLD_NANOS + 20L * i && this.nextTickTimeNanos - this.lastOverloadWarningNanos >= MinecraftServer.OVERLOADED_WARNING_INTERVAL_NANOS + 100L * i) { long k = j / i; @@ -570,15 +570,15 @@ MinecraftServer.LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", j / TimeRange.NANOSECONDS_PER_MILLISECOND, k); this.nextTickTimeNanos += k * i; this.lastOverloadWarningNanos = this.nextTickTimeNanos; -@@ -742,6 +1029,7 @@ +@@ -757,6 +1044,7 @@ this.debugCommandProfiler = new MinecraftServer.TimeProfiler(SystemUtils.getNanos(), this.tickCount); } + MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit this.nextTickTimeNanos += i; - this.startMetricsRecordingTick(); - this.profiler.push("tick"); -@@ -789,6 +1077,12 @@ + + try { +@@ -830,6 +1118,12 @@ this.services.profileCache().clearExecutor(); } @@ -591,7 +591,7 @@ this.onServerExit(); } -@@ -848,7 +1142,14 @@ +@@ -889,7 +1183,14 @@ } private boolean haveTime() { @@ -607,7 +607,7 @@ } public static boolean throwIfFatalException() { -@@ -862,7 +1163,7 @@ +@@ -903,7 +1204,7 @@ } public static void setFatalException(RuntimeException runtimeexception) { @@ -616,36 +616,49 @@ } @Override -@@ -928,7 +1229,7 @@ +@@ -977,7 +1278,7 @@ } } - protected void doRunTask(TickTask ticktask) { + public void doRunTask(TickTask ticktask) { // CraftBukkit - decompile error - this.getProfiler().incrementCounter("runTask"); + Profiler.get().incrementCounter("runTask"); super.doRunTask(ticktask); } -@@ -987,8 +1288,10 @@ +@@ -1041,6 +1342,7 @@ + this.autoSave(); + } + ++ this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit + this.tickConnection(); + return; + } +@@ -1055,7 +1357,7 @@ } --this.ticksUntilAutosave; - if (this.ticksUntilAutosave <= 0) { -- this.ticksUntilAutosave = this.computeNextAutosaveInterval(); -+ // CraftBukkit start -+ if (this.autosavePeriod > 0 && this.ticksUntilAutosave <= 0) { -+ this.ticksUntilAutosave = this.autosavePeriod; -+ // CraftBukkit end - MinecraftServer.LOGGER.debug("Autosave started"); - this.profiler.push("save"); - this.saveEverything(true, false, false); -@@ -1076,11 +1379,26 @@ ++ if (this.autosavePeriod > 0 && this.ticksUntilAutosave <= 0) { // CraftBukkit + this.autoSave(); + } + +@@ -1074,7 +1376,7 @@ + } + + private void autoSave() { +- this.ticksUntilAutosave = this.computeNextAutosaveInterval(); ++ this.ticksUntilAutosave = this.autosavePeriod; // CraftBukkit + MinecraftServer.LOGGER.debug("Autosave started"); + GameProfilerFiller gameprofilerfiller = Profiler.get(); + +@@ -1154,11 +1456,26 @@ this.getPlayerList().getPlayers().forEach((entityplayer) -> { entityplayer.connection.suspendFlushing(); }); -+ this.server.getScheduler().mainThreadHeartbeat(this.tickCount); // CraftBukkit - this.profiler.push("commandFunctions"); ++ this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit + gameprofilerfiller.push("commandFunctions"); this.getFunctions().tick(); - this.profiler.popPush("levels"); + gameprofilerfiller.popPush("levels"); Iterator iterator = this.getAllLevels().iterator(); + // CraftBukkit start @@ -658,28 +671,28 @@ + if (this.tickCount % 20 == 0) { + for (int i = 0; i < this.getPlayerList().players.size(); ++i) { + EntityPlayer entityplayer = (EntityPlayer) this.getPlayerList().players.get(i); -+ entityplayer.connection.send(new PacketPlayOutUpdateTime(entityplayer.level().getGameTime(), entityplayer.getPlayerTime(), entityplayer.level().getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); // Add support for per player time ++ entityplayer.connection.send(new PacketPlayOutUpdateTime(entityplayer.level().getGameTime(), entityplayer.getPlayerTime(), entityplayer.serverLevel().getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); // Add support for per player time + } + } + while (iterator.hasNext()) { WorldServer worldserver = (WorldServer) iterator.next(); -@@ -1089,11 +1407,13 @@ +@@ -1167,11 +1484,13 @@ return s + " " + String.valueOf(worldserver.dimension().location()); }); + /* Drop global time updates if (this.tickCount % 20 == 0) { - this.profiler.push("timeSync"); + gameprofilerfiller.push("timeSync"); this.synchronizeTime(worldserver); - this.profiler.pop(); + gameprofilerfiller.pop(); } + // CraftBukkit end */ - this.profiler.push("tick"); + gameprofilerfiller.push("tick"); -@@ -1183,6 +1503,22 @@ +@@ -1267,6 +1586,22 @@ return (WorldServer) this.levels.get(resourcekey); } @@ -702,7 +715,7 @@ public Set> levelKeys() { return this.levels.keySet(); } -@@ -1212,7 +1548,7 @@ +@@ -1296,7 +1631,7 @@ @DontObfuscate public String getServerModName() { @@ -711,7 +724,7 @@ } public SystemReport fillSystemReport(SystemReport systemreport) { -@@ -1554,11 +1890,11 @@ +@@ -1634,11 +1969,11 @@ public CompletableFuture reloadResources(Collection collection) { CompletableFuture completablefuture = CompletableFuture.supplyAsync(() -> { @@ -724,8 +737,8 @@ + return stream.map(resourcepackrepository::getPack).filter(Objects::nonNull).map(ResourcePackLoader::open).collect(ImmutableList.toImmutableList()); // CraftBukkit - decompile error }, this).thenCompose((immutablelist) -> { ResourceManager resourcemanager = new ResourceManager(EnumResourcePackType.SERVER_DATA, immutablelist); - -@@ -1573,6 +1909,7 @@ + List> list = TagDataPack.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess()); +@@ -1654,6 +1989,7 @@ }).thenAcceptAsync((minecraftserver_reloadableresources) -> { this.resources.close(); this.resources = minecraftserver_reloadableresources; @@ -733,16 +746,16 @@ this.packRepository.setSelected(collection); WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures()); -@@ -1873,7 +2210,7 @@ +@@ -1952,7 +2288,7 @@ final List list = Lists.newArrayList(); final GameRules gamerules = this.getGameRules(); -- GameRules.visitGameRuleTypes(new GameRules.GameRuleVisitor(this) { -+ GameRules.visitGameRuleTypes(new GameRules.GameRuleVisitor() { // CraftBukkit - decompile error +- gamerules.visitGameRuleTypes(new GameRules.GameRuleVisitor(this) { ++ gamerules.visitGameRuleTypes(new GameRules.GameRuleVisitor() { // CraftBukkit - decompile error @Override public > void visit(GameRules.GameRuleKey gamerules_gamerulekey, GameRules.GameRuleDefinition gamerules_gameruledefinition) { list.add(String.format(Locale.ROOT, "%s=%s\n", gamerules_gamerulekey.getId(), gamerules.getRule(gamerules_gamerulekey))); -@@ -1979,7 +2316,7 @@ +@@ -2058,7 +2394,7 @@ try { label51: { @@ -751,7 +764,7 @@ try { arraylist = Lists.newArrayList(NativeModuleLister.listModules()); -@@ -2029,6 +2366,22 @@ +@@ -2108,6 +2444,22 @@ } @@ -771,10 +784,10 @@ + } + // CraftBukkit end + - private void startMetricsRecordingTick() { + private GameProfilerFiller createProfiler() { if (this.willStartRecordingMetrics) { this.metricsRecorder = ActiveMetricsRecorder.createStarted(new ServerMetricsSamplersProvider(SystemUtils.timeSource, this.isDedicatedServer()), SystemUtils.timeSource, SystemUtils.ioPool(), new MetricsPersister("server"), this.onMetricsRecordingStopped, (path) -> { -@@ -2159,6 +2512,11 @@ +@@ -2235,6 +2587,11 @@ } diff --git a/paper-server/nms-patches/net/minecraft/server/commands/CommandGamerule.patch b/paper-server/nms-patches/net/minecraft/server/commands/CommandGamerule.patch index e9c56cdd3c..f3107570d5 100644 --- a/paper-server/nms-patches/net/minecraft/server/commands/CommandGamerule.patch +++ b/paper-server/nms-patches/net/minecraft/server/commands/CommandGamerule.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/commands/CommandGamerule.java +++ b/net/minecraft/server/commands/CommandGamerule.java -@@ -31,7 +31,7 @@ +@@ -34,7 +34,7 @@ static > int setRule(CommandContext commandcontext, GameRules.GameRuleKey gamerules_gamerulekey) { CommandListenerWrapper commandlistenerwrapper = (CommandListenerWrapper) commandcontext.getSource(); @@ -9,7 +9,7 @@ t0.setFromArgument(commandcontext, "value"); commandlistenerwrapper.sendSuccess(() -> { -@@ -41,7 +41,7 @@ +@@ -44,7 +44,7 @@ } static > int queryRule(CommandListenerWrapper commandlistenerwrapper, GameRules.GameRuleKey gamerules_gamerulekey) { diff --git a/paper-server/nms-patches/net/minecraft/server/commands/CommandLoot.patch b/paper-server/nms-patches/net/minecraft/server/commands/CommandLoot.patch index 8c24291735..d68afd407f 100644 --- a/paper-server/nms-patches/net/minecraft/server/commands/CommandLoot.patch +++ b/paper-server/nms-patches/net/minecraft/server/commands/CommandLoot.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/commands/CommandLoot.java +++ b/net/minecraft/server/commands/CommandLoot.java -@@ -91,7 +91,7 @@ +@@ -95,7 +95,7 @@ } private static > T addTargets(T t0, CommandLoot.c commandloot_c) { @@ -9,7 +9,7 @@ return entityReplace(ArgumentEntity.getEntities(commandcontext, "entities"), ArgumentInventorySlot.getSlot(commandcontext, "slot"), list.size(), list, commandloot_a); }).then(commandloot_c.construct(net.minecraft.commands.CommandDispatcher.argument("count", IntegerArgumentType.integer(0)), (commandcontext, list, commandloot_a) -> { return entityReplace(ArgumentEntity.getEntities(commandcontext, "entities"), ArgumentInventorySlot.getSlot(commandcontext, "slot"), IntegerArgumentType.getInteger(commandcontext, "count"), list, commandloot_a); -@@ -246,6 +246,7 @@ +@@ -250,6 +250,7 @@ private static int dropInWorld(CommandListenerWrapper commandlistenerwrapper, Vec3D vec3d, List list, CommandLoot.a commandloot_a) throws CommandSyntaxException { WorldServer worldserver = commandlistenerwrapper.getLevel(); diff --git a/paper-server/nms-patches/net/minecraft/server/commands/CommandSchedule.patch b/paper-server/nms-patches/net/minecraft/server/commands/CommandSchedule.patch index 00b2030779..96177b3a22 100644 --- a/paper-server/nms-patches/net/minecraft/server/commands/CommandSchedule.patch +++ b/paper-server/nms-patches/net/minecraft/server/commands/CommandSchedule.patch @@ -1,11 +1,11 @@ --- a/net/minecraft/server/commands/CommandSchedule.java +++ b/net/minecraft/server/commands/CommandSchedule.java -@@ -55,7 +55,7 @@ +@@ -58,7 +58,7 @@ } else { long j = commandlistenerwrapper.getLevel().getGameTime() + (long) i; MinecraftKey minecraftkey = (MinecraftKey) pair.getFirst(); - CustomFunctionCallbackTimerQueue customfunctioncallbacktimerqueue = commandlistenerwrapper.getServer().getWorldData().overworldData().getScheduledEvents(); + CustomFunctionCallbackTimerQueue customfunctioncallbacktimerqueue = commandlistenerwrapper.getLevel().serverLevelData.overworldData().getScheduledEvents(); // CraftBukkit - SPIGOT-6667: Use world specific function timer + Optional> optional = ((Either) pair.getSecond()).left(); + String s; - ((Either) pair.getSecond()).ifLeft((net_minecraft_commands_functions_commandfunction) -> { - String s = minecraftkey.toString(); diff --git a/paper-server/nms-patches/net/minecraft/server/commands/CommandSpreadPlayers.patch b/paper-server/nms-patches/net/minecraft/server/commands/CommandSpreadPlayers.patch index b637188cd4..67d39d3329 100644 --- a/paper-server/nms-patches/net/minecraft/server/commands/CommandSpreadPlayers.patch +++ b/paper-server/nms-patches/net/minecraft/server/commands/CommandSpreadPlayers.patch @@ -13,8 +13,8 @@ commandspreadplayers_a = acommandspreadplayers_a[j++]; } -- entity.teleportTo(worldserver, (double) MathHelper.floor(commandspreadplayers_a.x) + 0.5D, (double) commandspreadplayers_a.getSpawnY(worldserver, i), (double) MathHelper.floor(commandspreadplayers_a.z) + 0.5D, Set.of(), entity.getYRot(), entity.getXRot()); -+ entity.teleportTo(worldserver, (double) MathHelper.floor(commandspreadplayers_a.x) + 0.5D, (double) commandspreadplayers_a.getSpawnY(worldserver, i), (double) MathHelper.floor(commandspreadplayers_a.z) + 0.5D, Set.of(), entity.getYRot(), entity.getXRot(), org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.COMMAND); // CraftBukkit - handle teleport reason +- entity.teleportTo(worldserver, (double) MathHelper.floor(commandspreadplayers_a.x) + 0.5D, (double) commandspreadplayers_a.getSpawnY(worldserver, i), (double) MathHelper.floor(commandspreadplayers_a.z) + 0.5D, Set.of(), entity.getYRot(), entity.getXRot(), true); ++ entity.teleportTo(worldserver, (double) MathHelper.floor(commandspreadplayers_a.x) + 0.5D, (double) commandspreadplayers_a.getSpawnY(worldserver, i), (double) MathHelper.floor(commandspreadplayers_a.z) + 0.5D, Set.of(), entity.getYRot(), entity.getXRot(), true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.COMMAND); // CraftBukkit - handle teleport reason d1 = Double.MAX_VALUE; CommandSpreadPlayers.a[] acommandspreadplayers_a1 = acommandspreadplayers_a; int k = acommandspreadplayers_a.length; diff --git a/paper-server/nms-patches/net/minecraft/server/commands/CommandSummon.patch b/paper-server/nms-patches/net/minecraft/server/commands/CommandSummon.patch index 7cff016f53..8e53d33698 100644 --- a/paper-server/nms-patches/net/minecraft/server/commands/CommandSummon.patch +++ b/paper-server/nms-patches/net/minecraft/server/commands/CommandSummon.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/server/commands/CommandSummon.java +++ b/net/minecraft/server/commands/CommandSummon.java @@ -67,7 +67,7 @@ - ((EntityInsentient) entity).finalizeSpawn(commandlistenerwrapper.getLevel(), commandlistenerwrapper.getLevel().getCurrentDifficultyAt(entity.blockPosition()), EnumMobSpawn.COMMAND, (GroupDataEntity) null); + ((EntityInsentient) entity).finalizeSpawn(commandlistenerwrapper.getLevel(), commandlistenerwrapper.getLevel().getCurrentDifficultyAt(entity.blockPosition()), EntitySpawnReason.COMMAND, (GroupDataEntity) null); } - if (!worldserver.tryAddFreshEntityWithPassengers(entity)) { diff --git a/paper-server/nms-patches/net/minecraft/server/commands/CommandTeleport.patch b/paper-server/nms-patches/net/minecraft/server/commands/CommandTeleport.patch index c96cfba8e5..01612c03da 100644 --- a/paper-server/nms-patches/net/minecraft/server/commands/CommandTeleport.patch +++ b/paper-server/nms-patches/net/minecraft/server/commands/CommandTeleport.patch @@ -1,10 +1,11 @@ --- a/net/minecraft/server/commands/CommandTeleport.java +++ b/net/minecraft/server/commands/CommandTeleport.java -@@ -33,6 +33,13 @@ +@@ -31,6 +31,14 @@ import net.minecraft.world.phys.Vec2F; import net.minecraft.world.phys.Vec3D; +// CraftBukkit start ++import net.minecraft.server.level.EntityPlayer; +import org.bukkit.Location; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.event.entity.EntityTeleportEvent; @@ -14,35 +15,35 @@ public class CommandTeleport { private static final SimpleCommandExceptionType INVALID_POSITION = new SimpleCommandExceptionType(IChatBaseComponent.translatable("commands.teleport.invalidPosition")); -@@ -155,7 +162,30 @@ - float f2 = MathHelper.wrapDegrees(f); - float f3 = MathHelper.wrapDegrees(f1); +@@ -167,7 +175,30 @@ + float f4 = MathHelper.wrapDegrees(f2); + float f5 = MathHelper.wrapDegrees(f3); -- if (entity.teleportTo(worldserver, d0, d1, d2, set, f2, f3)) { +- if (entity.teleportTo(worldserver, d3, d4, d5, set, f4, f5, true)) { + // CraftBukkit start - Teleport event + boolean result; + if (entity instanceof EntityPlayer player) { -+ result = player.teleportTo(worldserver, d0, d1, d2, set, f2, f3, PlayerTeleportEvent.TeleportCause.COMMAND); ++ result = player.teleportTo(worldserver, d3, d4, d5, set, f4, f5, true, PlayerTeleportEvent.TeleportCause.COMMAND); + } else { -+ Location to = new Location(worldserver.getWorld(), d0, d1, d2, f2, f3); ++ Location to = new Location(worldserver.getWorld(), d3, d4, d5, f4, f5); + EntityTeleportEvent event = new EntityTeleportEvent(entity.getBukkitEntity(), entity.getBukkitEntity().getLocation(), to); + worldserver.getCraftServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return; + } + -+ d0 = to.getX(); -+ d1 = to.getY(); -+ d2 = to.getZ(); -+ f2 = to.getYaw(); -+ f3 = to.getPitch(); ++ d3 = to.getX(); ++ d4 = to.getY(); ++ d5 = to.getZ(); ++ f4 = to.getYaw(); ++ f5 = to.getPitch(); + worldserver = ((CraftWorld) to.getWorld()).getHandle(); + -+ result = entity.teleportTo(worldserver, d0, d1, d2, set, f2, f3); ++ result = entity.teleportTo(worldserver, d3, d4, d5, set, f4, f5, true); + } + + if (result) { + // CraftBukkit end - if (commandteleport_a != null) { - commandteleport_a.perform(commandlistenerwrapper, entity); + if (lookat != null) { + lookat.perform(commandlistenerwrapper, entity); } diff --git a/paper-server/nms-patches/net/minecraft/server/dedicated/DedicatedServer.patch b/paper-server/nms-patches/net/minecraft/server/dedicated/DedicatedServer.patch index 2113fa769b..2b0e239702 100644 --- a/paper-server/nms-patches/net/minecraft/server/dedicated/DedicatedServer.patch +++ b/paper-server/nms-patches/net/minecraft/server/dedicated/DedicatedServer.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/dedicated/DedicatedServer.java +++ b/net/minecraft/server/dedicated/DedicatedServer.java -@@ -60,6 +60,18 @@ +@@ -59,6 +59,18 @@ import net.minecraft.world.level.storage.Convertable; import org.slf4j.Logger; @@ -19,7 +19,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer { static final Logger LOGGER = LogUtils.getLogger(); -@@ -68,7 +80,7 @@ +@@ -67,7 +79,7 @@ private final List consoleInput = Collections.synchronizedList(Lists.newArrayList()); @Nullable private RemoteStatusListener queryThreadGs4; @@ -28,7 +28,7 @@ @Nullable private RemoteControlListener rconThread; public DedicatedServerSettings settings; -@@ -82,10 +94,12 @@ +@@ -81,10 +93,12 @@ private DebugSampleSubscriptionTracker debugSampleSubscriptionTracker; public ServerLinks serverLinks; @@ -41,10 +41,10 @@ this.settings = dedicatedserversettings; - this.rconConsoleSource = new RemoteControlCommandListener(this); + // this.rconConsoleSource = new RemoteControlCommandListener(this); // CraftBukkit - remove field - this.textFilterClient = TextFilter.createFromConfig(dedicatedserversettings.getProperties().textFilteringConfig); + this.serverTextFilter = ServerTextFilter.createFromConfig(dedicatedserversettings.getProperties()); this.serverLinks = createServerLinks(dedicatedserversettings); } -@@ -94,13 +108,44 @@ +@@ -93,13 +107,44 @@ public boolean initServer() throws IOException { Thread thread = new Thread("Server console handler") { public void run() { @@ -92,7 +92,7 @@ } } catch (IOException ioexception) { DedicatedServer.LOGGER.error("Exception handling console input", ioexception); -@@ -109,6 +154,29 @@ +@@ -108,6 +153,29 @@ } }; @@ -122,7 +122,7 @@ thread.setDaemon(true); thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(DedicatedServer.LOGGER)); thread.start(); -@@ -133,7 +201,7 @@ +@@ -132,7 +200,7 @@ this.setMotd(dedicatedserverproperties.motd); super.setPlayerIdleTimeout((Integer) dedicatedserverproperties.playerIdleTimeout.get()); this.setEnforceWhitelist(dedicatedserverproperties.enforceWhitelist); @@ -131,7 +131,7 @@ DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode); InetAddress inetaddress = null; -@@ -157,6 +225,12 @@ +@@ -156,6 +224,12 @@ return false; } @@ -144,7 +144,7 @@ if (!this.usesAuthentication()) { DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!"); DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware."); -@@ -171,7 +245,7 @@ +@@ -170,7 +244,7 @@ if (!NameReferencingFileConverter.serverReadyAfterUserconversion(this)) { return false; } else { @@ -153,7 +153,7 @@ this.debugSampleSubscriptionTracker = new DebugSampleSubscriptionTracker(this.getPlayerList()); this.tickTimeLogger = new RemoteSampleLogger(TpsDebugDimensions.values().length, this.debugSampleSubscriptionTracker, RemoteDebugSampleType.TICK_TIME); long i = SystemUtils.getNanos(); -@@ -179,13 +253,13 @@ +@@ -178,13 +252,13 @@ TileEntitySkull.setup(this.services, this); UserCache.setUsesAuthentication(this.usesAuthentication()); DedicatedServer.LOGGER.info("Preparing level \"{}\"", this.getLevelIdName()); @@ -169,7 +169,7 @@ } if (dedicatedserverproperties.enableQuery) { -@@ -311,6 +385,7 @@ +@@ -293,6 +367,7 @@ this.queryThreadGs4.stop(); } @@ -177,7 +177,7 @@ } @Override -@@ -332,7 +407,15 @@ +@@ -314,7 +389,15 @@ while (!this.consoleInput.isEmpty()) { ServerCommand servercommand = (ServerCommand) this.consoleInput.remove(0); @@ -194,7 +194,7 @@ } } -@@ -559,16 +642,52 @@ +@@ -541,16 +624,52 @@ @Override public String getPluginNames() { @@ -251,7 +251,7 @@ } public void storeUsingWhiteList(boolean flag) { -@@ -673,4 +792,15 @@ +@@ -660,4 +779,15 @@ } } } diff --git a/paper-server/nms-patches/net/minecraft/server/dedicated/DedicatedServerProperties.patch b/paper-server/nms-patches/net/minecraft/server/dedicated/DedicatedServerProperties.patch index b14bb65a3c..f46a8a100f 100644 --- a/paper-server/nms-patches/net/minecraft/server/dedicated/DedicatedServerProperties.patch +++ b/paper-server/nms-patches/net/minecraft/server/dedicated/DedicatedServerProperties.patch @@ -30,7 +30,7 @@ this.difficulty = (EnumDifficulty) this.get("difficulty", dispatchNumberOrString(EnumDifficulty::byId, EnumDifficulty::byName), EnumDifficulty::getKey, EnumDifficulty.EASY); this.gamemode = (EnumGamemode) this.get("gamemode", dispatchNumberOrString(EnumGamemode::byId, EnumGamemode::byName), EnumGamemode::getName, EnumGamemode.SURVIVAL); this.levelName = this.get("level-name", "world"); -@@ -165,13 +172,15 @@ +@@ -167,13 +174,15 @@ this.initialDataPackConfiguration = getDatapackConfig(this.get("initial-enabled-packs", String.join(",", WorldDataConfiguration.DEFAULT.dataPacks().getEnabled())), this.get("initial-disabled-packs", String.join(",", WorldDataConfiguration.DEFAULT.dataPacks().getDisabled()))); } @@ -50,7 +50,7 @@ } @Nullable -@@ -252,10 +261,10 @@ +@@ -254,10 +263,10 @@ }).orElseThrow(() -> { return new IllegalStateException("Invalid datapack contents: can't find default preset"); }); @@ -62,11 +62,11 @@ + return Optional.ofNullable(DedicatedServerProperties.WorldDimensionData.LEGACY_PRESET_NAMES.get(this.levelType)); // CraftBukkit - decompile error }); - Objects.requireNonNull(iregistry); -@@ -267,7 +276,7 @@ + Objects.requireNonNull(holderlookup); +@@ -269,7 +278,7 @@ if (holder.is(WorldPresets.FLAT)) { - RegistryOps registryops = iregistrycustom.createSerializationContext(JsonOps.INSTANCE); + RegistryOps registryops = holderlookup_a.createSerializationContext(JsonOps.INSTANCE); - DataResult dataresult = GeneratorSettingsFlat.CODEC.parse(new Dynamic(registryops, this.generatorSettings())); + DataResult dataresult = GeneratorSettingsFlat.CODEC.parse(new Dynamic(registryops, this.generatorSettings())); // CraftBukkit - decompile error Logger logger = DedicatedServerProperties.LOGGER; diff --git a/paper-server/nms-patches/net/minecraft/server/level/ChunkMapDistance.patch b/paper-server/nms-patches/net/minecraft/server/level/ChunkMapDistance.patch index bb9ae3fb47..8a42bd4dad 100644 --- a/paper-server/nms-patches/net/minecraft/server/level/ChunkMapDistance.patch +++ b/paper-server/nms-patches/net/minecraft/server/level/ChunkMapDistance.patch @@ -1,18 +1,22 @@ --- a/net/minecraft/server/level/ChunkMapDistance.java +++ b/net/minecraft/server/level/ChunkMapDistance.java -@@ -121,6 +121,11 @@ - } +@@ -117,6 +117,15 @@ + + PlayerChunk playerchunk; - if (!this.chunksToUpdateFutures.isEmpty()) { + // CraftBukkit start - SPIGOT-7780: Call chunk unload events before updateHighestAllowedStatus -+ this.chunksToUpdateFutures.forEach((playerchunk) -> { ++ while (iterator.hasNext()) { ++ playerchunk = (PlayerChunk) iterator.next(); + playerchunk.callEventIfUnloading(playerchunkmap); -+ }); ++ } ++ ++ iterator = this.chunksToUpdateFutures.iterator(); + // CraftBukkit end - this.chunksToUpdateFutures.forEach((playerchunk) -> { ++ + while (iterator.hasNext()) { + playerchunk = (PlayerChunk) iterator.next(); playerchunk.updateHighestAllowedStatus(playerchunkmap); - }); -@@ -163,7 +168,7 @@ +@@ -165,7 +174,7 @@ } } @@ -21,7 +25,7 @@ ArraySetSorted> arraysetsorted = this.getTickets(i); int j = getTicketLevelAt(arraysetsorted); Ticket ticket1 = (Ticket) arraysetsorted.addOrGet(ticket); -@@ -173,13 +178,15 @@ +@@ -175,13 +184,15 @@ this.ticketTracker.update(i, ticket.getTicketLevel(), true); } @@ -39,7 +43,7 @@ } if (arraysetsorted.isEmpty()) { -@@ -187,6 +194,7 @@ +@@ -189,6 +200,7 @@ } this.ticketTracker.update(i, getTicketLevelAt(arraysetsorted), false); @@ -47,7 +51,7 @@ } public void addTicket(TicketType tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) { -@@ -200,19 +208,33 @@ +@@ -202,19 +214,33 @@ } public void addRegionTicket(TicketType tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) { @@ -83,7 +87,7 @@ } private ArraySetSorted> getTickets(long i) { -@@ -251,6 +273,7 @@ +@@ -253,6 +279,7 @@ ChunkCoordIntPair chunkcoordintpair = sectionposition.chunk(); long i = chunkcoordintpair.toLong(); ObjectSet objectset = (ObjectSet) this.playersPerChunk.get(i); @@ -91,7 +95,7 @@ objectset.remove(entityplayer); if (objectset.isEmpty()) { -@@ -380,6 +403,26 @@ +@@ -391,6 +418,26 @@ return !this.tickets.isEmpty(); } diff --git a/paper-server/nms-patches/net/minecraft/server/level/ChunkProviderServer.patch b/paper-server/nms-patches/net/minecraft/server/level/ChunkProviderServer.patch index 18aed6e829..6d00dd684d 100644 --- a/paper-server/nms-patches/net/minecraft/server/level/ChunkProviderServer.patch +++ b/paper-server/nms-patches/net/minecraft/server/level/ChunkProviderServer.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/level/ChunkProviderServer.java +++ b/net/minecraft/server/level/ChunkProviderServer.java -@@ -82,6 +82,16 @@ +@@ -96,6 +96,16 @@ this.clearCache(); } @@ -17,7 +17,7 @@ @Override public LightEngineThreaded getLightEngine() { return this.lightEngine; -@@ -125,7 +135,7 @@ +@@ -139,7 +149,7 @@ if (k == this.lastChunkPos[l] && chunkstatus == this.lastChunkStatus[l]) { IChunkAccess ichunkaccess = this.lastChunk[l]; @@ -26,7 +26,7 @@ return ichunkaccess; } } -@@ -138,7 +148,7 @@ +@@ -152,7 +162,7 @@ Objects.requireNonNull(completablefuture); chunkproviderserver_b.managedBlock(completablefuture::isDone); ChunkResult chunkresult = (ChunkResult) completablefuture.join(); @@ -35,7 +35,7 @@ if (ichunkaccess1 == null && flag) { throw (IllegalStateException) SystemUtils.pauseInIde(new IllegalStateException("Chunk not there when requested: " + chunkresult.getError())); -@@ -218,7 +228,15 @@ +@@ -232,7 +242,15 @@ int l = ChunkLevel.byStatus(chunkstatus); PlayerChunk playerchunk = this.getVisibleChunkIfPresent(k); @@ -51,8 +51,8 @@ + // CraftBukkit end this.distanceManager.addTicket(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair); if (this.chunkAbsent(playerchunk, l)) { - GameProfilerFiller gameprofilerfiller = this.level.getProfiler(); -@@ -237,7 +255,7 @@ + GameProfilerFiller gameprofilerfiller = Profiler.get(); +@@ -251,7 +269,7 @@ } private boolean chunkAbsent(@Nullable PlayerChunk playerchunk, int i) { @@ -61,7 +61,7 @@ } @Override -@@ -292,11 +310,31 @@ +@@ -310,12 +328,34 @@ @Override public void close() throws IOException { @@ -75,40 +75,63 @@ + this.save(true); + } + // CraftBukkit end + this.dataStorage.close(); this.lightEngine.close(); this.chunkMap.close(); } + // CraftBukkit start - modelled on below + public void purgeUnload() { -+ this.level.getProfiler().push("purge"); ++ GameProfilerFiller gameprofilerfiller = Profiler.get(); ++ ++ gameprofilerfiller.push("purge"); + this.distanceManager.purgeStaleTickets(); + this.runDistanceManagerUpdates(); -+ this.level.getProfiler().popPush("unload"); ++ gameprofilerfiller.popPush("unload"); + this.chunkMap.tick(() -> true); -+ this.level.getProfiler().pop(); ++ gameprofilerfiller.pop(); + this.clearCache(); + } + // CraftBukkit end + @Override public void tick(BooleanSupplier booleansupplier, boolean flag) { - this.level.getProfiler().push("purge"); -@@ -346,11 +384,11 @@ + GameProfilerFiller gameprofilerfiller = Profiler.get(); +@@ -402,14 +442,14 @@ - this.lastSpawnState = spawnercreature_d; - gameprofilerfiller.popPush("spawnAndTick"); -- boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING); -+ boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit + this.lastSpawnState = spawnercreature_d; + gameprofilerfiller.popPush("spawnAndTick"); +- boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING); ++ boolean flag = this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING) && !this.level.players().isEmpty(); // CraftBukkit + int k = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING); + List list1; - SystemUtils.shuffle(list, this.level.random); - int l = this.level.getGameRules().getInt(GameRules.RULE_RANDOMTICKING); -- boolean flag1 = this.level.getLevelData().getGameTime() % 400L == 0L; -+ boolean flag1 = this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && this.level.getLevelData().getGameTime() % this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit - Iterator iterator1 = list.iterator(); + if (flag && (this.spawnEnemies || this.spawnFriendlies)) { +- boolean flag1 = this.level.getLevelData().getGameTime() % 400L == 0L; ++ boolean flag1 = this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) != 0L && this.level.getLevelData().getGameTime() % this.level.ticksPerSpawnCategory.getLong(org.bukkit.entity.SpawnCategory.ANIMAL) == 0L; // CraftBukkit - while (iterator1.hasNext()) { -@@ -560,13 +598,19 @@ +- list1 = SpawnerCreature.getFilteredSpawningCategories(spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1); ++ list1 = SpawnerCreature.getFilteredSpawningCategories(spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1, this.level); // CraftBukkit + } else { + list1 = List.of(); + } +@@ -542,8 +582,14 @@ + + @Override + public void setSpawnSettings(boolean flag) { ++ // CraftBukkit start ++ this.setSpawnSettings(flag, this.spawnFriendlies); ++ } ++ ++ public void setSpawnSettings(boolean flag, boolean spawnFriendlies) { + this.spawnEnemies = flag; +- this.spawnFriendlies = this.spawnFriendlies; ++ this.spawnFriendlies = spawnFriendlies; ++ // CraftBukkit end + } + + public String getChunkDebugData(ChunkCoordIntPair chunkcoordintpair) { +@@ -619,13 +665,19 @@ } @Override diff --git a/paper-server/nms-patches/net/minecraft/server/level/EntityPlayer.patch b/paper-server/nms-patches/net/minecraft/server/level/EntityPlayer.patch index f14d7ace30..d2126ebd73 100644 --- a/paper-server/nms-patches/net/minecraft/server/level/EntityPlayer.patch +++ b/paper-server/nms-patches/net/minecraft/server/level/EntityPlayer.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/level/EntityPlayer.java +++ b/net/minecraft/server/level/EntityPlayer.java -@@ -166,6 +166,40 @@ +@@ -184,6 +184,41 @@ import net.minecraft.world.scores.criteria.IScoreboardCriteria; import org.slf4j.Logger; @@ -15,6 +15,7 @@ +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.WeatherType; ++import org.bukkit.command.CommandSender; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.CraftWorldBorder; +import org.bukkit.craftbukkit.entity.CraftPlayer; @@ -28,20 +29,20 @@ +import org.bukkit.event.player.PlayerBedLeaveEvent; +import org.bukkit.event.player.PlayerChangedMainHandEvent; +import org.bukkit.event.player.PlayerChangedWorldEvent; ++import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerLocaleChangeEvent; +import org.bukkit.event.player.PlayerPortalEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerSpawnChangeEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -+import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.inventory.MainHand; +// CraftBukkit end + public class EntityPlayer extends EntityHuman { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -204,7 +238,7 @@ +@@ -227,7 +262,7 @@ private int levitationStartTime; private boolean disconnected; private int requestedViewDistance; @@ -50,7 +51,7 @@ @Nullable private Vec3D startingToFallPosition; @Nullable -@@ -235,6 +269,21 @@ +@@ -261,6 +296,22 @@ private int containerCounter; public boolean wonGame; @@ -58,6 +59,7 @@ + public CraftPlayer.TransferCookieConnection transferCookieConnection; + public String displayName; + public IChatBaseComponent listName; ++ public int listOrder = 0; + public org.bukkit.Location compassTarget; + public int newExp = 0; + public int newLevel = 0; @@ -72,7 +74,21 @@ public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, ClientInformation clientinformation) { super(worldserver, worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle(), gameprofile); this.chatVisibility = EnumChatVisibility.FULL; -@@ -302,14 +351,67 @@ +@@ -342,6 +393,13 @@ + public void sendSystemMessage(IChatBaseComponent ichatbasecomponent) { + EntityPlayer.this.sendSystemMessage(ichatbasecomponent); + } ++ ++ // CraftBukkit start ++ @Override ++ public CommandSender getBukkitSender(CommandListenerWrapper wrapper) { ++ return getBukkitEntity(); ++ } ++ // CraftBukkit end + }; + this.textFilter = minecraftserver.createTextFilterForPlayer(this); + this.gameMode = minecraftserver.createGameModeForPlayer(this); +@@ -354,14 +412,67 @@ this.moveTo(this.adjustSpawnLocation(worldserver, worldserver.getSharedSpawnPos()).getBottomCenter(), 0.0F, 0.0F); this.updateOptions(clientinformation); this.object = null; @@ -81,8 +97,8 @@ + this.displayName = this.getScoreboardName(); + this.bukkitPickUpLoot = true; + this.maxHealthCache = this.getMaxHealth(); - } - ++ } ++ + // Use method to resend items in hands in case of client desync, because the item use got cancelled. + // For example, when cancelling the leash event + public void resendItemInHands() { @@ -128,9 +144,9 @@ + } + + return blockposition; -+ } + } + // CraftBukkit end -+ + @Override public BlockPosition adjustSpawnLocation(WorldServer worldserver, BlockPosition blockposition) { AxisAlignedBB axisalignedbb = this.getDimensions(EntityPose.STANDING).makeBoundingBox(Vec3D.ZERO); @@ -141,7 +157,30 @@ int i = Math.max(0, this.server.getSpawnRadius(worldserver)); int j = MathHelper.floor(worldserver.getWorldBorder().getDistanceToBorder((double) blockposition.getX(), (double) blockposition.getZ())); -@@ -366,7 +468,7 @@ +@@ -397,14 +508,20 @@ + + Objects.requireNonNull(blockposition); + crashreportsystemdetails.setDetail("Origin", blockposition::toString); ++ // CraftBukkit start - decompile error ++ int finalI = i; + crashreportsystemdetails.setDetail("Radius", () -> { +- return Integer.toString(i); ++ return Integer.toString(finalI); ++ // CraftBukkit end + }); + crashreportsystemdetails.setDetail("Candidate", () -> { + return "[" + l2 + "," + i3 + "]"; + }); ++ // CraftBukkit start - decompile error ++ int finalL1 = l1; + crashreportsystemdetails.setDetail("Progress", () -> { +- return "" + l1 + " out of " + i1; ++ return "" + finalL1 + " out of " + i1; ++ // CraftBukkit end + }); + throw new ReportedException(crashreport); + } +@@ -442,7 +559,7 @@ dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("warden_spawn_tracker"))); logger = EntityPlayer.LOGGER; Objects.requireNonNull(logger); @@ -150,9 +189,9 @@ this.wardenSpawnTracker = wardenspawntracker; }); } -@@ -381,17 +483,26 @@ - if (nbttagcompound.contains("recipeBook", 10)) { - this.recipeBook.fromNbt(nbttagcompound.getCompound("recipeBook"), this.server.getRecipeManager()); +@@ -459,17 +576,26 @@ + return this.server.getRecipeManager().byKey(resourcekey).isPresent(); + }); } + this.getBukkitEntity().readExtraData(nbttagcompound); // CraftBukkit @@ -178,7 +217,7 @@ Logger logger1 = EntityPlayer.LOGGER; Objects.requireNonNull(logger1); -@@ -406,7 +517,7 @@ +@@ -484,7 +610,7 @@ dataresult = BlockPosition.CODEC.parse(DynamicOpsNBT.INSTANCE, nbtbase); logger = EntityPlayer.LOGGER; Objects.requireNonNull(logger); @@ -187,7 +226,7 @@ this.raidOmenPosition = blockposition; }); } -@@ -416,7 +527,7 @@ +@@ -494,7 +620,7 @@ @Override public void addAdditionalSaveData(NBTTagCompound nbttagcompound) { super.addAdditionalSaveData(nbttagcompound); @@ -196,7 +235,15 @@ Logger logger = EntityPlayer.LOGGER; Objects.requireNonNull(logger); -@@ -437,7 +548,20 @@ +@@ -528,6 +654,7 @@ + nbttagcompound.put("SpawnDimension", nbtbase); + }); + } ++ this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit + + nbttagcompound.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall); + if (this.raidOmenPosition != null) { +@@ -546,7 +673,20 @@ Entity entity = this.getRootVehicle(); Entity entity1 = this.getVehicle(); @@ -215,18 +262,43 @@ + + if (persistVehicle && entity1 != null && entity != this && entity.hasExactlyOnePlayerPassenger()) { + // CraftBukkit end + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); NBTTagCompound nbttagcompound2 = new NBTTagCompound(); - NBTTagCompound nbttagcompound3 = new NBTTagCompound(); -@@ -462,6 +586,7 @@ - nbttagcompound.put("SpawnDimension", nbtbase); - }); - } -+ this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit +@@ -600,12 +740,12 @@ - nbttagcompound.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall); - if (this.raidOmenPosition != null) { -@@ -475,6 +600,29 @@ + if (!this.isPassenger()) { + EntityPlayer.LOGGER.warn("Couldn't reattach entity to player"); +- entity.discard(); ++ entity.discard(null); // CraftBukkit - add Bukkit remove cause + iterator = entity.getIndirectPassengers().iterator(); + + while (iterator.hasNext()) { + entity1 = (Entity) iterator.next(); +- entity1.discard(); ++ entity1.discard(null); // CraftBukkit - add Bukkit remove cause + } + } + } +@@ -627,7 +767,7 @@ + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + + entityenderpearl.save(nbttagcompound1); +- DataResult dataresult = MinecraftKey.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, entityenderpearl.level().dimension().location()); ++ DataResult dataresult = MinecraftKey.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, entityenderpearl.level().dimension().location()); // CraftBukkit - decompile error + Logger logger = EntityPlayer.LOGGER; + + Objects.requireNonNull(logger); +@@ -653,7 +793,7 @@ + nbttaglist.forEach((nbtbase1) -> { + if (nbtbase1 instanceof NBTTagCompound nbttagcompound) { + if (nbttagcompound.contains("ender_pearl_dimension")) { +- DataResult dataresult = World.RESOURCE_KEY_CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("ender_pearl_dimension")); ++ DataResult> dataresult = World.RESOURCE_KEY_CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("ender_pearl_dimension")); // CraftBukkit - decompile error + Logger logger = EntityPlayer.LOGGER; + + Objects.requireNonNull(logger); +@@ -688,6 +828,29 @@ } @@ -256,7 +328,7 @@ public void setExperiencePoints(int i) { float f = (float) this.getXpNeededForNextLevel(); float f1 = (f - 1.0F) / f; -@@ -533,6 +681,11 @@ +@@ -746,6 +909,11 @@ @Override public void tick() { @@ -268,7 +340,7 @@ this.gameMode.tick(); this.wardenSpawnTracker.tick(); --this.spawnInvulnerableTime; -@@ -613,7 +766,7 @@ +@@ -822,7 +990,7 @@ } if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) { @@ -277,7 +349,7 @@ this.lastSentHealth = this.getHealth(); this.lastSentFood = this.foodData.getFoodLevel(); this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F; -@@ -644,6 +797,12 @@ +@@ -853,6 +1021,12 @@ this.updateScoreForCriteria(IScoreboardCriteria.EXPERIENCE, MathHelper.ceil((float) this.lastRecordedExperience)); } @@ -290,7 +362,7 @@ if (this.experienceLevel != this.lastRecordedLevel) { this.lastRecordedLevel = this.experienceLevel; this.updateScoreForCriteria(IScoreboardCriteria.LEVEL, MathHelper.ceil((float) this.lastRecordedLevel)); -@@ -658,6 +817,20 @@ +@@ -867,6 +1041,20 @@ CriterionTriggers.LOCATION.trigger(this); } @@ -311,7 +383,16 @@ } catch (Throwable throwable) { CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player"); CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Player being ticked"); -@@ -703,7 +876,8 @@ +@@ -895,7 +1083,7 @@ + if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL && this.serverLevel().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION)) { + if (this.tickCount % 20 == 0) { + if (this.getHealth() < this.getMaxHealth()) { +- this.heal(1.0F); ++ this.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN); // CraftBukkit - added regain reason of "REGEN" for filtering purposes. + } + + float f = this.foodData.getSaturationLevel(); +@@ -948,7 +1136,8 @@ } private void updateScoreForCriteria(IScoreboardCriteria iscoreboardcriteria, int i) { @@ -321,16 +402,16 @@ scoreaccess.set(i); }); } -@@ -712,9 +886,47 @@ +@@ -957,9 +1146,47 @@ public void die(DamageSource damagesource) { this.gameEvent(GameEvent.ENTITY_DIE); - boolean flag = this.level().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES); + boolean flag = this.serverLevel().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES); + // CraftBukkit start - fire PlayerDeathEvent + if (this.isRemoved()) { + return; + } + java.util.List loot = new java.util.ArrayList<>(this.getInventory().getContainerSize()); -+ boolean keepInventory = this.level().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || this.isSpectator(); ++ boolean keepInventory = this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || this.isSpectator(); - if (flag) { - IChatBaseComponent ichatbasecomponent = this.getCombatTracker().getDeathMessage(); @@ -342,7 +423,7 @@ + } + } + // SPIGOT-5071: manually add player loot tables (SPIGOT-5195 - ignores keepInventory rule) -+ this.dropFromLootTable(damagesource, this.lastHurtByPlayerTime > 0); ++ this.dropFromLootTable(this.serverLevel(), damagesource, this.lastHurtByPlayerTime > 0); + this.dropCustomDeathLoot(this.serverLevel(), damagesource, flag); + + loot.addAll(this.drops); @@ -371,15 +452,15 @@ this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> { boolean flag1 = true; -@@ -745,12 +957,18 @@ - if (this.level().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) { +@@ -990,12 +1217,18 @@ + if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) { this.tellNeutralMobsThatIDied(); } - - if (!this.isSpectator()) { - this.dropAllDeathLoot(this.serverLevel(), damagesource); + // SPIGOT-5478 must be called manually now -+ this.dropExperience(damagesource.getEntity()); ++ this.dropExperience(this.serverLevel(), damagesource.getEntity()); + // we clean the player's inventory after the EntityDeathEvent is called so plugins can get the exact state of the inventory. + if (!event.getKeepInventory()) { + this.getInventory().clearContent(); @@ -394,7 +475,7 @@ EntityLiving entityliving = this.getKillCredit(); if (entityliving != null) { -@@ -785,10 +1003,12 @@ +@@ -1030,10 +1263,12 @@ if (entity != this) { super.awardKillScore(entity, i, damagesource); this.increaseScore(i); @@ -409,7 +490,7 @@ } else { this.awardStat(StatisticList.MOB_KILLS); } -@@ -806,7 +1026,8 @@ +@@ -1051,7 +1286,8 @@ int i = scoreboardteam.getColor().getId(); if (i >= 0 && i < aiscoreboardcriteria.length) { @@ -419,7 +500,7 @@ } } -@@ -856,10 +1077,16 @@ +@@ -1101,10 +1337,16 @@ } private boolean isPvpAllowed() { @@ -428,53 +509,53 @@ + return this.level().pvpMode; } -- public DimensionTransition findRespawnPositionAndUseSpawnBlock(boolean flag, DimensionTransition.a dimensiontransition_a) { +- public TeleportTransition findRespawnPositionAndUseSpawnBlock(boolean flag, TeleportTransition.a teleporttransition_a) { + // CraftBukkit start -+ public DimensionTransition findRespawnPositionAndUseSpawnBlock(boolean flag, DimensionTransition.a dimensiontransition_a, PlayerRespawnEvent.RespawnReason reason) { -+ DimensionTransition dimensionTransition; ++ public TeleportTransition findRespawnPositionAndUseSpawnBlock(boolean flag, TeleportTransition.a teleporttransition_a, PlayerRespawnEvent.RespawnReason reason) { ++ TeleportTransition teleportTransition; + boolean isBedSpawn = false; + boolean isAnchorSpawn = false; + // CraftBukkit end BlockPosition blockposition = this.getRespawnPosition(); float f = this.getRespawnAngle(); boolean flag1 = this.isRespawnForced(); -@@ -871,13 +1098,32 @@ +@@ -1116,13 +1358,32 @@ if (optional.isPresent()) { EntityPlayer.RespawnPosAngle entityplayer_respawnposangle = (EntityPlayer.RespawnPosAngle) optional.get(); -- return new DimensionTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, dimensiontransition_a); +- return new TeleportTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, teleporttransition_a); + // CraftBukkit start + isBedSpawn = entityplayer_respawnposangle.isBedSpawn(); + isAnchorSpawn = entityplayer_respawnposangle.isAnchorSpawn(); -+ dimensionTransition = new DimensionTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, dimensiontransition_a); ++ teleportTransition = new TeleportTransition(worldserver, entityplayer_respawnposangle.position(), Vec3D.ZERO, entityplayer_respawnposangle.yaw(), 0.0F, teleporttransition_a); + // CraftBukkit end } else { -- return DimensionTransition.missingRespawnBlock(this.server.overworld(), this, dimensiontransition_a); -+ dimensionTransition = DimensionTransition.missingRespawnBlock(this.server.overworld(), this, dimensiontransition_a); // CraftBukkit +- return TeleportTransition.missingRespawnBlock(this.server.overworld(), this, teleporttransition_a); ++ teleportTransition = TeleportTransition.missingRespawnBlock(this.server.overworld(), this, teleporttransition_a); // CraftBukkit } } else { -- return new DimensionTransition(this.server.overworld(), this, dimensiontransition_a); -+ dimensionTransition = new DimensionTransition(this.server.overworld(), this, dimensiontransition_a); // CraftBukkit +- return new TeleportTransition(this.server.overworld(), this, teleporttransition_a); ++ teleportTransition = new TeleportTransition(this.server.overworld(), this, teleporttransition_a); // CraftBukkit } + // CraftBukkit start + if (reason == null) { -+ return dimensionTransition; ++ return teleportTransition; + } + + Player respawnPlayer = this.getBukkitEntity(); -+ Location location = CraftLocation.toBukkit(dimensionTransition.pos(), dimensionTransition.newLevel().getWorld(), dimensionTransition.yRot(), dimensionTransition.xRot()); ++ Location location = CraftLocation.toBukkit(teleportTransition.position(), teleportTransition.newLevel().getWorld(), teleportTransition.yRot(), teleportTransition.xRot()); + + PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn, isAnchorSpawn, reason); + this.level().getCraftServer().getPluginManager().callEvent(respawnEvent); + + location = respawnEvent.getRespawnLocation(); + -+ return new DimensionTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), dimensionTransition.speed(), location.getYaw(), location.getPitch(), dimensionTransition.missingRespawnBlock(), dimensionTransition.postDimensionTransition(), dimensionTransition.cause()); ++ return new TeleportTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), teleportTransition.deltaMovement(), location.getYaw(), location.getPitch(), teleportTransition.missingRespawnBlock(), teleportTransition.asPassenger(), teleportTransition.relatives(), teleportTransition.postTeleportTransition(), teleportTransition.cause()); + // CraftBukkit end } public static Optional findRespawnAndUseSpawnBlock(WorldServer worldserver, BlockPosition blockposition, float f, boolean flag, boolean flag1) { -@@ -892,11 +1138,11 @@ +@@ -1137,11 +1398,11 @@ } return optional.map((vec3d) -> { @@ -488,7 +569,7 @@ }); } else if (!flag) { return Optional.empty(); -@@ -905,7 +1151,7 @@ +@@ -1150,7 +1411,7 @@ IBlockData iblockdata1 = worldserver.getBlockState(blockposition.above()); boolean flag3 = iblockdata1.getBlock().isPossibleToRespawnInThis(iblockdata1); @@ -497,32 +578,49 @@ } } -@@ -923,6 +1169,7 @@ +@@ -1168,6 +1429,7 @@ @Nullable @Override - public Entity changeDimension(DimensionTransition dimensiontransition) { + public EntityPlayer teleport(TeleportTransition teleporttransition) { + if (this.isSleeping()) return null; // CraftBukkit - SPIGOT-3154 if (this.isRemoved()) { return null; } else { -@@ -932,14 +1179,21 @@ +@@ -1177,18 +1439,38 @@ - WorldServer worldserver = dimensiontransition.newLevel(); + WorldServer worldserver = teleporttransition.newLevel(); WorldServer worldserver1 = this.serverLevel(); - ResourceKey resourcekey = worldserver1.dimension(); + // CraftBukkit start + ResourceKey resourcekey = worldserver1.getTypeKey(); ++ ++ Location enter = this.getBukkitEntity().getLocation(); ++ PositionMoveRotation absolutePosition = PositionMoveRotation.calculateAbsolute(PositionMoveRotation.of(this), PositionMoveRotation.of(teleporttransition), teleporttransition.relatives()); ++ Location exit = (worldserver == null) ? null : CraftLocation.toBukkit(absolutePosition.position(), worldserver.getWorld(), absolutePosition.yRot(), absolutePosition.xRot()); ++ PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.getBukkitEntity(), enter, exit, teleporttransition.cause()); ++ Bukkit.getServer().getPluginManager().callEvent(tpEvent); ++ Location newExit = tpEvent.getTo(); ++ if (tpEvent.isCancelled() || newExit == null) { ++ return null; ++ } ++ if (!newExit.equals(exit)) { ++ worldserver = ((CraftWorld) newExit.getWorld()).getHandle(); ++ teleporttransition = new TeleportTransition(worldserver, CraftLocation.toVec3D(newExit), Vec3D.ZERO, newExit.getYaw(), newExit.getPitch(), teleporttransition.missingRespawnBlock(), teleporttransition.asPassenger(), Set.of(), teleporttransition.postTeleportTransition(), teleporttransition.cause()); ++ } ++ // CraftBukkit end + + if (!teleporttransition.asPassenger()) { + this.stopRiding(); + } - if (worldserver.dimension() == resourcekey) { -- this.connection.teleport(dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), dimensiontransition.xRot()); -+ if (worldserver != null && worldserver.dimension() == worldserver1.dimension()) { // CraftBukkit -+ boolean result = this.connection.teleport(dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), dimensiontransition.xRot(), dimensiontransition.cause()); -+ if (!result) { -+ return null; -+ } +- this.connection.teleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives()); ++ // CraftBukkit start ++ if (worldserver != null && worldserver.dimension() == worldserver1.dimension()) { ++ this.connection.internalTeleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives()); + // CraftBukkit end this.connection.resetPosition(); - dimensiontransition.postDimensionTransition().onTransition(this); + teleporttransition.postTeleportTransition().onTransition(this); return this; } else { + // CraftBukkit start @@ -530,31 +628,22 @@ this.isChangingDimension = true; WorldData worlddata = worldserver.getLevelData(); -@@ -950,15 +1204,40 @@ +@@ -1199,17 +1481,31 @@ playerlist.sendPlayerPermissionLevel(this); worldserver1.removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION); this.unsetRemoved(); + */ + // CraftBukkit end - worldserver1.getProfiler().push("moving"); + GameProfilerFiller gameprofilerfiller = Profiler.get(); + + gameprofilerfiller.push("moving"); - if (resourcekey == World.OVERWORLD && worldserver.dimension() == World.NETHER) { + if (worldserver != null && resourcekey == WorldDimension.OVERWORLD && worldserver.getTypeKey() == WorldDimension.NETHER) { // CraftBukkit - empty to fall through to null to event this.enteredNetherPosition = this.position(); } -+ // CraftBukkit start -+ Location enter = this.getBukkitEntity().getLocation(); -+ Location exit = (worldserver == null) ? null : CraftLocation.toBukkit(dimensiontransition.pos(), worldserver.getWorld(), dimensiontransition.yRot(), dimensiontransition.xRot()); -+ PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.getBukkitEntity(), enter, exit, dimensiontransition.cause()); -+ Bukkit.getServer().getPluginManager().callEvent(tpEvent); -+ if (tpEvent.isCancelled() || tpEvent.getTo() == null) { -+ return null; -+ } -+ exit = tpEvent.getTo(); -+ worldserver = ((CraftWorld) exit.getWorld()).getHandle(); -+ // CraftBukkit end - worldserver1.getProfiler().pop(); - worldserver1.getProfiler().push("placing"); + gameprofilerfiller.pop(); + gameprofilerfiller.push("placing"); + // CraftBukkit start + this.isChangingDimension = true; // CraftBukkit - Set teleport invulnerability only if player changing worlds + WorldData worlddata = worldserver.getLevelData(); @@ -568,12 +657,12 @@ + this.unsetRemoved(); + // CraftBukkit end this.setServerLevel(worldserver); -- this.connection.teleport(dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), dimensiontransition.xRot()); -+ this.connection.teleport(exit); // CraftBukkit - use internal teleport without event +- this.connection.teleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives()); ++ this.connection.internalTeleport(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives()); // CraftBukkit - use internal teleport without event this.connection.resetPosition(); worldserver.addDuringTeleport(this); - worldserver1.getProfiler().pop(); -@@ -971,21 +1250,47 @@ + gameprofilerfiller.pop(); +@@ -1223,11 +1519,29 @@ this.lastSentExp = -1; this.lastSentHealth = -1.0F; this.lastSentFood = -1; @@ -600,6 +689,10 @@ + } + // CraftBukkit end + + @Override + public void forceSetRotation(float f, float f1) { + this.connection.send(new ClientboundPlayerRotationPacket(f, f1)); +@@ -1236,13 +1550,21 @@ public void triggerDimensionChangeTriggers(WorldServer worldserver) { ResourceKey resourcekey = worldserver.dimension(); ResourceKey resourcekey1 = this.level().dimension(); @@ -624,7 +717,7 @@ this.enteredNetherPosition = null; } -@@ -1002,19 +1307,17 @@ +@@ -1259,19 +1581,17 @@ this.containerMenu.broadcastChanges(); } @@ -648,7 +741,7 @@ if (this.level().isDay()) { return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_NOW); } else { -@@ -1031,7 +1334,36 @@ +@@ -1288,7 +1608,36 @@ } } @@ -686,7 +779,7 @@ this.awardStat(StatisticList.SLEEP_IN_BED); CriterionTriggers.SLEPT_IN_BED.trigger(this); }); -@@ -1044,9 +1376,8 @@ +@@ -1301,9 +1650,8 @@ return either; } } @@ -697,7 +790,7 @@ } @Override -@@ -1073,13 +1404,31 @@ +@@ -1330,13 +1678,31 @@ @Override public void stopSleepInBed(boolean flag, boolean flag1) { @@ -730,7 +823,7 @@ } } -@@ -1146,8 +1495,9 @@ +@@ -1403,8 +1769,9 @@ this.connection.send(new PacketPlayOutOpenSignEditor(tileentitysign.getBlockPos(), flag)); } @@ -741,7 +834,7 @@ } @Override -@@ -1155,13 +1505,35 @@ +@@ -1412,13 +1779,35 @@ if (itileinventory == null) { return OptionalInt.empty(); } else { @@ -777,7 +870,7 @@ if (container == null) { if (this.isSpectator()) { this.displayClientMessage(IChatBaseComponent.translatable("container.spectatorCantOpen").withStyle(EnumChatFormat.RED), true); -@@ -1169,9 +1541,11 @@ +@@ -1426,9 +1815,11 @@ return OptionalInt.empty(); } else { @@ -791,7 +884,7 @@ return OptionalInt.of(this.containerCounter); } } -@@ -1184,15 +1558,26 @@ +@@ -1441,15 +1832,26 @@ @Override public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) { @@ -820,7 +913,7 @@ this.initMenu(this.containerMenu); } -@@ -1215,6 +1600,7 @@ +@@ -1472,6 +1874,7 @@ @Override public void closeContainer() { @@ -828,24 +921,7 @@ this.connection.send(new PacketPlayOutCloseWindow(this.containerMenu.containerId)); this.doCloseContainer(); } -@@ -1237,6 +1623,16 @@ - } - - this.jumping = flag; -+ // CraftBukkit start -+ if (flag1 != this.isShiftKeyDown()) { -+ PlayerToggleSneakEvent event = new PlayerToggleSneakEvent(this.getBukkitEntity(), flag1); -+ this.server.server.getPluginManager().callEvent(event); -+ -+ if (event.isCancelled()) { -+ return; -+ } -+ } -+ // CraftBukkit end - this.setShiftKeyDown(flag1); - } - -@@ -1270,19 +1666,19 @@ +@@ -1501,19 +1904,19 @@ i = Math.round((float) Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2) * 100.0F); if (i > 0) { this.awardStat(StatisticList.SWIM_ONE_CM, i); @@ -868,7 +944,7 @@ } } else if (this.onClimbable()) { if (d1 > 0.0D) { -@@ -1293,13 +1689,13 @@ +@@ -1524,13 +1927,13 @@ if (i > 0) { if (this.isSprinting()) { this.awardStat(StatisticList.SPRINT_ONE_CM, i); @@ -885,7 +961,7 @@ } } } else if (this.isFallFlying()) { -@@ -1342,7 +1738,7 @@ +@@ -1573,7 +1976,7 @@ @Override public void awardStat(Statistic statistic, int i) { this.stats.increment(this, statistic, i); @@ -894,7 +970,7 @@ scoreaccess.add(i); }); } -@@ -1350,7 +1746,7 @@ +@@ -1581,7 +1984,7 @@ @Override public void resetStat(Statistic statistic) { this.stats.setValue(this, statistic, 0); @@ -903,7 +979,19 @@ } @Override -@@ -1398,6 +1794,7 @@ +@@ -1613,9 +2016,9 @@ + super.jumpFromGround(); + this.awardStat(StatisticList.JUMP); + if (this.isSprinting()) { +- this.causeFoodExhaustion(0.2F); ++ this.causeFoodExhaustion(0.2F, EntityExhaustionEvent.ExhaustionReason.JUMP_SPRINT); // CraftBukkit - EntityExhaustionEvent + } else { +- this.causeFoodExhaustion(0.05F); ++ this.causeFoodExhaustion(0.05F, EntityExhaustionEvent.ExhaustionReason.JUMP); // CraftBukkit - EntityExhaustionEvent + } + + } +@@ -1641,6 +2044,7 @@ public void resetSentInfo() { this.lastSentHealth = -1.0E8F; @@ -911,16 +999,7 @@ } @Override -@@ -1433,7 +1830,7 @@ - this.gameMode.setGameModeForPlayer(entityplayer.gameMode.getGameModeForPlayer(), entityplayer.gameMode.getPreviousGameModeForPlayer()); - this.onUpdateAbilities(); - this.getAttributes().assignBaseValues(entityplayer.getAttributes()); -- this.setHealth(this.getMaxHealth()); -+ // this.setHealth(this.getMaxHealth()); // CraftBukkit - if (flag) { - this.getInventory().replaceWith(entityplayer.getInventory()); - this.setHealth(entityplayer.getHealth()); -@@ -1443,7 +1840,7 @@ +@@ -1685,7 +2089,7 @@ while (iterator.hasNext()) { MobEffect mobeffect = (MobEffect) iterator.next(); @@ -928,8 +1007,17 @@ + // this.addEffect(new MobEffect(mobeffect)); // CraftBukkit } - this.experienceLevel = entityplayer.experienceLevel; -@@ -1465,7 +1862,7 @@ + this.getInventory().replaceWith(entityplayer.getInventory()); +@@ -1696,7 +2100,7 @@ + this.portalProcess = entityplayer.portalProcess; + } else { + this.getAttributes().assignBaseValues(entityplayer.getAttributes()); +- this.setHealth(this.getMaxHealth()); ++ // this.setHealth(this.getMaxHealth()); // CraftBukkit + if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || entityplayer.isSpectator()) { + this.getInventory().replaceWith(entityplayer.getInventory()); + this.experienceLevel = entityplayer.experienceLevel; +@@ -1712,7 +2116,7 @@ this.lastSentExp = -1; this.lastSentHealth = -1.0F; this.lastSentFood = -1; @@ -938,32 +1026,25 @@ this.seenCredits = entityplayer.seenCredits; this.enteredNetherPosition = entityplayer.enteredNetherPosition; this.chunkTrackingView = entityplayer.chunkTrackingView; -@@ -1516,6 +1913,12 @@ +@@ -1768,7 +2172,7 @@ + } @Override - public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1) { -+ // CraftBukkit start -+ return teleportTo(worldserver, d0, d1, d2, set, f, f1, TeleportCause.UNKNOWN); -+ } -+ -+ public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1, TeleportCause cause) { -+ // CraftBukkit end +- public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1, boolean flag) { ++ public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1, boolean flag, TeleportCause cause) { // CraftBukkit ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(BlockPosition.containing(d0, d1, d2)); worldserver.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkcoordintpair, 1, this.getId()); -@@ -1525,9 +1928,9 @@ +@@ -1780,7 +2184,7 @@ + this.setCamera(this); } - if (worldserver == this.level()) { -- this.connection.teleport(d0, d1, d2, f, f1, set); -+ this.connection.teleport(d0, d1, d2, f, f1, set, cause); // CraftBukkit - } else { -- this.teleportTo(worldserver, d0, d1, d2, f, f1); -+ this.teleportTo(worldserver, d0, d1, d2, f, f1, cause); // CraftBukkit - } +- boolean flag1 = super.teleportTo(worldserver, d0, d1, d2, set, f, f1, flag); ++ boolean flag1 = super.teleportTo(worldserver, d0, d1, d2, set, f, f1, flag, cause); // CraftBukkit - this.setYHeadRot(f); -@@ -1635,6 +2038,16 @@ + if (flag1) { + this.setYHeadRot(set.contains(Relative.Y_ROT) ? this.getYHeadRot() + f : f); +@@ -1897,6 +2301,16 @@ } public void updateOptions(ClientInformation clientinformation) { @@ -980,16 +1061,16 @@ this.language = clientinformation.language(); this.requestedViewDistance = clientinformation.viewDistance(); this.chatVisibility = clientinformation.chatVisibility(); -@@ -1718,7 +2131,7 @@ +@@ -1981,7 +2395,7 @@ if (world instanceof WorldServer) { WorldServer worldserver = (WorldServer) world; -- this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot()); -+ this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot(), TeleportCause.SPECTATE); // CraftBukkit +- this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot(), false); ++ this.teleportTo(worldserver, this.camera.getX(), this.camera.getY(), this.camera.getZ(), Set.of(), this.getYRot(), this.getXRot(), false, TeleportCause.SPECTATE); // CraftBukkit } if (entity != null) { -@@ -1755,7 +2168,7 @@ +@@ -2018,11 +2432,11 @@ @Nullable public IChatBaseComponent getTabListDisplayName() { @@ -997,33 +1078,13 @@ + return listName; // CraftBukkit } + public int getTabListOrder() { +- return 0; ++ return listOrder; // CraftBukkit + } + @Override -@@ -1776,14 +2189,24 @@ - return this.advancements; - } - -+ // CraftBukkit start - public void teleportTo(WorldServer worldserver, double d0, double d1, double d2, float f, float f1) { -+ this.teleportTo(worldserver, d0, d1, d2, f, f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.UNKNOWN); -+ } -+ -+ public void teleportTo(WorldServer worldserver, double d0, double d1, double d2, float f, float f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) { -+ // CraftBukkit end - this.setCamera(this); - this.stopRiding(); -+ /* CraftBukkit start - replace with bukkit handling for multi-world - if (worldserver == this.level()) { - this.connection.teleport(d0, d1, d2, f, f1); - } else { - this.changeDimension(new DimensionTransition(worldserver, new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f1, DimensionTransition.DO_NOTHING)); - } -+ */ -+ this.getBukkitEntity().teleport(new Location(worldserver.getWorld(), d0, d1, d2, f, f1), cause); -+ // CraftBukkit end - - } - -@@ -1809,6 +2232,32 @@ +@@ -2065,6 +2479,32 @@ } public void setRespawnPosition(ResourceKey resourcekey, @Nullable BlockPosition blockposition, float f, boolean flag, boolean flag1) { @@ -1056,24 +1117,48 @@ if (blockposition != null) { boolean flag2 = blockposition.equals(this.respawnPosition) && resourcekey.equals(this.respawnDimension); -@@ -1852,7 +2301,14 @@ +@@ -2107,12 +2547,38 @@ + } @Override - public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) { -- EntityItem entityitem = super.drop(itemstack, flag, flag1); -+ // CraftBukkit start - SPIGOT-2942: Add boolean to call event -+ return drop(itemstack, flag, flag1, true); -+ } -+ -+ @Override -+ public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1, boolean callEvent) { -+ EntityItem entityitem = super.drop(itemstack, flag, flag1, callEvent); -+ // CraftBukkit end +- public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) { ++ public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1, boolean callEvent) { // CraftBukkit - SPIGOT-2942: Add boolean to call event + EntityItem entityitem = this.createItemStackToDrop(itemstack, flag, flag1); if (entityitem == null) { return null; -@@ -2049,10 +2505,12 @@ - this.awardStat(StatisticList.ITEM_BROKEN.get(item)); + } else { ++ // CraftBukkit start - fire PlayerDropItemEvent ++ if (callEvent) { ++ Player player = (Player) this.getBukkitEntity(); ++ org.bukkit.entity.Item drop = (org.bukkit.entity.Item) entityitem.getBukkitEntity(); ++ ++ PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop); ++ this.level().getCraftServer().getPluginManager().callEvent(event); ++ ++ if (event.isCancelled()) { ++ org.bukkit.inventory.ItemStack cur = player.getInventory().getItemInHand(); ++ if (flag1 && (cur == null || cur.getAmount() == 0)) { ++ // The complete stack was dropped ++ player.getInventory().setItemInHand(drop.getItemStack()); ++ } else if (flag1 && cur.isSimilar(drop.getItemStack()) && cur.getAmount() < cur.getMaxStackSize() && drop.getItemStack().getAmount() == 1) { ++ // Only one item is dropped ++ cur.setAmount(cur.getAmount() + 1); ++ player.getInventory().setItemInHand(cur); ++ } else { ++ // Fallback ++ player.getInventory().addItem(drop.getItemStack()); ++ } ++ return null; ++ } ++ } ++ // CraftBukkit end ++ + this.level().addFreshEntity(entityitem); + ItemStack itemstack1 = entityitem.getItem(); + +@@ -2394,10 +2860,12 @@ + return TicketType.ENDER_PEARL.timeout(); } - public static record RespawnPosAngle(Vec3D position, float yaw) { @@ -1088,7 +1173,7 @@ } private static float calculateLookAtYaw(Vec3D vec3d, BlockPosition blockposition) { -@@ -2061,4 +2519,147 @@ +@@ -2406,4 +2874,146 @@ return (float) MathHelper.wrapDegrees(MathHelper.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D); } } @@ -1195,7 +1280,6 @@ + + public void reset() { + float exp = 0; -+ boolean keepInventory = this.level().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY); + + if (this.keepLevel) { // CraftBukkit - SPIGOT-6687: Only use keepLevel (was pre-set with RULE_KEEPINVENTORY value in PlayerDeathEvent) + exp = this.experienceProgress; @@ -1207,7 +1291,7 @@ + this.stopUsingItem(); // CraftBukkit - SPIGOT-6682: Clear active item on reset + this.setRemainingFireTicks(0); + this.fallDistance = 0; -+ this.foodData = new FoodMetaData(this); ++ this.foodData = new FoodMetaData(); + this.experienceLevel = this.newLevel; + this.totalExperience = this.newTotalExp; + this.experienceProgress = 0; diff --git a/paper-server/nms-patches/net/minecraft/server/level/EntityTrackerEntry.patch b/paper-server/nms-patches/net/minecraft/server/level/EntityTrackerEntry.patch index f8ac888b35..1e4584f0ea 100644 --- a/paper-server/nms-patches/net/minecraft/server/level/EntityTrackerEntry.patch +++ b/paper-server/nms-patches/net/minecraft/server/level/EntityTrackerEntry.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/level/EntityTrackerEntry.java +++ b/net/minecraft/server/level/EntityTrackerEntry.java -@@ -46,6 +46,12 @@ +@@ -50,6 +50,12 @@ import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; @@ -13,7 +13,7 @@ public class EntityTrackerEntry { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -70,8 +76,12 @@ +@@ -74,8 +80,12 @@ private boolean wasOnGround; @Nullable private List> trackedDataValues; @@ -27,7 +27,7 @@ this.level = worldserver; this.broadcast = consumer; this.entity = entity; -@@ -90,7 +100,7 @@ +@@ -94,7 +104,7 @@ List list = this.entity.getPassengers(); if (!list.equals(this.lastPassengers)) { @@ -36,7 +36,7 @@ removedPassengers(list, this.lastPassengers).forEach((entity) -> { if (entity instanceof EntityPlayer entityplayer) { entityplayer.connection.teleport(entityplayer.getX(), entityplayer.getY(), entityplayer.getZ(), entityplayer.getYRot(), entityplayer.getXRot()); -@@ -103,18 +113,18 @@ +@@ -107,18 +117,18 @@ Entity entity = this.entity; if (entity instanceof EntityItemFrame entityitemframe) { @@ -59,7 +59,7 @@ worldmap.tickCarriedBy(entityplayer, itemstack); Packet packet = worldmap.getUpdatePacket(mapid, entityplayer); -@@ -232,6 +242,27 @@ +@@ -248,6 +258,27 @@ ++this.tickCount; if (this.entity.hurtMarked) { @@ -87,7 +87,7 @@ this.entity.hurtMarked = false; this.broadcastAndSend(new PacketPlayOutEntityVelocity(this.entity)); } -@@ -260,7 +291,10 @@ +@@ -298,7 +329,10 @@ public void sendPairingData(EntityPlayer entityplayer, Consumer> consumer) { if (this.entity.isRemoved()) { @@ -99,7 +99,7 @@ } Packet packet = this.entity.getAddEntityPacket(this); -@@ -275,6 +309,12 @@ +@@ -313,6 +347,12 @@ if (this.entity instanceof EntityLiving) { Collection collection = ((EntityLiving) this.entity).getAttributes().getSyncableAttributes(); @@ -112,7 +112,7 @@ if (!collection.isEmpty()) { consumer.accept(new PacketPlayOutUpdateAttributes(this.entity.getId(), collection)); } -@@ -305,6 +345,7 @@ +@@ -344,6 +384,7 @@ if (!list.isEmpty()) { consumer.accept(new PacketPlayOutEntityEquipment(this.entity.getId(), list)); } @@ -120,7 +120,7 @@ } if (!this.entity.getPassengers().isEmpty()) { -@@ -358,6 +399,11 @@ +@@ -396,6 +437,11 @@ Set set = ((EntityLiving) this.entity).getAttributes().getAttributesToSync(); if (!set.isEmpty()) { diff --git a/paper-server/nms-patches/net/minecraft/server/level/PlayerChunk.patch b/paper-server/nms-patches/net/minecraft/server/level/PlayerChunk.patch index fa19b6b41a..8cdc550802 100644 --- a/paper-server/nms-patches/net/minecraft/server/level/PlayerChunk.patch +++ b/paper-server/nms-patches/net/minecraft/server/level/PlayerChunk.patch @@ -52,15 +52,15 @@ } @Nullable -@@ -134,6 +150,7 @@ - if (chunk != null) { +@@ -138,6 +154,7 @@ + boolean flag = this.hasChangedSections; int i = this.levelHeightAccessor.getSectionIndex(blockposition.getY()); -+ if (i < 0 || i >= this.changedBlocksPerSection.length) return; // CraftBukkit - SPIGOT-6086, SPIGOT-6296 ++ if (i < 0 || i >= this.changedBlocksPerSection.length) return false; // CraftBukkit - SPIGOT-6086, SPIGOT-6296 if (this.changedBlocksPerSection[i] == null) { this.hasChangedSections = true; this.changedBlocksPerSection[i] = new ShortOpenHashSet(); -@@ -208,8 +225,11 @@ +@@ -224,8 +241,11 @@ PacketPlayOutMultiBlockChange packetplayoutmultiblockchange = new PacketPlayOutMultiBlockChange(sectionposition, shortset, chunksection); this.broadcast(list, packetplayoutmultiblockchange); @@ -73,7 +73,7 @@ }); } } -@@ -275,7 +295,7 @@ +@@ -291,7 +311,7 @@ this.pendingFullStateConfirmation = completablefuture1; completablefuture.thenAccept((chunkresult) -> { chunkresult.ifSuccess((chunk) -> { @@ -82,7 +82,7 @@ }); }); } -@@ -285,6 +305,38 @@ +@@ -301,6 +321,38 @@ playerchunkmap.onFullChunkStatusChange(this.pos, fullchunkstatus); } @@ -102,7 +102,7 @@ + // Minecraft will apply the chunks tick lists to the world once the chunk got loaded, and then store the tick + // lists again inside the chunk once the chunk becomes inaccessible and set the chunk's needsSaving flag. + // These actions may however happen deferred, so we manually set the needsSaving flag already here. -+ chunk.setUnsaved(true); ++ chunk.markUnsaved(); + chunk.unloadCallback(); + }); + } @@ -121,7 +121,7 @@ protected void updateFutures(PlayerChunkMap playerchunkmap, Executor executor) { FullChunkStatus fullchunkstatus = ChunkLevel.fullStatus(this.oldTicketLevel); FullChunkStatus fullchunkstatus1 = ChunkLevel.fullStatus(this.ticketLevel); -@@ -341,6 +393,26 @@ +@@ -357,6 +409,26 @@ this.onLevelChange.onLevelChange(this.pos, this::getQueueLevel, this.ticketLevel, this::setQueueLevel); this.oldTicketLevel = this.ticketLevel; diff --git a/paper-server/nms-patches/net/minecraft/server/level/PlayerChunkMap.patch b/paper-server/nms-patches/net/minecraft/server/level/PlayerChunkMap.patch index f6390c0e39..91440ae953 100644 --- a/paper-server/nms-patches/net/minecraft/server/level/PlayerChunkMap.patch +++ b/paper-server/nms-patches/net/minecraft/server/level/PlayerChunkMap.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/level/PlayerChunkMap.java +++ b/net/minecraft/server/level/PlayerChunkMap.java -@@ -102,6 +102,10 @@ +@@ -104,6 +104,10 @@ import org.apache.commons.lang3.mutable.MutableBoolean; import org.slf4j.Logger; @@ -11,7 +11,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.b, GeneratingChunkMap { private static final ChunkResult> UNLOADED_CHUNK_LIST_RESULT = ChunkResult.error("Unloaded chunks found in range"); -@@ -145,6 +149,27 @@ +@@ -149,6 +153,27 @@ public int serverViewDistance; private final WorldGenContext worldGenContext; @@ -39,7 +39,7 @@ public PlayerChunkMap(WorldServer worldserver, Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, StructureTemplateManager structuretemplatemanager, Executor executor, IAsyncTaskHandler iasynctaskhandler, ILightAccess ilightaccess, ChunkGenerator chunkgenerator, WorldLoadListener worldloadlistener, ChunkStatusUpdateListener chunkstatusupdatelistener, Supplier supplier, int i, boolean flag) { super(new RegionStorageInfo(convertable_conversionsession.getLevelId(), worldserver.dimension(), "chunk"), convertable_conversionsession.getDimensionPath(worldserver.dimension()).resolve("region"), datafixer, flag); this.visibleChunkMap = this.updatingChunkMap.clone(); -@@ -164,7 +189,13 @@ +@@ -170,7 +195,13 @@ IRegistryCustom iregistrycustom = worldserver.registryAccess(); long j = worldserver.getSeed(); @@ -54,7 +54,7 @@ this.randomState = RandomState.create((GeneratorSettingBase) chunkgeneratorabstract.generatorSettings().value(), (HolderGetter) iregistrycustom.lookupOrThrow(Registries.NOISE), j); } else { this.randomState = RandomState.create(GeneratorSettingBase.dummy(), (HolderGetter) iregistrycustom.lookupOrThrow(Registries.NOISE), j); -@@ -318,7 +349,7 @@ +@@ -325,7 +356,7 @@ throw this.debugFuturesAndCreateReportedException(new IllegalStateException("At least one of the chunk futures were null"), "n/a"); } @@ -63,7 +63,7 @@ if (ichunkaccess == null) { return PlayerChunkMap.UNLOADED_CHUNK_LIST_RESULT; -@@ -937,7 +968,8 @@ +@@ -977,7 +1008,8 @@ return ichunkaccess instanceof Chunk ? Optional.of((Chunk) ichunkaccess) : Optional.empty(); }); @@ -73,7 +73,7 @@ return chunk.getBlockEntities().size(); }).orElse(0), tickingtracker.getTicketDebugString(i), tickingtracker.getLevel(i), optional1.map((chunk) -> { return chunk.getBlockTicks().count(); -@@ -950,7 +982,7 @@ +@@ -990,7 +1022,7 @@ private static String printFuture(CompletableFuture> completablefuture) { try { @@ -82,13 +82,13 @@ return chunkresult != null ? (chunkresult.isSuccess() ? "done" : "unloaded") : "not completed"; } catch (CompletionException completionexception) { -@@ -962,12 +994,14 @@ +@@ -1002,12 +1034,14 @@ private CompletableFuture> readChunk(ChunkCoordIntPair chunkcoordintpair) { return this.read(chunkcoordintpair).thenApplyAsync((optional) -> { - return optional.map(this::upgradeChunkTag); + return optional.map((nbttagcompound) -> upgradeChunkTag(nbttagcompound, chunkcoordintpair)); // CraftBukkit - }, SystemUtils.backgroundExecutor()); + }, SystemUtils.backgroundExecutor().forName("upgradeChunk")); } - private NBTTagCompound upgradeChunkTag(NBTTagCompound nbttagcompound) { @@ -99,8 +99,8 @@ + // CraftBukkit end } - boolean anyPlayerCloseEnoughForSpawning(ChunkCoordIntPair chunkcoordintpair) { -@@ -1370,7 +1404,7 @@ + void forEachSpawnCandidateChunk(Consumer consumer) { +@@ -1424,7 +1458,7 @@ public final Set seenBy = Sets.newIdentityHashSet(); public EntityTracker(final Entity entity, final int i, final int j, final boolean flag) { @@ -109,7 +109,7 @@ this.entity = entity; this.range = i; this.lastSectionPos = SectionPosition.of((EntityAccess) entity); -@@ -1430,6 +1464,11 @@ +@@ -1484,6 +1518,11 @@ double d2 = d0 * d0; boolean flag = d1 <= d2 && this.entity.broadcastToPlayer(entityplayer) && PlayerChunkMap.this.isChunkTracked(entityplayer, this.entity.chunkPosition().x, this.entity.chunkPosition().z); diff --git a/paper-server/nms-patches/net/minecraft/server/level/PlayerInteractManager.patch b/paper-server/nms-patches/net/minecraft/server/level/PlayerInteractManager.patch index a82ef80b1a..5826f84b9b 100644 --- a/paper-server/nms-patches/net/minecraft/server/level/PlayerInteractManager.patch +++ b/paper-server/nms-patches/net/minecraft/server/level/PlayerInteractManager.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/level/PlayerInteractManager.java +++ b/net/minecraft/server/level/PlayerInteractManager.java -@@ -28,6 +28,27 @@ +@@ -26,6 +26,27 @@ import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; @@ -28,7 +28,7 @@ public class PlayerInteractManager { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -58,9 +79,16 @@ +@@ -56,9 +77,16 @@ if (enumgamemode == this.gameModeForPlayer) { return false; } else { @@ -46,7 +46,7 @@ this.level.updateSleepingPlayerList(); if (enumgamemode == EnumGamemode.CREATIVE) { this.player.resetCurrentImpulseContext(); -@@ -94,7 +122,7 @@ +@@ -92,7 +120,7 @@ } public void tick() { @@ -55,7 +55,7 @@ IBlockData iblockdata; if (this.hasDelayedDestroy) { -@@ -148,11 +176,33 @@ +@@ -146,11 +174,33 @@ if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.START_DESTROY_BLOCK) { if (!this.level.mayInteract(this.player, blockposition)) { @@ -89,7 +89,7 @@ if (this.isCreative()) { this.destroyAndAck(blockposition, j, "creative destroy"); return; -@@ -168,7 +218,19 @@ +@@ -166,7 +216,19 @@ float f = 1.0F; iblockdata = this.level.getBlockState(blockposition); @@ -110,7 +110,7 @@ EnchantmentManager.onHitBlock(this.level, this.player.getMainHandItem(), this.player, this.player, EnumItemSlot.MAINHAND, Vec3D.atCenterOf(blockposition), iblockdata, (item) -> { this.player.onEquippedItemBroken(item, EnumItemSlot.MAINHAND); }); -@@ -176,6 +238,26 @@ +@@ -174,6 +236,26 @@ f = iblockdata.getDestroyProgress(this.player, this.player.level(), blockposition); } @@ -137,7 +137,7 @@ if (!iblockdata.isAir() && f >= 1.0F) { this.destroyAndAck(blockposition, j, "insta mine"); } else { -@@ -220,13 +302,15 @@ +@@ -218,13 +300,15 @@ } else if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.ABORT_DESTROY_BLOCK) { this.isDestroyingBlock = false; if (!Objects.equals(this.destroyPos, blockposition)) { @@ -154,7 +154,7 @@ } } -@@ -244,10 +328,65 @@ +@@ -242,10 +326,65 @@ public boolean destroyBlock(BlockPosition blockposition) { IBlockData iblockdata = this.level.getBlockState(blockposition); @@ -221,7 +221,7 @@ TileEntity tileentity = this.level.getBlockEntity(blockposition); Block block = iblockdata.getBlock(); -@@ -257,6 +396,10 @@ +@@ -255,6 +394,10 @@ } else if (this.player.blockActionRestricted(this.level, blockposition, this.gameModeForPlayer)) { return false; } else { @@ -232,7 +232,7 @@ IBlockData iblockdata1 = block.playerWillDestroy(this.level, blockposition, iblockdata, this.player); boolean flag = this.level.removeBlock(blockposition, false); -@@ -265,19 +408,32 @@ +@@ -263,19 +406,32 @@ } if (this.isCreative()) { @@ -268,7 +268,7 @@ } } } -@@ -315,14 +471,53 @@ +@@ -321,14 +477,53 @@ } } @@ -290,7 +290,7 @@ + cancelledBlock = !(itileinventory instanceof ITileInventory); + } + -+ if (entityplayer.getCooldowns().isOnCooldown(itemstack.getItem())) { ++ if (entityplayer.getCooldowns().isOnCooldown(itemstack)) { + cancelledBlock = true; + } + @@ -322,11 +322,11 @@ if (itileinventory != null) { entityplayer.openMenu(itileinventory); -@@ -353,7 +548,7 @@ +@@ -359,7 +554,7 @@ } } -- if (!itemstack.isEmpty() && !entityplayer.getCooldowns().isOnCooldown(itemstack.getItem())) { +- if (!itemstack.isEmpty() && !entityplayer.getCooldowns().isOnCooldown(itemstack)) { + if (!itemstack.isEmpty() && !interactResult) { // add !interactResult SPIGOT-764 ItemActionContext itemactioncontext = new ItemActionContext(entityplayer, enumhand, movingobjectpositionblock); diff --git a/paper-server/nms-patches/net/minecraft/server/level/TicketType.patch b/paper-server/nms-patches/net/minecraft/server/level/TicketType.patch index a83c57b303..641764302f 100644 --- a/paper-server/nms-patches/net/minecraft/server/level/TicketType.patch +++ b/paper-server/nms-patches/net/minecraft/server/level/TicketType.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/server/level/TicketType.java +++ b/net/minecraft/server/level/TicketType.java -@@ -22,6 +22,8 @@ - public static final TicketType PORTAL = create("portal", BaseBlockPosition::compareTo, 300); +@@ -23,6 +23,8 @@ + public static final TicketType ENDER_PEARL = create("ender_pearl", Comparator.comparingLong(ChunkCoordIntPair::toLong), 40); public static final TicketType POST_TELEPORT = create("post_teleport", Integer::compareTo, 5); public static final TicketType UNKNOWN = create("unknown", Comparator.comparingLong(ChunkCoordIntPair::toLong), 1); + public static final TicketType PLUGIN = create("plugin", (a, b) -> 0); // CraftBukkit diff --git a/paper-server/nms-patches/net/minecraft/server/level/WorldServer.patch b/paper-server/nms-patches/net/minecraft/server/level/WorldServer.patch index 2327d7de5c..170108a5ab 100644 --- a/paper-server/nms-patches/net/minecraft/server/level/WorldServer.patch +++ b/paper-server/nms-patches/net/minecraft/server/level/WorldServer.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/level/WorldServer.java +++ b/net/minecraft/server/level/WorldServer.java -@@ -171,6 +171,23 @@ +@@ -173,6 +173,23 @@ import net.minecraft.world.ticks.TickListServer; import org.slf4j.Logger; @@ -21,31 +21,28 @@ +import org.bukkit.event.world.TimeSkipEvent; +// CraftBukkit end + - public class WorldServer extends World implements GeneratorAccessSeed { + public class WorldServer extends World implements ServerEntityGetter, GeneratorAccessSeed { public static final BlockPosition END_SPAWN_POINT = new BlockPosition(100, 50, 0); -@@ -184,7 +201,7 @@ - final List players; +@@ -186,7 +203,7 @@ + final List players = Lists.newArrayList(); private final ChunkProviderServer chunkSource; private final MinecraftServer server; - public final IWorldDataServer serverLevelData; + public final WorldDataServer serverLevelData; // CraftBukkit - type private int lastSpawnChunkRadius; - final EntityTickList entityTickList; + final EntityTickList entityTickList = new EntityTickList(); public final PersistentEntitySectionManager entityManager; -@@ -211,12 +228,30 @@ +@@ -213,13 +230,47 @@ private final boolean tickTime; private final RandomSequences randomSequences; - public WorldServer(MinecraftServer minecraftserver, Executor executor, Convertable.ConversionSession convertable_conversionsession, IWorldDataServer iworlddataserver, ResourceKey resourcekey, WorldDimension worlddimension, WorldLoadListener worldloadlistener, boolean flag, long i, List list, boolean flag1, @Nullable RandomSequences randomsequences) { -- IRegistryCustom.Dimension iregistrycustom_dimension = minecraftserver.registryAccess(); -- Holder holder = worlddimension.type(); +- super(iworlddataserver, resourcekey, minecraftserver.registryAccess(), worlddimension.type(), false, flag, i, minecraftserver.getMaxChainedNeighborUpdates()); + // CraftBukkit start + public final Convertable.ConversionSession convertable; + public final UUID uuid; - -- Objects.requireNonNull(minecraftserver); -- super(iworlddataserver, resourcekey, iregistrycustom_dimension, holder, minecraftserver::getProfiler, false, flag, i, minecraftserver.getMaxChainedNeighborUpdates()); ++ + public Chunk getChunkIfLoaded(int x, int z) { + return this.chunkSource.getChunk(x, z, false); + } @@ -57,19 +54,13 @@ + + // Add env and gen to constructor, IWorldDataServer -> WorldDataServer + public WorldServer(MinecraftServer minecraftserver, Executor executor, Convertable.ConversionSession convertable_conversionsession, WorldDataServer iworlddataserver, ResourceKey resourcekey, WorldDimension worlddimension, WorldLoadListener worldloadlistener, boolean flag, long i, List list, boolean flag1, @Nullable RandomSequences randomsequences, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider) { -+ // IRegistryCustom.Dimension iregistrycustom_dimension = minecraftserver.registryAccess(); // CraftBukkit - decompile error -+ // Holder holder = worlddimension.type(); // CraftBukkit - decompile error -+ -+ // Objects.requireNonNull(minecraftserver); // CraftBukkit - decompile error -+ super(iworlddataserver, resourcekey, minecraftserver.registryAccess(), worlddimension.type(), minecraftserver::getProfiler, false, flag, i, minecraftserver.getMaxChainedNeighborUpdates(), gen, biomeProvider, env); ++ super(iworlddataserver, resourcekey, minecraftserver.registryAccess(), worlddimension.type(), false, flag, i, minecraftserver.getMaxChainedNeighborUpdates(), gen, biomeProvider, env); + this.pvpMode = minecraftserver.isPvpAllowed(); + convertable = convertable_conversionsession; + uuid = WorldUUID.getUUID(convertable_conversionsession.levelDirectory.path().toFile()); + // CraftBukkit end - this.players = Lists.newArrayList(); - this.entityTickList = new EntityTickList(); - this.blockTicks = new TickListServer<>(this::isPositionTickingWithEntitiesLoaded, this.getProfilerSupplier()); -@@ -231,6 +266,22 @@ + this.tickTime = flag1; + this.server = minecraftserver; this.customSpawners = list; this.serverLevelData = iworlddataserver; ChunkGenerator chunkgenerator = worlddimension.generator(); @@ -77,7 +68,7 @@ + serverLevelData.setWorld(this); + + if (biomeProvider != null) { -+ WorldChunkManager worldChunkManager = new CustomWorldChunkManager(getWorld(), biomeProvider, server.registryAccess().registryOrThrow(Registries.BIOME)); ++ WorldChunkManager worldChunkManager = new CustomWorldChunkManager(getWorld(), biomeProvider, server.registryAccess().lookupOrThrow(Registries.BIOME)); + if (chunkgenerator instanceof ChunkGeneratorAbstract cga) { + chunkgenerator = new ChunkGeneratorAbstract(worldChunkManager, cga.settings); + } else if (chunkgenerator instanceof ChunkProviderFlat cpf) { @@ -92,7 +83,7 @@ boolean flag2 = minecraftserver.forceSynchronousWrites(); DataFixer datafixer = minecraftserver.getFixerUpper(); EntityPersistentStorage entitypersistentstorage = new EntityStorage(new SimpleRegionStorage(new RegionStorageInfo(convertable_conversionsession.getLevelId(), resourcekey, "entities"), convertable_conversionsession.getDimensionPath(resourcekey).resolve("entities"), datafixer, flag2, DataFixTypes.ENTITY_CHUNK), this, minecraftserver); -@@ -258,9 +309,9 @@ +@@ -247,9 +298,9 @@ long l = minecraftserver.getWorldData().worldGenOptions().seed(); this.structureCheck = new StructureCheck(this.chunkSource.chunkScanner(), this.registryAccess(), minecraftserver.getStructureManager(), resourcekey, chunkgenerator, this.chunkSource.randomState(), this, chunkgenerator.getBiomeSource(), l, datafixer); @@ -105,7 +96,7 @@ } else { this.dragonFight = null; } -@@ -270,6 +321,7 @@ +@@ -259,6 +310,7 @@ this.randomSequences = (RandomSequences) Objects.requireNonNullElseGet(randomsequences, () -> { return (RandomSequences) this.getDataStorage().computeIfAbsent(RandomSequences.factory(l), "random_sequences"); }); @@ -113,7 +104,7 @@ } /** @deprecated */ -@@ -314,12 +366,20 @@ +@@ -304,12 +356,20 @@ long j; if (this.sleepStatus.areEnoughSleeping(i) && this.sleepStatus.areEnoughDeepSleeping(i, this.players)) { @@ -137,7 +128,7 @@ if (this.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE) && this.isRaining()) { this.resetWeatherCycle(); } -@@ -354,7 +414,7 @@ +@@ -344,7 +404,7 @@ this.handlingTick = false; gameprofilerfiller.pop(); @@ -146,16 +137,7 @@ if (flag1) { this.resetEmptyTime(); -@@ -370,7 +430,7 @@ - - this.entityTickList.forEach((entity) -> { - if (!entity.isRemoved()) { -- if (this.shouldDiscardEntity(entity)) { -+ if (false && this.shouldDiscardEntity(entity)) { // CraftBukkit - We prevent spawning in general, so this butchering is not needed - entity.discard(); - } else if (!tickratemanager.isEntityFrozen(entity)) { - gameprofilerfiller.push("checkDespawn"); -@@ -442,7 +502,7 @@ +@@ -428,7 +488,7 @@ private void wakeUpAllPlayers() { this.sleepStatus.removeAllSleepers(); @@ -164,7 +146,7 @@ entityplayer.stopSleepInBed(false, false); }); } -@@ -469,7 +529,7 @@ +@@ -455,7 +515,7 @@ entityhorseskeleton.setTrap(true); entityhorseskeleton.setAge(0); entityhorseskeleton.setPos((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ()); @@ -173,7 +155,7 @@ } } -@@ -478,7 +538,7 @@ +@@ -464,7 +524,7 @@ if (entitylightning != null) { entitylightning.moveTo(Vec3D.atBottomCenterOf(blockposition)); entitylightning.setVisualOnly(flag1); @@ -182,7 +164,7 @@ } } } -@@ -534,7 +594,7 @@ +@@ -520,7 +580,7 @@ BiomeBase biomebase = (BiomeBase) this.getBiome(blockposition1).value(); if (biomebase.shouldFreeze(this, blockposition2)) { @@ -191,7 +173,7 @@ } if (this.isRaining()) { -@@ -550,10 +610,10 @@ +@@ -536,10 +596,10 @@ IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockSnow.LAYERS, j + 1); Block.pushEntitiesUp(iblockdata, iblockdata1, this, blockposition1); @@ -204,7 +186,7 @@ } } -@@ -714,6 +774,7 @@ +@@ -700,6 +760,7 @@ this.rainLevel = MathHelper.clamp(this.rainLevel, 0.0F, 1.0F); } @@ -212,7 +194,7 @@ if (this.oRainLevel != this.rainLevel) { this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel), this.dimension()); } -@@ -732,15 +793,48 @@ +@@ -718,15 +779,48 @@ this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel)); this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.THUNDER_LEVEL_CHANGE, this.thunderLevel)); } @@ -263,15 +245,15 @@ } public void resetEmptyTime() { -@@ -775,6 +869,7 @@ +@@ -762,6 +856,7 @@ }); gameprofilerfiller.incrementCounter("tickNonPassenger"); entity.tick(); + entity.postTick(); // CraftBukkit - this.getProfiler().pop(); + gameprofilerfiller.pop(); Iterator iterator = entity.getPassengers().iterator(); -@@ -798,6 +893,7 @@ +@@ -785,6 +880,7 @@ }); gameprofilerfiller.incrementCounter("tickPassenger"); entity1.rideTick(); @@ -279,7 +261,7 @@ gameprofilerfiller.pop(); Iterator iterator = entity1.getPassengers().iterator(); -@@ -822,6 +918,7 @@ +@@ -809,6 +905,7 @@ ChunkProviderServer chunkproviderserver = this.getChunkSource(); if (!flag1) { @@ -287,7 +269,7 @@ if (iprogressupdate != null) { iprogressupdate.progressStartNoAbort(IChatBaseComponent.translatable("menu.savingLevel")); } -@@ -839,11 +936,19 @@ +@@ -826,11 +923,19 @@ } } @@ -301,14 +283,14 @@ + // CraftBukkit end } - private void saveLevelData() { + private void saveLevelData(boolean flag) { if (this.dragonFight != null) { - this.server.getWorldData().setEndDragonFightData(this.dragonFight.saveData()); + this.serverLevelData.setEndDragonFightData(this.dragonFight.saveData()); // CraftBukkit } - this.getChunkSource().getDataStorage().save(); -@@ -908,18 +1013,40 @@ + WorldPersistentData worldpersistentdata = this.getChunkSource().getDataStorage(); +@@ -902,18 +1007,40 @@ @Override public boolean addFreshEntity(Entity entity) { @@ -352,7 +334,7 @@ } } -@@ -944,24 +1071,37 @@ +@@ -938,24 +1065,37 @@ this.entityManager.addNewEntity(entityplayer); } @@ -394,19 +376,19 @@ return true; } } -@@ -972,13 +1112,35 @@ +@@ -966,13 +1106,35 @@ } public void removePlayerImmediately(EntityPlayer entityplayer, Entity.RemovalReason entity_removalreason) { - entityplayer.remove(entity_removalreason); + entityplayer.remove(entity_removalreason, null); // CraftBukkit - add Bukkit remove cause - } - ++ } ++ + // CraftBukkit start + public boolean strikeLightning(Entity entitylightning) { + return this.strikeLightning(entitylightning, LightningStrikeEvent.Cause.UNKNOWN); -+ } -+ + } + + public boolean strikeLightning(Entity entitylightning, LightningStrikeEvent.Cause cause) { + LightningStrikeEvent lightning = CraftEventFactory.callLightningStrikeEvent((org.bukkit.entity.LightningStrike) entitylightning.getBukkitEntity(), cause); + @@ -431,7 +413,7 @@ while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer) iterator.next(); -@@ -987,6 +1149,12 @@ +@@ -981,6 +1143,12 @@ double d1 = (double) blockposition.getY() - entityplayer.getY(); double d2 = (double) blockposition.getZ() - entityplayer.getZ(); @@ -444,7 +426,7 @@ if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) { entityplayer.connection.send(new PacketPlayOutBlockBreakAnimation(i, blockposition, j)); } -@@ -1047,7 +1215,18 @@ +@@ -1059,7 +1227,18 @@ Iterator iterator = this.navigatingMobs.iterator(); while (iterator.hasNext()) { @@ -464,19 +446,52 @@ NavigationAbstract navigationabstract = entityinsentient.getNavigation(); if (navigationabstract.shouldRecomputePath(blockposition)) { -@@ -1109,6 +1288,11 @@ +@@ -1125,6 +1304,12 @@ + @Override - public Explosion explode(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, World.a world_a, ParticleParam particleparam, ParticleParam particleparam1, Holder holder) { - Explosion explosion = this.explode(entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, world_a, false, particleparam, particleparam1, holder); + public void explode(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, World.a world_a, ParticleParam particleparam, ParticleParam particleparam1, Holder holder) { + // CraftBukkit start -+ if (explosion.wasCanceled) { -+ return explosion; ++ this.explode0(entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, world_a, particleparam, particleparam1, holder); ++ } ++ ++ public ServerExplosion explode0(@Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, double d0, double d1, double d2, float f, boolean flag, World.a world_a, ParticleParam particleparam, ParticleParam particleparam1, Holder holder) { ++ // CraftBukkit end + Explosion.Effect explosion_effect; + + switch (world_a) { +@@ -1143,6 +1328,11 @@ + case TRIGGER: + explosion_effect = Explosion.Effect.TRIGGER_BLOCK; + break; ++ // CraftBukkit start - handle custom explosion type ++ case STANDARD: ++ explosion_effect = Explosion.Effect.DESTROY; ++ break; ++ // CraftBukkit end + default: + throw new MatchException((String) null, (Throwable) null); + } +@@ -1152,6 +1342,11 @@ + ServerExplosion serverexplosion = new ServerExplosion(this, entity, damagesource, explosiondamagecalculator, vec3d, f, flag, explosion_effect1); + + serverexplosion.explode(); ++ // CraftBukkit start ++ if (serverexplosion.wasCanceled) { ++ return serverexplosion; + } + // CraftBukkit end + ParticleParam particleparam2 = serverexplosion.isSmall() ? particleparam : particleparam1; + Iterator iterator = this.players.iterator(); - if (!explosion.interactsWithBlocks()) { - explosion.clearToBlow(); -@@ -1181,13 +1365,20 @@ +@@ -1165,6 +1360,7 @@ + } + } + ++ return serverexplosion; // CraftBukkit + } + + private Explosion.Effect getDestroyType(GameRules.GameRuleKey gamerules_gamerulekey) { +@@ -1225,13 +1421,20 @@ } public int sendParticles(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) { @@ -499,7 +514,7 @@ ++j; } } -@@ -1238,7 +1429,7 @@ +@@ -1282,7 +1485,7 @@ @Nullable public BlockPosition findNearestMapStructure(TagKey tagkey, BlockPosition blockposition, int i, boolean flag) { @@ -507,8 +522,8 @@ + if (!this.serverLevelData.worldGenOptions().generateStructures()) { // CraftBukkit return null; } else { - Optional> optional = this.registryAccess().registryOrThrow(Registries.STRUCTURE).getTag(tagkey); -@@ -1280,11 +1471,22 @@ + Optional> optional = this.registryAccess().lookupOrThrow(Registries.STRUCTURE).get(tagkey); +@@ -1324,11 +1527,22 @@ @Nullable @Override public WorldMap getMapData(MapId mapid) { @@ -532,7 +547,7 @@ this.getServer().overworld().getDataStorage().set(mapid.key(), worldmap); } -@@ -1595,6 +1797,11 @@ +@@ -1639,6 +1853,11 @@ @Override public void blockUpdated(BlockPosition blockposition, Block block) { if (!this.isDebug()) { @@ -544,7 +559,7 @@ this.updateNeighborsAt(blockposition, block); } -@@ -1614,12 +1821,12 @@ +@@ -1658,12 +1877,12 @@ } public boolean isFlat() { @@ -559,7 +574,7 @@ } @Nullable -@@ -1642,7 +1849,7 @@ +@@ -1686,7 +1905,7 @@ private static String getTypeCount(Iterable iterable, Function function) { try { Object2IntOpenHashMap object2intopenhashmap = new Object2IntOpenHashMap(); @@ -568,7 +583,7 @@ while (iterator.hasNext()) { T t0 = iterator.next(); -@@ -1651,7 +1858,7 @@ +@@ -1695,7 +1914,7 @@ object2intopenhashmap.addTo(s, 1); } @@ -577,7 +592,7 @@ String s1 = (String) entry.getKey(); return s1 + ":" + entry.getIntValue(); -@@ -1796,6 +2003,8 @@ +@@ -1854,6 +2073,8 @@ } entity.updateDynamicGameEventListener(DynamicGameEventListener::add); @@ -586,7 +601,7 @@ } public void onTrackingEnd(Entity entity) { -@@ -1827,6 +2036,14 @@ +@@ -1885,6 +2106,14 @@ } entity.updateDynamicGameEventListener(DynamicGameEventListener::remove); diff --git a/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch b/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch index ef370f58fd..b11116f726 100644 --- a/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch +++ b/paper-server/nms-patches/net/minecraft/server/network/PlayerConnection.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/network/PlayerConnection.java +++ b/net/minecraft/server/network/PlayerConnection.java -@@ -191,6 +191,67 @@ +@@ -196,6 +196,69 @@ import net.minecraft.world.phys.shapes.VoxelShapes; import org.slf4j.Logger; @@ -13,7 +13,7 @@ +import net.minecraft.network.chat.OutgoingChatMessage; +import net.minecraft.network.protocol.game.PacketPlayOutAttachEntity; +import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; -+import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity; ++import net.minecraft.network.protocol.game.PacketPlayOutSetSlot; +import net.minecraft.world.entity.EntityInsentient; +import net.minecraft.world.entity.animal.Bucketable; +import net.minecraft.world.entity.EntityLiving; @@ -30,7 +30,9 @@ +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.inventory.CraftItemType; ++import org.bukkit.craftbukkit.inventory.CraftRecipe; +import org.bukkit.craftbukkit.util.CraftChatMessage; ++import org.bukkit.craftbukkit.util.CraftLocation; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.craftbukkit.util.LazyPlayerSet; +import org.bukkit.craftbukkit.util.Waitable; @@ -68,18 +70,7 @@ public class PlayerConnection extends ServerCommonPacketListenerImpl implements PacketListenerPlayIn, ServerPlayerConnection, TickablePacketListener { static final Logger LOGGER = LogUtils.getLogger(); -@@ -204,7 +265,9 @@ - public final PlayerChunkSender chunkSender; - private int tickCount; - private int ackBlockChangesUpTo = -1; -- private int chatSpamTickCount; -+ // CraftBukkit start - multithreaded fields -+ private final AtomicInteger chatSpamTickCount = new AtomicInteger(); -+ // CraftBukkit end - private int dropSpamTickCount; - private double firstGoodX; - private double firstGoodY; -@@ -239,7 +302,7 @@ +@@ -245,7 +308,7 @@ private boolean waitingForSwitchToConfig; public PlayerConnection(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer, CommonListenerCookie commonlistenercookie) { @@ -88,7 +79,7 @@ this.chunkSender = new PlayerChunkSender(networkmanager.isMemoryConnection()); this.player = entityplayer; entityplayer.connection = this; -@@ -248,9 +311,25 @@ +@@ -254,9 +317,25 @@ Objects.requireNonNull(minecraftserver); this.signedMessageDecoder = SignedMessageChain.b.unsigned(uuid, minecraftserver::enforceSecureProfile); @@ -115,29 +106,15 @@ @Override public void tick() { if (this.ackBlockChangesUpTo > -1) { -@@ -302,15 +381,21 @@ - } - - this.keepConnectionAlive(); -+ // CraftBukkit start -+ for (int spam; (spam = this.chatSpamTickCount.get()) > 0 && !chatSpamTickCount.compareAndSet(spam, spam - 1); ) ; -+ /* Use thread-safe field access instead - if (this.chatSpamTickCount > 0) { - --this.chatSpamTickCount; - } -+ */ -+ // CraftBukkit end - - if (this.dropSpamTickCount > 0) { - --this.dropSpamTickCount; - } - +@@ -311,6 +390,7 @@ + this.chatSpamThrottler.tick(); + this.dropSpamThrottler.tick(); if (this.player.getLastActionTime() > 0L && this.server.getPlayerIdleTimeout() > 0 && SystemUtils.getMillis() - this.player.getLastActionTime() > (long) this.server.getPlayerIdleTimeout() * 1000L * 60L) { + this.player.resetLastActionTime(); // CraftBukkit - SPIGOT-854 this.disconnect((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.idling")); } -@@ -399,6 +484,13 @@ +@@ -399,6 +479,13 @@ if (entity != this.player && entity.getControllingPassenger() == this.player && entity == this.lastVehicle) { WorldServer worldserver = this.player.serverLevel(); @@ -151,7 +128,7 @@ double d0 = entity.getX(); double d1 = entity.getY(); double d2 = entity.getZ(); -@@ -413,7 +505,33 @@ +@@ -413,7 +500,33 @@ double d9 = entity.getDeltaMovement().lengthSqr(); double d10 = d6 * d6 + d7 * d7 + d8 * d8; @@ -186,7 +163,7 @@ PlayerConnection.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", new Object[]{entity.getName().getString(), this.player.getName().getString(), d6, d7, d8}); this.send(new PacketPlayOutVehicleMove(entity)); return; -@@ -453,14 +571,76 @@ +@@ -453,14 +566,76 @@ } entity.absMoveTo(d3, d4, d5, f, f1); @@ -261,9 +238,9 @@ + // CraftBukkit end + this.player.serverLevel().getChunkSource().move(this.player); + entity.recordMovementThroughBlocks(new Vec3D(d0, d1, d2), entity.position()); Vec3D vec3d = new Vec3D(entity.getX() - d0, entity.getY() - d1, entity.getZ() - d2); - -@@ -497,6 +677,7 @@ +@@ -498,6 +673,7 @@ } this.awaitingPositionFromClient = null; @@ -271,16 +248,7 @@ } } -@@ -504,7 +685,7 @@ - @Override - public void handleRecipeBookSeenRecipePacket(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) { - PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipedisplayed, this, this.player.serverLevel()); -- Optional optional = this.server.getRecipeManager().byKey(packetplayinrecipedisplayed.getRecipe()); -+ Optional> optional = this.server.getRecipeManager().byKey(packetplayinrecipedisplayed.getRecipe()); // CraftBukkit - decompile error - RecipeBookServer recipebookserver = this.player.getRecipeBook(); - - Objects.requireNonNull(recipebookserver); -@@ -514,6 +695,7 @@ +@@ -521,6 +697,7 @@ @Override public void handleRecipeBookChangeSettingsPacket(PacketPlayInRecipeSettings packetplayinrecipesettings) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipesettings, this, this.player.serverLevel()); @@ -288,12 +256,12 @@ this.player.getRecipeBook().setBookSetting(packetplayinrecipesettings.getBookType(), packetplayinrecipesettings.isOpen(), packetplayinrecipesettings.isFiltering()); } -@@ -534,6 +716,12 @@ +@@ -541,6 +718,12 @@ @Override public void handleCustomCommandSuggestions(PacketPlayInTabComplete packetplayintabcomplete) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayintabcomplete, this, this.player.serverLevel()); + // CraftBukkit start -+ if (chatSpamTickCount.addAndGet(1) > 500 && !this.server.getPlayerList().isOp(this.player.getGameProfile())) { ++ if (!this.chatSpamThrottler.isIncrementAndUnderThreshold(1, 500) && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) { + this.disconnect(IChatBaseComponent.translatable("disconnect.spam")); + return; + } @@ -301,7 +269,7 @@ StringReader stringreader = new StringReader(packetplayintabcomplete.getCommand()); if (stringreader.canRead() && stringreader.peek() == '/') { -@@ -543,6 +731,7 @@ +@@ -550,6 +733,7 @@ ParseResults parseresults = this.server.getCommands().getDispatcher().parse(stringreader, this.player.createCommandSourceStack()); this.server.getCommands().getDispatcher().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> { @@ -309,7 +277,7 @@ Suggestions suggestions1 = suggestions.getList().size() <= 1000 ? suggestions : new Suggestions(suggestions.getRange(), suggestions.getList().subList(0, 1000)); this.send(new PacketPlayOutTabComplete(packetplayintabcomplete.getId(), suggestions1)); -@@ -787,6 +976,13 @@ +@@ -796,6 +980,13 @@ Container container = this.player.containerMenu; if (container instanceof ContainerMerchant containermerchant) { @@ -323,7 +291,7 @@ if (!containermerchant.stillValid(this.player)) { PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, containermerchant); return; -@@ -800,6 +996,13 @@ +@@ -809,6 +1000,13 @@ @Override public void handleEditBook(PacketPlayInBEdit packetplayinbedit) { @@ -337,16 +305,7 @@ int i = packetplayinbedit.slot(); if (PlayerInventory.isHotbarSlot(i) || i == 40) { -@@ -808,7 +1011,7 @@ - - Objects.requireNonNull(list); - optional.ifPresent(list::add); -- Stream stream = packetplayinbedit.pages().stream().limit(100L); -+ Stream stream = packetplayinbedit.pages().stream().limit(100L); // CraftBukkit - decompile error - - Objects.requireNonNull(list); - stream.forEach(list::add); -@@ -823,12 +1026,16 @@ +@@ -829,12 +1027,16 @@ } private void updateBookContents(List list, int i) { @@ -356,7 +315,7 @@ + ItemStack itemstack = handItem.copy(); + // CraftBukkit end - if (itemstack.is(Items.WRITABLE_BOOK)) { + if (itemstack.has(DataComponents.WRITABLE_BOOK_CONTENT)) { List> list1 = list.stream().map(this::filterableFromOutgoing).toList(); itemstack.set(DataComponents.WRITABLE_BOOK_CONTENT, new WritableBookContent(list1)); @@ -364,7 +323,7 @@ } } -@@ -839,12 +1046,13 @@ +@@ -845,12 +1047,13 @@ ItemStack itemstack1 = itemstack.transmuteCopy(Items.WRITTEN_BOOK); itemstack1.remove(DataComponents.WRITABLE_BOOK_CONTENT); @@ -380,7 +339,7 @@ } } -@@ -906,7 +1114,7 @@ +@@ -912,7 +1115,7 @@ } else { WorldServer worldserver = this.player.serverLevel(); @@ -389,7 +348,7 @@ if (this.tickCount == 0) { this.resetPosition(); } -@@ -921,7 +1129,15 @@ +@@ -927,7 +1130,15 @@ if (this.player.isPassenger()) { this.player.absMoveTo(this.player.getX(), this.player.getY(), this.player.getZ(), f, f1); this.player.serverLevel().getChunkSource().move(this.player); @@ -405,7 +364,7 @@ double d3 = this.player.getX(); double d4 = this.player.getY(); double d5 = this.player.getZ(); -@@ -943,15 +1159,33 @@ +@@ -949,15 +1160,33 @@ ++this.receivedMovePacketCount; int i = this.receivedMovePacketCount - this.knownMovePacketCount; @@ -432,16 +391,16 @@ + speed = player.getAbilities().walkingSpeed * 10f; + } + - if (!this.player.isChangingDimension() && (!this.player.level().getGameRules().getBoolean(GameRules.RULE_DISABLE_ELYTRA_MOVEMENT_CHECK) || !flag)) { + if (this.shouldCheckPlayerMovement(flag)) { float f2 = flag ? 300.0F : 100.0F; -- if (d10 - d9 > (double) (f2 * (float) i) && !this.isSingleplayerOwner()) { -+ if (d10 - d9 > Math.max(f2, Math.pow((double) (10.0F * (float) i * speed), 2)) && !this.isSingleplayerOwner()) { +- if (d10 - d9 > (double) (f2 * (float) i)) { ++ if (d10 - d9 > Math.max(f2, Math.pow((double) (10.0F * (float) i * speed), 2))) { + // CraftBukkit end PlayerConnection.LOGGER.warn("{} moved too quickly! {},{},{}", new Object[]{this.player.getName().getString(), d6, d7, d8}); this.teleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot()); return; -@@ -973,6 +1207,7 @@ +@@ -979,6 +1208,7 @@ boolean flag2 = this.player.verticalCollisionBelow; this.player.move(EnumMoveType.PLAYER, new Vec3D(d6, d7, d8)); @@ -449,12 +408,12 @@ double d11 = d7; d6 = d0 - this.player.getX(); -@@ -991,9 +1226,75 @@ +@@ -997,9 +1227,75 @@ } if (!this.player.noPhysics && !this.player.isSleeping() && (flag3 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew(worldserver, axisalignedbb, d0, d1, d2))) { - this.teleport(d3, d4, d5, f, f1); -+ this.internalTeleport(d3, d4, d5, f, f1, Collections.emptySet()); // CraftBukkit - SPIGOT-1807: Don't call teleport event, when the client thinks the player is falling, because the chunks are not loaded on the client yet. ++ this.internalTeleport(d3, d4, d5, f, f1); // CraftBukkit - SPIGOT-1807: Don't call teleport event, when the client thinks the player is falling, because the chunks are not loaded on the client yet. this.player.doCheckFallDamage(this.player.getX() - d3, this.player.getY() - d4, this.player.getZ() - d5, packetplayinflying.isOnGround()); } else { + // CraftBukkit start - fire PlayerMoveEvent @@ -526,7 +485,7 @@ this.player.absMoveTo(d0, d1, d2, f, f1); boolean flag4 = this.player.isAutoSpinAttack(); -@@ -1030,6 +1331,7 @@ +@@ -1049,6 +1345,7 @@ this.awaitingTeleportTime = this.tickCount; this.teleport(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot()); } @@ -534,38 +493,33 @@ return true; } else { -@@ -1057,11 +1359,68 @@ - return true; +@@ -1077,10 +1374,62 @@ } -+ // CraftBukkit start - Delegate to teleport(Location) public void teleport(double d0, double d1, double d2, float f, float f1) { -- this.teleport(d0, d1, d2, f, f1, Collections.emptySet()); +- this.teleport(new PositionMoveRotation(new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f1), Collections.emptySet()); ++ // CraftBukkit start - Delegate to teleport(Location) + this.teleport(d0, d1, d2, f, f1, PlayerTeleportEvent.TeleportCause.UNKNOWN); + } + + public boolean teleport(double d0, double d1, double d2, float f, float f1, PlayerTeleportEvent.TeleportCause cause) { -+ return this.teleport(d0, d1, d2, f, f1, Collections.emptySet(), cause); ++ return this.teleport(new PositionMoveRotation(new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f1), Collections.emptySet(), cause); ++ // CraftBukkit end } - public void teleport(double d0, double d1, double d2, float f, float f1, Set set) { -+ this.teleport(d0, d1, d2, f, f1, set, PlayerTeleportEvent.TeleportCause.UNKNOWN); + public void teleport(PositionMoveRotation positionmoverotation, Set set) { ++ // CraftBukkit start ++ this.teleport(positionmoverotation, set, PlayerTeleportEvent.TeleportCause.UNKNOWN); + } + -+ public boolean teleport(double d0, double d1, double d2, float f, float f1, Set set, PlayerTeleportEvent.TeleportCause cause) { // CraftBukkit - Return event status ++ public boolean teleport(PositionMoveRotation positionmoverotation, Set set, PlayerTeleportEvent.TeleportCause cause) { // CraftBukkit - Return event status + Player player = this.getCraftPlayer(); + Location from = player.getLocation(); -+ -+ double x = d0; -+ double y = d1; -+ double z = d2; -+ float yaw = f; -+ float pitch = f1; -+ -+ Location to = new Location(this.getCraftPlayer().getWorld(), x, y, z, yaw, pitch); ++ PositionMoveRotation absolutePosition = PositionMoveRotation.calculateAbsolute(PositionMoveRotation.of(this.player), positionmoverotation, set); ++ Location to = CraftLocation.toBukkit(absolutePosition.position(), this.getCraftPlayer().getWorld(), absolutePosition.yRot(), absolutePosition.xRot()); + // SPIGOT-5171: Triggered on join + if (from.equals(to)) { -+ this.internalTeleport(d0, d1, d2, f, f1, set); ++ this.internalTeleport(positionmoverotation, set); + return true; // CraftBukkit - Return event status + } + @@ -575,51 +529,48 @@ + if (event.isCancelled() || !to.equals(event.getTo())) { + set = Collections.emptySet(); // Can't relative teleport + to = event.isCancelled() ? event.getFrom() : event.getTo(); -+ d0 = to.getX(); -+ d1 = to.getY(); -+ d2 = to.getZ(); -+ f = to.getYaw(); -+ f1 = to.getPitch(); ++ positionmoverotation = new PositionMoveRotation(CraftLocation.toVec3D(to), Vec3D.ZERO, to.getYaw(), to.getPitch()); + } + -+ this.internalTeleport(d0, d1, d2, f, f1, set); ++ this.internalTeleport(positionmoverotation, set); + return !event.isCancelled(); // CraftBukkit - Return event status + } + + public void teleport(Location dest) { -+ internalTeleport(dest.getX(), dest.getY(), dest.getZ(), dest.getYaw(), dest.getPitch(), Collections.emptySet()); ++ this.internalTeleport(dest.getX(), dest.getY(), dest.getZ(), dest.getYaw(), dest.getPitch()); + } + -+ private void internalTeleport(double d0, double d1, double d2, float f, float f1, Set set) { -+ // CraftBukkit start -+ if (Float.isNaN(f)) { -+ f = 0; ++ private void internalTeleport(double d0, double d1, double d2, float f, float f1) { ++ this.internalTeleport(new PositionMoveRotation(new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f1), Collections.emptySet()); ++ } ++ ++ public void internalTeleport(PositionMoveRotation positionmoverotation, Set set) { ++ if (Float.isNaN(positionmoverotation.yRot())) { ++ positionmoverotation = new PositionMoveRotation(positionmoverotation.position(), positionmoverotation.deltaMovement(), 0, positionmoverotation.xRot()); + } -+ if (Float.isNaN(f1)) { -+ f1 = 0; ++ if (Float.isNaN(positionmoverotation.xRot())) { ++ positionmoverotation = new PositionMoveRotation(positionmoverotation.position(), positionmoverotation.deltaMovement(), positionmoverotation.yRot(), 0); + } + + this.justTeleported = true; + // CraftBukkit end - double d3 = set.contains(RelativeMovement.X) ? this.player.getX() : 0.0D; - double d4 = set.contains(RelativeMovement.Y) ? this.player.getY() : 0.0D; - double d5 = set.contains(RelativeMovement.Z) ? this.player.getZ() : 0.0D; -@@ -1073,6 +1432,14 @@ + this.awaitingTeleportTime = this.tickCount; + if (++this.awaitingTeleport == Integer.MAX_VALUE) { this.awaitingTeleport = 0; - } +@@ -1088,12 +1437,20 @@ + this.player.teleportSetPosition(positionmoverotation, set); + this.awaitingPositionFromClient = this.player.position(); + // CraftBukkit start - update last location + this.lastPosX = this.awaitingPositionFromClient.x; + this.lastPosY = this.awaitingPositionFromClient.y; + this.lastPosZ = this.awaitingPositionFromClient.z; -+ this.lastYaw = f; -+ this.lastPitch = f1; ++ this.lastYaw = this.player.getYRot(); ++ this.lastPitch = this.player.getXRot(); + // CraftBukkit end -+ - this.awaitingTeleportTime = this.tickCount; - this.player.absMoveTo(d0, d1, d2, f, f1); - this.player.connection.send(new PacketPlayOutPosition(d0 - d3, d1 - d4, d2 - d5, f - f2, f1 - f3, set, this.awaitingTeleport)); -@@ -1081,6 +1448,7 @@ + this.player.connection.send(PacketPlayOutPosition.of(this.awaitingTeleport, positionmoverotation, set)); + } + @Override public void handlePlayerAction(PacketPlayInBlockDig packetplayinblockdig) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockdig, this, this.player.serverLevel()); @@ -627,7 +578,7 @@ BlockPosition blockposition = packetplayinblockdig.getPos(); this.player.resetLastActionTime(); -@@ -1091,14 +1459,46 @@ +@@ -1104,14 +1461,46 @@ if (!this.player.isSpectator()) { ItemStack itemstack = this.player.getItemInHand(EnumHand.OFF_HAND); @@ -676,7 +627,7 @@ this.player.drop(false); } -@@ -1136,6 +1536,7 @@ +@@ -1149,6 +1538,7 @@ @Override public void handleUseItemOn(PacketPlayInUseItem packetplayinuseitem) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseitem, this, this.player.serverLevel()); @@ -684,15 +635,15 @@ this.player.connection.ackBlockChangesUpTo(packetplayinuseitem.getSequence()); WorldServer worldserver = this.player.serverLevel(); EnumHand enumhand = packetplayinuseitem.getHand(); -@@ -1158,6 +1559,7 @@ +@@ -1171,6 +1561,7 @@ - if (blockposition.getY() < i) { + if (blockposition.getY() <= i) { if (this.awaitingPositionFromClient == null && worldserver.mayInteract(this.player, blockposition)) { + this.player.stopUsingItem(); // CraftBukkit - SPIGOT-4706 EnumInteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock); if (enuminteractionresult.consumesAction()) { -@@ -1190,6 +1592,7 @@ +@@ -1207,6 +1598,7 @@ @Override public void handleUseItem(PacketPlayInBlockPlace packetplayinblockplace) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockplace, this, this.player.serverLevel()); @@ -700,7 +651,7 @@ this.ackBlockChangesUpTo(packetplayinblockplace.getSequence()); WorldServer worldserver = this.player.serverLevel(); EnumHand enumhand = packetplayinblockplace.getHand(); -@@ -1204,6 +1607,47 @@ +@@ -1221,6 +1613,47 @@ this.player.absRotateTo(f, f1); } @@ -747,17 +698,17 @@ + // CraftBukkit end EnumInteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand); - if (enuminteractionresult.shouldSwing()) { -@@ -1224,7 +1668,7 @@ + if (enuminteractionresult instanceof EnumInteractionResult.d) { +@@ -1245,7 +1678,7 @@ Entity entity = packetplayinspectate.getEntity(worldserver); if (entity != null) { -- this.player.teleportTo(worldserver, entity.getX(), entity.getY(), entity.getZ(), entity.getYRot(), entity.getXRot()); -+ this.player.teleportTo(worldserver, entity.getX(), entity.getY(), entity.getZ(), entity.getYRot(), entity.getXRot(), org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.SPECTATE); // CraftBukkit +- this.player.teleportTo(worldserver, entity.getX(), entity.getY(), entity.getZ(), Set.of(), entity.getYRot(), entity.getXRot(), true); ++ this.player.teleportTo(worldserver, entity.getX(), entity.getY(), entity.getZ(), Set.of(), entity.getYRot(), entity.getXRot(), true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.SPECTATE); // CraftBukkit return; } } -@@ -1245,6 +1689,13 @@ +@@ -1266,6 +1699,13 @@ @Override public void onDisconnect(DisconnectionDetails disconnectiondetails) { @@ -771,7 +722,7 @@ PlayerConnection.LOGGER.info("{} lost connection: {}", this.player.getName().getString(), disconnectiondetails.reason().getString()); this.removePlayerFromWorld(); super.onDisconnect(disconnectiondetails); -@@ -1252,10 +1703,18 @@ +@@ -1273,10 +1713,18 @@ private void removePlayerFromWorld() { this.chatMessageChain.close(); @@ -791,7 +742,7 @@ this.player.getTextFilter().leave(); } -@@ -1270,7 +1729,16 @@ +@@ -1291,7 +1739,16 @@ @Override public void handleSetCarriedItem(PacketPlayInHeldItemSlot packetplayinhelditemslot) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinhelditemslot, this, this.player.serverLevel()); @@ -808,7 +759,7 @@ if (this.player.getInventory().selected != packetplayinhelditemslot.getSlot() && this.player.getUsedItemHand() == EnumHand.MAIN_HAND) { this.player.stopUsingItem(); } -@@ -1279,11 +1747,18 @@ +@@ -1300,11 +1757,18 @@ this.player.resetLastActionTime(); } else { PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString()); @@ -827,7 +778,7 @@ Optional optional = this.unpackAndApplyLastSeen(packetplayinchat.lastSeenMessages()); if (!optional.isEmpty()) { -@@ -1297,7 +1772,7 @@ +@@ -1318,7 +1782,7 @@ return; } @@ -836,7 +787,7 @@ IChatBaseComponent ichatbasecomponent = this.server.getChatDecorator().decorate(this.player, playerchatmessage.decoratedContent()); this.chatMessageChain.append(completablefuture, (filteredtext) -> { -@@ -1305,19 +1780,36 @@ +@@ -1326,19 +1790,36 @@ this.broadcastChatMessage(playerchatmessage1); }); @@ -875,7 +826,7 @@ ParseResults parseresults = this.parseCommand(s); if (this.server.enforceSecureProfile() && SignableCommand.hasSignableArguments(parseresults)) { -@@ -1334,19 +1826,37 @@ +@@ -1355,19 +1836,37 @@ if (!optional.isEmpty()) { this.tryHandleChat(serverboundchatcommandsignedpacket.command(), () -> { @@ -916,7 +867,7 @@ } catch (SignedMessageChain.a signedmessagechain_a) { this.handleMessageDecodeFailure(signedmessagechain_a); return; -@@ -1354,10 +1864,10 @@ +@@ -1375,10 +1874,10 @@ CommandSigningContext.a commandsigningcontext_a = new CommandSigningContext.a(map); @@ -929,7 +880,7 @@ } private void handleMessageDecodeFailure(SignedMessageChain.a signedmessagechain_a) { -@@ -1433,14 +1943,20 @@ +@@ -1454,14 +1953,20 @@ return com_mojang_brigadier_commanddispatcher.parse(s, this.player.createCommandSourceStack()); } @@ -953,7 +904,7 @@ } } -@@ -1469,6 +1985,116 @@ +@@ -1490,6 +1995,116 @@ return false; } @@ -1070,7 +1021,7 @@ private PlayerChatMessage getSignedMessage(PacketPlayInChat packetplayinchat, LastSeenMessages lastseenmessages) throws SignedMessageChain.a { SignedMessageBody signedmessagebody = new SignedMessageBody(packetplayinchat.message(), packetplayinchat.timeStamp(), packetplayinchat.salt(), lastseenmessages); -@@ -1476,13 +2102,33 @@ +@@ -1497,13 +2112,33 @@ } private void broadcastChatMessage(PlayerChatMessage playerchatmessage) { @@ -1098,16 +1049,16 @@ } private void detectRateSpam() { -- this.chatSpamTickCount += 20; -- if (this.chatSpamTickCount > 200 && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) { +- this.chatSpamThrottler.increment(); +- if (!this.chatSpamThrottler.isUnderThreshold() && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) { + // CraftBukkit start - replaced with thread safe throttle -+ // this.chatSpamTickCount += 20; -+ if (this.chatSpamTickCount.addAndGet(20) > 200 && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) { ++ // this.chatSpamThrottler.increment(); ++ if (!this.chatSpamThrottler.isIncrementAndUnderThreshold() && !this.server.getPlayerList().isOp(this.player.getGameProfile()) && !this.server.isSingleplayerOwner(this.player.getGameProfile())) { + // CraftBukkit end this.disconnect((IChatBaseComponent) IChatBaseComponent.translatable("disconnect.spam")); } -@@ -1504,13 +2150,62 @@ +@@ -1525,13 +2160,62 @@ @Override public void handleAnimate(PacketPlayInArmAnimation packetplayinarmanimation) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinarmanimation, this, this.player.serverLevel()); @@ -1170,7 +1121,7 @@ this.player.resetLastActionTime(); Entity entity; -@@ -1587,6 +2282,12 @@ +@@ -1608,6 +2292,12 @@ } public void sendPlayerChatMessage(PlayerChatMessage playerchatmessage, ChatMessageType.a chatmessagetype_a) { @@ -1183,7 +1134,7 @@ this.send(new ClientboundPlayerChatPacket(playerchatmessage.link().sender(), playerchatmessage.link().index(), playerchatmessage.signature(), playerchatmessage.signedBody().pack(this.messageSignatureCache), playerchatmessage.unsignedContent(), playerchatmessage.filterMask(), chatmessagetype_a)); this.addPendingMessage(playerchatmessage); } -@@ -1614,6 +2315,7 @@ +@@ -1635,6 +2325,7 @@ @Override public void handleInteract(PacketPlayInUseEntity packetplayinuseentity) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseentity, this, this.player.serverLevel()); @@ -1191,9 +1142,9 @@ final WorldServer worldserver = this.player.serverLevel(); final Entity entity = packetplayinuseentity.getTarget(worldserver); -@@ -1628,13 +2330,51 @@ +@@ -1649,13 +2340,51 @@ - if (this.player.canInteractWithEntity(axisalignedbb, 1.0D)) { + if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) { packetplayinuseentity.dispatch(new PacketPlayInUseEntity.c() { - private void performInteraction(EnumHand enumhand, PlayerConnection.a playerconnection_a) { + private void performInteraction(EnumHand enumhand, PlayerConnection.a playerconnection_a, PlayerInteractEntityEvent event) { // CraftBukkit @@ -1241,10 +1192,10 @@ + } + // CraftBukkit end + - if (enuminteractionresult.consumesAction()) { - CriterionTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(PlayerConnection.this.player, enuminteractionresult.indicateItemUse() ? itemstack1 : ItemStack.EMPTY, entity); - if (enuminteractionresult.shouldSwing()) { -@@ -1647,19 +2387,20 @@ + if (enuminteractionresult instanceof EnumInteractionResult.d) { + EnumInteractionResult.d enuminteractionresult_d = (EnumInteractionResult.d) enuminteractionresult; + ItemStack itemstack2 = enuminteractionresult_d.wasItemInteraction() ? itemstack1 : ItemStack.EMPTY; +@@ -1671,19 +2400,20 @@ @Override public void onInteraction(EnumHand enumhand) { @@ -1268,7 +1219,7 @@ label23: { if (entity instanceof EntityArrow) { -@@ -1677,6 +2418,11 @@ +@@ -1701,6 +2431,11 @@ } PlayerConnection.this.player.attack(entity); @@ -1280,28 +1231,30 @@ return; } } -@@ -1700,17 +2446,17 @@ +@@ -1724,7 +2459,7 @@ case PERFORM_RESPAWN: if (this.player.wonGame) { this.player.wonGame = false; - this.player = this.server.getPlayerList().respawn(this.player, true, Entity.RemovalReason.CHANGED_DIMENSION); + this.player = this.server.getPlayerList().respawn(this.player, true, Entity.RemovalReason.CHANGED_DIMENSION, RespawnReason.END_PORTAL); // CraftBukkit + this.resetPosition(); CriterionTriggers.CHANGED_DIMENSION.trigger(this.player, World.END, World.OVERWORLD); } else { - if (this.player.getHealth() > 0.0F) { +@@ -1732,11 +2467,11 @@ return; } - this.player = this.server.getPlayerList().respawn(this.player, false, Entity.RemovalReason.KILLED); + this.player = this.server.getPlayerList().respawn(this.player, false, Entity.RemovalReason.KILLED, RespawnReason.DEATH); // CraftBukkit + this.resetPosition(); if (this.server.isHardcore()) { this.player.setGameMode(EnumGamemode.SPECTATOR); -- ((GameRules.GameRuleBoolean) this.player.level().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.server); -+ ((GameRules.GameRuleBoolean) this.player.level().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.player.serverLevel()); // CraftBukkit - per-world +- ((GameRules.GameRuleBoolean) this.player.serverLevel().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.server); ++ ((GameRules.GameRuleBoolean) this.player.serverLevel().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.player.serverLevel()); // CraftBukkit - per-world } } break; -@@ -1723,15 +2469,21 @@ +@@ -1749,15 +2484,21 @@ @Override public void handleContainerClose(PacketPlayInCloseWindow packetplayinclosewindow) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinclosewindow, this, this.player.serverLevel()); @@ -1325,7 +1278,7 @@ this.player.containerMenu.sendAllDataToRemote(); } else if (!this.player.containerMenu.stillValid(this.player)) { PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu); -@@ -1744,7 +2496,284 @@ +@@ -1770,7 +2511,284 @@ boolean flag = packetplayinwindowclick.getStateId() != this.player.containerMenu.getStateId(); this.player.containerMenu.suppressRemoteUpdates(); @@ -1611,28 +1564,30 @@ ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packetplayinwindowclick.getChangedSlots()).iterator(); while (objectiterator.hasNext()) { -@@ -1774,9 +2803,18 @@ - if (!this.player.containerMenu.stillValid(this.player)) { - PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu); - } else { -- this.server.getRecipeManager().byKey(packetplayinautorecipe.getRecipe()).ifPresent((recipeholder) -> { -- ((ContainerRecipeBook) this.player.containerMenu).handlePlacement(packetplayinautorecipe.isShiftDown(), recipeholder, this.player); -+ // CraftBukkit start - implement PlayerRecipeBookClickEvent -+ org.bukkit.inventory.Recipe recipe = this.cserver.getRecipe(CraftNamespacedKey.fromMinecraft(packetplayinautorecipe.getRecipe())); -+ if (recipe == null) { -+ return; -+ } -+ org.bukkit.event.player.PlayerRecipeBookClickEvent event = CraftEventFactory.callRecipeBookClickEvent(this.player, recipe, packetplayinautorecipe.isShiftDown()); +@@ -1816,7 +2834,21 @@ + return; + } + +- ContainerRecipeBook.a containerrecipebook_a = containerrecipebook.handlePlacement(packetplayinautorecipe.useMaxItems(), this.player.isCreative(), recipeholder, this.player.serverLevel(), this.player.getInventory()); ++ // CraftBukkit start - implement PlayerRecipeBookClickEvent ++ org.bukkit.inventory.Recipe recipe = recipeholder.toBukkitRecipe(); ++ if (recipe == null) { ++ return; ++ } ++ org.bukkit.event.player.PlayerRecipeBookClickEvent event = CraftEventFactory.callRecipeBookClickEvent(this.player, recipe, packetplayinautorecipe.useMaxItems()); + -+ // Cast to keyed should be safe as the recipe will never be a MerchantRecipe. -+ this.server.getRecipeManager().byKey(CraftNamespacedKey.toMinecraft(((org.bukkit.Keyed) event.getRecipe()).getKey())).ifPresent((recipeholder) -> { -+ ((ContainerRecipeBook) this.player.containerMenu).handlePlacement(event.isShiftClick(), recipeholder, this.player); - }); -+ // CraftBukkit end - } - } - } -@@ -1784,6 +2822,7 @@ ++ // Cast to keyed should be safe as the recipe will never be a MerchantRecipe. ++ recipeholder = this.server.getRecipeManager().byKey(CraftRecipe.toMinecraft(((org.bukkit.Keyed) event.getRecipe()).getKey())).orElse(null); ++ if (recipeholder == null) { ++ return; ++ } ++ ++ ContainerRecipeBook.a containerrecipebook_a = containerrecipebook.handlePlacement(event.isShiftClick(), this.player.isCreative(), recipeholder, this.player.serverLevel(), this.player.getInventory()); ++ // CraftBukkit end + + if (containerrecipebook_a == ContainerRecipeBook.a.PLACE_GHOST_RECIPE) { + this.player.connection.send(new PacketPlayOutAutoRecipe(this.player.containerMenu.containerId, craftingmanager_d.display().display())); +@@ -1832,6 +2864,7 @@ @Override public void handleContainerButtonClick(PacketPlayInEnchantItem packetplayinenchantitem) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinenchantitem, this, this.player.serverLevel()); @@ -1640,7 +1595,7 @@ this.player.resetLastActionTime(); if (this.player.containerMenu.containerId == packetplayinenchantitem.containerId() && !this.player.isSpectator()) { if (!this.player.containerMenu.stillValid(this.player)) { -@@ -1826,6 +2865,43 @@ +@@ -1875,6 +2908,43 @@ boolean flag1 = packetplayinsetcreativeslot.slotNum() >= 1 && packetplayinsetcreativeslot.slotNum() <= 45; boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize(); @@ -1684,7 +1639,7 @@ if (flag1 && flag2) { this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.slotNum()).setByPlayer(itemstack); -@@ -1848,6 +2924,7 @@ +@@ -1902,6 +2972,7 @@ } private void updateSignText(PacketPlayInUpdateSign packetplayinupdatesign, List list) { @@ -1692,7 +1647,7 @@ this.player.resetLastActionTime(); WorldServer worldserver = this.player.serverLevel(); BlockPosition blockposition = packetplayinupdatesign.getPos(); -@@ -1869,7 +2946,17 @@ +@@ -1923,7 +2994,17 @@ @Override public void handlePlayerAbilities(PacketPlayInAbilities packetplayinabilities) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinabilities, this, this.player.serverLevel()); @@ -1711,7 +1666,7 @@ } @Override -@@ -1928,7 +3015,7 @@ +@@ -1982,7 +3063,7 @@ if (!this.waitingForSwitchToConfig) { throw new IllegalStateException("Client acknowledged config, but none was requested"); } else { @@ -1720,7 +1675,7 @@ } } -@@ -1953,8 +3040,10 @@ +@@ -2007,8 +3088,10 @@ }); } @@ -1732,4 +1687,4 @@ + // CraftBukkit end @Override - public EntityPlayer getPlayer() { + public void handleClientTickEnd(ServerboundClientTickEndPacket serverboundclienttickendpacket) { diff --git a/paper-server/nms-patches/net/minecraft/server/network/ServerCommonPacketListenerImpl.patch b/paper-server/nms-patches/net/minecraft/server/network/ServerCommonPacketListenerImpl.patch index a158caaaa2..53e150b2ba 100644 --- a/paper-server/nms-patches/net/minecraft/server/network/ServerCommonPacketListenerImpl.patch +++ b/paper-server/nms-patches/net/minecraft/server/network/ServerCommonPacketListenerImpl.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java +++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java -@@ -28,8 +28,44 @@ +@@ -29,8 +29,44 @@ import net.minecraft.util.thread.IAsyncTaskHandler; import org.slf4j.Logger; @@ -46,7 +46,7 @@ private static final Logger LOGGER = LogUtils.getLogger(); public static final int LATENCY_CHECK_INTERVAL = 15000; private static final int CLOSED_LISTENER_TIMEOUT = 15000; -@@ -46,12 +82,24 @@ +@@ -47,12 +83,24 @@ private int latency; private volatile boolean suspendFlushingOnServerThread = false; @@ -72,7 +72,7 @@ } private void close() { -@@ -73,6 +121,7 @@ +@@ -80,6 +128,7 @@ @Override public void handleKeepAlive(ServerboundKeepAlivePacket serverboundkeepalivepacket) { @@ -80,7 +80,7 @@ if (this.keepAlivePending && serverboundkeepalivepacket.getId() == this.keepAliveChallenge) { int i = (int) (SystemUtils.getMillis() - this.keepAliveTime); -@@ -87,8 +136,56 @@ +@@ -94,8 +143,56 @@ @Override public void handlePong(ServerboundPongPacket serverboundpongpacket) {} @@ -138,7 +138,7 @@ @Override public void handleResourcePackResponse(ServerboundResourcePackPacket serverboundresourcepackpacket) { -@@ -97,11 +194,18 @@ +@@ -104,11 +201,18 @@ ServerCommonPacketListenerImpl.LOGGER.info("Disconnecting {} due to resource pack {} rejection", this.playerProfile().getName(), serverboundresourcepackpacket.id()); this.disconnect((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.requiredTexturePrompt.disconnect")); } @@ -157,8 +157,8 @@ this.disconnect(ServerCommonPacketListenerImpl.DISCONNECT_UNEXPECTED_QUERY); } -@@ -109,7 +213,7 @@ - this.server.getProfiler().push("keepAlive"); +@@ -116,7 +220,7 @@ + Profiler.get().push("keepAlive"); long i = SystemUtils.getMillis(); - if (!this.isSingleplayerOwner() && i - this.keepAliveTime >= 15000L) { @@ -166,7 +166,7 @@ if (this.keepAlivePending) { this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE); } else if (this.checkIfClosed(i)) { -@@ -149,6 +253,14 @@ +@@ -156,6 +260,14 @@ } public void send(Packet packet, @Nullable PacketSendListener packetsendlistener) { @@ -181,7 +181,7 @@ if (packet.isTerminal()) { this.close(); } -@@ -173,15 +285,61 @@ +@@ -180,15 +292,61 @@ } public void disconnect(DisconnectionDetails disconnectiondetails) { diff --git a/paper-server/nms-patches/net/minecraft/server/players/PlayerList.patch b/paper-server/nms-patches/net/minecraft/server/players/PlayerList.patch index da2910eb70..f4b02439b8 100644 --- a/paper-server/nms-patches/net/minecraft/server/players/PlayerList.patch +++ b/paper-server/nms-patches/net/minecraft/server/players/PlayerList.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/players/PlayerList.java +++ b/net/minecraft/server/players/PlayerList.java -@@ -103,6 +103,27 @@ +@@ -104,6 +104,27 @@ import net.minecraft.world.scores.ScoreboardTeam; import org.slf4j.Logger; @@ -28,7 +28,7 @@ public abstract class PlayerList { public static final File USERBANLIST_FILE = new File("banned-players.json"); -@@ -115,14 +136,16 @@ +@@ -116,14 +137,16 @@ private static final int SEND_PLAYER_INFO_INTERVAL = 600; private static final SimpleDateFormat BAN_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z"); private final MinecraftServer server; @@ -48,7 +48,7 @@ public final WorldNBTStorage playerIo; private boolean doWhiteList; private final LayeredRegistryAccess registries; -@@ -133,13 +156,23 @@ +@@ -134,13 +157,23 @@ private static final boolean ALLOW_LOGOUTIVATOR = false; private int sendAllPlayerInfoIn; @@ -74,7 +74,7 @@ this.server = minecraftserver; this.registries = layeredregistryaccess; this.maxPlayers = i; -@@ -149,25 +182,34 @@ +@@ -150,25 +183,34 @@ public void placeNewPlayer(NetworkManager networkmanager, EntityPlayer entityplayer, CommonListenerCookie commonlistenercookie) { GameProfile gameprofile = entityplayer.getGameProfile(); UserCache usercache = this.server.getProfileCache(); @@ -114,7 +114,7 @@ WorldServer worldserver = this.server.getLevel(resourcekey); WorldServer worldserver1; -@@ -181,10 +223,11 @@ +@@ -182,10 +224,11 @@ entityplayer.setServerLevel(worldserver1); String s1 = networkmanager.getLoggableAddress(this.server.logIPs()); @@ -128,7 +128,7 @@ PlayerConnection playerconnection = new PlayerConnection(this.server, networkmanager, entityplayer, commonlistenercookie); networkmanager.setupInboundProtocol(GameProtocols.SERVERBOUND_TEMPLATE.bind(RegistryFriendlyByteBuf.decorator(this.server.registryAccess())), playerconnection); -@@ -194,6 +237,7 @@ +@@ -195,6 +238,7 @@ boolean flag2 = gamerules.getBoolean(GameRules.RULE_LIMITED_CRAFTING); playerconnection.send(new PacketPlayOutLogin(entityplayer.getId(), worlddata.isHardcore(), this.server.levelKeys(), this.getMaxPlayers(), this.viewDistance, this.simulationDistance, flag1, !flag, flag2, entityplayer.createCommonSpawnInfo(worldserver1), this.server.enforceSecureProfile())); @@ -136,7 +136,7 @@ playerconnection.send(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked())); playerconnection.send(new PacketPlayOutAbilities(entityplayer.getAbilities())); playerconnection.send(new PacketPlayOutHeldItemSlot(entityplayer.getInventory().selected)); -@@ -210,8 +254,10 @@ +@@ -213,8 +257,10 @@ } else { ichatmutablecomponent = IChatBaseComponent.translatable("multiplayer.player.joined.renamed", entityplayer.getDisplayName(), s); } @@ -148,7 +148,7 @@ playerconnection.teleport(entityplayer.getX(), entityplayer.getY(), entityplayer.getZ(), entityplayer.getYRot(), entityplayer.getXRot()); ServerPing serverping = this.server.getStatus(); -@@ -219,18 +265,70 @@ +@@ -222,17 +268,70 @@ entityplayer.sendServerStatus(serverping); } @@ -215,39 +215,15 @@ + worldserver1 = entityplayer.serverLevel(); // CraftBukkit - Update in case join event changed it + // CraftBukkit end this.sendActivePlayerEffects(entityplayer); - if (optional.isPresent() && ((NBTTagCompound) optional.get()).contains("RootVehicle", 10)) { - NBTTagCompound nbttagcompound = ((NBTTagCompound) optional.get()).getCompound("RootVehicle"); -+ WorldServer finalWorldServer = worldserver1; // CraftBukkit - decompile error - Entity entity = EntityTypes.loadEntityRecursive(nbttagcompound.getCompound("Entity"), worldserver1, (entity1) -> { -- return !worldserver1.addWithUUID(entity1) ? null : entity1; -+ return !finalWorldServer.addWithUUID(entity1) ? null : entity1; // CraftBukkit - decompile error - }); - - if (entity != null) { -@@ -261,18 +359,20 @@ - - if (!entityplayer.isPassenger()) { - PlayerList.LOGGER.warn("Couldn't reattach entity to player"); -- entity.discard(); -+ entity.discard(null); // CraftBukkit - add Bukkit remove cause - iterator = entity.getIndirectPassengers().iterator(); - - while (iterator.hasNext()) { - entity1 = (Entity) iterator.next(); -- entity1.discard(); -+ entity1.discard(null); // CraftBukkit - add Bukkit remove cause - } - } - } - } - + entityplayer.loadAndSpawnEnderpearls(optional); + entityplayer.loadAndSpawnParentVehicle(optional); entityplayer.initInventoryMenu(); + // CraftBukkit - Moved from above, added world + PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", entityplayer.getName().getString(), s1, entityplayer.getId(), worldserver1.serverLevelData.getLevelName(), entityplayer.getX(), entityplayer.getY(), entityplayer.getZ()); } public void updateEntireScoreboard(ScoreboardServer scoreboardserver, EntityPlayer entityplayer) { -@@ -309,30 +409,31 @@ +@@ -269,30 +368,31 @@ } public void addWorldborderListener(WorldServer worldserver) { @@ -284,7 +260,7 @@ } @Override -@@ -359,14 +460,15 @@ +@@ -319,14 +419,15 @@ } protected void save(EntityPlayer entityplayer) { @@ -302,7 +278,7 @@ if (advancementdataplayer != null) { advancementdataplayer.save(); -@@ -374,10 +476,24 @@ +@@ -334,10 +435,24 @@ } @@ -328,7 +304,7 @@ this.save(entityplayer); if (entityplayer.isPassenger()) { Entity entity = entityplayer.getRootVehicle(); -@@ -386,7 +502,7 @@ +@@ -346,7 +461,7 @@ PlayerList.LOGGER.debug("Removing player mount"); entityplayer.stopRiding(); entity.getPassengersAndSelf().forEach((entity1) -> { @@ -337,7 +313,16 @@ }); } } -@@ -401,17 +517,66 @@ +@@ -357,7 +472,7 @@ + while (iterator.hasNext()) { + EntityEnderPearl entityenderpearl = (EntityEnderPearl) iterator.next(); + +- entityenderpearl.setRemoved(Entity.RemovalReason.UNLOADED_WITH_PLAYER); ++ entityenderpearl.setRemoved(Entity.RemovalReason.UNLOADED_WITH_PLAYER, EntityRemoveEvent.Cause.PLAYER_QUIT); // CraftBukkit - add Bukkit remove cause + } + + worldserver.removePlayerImmediately(entityplayer, Entity.RemovalReason.UNLOADED_WITH_PLAYER); +@@ -369,17 +484,66 @@ if (entityplayer1 == entityplayer) { this.playersByUUID.remove(uuid); @@ -409,7 +394,7 @@ if (this.bans.isBanned(gameprofile)) { GameProfileBanEntry gameprofilebanentry = (GameProfileBanEntry) this.bans.get(gameprofile); -@@ -420,9 +585,11 @@ +@@ -388,9 +552,11 @@ ichatmutablecomponent.append((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.banned.expiration", PlayerList.BAN_DATE_FORMAT.format(gameprofilebanentry.getExpires()))); } @@ -423,7 +408,7 @@ } else if (this.ipBans.isBanned(socketaddress)) { IpBanEntry ipbanentry = this.ipBans.get(socketaddress); -@@ -431,17 +598,32 @@ +@@ -399,17 +565,32 @@ ichatmutablecomponent.append((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.banned_ip.expiration", PlayerList.BAN_DATE_FORMAT.format(ipbanentry.getExpires()))); } @@ -436,13 +421,13 @@ + if (this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile)) { + event.disallow(PlayerLoginEvent.Result.KICK_FULL, "The server is full"); + } -+ } + } + + cserver.getPluginManager().callEvent(event); + if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) { + loginlistener.disconnect(event.getKickMessage()); + return null; - } ++ } + return entity; } @@ -461,7 +446,7 @@ UUID uuid = gameprofile.getId(); Set set = Sets.newIdentityHashSet(); Iterator iterator = this.players.iterator(); -@@ -469,22 +651,41 @@ +@@ -437,22 +618,41 @@ } return !set.isEmpty(); @@ -481,8 +466,8 @@ this.players.remove(entityplayer); entityplayer.serverLevel().removePlayerImmediately(entityplayer, entity_removalreason); + /* CraftBukkit start - DimensionTransition dimensiontransition = entityplayer.findRespawnPositionAndUseSpawnBlock(flag, DimensionTransition.DO_NOTHING); - WorldServer worldserver = dimensiontransition.newLevel(); + TeleportTransition teleporttransition = entityplayer.findRespawnPositionAndUseSpawnBlock(!flag, TeleportTransition.DO_NOTHING); + WorldServer worldserver = teleporttransition.newLevel(); EntityPlayer entityplayer1 = new EntityPlayer(this.server, worldserver, entityplayer.getGameProfile(), entityplayer.clientInformation()); + // */ + EntityPlayer entityplayer1 = entityplayer; @@ -496,7 +481,7 @@ entityplayer1.setMainArm(entityplayer.getMainArm()); + // CraftBukkit - not required, just copies old location into reused entity + /* - if (!dimensiontransition.missingRespawnBlock()) { + if (!teleporttransition.missingRespawnBlock()) { entityplayer1.copyRespawnPosition(entityplayer); } + */ @@ -504,35 +489,35 @@ Iterator iterator = entityplayer.getTags().iterator(); -@@ -494,11 +695,26 @@ +@@ -462,11 +662,26 @@ entityplayer1.addTag(s); } + // CraftBukkit start - fire PlayerRespawnEvent -+ DimensionTransition dimensiontransition; ++ TeleportTransition teleporttransition; + if (location == null) { -+ dimensiontransition = entityplayer.findRespawnPositionAndUseSpawnBlock(flag, DimensionTransition.DO_NOTHING, reason); ++ teleporttransition = entityplayer.findRespawnPositionAndUseSpawnBlock(!flag, TeleportTransition.DO_NOTHING, reason); + + if (!flag) entityplayer.reset(); // SPIGOT-4785 + } else { -+ dimensiontransition = new DimensionTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), Vec3D.ZERO, location.getYaw(), location.getPitch(), DimensionTransition.DO_NOTHING); ++ teleporttransition = new TeleportTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), Vec3D.ZERO, location.getYaw(), location.getPitch(), TeleportTransition.DO_NOTHING); + } -+ WorldServer worldserver = dimensiontransition.newLevel(); ++ WorldServer worldserver = teleporttransition.newLevel(); + entityplayer1.spawnIn(worldserver); + entityplayer1.unsetRemoved(); + entityplayer1.setShiftKeyDown(false); - Vec3D vec3d = dimensiontransition.pos(); + Vec3D vec3d = teleporttransition.position(); -- entityplayer1.moveTo(vec3d.x, vec3d.y, vec3d.z, dimensiontransition.yRot(), dimensiontransition.xRot()); -+ entityplayer1.forceSetPositionRotation(vec3d.x, vec3d.y, vec3d.z, dimensiontransition.yRot(), dimensiontransition.xRot()); +- entityplayer1.moveTo(vec3d.x, vec3d.y, vec3d.z, teleporttransition.yRot(), teleporttransition.xRot()); ++ entityplayer1.forceSetPositionRotation(vec3d.x, vec3d.y, vec3d.z, teleporttransition.yRot(), teleporttransition.xRot()); + // CraftBukkit end - if (dimensiontransition.missingRespawnBlock()) { + if (teleporttransition.missingRespawnBlock()) { entityplayer1.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.NO_RESPAWN_BLOCK_AVAILABLE, 0.0F)); + entityplayer1.setRespawnPosition(null, null, 0f, false, false, PlayerSpawnChangeEvent.Cause.RESET); // CraftBukkit - SPIGOT-5988: Clear respawn location when obstructed } int i = flag ? 1 : 0; -@@ -506,17 +722,19 @@ +@@ -474,17 +689,19 @@ WorldData worlddata = worldserver1.getLevelData(); entityplayer1.connection.send(new PacketPlayOutRespawn(entityplayer1.createCommonSpawnInfo(worldserver1), (byte) i)); @@ -555,9 +540,9 @@ + } + // entityplayer1.initInventoryMenu(); entityplayer1.setHealth(entityplayer1.getHealth()); - if (!flag) { - BlockPosition blockposition = BlockPosition.containing(dimensiontransition.pos()); -@@ -526,6 +744,27 @@ + BlockPosition blockposition = entityplayer1.getRespawnPosition(); + WorldServer worldserver2 = this.server.getLevel(entityplayer1.getRespawnDimension()); +@@ -496,6 +713,27 @@ entityplayer1.connection.send(new PacketPlayOutNamedSoundEffect(SoundEffects.RESPAWN_ANCHOR_DEPLETE, SoundCategory.BLOCKS, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), 1.0F, 1.0F, worldserver.getRandom().nextLong())); } } @@ -585,7 +570,7 @@ return entityplayer1; } -@@ -554,7 +793,18 @@ +@@ -524,7 +762,18 @@ public void tick() { if (++this.sendAllPlayerInfoIn > 600) { @@ -605,7 +590,7 @@ this.sendAllPlayerInfoIn = 0; } -@@ -571,6 +821,25 @@ +@@ -541,6 +790,25 @@ } @@ -631,7 +616,7 @@ public void broadcastAll(Packet packet, ResourceKey resourcekey) { Iterator iterator = this.players.iterator(); -@@ -649,7 +918,7 @@ +@@ -619,7 +887,7 @@ } public void deop(GameProfile gameprofile) { @@ -640,7 +625,7 @@ EntityPlayer entityplayer = this.getPlayer(gameprofile.getId()); if (entityplayer != null) { -@@ -673,6 +942,7 @@ +@@ -643,6 +911,7 @@ entityplayer.connection.send(new PacketPlayOutEntityStatus(entityplayer, b0)); } @@ -648,7 +633,7 @@ this.server.getCommands().sendCommands(entityplayer); } -@@ -703,6 +973,12 @@ +@@ -673,6 +942,12 @@ for (int i = 0; i < this.players.size(); ++i) { EntityPlayer entityplayer = (EntityPlayer) this.players.get(i); @@ -661,7 +646,7 @@ if (entityplayer != entityhuman && entityplayer.level().dimension() == resourcekey) { double d4 = d0 - entityplayer.getX(); double d5 = d1 - entityplayer.getY(); -@@ -742,15 +1018,19 @@ +@@ -712,15 +987,19 @@ public void reloadWhiteList() {} public void sendLevelInfo(EntityPlayer entityplayer, WorldServer worldserver) { @@ -685,7 +670,7 @@ } entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.LEVEL_CHUNKS_LOAD_START, 0.0F)); -@@ -759,8 +1039,16 @@ +@@ -729,8 +1008,16 @@ public void sendAllPlayerInfo(EntityPlayer entityplayer) { entityplayer.inventoryMenu.sendAllDataToRemote(); @@ -695,15 +680,15 @@ + entityplayer.refreshEntityData(entityplayer); // CraftBukkkit - SPIGOT-7218: sync metadata entityplayer.connection.send(new PacketPlayOutHeldItemSlot(entityplayer.getInventory().selected)); + // CraftBukkit start - from GameRules -+ int i = entityplayer.level().getGameRules().getBoolean(GameRules.RULE_REDUCEDDEBUGINFO) ? 22 : 23; ++ int i = entityplayer.serverLevel().getGameRules().getBoolean(GameRules.RULE_REDUCEDDEBUGINFO) ? 22 : 23; + entityplayer.connection.send(new PacketPlayOutEntityStatus(entityplayer, (byte) i)); -+ float immediateRespawn = entityplayer.level().getGameRules().getBoolean(GameRules.RULE_DO_IMMEDIATE_RESPAWN) ? 1.0F: 0.0F; ++ float immediateRespawn = entityplayer.serverLevel().getGameRules().getBoolean(GameRules.RULE_DO_IMMEDIATE_RESPAWN) ? 1.0F: 0.0F; + entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.IMMEDIATE_RESPAWN, immediateRespawn)); + // CraftBukkit end } public int getPlayerCount() { -@@ -816,12 +1104,22 @@ +@@ -786,12 +1073,22 @@ } public void removeAll() { @@ -728,7 +713,7 @@ public void broadcastSystemMessage(IChatBaseComponent ichatbasecomponent, boolean flag) { this.broadcastSystemMessage(ichatbasecomponent, (entityplayer) -> { return ichatbasecomponent; -@@ -879,16 +1177,23 @@ +@@ -849,16 +1146,23 @@ return playerchatmessage.hasSignature() && !playerchatmessage.hasExpiredServer(Instant.now()); } @@ -756,7 +741,7 @@ Path path = file2.toPath(); if (FileUtils.isPathNormalized(path) && FileUtils.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) { -@@ -897,7 +1202,7 @@ +@@ -867,7 +1171,7 @@ } serverstatisticmanager = new ServerStatisticManager(this.server, file1); @@ -765,7 +750,7 @@ } return serverstatisticmanager; -@@ -905,13 +1210,13 @@ +@@ -875,13 +1179,13 @@ public AdvancementDataPlayer getPlayerAdvancements(EntityPlayer entityplayer) { UUID uuid = entityplayer.getUUID(); @@ -781,7 +766,7 @@ } advancementdataplayer.setPlayer(entityplayer); -@@ -962,13 +1267,20 @@ +@@ -932,13 +1236,20 @@ } public void reloadResources() { @@ -802,4 +787,4 @@ + // CraftBukkit end this.broadcastAll(new ClientboundUpdateTagsPacket(TagNetworkSerialization.serializeTagsToNetwork(this.registries))); - PacketPlayOutRecipeUpdate packetplayoutrecipeupdate = new PacketPlayOutRecipeUpdate(this.server.getRecipeManager().getOrderedRecipes()); + CraftingManager craftingmanager = this.server.getRecipeManager(); diff --git a/paper-server/nms-patches/net/minecraft/stats/RecipeBookServer.patch b/paper-server/nms-patches/net/minecraft/stats/RecipeBookServer.patch index 82d48407a1..38c18d2127 100644 --- a/paper-server/nms-patches/net/minecraft/stats/RecipeBookServer.patch +++ b/paper-server/nms-patches/net/minecraft/stats/RecipeBookServer.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/stats/RecipeBookServer.java +++ b/net/minecraft/stats/RecipeBookServer.java -@@ -20,6 +20,8 @@ - import net.minecraft.world.item.crafting.RecipeHolder; +@@ -29,6 +29,8 @@ + import net.minecraft.world.item.crafting.display.RecipeDisplayId; import org.slf4j.Logger; +import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit @@ -9,20 +9,30 @@ public class RecipeBookServer extends RecipeBook { public static final String RECIPE_BOOK_TAG = "recipeBook"; -@@ -36,7 +38,7 @@ +@@ -72,7 +74,7 @@ RecipeHolder recipeholder = (RecipeHolder) iterator.next(); - MinecraftKey minecraftkey = recipeholder.id(); + ResourceKey> resourcekey = recipeholder.id(); -- if (!this.known.contains(minecraftkey) && !recipeholder.value().isSpecial()) { -+ if (!this.known.contains(minecraftkey) && !recipeholder.value().isSpecial() && CraftEventFactory.handlePlayerRecipeListUpdateEvent(entityplayer, minecraftkey)) { // CraftBukkit - this.add(minecraftkey); - this.addHighlight(minecraftkey); - list.add(minecraftkey); -@@ -73,6 +75,7 @@ - } +- if (!this.known.contains(resourcekey) && !recipeholder.value().isSpecial()) { ++ if (!this.known.contains(resourcekey) && !recipeholder.value().isSpecial() && CraftEventFactory.handlePlayerRecipeListUpdateEvent(entityplayer, resourcekey.location())) { // CraftBukkit + this.add(resourcekey); + this.addHighlight(resourcekey); + this.displayResolver.displaysForRecipe(resourcekey, (recipedisplayentry) -> { +@@ -82,7 +84,7 @@ + } + } - private void sendRecipes(PacketPlayOutRecipes.Action packetplayoutrecipes_action, EntityPlayer entityplayer, List list) { -+ if (entityplayer.connection == null) return; // SPIGOT-4478 during PlayerLoginEvent - entityplayer.connection.send(new PacketPlayOutRecipes(packetplayoutrecipes_action, list, Collections.emptyList(), this.getBookSettings())); - } +- if (!list.isEmpty()) { ++ if (!list.isEmpty() && entityplayer.connection != null) { // SPIGOT-4478 during PlayerLoginEvent + entityplayer.connection.send(new ClientboundRecipeBookAddPacket(list, false)); + } + +@@ -105,7 +107,7 @@ + } + } + +- if (!list.isEmpty()) { ++ if (!list.isEmpty() && entityplayer.connection != null) { // SPIGOT-4478 during PlayerLoginEvent + entityplayer.connection.send(new ClientboundRecipeBookRemovePacket(list)); + } diff --git a/paper-server/nms-patches/net/minecraft/util/SpawnUtil.patch b/paper-server/nms-patches/net/minecraft/util/SpawnUtil.patch index 7ac5d4fa30..47da6b1143 100644 --- a/paper-server/nms-patches/net/minecraft/util/SpawnUtil.patch +++ b/paper-server/nms-patches/net/minecraft/util/SpawnUtil.patch @@ -1,27 +1,27 @@ --- a/net/minecraft/util/SpawnUtil.java +++ b/net/minecraft/util/SpawnUtil.java -@@ -20,6 +20,12 @@ +@@ -21,6 +21,12 @@ public SpawnUtil() {} - public static Optional trySpawnMob(EntityTypes entitytypes, EnumMobSpawn enummobspawn, WorldServer worldserver, BlockPosition blockposition, int i, int j, int k, SpawnUtil.a spawnutil_a) { + public static Optional trySpawnMob(EntityTypes entitytypes, EntitySpawnReason entityspawnreason, WorldServer worldserver, BlockPosition blockposition, int i, int j, int k, SpawnUtil.a spawnutil_a) { + // CraftBukkit start -+ return trySpawnMob(entitytypes, enummobspawn, worldserver, blockposition, i, j, k, spawnutil_a, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT); ++ return trySpawnMob(entitytypes, entityspawnreason, worldserver, blockposition, i, j, k, spawnutil_a, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT); + } + -+ public static Optional trySpawnMob(EntityTypes entitytypes, EnumMobSpawn enummobspawn, WorldServer worldserver, BlockPosition blockposition, int i, int j, int k, SpawnUtil.a spawnutil_a, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) { ++ public static Optional trySpawnMob(EntityTypes entitytypes, EntitySpawnReason entityspawnreason, WorldServer worldserver, BlockPosition blockposition, int i, int j, int k, SpawnUtil.a spawnutil_a, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason reason) { + // CraftBukkit end BlockPosition.MutableBlockPosition blockposition_mutableblockposition = blockposition.mutable(); for (int l = 0; l < i; ++l) { -@@ -28,15 +34,15 @@ +@@ -29,15 +35,15 @@ blockposition_mutableblockposition.setWithOffset(blockposition, i1, k, j1); if (worldserver.getWorldBorder().isWithinBounds((BlockPosition) blockposition_mutableblockposition) && moveToPossibleSpawnPosition(worldserver, k, blockposition_mutableblockposition, spawnutil_a)) { -- T t0 = (EntityInsentient) entitytypes.create(worldserver, (Consumer) null, blockposition_mutableblockposition, enummobspawn, false, false); -+ T t0 = entitytypes.create(worldserver, (Consumer) null, blockposition_mutableblockposition, enummobspawn, false, false); // CraftBukkit - decompile error +- T t0 = (EntityInsentient) entitytypes.create(worldserver, (Consumer) null, blockposition_mutableblockposition, entityspawnreason, false, false); ++ T t0 = entitytypes.create(worldserver, (Consumer) null, blockposition_mutableblockposition, entityspawnreason, false, false); // CraftBukkit - decompile error if (t0 != null) { - if (t0.checkSpawnRules(worldserver, enummobspawn) && t0.checkSpawnObstruction(worldserver)) { + if (t0.checkSpawnRules(worldserver, entityspawnreason) && t0.checkSpawnObstruction(worldserver)) { - worldserver.addFreshEntityWithPassengers(t0); + worldserver.addFreshEntityWithPassengers(t0, reason); // CraftBukkit return Optional.of(t0); diff --git a/paper-server/nms-patches/net/minecraft/util/TickThrottler.patch b/paper-server/nms-patches/net/minecraft/util/TickThrottler.patch new file mode 100644 index 0000000000..38e6ddbc1a --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/util/TickThrottler.patch @@ -0,0 +1,53 @@ +--- a/net/minecraft/util/TickThrottler.java ++++ b/net/minecraft/util/TickThrottler.java +@@ -1,10 +1,14 @@ + package net.minecraft.util; + ++// CraftBukkit start ++import java.util.concurrent.atomic.AtomicInteger; ++// CraftBukkit end ++ + public class TickThrottler { + + private final int incrementStep; + private final int threshold; +- private int count; ++ private final AtomicInteger count = new AtomicInteger(); // CraftBukkit - multithreaded field + + public TickThrottler(int i, int j) { + this.incrementStep = i; +@@ -12,17 +16,32 @@ + } + + public void increment() { +- this.count += this.incrementStep; ++ this.count.addAndGet(this.incrementStep); // CraftBukkit - use thread-safe field access instead + } + + public void tick() { ++ // CraftBukkit start ++ for (int val; (val = this.count.get()) > 0 && !count.compareAndSet(val, val - 1); ) ; ++ /* Use thread-safe field access instead + if (this.count > 0) { + --this.count; + } ++ */ ++ // CraftBukkit end + + } + + public boolean isUnderThreshold() { +- return this.count < this.threshold; ++ // CraftBukkit start - use thread-safe field access instead ++ return this.count.get() < this.threshold; ++ } ++ ++ public boolean isIncrementAndUnderThreshold() { ++ return isIncrementAndUnderThreshold(this.incrementStep, this.threshold); ++ } ++ ++ public boolean isIncrementAndUnderThreshold(int incrementStep, int threshold) { ++ return this.count.addAndGet(incrementStep) < threshold; ++ // CraftBukkit end + } + } diff --git a/paper-server/nms-patches/net/minecraft/util/datafix/DataConverterRegistry.patch b/paper-server/nms-patches/net/minecraft/util/datafix/DataConverterRegistry.patch index ebbba19e01..1148881f24 100644 --- a/paper-server/nms-patches/net/minecraft/util/datafix/DataConverterRegistry.patch +++ b/paper-server/nms-patches/net/minecraft/util/datafix/DataConverterRegistry.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/util/datafix/DataConverterRegistry.java +++ b/net/minecraft/util/datafix/DataConverterRegistry.java -@@ -495,6 +495,18 @@ +@@ -510,6 +510,18 @@ datafixerbuilder.addFixer(new DataConverterItemFrame(schema44, false)); Schema schema45 = datafixerbuilder.addSchema(1458, DataConverterRegistry.SAME_NAMESPACED); @@ -19,7 +19,7 @@ datafixerbuilder.addFixer(new DataConverterCustomNameEntity(schema45, false)); datafixerbuilder.addFixer(new DataConverterCustomNameItem(schema45, false)); datafixerbuilder.addFixer(new DataConverterCustomNameTile(schema45, false)); -@@ -753,7 +765,8 @@ +@@ -768,7 +780,8 @@ datafixerbuilder.addFixer(new DataConverterAddChoices(schema110, "Added Zoglin", DataConverterTypes.ENTITY)); Schema schema111 = datafixerbuilder.addSchema(2523, DataConverterRegistry.SAME_NAMESPACED); @@ -29,7 +29,7 @@ Schema schema112 = datafixerbuilder.addSchema(2527, DataConverterRegistry.SAME_NAMESPACED); datafixerbuilder.addFixer(new DataConverterBitStorageAlign(schema112)); -@@ -816,12 +829,14 @@ +@@ -831,12 +844,14 @@ datafixerbuilder.addFixer(new DataConverterAddChoices(schema130, "Added Glow Squid", DataConverterTypes.ENTITY)); datafixerbuilder.addFixer(new DataConverterAddChoices(schema130, "Added Glow Item Frame", DataConverterTypes.ENTITY)); Schema schema131 = datafixerbuilder.addSchema(2690, DataConverterRegistry.SAME_NAMESPACED); @@ -46,7 +46,7 @@ datafixerbuilder.addFixer(DataConverterItemName.create(schema132, "Rename copper item suffixes", createRenamer(immutablemap1))); datafixerbuilder.addFixer(DataConverterBlockRename.create(schema132, "Rename copper blocks suffixes", createRenamer(immutablemap1))); -@@ -829,7 +844,8 @@ +@@ -844,7 +859,8 @@ datafixerbuilder.addFixer(new AddFlagIfNotPresentFix(schema133, DataConverterTypes.WORLD_GEN_SETTINGS, "has_increased_height_already", false)); Schema schema134 = datafixerbuilder.addSchema(2696, DataConverterRegistry.SAME_NAMESPACED); @@ -56,7 +56,7 @@ datafixerbuilder.addFixer(DataConverterItemName.create(schema134, "Renamed grimstone block items to deepslate", createRenamer(immutablemap2))); datafixerbuilder.addFixer(DataConverterBlockRename.create(schema134, "Renamed grimstone blocks to deepslate", createRenamer(immutablemap2))); -@@ -916,10 +932,11 @@ +@@ -931,10 +947,11 @@ datafixerbuilder.addFixer(new DataConverterAddChoices(schema159, "Added Allay", DataConverterTypes.ENTITY)); Schema schema160 = datafixerbuilder.addSchema(3084, DataConverterRegistry.SAME_NAMESPACED); @@ -70,7 +70,7 @@ int2objectopenhashmap1.defaultReturnValue("minecraft:tabby"); int2objectopenhashmap1.put(0, "minecraft:tabby"); int2objectopenhashmap1.put(1, "minecraft:black"); -@@ -936,7 +953,8 @@ +@@ -951,7 +968,8 @@ Objects.requireNonNull(int2objectopenhashmap); datafixerbuilder.addFixer(new EntityVariantFix(schema161, "Change cat variant type", typereference, "minecraft:cat", "CatType", int2objectopenhashmap::get)); diff --git a/paper-server/nms-patches/net/minecraft/util/worldupdate/WorldUpgrader.patch b/paper-server/nms-patches/net/minecraft/util/worldupdate/WorldUpgrader.patch index 05b7105fd5..722e0a99b1 100644 --- a/paper-server/nms-patches/net/minecraft/util/worldupdate/WorldUpgrader.patch +++ b/paper-server/nms-patches/net/minecraft/util/worldupdate/WorldUpgrader.patch @@ -1,18 +1,18 @@ --- a/net/minecraft/util/worldupdate/WorldUpgrader.java +++ b/net/minecraft/util/worldupdate/WorldUpgrader.java -@@ -81,7 +81,7 @@ +@@ -80,7 +80,7 @@ public WorldUpgrader(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, IRegistryCustom iregistrycustom, boolean flag, boolean flag1) { - this.dimensions = iregistrycustom.registryOrThrow(Registries.LEVEL_STEM); + this.dimensions = iregistrycustom.lookupOrThrow(Registries.LEVEL_STEM); - this.levels = (Set) this.dimensions.registryKeySet().stream().map(Registries::levelStemToLevel).collect(Collectors.toUnmodifiableSet()); + this.levels = (Set) java.util.stream.Stream.of(convertable_conversionsession.dimensionType).map(Registries::levelStemToLevel).collect(Collectors.toUnmodifiableSet()); // CraftBukkit this.eraseCache = flag; this.dataFixer = datafixer; this.levelStorage = convertable_conversionsession; -@@ -194,9 +194,9 @@ +@@ -197,9 +197,9 @@ if (nbttagcompound != null) { int i = IChunkLoader.getVersion(nbttagcompound); - ChunkGenerator chunkgenerator = ((WorldDimension) WorldUpgrader.this.dimensions.getOrThrow(Registries.levelToLevelStem(resourcekey))).generator(); + ChunkGenerator chunkgenerator = ((WorldDimension) WorldUpgrader.this.dimensions.getValueOrThrow(Registries.levelToLevelStem(resourcekey))).generator(); - NBTTagCompound nbttagcompound1 = ichunkloader.upgradeChunkTag(resourcekey, () -> { + NBTTagCompound nbttagcompound1 = ichunkloader.upgradeChunkTag(Registries.levelToLevelStem(resourcekey), () -> { // CraftBukkit return WorldUpgrader.this.overworldDataStorage; @@ -21,7 +21,7 @@ ChunkCoordIntPair chunkcoordintpair1 = new ChunkCoordIntPair(nbttagcompound1.getInt("xPos"), nbttagcompound1.getInt("zPos")); if (!chunkcoordintpair1.equals(chunkcoordintpair)) { -@@ -316,7 +316,7 @@ +@@ -321,7 +321,7 @@ WorldUpgrader.c worldupgrader_c = (WorldUpgrader.c) iterator.next(); ResourceKey resourcekey = worldupgrader_c.dimensionKey; ListIterator listiterator = worldupgrader_c.files; diff --git a/paper-server/nms-patches/net/minecraft/world/ChestLock.patch b/paper-server/nms-patches/net/minecraft/world/ChestLock.patch deleted file mode 100644 index a6fe4a98bb..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/ChestLock.patch +++ /dev/null @@ -1,35 +0,0 @@ ---- a/net/minecraft/world/ChestLock.java -+++ b/net/minecraft/world/ChestLock.java -@@ -6,6 +6,11 @@ - import net.minecraft.network.chat.IChatBaseComponent; - import net.minecraft.world.item.ItemStack; - -+// CraftBukkit start -+import org.bukkit.ChatColor; -+import org.bukkit.craftbukkit.util.CraftChatMessage; -+// CraftBukkit end -+ - public record ChestLock(String key) { - - public static final ChestLock NO_LOCK = new ChestLock(""); -@@ -18,7 +23,19 @@ - } else { - IChatBaseComponent ichatbasecomponent = (IChatBaseComponent) itemstack.get(DataComponents.CUSTOM_NAME); - -- return ichatbasecomponent != null && this.key.equals(ichatbasecomponent.getString()); -+ // CraftBukkit start - SPIGOT-6307: Check for color codes if the lock contains color codes -+ if (this.key.isEmpty()) return true; -+ if (ichatbasecomponent != null) { -+ if (this.key.indexOf(ChatColor.COLOR_CHAR) == -1) { -+ // The lock key contains no color codes, so let's ignore colors in the item display name (vanilla Minecraft behavior): -+ return this.key.equals(ichatbasecomponent.getString()); -+ } else { -+ // The lock key contains color codes, so let's take them into account: -+ return this.key.equals(CraftChatMessage.fromComponent(ichatbasecomponent)); -+ } -+ } -+ return false; -+ // CraftBukkit end - } - } - diff --git a/paper-server/nms-patches/net/minecraft/world/damagesource/DamageSources.patch b/paper-server/nms-patches/net/minecraft/world/damagesource/DamageSources.patch index 86fc05e293..2397a45a46 100644 --- a/paper-server/nms-patches/net/minecraft/world/damagesource/DamageSources.patch +++ b/paper-server/nms-patches/net/minecraft/world/damagesource/DamageSources.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/damagesource/DamageSources.java +++ b/net/minecraft/world/damagesource/DamageSources.java -@@ -42,9 +42,15 @@ +@@ -43,9 +43,15 @@ private final DamageSource stalagmite; private final DamageSource outsideBorder; private final DamageSource genericKill; @@ -9,15 +9,15 @@ + private final DamageSource poison; public DamageSources(IRegistryCustom iregistrycustom) { - this.damageTypes = iregistrycustom.registryOrThrow(Registries.DAMAGE_TYPE); + this.damageTypes = iregistrycustom.lookupOrThrow(Registries.DAMAGE_TYPE); + this.melting = this.source(DamageTypes.ON_FIRE).melting(); + this.poison = this.source(DamageTypes.MAGIC).poison(); + // CraftBukkit end this.inFire = this.source(DamageTypes.IN_FIRE); this.campfire = this.source(DamageTypes.CAMPFIRE); this.lightningBolt = this.source(DamageTypes.LIGHTNING_BOLT); -@@ -83,6 +89,16 @@ - return new DamageSource(this.damageTypes.getHolderOrThrow(resourcekey), entity, entity1); +@@ -85,6 +91,16 @@ + return new DamageSource(this.damageTypes.getOrThrow(resourcekey), entity, entity1); } + // CraftBukkit start @@ -33,7 +33,7 @@ public DamageSource inFire() { return this.inFire; } -@@ -248,7 +264,13 @@ +@@ -254,7 +270,13 @@ } public DamageSource explosion(@Nullable Entity entity, @Nullable Entity entity1) { @@ -48,17 +48,17 @@ } public DamageSource sonicBoom(Entity entity) { -@@ -256,7 +278,13 @@ +@@ -262,7 +284,13 @@ } public DamageSource badRespawnPointExplosion(Vec3D vec3d) { -- return new DamageSource(this.damageTypes.getHolderOrThrow(DamageTypes.BAD_RESPAWN_POINT), vec3d); +- return new DamageSource(this.damageTypes.getOrThrow(DamageTypes.BAD_RESPAWN_POINT), vec3d); + // CraftBukkit start + return badRespawnPointExplosion(vec3d, null); + } + + public DamageSource badRespawnPointExplosion(Vec3D vec3d, org.bukkit.block.BlockState blockState) { -+ return new DamageSource(this.damageTypes.getHolderOrThrow(DamageTypes.BAD_RESPAWN_POINT), vec3d).directBlockState(blockState); ++ return new DamageSource(this.damageTypes.getOrThrow(DamageTypes.BAD_RESPAWN_POINT), vec3d).directBlockState(blockState); + // CraftBukkit end } diff --git a/paper-server/nms-patches/net/minecraft/world/effect/HealOrHarmMobEffect.patch b/paper-server/nms-patches/net/minecraft/world/effect/HealOrHarmMobEffect.patch index 539a08569e..f6f2811028 100644 --- a/paper-server/nms-patches/net/minecraft/world/effect/HealOrHarmMobEffect.patch +++ b/paper-server/nms-patches/net/minecraft/world/effect/HealOrHarmMobEffect.patch @@ -1,15 +1,15 @@ --- a/net/minecraft/world/effect/HealOrHarmMobEffect.java +++ b/net/minecraft/world/effect/HealOrHarmMobEffect.java -@@ -16,7 +16,7 @@ +@@ -17,7 +17,7 @@ @Override - public boolean applyEffectTick(EntityLiving entityliving, int i) { + public boolean applyEffectTick(WorldServer worldserver, EntityLiving entityliving, int i) { if (this.isHarm == entityliving.isInvertedHealAndHarm()) { - entityliving.heal((float) Math.max(4 << i, 0)); + entityliving.heal((float) Math.max(4 << i, 0), org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.MAGIC); // CraftBukkit } else { - entityliving.hurt(entityliving.damageSources().magic(), (float) (6 << i)); + entityliving.hurtServer(worldserver, entityliving.damageSources().magic(), (float) (6 << i)); } -@@ -30,7 +30,7 @@ +@@ -31,7 +31,7 @@ if (this.isHarm == entityliving.isInvertedHealAndHarm()) { j = (int) (d0 * (double) (4 << i) + 0.5D); diff --git a/paper-server/nms-patches/net/minecraft/world/effect/HungerMobEffect.patch b/paper-server/nms-patches/net/minecraft/world/effect/HungerMobEffect.patch index 3bfa8f796f..f3a3c20618 100644 --- a/paper-server/nms-patches/net/minecraft/world/effect/HungerMobEffect.patch +++ b/paper-server/nms-patches/net/minecraft/world/effect/HungerMobEffect.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/effect/HungerMobEffect.java +++ b/net/minecraft/world/effect/HungerMobEffect.java -@@ -12,7 +12,7 @@ +@@ -13,7 +13,7 @@ @Override - public boolean applyEffectTick(EntityLiving entityliving, int i) { + public boolean applyEffectTick(WorldServer worldserver, EntityLiving entityliving, int i) { if (entityliving instanceof EntityHuman entityhuman) { - entityhuman.causeFoodExhaustion(0.005F * (float) (i + 1)); + entityhuman.causeFoodExhaustion(0.005F * (float) (i + 1), org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.HUNGER_EFFECT); // CraftBukkit - EntityExhaustionEvent diff --git a/paper-server/nms-patches/net/minecraft/world/effect/InfestedMobEffect.patch b/paper-server/nms-patches/net/minecraft/world/effect/InfestedMobEffect.patch index 608618653a..ce145e5229 100644 --- a/paper-server/nms-patches/net/minecraft/world/effect/InfestedMobEffect.patch +++ b/paper-server/nms-patches/net/minecraft/world/effect/InfestedMobEffect.patch @@ -1,12 +1,12 @@ --- a/net/minecraft/world/effect/InfestedMobEffect.java +++ b/net/minecraft/world/effect/InfestedMobEffect.java -@@ -47,7 +47,11 @@ +@@ -48,7 +48,11 @@ - entitysilverfish.moveTo(d0, d1, d2, world.getRandom().nextFloat() * 360.0F, 0.0F); + entitysilverfish.moveTo(d0, d1, d2, worldserver.getRandom().nextFloat() * 360.0F, 0.0F); entitysilverfish.setDeltaMovement(new Vec3D(vector3f)); -- world.addFreshEntity(entitysilverfish); +- worldserver.addFreshEntity(entitysilverfish); + // CraftBukkit start -+ if (!world.addFreshEntity(entitysilverfish, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.POTION_EFFECT)) { ++ if (!worldserver.addFreshEntity(entitysilverfish, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.POTION_EFFECT)) { + return; + } + // CraftBukkit end diff --git a/paper-server/nms-patches/net/minecraft/world/effect/OozingMobEffect.patch b/paper-server/nms-patches/net/minecraft/world/effect/OozingMobEffect.patch index 02adb1c7ef..1619b97690 100644 --- a/paper-server/nms-patches/net/minecraft/world/effect/OozingMobEffect.patch +++ b/paper-server/nms-patches/net/minecraft/world/effect/OozingMobEffect.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/effect/OozingMobEffect.java +++ b/net/minecraft/world/effect/OozingMobEffect.java -@@ -51,7 +51,7 @@ +@@ -52,7 +52,7 @@ if (entityslime != null) { entityslime.setSize(2, true); entityslime.moveTo(d0, d1, d2, world.getRandom().nextFloat() * 360.0F, 0.0F); diff --git a/paper-server/nms-patches/net/minecraft/world/effect/PoisonMobEffect.patch b/paper-server/nms-patches/net/minecraft/world/effect/PoisonMobEffect.patch index e493de93e1..14617da0f4 100644 --- a/paper-server/nms-patches/net/minecraft/world/effect/PoisonMobEffect.patch +++ b/paper-server/nms-patches/net/minecraft/world/effect/PoisonMobEffect.patch @@ -1,11 +1,11 @@ --- a/net/minecraft/world/effect/PoisonMobEffect.java +++ b/net/minecraft/world/effect/PoisonMobEffect.java -@@ -11,7 +11,7 @@ +@@ -12,7 +12,7 @@ @Override - public boolean applyEffectTick(EntityLiving entityliving, int i) { + public boolean applyEffectTick(WorldServer worldserver, EntityLiving entityliving, int i) { if (entityliving.getHealth() > 1.0F) { -- entityliving.hurt(entityliving.damageSources().magic(), 1.0F); -+ entityliving.hurt(entityliving.damageSources().poison(), 1.0F); // CraftBukkit - DamageSource.MAGIC -> CraftEventFactory.POISON +- entityliving.hurtServer(worldserver, entityliving.damageSources().magic(), 1.0F); ++ entityliving.hurtServer(worldserver, entityliving.damageSources().poison(), 1.0F); // CraftBukkit - DamageSource.MAGIC -> CraftEventFactory.POISON } return true; diff --git a/paper-server/nms-patches/net/minecraft/world/effect/RegenerationMobEffect.patch b/paper-server/nms-patches/net/minecraft/world/effect/RegenerationMobEffect.patch index 7ec7c8c01a..4ca57f3724 100644 --- a/paper-server/nms-patches/net/minecraft/world/effect/RegenerationMobEffect.patch +++ b/paper-server/nms-patches/net/minecraft/world/effect/RegenerationMobEffect.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/effect/RegenerationMobEffect.java +++ b/net/minecraft/world/effect/RegenerationMobEffect.java -@@ -11,7 +11,7 @@ +@@ -12,7 +12,7 @@ @Override - public boolean applyEffectTick(EntityLiving entityliving, int i) { + public boolean applyEffectTick(WorldServer worldserver, EntityLiving entityliving, int i) { if (entityliving.getHealth() < entityliving.getMaxHealth()) { - entityliving.heal(1.0F); + entityliving.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.MAGIC_REGEN); // CraftBukkit diff --git a/paper-server/nms-patches/net/minecraft/world/effect/SaturationMobEffect.patch b/paper-server/nms-patches/net/minecraft/world/effect/SaturationMobEffect.patch index 390177b4bb..ebf1e21ea1 100644 --- a/paper-server/nms-patches/net/minecraft/world/effect/SaturationMobEffect.patch +++ b/paper-server/nms-patches/net/minecraft/world/effect/SaturationMobEffect.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/effect/SaturationMobEffect.java +++ b/net/minecraft/world/effect/SaturationMobEffect.java -@@ -3,6 +3,11 @@ +@@ -4,6 +4,11 @@ import net.minecraft.world.entity.EntityLiving; import net.minecraft.world.entity.player.EntityHuman; @@ -12,10 +12,10 @@ class SaturationMobEffect extends InstantMobEffect { protected SaturationMobEffect(MobEffectInfo mobeffectinfo, int i) { -@@ -12,7 +17,15 @@ +@@ -13,7 +18,15 @@ @Override - public boolean applyEffectTick(EntityLiving entityliving, int i) { - if (!entityliving.level().isClientSide && entityliving instanceof EntityHuman entityhuman) { + public boolean applyEffectTick(WorldServer worldserver, EntityLiving entityliving, int i) { + if (entityliving instanceof EntityHuman entityhuman) { - entityhuman.getFoodData().eat(i + 1, 1.0F); + // CraftBukkit start + int oldFoodLevel = entityhuman.getFoodData().foodLevel; diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ConversionType.patch b/paper-server/nms-patches/net/minecraft/world/entity/ConversionType.patch new file mode 100644 index 0000000000..4aaf08e2cd --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/entity/ConversionType.patch @@ -0,0 +1,41 @@ +--- a/net/minecraft/world/entity/ConversionType.java ++++ b/net/minecraft/world/entity/ConversionType.java +@@ -12,6 +12,11 @@ + import net.minecraft.world.item.ItemStack; + import net.minecraft.world.scores.Scoreboard; + ++// CraftBukkit start ++import net.minecraft.core.BlockPosition; ++import org.bukkit.event.entity.EntityRemoveEvent; ++// CraftBukkit end ++ + public enum ConversionType { + + SINGLE(true) { +@@ -31,7 +36,7 @@ + while (iterator.hasNext()) { + entity1 = (Entity) iterator.next(); + entity1.stopRiding(); +- entity1.remove(Entity.RemovalReason.DISCARDED); ++ entity1.remove(Entity.RemovalReason.DISCARDED, EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - add Bukkit remove cause + } + + entity.startRiding(entityinsentient1); +@@ -64,7 +69,7 @@ + entityinsentient1.hurtTime = entityinsentient.hurtTime; + entityinsentient1.yBodyRot = entityinsentient.yBodyRot; + entityinsentient1.setOnGround(entityinsentient.onGround()); +- Optional optional = entityinsentient.getSleepingPos(); ++ Optional optional = entityinsentient.getSleepingPos(); // CraftBukkit - decompile error + + Objects.requireNonNull(entityinsentient1); + optional.ifPresent(entityinsentient1::setSleepingPos); +@@ -156,7 +161,7 @@ + entityinsentient1.setNoGravity(entityinsentient.isNoGravity()); + entityinsentient1.setPortalCooldown(entityinsentient.getPortalCooldown()); + entityinsentient1.setSilent(entityinsentient.isSilent()); +- Set set = entityinsentient.getTags(); ++ Set set = entityinsentient.getTags(); // CraftBukkit - decompile error + + Objects.requireNonNull(entityinsentient1); + set.forEach(entityinsentient1::addTag); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/Entity.patch b/paper-server/nms-patches/net/minecraft/world/entity/Entity.patch index 86ac3ad825..cf4d28c95b 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/Entity.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/Entity.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java -@@ -131,8 +131,72 @@ +@@ -139,8 +139,67 @@ import net.minecraft.world.scores.ScoreboardTeamBase; import org.slf4j.Logger; @@ -42,7 +42,7 @@ +import org.bukkit.plugin.PluginManager; +// CraftBukkit end + - public abstract class Entity implements SyncedDataHolder, INamableTileEntity, EntityAccess, ICommandListener, ScoreHolder { + public abstract class Entity implements SyncedDataHolder, INamableTileEntity, EntityAccess, ScoreHolder { + // CraftBukkit start + private static final int CURRENT_LEVEL = 2; @@ -59,11 +59,6 @@ + return bukkitEntity; + } + -+ @Override -+ public CommandSender getBukkitSender(CommandListenerWrapper wrapper) { -+ return getBukkitEntity(); -+ } -+ + // CraftBukkit - SPIGOT-6907: re-implement LivingEntity#setMaximumAir() + public int getDefaultMaxAirSupply() { + return TOTAL_AIR_SUPPLY; @@ -73,10 +68,10 @@ private static final Logger LOGGER = LogUtils.getLogger(); public static final String ID_TAG = "id"; public static final String PASSENGERS_TAG = "Passengers"; -@@ -245,6 +309,30 @@ - public boolean hasVisualFire; - @Nullable - private IBlockData inBlockState; +@@ -253,6 +312,30 @@ + private final List movementThisTick; + private final Set blocksInside; + private final LongSet visitedBlocks; + // CraftBukkit start + public boolean forceDrops; + public boolean persist = true; @@ -104,10 +99,10 @@ public Entity(EntityTypes entitytypes, World world) { this.id = Entity.ENTITY_COUNTER.incrementAndGet(); -@@ -351,12 +439,18 @@ +@@ -362,12 +445,18 @@ } - public void kill() { + public void kill(WorldServer worldserver) { - this.remove(Entity.RemovalReason.KILLED); + this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause this.gameEvent(GameEvent.ENTITY_DIE); @@ -125,7 +120,7 @@ } protected abstract void defineSynchedData(DataWatcher.a datawatcher_a); -@@ -365,6 +459,16 @@ +@@ -376,6 +465,16 @@ return this.entityData; } @@ -142,7 +137,7 @@ public boolean equals(Object object) { return object instanceof Entity ? ((Entity) object).id == this.id : false; } -@@ -374,12 +478,24 @@ +@@ -385,7 +484,13 @@ } public void remove(Entity.RemovalReason entity_removalreason) { @@ -157,6 +152,8 @@ } public void onClientRemoval() {} +@@ -393,6 +498,12 @@ + public void onRemoval(Entity.RemovalReason entity_removalreason) {} public void setPose(EntityPose entitypose) { + // CraftBukkit start @@ -168,7 +165,7 @@ this.entityData.set(Entity.DATA_POSE, entitypose); } -@@ -404,6 +520,33 @@ +@@ -417,6 +528,33 @@ } protected void setRot(float f, float f1) { @@ -202,7 +199,7 @@ this.setYRot(f % 360.0F); this.setXRot(f1 % 360.0F); } -@@ -445,6 +588,15 @@ +@@ -458,6 +596,15 @@ this.baseTick(); } @@ -216,18 +213,18 @@ + // CraftBukkit end + public void baseTick() { - this.level().getProfiler().push("entityBaseTick"); - this.inBlockState = null; -@@ -459,7 +611,7 @@ - this.walkDistO = this.walkDist; - this.xRotO = this.getXRot(); - this.yRotO = this.getYRot(); + GameProfilerFiller gameprofilerfiller = Profiler.get(); + +@@ -471,7 +618,7 @@ + --this.boardingCooldown; + } + - this.handlePortal(); + if (this instanceof EntityPlayer) this.handlePortal(); // CraftBukkit - // Moved up to postTick if (this.canSpawnSprintParticle()) { this.spawnSprintParticle(); } -@@ -494,6 +646,10 @@ +@@ -510,6 +657,10 @@ if (this.isInLava()) { this.lavaHurt(); this.fallDistance *= 0.5F; @@ -238,21 +235,20 @@ } this.checkBelowWorld(); -@@ -503,7 +659,7 @@ - - this.firstTick = false; - if (!this.level().isClientSide && this instanceof Leashable) { -- Leashable.tickLeash((Entity) ((Leashable) this)); -+ Leashable.tickLeash((Entity & Leashable) this); // CraftBukkit - decompile error +@@ -521,7 +672,7 @@ + world = this.level(); + if (world instanceof WorldServer worldserver) { + if (this instanceof Leashable) { +- Leashable.tickLeash(worldserver, (Entity) ((Leashable) this)); ++ Leashable.tickLeash(worldserver, (Entity & Leashable) this); // CraftBukkit - decompile error + } } - this.level().getProfiler().pop(); -@@ -545,15 +701,47 @@ +@@ -564,15 +715,32 @@ public void lavaHurt() { if (!this.fireImmune()) { - this.igniteForSeconds(15.0F); -- if (this.hurt(this.damageSources().lava(), 4.0F)) { + // CraftBukkit start - Fallen in lava TODO: this event spams! + if (this instanceof EntityLiving && remainingFireTicks <= 0) { + // not on fire yet @@ -268,13 +264,22 @@ + // This will be called every single tick the entity is in lava, so don't throw an event + this.igniteForSeconds(15.0F, false); + } -+ -+ if (this.hurt(this.damageSources().lava().directBlock(level, lastLavaContact), 4.0F)) { - this.playSound(SoundEffects.GENERIC_BURN, 0.4F, 2.0F + this.random.nextFloat() * 0.4F); ++ // CraftBukkit end + World world = this.level(); + + if (world instanceof WorldServer) { + WorldServer worldserver = (WorldServer) world; + +- if (this.hurtServer(worldserver, this.damageSources().lava(), 4.0F) && this.shouldPlayLavaHurtSound() && !this.isSilent()) { ++ // CraftBukkit start ++ if (this.hurtServer(worldserver, this.damageSources().lava().directBlock(level, lastLavaContact), 4.0F) && this.shouldPlayLavaHurtSound() && !this.isSilent()) { + worldserver.playSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), SoundEffects.GENERIC_BURN, this.getSoundSource(), 0.4F, 2.0F + this.random.nextFloat() * 0.4F); + } ++ // CraftBukkit end - we also don't throw an event unless the object in lava is living, to save on some event calls } -+ // CraftBukkit end - we also don't throw an event unless the object in lava is living, to save on some event calls } +@@ -583,6 +751,22 @@ } public final void igniteForSeconds(float f) { @@ -297,7 +302,7 @@ this.igniteForTicks(MathHelper.floor(f * 20.0F)); } -@@ -577,7 +765,7 @@ +@@ -606,7 +790,7 @@ } protected void onBelowWorld() { @@ -306,8 +311,8 @@ } public boolean isFree(double d0, double d1, double d2) { -@@ -702,6 +890,28 @@ - block.updateEntityAfterFallOn(this.level(), this); +@@ -739,6 +923,28 @@ + } } + // CraftBukkit start @@ -332,10 +337,10 @@ + } + // CraftBukkit end + - if (this.onGround()) { - block.stepOn(this.level(), blockposition, iblockdata, this); - } -@@ -1073,6 +1283,20 @@ + if (!this.level().isClientSide() || this.isControlledByLocalInstance()) { + Entity.MovementEmission entity_movementemission = this.getMovementEmission(); + +@@ -1120,6 +1326,20 @@ return SoundEffects.GENERIC_SPLASH; } @@ -353,10 +358,10 @@ + } + // CraftBukkit end + - protected void checkInsideBlocks() { - AxisAlignedBB axisalignedbb = this.getBoundingBox(); - BlockPosition blockposition = BlockPosition.containing(axisalignedbb.minX + 1.0E-7D, axisalignedbb.minY + 1.0E-7D, axisalignedbb.minZ + 1.0E-7D); -@@ -1512,6 +1736,7 @@ + public void recordMovementThroughBlocks(Vec3D vec3d, Vec3D vec3d1) { + this.movementThisTick.add(new Entity.b(vec3d, vec3d1)); + } +@@ -1586,6 +1806,7 @@ this.yo = d1; this.zo = d4; this.setPos(d3, d1, d4); @@ -364,7 +369,7 @@ } public void moveTo(Vec3D vec3d) { -@@ -1718,6 +1943,12 @@ +@@ -1838,6 +2059,12 @@ return false; } @@ -377,7 +382,7 @@ public void awardKillScore(Entity entity, int i, DamageSource damagesource) { if (entity instanceof EntityPlayer) { CriterionTriggers.ENTITY_KILLED_PLAYER.trigger((EntityPlayer) entity, this, damagesource); -@@ -1746,16 +1977,22 @@ +@@ -1866,16 +2093,22 @@ } public boolean saveAsPassenger(NBTTagCompound nbttagcompound) { @@ -402,7 +407,7 @@ return true; } } -@@ -1766,16 +2003,38 @@ +@@ -1886,16 +2119,38 @@ } public NBTTagCompound saveWithoutId(NBTTagCompound nbttagcompound) { @@ -445,7 +450,7 @@ nbttagcompound.put("Rotation", this.newFloatList(this.getYRot(), this.getXRot())); nbttagcompound.putFloat("FallDistance", this.fallDistance); nbttagcompound.putShort("Fire", (short) this.remainingFireTicks); -@@ -1783,7 +2042,28 @@ +@@ -1903,7 +2158,28 @@ nbttagcompound.putBoolean("OnGround", this.onGround()); nbttagcompound.putBoolean("Invulnerable", this.invulnerable); nbttagcompound.putInt("PortalCooldown", this.portalCooldown); @@ -475,7 +480,7 @@ IChatBaseComponent ichatbasecomponent = this.getCustomName(); if (ichatbasecomponent != null) { -@@ -1832,7 +2112,7 @@ +@@ -1952,7 +2228,7 @@ nbttagcompound.put("Tags", nbttaglist); } @@ -484,7 +489,7 @@ if (this.isVehicle()) { nbttaglist = new NBTTagList(); iterator = this.getPassengers().iterator(); -@@ -1841,7 +2121,7 @@ +@@ -1961,7 +2237,7 @@ Entity entity = (Entity) iterator.next(); NBTTagCompound nbttagcompound1 = new NBTTagCompound(); @@ -493,7 +498,7 @@ nbttaglist.add(nbttagcompound1); } } -@@ -1851,6 +2131,11 @@ +@@ -1971,6 +2247,11 @@ } } @@ -505,7 +510,7 @@ return nbttagcompound; } catch (Throwable throwable) { CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT"); -@@ -1934,6 +2219,45 @@ +@@ -2055,6 +2336,45 @@ } else { throw new IllegalStateException("Entity has invalid position"); } @@ -551,7 +556,7 @@ } catch (Throwable throwable) { CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT"); CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Entity being loaded"); -@@ -1955,6 +2279,12 @@ +@@ -2076,6 +2396,12 @@ return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null; } @@ -564,8 +569,8 @@ protected abstract void readAdditionalSaveData(NBTTagCompound nbttagcompound); protected abstract void addAdditionalSaveData(NBTTagCompound nbttagcompound); -@@ -2009,9 +2339,22 @@ - } else if (this.level().isClientSide) { +@@ -2128,9 +2454,22 @@ + if (itemstack.isEmpty()) { return null; } else { + // CraftBukkit start - Capture drops for death event @@ -574,7 +579,7 @@ + return null; + } + // CraftBukkit end - EntityItem entityitem = new EntityItem(this.level(), this.getX(), this.getY() + (double) f, this.getZ(), itemstack); + EntityItem entityitem = new EntityItem(worldserver, this.getX(), this.getY() + (double) f, this.getZ(), itemstack); entityitem.setDefaultPickUpDelay(); + // CraftBukkit start @@ -584,10 +589,10 @@ + return null; + } + // CraftBukkit end - this.level().addFreshEntity(entityitem); + worldserver.addFreshEntity(entityitem); return entityitem; } -@@ -2040,6 +2383,12 @@ +@@ -2159,6 +2498,12 @@ if (this.isAlive() && this instanceof Leashable leashable) { if (leashable.getLeashHolder() == entityhuman) { if (!this.level().isClientSide()) { @@ -600,7 +605,7 @@ leashable.dropLeash(true, !entityhuman.hasInfiniteMaterials()); this.gameEvent(GameEvent.ENTITY_INTERACT, entityhuman); } -@@ -2051,6 +2400,13 @@ +@@ -2170,6 +2515,13 @@ if (itemstack.is(Items.LEAD) && leashable.canHaveALeashAttachedToIt()) { if (!this.level().isClientSide()) { @@ -614,7 +619,7 @@ leashable.setLeashedTo(entityhuman, true); } -@@ -2134,6 +2490,27 @@ +@@ -2255,6 +2607,27 @@ if (!flag && (!this.canRide(entity) || !entity.canAddPassenger(this))) { return false; } else { @@ -642,7 +647,7 @@ if (this.isPassenger()) { this.stopRiding(); } -@@ -2167,7 +2544,7 @@ +@@ -2288,7 +2661,7 @@ Entity entity = this.vehicle; this.vehicle = null; @@ -651,7 +656,7 @@ } } -@@ -2198,10 +2575,38 @@ +@@ -2319,10 +2692,38 @@ } } @@ -691,7 +696,7 @@ if (this.passengers.size() == 1 && this.passengers.get(0) == entity) { this.passengers = ImmutableList.of(); } else { -@@ -2213,6 +2618,7 @@ +@@ -2334,6 +2735,7 @@ entity.boardingCooldown = 60; this.gameEvent(GameEvent.ENTITY_DISMOUNT, entity); } @@ -699,16 +704,16 @@ } protected boolean canAddPassenger(Entity entity) { -@@ -2307,7 +2713,7 @@ - if (dimensiontransition != null) { - WorldServer worldserver1 = dimensiontransition.newLevel(); +@@ -2434,7 +2836,7 @@ + if (teleporttransition != null) { + WorldServer worldserver1 = teleporttransition.newLevel(); -- if (worldserver.getServer().isLevelEnabled(worldserver1) && (worldserver1.dimension() == worldserver.dimension() || this.canChangeDimensions(worldserver, worldserver1))) { -+ if (this instanceof EntityPlayer || (worldserver1 != null && (worldserver1.dimension() == worldserver.dimension() || this.canChangeDimensions(worldserver, worldserver1)))) { // CraftBukkit - always call event for players - this.changeDimension(dimensiontransition); +- if (worldserver.getServer().isLevelEnabled(worldserver1) && (worldserver1.dimension() == worldserver.dimension() || this.canTeleport(worldserver, worldserver1))) { ++ if (this instanceof EntityPlayer || (worldserver1 != null && (worldserver1.dimension() == worldserver.dimension() || this.canTeleport(worldserver, worldserver1)))) { // CraftBukkit - always call event for players + this.teleport(teleporttransition); } } -@@ -2414,6 +2820,13 @@ +@@ -2541,6 +2943,13 @@ } public void setSwimming(boolean flag) { @@ -722,7 +727,7 @@ this.setSharedFlag(4, flag); } -@@ -2463,8 +2876,12 @@ +@@ -2594,8 +3003,12 @@ return this.getTeam() != null ? this.getTeam().isAlliedTo(scoreboardteambase) : false; } @@ -736,7 +741,7 @@ } public boolean getSharedFlag(int i) { -@@ -2483,7 +2900,7 @@ +@@ -2614,7 +3027,7 @@ } public int getMaxAirSupply() { @@ -745,7 +750,7 @@ } public int getAirSupply() { -@@ -2491,7 +2908,18 @@ +@@ -2622,7 +3035,18 @@ } public void setAirSupply(int i) { @@ -765,7 +770,7 @@ } public int getTicksFrozen() { -@@ -2518,11 +2946,40 @@ +@@ -2649,11 +3073,40 @@ public void thunderHit(WorldServer worldserver, EntityLightning entitylightning) { this.setRemainingFireTicks(this.remainingFireTicks + 1); @@ -786,7 +791,7 @@ + // CraftBukkit end } -- this.hurt(this.damageSources().lightningBolt(), 5.0F); +- this.hurtServer(worldserver, this.damageSources().lightningBolt(), 5.0F); + // CraftBukkit start + if (thisBukkitEntity instanceof Hanging) { + HangingBreakByEntityEvent hangingEvent = new HangingBreakByEntityEvent((Hanging) thisBukkitEntity, stormBukkitEntity); @@ -801,47 +806,47 @@ + return; + } + -+ if (!this.hurt(this.damageSources().lightningBolt().customEntityDamager(entitylightning), 5.0F)) { ++ if (!this.hurtServer(worldserver, this.damageSources().lightningBolt().customEntityDamager(entitylightning), 5.0F)) { + return; + } + // CraftBukkit end } public void onAboveBubbleCol(boolean flag) { -@@ -2691,6 +3148,15 @@ +@@ -2822,6 +3275,18 @@ if (world instanceof WorldServer worldserver) { if (!this.isRemoved()) { + // CraftBukkit start -+ Location to = new Location(dimensiontransition.newLevel().getWorld(), dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), dimensiontransition.xRot()); ++ PositionMoveRotation absolutePosition = PositionMoveRotation.calculateAbsolute(PositionMoveRotation.of(this), PositionMoveRotation.of(teleporttransition), teleporttransition.relatives()); ++ Location to = CraftLocation.toBukkit(absolutePosition.position(), teleporttransition.newLevel().getWorld(), absolutePosition.yRot(), absolutePosition.xRot()); + EntityTeleportEvent teleEvent = CraftEventFactory.callEntityTeleportEvent(this, to); + if (teleEvent.isCancelled()) { + return null; + } -+ to = teleEvent.getTo(); -+ dimensiontransition = new DimensionTransition(((CraftWorld) to.getWorld()).getHandle(), CraftLocation.toVec3D(to), dimensiontransition.speed(), to.getYaw(), to.getPitch(), dimensiontransition.missingRespawnBlock(), dimensiontransition.postDimensionTransition(), dimensiontransition.cause()); ++ if (!to.equals(teleEvent.getTo())) { ++ to = teleEvent.getTo(); ++ teleporttransition = new TeleportTransition(((CraftWorld) to.getWorld()).getHandle(), CraftLocation.toVec3D(to), Vec3D.ZERO, to.getYaw(), to.getPitch(), teleporttransition.missingRespawnBlock(), teleporttransition.asPassenger(), Set.of(), teleporttransition.postTeleportTransition(), teleporttransition.cause()); ++ } + // CraftBukkit end - WorldServer worldserver1 = dimensiontransition.newLevel(); - List list = this.getPassengers(); + WorldServer worldserver1 = teleporttransition.newLevel(); + boolean flag = worldserver1.dimension() != worldserver.dimension(); -@@ -2716,11 +3182,15 @@ - if (this != entity2) { - entity2.restoreFrom(this); - this.removeAfterChangingDimensions(); -+ // CraftBukkit start - Forward the CraftEntity to the new entity -+ this.getBukkitEntity().setHandle(entity2); -+ entity2.bukkitEntity = this.getBukkitEntity(); -+ // CraftBukkit end - } +@@ -2890,8 +3355,12 @@ + } else { + entity.restoreFrom(this); + this.removeAfterChangingDimensions(); ++ // CraftBukkit start - Forward the CraftEntity to the new entity ++ this.getBukkitEntity().setHandle(entity); ++ entity.bukkitEntity = this.getBukkitEntity(); ++ // CraftBukkit end + entity.teleportSetPosition(PositionMoveRotation.of(teleporttransition), teleporttransition.relatives()); +- worldserver.addDuringTeleport(entity); ++ if (this.inWorld) worldserver.addDuringTeleport(entity); // CraftBukkit - Don't spawn the new entity if the current entity isn't spawned + Iterator iterator1 = list1.iterator(); - entity2.moveTo(dimensiontransition.pos().x, dimensiontransition.pos().y, dimensiontransition.pos().z, dimensiontransition.yRot(), entity2.getXRot()); - entity2.setDeltaMovement(dimensiontransition.speed()); -- if (this != entity2) { -+ if (this != entity2 && this.inWorld) { // CraftBukkit - Don't spawn the new entity if the current entity isn't spawned - worldserver1.addDuringTeleport(entity2); - } - -@@ -2754,8 +3224,9 @@ + while (iterator1.hasNext()) { +@@ -2965,8 +3434,9 @@ } protected void removeAfterChangingDimensions() { @@ -852,7 +857,7 @@ leashable.dropLeash(true, false); } -@@ -2765,6 +3236,20 @@ +@@ -2976,6 +3446,20 @@ return BlockPortalShape.getRelativePosition(blockutil_rectangle, enumdirection_enumaxis, this.position(), this.getDimensions(this.getPose())); } @@ -873,35 +878,25 @@ public boolean canUsePortal(boolean flag) { return (flag || !this.isPassenger()) && this.isAlive(); } -@@ -2877,6 +3362,12 @@ +@@ -3104,9 +3588,15 @@ return (Boolean) this.entityData.get(Entity.DATA_CUSTOM_NAME_VISIBLE); } +- public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1, boolean flag) { + // CraftBukkit start -+ public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) { -+ return this.teleportTo(worldserver, d0, d1, d2, set, f, f1); ++ public final boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1, boolean flag) { ++ return teleportTo(worldserver, d0, d1, d2, set, f, f1, flag, PlayerTeleportEvent.TeleportCause.UNKNOWN); + } -+ // CraftBukkit end + - public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1) { ++ public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1, boolean flag, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause cause) { float f2 = MathHelper.clamp(f1, -90.0F, 90.0F); +- Entity entity = this.teleport(new TeleportTransition(worldserver, new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f2, set, TeleportTransition.DO_NOTHING)); ++ Entity entity = this.teleport(new TeleportTransition(worldserver, new Vec3D(d0, d1, d2), Vec3D.ZERO, f, f2, set, TeleportTransition.DO_NOTHING, cause)); ++ // CraftBukkit end -@@ -2895,8 +3386,12 @@ - entity.restoreFrom(this); - entity.moveTo(d0, d1, d2, f, f2); - entity.setYHeadRot(f); -- this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION); -- worldserver.addDuringTeleport(entity); -+ this.setRemoved(Entity.RemovalReason.CHANGED_DIMENSION, null); // CraftBukkit - add Bukkit remove cause -+ // CraftBukkit start - Don't spawn the new entity if the current entity isn't spawned -+ if (inWorld) { -+ worldserver.addDuringTeleport(entity); -+ } -+ // CraftBukkit end - } - - return true; -@@ -3023,7 +3518,26 @@ + return entity != null; + } +@@ -3228,7 +3718,26 @@ } public final void setBoundingBox(AxisAlignedBB axisalignedbb) { @@ -929,7 +924,7 @@ } public final float getEyeHeight(EntityPose entitypose) { -@@ -3332,6 +3846,11 @@ +@@ -3525,6 +4034,11 @@ vec3d = vec3d.add(vec3d1); ++k1; } @@ -941,7 +936,7 @@ } } } -@@ -3601,6 +4120,14 @@ +@@ -3792,6 +4306,14 @@ @Override public final void setRemoved(Entity.RemovalReason entity_removalreason) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/EntityAgeable.patch b/paper-server/nms-patches/net/minecraft/world/entity/EntityAgeable.patch index b5e1154ce9..77d10c6a16 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/EntityAgeable.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/EntityAgeable.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/EntityAgeable.java +++ b/net/minecraft/world/entity/EntityAgeable.java -@@ -20,6 +20,7 @@ +@@ -21,6 +21,7 @@ protected int age; protected int forcedAge; protected int forcedAgeTimer; @@ -8,7 +8,7 @@ protected EntityAgeable(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -103,6 +104,7 @@ +@@ -104,6 +105,7 @@ super.addAdditionalSaveData(nbttagcompound); nbttagcompound.putInt("Age", this.getAge()); nbttagcompound.putInt("ForcedAge", this.forcedAge); @@ -16,7 +16,7 @@ } @Override -@@ -110,6 +112,7 @@ +@@ -111,6 +113,7 @@ super.readAdditionalSaveData(nbttagcompound); this.setAge(nbttagcompound.getInt("Age")); this.forcedAge = nbttagcompound.getInt("ForcedAge"); @@ -24,7 +24,7 @@ } @Override -@@ -124,7 +127,7 @@ +@@ -125,7 +128,7 @@ @Override public void aiStep() { super.aiStep(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/EntityAreaEffectCloud.patch b/paper-server/nms-patches/net/minecraft/world/entity/EntityAreaEffectCloud.patch index ee7c730663..3f2bb94126 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/EntityAreaEffectCloud.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/EntityAreaEffectCloud.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/EntityAreaEffectCloud.java +++ b/net/minecraft/world/entity/EntityAreaEffectCloud.java -@@ -32,6 +32,12 @@ +@@ -33,6 +33,12 @@ import net.minecraft.world.level.material.EnumPistonReaction; import org.slf4j.Logger; @@ -13,81 +13,81 @@ public class EntityAreaEffectCloud extends Entity implements TraceableEntity { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -188,7 +194,7 @@ - } +@@ -200,7 +206,7 @@ + + private void serverTick(WorldServer worldserver) { + if (this.tickCount >= this.waitTime + this.duration) { +- this.discard(); ++ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause } else { - if (this.tickCount >= this.waitTime + this.duration) { -- this.discard(); -+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause - return; - } + boolean flag = this.isWaiting(); + boolean flag1 = this.tickCount < this.waitTime; +@@ -215,7 +221,7 @@ + if (this.radiusPerTick != 0.0F) { + f += this.radiusPerTick; + if (f < 0.5F) { +- this.discard(); ++ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause + return; + } -@@ -205,7 +211,7 @@ - if (this.radiusPerTick != 0.0F) { - f += this.radiusPerTick; - if (f < 0.5F) { -- this.discard(); -+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause - return; - } +@@ -249,11 +255,12 @@ + if (!list1.isEmpty()) { + Iterator iterator1 = list1.iterator(); -@@ -239,11 +245,12 @@ - if (!list1.isEmpty()) { - Iterator iterator1 = list1.iterator(); ++ List entities = new java.util.ArrayList(); // CraftBukkit + while (iterator1.hasNext()) { + EntityLiving entityliving = (EntityLiving) iterator1.next(); -+ List entities = new java.util.ArrayList(); // CraftBukkit - while (iterator1.hasNext()) { - EntityLiving entityliving = (EntityLiving) iterator1.next(); + if (!this.victims.containsKey(entityliving) && entityliving.isAffectedByPotions()) { +- Stream stream = list.stream(); ++ Stream stream = list.stream(); // CraftBukkit - decompile error - if (!this.victims.containsKey(entityliving) && entityliving.isAffectedByPotions()) { -- Stream stream = list.stream(); -+ Stream stream = list.stream(); // CraftBukkit - decompile error + Objects.requireNonNull(entityliving); + if (!stream.noneMatch(entityliving::canBeAffected)) { +@@ -262,6 +269,19 @@ + double d2 = d0 * d0 + d1 * d1; - Objects.requireNonNull(entityliving); - if (!stream.noneMatch(entityliving::canBeAffected)) { -@@ -252,6 +259,19 @@ - double d5 = d3 * d3 + d4 * d4; - - if (d5 <= (double) (f * f)) { -+ // CraftBukkit start -+ entities.add((LivingEntity) entityliving.getBukkitEntity()); + if (d2 <= (double) (f * f)) { ++ // CraftBukkit start ++ entities.add((LivingEntity) entityliving.getBukkitEntity()); ++ } + } + } + } -+ } -+ { -+ org.bukkit.event.entity.AreaEffectCloudApplyEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callAreaEffectCloudApplyEvent(this, entities); -+ if (!event.isCancelled()) { -+ for (LivingEntity entity : event.getAffectedEntities()) { -+ if (entity instanceof CraftLivingEntity) { -+ EntityLiving entityliving = ((CraftLivingEntity) entity).getHandle(); -+ // CraftBukkit end - this.victims.put(entityliving, this.tickCount + this.reapplicationDelay); - Iterator iterator2 = list.iterator(); ++ { ++ org.bukkit.event.entity.AreaEffectCloudApplyEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callAreaEffectCloudApplyEvent(this, entities); ++ if (!event.isCancelled()) { ++ for (LivingEntity entity : event.getAffectedEntities()) { ++ if (entity instanceof CraftLivingEntity) { ++ EntityLiving entityliving = ((CraftLivingEntity) entity).getHandle(); ++ // CraftBukkit end + this.victims.put(entityliving, this.tickCount + this.reapplicationDelay); + Iterator iterator2 = list.iterator(); -@@ -261,14 +281,14 @@ - if (((MobEffectList) mobeffect1.getEffect().value()).isInstantenous()) { - ((MobEffectList) mobeffect1.getEffect().value()).applyInstantenousEffect(this, this.getOwner(), entityliving, mobeffect1.getAmplifier(), 0.5D); - } else { -- entityliving.addEffect(new MobEffect(mobeffect1), this); -+ entityliving.addEffect(new MobEffect(mobeffect1), this, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.AREA_EFFECT_CLOUD); // CraftBukkit - } - } - - if (this.radiusOnUse != 0.0F) { - f += this.radiusOnUse; - if (f < 0.5F) { -- this.discard(); -+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause - return; +@@ -271,14 +291,14 @@ + if (((MobEffectList) mobeffect1.getEffect().value()).isInstantenous()) { + ((MobEffectList) mobeffect1.getEffect().value()).applyInstantenousEffect(worldserver, this, this.getOwner(), entityliving, mobeffect1.getAmplifier(), 0.5D); + } else { +- entityliving.addEffect(new MobEffect(mobeffect1), this); ++ entityliving.addEffect(new MobEffect(mobeffect1), this, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.AREA_EFFECT_CLOUD); // CraftBukkit + } } -@@ -278,7 +298,7 @@ - if (this.durationOnUse != 0) { - this.duration += this.durationOnUse; - if (this.duration <= 0) { -- this.discard(); -+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause - return; + if (this.radiusOnUse != 0.0F) { + f += this.radiusOnUse; + if (f < 0.5F) { +- this.discard(); ++ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause + return; + } + +@@ -288,7 +308,7 @@ + if (this.durationOnUse != 0) { + this.duration += this.durationOnUse; + if (this.duration <= 0) { +- this.discard(); ++ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause + return; + } } - } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/EntityExperienceOrb.patch b/paper-server/nms-patches/net/minecraft/world/entity/EntityExperienceOrb.patch index 4ada992e8c..48c47f28a6 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/EntityExperienceOrb.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/EntityExperienceOrb.patch @@ -47,7 +47,7 @@ Vec3D vec3d = new Vec3D(this.followingPlayer.getX() - this.getX(), this.followingPlayer.getY() + (double) this.followingPlayer.getEyeHeight() / 2.0D - this.getY(), this.followingPlayer.getZ() - this.getZ()); double d0 = vec3d.lengthSqr(); -@@ -118,7 +142,7 @@ +@@ -119,7 +143,7 @@ ++this.age; if (this.age >= 6000) { @@ -56,7 +56,7 @@ } } -@@ -187,7 +211,7 @@ +@@ -188,7 +212,7 @@ private void merge(EntityExperienceOrb entityexperienceorb) { this.count += entityexperienceorb.count; this.age = Math.min(this.age, entityexperienceorb.age); @@ -65,7 +65,7 @@ } private void setUnderwaterMovement() { -@@ -209,7 +233,7 @@ +@@ -213,7 +237,7 @@ this.markHurt(); this.health = (int) ((float) this.health - f); if (this.health <= 0) { @@ -74,7 +74,7 @@ } return true; -@@ -236,17 +260,17 @@ +@@ -240,17 +264,17 @@ public void playerTouch(EntityHuman entityhuman) { if (entityhuman instanceof EntityPlayer entityplayer) { if (entityhuman.takeXpDelay == 0) { @@ -95,7 +95,7 @@ } } -@@ -260,12 +284,20 @@ +@@ -264,12 +288,20 @@ ItemStack itemstack = ((EnchantedItemInUse) optional.get()).itemStack(); int j = EnchantmentManager.modifyDurabilityToRepairFromXp(entityplayer.serverLevel(), itemstack, i); int k = Math.min(j, itemstack.getDamageValue()); @@ -116,7 +116,7 @@ return this.repairPlayerItems(entityplayer, l); } } -@@ -285,6 +317,24 @@ +@@ -289,6 +321,24 @@ } public static int getExperienceValue(int i) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/EntityInsentient.patch b/paper-server/nms-patches/net/minecraft/world/entity/EntityInsentient.patch index 54e16c0d86..a27e32292a 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/EntityInsentient.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/EntityInsentient.patch @@ -1,15 +1,13 @@ --- a/net/minecraft/world/entity/EntityInsentient.java +++ b/net/minecraft/world/entity/EntityInsentient.java -@@ -87,6 +87,20 @@ +@@ -89,6 +89,18 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParameters; import net.minecraft.world.phys.AxisAlignedBB; +// CraftBukkit start -+import net.minecraft.server.level.EntityPlayer; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.entity.CraftLivingEntity; +import org.bukkit.event.entity.CreatureSpawnEvent; -+import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.entity.EntityRemoveEvent; +import org.bukkit.event.entity.EntityTargetLivingEntityEvent; +import org.bukkit.event.entity.EntityTargetEvent; @@ -21,7 +19,7 @@ public abstract class EntityInsentient extends EntityLiving implements EquipmentUser, Leashable, Targeting { private static final DataWatcherObject DATA_MOB_FLAGS_ID = DataWatcher.defineId(EntityInsentient.class, DataWatcherRegistry.BYTE); -@@ -134,6 +148,8 @@ +@@ -136,6 +148,8 @@ private BlockPosition restrictCenter; private float restrictRadius; @@ -30,7 +28,7 @@ protected EntityInsentient(EntityTypes entitytypes, World world) { super(entitytypes, world); this.handItems = NonNullList.withSize(2, ItemStack.EMPTY); -@@ -161,6 +177,12 @@ +@@ -164,6 +178,12 @@ } @@ -43,7 +41,7 @@ protected void registerGoals() {} public static AttributeProvider.Builder createMobAttributes() { -@@ -265,11 +287,42 @@ +@@ -268,11 +288,42 @@ @Nullable protected final EntityLiving getTargetFromBrain() { @@ -87,7 +85,7 @@ } @Override -@@ -405,6 +458,12 @@ +@@ -403,6 +454,12 @@ return null; } @@ -100,7 +98,7 @@ @Override public void addAdditionalSaveData(NBTTagCompound nbttagcompound) { super.addAdditionalSaveData(nbttagcompound); -@@ -478,16 +537,26 @@ +@@ -476,16 +533,26 @@ nbttagcompound.putBoolean("NoAI", this.isNoAi()); } @@ -112,7 +110,7 @@ super.readAdditionalSaveData(nbttagcompound); + + // CraftBukkit start - If looting or persistence is false only use it if it was set after we started using it - if (nbttagcompound.contains("CanPickUpLoot", 1)) { + if (nbttagcompound.contains("CanPickUpLoot", 99)) { - this.setCanPickUpLoot(nbttagcompound.getBoolean("CanPickUpLoot")); + boolean data = nbttagcompound.getBoolean("CanPickUpLoot"); + if (isLevelAtLeast(nbttagcompound, 1) || data) { @@ -129,7 +127,7 @@ NBTTagList nbttaglist; NBTTagCompound nbttagcompound1; int i; -@@ -541,6 +610,11 @@ +@@ -539,6 +606,11 @@ } this.setNoAi(nbttagcompound.getBoolean("NoAI")); @@ -141,12 +139,12 @@ } @Override -@@ -615,20 +689,26 @@ +@@ -615,20 +687,26 @@ - protected void pickUpItem(EntityItem entityitem) { + protected void pickUpItem(WorldServer worldserver, EntityItem entityitem) { ItemStack itemstack = entityitem.getItem(); -- ItemStack itemstack1 = this.equipItemIfPossible(itemstack.copy()); -+ ItemStack itemstack1 = this.equipItemIfPossible(itemstack.copy(), entityitem); // CraftBukkit - add item +- ItemStack itemstack1 = this.equipItemIfPossible(worldserver, itemstack.copy()); ++ ItemStack itemstack1 = this.equipItemIfPossible(worldserver, itemstack.copy(), entityitem); // CraftBukkit - add item if (!itemstack1.isEmpty()) { this.onItemPickup(entityitem); @@ -160,17 +158,17 @@ } - public ItemStack equipItemIfPossible(ItemStack itemstack) { + public ItemStack equipItemIfPossible(WorldServer worldserver, ItemStack itemstack) { + // CraftBukkit start - add item -+ return this.equipItemIfPossible(itemstack, null); ++ return this.equipItemIfPossible(worldserver, itemstack, null); + } + -+ public ItemStack equipItemIfPossible(ItemStack itemstack, EntityItem entityitem) { ++ public ItemStack equipItemIfPossible(WorldServer worldserver, ItemStack itemstack, EntityItem entityitem) { + // CraftBukkit end EnumItemSlot enumitemslot = this.getEquipmentSlotForItem(itemstack); ItemStack itemstack1 = this.getItemBySlot(enumitemslot); - boolean flag = this.canReplaceCurrentItem(itemstack, itemstack1); -@@ -639,11 +719,19 @@ + boolean flag = this.canReplaceCurrentItem(itemstack, itemstack1, enumitemslot); +@@ -639,11 +717,19 @@ flag = itemstack1.isEmpty(); } @@ -186,12 +184,12 @@ if (!itemstack1.isEmpty() && (double) Math.max(this.random.nextFloat() - 0.1F, 0.0F) < d0) { + this.forceDrops = true; // CraftBukkit - this.spawnAtLocation(itemstack1); + this.spawnAtLocation(worldserver, itemstack1); + this.forceDrops = false; // CraftBukkit } ItemStack itemstack2 = enumitemslot.limit(itemstack); -@@ -772,7 +860,7 @@ +@@ -770,7 +856,7 @@ @Override public void checkDespawn() { if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL && this.shouldDespawnInPeaceful()) { @@ -200,7 +198,7 @@ } else if (!this.isPersistenceRequired() && !this.requiresCustomPersistence()) { EntityHuman entityhuman = this.level().getNearestPlayer(this, -1.0D); -@@ -782,14 +870,14 @@ +@@ -780,14 +866,14 @@ int j = i * i; if (d0 > (double) j && this.removeWhenFarAway(d0)) { @@ -217,15 +215,15 @@ } else if (d0 < (double) l) { this.noActionTime = 0; } -@@ -803,6 +891,7 @@ +@@ -801,6 +887,7 @@ @Override protected final void serverAiStep() { ++this.noActionTime; + if (!this.aware) return; // CraftBukkit - GameProfilerFiller gameprofilerfiller = this.level().getProfiler(); + GameProfilerFiller gameprofilerfiller = Profiler.get(); gameprofilerfiller.push("sensing"); -@@ -1354,7 +1443,7 @@ +@@ -1340,7 +1427,7 @@ if (itemstack.getItem() instanceof ItemMonsterEgg) { if (this.level() instanceof WorldServer) { ItemMonsterEgg itemmonsteregg = (ItemMonsterEgg) itemstack.getItem(); @@ -234,51 +232,71 @@ optional.ifPresent((entityinsentient) -> { this.onOffspringSpawnedFromEgg(entityhuman, entityinsentient); -@@ -1403,12 +1492,19 @@ +@@ -1391,12 +1478,19 @@ return this.restrictRadius != -1.0F; } + // CraftBukkit start @Nullable - public T convertTo(EntityTypes entitytypes, boolean flag) { -+ return this.convertTo(entitytypes, flag, EntityTransformEvent.TransformReason.UNKNOWN, CreatureSpawnEvent.SpawnReason.DEFAULT); + public T convertTo(EntityTypes entitytypes, ConversionParams conversionparams, EntitySpawnReason entityspawnreason, ConversionParams.a conversionparams_a) { ++ return this.convertTo(entitytypes, conversionparams, entityspawnreason, conversionparams_a, EntityTransformEvent.TransformReason.UNKNOWN, CreatureSpawnEvent.SpawnReason.DEFAULT); + } + + @Nullable -+ public T convertTo(EntityTypes entitytypes, boolean flag, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) { ++ public T convertTo(EntityTypes entitytypes, ConversionParams conversionparams, EntitySpawnReason entityspawnreason, ConversionParams.a conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) { + // CraftBukkit end if (this.isRemoved()) { return null; } else { -- T t0 = (EntityInsentient) entitytypes.create(this.level()); -+ T t0 = entitytypes.create(this.level()); // CraftBukkit - decompile error +- T t0 = (EntityInsentient) entitytypes.create(this.level(), entityspawnreason); ++ T t0 = entitytypes.create(this.level(), EntitySpawnReason.CONVERSION); // CraftBukkit - decompile error if (t0 == null) { return null; -@@ -1442,7 +1538,12 @@ - } - } +@@ -1405,14 +1499,24 @@ + conversionparams_a.finalizeConversion(t0); + World world = this.level(); -- this.level().addFreshEntity(t0); + // CraftBukkit start ++ if (transformReason == null) { ++ // Special handling for slime split and pig lightning ++ return t0; ++ } ++ + if (CraftEventFactory.callEntityTransformEvent(this, t0, transformReason).isCancelled()) { + return null; + } -+ this.level().addFreshEntity(t0, spawnReason); + // CraftBukkit end - if (this.isPassenger()) { - Entity entity = this.getVehicle(); + if (world instanceof WorldServer) { + WorldServer worldserver = (WorldServer) world; -@@ -1450,7 +1551,7 @@ - t0.startRiding(entity, true); +- worldserver.addFreshEntity(t0); ++ worldserver.addFreshEntity(t0, spawnReason); // CraftBukkit + } + + if (conversionparams.type().shouldDiscardAfterConversion()) { +- this.discard(); ++ this.discard(EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - add Bukkit remove cause } -- this.discard(); -+ this.discard(EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - add Bukkit remove cause return t0; - } - } -@@ -1492,6 +1593,7 @@ +@@ -1422,7 +1526,14 @@ + + @Nullable + public T convertTo(EntityTypes entitytypes, ConversionParams conversionparams, ConversionParams.a conversionparams_a) { +- return this.convertTo(entitytypes, conversionparams, EntitySpawnReason.CONVERSION, conversionparams_a); ++ // CraftBukkit start ++ return this.convertTo(entitytypes, conversionparams, conversionparams_a, EntityTransformEvent.TransformReason.UNKNOWN, CreatureSpawnEvent.SpawnReason.DEFAULT); ++ } ++ ++ @Nullable ++ public T convertTo(EntityTypes entitytypes, ConversionParams conversionparams, ConversionParams.a conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) { ++ return this.convertTo(entitytypes, conversionparams, EntitySpawnReason.CONVERSION, conversionparams_a, transformReason, spawnReason); ++ // CraftBukkit end + } + + @Nullable +@@ -1461,6 +1572,7 @@ boolean flag1 = super.startRiding(entity, flag); if (flag1 && this.isLeashed()) { @@ -286,10 +304,10 @@ this.dropLeash(true, true); } -@@ -1578,7 +1680,7 @@ - if (f1 > 0.0F && entity instanceof EntityLiving) { - EntityLiving entityliving = (EntityLiving) entity; +@@ -1545,7 +1657,7 @@ + if (f1 > 0.0F && entity instanceof EntityLiving) { + entityliving = (EntityLiving) entity; - entityliving.knockback((double) (f1 * 0.5F), (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F))); + entityliving.knockback((double) (f1 * 0.5F), (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)), this, org.bukkit.event.entity.EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); // CraftBukkit this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D)); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/EntityLightning.patch b/paper-server/nms-patches/net/minecraft/world/entity/EntityLightning.patch index 84f36215b0..04073819bc 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/EntityLightning.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/EntityLightning.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/EntityLightning.java +++ b/net/minecraft/world/entity/EntityLightning.java -@@ -30,6 +30,11 @@ +@@ -31,6 +31,11 @@ import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; @@ -12,7 +12,7 @@ public class EntityLightning extends Entity { private static final int START_LIFE = 2; -@@ -121,7 +126,7 @@ +@@ -120,7 +125,7 @@ } } @@ -21,7 +21,7 @@ } else if (this.life < -this.random.nextInt(10)) { --this.flashes; this.life = 1; -@@ -130,7 +135,7 @@ +@@ -129,7 +134,7 @@ } } @@ -30,37 +30,37 @@ if (!(this.level() instanceof WorldServer)) { this.level().setSkyFlashTime(2); } else if (!this.visualOnly) { -@@ -164,8 +169,12 @@ - IBlockData iblockdata = BlockFireAbstract.getState(this.level(), blockposition); +@@ -169,8 +174,12 @@ + IBlockData iblockdata = BlockFireAbstract.getState(this.level(), blockposition); - if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) { -- this.level().setBlockAndUpdate(blockposition, iblockdata); -- ++this.blocksSetOnFire; -+ // CraftBukkit start - add "!visualOnly" -+ if (!visualOnly && !CraftEventFactory.callBlockIgniteEvent(this.level(), blockposition, this).isCancelled()) { -+ this.level().setBlockAndUpdate(blockposition, iblockdata); -+ ++this.blocksSetOnFire; -+ } -+ // CraftBukkit end - } + if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) { +- this.level().setBlockAndUpdate(blockposition, iblockdata); +- ++this.blocksSetOnFire; ++ // CraftBukkit start - add "!visualOnly" ++ if (!visualOnly && !CraftEventFactory.callBlockIgniteEvent(this.level(), blockposition, this).isCancelled()) { ++ this.level().setBlockAndUpdate(blockposition, iblockdata); ++ ++this.blocksSetOnFire; ++ } ++ // CraftBukkit end + } - for (int j = 0; j < i; ++j) { -@@ -173,8 +182,12 @@ + for (int j = 0; j < i; ++j) { +@@ -178,8 +187,12 @@ - iblockdata = BlockFireAbstract.getState(this.level(), blockposition1); - if (this.level().getBlockState(blockposition1).isAir() && iblockdata.canSurvive(this.level(), blockposition1)) { -- this.level().setBlockAndUpdate(blockposition1, iblockdata); -- ++this.blocksSetOnFire; -+ // CraftBukkit start - add "!visualOnly" -+ if (!visualOnly && !CraftEventFactory.callBlockIgniteEvent(this.level(), blockposition1, this).isCancelled()) { -+ this.level().setBlockAndUpdate(blockposition1, iblockdata); -+ ++this.blocksSetOnFire; -+ } -+ // CraftBukkit end - } - } + iblockdata = BlockFireAbstract.getState(this.level(), blockposition1); + if (this.level().getBlockState(blockposition1).isAir() && iblockdata.canSurvive(this.level(), blockposition1)) { +- this.level().setBlockAndUpdate(blockposition1, iblockdata); +- ++this.blocksSetOnFire; ++ // CraftBukkit start - add "!visualOnly" ++ if (!visualOnly && !CraftEventFactory.callBlockIgniteEvent(this.level(), blockposition1, this).isCancelled()) { ++ this.level().setBlockAndUpdate(blockposition1, iblockdata); ++ ++this.blocksSetOnFire; ++ } ++ // CraftBukkit end + } + } -@@ -238,8 +251,9 @@ +@@ -247,8 +260,9 @@ iblockdata = world.getBlockState(blockposition1); } while (!(iblockdata.getBlock() instanceof WeatheringCopper)); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/EntityLiving.patch b/paper-server/nms-patches/net/minecraft/world/entity/EntityLiving.patch index 1db9c0fb4c..730ea72b1f 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/EntityLiving.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/EntityLiving.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/EntityLiving.java +++ b/net/minecraft/world/entity/EntityLiving.java -@@ -132,6 +132,32 @@ +@@ -137,6 +137,33 @@ import net.minecraft.world.scores.ScoreboardTeam; import org.slf4j.Logger; @@ -8,10 +8,11 @@ +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; -+import com.google.common.base.Function; ++import java.util.LinkedList; +import java.util.UUID; +import net.minecraft.nbt.NBTTagFloat; +import net.minecraft.nbt.NBTTagInt; ++import net.minecraft.world.item.component.Consumable; +import org.bukkit.Location; +import org.bukkit.craftbukkit.attribute.CraftAttributeMap; +import org.bukkit.craftbukkit.event.CraftEventFactory; @@ -33,18 +34,9 @@ public abstract class EntityLiving extends Entity implements Attackable { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -157,7 +183,7 @@ - private static final double MAX_LINE_OF_SIGHT_TEST_RANGE = 128.0D; - protected static final int LIVING_ENTITY_FLAG_IS_USING = 1; - protected static final int LIVING_ENTITY_FLAG_OFF_HAND = 2; -- protected static final int LIVING_ENTITY_FLAG_SPIN_ATTACK = 4; -+ public static final int LIVING_ENTITY_FLAG_SPIN_ATTACK = 4; - protected static final DataWatcherObject DATA_LIVING_ENTITY_FLAGS = DataWatcher.defineId(EntityLiving.class, DataWatcherRegistry.BYTE); - public static final DataWatcherObject DATA_HEALTH_ID = DataWatcher.defineId(EntityLiving.class, DataWatcherRegistry.FLOAT); - private static final DataWatcherObject> DATA_EFFECT_PARTICLES = DataWatcher.defineId(EntityLiving.class, DataWatcherRegistry.PARTICLES); -@@ -249,6 +275,19 @@ +@@ -262,6 +289,19 @@ protected boolean skipDropExperience; - private final Reference2ObjectMap> activeLocationDependentEnchantments; + private final EnumMap>> activeLocationDependentEnchantments; protected float appliedScale; + // CraftBukkit start + public int expToDrop; @@ -62,8 +54,8 @@ protected EntityLiving(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -264,7 +303,9 @@ - this.activeLocationDependentEnchantments = new Reference2ObjectArrayMap(); +@@ -278,7 +318,9 @@ + this.activeLocationDependentEnchantments = new EnumMap(EnumItemSlot.class); this.appliedScale = 1.0F; this.attributes = new AttributeMapBase(AttributeDefaults.getSupplier(entitytypes)); - this.setHealth(this.getMaxHealth()); @@ -73,22 +65,22 @@ this.blocksBuilding = true; this.rotA = (float) ((Math.random() + 1.0D) * 0.009999999776482582D); this.reapplyPosition(); -@@ -344,7 +385,13 @@ +@@ -358,7 +400,13 @@ double d8 = Math.min((double) (0.2F + f / 15.0F), 2.5D); int i = (int) (150.0D * d8); -- ((WorldServer) this.level()).sendParticles(new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D); +- worldserver.sendParticles(new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D); + // CraftBukkit start - visiblity api + if (this instanceof EntityPlayer) { -+ ((WorldServer) this.level()).sendParticles((EntityPlayer) this, new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, false); ++ worldserver.sendParticles((EntityPlayer) this, new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, false); + } else { -+ ((WorldServer) this.level()).sendParticles(new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D); ++ worldserver.sendParticles(new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D); + } + // CraftBukkit end } } } -@@ -555,7 +602,7 @@ +@@ -573,7 +621,7 @@ ++this.deathTime; if (this.deathTime >= 20 && !this.level().isClientSide() && !this.isRemoved()) { this.level().broadcastEntityEvent(this, (byte) 60); @@ -97,7 +89,7 @@ } } -@@ -661,13 +708,19 @@ +@@ -679,13 +727,19 @@ } public void onEquipItem(EnumItemSlot enumitemslot, ItemStack itemstack, ItemStack itemstack1) { @@ -107,18 +99,18 @@ + + public void onEquipItem(EnumItemSlot enumitemslot, ItemStack itemstack, ItemStack itemstack1, boolean silent) { + // CraftBukkit end - boolean flag = itemstack1.isEmpty() && itemstack.isEmpty(); + if (!this.level().isClientSide() && !this.isSpectator()) { + boolean flag = itemstack1.isEmpty() && itemstack.isEmpty(); - if (!flag && !ItemStack.isSameItemSameComponents(itemstack, itemstack1) && !this.firstTick) { - Equipable equipable = Equipable.get(itemstack1); + if (!flag && !ItemStack.isSameItemSameComponents(itemstack, itemstack1) && !this.firstTick) { + Equippable equippable = (Equippable) itemstack1.get(DataComponents.EQUIPPABLE); - if (!this.level().isClientSide() && !this.isSpectator()) { -- if (!this.isSilent() && equipable != null && equipable.getEquipmentSlot() == enumitemslot) { -+ if (!this.isSilent() && equipable != null && equipable.getEquipmentSlot() == enumitemslot && !silent) { // CraftBukkit - this.level().playSeededSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), equipable.getEquipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong()); +- if (!this.isSilent() && equippable != null && enumitemslot == equippable.slot()) { ++ if (!this.isSilent() && equippable != null && enumitemslot == equippable.slot() && !silent) { // CraftBukkit + this.level().playSeededSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), equippable.equipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong()); } -@@ -681,11 +734,18 @@ +@@ -699,6 +753,13 @@ @Override public void remove(Entity.RemovalReason entity_removalreason) { @@ -130,7 +122,10 @@ + public void remove(Entity.RemovalReason entity_removalreason, EntityRemoveEvent.Cause cause) { + // CraftBukkit end if (entity_removalreason == Entity.RemovalReason.KILLED || entity_removalreason == Entity.RemovalReason.DISCARDED) { - this.triggerOnDeathMobEffects(entity_removalreason); + World world = this.level(); + +@@ -709,7 +770,7 @@ + } } - super.remove(entity_removalreason); @@ -138,15 +133,15 @@ this.brain.clearMemories(); } -@@ -698,6 +758,7 @@ - mobeffect.onMobRemoved(this, entity_removalreason); +@@ -722,6 +783,7 @@ + mobeffect.onMobRemoved(worldserver, this, entity_removalreason); } + this.removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause.DEATH); // CraftBukkit this.activeEffects.clear(); } -@@ -757,6 +818,17 @@ +@@ -781,6 +843,17 @@ } } @@ -164,7 +159,7 @@ if (nbttagcompound.contains("Health", 99)) { this.setHealth(nbttagcompound.getFloat("Health")); } -@@ -795,9 +867,32 @@ +@@ -819,9 +892,32 @@ } @@ -197,7 +192,7 @@ try { while (iterator.hasNext()) { Holder holder = (Holder) iterator.next(); -@@ -807,6 +902,12 @@ +@@ -831,6 +927,12 @@ this.onEffectUpdated(mobeffect, true, (Entity) null); })) { if (!this.level().isClientSide) { @@ -208,9 +203,9 @@ + } + // CraftBukkit end iterator.remove(); - this.onEffectRemoved(mobeffect); + this.onEffectsRemoved(List.of(mobeffect)); } -@@ -817,6 +918,17 @@ +@@ -841,6 +943,17 @@ } catch (ConcurrentModificationException concurrentmodificationexception) { ; } @@ -228,7 +223,7 @@ if (this.effectsDirty) { if (!this.level().isClientSide) { -@@ -932,7 +1044,13 @@ +@@ -952,17 +1065,36 @@ this.entityData.set(EntityLiving.DATA_EFFECT_PARTICLES, List.of()); } @@ -241,24 +236,35 @@ + // CraftBukkit end if (this.level().isClientSide) { return false; + } else if (this.activeEffects.isEmpty()) { + return false; } else { -@@ -941,7 +1059,14 @@ - boolean flag; +- Map, MobEffect> map = Maps.newHashMap(this.activeEffects); ++ // CraftBukkit start ++ List toRemove = new LinkedList<>(); ++ Iterator iterator = this.activeEffects.values().iterator(); - for (flag = false; iterator.hasNext(); flag = true) { -- this.onEffectRemoved((MobEffect) iterator.next()); -+ // CraftBukkit start -+ MobEffect effect = (MobEffect) iterator.next(); +- this.activeEffects.clear(); +- this.onEffectsRemoved(map.values()); +- return true; ++ while (iterator.hasNext()) { ++ MobEffect effect = iterator.next(); + EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent(this, effect, null, cause, EntityPotionEffectEvent.Action.CLEARED); + if (event.isCancelled()) { + continue; + } -+ this.onEffectRemoved(effect); -+ // CraftBukkit end - iterator.remove(); - } ++ ++ iterator.remove(); ++ toRemove.add(effect); ++ } ++ ++ this.onEffectsRemoved(toRemove); ++ return !toRemove.isEmpty(); ++ // CraftBukkit end + } + } -@@ -970,20 +1095,50 @@ +@@ -987,20 +1119,50 @@ return this.addEffect(mobeffect, (Entity) null); } @@ -310,7 +316,7 @@ flag = true; } -@@ -1014,13 +1169,39 @@ +@@ -1031,13 +1193,39 @@ return this.getType().is(TagsEntity.INVERTED_HEALING_AND_HARM); } @@ -350,8 +356,8 @@ + // CraftBukkit end if (mobeffect != null) { - this.onEffectRemoved(mobeffect); -@@ -1118,20 +1299,55 @@ + this.onEffectsRemoved(List.of(mobeffect)); +@@ -1142,20 +1330,55 @@ } @@ -408,18 +414,18 @@ this.entityData.set(EntityLiving.DATA_HEALTH_ID, MathHelper.clamp(f, 0.0F, this.getMaxHealth())); } -@@ -1145,7 +1361,7 @@ - return false; - } else if (this.level().isClientSide) { +@@ -1167,7 +1390,7 @@ + public boolean hurtServer(WorldServer worldserver, DamageSource damagesource, float f) { + if (this.isInvulnerableTo(worldserver, damagesource)) { return false; - } else if (this.isDeadOrDying()) { + } else if (this.isRemoved() || this.dead || this.getHealth() <= 0.0F) { // CraftBukkit - Don't allow entities that got set to dead/killed elsewhere to get damaged and die return false; } else if (damagesource.is(DamageTypeTags.IS_FIRE) && this.hasEffect(MobEffects.FIRE_RESISTANCE)) { return false; -@@ -1156,10 +1372,11 @@ +@@ -1182,10 +1405,11 @@ + } - this.noActionTime = 0; float f1 = f; - boolean flag = false; + boolean flag = f > 0.0F && this.isDamageSourceBlocked(damagesource); // Copied from below @@ -431,7 +437,7 @@ this.hurtCurrentlyUsedShield(f); f2 = f; f = 0.0F; -@@ -1176,30 +1393,50 @@ +@@ -1202,15 +1426,26 @@ flag = true; } @@ -458,6 +464,10 @@ + // CraftBukkit end + this.walkAnimation.setSpeed(1.5F); + if (Float.isNaN(f) || Float.isInfinite(f)) { + f = Float.MAX_VALUE; +@@ -1218,18 +1453,27 @@ + boolean flag1 = true; - if ((float) this.invulnerableTime > 10.0F && !damagesource.is(DamageTypeTags.BYPASSES_COOLDOWN)) { @@ -466,9 +476,9 @@ return false; } -- this.actuallyHurt(damagesource, f - this.lastHurt); +- this.actuallyHurt(worldserver, damagesource, f - this.lastHurt); + // CraftBukkit start -+ if (!this.actuallyHurt(damagesource, (float) event.getFinalDamage() - this.lastHurt, event)) { ++ if (!this.actuallyHurt(worldserver, damagesource, (float) event.getFinalDamage() - this.lastHurt, event)) { + return false; + } + // CraftBukkit end @@ -476,20 +486,20 @@ flag1 = false; } else { + // CraftBukkit start -+ if (!this.actuallyHurt(damagesource, (float) event.getFinalDamage(), event)) { ++ if (!this.actuallyHurt(worldserver, damagesource, (float) event.getFinalDamage(), event)) { + return false; + } this.lastHurt = f; - this.invulnerableTime = 20; -- this.actuallyHurt(damagesource, f); +- this.actuallyHurt(worldserver, damagesource, f); + this.invulnerableTime = this.invulnerableDuration; // CraftBukkit - restore use of maxNoDamageTicks -+ // this.actuallyHurt(damagesource, f); ++ // this.actuallyHurt(worldserver, damagesource, f); + // CraftBukkit end this.hurtDuration = 10; this.hurtTime = this.hurtDuration; } -@@ -1245,7 +1482,7 @@ - this.level().broadcastDamageEvent(this, damagesource); +@@ -1275,7 +1519,7 @@ + worldserver.broadcastDamageEvent(this, damagesource); } - if (!damagesource.is(DamageTypeTags.NO_IMPACT) && (!flag || f > 0.0F)) { @@ -497,7 +507,7 @@ this.markHurt(); } -@@ -1265,7 +1502,7 @@ +@@ -1295,7 +1539,7 @@ d1 = damagesource.getSourcePosition().z() - this.getZ(); } @@ -506,7 +516,7 @@ if (!flag) { this.indicateDamage(d0, d1); } -@@ -1284,7 +1521,7 @@ +@@ -1314,7 +1558,7 @@ this.playHurtSound(damagesource); } @@ -515,7 +525,7 @@ if (flag2) { this.lastDamageSource = damagesource; -@@ -1318,7 +1555,7 @@ +@@ -1352,7 +1596,7 @@ } protected void blockedByShield(EntityLiving entityliving) { @@ -524,7 +534,7 @@ } private boolean checkTotemDeathProtection(DamageSource damagesource) { -@@ -1329,19 +1566,32 @@ +@@ -1364,20 +1608,33 @@ EnumHand[] aenumhand = EnumHand.values(); int i = aenumhand.length; @@ -536,7 +546,8 @@ - ItemStack itemstack1 = this.getItemInHand(enumhand); + itemstack1 = this.getItemInHand(enumhand); - if (itemstack1.is(Items.TOTEM_OF_UNDYING)) { + deathprotection = (DeathProtection) itemstack1.get(DataComponents.DEATH_PROTECTION); + if (deathprotection != null) { + hand = enumhand; // CraftBukkit itemstack = itemstack1.copy(); - itemstack1.shrink(1); @@ -560,30 +571,8 @@ + // CraftBukkit end EntityPlayer entityplayer = (EntityPlayer) this; - entityplayer.awardStat(StatisticList.ITEM_USED.get(Items.TOTEM_OF_UNDYING)); -@@ -1350,14 +1600,16 @@ - } - - this.setHealth(1.0F); -- this.removeAllEffects(); -- this.addEffect(new MobEffect(MobEffects.REGENERATION, 900, 1)); -- this.addEffect(new MobEffect(MobEffects.ABSORPTION, 100, 1)); -- this.addEffect(new MobEffect(MobEffects.FIRE_RESISTANCE, 800, 0)); -+ // CraftBukkit start -+ this.removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM); -+ this.addEffect(new MobEffect(MobEffects.REGENERATION, 900, 1), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM); -+ this.addEffect(new MobEffect(MobEffects.ABSORPTION, 100, 1), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM); -+ this.addEffect(new MobEffect(MobEffects.FIRE_RESISTANCE, 800, 0), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TOTEM); -+ // CraftBukkit end - this.level().broadcastEntityEvent(this, (byte) 35); - } - -- return itemstack != null; -+ return !event.isCancelled(); - } - } - -@@ -1464,14 +1716,22 @@ + entityplayer.awardStat(StatisticList.ITEM_USED.get(itemstack.getItem())); +@@ -1501,14 +1758,22 @@ IBlockData iblockdata = Blocks.WITHER_ROSE.defaultBlockState(); if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) { @@ -608,13 +597,13 @@ this.level().addFreshEntity(entityitem); } } -@@ -1482,26 +1742,41 @@ +@@ -1519,22 +1784,37 @@ protected void dropAllDeathLoot(WorldServer worldserver, DamageSource damagesource) { boolean flag = this.lastHurtByPlayerTime > 0; -+ this.dropEquipment(); // CraftBukkit - from below ++ this.dropEquipment(worldserver); // CraftBukkit - from below if (this.shouldDropLoot() && worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { - this.dropFromLootTable(damagesource, flag); + this.dropFromLootTable(worldserver, damagesource, flag); this.dropCustomDeathLoot(worldserver, damagesource, flag); } + // CraftBukkit start - Call death event @@ -622,38 +611,34 @@ + this.drops = new ArrayList<>(); + // CraftBukkit end -- this.dropEquipment(); -+ // this.dropEquipment();// CraftBukkit - moved up - this.dropExperience(damagesource.getEntity()); +- this.dropEquipment(worldserver); ++ // this.dropEquipment(worldserver);// CraftBukkit - moved up + this.dropExperience(worldserver, damagesource.getEntity()); } - protected void dropEquipment() {} + protected void dropEquipment(WorldServer worldserver) {} -- protected void dropExperience(@Nullable Entity entity) { -+ public int getExpReward(@Nullable Entity entity) { // CraftBukkit - World world = this.level(); - - if (world instanceof WorldServer worldserver) { - if (!this.wasExperienceConsumed() && (this.isAlwaysExperienceDropper() || this.lastHurtByPlayerTime > 0 && this.shouldDropExperience() && this.level().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT))) { -- EntityExperienceOrb.award(worldserver, this.position(), this.getExperienceReward(worldserver, entity)); -+ return this.getExperienceReward(worldserver, entity); // CraftBukkit - } +- protected void dropExperience(WorldServer worldserver, @Nullable Entity entity) { ++ public int getExpReward(WorldServer worldserver, @Nullable Entity entity) { // CraftBukkit + if (!this.wasExperienceConsumed() && (this.isAlwaysExperienceDropper() || this.lastHurtByPlayerTime > 0 && this.shouldDropExperience() && worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT))) { +- EntityExperienceOrb.award(worldserver, this.position(), this.getExperienceReward(worldserver, entity)); ++ return this.getExperienceReward(worldserver, entity); // CraftBukkit } } + return 0; // CraftBukkit + } + -+ protected void dropExperience(@Nullable Entity entity) { ++ protected void dropExperience(WorldServer worldserver, @Nullable Entity entity) { + // CraftBukkit start - Update getExpReward() above if the removed if() changes! + if (!(this instanceof net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon)) { // CraftBukkit - SPIGOT-2420: Special case ender dragon will drop the xp over time -+ EntityExperienceOrb.award((WorldServer) this.level(), this.position(), this.expToDrop); ++ EntityExperienceOrb.award(worldserver, this.position(), this.expToDrop); + this.expToDrop = 0; + } + // CraftBukkit end } protected void dropCustomDeathLoot(WorldServer worldserver, DamageSource damagesource, boolean flag) {} -@@ -1540,9 +1815,14 @@ +@@ -1601,9 +1881,14 @@ } public void knockback(double d0, double d1, double d2) { @@ -670,7 +655,7 @@ Vec3D vec3d; -@@ -1552,7 +1832,14 @@ +@@ -1613,7 +1898,14 @@ Vec3D vec3d1 = (new Vec3D(d1, 0.0D, d2)).normalize().scale(d0); @@ -686,8 +671,8 @@ } } -@@ -1613,6 +1900,28 @@ - return itemstack.getEatingSound(); +@@ -1668,6 +1960,20 @@ + return new EntityLiving.a(SoundEffects.GENERIC_SMALL_FALL, SoundEffects.GENERIC_BIG_FALL); } + // CraftBukkit start - Add delegate methods @@ -702,25 +687,17 @@ + public SoundEffect getFallDamageSound0(int fallHeight) { + return getFallDamageSound(fallHeight); + } -+ -+ public SoundEffect getDrinkingSound0(ItemStack itemstack) { -+ return getDrinkingSound(itemstack); -+ } -+ -+ public SoundEffect getEatingSound0(ItemStack itemstack) { -+ return getEatingSound(itemstack); -+ } + // CraftBukkit end + public Optional getLastClimbablePos() { return this.lastClimbablePos; } -@@ -1666,9 +1975,14 @@ +@@ -1746,9 +2052,14 @@ int i = this.calculateFallDamage(f, f1); if (i > 0) { + // CraftBukkit start -+ if (!this.hurt(damagesource, (float) i)) { ++ if (!this.hurtServer((WorldServer) this.level(), damagesource, (float) i)) { + return true; + } + // CraftBukkit end @@ -731,7 +708,7 @@ return true; } else { return flag; -@@ -1738,7 +2052,7 @@ +@@ -1819,7 +2130,7 @@ protected float getDamageAfterArmorAbsorb(DamageSource damagesource, float f) { if (!damagesource.is(DamageTypeTags.BYPASSES_ARMOR)) { @@ -740,7 +717,7 @@ f = CombatMath.getDamageAfterAbsorb(this, f, damagesource, (float) this.getArmorValue(), (float) this.getAttributeValue(GenericAttributes.ARMOR_TOUGHNESS)); } -@@ -1749,7 +2063,8 @@ +@@ -1830,7 +2141,8 @@ if (damagesource.is(DamageTypeTags.BYPASSES_EFFECTS)) { return f; } else { @@ -750,16 +727,16 @@ int i = (this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5; int j = 25 - i; float f1 = f * (float) j; -@@ -1792,15 +2107,140 @@ +@@ -1873,15 +2185,140 @@ } } -- protected void actuallyHurt(DamageSource damagesource, float f) { +- protected void actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f) { + // CraftBukkit start + private EntityDamageEvent handleEntityDamage(final DamageSource damagesource, float f) { + float originalDamage = f; + -+ Function freezing = new Function() { ++ com.google.common.base.Function freezing = new com.google.common.base.Function() { + @Override + public Double apply(Double f) { + if (damagesource.is(DamageTypeTags.IS_FREEZING) && EntityLiving.this.getType().is(TagsEntity.FREEZE_HURTS_EXTRA_TYPES)) { @@ -771,7 +748,7 @@ + float freezingModifier = freezing.apply((double) f).floatValue(); + f += freezingModifier; + -+ Function hardHat = new Function() { ++ com.google.common.base.Function hardHat = new com.google.common.base.Function() { + @Override + public Double apply(Double f) { + if (damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !EntityLiving.this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) { @@ -783,7 +760,7 @@ + float hardHatModifier = hardHat.apply((double) f).floatValue(); + f += hardHatModifier; + -+ Function blocking = new Function() { ++ com.google.common.base.Function blocking = new com.google.common.base.Function() { + @Override + public Double apply(Double f) { + return -((EntityLiving.this.isDamageSourceBlocked(damagesource)) ? f : 0.0); @@ -792,7 +769,7 @@ + float blockingModifier = blocking.apply((double) f).floatValue(); + f += blockingModifier; + -+ Function armor = new Function() { ++ com.google.common.base.Function armor = new com.google.common.base.Function() { + @Override + public Double apply(Double f) { + return -(f - EntityLiving.this.getDamageAfterArmorAbsorb(damagesource, f.floatValue())); @@ -801,7 +778,7 @@ + float armorModifier = armor.apply((double) f).floatValue(); + f += armorModifier; + -+ Function resistance = new Function() { ++ com.google.common.base.Function resistance = new com.google.common.base.Function() { + @Override + public Double apply(Double f) { + if (!damagesource.is(DamageTypeTags.BYPASSES_EFFECTS) && EntityLiving.this.hasEffect(MobEffects.DAMAGE_RESISTANCE) && !damagesource.is(DamageTypeTags.BYPASSES_RESISTANCE)) { @@ -816,7 +793,7 @@ + float resistanceModifier = resistance.apply((double) f).floatValue(); + f += resistanceModifier; + -+ Function magic = new Function() { ++ com.google.common.base.Function magic = new com.google.common.base.Function() { + @Override + public Double apply(Double f) { + return -(f - EntityLiving.this.getDamageAfterMagicAbsorb(damagesource, f.floatValue())); @@ -825,7 +802,7 @@ + float magicModifier = magic.apply((double) f).floatValue(); + f += magicModifier; + -+ Function absorption = new Function() { ++ com.google.common.base.Function absorption = new com.google.common.base.Function() { + @Override + public Double apply(Double f) { + return -(Math.max(f - Math.max(f - EntityLiving.this.getAbsorptionAmount(), 0.0F), 0.0F)); @@ -836,8 +813,8 @@ + return CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, freezingModifier, hardHatModifier, blockingModifier, armorModifier, resistanceModifier, magicModifier, absorptionModifier, freezing, hardHat, blocking, armor, resistance, magic, absorption); + } + -+ protected boolean actuallyHurt(final DamageSource damagesource, float f, final EntityDamageEvent event) { // void -> boolean, add final - if (!this.isInvulnerableTo(damagesource)) { ++ protected boolean actuallyHurt(WorldServer worldserver, final DamageSource damagesource, float f, final EntityDamageEvent event) { // void -> boolean, add final + if (!this.isInvulnerableTo(worldserver, damagesource)) { - f = this.getDamageAfterArmorAbsorb(damagesource, f); - f = this.getDamageAfterMagicAbsorb(damagesource, f); - float f1 = f; @@ -898,7 +875,7 @@ if (f2 > 0.0F && f2 < 3.4028235E37F) { Entity entity = damagesource.getEntity(); -@@ -1812,13 +2252,48 @@ +@@ -1893,13 +2330,48 @@ } } @@ -949,7 +926,7 @@ } public CombatTracker getCombatTracker() { -@@ -1843,9 +2318,19 @@ +@@ -1924,9 +2396,19 @@ } public final void setArrowCount(int i) { @@ -970,7 +947,7 @@ public final int getStingerCount() { return (Integer) this.entityData.get(EntityLiving.DATA_STINGER_COUNT_ID); } -@@ -2086,6 +2571,12 @@ +@@ -2171,6 +2653,12 @@ public abstract ItemStack getItemBySlot(EnumItemSlot enumitemslot); @@ -983,15 +960,7 @@ public abstract void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack); public Iterable getHandSlots() { -@@ -2336,6 +2827,7 @@ - } - - if (this.onGround() && !this.level().isClientSide) { -+ if (getSharedFlag(7) && !CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) // CraftBukkit - this.setSharedFlag(7, false); - } - } else { -@@ -2506,7 +2998,7 @@ +@@ -2623,7 +3111,7 @@ } } @@ -1000,8 +969,8 @@ if (this.tickCount % 20 == 0) { this.getCombatTracker().recheckStatus(); } -@@ -2610,7 +3102,7 @@ - +@@ -2730,7 +3218,7 @@ + this.elytraAnimationState.tick(); } - public void detectEquipmentUpdates() { @@ -1009,15 +978,15 @@ Map map = this.collectEquipmentChanges(); if (map != null) { -@@ -2949,6 +3441,7 @@ - } - +@@ -3052,6 +3540,7 @@ + this.checkSlowFallDistance(); if (!this.level().isClientSide) { -+ if (flag != this.getSharedFlag(7) && !CraftEventFactory.callToggleGlideEvent(this, flag).isCancelled()) // CraftBukkit - this.setSharedFlag(7, flag); - } - -@@ -3141,13 +3634,20 @@ + if (!this.canGlide()) { ++ if (this.getSharedFlag(7) != false && !CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) // CraftBukkit + this.setSharedFlag(7, false); + return; + } +@@ -3298,14 +3787,21 @@ @Override public boolean isPickable() { @@ -1029,30 +998,22 @@ public boolean isPushable() { - return this.isAlive() && !this.isSpectator() && !this.onClimbable(); + return this.isAlive() && !this.isSpectator() && !this.onClimbable() && this.collides; // CraftBukkit -+ } -+ + } + + // CraftBukkit start - collidable API + @Override + public boolean canCollideWithBukkit(Entity entity) { + return isPushable() && this.collides != this.collidableExemptions.contains(entity.getUUID()); - } ++ } + // CraftBukkit end - ++ @Override public float getYHeadRot() { -@@ -3245,7 +3745,7 @@ - - } - -- protected void setLivingEntityFlag(int i, boolean flag) { -+ public void setLivingEntityFlag(int i, boolean flag) { - int j = (Byte) this.entityData.get(EntityLiving.DATA_LIVING_ENTITY_FLAGS); - - if (flag) { -@@ -3346,7 +3846,29 @@ + return this.yHeadRot; +@@ -3476,7 +3972,30 @@ + this.releaseUsingItem(); } else { if (!this.useItem.isEmpty() && this.isUsingItem()) { - this.triggerItemUseEffects(this.useItem, 16); - ItemStack itemstack = this.useItem.finishUsingItem(this.level(), this); + // CraftBukkit start - fire PlayerItemConsumeEvent + ItemStack itemstack; @@ -1064,8 +1025,9 @@ + + if (event.isCancelled()) { + // Update client -+ if (this.useItem.getItem() instanceof net.minecraft.world.item.ItemSuspiciousStew itemSuspiciousStew) { -+ itemSuspiciousStew.cancelUsingItem(entityPlayer, this.useItem); ++ Consumable consumable = this.useItem.get(DataComponents.CONSUMABLE); ++ if (consumable != null) { ++ consumable.cancelUsingItem(entityPlayer, this.useItem); + } + entityPlayer.getBukkitEntity().updateInventory(); + entityPlayer.getBukkitEntity().updateScaledHealth(); @@ -1080,7 +1042,7 @@ if (itemstack != this.useItem) { this.setItemInHand(enumhand, itemstack); -@@ -3424,6 +3946,12 @@ +@@ -3561,6 +4080,12 @@ } public boolean randomTeleport(double d0, double d1, double d2, boolean flag) { @@ -1093,7 +1055,7 @@ double d3 = this.getX(); double d4 = this.getY(); double d5 = this.getZ(); -@@ -3448,16 +3976,41 @@ +@@ -3585,16 +4110,41 @@ } if (flag2) { @@ -1121,7 +1083,7 @@ + } + } else { + // player teleport event is called in the underlining code -+ if (!((EntityPlayer) this).connection.teleport(d0, d6, d2, this.getYRot(), this.getXRot(), java.util.Collections.emptySet(), cause)) { ++ if (!((EntityPlayer) this).connection.teleport(d0, d6, d2, this.getYRot(), this.getXRot(), cause)) { + return Optional.empty(); + } + } @@ -1138,7 +1100,7 @@ } else { if (flag) { world.broadcastEntityEvent(this, (byte) 46); -@@ -3469,7 +4022,7 @@ +@@ -3606,7 +4156,7 @@ entitycreature.getNavigation().stop(); } @@ -1147,7 +1109,7 @@ } } -@@ -3562,7 +4115,7 @@ +@@ -3699,7 +4249,7 @@ } public void stopSleeping() { @@ -1156,7 +1118,7 @@ World world = this.level(); java.util.Objects.requireNonNull(world); -@@ -3596,7 +4149,7 @@ +@@ -3733,7 +4283,7 @@ @Nullable public EnumDirection getBedOrientation() { @@ -1165,12 +1127,3 @@ return blockposition != null ? BlockBed.getBedOrientation(this.level(), blockposition) : null; } -@@ -3633,7 +4186,7 @@ - FoodInfo.b foodinfo_b = (FoodInfo.b) iterator.next(); - - if (this.random.nextFloat() < foodinfo_b.probability()) { -- this.addEffect(foodinfo_b.effect()); -+ this.addEffect(foodinfo_b.effect(), EntityPotionEffectEvent.Cause.FOOD); // CraftBukkit - } - } - diff --git a/paper-server/nms-patches/net/minecraft/world/entity/EntityTameableAnimal.patch b/paper-server/nms-patches/net/minecraft/world/entity/EntityTameableAnimal.patch index cd568c2985..c7f83229ca 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/EntityTameableAnimal.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/EntityTameableAnimal.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/EntityTameableAnimal.java +++ b/net/minecraft/world/entity/EntityTameableAnimal.java -@@ -27,6 +27,12 @@ +@@ -28,6 +28,12 @@ import net.minecraft.world.level.pathfinder.PathfinderNormal; import net.minecraft.world.scores.ScoreboardTeam; @@ -13,7 +13,7 @@ public abstract class EntityTameableAnimal extends EntityAnimal implements OwnableEntity { public static final int TELEPORT_WHEN_DISTANCE_IS_SQ = 144; -@@ -281,7 +287,14 @@ +@@ -292,7 +298,14 @@ if (!this.canTeleportTo(new BlockPosition(i, j, k))) { return false; } else { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/EntityTypes.patch b/paper-server/nms-patches/net/minecraft/world/entity/EntityTypes.patch index fc45d0b23e..a57f473f3c 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/EntityTypes.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/EntityTypes.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/EntityTypes.java +++ b/net/minecraft/world/entity/EntityTypes.java -@@ -168,6 +168,7 @@ +@@ -176,6 +176,7 @@ import net.minecraft.world.phys.Vec3D; import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapes; @@ -8,83 +8,81 @@ import org.slf4j.Logger; public class EntityTypes implements FeatureElement, EntityTypeTest { -@@ -177,7 +178,7 @@ - private static final float MAGIC_HORSE_WIDTH = 1.3964844F; - private static final int DISPLAY_TRACKING_RANGE = 10; +@@ -191,7 +192,7 @@ + return Items.ACACIA_CHEST_BOAT; + }), EnumCreatureType.MISC).noLootTable().sized(1.375F, 0.5625F).eyeHeight(0.5625F).clientTrackingRange(10)); public static final EntityTypes ALLAY = register("allay", EntityTypes.Builder.of(Allay::new, EnumCreatureType.CREATURE).sized(0.35F, 0.6F).eyeHeight(0.36F).ridingOffset(0.04F).clientTrackingRange(8).updateInterval(2)); -- public static final EntityTypes AREA_EFFECT_CLOUD = register("area_effect_cloud", EntityTypes.Builder.of(EntityAreaEffectCloud::new, EnumCreatureType.MISC).fireImmune().sized(6.0F, 0.5F).clientTrackingRange(10).updateInterval(Integer.MAX_VALUE)); -+ public static final EntityTypes AREA_EFFECT_CLOUD = register("area_effect_cloud", EntityTypes.Builder.of(EntityAreaEffectCloud::new, EnumCreatureType.MISC).fireImmune().sized(6.0F, 0.5F).clientTrackingRange(10).updateInterval(10)); // CraftBukkit - SPIGOT-3729: track area effect clouds +- public static final EntityTypes AREA_EFFECT_CLOUD = register("area_effect_cloud", EntityTypes.Builder.of(EntityAreaEffectCloud::new, EnumCreatureType.MISC).noLootTable().fireImmune().sized(6.0F, 0.5F).clientTrackingRange(10).updateInterval(Integer.MAX_VALUE)); ++ public static final EntityTypes AREA_EFFECT_CLOUD = register("area_effect_cloud", EntityTypes.Builder.of(EntityAreaEffectCloud::new, EnumCreatureType.MISC).noLootTable().fireImmune().sized(6.0F, 0.5F).clientTrackingRange(10).updateInterval(10)); // CraftBukkit - SPIGOT-3729: track area effect clouds public static final EntityTypes ARMADILLO = register("armadillo", EntityTypes.Builder.of(Armadillo::new, EnumCreatureType.CREATURE).sized(0.7F, 0.65F).eyeHeight(0.26F).clientTrackingRange(10)); public static final EntityTypes ARMOR_STAND = register("armor_stand", EntityTypes.Builder.of(EntityArmorStand::new, EnumCreatureType.MISC).sized(0.5F, 1.975F).eyeHeight(1.7775F).clientTrackingRange(10)); - public static final EntityTypes ARROW = register("arrow", EntityTypes.Builder.of(EntityTippedArrow::new, EnumCreatureType.MISC).sized(0.5F, 0.5F).eyeHeight(0.13F).clientTrackingRange(4).updateInterval(20)); -@@ -325,8 +326,8 @@ - private final float spawnDimensionsScale; - private final FeatureFlagSet requiredFeatures; - -- private static EntityTypes register(String s, EntityTypes.Builder entitytypes_builder) { -- return (EntityTypes) IRegistry.register(BuiltInRegistries.ENTITY_TYPE, s, entitytypes_builder.build(s)); -+ private static EntityTypes register(String s, EntityTypes.Builder entitytypes_builder) { // CraftBukkit - decompile error -+ return (EntityTypes) IRegistry.register(BuiltInRegistries.ENTITY_TYPE, s, (EntityTypes) entitytypes_builder.build(s)); // CraftBukkit - decompile error + public static final EntityTypes ARROW = register("arrow", EntityTypes.Builder.of(EntityTippedArrow::new, EnumCreatureType.MISC).noLootTable().sized(0.5F, 0.5F).eyeHeight(0.13F).clientTrackingRange(4).updateInterval(20)); +@@ -399,7 +400,7 @@ + return ResourceKey.create(Registries.ENTITY_TYPE, MinecraftKey.withDefaultNamespace(s)); } - public static MinecraftKey getKey(EntityTypes entitytypes) { -@@ -355,7 +356,14 @@ +- private static EntityTypes register(String s, EntityTypes.Builder entitytypes_builder) { ++ private static EntityTypes register(String s, EntityTypes.Builder entitytypes_builder) { // CraftBukkit - decompile error + return register(vanillaEntityId(s), entitytypes_builder); + } + +@@ -431,7 +432,14 @@ @Nullable - public T spawn(WorldServer worldserver, @Nullable ItemStack itemstack, @Nullable EntityHuman entityhuman, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1) { + public T spawn(WorldServer worldserver, @Nullable ItemStack itemstack, @Nullable EntityHuman entityhuman, BlockPosition blockposition, EntitySpawnReason entityspawnreason, boolean flag, boolean flag1) { - Consumer consumer; + // CraftBukkit start -+ return this.spawn(worldserver, itemstack, entityhuman, blockposition, enummobspawn, flag, flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG); ++ return this.spawn(worldserver, itemstack, entityhuman, blockposition, entityspawnreason, flag, flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG); + } + + @Nullable -+ public T spawn(WorldServer worldserver, @Nullable ItemStack itemstack, @Nullable EntityHuman entityhuman, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) { ++ public T spawn(WorldServer worldserver, @Nullable ItemStack itemstack, @Nullable EntityHuman entityhuman, BlockPosition blockposition, EntitySpawnReason entityspawnreason, boolean flag, boolean flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) { + // CraftBukkit end + Consumer consumer; // CraftBukkit - decompile error if (itemstack != null) { consumer = createDefaultStackConfig(worldserver, itemstack, entityhuman); -@@ -364,7 +372,7 @@ +@@ -440,7 +448,7 @@ }; } -- return this.spawn(worldserver, consumer, blockposition, enummobspawn, flag, flag1); -+ return this.spawn(worldserver, consumer, blockposition, enummobspawn, flag, flag1, spawnReason); // CraftBukkit +- return this.spawn(worldserver, consumer, blockposition, entityspawnreason, flag, flag1); ++ return this.spawn(worldserver, consumer, blockposition, entityspawnreason, flag, flag1, spawnReason); // CraftBukkit } - public static Consumer createDefaultStackConfig(WorldServer worldserver, ItemStack itemstack, @Nullable EntityHuman entityhuman) { -@@ -388,21 +396,37 @@ + public static Consumer createDefaultStackConfig(World world, ItemStack itemstack, @Nullable EntityHuman entityhuman) { +@@ -464,21 +472,37 @@ CustomData customdata = (CustomData) itemstack.getOrDefault(DataComponents.ENTITY_DATA, CustomData.EMPTY); return !customdata.isEmpty() ? consumer.andThen((entity) -> { -- updateCustomEntityTag(worldserver, entityhuman, entity, customdata); -+ try { updateCustomEntityTag(worldserver, entityhuman, entity, customdata); } catch (Throwable t) { LOGGER.warn("Error loading spawn egg NBT", t); } // CraftBukkit - SPIGOT-5665 +- updateCustomEntityTag(world, entityhuman, entity, customdata); ++ try { updateCustomEntityTag(world, entityhuman, entity, customdata); } catch (Throwable t) { LOGGER.warn("Error loading spawn egg NBT", t); } // CraftBukkit - SPIGOT-5665 }) : consumer; } @Nullable - public T spawn(WorldServer worldserver, BlockPosition blockposition, EnumMobSpawn enummobspawn) { -- return this.spawn(worldserver, (Consumer) null, blockposition, enummobspawn, false, false); + public T spawn(WorldServer worldserver, BlockPosition blockposition, EntitySpawnReason entityspawnreason) { +- return this.spawn(worldserver, (Consumer) null, blockposition, entityspawnreason, false, false); + // CraftBukkit start -+ return this.spawn(worldserver, blockposition, enummobspawn, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT); ++ return this.spawn(worldserver, blockposition, entityspawnreason, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT); + } + + @Nullable -+ public T spawn(WorldServer worldserver, BlockPosition blockposition, EnumMobSpawn enummobspawn, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) { -+ return this.spawn(worldserver, (Consumer) null, blockposition, enummobspawn, false, false, spawnReason); // CraftBukkit - decompile error ++ public T spawn(WorldServer worldserver, BlockPosition blockposition, EntitySpawnReason entityspawnreason, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) { ++ return this.spawn(worldserver, (Consumer) null, blockposition, entityspawnreason, false, false, spawnReason); // CraftBukkit - decompile error + // CraftBukkit end } @Nullable - public T spawn(WorldServer worldserver, @Nullable Consumer consumer, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1) { + public T spawn(WorldServer worldserver, @Nullable Consumer consumer, BlockPosition blockposition, EntitySpawnReason entityspawnreason, boolean flag, boolean flag1) { + // CraftBukkit start -+ return this.spawn(worldserver, consumer, blockposition, enummobspawn, flag, flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT); ++ return this.spawn(worldserver, consumer, blockposition, entityspawnreason, flag, flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT); + } + + @Nullable -+ public T spawn(WorldServer worldserver, @Nullable Consumer consumer, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) { ++ public T spawn(WorldServer worldserver, @Nullable Consumer consumer, BlockPosition blockposition, EntitySpawnReason entityspawnreason, boolean flag, boolean flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) { + // CraftBukkit end - T t0 = this.create(worldserver, consumer, blockposition, enummobspawn, flag, flag1); + T t0 = this.create(worldserver, consumer, blockposition, entityspawnreason, flag, flag1); if (t0 != null) { - worldserver.addFreshEntityWithPassengers(t0); @@ -94,7 +92,7 @@ } return t0; -@@ -583,7 +607,7 @@ +@@ -649,7 +673,7 @@ } return entity; @@ -102,8 +100,8 @@ + }).orElse(null); // CraftBukkit - decompile error } - public static Stream loadEntitiesRecursive(final List list, final World world) { -@@ -644,7 +668,7 @@ + public static Stream loadEntitiesRecursive(final List list, final World world, final EntitySpawnReason entityspawnreason) { +@@ -710,7 +734,7 @@ @Nullable public T tryCast(Entity entity) { @@ -112,7 +110,7 @@ } @Override -@@ -681,7 +705,7 @@ +@@ -779,7 +803,7 @@ this.canSpawnFarFromPlayer = enumcreaturetype == EnumCreatureType.CREATURE || enumcreaturetype == EnumCreatureType.MISC; } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/IEntitySelector.patch b/paper-server/nms-patches/net/minecraft/world/entity/IEntitySelector.patch index 625f1d6c14..35099c5ae7 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/IEntitySelector.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/IEntitySelector.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/IEntitySelector.java +++ b/net/minecraft/world/entity/IEntitySelector.java -@@ -44,7 +44,7 @@ +@@ -43,7 +43,7 @@ ScoreboardTeamBase.EnumTeamPush scoreboardteambase_enumteampush = scoreboardteam == null ? ScoreboardTeamBase.EnumTeamPush.ALWAYS : scoreboardteam.getCollisionRule(); return (Predicate) (scoreboardteambase_enumteampush == ScoreboardTeamBase.EnumTeamPush.NEVER ? Predicates.alwaysFalse() : IEntitySelector.NO_SPECTATORS.and((entity1) -> { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/Interaction.patch b/paper-server/nms-patches/net/minecraft/world/entity/Interaction.patch index 230f95fb0d..69b475e87a 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/Interaction.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/Interaction.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/Interaction.java +++ b/net/minecraft/world/entity/Interaction.java -@@ -24,6 +24,12 @@ +@@ -26,6 +26,12 @@ import net.minecraft.world.phys.AxisAlignedBB; import org.slf4j.Logger; @@ -13,7 +13,7 @@ public class Interaction extends Entity implements Attackable, Targeting { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -62,7 +68,7 @@ +@@ -64,7 +70,7 @@ this.setHeight(nbttagcompound.getFloat("height")); } @@ -22,7 +22,7 @@ Logger logger; if (nbttagcompound.contains("attack")) { -@@ -142,9 +148,16 @@ +@@ -144,9 +150,16 @@ @Override public boolean skipAttackInteraction(Entity entity) { if (entity instanceof EntityHuman entityhuman) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/Leashable.patch b/paper-server/nms-patches/net/minecraft/world/entity/Leashable.patch index 16295d0a0f..770872a7a1 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/Leashable.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/Leashable.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/Leashable.java +++ b/net/minecraft/world/entity/Leashable.java -@@ -15,6 +15,11 @@ +@@ -16,6 +16,11 @@ import net.minecraft.world.level.IMaterial; import net.minecraft.world.level.World; @@ -12,7 +12,7 @@ public interface Leashable { String LEASH_TAG = "leash"; -@@ -44,7 +49,7 @@ +@@ -45,7 +50,7 @@ default void setDelayedLeashHolderId(int i) { this.setLeashData(new Leashable.a(i)); @@ -21,7 +21,7 @@ } @Nullable -@@ -53,7 +58,7 @@ +@@ -54,7 +59,7 @@ return new Leashable.a(Either.left(nbttagcompound.getCompound("leash").getUUID("UUID"))); } else { if (nbttagcompound.contains("leash", 11)) { @@ -30,7 +30,7 @@ if (either != null) { return new Leashable.a(either); -@@ -68,6 +73,11 @@ +@@ -69,6 +74,11 @@ if (leashable_a != null) { Either either = leashable_a.delayedLeashInfo; Entity entity = leashable_a.leashHolder; @@ -42,17 +42,17 @@ if (entity instanceof EntityLeash) { EntityLeash entityleash = (EntityLeash) entity; -@@ -110,7 +120,9 @@ +@@ -111,7 +121,9 @@ } if (e0.tickCount > 100) { + e0.forceDrops = true; // CraftBukkit - e0.spawnAtLocation((IMaterial) Items.LEAD); + e0.spawnAtLocation(worldserver, (IMaterial) Items.LEAD); + e0.forceDrops = false; // CraftBukkit ((Leashable) e0).setLeashData((Leashable.a) null); } } -@@ -119,7 +131,7 @@ +@@ -120,7 +132,7 @@ } default void dropLeash(boolean flag, boolean flag1) { @@ -61,27 +61,27 @@ } private static void dropLeash(E e0, boolean flag, boolean flag1) { -@@ -128,7 +140,9 @@ - if (leashable_a != null && leashable_a.leashHolder != null) { - ((Leashable) e0).setLeashData((Leashable.a) null); - if (!e0.level().isClientSide && flag1) { -+ e0.forceDrops = true; // CraftBukkit - e0.spawnAtLocation((IMaterial) Items.LEAD); -+ e0.forceDrops = false; // CraftBukkit - } +@@ -134,7 +146,9 @@ + WorldServer worldserver = (WorldServer) world; - if (flag) { -@@ -153,7 +167,8 @@ + if (flag1) { ++ e0.forceDrops = true; // CraftBukkit + e0.spawnAtLocation(worldserver, (IMaterial) Items.LEAD); ++ e0.forceDrops = false; // CraftBukkit + } + + if (flag) { +@@ -154,7 +168,8 @@ if (leashable_a != null && leashable_a.leashHolder != null) { if (!e0.isAlive() || !leashable_a.leashHolder.isAlive()) { -- dropLeash(e0, true, true); -+ e0.level().getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(e0.getBukkitEntity(), (!e0.isAlive()) ? UnleashReason.PLAYER_UNLEASH : UnleashReason.HOLDER_GONE)); // CraftBukkit -+ dropLeash(e0, true, !e0.pluginRemoved); // CraftBukkit - SPIGOT-7487: Don't drop leash, when the holder was removed by a plugin +- dropLeash(e0, true, worldserver.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)); ++ worldserver.getCraftServer().getPluginManager().callEvent(new EntityUnleashEvent(e0.getBukkitEntity(), (!e0.isAlive()) ? UnleashReason.PLAYER_UNLEASH : UnleashReason.HOLDER_GONE)); // CraftBukkit ++ dropLeash(e0, true, worldserver.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS) && !e0.pluginRemoved); // CraftBukkit - SPIGOT-7487: Don't drop leash, when the holder was removed by a plugin } Entity entity = ((Leashable) e0).getLeashHolder(); -@@ -183,13 +198,18 @@ +@@ -184,13 +199,18 @@ } default void leashTooFarBehaviour() { @@ -101,7 +101,7 @@ } private static void legacyElasticRangeLeashBehaviour(E e0, Entity entity, float f) { -@@ -201,7 +221,7 @@ +@@ -202,7 +222,7 @@ } default void setLeashedTo(Entity entity, boolean flag) { @@ -110,7 +110,7 @@ } private static void setLeashedTo(E e0, Entity entity, boolean flag) { -@@ -232,7 +252,7 @@ +@@ -233,7 +253,7 @@ @Nullable default Entity getLeashHolder() { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorAttackTargetForget.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorAttackTargetForget.patch index 68f2b43b4c..7952cb5e14 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorAttackTargetForget.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorAttackTargetForget.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/ai/behavior/BehaviorAttackTargetForget.java +++ b/net/minecraft/world/entity/ai/behavior/BehaviorAttackTargetForget.java -@@ -8,6 +8,12 @@ +@@ -7,6 +7,12 @@ import net.minecraft.world.entity.ai.behavior.declarative.BehaviorBuilder; import net.minecraft.world.entity.ai.memory.MemoryModuleType; @@ -13,8 +13,8 @@ public class BehaviorAttackTargetForget { private static final int TIMEOUT_TO_GET_WITHIN_ATTACK_RANGE = 200; -@@ -41,6 +47,17 @@ - if (entityinsentient.canAttack(entityliving) && (!flag || !isTiredOfTryingToReachTarget(entityinsentient, behaviorbuilder_b.tryGet(memoryaccessor1))) && entityliving.isAlive() && entityliving.level() == entityinsentient.level() && !predicate.test(entityliving)) { +@@ -40,6 +46,17 @@ + if (entityinsentient.canAttack(entityliving) && (!flag || !isTiredOfTryingToReachTarget(entityinsentient, behaviorbuilder_b.tryGet(memoryaccessor1))) && entityliving.isAlive() && entityliving.level() == entityinsentient.level() && !behaviorattacktargetforget_a.test(worldserver, entityliving)) { return true; } else { + // CraftBukkit start @@ -28,6 +28,6 @@ + return true; + } + // CraftBukkit end - biconsumer.accept(entityinsentient, entityliving); + behaviorattacktargetforget_b.accept(worldserver, entityinsentient, entityliving); memoryaccessor.erase(); return true; diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorAttackTargetSet.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorAttackTargetSet.patch index 774133bc5c..51929e4020 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorAttackTargetSet.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorAttackTargetSet.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/ai/behavior/BehaviorAttackTargetSet.java +++ b/net/minecraft/world/entity/ai/behavior/BehaviorAttackTargetSet.java -@@ -8,6 +8,13 @@ +@@ -7,6 +7,13 @@ import net.minecraft.world.entity.ai.behavior.declarative.BehaviorBuilder; import net.minecraft.world.entity.ai.memory.MemoryModuleType; @@ -14,7 +14,7 @@ public class BehaviorAttackTargetSet { public BehaviorAttackTargetSet() {} -@@ -35,6 +42,17 @@ +@@ -34,6 +41,17 @@ if (!entityinsentient.canAttack(entityliving)) { return false; } else { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorFindAdmirableItem.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorFindAdmirableItem.patch index de85cbfef8..bc34f91743 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorFindAdmirableItem.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorFindAdmirableItem.patch @@ -3,7 +3,7 @@ @@ -28,6 +28,20 @@ EntityItem entityitem = (EntityItem) behaviorbuilder_b.get(memoryaccessor2); - if (behaviorbuilder_b.tryGet(memoryaccessor3).isEmpty() && predicate.test(entityliving) && entityitem.closerThan(entityliving, (double) i) && entityliving.level().getWorldBorder().isWithinBounds(entityitem.blockPosition())) { + if (behaviorbuilder_b.tryGet(memoryaccessor3).isEmpty() && predicate.test(entityliving) && entityitem.closerThan(entityliving, (double) i) && entityliving.level().getWorldBorder().isWithinBounds(entityitem.blockPosition()) && entityliving.canPickUpLoot()) { + // CraftBukkit start + if (entityliving instanceof net.minecraft.world.entity.animal.allay.Allay) { + org.bukkit.event.entity.EntityTargetEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetEvent(entityliving, entityitem, org.bukkit.event.entity.EntityTargetEvent.TargetReason.CLOSEST_ENTITY); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/PrepareRamNearestTarget.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/PrepareRamNearestTarget.patch index 822fafa21f..eed68fa491 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/PrepareRamNearestTarget.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/PrepareRamNearestTarget.patch @@ -15,7 +15,7 @@ public static final int TIME_OUT_DURATION = 160; @@ -63,6 +70,13 @@ - return this.ramTargeting.test(entitycreature, entityliving); + return this.ramTargeting.test(worldserver, entitycreature, entityliving); }); }).ifPresent((entityliving) -> { + // CraftBukkit start diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalBreakDoor.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalBreakDoor.patch index 2a6ba8eb11..c4a2f98fcd 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalBreakDoor.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalBreakDoor.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/ai/goal/PathfinderGoalBreakDoor.java +++ b/net/minecraft/world/entity/ai/goal/PathfinderGoalBreakDoor.java -@@ -71,6 +71,12 @@ +@@ -72,6 +72,12 @@ } if (this.breakTime == this.getDoorBreakTime() && this.isValidDifficulty(this.mob.level().getDifficulty())) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalEatTile.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalEatTile.patch index 169dd13029..34b12bbccc 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalEatTile.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalEatTile.patch @@ -15,8 +15,8 @@ BlockPosition blockposition = this.mob.blockPosition(); if (PathfinderGoalEatTile.IS_TALL_GRASS.test(this.level.getBlockState(blockposition))) { -- if (this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { -+ if (CraftEventFactory.callEntityChangeBlockEvent(this.mob, blockposition, Blocks.AIR.defaultBlockState(), !this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))) { // CraftBukkit +- if (getServerLevel(this.level).getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { ++ if (CraftEventFactory.callEntityChangeBlockEvent(this.mob, blockposition, Blocks.AIR.defaultBlockState(), !getServerLevel(this.level).getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))) { // CraftBukkit this.level.destroyBlock(blockposition, false); } @@ -24,8 +24,8 @@ BlockPosition blockposition1 = blockposition.below(); if (this.level.getBlockState(blockposition1).is(Blocks.GRASS_BLOCK)) { -- if (this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { -+ if (CraftEventFactory.callEntityChangeBlockEvent(this.mob, blockposition1, Blocks.AIR.defaultBlockState(), !this.level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))) { // CraftBukkit +- if (getServerLevel(this.level).getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { ++ if (CraftEventFactory.callEntityChangeBlockEvent(this.mob, blockposition1, Blocks.AIR.defaultBlockState(), !getServerLevel(this.level).getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))) { // CraftBukkit this.level.levelEvent(2001, blockposition1, Block.getId(Blocks.GRASS_BLOCK.defaultBlockState())); this.level.setBlock(blockposition1, Blocks.DIRT.defaultBlockState(), 2); } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalRemoveBlock.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalRemoveBlock.patch index 060e890547..b0ee5531f7 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalRemoveBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalRemoveBlock.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/ai/goal/PathfinderGoalRemoveBlock.java +++ b/net/minecraft/world/entity/ai/goal/PathfinderGoalRemoveBlock.java -@@ -21,6 +21,11 @@ +@@ -22,6 +22,11 @@ import net.minecraft.world.level.chunk.status.ChunkStatus; import net.minecraft.world.phys.Vec3D; @@ -12,7 +12,7 @@ public class PathfinderGoalRemoveBlock extends PathfinderGoalGotoTarget { private final Block blockToRemove; -@@ -96,6 +101,11 @@ +@@ -97,6 +102,11 @@ } if (this.ticksSinceReachedGoal > 60) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalTempt.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalTempt.patch index f47a666e9a..bff667efef 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalTempt.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalTempt.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/ai/goal/PathfinderGoalTempt.java +++ b/net/minecraft/world/entity/ai/goal/PathfinderGoalTempt.java -@@ -10,6 +10,13 @@ +@@ -11,6 +11,13 @@ import net.minecraft.world.entity.player.EntityHuman; import net.minecraft.world.item.ItemStack; @@ -13,8 +13,8 @@ + public class PathfinderGoalTempt extends PathfinderGoal { - private static final PathfinderTargetCondition TEMP_TARGETING = PathfinderTargetCondition.forNonCombat().range(10.0D).ignoreLineOfSight(); -@@ -22,7 +29,7 @@ + private static final PathfinderTargetCondition TEMPT_TARGETING = PathfinderTargetCondition.forNonCombat().ignoreLineOfSight(); +@@ -23,7 +30,7 @@ private double pRotX; private double pRotY; @Nullable @@ -23,10 +23,10 @@ private int calmDown; private boolean isRunning; private final Predicate items; -@@ -44,6 +51,15 @@ +@@ -47,6 +54,15 @@ return false; } else { - this.player = this.mob.level().getNearestPlayer(this.targetingConditions, this.mob); + this.player = getServerLevel((Entity) this.mob).getNearestPlayer(this.targetingConditions.range(this.mob.getAttributeValue(GenericAttributes.TEMPT_RANGE)), this.mob); + // CraftBukkit start + if (this.player != null) { + EntityTargetLivingEntityEvent event = CraftEventFactory.callEntityTargetLivingEvent(this.mob, this.player, EntityTargetEvent.TargetReason.TEMPT); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/target/PathfinderGoalDefendVillage.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/target/PathfinderGoalDefendVillage.patch index 8e8bf5a04a..e5894e995f 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/target/PathfinderGoalDefendVillage.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/target/PathfinderGoalDefendVillage.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/ai/goal/target/PathfinderGoalDefendVillage.java +++ b/net/minecraft/world/entity/ai/goal/target/PathfinderGoalDefendVillage.java -@@ -58,7 +58,7 @@ +@@ -61,7 +61,7 @@ @Override public void start() { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/target/PathfinderGoalNearestAttackableTarget.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/target/PathfinderGoalNearestAttackableTarget.patch index bc34787305..61d5a08fda 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/target/PathfinderGoalNearestAttackableTarget.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/target/PathfinderGoalNearestAttackableTarget.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/ai/goal/target/PathfinderGoalNearestAttackableTarget.java +++ b/net/minecraft/world/entity/ai/goal/target/PathfinderGoalNearestAttackableTarget.java -@@ -67,7 +67,7 @@ +@@ -70,7 +70,7 @@ @Override public void start() { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/sensing/TemptingSensor.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/sensing/TemptingSensor.patch index 2301d3e948..0781087ad9 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/sensing/TemptingSensor.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/sensing/TemptingSensor.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/ai/sensing/TemptingSensor.java +++ b/net/minecraft/world/entity/ai/sensing/TemptingSensor.java -@@ -18,6 +18,14 @@ +@@ -19,6 +19,14 @@ import net.minecraft.world.entity.player.EntityHuman; import net.minecraft.world.item.ItemStack; @@ -14,17 +14,17 @@ + public class TemptingSensor extends Sensor { - public static final int TEMPTATION_RANGE = 10; -@@ -30,7 +38,7 @@ - + private static final PathfinderTargetCondition TEMPT_TARGETING = PathfinderTargetCondition.forNonCombat().ignoreLineOfSight(); +@@ -31,7 +39,7 @@ protected void doTick(WorldServer worldserver, EntityCreature entitycreature) { BehaviorController behaviorcontroller = entitycreature.getBrain(); + PathfinderTargetCondition pathfindertargetcondition = TemptingSensor.TEMPT_TARGETING.copy().range((double) ((float) entitycreature.getAttributeValue(GenericAttributes.TEMPT_RANGE))); - Stream stream = worldserver.players().stream().filter(IEntitySelector.NO_SPECTATORS).filter((entityplayer) -> { + Stream stream = worldserver.players().stream().filter(IEntitySelector.NO_SPECTATORS).filter((entityplayer) -> { // CraftBukkit - decompile error - return TemptingSensor.TEMPT_TARGETING.test(entitycreature, entityplayer); - }).filter((entityplayer) -> { - return entitycreature.closerThan(entityplayer, 10.0D); -@@ -44,7 +52,17 @@ + return pathfindertargetcondition.test(worldserver, entitycreature, entityplayer); + }).filter(this::playerHoldingTemptation).filter((entityplayer) -> { + return !entitycreature.hasPassenger((Entity) entityplayer); +@@ -43,7 +51,17 @@ if (!list.isEmpty()) { EntityHuman entityhuman = (EntityHuman) list.get(0); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ambient/EntityBat.patch b/paper-server/nms-patches/net/minecraft/world/entity/ambient/EntityBat.patch index 3f575b8b51..fbac4f6090 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ambient/EntityBat.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ambient/EntityBat.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/entity/ambient/EntityBat.java +++ b/net/minecraft/world/entity/ambient/EntityBat.java -@@ -27,6 +27,10 @@ - import net.minecraft.world.level.block.state.IBlockData; +@@ -30,6 +30,10 @@ + import net.minecraft.world.level.levelgen.HeightMap; import net.minecraft.world.phys.Vec3D; +// CraftBukkit start @@ -11,37 +11,37 @@ public class EntityBat extends EntityAmbient { public static final float FLAP_LENGTH_SECONDS = 0.5F; -@@ -141,13 +145,13 @@ +@@ -144,13 +148,13 @@ this.yHeadRot = (float) this.random.nextInt(360); } -- if (this.level().getNearestPlayer(EntityBat.BAT_RESTING_TARGETING, this) != null) { -+ if (this.level().getNearestPlayer(EntityBat.BAT_RESTING_TARGETING, this) != null && CraftEventFactory.handleBatToggleSleepEvent(this, true)) { // CraftBukkit - Call BatToggleSleepEvent +- if (worldserver.getNearestPlayer(EntityBat.BAT_RESTING_TARGETING, this) != null) { ++ if (worldserver.getNearestPlayer(EntityBat.BAT_RESTING_TARGETING, this) != null && CraftEventFactory.handleBatToggleSleepEvent(this, true)) { // CraftBukkit - Call BatToggleSleepEvent this.setResting(false); if (!flag) { - this.level().levelEvent((EntityHuman) null, 1025, blockposition, 0); + worldserver.levelEvent((EntityHuman) null, 1025, blockposition, 0); } } - } else { + } else if (CraftEventFactory.handleBatToggleSleepEvent(this, true)) { // CraftBukkit - Call BatToggleSleepEvent this.setResting(false); if (!flag) { - this.level().levelEvent((EntityHuman) null, 1025, blockposition, 0); -@@ -174,7 +178,7 @@ + worldserver.levelEvent((EntityHuman) null, 1025, blockposition, 0); +@@ -177,7 +181,7 @@ this.zza = 0.5F; this.setYRot(this.getYRot() + f1); -- if (this.random.nextInt(100) == 0 && this.level().getBlockState(blockposition1).isRedstoneConductor(this.level(), blockposition1)) { -+ if (this.random.nextInt(100) == 0 && this.level().getBlockState(blockposition1).isRedstoneConductor(this.level(), blockposition1) && CraftEventFactory.handleBatToggleSleepEvent(this, false)) { // CraftBukkit - Call BatToggleSleepEvent +- if (this.random.nextInt(100) == 0 && worldserver.getBlockState(blockposition1).isRedstoneConductor(worldserver, blockposition1)) { ++ if (this.random.nextInt(100) == 0 && worldserver.getBlockState(blockposition1).isRedstoneConductor(worldserver, blockposition1) && CraftEventFactory.handleBatToggleSleepEvent(this, false)) { // CraftBukkit - Call BatToggleSleepEvent this.setResting(true); } } -@@ -199,7 +203,7 @@ - if (this.isInvulnerableTo(damagesource)) { +@@ -202,7 +206,7 @@ + if (this.isInvulnerableTo(worldserver, damagesource)) { return false; } else { -- if (!this.level().isClientSide && this.isResting()) { -+ if (!this.level().isClientSide && this.isResting() && CraftEventFactory.handleBatToggleSleepEvent(this, true)) { // CraftBukkit - Call BatToggleSleepEvent +- if (this.isResting()) { ++ if (this.isResting() && CraftEventFactory.handleBatToggleSleepEvent(this, true)) { // CraftBukkit - Call BatToggleSleepEvent this.setResting(false); } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/Bucketable.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/Bucketable.patch index 77ebdc3f32..1476f05000 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/Bucketable.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/Bucketable.patch @@ -45,6 +45,6 @@ - t0.discard(); + t0.discard(EntityRemoveEvent.Cause.PICKUP); // CraftBukkit - add Bukkit remove cause - return Optional.of(EnumInteractionResult.sidedSuccess(world.isClientSide)); + return Optional.of(EnumInteractionResult.SUCCESS); } else { return Optional.empty(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityAnimal.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityAnimal.patch index 1c9add4db7..2a29f15fe9 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityAnimal.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityAnimal.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntityAnimal.java +++ b/net/minecraft/world/entity/animal/EntityAnimal.java -@@ -29,12 +29,20 @@ +@@ -35,12 +35,20 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.pathfinder.PathType; @@ -21,25 +21,25 @@ protected EntityAnimal(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -72,9 +80,15 @@ +@@ -82,9 +90,15 @@ } @Override -- protected void actuallyHurt(DamageSource damagesource, float f) { +- protected void actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f) { + // CraftBukkit start - void -> boolean -+ public boolean actuallyHurt(DamageSource damagesource, float f, EntityDamageEvent event) { -+ boolean damageResult = super.actuallyHurt(damagesource, f, event); ++ public boolean actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f, EntityDamageEvent event) { ++ boolean damageResult = super.actuallyHurt(worldserver, damagesource, f, event); + if (!damageResult) { + return false; + } this.resetLove(); -- super.actuallyHurt(damagesource, f); +- super.actuallyHurt(worldserver, damagesource, f); + return true; + // CraftBukkit end } @Override -@@ -162,10 +176,17 @@ +@@ -188,10 +202,17 @@ } public void setInLove(@Nullable EntityHuman entityhuman) { @@ -58,7 +58,7 @@ this.level().broadcastEntityEvent(this, (byte) 18); } -@@ -207,12 +228,29 @@ +@@ -233,12 +254,29 @@ if (entityageable != null) { entityageable.setBaby(true); entityageable.moveTo(this.getX(), this.getY(), this.getZ(), 0.0F, 0.0F); @@ -90,7 +90,7 @@ Optional.ofNullable(this.getLoveCause()).or(() -> { return Optional.ofNullable(entityanimal.getLoveCause()); }).ifPresent((entityplayer) -> { -@@ -225,7 +263,11 @@ +@@ -251,7 +289,11 @@ entityanimal.resetLove(); worldserver.broadcastEntityEvent(this, (byte) 18); if (worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityBee.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityBee.patch index b3940b512e..7ed8bcd274 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityBee.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityBee.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntityBee.java +++ b/net/minecraft/world/entity/animal/EntityBee.java -@@ -87,6 +87,12 @@ +@@ -89,6 +89,12 @@ import net.minecraft.world.level.pathfinder.PathType; import net.minecraft.world.phys.Vec3D; @@ -13,7 +13,7 @@ public class EntityBee extends EntityAnimal implements IEntityAngerable, EntityBird { public static final float FLAP_DEGREES_PER_TICK = 120.32113F; -@@ -186,12 +192,19 @@ +@@ -194,12 +200,19 @@ @Override public void addAdditionalSaveData(NBTTagCompound nbttagcompound) { @@ -35,18 +35,18 @@ nbttagcompound.put("flower_pos", GameProfileSerializer.writeBlockPos(this.getSavedFlowerPos())); } -@@ -205,8 +218,8 @@ - - @Override - public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { +@@ -219,8 +232,8 @@ + this.ticksWithoutNectarSinceExitingHive = nbttagcompound.getInt("TicksSincePollination"); + this.stayOutOfHiveCountdown = nbttagcompound.getInt("CannotEnterHiveTicks"); + this.numCropsGrownSincePollination = nbttagcompound.getInt("CropsGrownSincePollination"); - this.hivePos = (BlockPosition) GameProfileSerializer.readBlockPos(nbttagcompound, "hive_pos").orElse((Object) null); - this.savedFlowerPos = (BlockPosition) GameProfileSerializer.readBlockPos(nbttagcompound, "flower_pos").orElse((Object) null); + this.hivePos = (BlockPosition) GameProfileSerializer.readBlockPos(nbttagcompound, "hive_pos").orElse(null); // CraftBukkit - decompile error + this.savedFlowerPos = (BlockPosition) GameProfileSerializer.readBlockPos(nbttagcompound, "flower_pos").orElse(null); // CraftBukkit - decompile error - super.readAdditionalSaveData(nbttagcompound); - this.setHasNectar(nbttagcompound.getBoolean("HasNectar")); - this.setHasStung(nbttagcompound.getBoolean("HasStung")); -@@ -243,7 +256,7 @@ + this.readPersistentAngerSaveData(this.level(), nbttagcompound); + } + +@@ -244,7 +257,7 @@ } if (b0 > 0) { @@ -55,24 +55,32 @@ } } -@@ -636,11 +649,14 @@ - if (this.isInvulnerableTo(damagesource)) { +@@ -502,7 +515,7 @@ + + @Nullable + TileEntityBeehive getBeehiveBlockEntity() { +- return this.hivePos == null ? null : (this.isTooFarAway(this.hivePos) ? null : (TileEntityBeehive) this.level().getBlockEntity(this.hivePos, TileEntityTypes.BEEHIVE).orElse((Object) null)); ++ return this.hivePos == null ? null : (this.isTooFarAway(this.hivePos) ? null : (TileEntityBeehive) this.level().getBlockEntity(this.hivePos, TileEntityTypes.BEEHIVE).orElse(null)); // CraftBukkit - decompile error + } + + boolean isHiveValid() { +@@ -638,8 +651,14 @@ + if (this.isInvulnerableTo(worldserver, damagesource)) { return false; } else { -- if (!this.level().isClientSide) { + // CraftBukkit start - Only stop pollinating if entity was damaged -+ boolean result = super.hurt(damagesource, f); -+ if (result && !this.level().isClientSide) { ++ boolean result = super.hurtServer(worldserver, damagesource, f); ++ if (!result) { ++ return result; ++ } + // CraftBukkit end - this.beePollinateGoal.stopPollinating(); - } - -- return super.hurt(damagesource, f); + this.beePollinateGoal.stopPollinating(); +- return super.hurtServer(worldserver, damagesource, f); + return result; // CraftBukkit } } -@@ -992,7 +1008,7 @@ +@@ -1048,7 +1067,7 @@ e() { super(); @@ -81,7 +89,7 @@ this.blacklistedTargets = Lists.newArrayList(); this.setFlags(EnumSet.of(PathfinderGoal.Type.MOVE)); } -@@ -1109,7 +1125,7 @@ +@@ -1162,7 +1181,7 @@ f() { super(); @@ -90,7 +98,7 @@ this.setFlags(EnumSet.of(PathfinderGoal.Type.MOVE)); } -@@ -1209,7 +1225,7 @@ +@@ -1267,7 +1286,7 @@ } } @@ -99,7 +107,7 @@ EntityBee.this.level().levelEvent(2011, blockposition, 15); EntityBee.this.level().setBlockAndUpdate(blockposition, iblockdata1); EntityBee.this.incrementNumCropsGrownSincePollination(); -@@ -1282,7 +1298,7 @@ +@@ -1344,7 +1363,7 @@ @Override protected void alertOther(EntityInsentient entityinsentient, EntityLiving entityliving) { if (entityinsentient instanceof EntityBee && this.mob.hasLineOfSight(entityliving)) { @@ -108,7 +116,7 @@ } } -@@ -1291,7 +1307,7 @@ +@@ -1353,7 +1372,7 @@ private static class c extends PathfinderGoalNearestAttackableTarget { c(EntityBee entitybee) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityCat.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityCat.patch index 334d99b6a8..c8275b2fd3 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityCat.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityCat.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntityCat.java +++ b/net/minecraft/world/entity/animal/EntityCat.java -@@ -181,10 +181,10 @@ +@@ -174,10 +174,10 @@ @Override public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { super.readAdditionalSaveData(nbttagcompound); @@ -12,8 +12,8 @@ + IRegistry iregistry = BuiltInRegistries.CAT_VARIANT; // CraftBukkit - decompile error Objects.requireNonNull(iregistry); - optional.flatMap(iregistry::getHolder).ifPresent(this::setVariant); -@@ -452,7 +452,7 @@ + optional.flatMap(iregistry::get).ifPresent(this::setVariant); +@@ -463,7 +463,7 @@ } private void tryToTame(EntityHuman entityhuman) { @@ -22,7 +22,7 @@ this.tame(entityhuman); this.setOrderedToSit(true); this.level().broadcastEntityEvent(this, (byte) 7); -@@ -470,7 +470,7 @@ +@@ -481,7 +481,7 @@ private static class PathfinderGoalTemptChance extends PathfinderGoalTempt { @Nullable @@ -31,24 +31,24 @@ private final EntityCat cat; public PathfinderGoalTemptChance(EntityCat entitycat, double d0, Predicate predicate, boolean flag) { -@@ -611,7 +611,15 @@ - while (iterator.hasNext()) { - ItemStack itemstack = (ItemStack) iterator.next(); - -- this.cat.level().addFreshEntity(new EntityItem(this.cat.level(), (double) blockposition_mutableblockposition.getX() - (double) MathHelper.sin(this.cat.yBodyRot * 0.017453292F), (double) blockposition_mutableblockposition.getY(), (double) blockposition_mutableblockposition.getZ() + (double) MathHelper.cos(this.cat.yBodyRot * 0.017453292F), itemstack)); +@@ -615,7 +615,15 @@ + this.cat.randomTeleport((double) (blockposition_mutableblockposition.getX() + randomsource.nextInt(11) - 5), (double) (blockposition_mutableblockposition.getY() + randomsource.nextInt(5) - 2), (double) (blockposition_mutableblockposition.getZ() + randomsource.nextInt(11) - 5), false); + blockposition_mutableblockposition.set(this.cat.blockPosition()); + this.cat.dropFromGiftLootTable(getServerLevel((Entity) this.cat), LootTables.CAT_MORNING_GIFT, (worldserver, itemstack) -> { +- worldserver.addFreshEntity(new EntityItem(worldserver, (double) blockposition_mutableblockposition.getX() - (double) MathHelper.sin(this.cat.yBodyRot * 0.017453292F), (double) blockposition_mutableblockposition.getY(), (double) blockposition_mutableblockposition.getZ() + (double) MathHelper.cos(this.cat.yBodyRot * 0.017453292F), itemstack)); + // CraftBukkit start -+ EntityItem entityitem = new EntityItem(this.cat.level(), (double) blockposition_mutableblockposition.getX() - (double) MathHelper.sin(this.cat.yBodyRot * 0.017453292F), (double) blockposition_mutableblockposition.getY(), (double) blockposition_mutableblockposition.getZ() + (double) MathHelper.cos(this.cat.yBodyRot * 0.017453292F), itemstack); ++ EntityItem entityitem = new EntityItem(worldserver, (double) blockposition_mutableblockposition.getX() - (double) MathHelper.sin(this.cat.yBodyRot * 0.017453292F), (double) blockposition_mutableblockposition.getY(), (double) blockposition_mutableblockposition.getZ() + (double) MathHelper.cos(this.cat.yBodyRot * 0.017453292F), itemstack); + org.bukkit.event.entity.EntityDropItemEvent event = new org.bukkit.event.entity.EntityDropItemEvent(this.cat.getBukkitEntity(), (org.bukkit.entity.Item) entityitem.getBukkitEntity()); + entityitem.level().getCraftServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { -+ continue; ++ return; + } -+ this.cat.level().addFreshEntity(entityitem); ++ worldserver.addFreshEntity(entityitem); + // CraftBukkit end - } - + }); } -@@ -643,10 +651,10 @@ + +@@ -646,10 +654,10 @@ private final EntityCat cat; public a(EntityCat entitycat, Class oclass, float f, double d0, double d1) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityChicken.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityChicken.patch index 3319415105..11e71cc922 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityChicken.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityChicken.patch @@ -1,12 +1,15 @@ --- a/net/minecraft/world/entity/animal/EntityChicken.java +++ b/net/minecraft/world/entity/animal/EntityChicken.java -@@ -98,7 +98,9 @@ - this.flap += this.flapping * 2.0F; - if (!this.level().isClientSide && this.isAlive() && !this.isBaby() && !this.isChickenJockey() && --this.eggTime <= 0) { - this.playSound(SoundEffects.CHICKEN_EGG, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F); -+ this.forceDrops = true; // CraftBukkit - this.spawnAtLocation((IMaterial) Items.EGG); -+ this.forceDrops = false; // CraftBukkit - this.gameEvent(GameEvent.ENTITY_PLACE); - this.eggTime = this.random.nextInt(6000) + 6000; - } +@@ -99,10 +99,12 @@ + + if (world instanceof WorldServer worldserver) { + if (this.isAlive() && !this.isBaby() && !this.isChickenJockey() && --this.eggTime <= 0) { ++ this.forceDrops = true; // CraftBukkit + if (this.dropFromGiftLootTable(worldserver, LootTables.CHICKEN_LAY, this::spawnAtLocation)) { + this.playSound(SoundEffects.CHICKEN_EGG, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F); + this.gameEvent(GameEvent.ENTITY_PLACE); + } ++ this.forceDrops = false; // CraftBukkit + + this.eggTime = this.random.nextInt(6000) + 6000; + } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityCow.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityCow.patch index 40f3a47c00..35abe25ccf 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityCow.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityCow.patch @@ -30,4 +30,4 @@ + ItemStack itemstack1 = ItemLiquidUtil.createFilledResult(itemstack, entityhuman, CraftItemStack.asNMSCopy(event.getItemStack())); // CraftBukkit entityhuman.setItemInHand(enumhand, itemstack1); - return EnumInteractionResult.sidedSuccess(this.level().isClientSide); + return EnumInteractionResult.SUCCESS; diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityDolphin.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityDolphin.patch index 932c266ec9..27264decc0 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityDolphin.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityDolphin.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntityDolphin.java +++ b/net/minecraft/world/entity/animal/EntityDolphin.java -@@ -59,8 +59,20 @@ +@@ -62,8 +62,20 @@ import net.minecraft.world.level.pathfinder.PathMode; import net.minecraft.world.phys.Vec3D; @@ -10,7 +10,7 @@ +import org.bukkit.event.entity.EntityRemoveEvent; +// CraftBukkit end + - public class EntityDolphin extends EntityWaterAnimal { + public class EntityDolphin extends AgeableWaterCreature { + // CraftBukkit start - SPIGOT-6907: re-implement LivingEntity#setMaximumAir() + @Override @@ -21,7 +21,7 @@ private static final DataWatcherObject TREASURE_POS = DataWatcher.defineId(EntityDolphin.class, DataWatcherRegistry.BLOCK_POS); private static final DataWatcherObject GOT_FISH = DataWatcher.defineId(EntityDolphin.class, DataWatcherRegistry.BOOLEAN); private static final DataWatcherObject MOISTNESS_LEVEL = DataWatcher.defineId(EntityDolphin.class, DataWatcherRegistry.INT); -@@ -176,7 +188,7 @@ +@@ -200,7 +212,7 @@ @Override public int getMaxAirSupply() { @@ -30,7 +30,7 @@ } @Override -@@ -212,11 +224,17 @@ +@@ -234,11 +246,17 @@ ItemStack itemstack = entityitem.getItem(); if (this.canHoldItem(itemstack)) { @@ -49,7 +49,7 @@ } } -@@ -467,7 +485,7 @@ +@@ -495,7 +513,7 @@ @Override public void start() { @@ -58,7 +58,7 @@ } @Override -@@ -486,7 +504,7 @@ +@@ -514,7 +532,7 @@ } if (this.player.isSwimming() && this.player.level().random.nextInt(6) == 0) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityFox.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityFox.patch index ef52d3da83..2c4b0856d0 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityFox.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityFox.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntityFox.java +++ b/net/minecraft/world/entity/animal/EntityFox.java -@@ -93,6 +93,10 @@ +@@ -91,6 +91,10 @@ import net.minecraft.world.level.pathfinder.PathType; import net.minecraft.world.phys.Vec3D; @@ -11,8 +11,8 @@ public class EntityFox extends EntityAnimal implements VariantHolder { private static final DataWatcherObject DATA_TYPE_ID = DataWatcher.defineId(EntityFox.class, DataWatcherRegistry.INT); -@@ -518,7 +522,8 @@ - protected void pickUpItem(EntityItem entityitem) { +@@ -503,7 +507,8 @@ + protected void pickUpItem(WorldServer worldserver, EntityItem entityitem) { ItemStack itemstack = entityitem.getItem(); - if (this.canHoldItem(itemstack)) { @@ -21,7 +21,7 @@ int i = itemstack.getCount(); if (i > 1) { -@@ -530,7 +535,7 @@ +@@ -515,7 +520,7 @@ this.setItemSlot(EnumItemSlot.MAINHAND, itemstack.split(1)); this.setGuaranteedDrop(EnumItemSlot.MAINHAND); this.take(entityitem, itemstack.getCount()); @@ -30,7 +30,7 @@ this.ticksSinceEaten = 0; } -@@ -868,6 +873,16 @@ +@@ -853,6 +858,16 @@ if (entityplayer1 != null && entityplayer != entityplayer1) { entityfox.addTrustedUUID(entityplayer1.getUUID()); } @@ -47,7 +47,7 @@ if (entityplayer2 != null) { entityplayer2.awardStat(StatisticList.ANIMALS_BRED); -@@ -878,12 +893,14 @@ +@@ -863,12 +878,14 @@ this.partner.setAge(6000); this.animal.resetLove(); this.partner.resetLove(); @@ -56,7 +56,7 @@ - worldserver.addFreshEntityWithPassengers(entityfox); + worldserver.addFreshEntityWithPassengers(entityfox, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING); // CraftBukkit - added SpawnReason this.level.broadcastEntityEvent(this.animal, (byte) 18); - if (this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { + if (worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { - this.level.addFreshEntity(new EntityExperienceOrb(this.level, this.animal.getX(), this.animal.getY(), this.animal.getZ(), this.animal.getRandom().nextInt(7) + 1)); + // CraftBukkit start - use event experience + if (experience > 0) { @@ -66,7 +66,7 @@ } } -@@ -1279,6 +1296,11 @@ +@@ -1264,6 +1281,11 @@ int i = (Integer) iblockdata.getValue(BlockSweetBerryBush.AGE); iblockdata.setValue(BlockSweetBerryBush.AGE, 1); @@ -78,12 +78,12 @@ int j = 1 + EntityFox.this.level().random.nextInt(2) + (i == 3 ? 1 : 0); ItemStack itemstack = EntityFox.this.getItemBySlot(EnumItemSlot.MAINHAND); -@@ -1436,7 +1458,7 @@ - private EntityLiving trustedLastHurt; - private int timestamp; - -- public a(final Class oclass, final boolean flag, final boolean flag1, @Nullable final Predicate predicate) { -+ public a(final Class oclass, final boolean flag, final boolean flag1, @Nullable final Predicate predicate) { // CraftBukkit - decompile error - super(EntityFox.this, oclass, 10, flag, flag1, predicate); +@@ -1494,7 +1516,7 @@ } + public static EntityFox.Type byName(String s) { +- return (EntityFox.Type) EntityFox.Type.CODEC.byName(s, (Enum) EntityFox.Type.RED); ++ return (EntityFox.Type) EntityFox.Type.CODEC.byName(s, EntityFox.Type.RED); // CraftBukkit - decompile error + } + + public static EntityFox.Type byId(int i) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityMushroomCow.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityMushroomCow.patch index 5eb23724f6..25e301c40c 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityMushroomCow.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityMushroomCow.patch @@ -1,66 +1,59 @@ --- a/net/minecraft/world/entity/animal/EntityMushroomCow.java +++ b/net/minecraft/world/entity/animal/EntityMushroomCow.java -@@ -42,6 +42,14 @@ - import net.minecraft.world.level.block.state.IBlockData; +@@ -44,6 +44,13 @@ import net.minecraft.world.level.gameevent.GameEvent; + import net.minecraft.world.level.storage.loot.LootTables; +// CraftBukkit start +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.entity.EntityDropItemEvent; -+import org.bukkit.event.entity.EntityRemoveEvent; +import org.bukkit.event.entity.EntityTransformEvent; +// CraftBukkit end + public class EntityMushroomCow extends EntityCow implements IShearable, VariantHolder { private static final DataWatcherObject DATA_TYPE = DataWatcher.defineId(EntityMushroomCow.class, DataWatcherRegistry.STRING); -@@ -114,6 +122,11 @@ - this.playSound(soundeffect, 1.0F, 1.0F); - return EnumInteractionResult.sidedSuccess(this.level().isClientSide); - } else if (itemstack.is(Items.SHEARS) && this.readyForShearing()) { -+ // CraftBukkit start -+ if (!CraftEventFactory.handlePlayerShearEntityEvent(entityhuman, this, itemstack, enumhand)) { -+ return EnumInteractionResult.PASS; -+ } -+ // CraftBukkit end - this.shear(SoundCategory.PLAYERS); - this.gameEvent(GameEvent.SHEAR, entityhuman); - if (!this.level().isClientSide) { -@@ -157,7 +170,7 @@ +@@ -121,6 +128,11 @@ + if (world instanceof WorldServer) { + WorldServer worldserver = (WorldServer) world; - if (entitycow != null) { - ((WorldServer) this.level()).sendParticles(Particles.EXPLOSION, this.getX(), this.getY(0.5D), this.getZ(), 1, 0.0D, 0.0D, 0.0D, 0.0D); -- this.discard(); -+ // this.discard(); // CraftBukkit - moved down - entitycow.moveTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot()); - entitycow.setHealth(this.getHealth()); - entitycow.yBodyRot = this.yBodyRot; -@@ -171,10 +184,25 @@ - } - - entitycow.setInvulnerable(this.isInvulnerable()); -- this.level().addFreshEntity(entitycow); + // CraftBukkit start -+ if (CraftEventFactory.callEntityTransformEvent(this, entitycow, EntityTransformEvent.TransformReason.SHEARED).isCancelled()) { -+ return; ++ if (!CraftEventFactory.handlePlayerShearEntityEvent(entityhuman, this, itemstack, enumhand)) { ++ return EnumInteractionResult.PASS; + } -+ this.level().addFreshEntity(entitycow, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SHEARED); -+ -+ this.discard(EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - from above and add Bukkit remove cause + // CraftBukkit end - - for (int i = 0; i < 5; ++i) { -- this.level().addFreshEntity(new EntityItem(this.level(), this.getX(), this.getY(1.0D), this.getZ(), new ItemStack(this.getVariant().blockState.getBlock()))); + this.shear(worldserver, SoundCategory.PLAYERS, itemstack); + this.gameEvent(GameEvent.SHEAR, entityhuman); + itemstack.hurtAndBreak(1, entityhuman, getSlotForHand(enumhand)); +@@ -162,11 +174,19 @@ + worldserver.sendParticles(Particles.EXPLOSION, this.getX(), this.getY(0.5D), this.getZ(), 1, 0.0D, 0.0D, 0.0D, 0.0D); + this.dropFromShearingLootTable(worldserver, LootTables.SHEAR_MOOSHROOM, itemstack, (worldserver1, itemstack1) -> { + for (int i = 0; i < itemstack1.getCount(); ++i) { +- worldserver1.addFreshEntity(new EntityItem(this.level(), this.getX(), this.getY(1.0D), this.getZ(), itemstack1.copyWithCount(1))); + // CraftBukkit start -+ EntityItem entityitem = new EntityItem(this.level(), this.getX(), this.getY(1.0D), this.getZ(), new ItemStack(this.getVariant().blockState.getBlock())); ++ EntityItem entityitem = new EntityItem(this.level(), this.getX(), this.getY(1.0D), this.getZ(), itemstack1.copyWithCount(1)); + EntityDropItemEvent event = new EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) entityitem.getBukkitEntity()); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) { + continue; + } -+ this.level().addFreshEntity(entityitem); ++ worldserver1.addFreshEntity(entityitem); + // CraftBukkit end } - } + + }); +- }); ++ }, EntityTransformEvent.TransformReason.SHEARED, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SHEARED); // CraftBukkit + } + + @Override +@@ -262,7 +282,7 @@ } + + static EntityMushroomCow.Type byName(String s) { +- return (EntityMushroomCow.Type) EntityMushroomCow.Type.CODEC.byName(s, (Enum) EntityMushroomCow.Type.RED); ++ return (EntityMushroomCow.Type) EntityMushroomCow.Type.CODEC.byName(s, EntityMushroomCow.Type.RED); // CraftBukkit - decompile error + } + } + } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityOcelot.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityOcelot.patch index adaf9451c4..9c76590e33 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityOcelot.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityOcelot.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntityOcelot.java +++ b/net/minecraft/world/entity/animal/EntityOcelot.java -@@ -168,7 +168,7 @@ +@@ -167,7 +167,7 @@ if ((this.temptGoal == null || this.temptGoal.isRunning()) && !this.isTrusting() && this.isFood(itemstack) && entityhuman.distanceToSqr((Entity) this) < 9.0D) { this.usePlayerItem(entityhuman, enumhand, itemstack); if (!this.level().isClientSide) { @@ -9,7 +9,7 @@ this.setTrusting(true); this.spawnTrustingParticles(true); this.level().broadcastEntityEvent(this, (byte) 41); -@@ -299,10 +299,10 @@ +@@ -298,10 +298,10 @@ private final EntityOcelot ocelot; public a(EntityOcelot entityocelot, Class oclass, float f, double d0, double d1) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityPanda.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityPanda.patch index fc566a8393..6dbcfc20f9 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityPanda.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityPanda.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/entity/animal/EntityPanda.java +++ b/net/minecraft/world/entity/animal/EntityPanda.java -@@ -73,6 +73,12 @@ - import net.minecraft.world.level.storage.loot.parameters.LootContextParameters; +@@ -69,6 +69,12 @@ + import net.minecraft.world.level.storage.loot.LootTables; import net.minecraft.world.phys.Vec3D; +// CraftBukkit start; @@ -13,12 +13,12 @@ public class EntityPanda extends EntityAnimal { private static final DataWatcherObject UNHAPPY_COUNTER = DataWatcher.defineId(EntityPanda.class, DataWatcherRegistry.INT); -@@ -558,14 +564,14 @@ +@@ -541,14 +547,14 @@ @Override - protected void pickUpItem(EntityItem entityitem) { -- if (this.getItemBySlot(EnumItemSlot.MAINHAND).isEmpty() && EntityPanda.PANDA_ITEMS.test(entityitem)) { -+ if (!CraftEventFactory.callEntityPickupItemEvent(this, entityitem, 0, !(this.getItemBySlot(EnumItemSlot.MAINHAND).isEmpty() && EntityPanda.PANDA_ITEMS.test(entityitem))).isCancelled()) { // CraftBukkit + protected void pickUpItem(WorldServer worldserver, EntityItem entityitem) { +- if (this.getItemBySlot(EnumItemSlot.MAINHAND).isEmpty() && canPickUpAndEat(entityitem)) { ++ if (!CraftEventFactory.callEntityPickupItemEvent(this, entityitem, 0, !(this.getItemBySlot(EnumItemSlot.MAINHAND).isEmpty() && canPickUpAndEat(entityitem))).isCancelled()) { // CraftBukkit this.onItemPickup(entityitem); ItemStack itemstack = entityitem.getItem(); @@ -30,7 +30,16 @@ } } -@@ -889,10 +895,10 @@ +@@ -772,7 +778,7 @@ + } + + public static EntityPanda.Gene byName(String s) { +- return (EntityPanda.Gene) EntityPanda.Gene.CODEC.byName(s, (Enum) EntityPanda.Gene.NORMAL); ++ return (EntityPanda.Gene) EntityPanda.Gene.CODEC.byName(s, EntityPanda.Gene.NORMAL); // CraftBukkit - decompile error + } + + public static EntityPanda.Gene getRandom(RandomSource randomsource) { +@@ -876,10 +882,10 @@ private final EntityPanda panda; public c(EntityPanda entitypanda, Class oclass, float f, double d0, double d1) { @@ -44,7 +53,7 @@ this.panda = entitypanda; } -@@ -1131,7 +1137,7 @@ +@@ -1116,7 +1122,7 @@ @Override protected void alertOther(EntityInsentient entityinsentient, EntityLiving entityliving) { if (entityinsentient instanceof EntityPanda && entityinsentient.isAggressive()) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityParrot.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityParrot.patch index 6087b83e9c..5cdb3fbcc4 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityParrot.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityParrot.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntityParrot.java +++ b/net/minecraft/world/entity/animal/EntityParrot.java -@@ -248,7 +248,7 @@ +@@ -250,7 +250,7 @@ } if (!this.level().isClientSide) { @@ -9,16 +9,16 @@ this.tame(entityhuman); this.level().broadcastEntityEvent(this, (byte) 7); } else { -@@ -269,7 +269,7 @@ +@@ -271,7 +271,7 @@ } } else { - itemstack.consume(1, entityhuman); + this.usePlayerItem(entityhuman, enumhand, itemstack); - this.addEffect(new MobEffect(MobEffects.POISON, 900)); + this.addEffect(new MobEffect(MobEffects.POISON, 900), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.FOOD); // CraftBukkit if (entityhuman.isCreative() || !this.isInvulnerable()) { this.hurt(this.damageSources().playerAttack(entityhuman), Float.MAX_VALUE); } -@@ -363,7 +363,7 @@ +@@ -365,7 +365,7 @@ @Override public boolean isPushable() { @@ -27,19 +27,18 @@ } @Override -@@ -378,11 +378,14 @@ - if (this.isInvulnerableTo(damagesource)) { +@@ -380,8 +380,14 @@ + if (this.isInvulnerableTo(worldserver, damagesource)) { return false; } else { -- if (!this.level().isClientSide) { + // CraftBukkit start -+ boolean result = super.hurt(damagesource, f); -+ if (!this.level().isClientSide && result) { -+ // CraftBukkit end - this.setOrderedToSit(false); - } - -- return super.hurt(damagesource, f); ++ boolean result = super.hurtServer(worldserver, damagesource, f); ++ if (!result) { ++ return result; ++ } ++ // CraftBukkit end + this.setOrderedToSit(false); +- return super.hurtServer(worldserver, damagesource, f); + return result; // CraftBukkit } } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityPig.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityPig.patch index aefc4f57f8..0f44b395a0 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityPig.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityPig.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntityPig.java +++ b/net/minecraft/world/entity/animal/EntityPig.java -@@ -49,6 +49,11 @@ +@@ -50,6 +50,11 @@ import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; @@ -12,20 +12,19 @@ public class EntityPig extends EntityAnimal implements ISteerable, ISaddleable { private static final DataWatcherObject DATA_SADDLE_ID = DataWatcher.defineId(EntityPig.class, DataWatcherRegistry.BOOLEAN); -@@ -253,8 +258,14 @@ +@@ -247,7 +252,14 @@ } - entitypigzombie.setPersistenceRequired(); -- worldserver.addFreshEntity(entitypigzombie); -- this.discard(); -+ // CraftBukkit start -+ if (CraftEventFactory.callPigZapEvent(this, entitylightning, entitypigzombie).isCancelled()) { -+ return; -+ } -+ // CraftBukkit - added a reason for spawning this creature -+ worldserver.addFreshEntity(entitypigzombie, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING); -+ // CraftBukkit end -+ this.discard(EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - add Bukkit remove cause - } else { + entitypigzombie1.setPersistenceRequired(); +- }); ++ // CraftBukkit start ++ }, null, null); ++ if (CraftEventFactory.callPigZapEvent(this, entitylightning, entitypigzombie).isCancelled()) { ++ return; ++ } ++ worldserver.addFreshEntity(entitypigzombie, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING); ++ this.discard(EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - add Bukkit remove cause ++ // CraftBukkit end + + if (entitypigzombie == null) { super.thunderHit(worldserver, entitylightning); - } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityPufferFish.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityPufferFish.patch index e896b2ba79..10104083f5 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityPufferFish.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityPufferFish.patch @@ -1,20 +1,20 @@ --- a/net/minecraft/world/entity/animal/EntityPufferFish.java +++ b/net/minecraft/world/entity/animal/EntityPufferFish.java -@@ -150,7 +150,7 @@ +@@ -155,7 +155,7 @@ int i = this.getPuffState(); - if (entityinsentient.hurt(this.damageSources().mobAttack(this), (float) (1 + i))) { + if (entityinsentient.hurtServer(worldserver, this.damageSources().mobAttack(this), (float) (1 + i))) { - entityinsentient.addEffect(new MobEffect(MobEffects.POISON, 60 * i, 0), this); + entityinsentient.addEffect(new MobEffect(MobEffects.POISON, 60 * i, 0), this, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.ATTACK); // CraftBukkit this.playSound(SoundEffects.PUFFER_FISH_STING, 1.0F, 1.0F); } -@@ -165,7 +165,7 @@ - ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.PUFFER_FISH_STING, 0.0F)); - } +@@ -171,7 +171,7 @@ + entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.PUFFER_FISH_STING, 0.0F)); + } -- entityhuman.addEffect(new MobEffect(MobEffects.POISON, 60 * i, 0), this); -+ entityhuman.addEffect(new MobEffect(MobEffects.POISON, 60 * i, 0), this, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.ATTACK); // CraftBukkit +- entityhuman.addEffect(new MobEffect(MobEffects.POISON, 60 * i, 0), this); ++ entityhuman.addEffect(new MobEffect(MobEffects.POISON, 60 * i, 0), this, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.ATTACK); // CraftBukkit + } } - } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityRabbit.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityRabbit.patch index 242b724f75..60b150a8bf 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityRabbit.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityRabbit.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntityRabbit.java +++ b/net/minecraft/world/entity/animal/EntityRabbit.java -@@ -67,6 +67,10 @@ +@@ -66,6 +66,10 @@ import net.minecraft.world.level.pathfinder.PathEntity; import net.minecraft.world.phys.Vec3D; @@ -11,7 +11,7 @@ public class EntityRabbit extends EntityAnimal implements VariantHolder { public static final double STROLL_SPEED_MOD = 0.6D; -@@ -91,7 +95,6 @@ +@@ -90,7 +94,6 @@ super(entitytypes, world); this.jumpControl = new EntityRabbit.ControllerJumpRabbit(this); this.moveControl = new EntityRabbit.ControllerMoveRabbit(this); @@ -19,7 +19,7 @@ } @Override -@@ -578,9 +581,19 @@ +@@ -577,9 +580,19 @@ int i = (Integer) iblockdata.getValue(BlockCarrots.AGE); if (i == 0) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntitySheep.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntitySheep.patch index 8bc4c6cefe..b5351cb7d4 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntitySheep.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntitySheep.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/entity/animal/EntitySheep.java +++ b/net/minecraft/world/entity/animal/EntitySheep.java -@@ -63,6 +63,12 @@ - import net.minecraft.world.level.storage.loot.LootTable; +@@ -57,6 +57,12 @@ + import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.level.storage.loot.LootTables; +// CraftBukkit start @@ -13,29 +13,29 @@ public class EntitySheep extends EntityAnimal implements IShearable { private static final int EAT_ANIMATION_TICKS = 40; -@@ -250,6 +256,11 @@ +@@ -167,6 +173,11 @@ + WorldServer worldserver = (WorldServer) world; - if (itemstack.is(Items.SHEARS)) { - if (!this.level().isClientSide && this.readyForShearing()) { -+ // CraftBukkit start -+ if (!CraftEventFactory.handlePlayerShearEntityEvent(entityhuman, this, itemstack, enumhand)) { -+ return EnumInteractionResult.PASS; -+ } -+ // CraftBukkit end - this.shear(SoundCategory.PLAYERS); - this.gameEvent(GameEvent.SHEAR, entityhuman); - itemstack.hurtAndBreak(1, entityhuman, getSlotForHand(enumhand)); -@@ -269,7 +280,9 @@ - int i = 1 + this.random.nextInt(3); + if (this.readyForShearing()) { ++ // CraftBukkit start ++ if (!CraftEventFactory.handlePlayerShearEntityEvent(entityhuman, this, itemstack, enumhand)) { ++ return EnumInteractionResult.PASS; ++ } ++ // CraftBukkit end + this.shear(worldserver, SoundCategory.PLAYERS, itemstack); + this.gameEvent(GameEvent.SHEAR, entityhuman); + itemstack.hurtAndBreak(1, entityhuman, getSlotForHand(enumhand)); +@@ -185,7 +196,9 @@ + worldserver.playSound((EntityHuman) null, (Entity) this, SoundEffects.SHEEP_SHEAR, soundcategory, 1.0F, 1.0F); + this.dropFromShearingLootTable(worldserver, LootTables.SHEAR_SHEEP, itemstack, (worldserver1, itemstack1) -> { + for (int i = 0; i < itemstack1.getCount(); ++i) { ++ this.forceDrops = true; // CraftBukkit + EntityItem entityitem = this.spawnAtLocation(worldserver1, itemstack1.copyWithCount(1), 1.0F); ++ this.forceDrops = false; // CraftBukkit - for (int j = 0; j < i; ++j) { -+ this.forceDrops = true; // CraftBukkit - EntityItem entityitem = this.spawnAtLocation((IMaterial) EntitySheep.ITEM_BY_DYE.get(this.getColor()), 1); -+ this.forceDrops = false; // CraftBukkit - - if (entityitem != null) { - entityitem.setDeltaMovement(entityitem.getDeltaMovement().add((double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F), (double) (this.random.nextFloat() * 0.05F), (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F))); -@@ -362,6 +375,12 @@ + if (entityitem != null) { + entityitem.setDeltaMovement(entityitem.getDeltaMovement().add((double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F), (double) (this.random.nextFloat() * 0.05F), (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F))); +@@ -280,6 +293,12 @@ @Override public void ate() { @@ -48,12 +48,12 @@ super.ate(); this.setSheared(false); if (this.isBaby()) { -@@ -381,7 +400,7 @@ - EnumColor enumcolor = ((EntitySheep) entityanimal).getColor(); - EnumColor enumcolor1 = ((EntitySheep) entityanimal1).getColor(); +@@ -299,7 +318,7 @@ + EnumColor enumcolor = entitysheep.getColor(); + EnumColor enumcolor1 = entitysheep1.getColor(); CraftingInput craftinginput = makeCraftInput(enumcolor, enumcolor1); -- Optional optional = this.level().getRecipeManager().getRecipeFor(Recipes.CRAFTING, craftinginput, this.level()).map((recipeholder) -> { -+ Optional optional = this.level().getRecipeManager().getRecipeFor(Recipes.CRAFTING, craftinginput, this.level()).map((recipeholder) -> { // CraftBukkit - decompile error - return ((RecipeCrafting) recipeholder.value()).assemble(craftinginput, this.level().registryAccess()); +- Optional optional = worldserver.recipeAccess().getRecipeFor(Recipes.CRAFTING, craftinginput, worldserver).map((recipeholder) -> { ++ Optional optional = worldserver.recipeAccess().getRecipeFor(Recipes.CRAFTING, craftinginput, worldserver).map((recipeholder) -> { // CraftBukkit - decompile error + return ((RecipeCrafting) recipeholder.value()).assemble(craftinginput, worldserver.registryAccess()); }).map(ItemStack::getItem); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntitySnowman.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntitySnowman.patch index 2c4f535b80..f662758d50 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntitySnowman.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntitySnowman.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/entity/animal/EntitySnowman.java +++ b/net/minecraft/world/entity/animal/EntitySnowman.java -@@ -40,6 +40,10 @@ - import net.minecraft.world.level.gameevent.GameEvent; +@@ -43,6 +43,10 @@ + import net.minecraft.world.level.storage.loot.LootTables; import net.minecraft.world.phys.Vec3D; +// CraftBukkit start @@ -11,16 +11,16 @@ public class EntitySnowman extends EntityGolem implements IShearable, IRangedEntity { private static final DataWatcherObject DATA_PUMPKIN_ID = DataWatcher.defineId(EntitySnowman.class, DataWatcherRegistry.BYTE); -@@ -95,7 +99,7 @@ - super.aiStep(); - if (!this.level().isClientSide) { +@@ -100,7 +104,7 @@ + + if (world instanceof WorldServer worldserver) { if (this.level().getBiome(this.blockPosition()).is(BiomeTags.SNOW_GOLEM_MELTS)) { -- this.hurt(this.damageSources().onFire(), 1.0F); -+ this.hurt(this.damageSources().melting(), 1.0F); // CraftBukkit - DamageSources.ON_FIRE -> CraftEventFactory.MELTING +- this.hurtServer(worldserver, this.damageSources().onFire(), 1.0F); ++ this.hurtServer(worldserver, this.damageSources().melting(), 1.0F); // CraftBukkit - DamageSources.ON_FIRE -> CraftEventFactory.MELTING } - if (!this.level().getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { -@@ -111,7 +115,11 @@ + if (!worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { +@@ -116,7 +120,11 @@ BlockPosition blockposition = new BlockPosition(j, k, l); if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) { @@ -33,25 +33,25 @@ this.level().gameEvent((Holder) GameEvent.BLOCK_PLACE, blockposition, GameEvent.a.of(this, iblockdata)); } } -@@ -138,6 +146,11 @@ - ItemStack itemstack = entityhuman.getItemInHand(enumhand); +@@ -153,6 +161,11 @@ + if (world instanceof WorldServer) { + WorldServer worldserver = (WorldServer) world; - if (itemstack.is(Items.SHEARS) && this.readyForShearing()) { -+ // CraftBukkit start -+ if (!CraftEventFactory.handlePlayerShearEntityEvent(entityhuman, this, itemstack, enumhand)) { -+ return EnumInteractionResult.PASS; -+ } -+ // CraftBukkit end - this.shear(SoundCategory.PLAYERS); - this.gameEvent(GameEvent.SHEAR, entityhuman); - if (!this.level().isClientSide) { -@@ -155,7 +168,9 @@ - this.level().playSound((EntityHuman) null, (Entity) this, SoundEffects.SNOW_GOLEM_SHEAR, soundcategory, 1.0F, 1.0F); - if (!this.level().isClientSide()) { - this.setPumpkin(false); ++ // CraftBukkit start ++ if (!CraftEventFactory.handlePlayerShearEntityEvent(entityhuman, this, itemstack, enumhand)) { ++ return EnumInteractionResult.PASS; ++ } ++ // CraftBukkit end + this.shear(worldserver, SoundCategory.PLAYERS, itemstack); + this.gameEvent(GameEvent.SHEAR, entityhuman); + itemstack.hurtAndBreak(1, entityhuman, getSlotForHand(enumhand)); +@@ -169,7 +182,9 @@ + worldserver.playSound((EntityHuman) null, (Entity) this, SoundEffects.SNOW_GOLEM_SHEAR, soundcategory, 1.0F, 1.0F); + this.setPumpkin(false); + this.dropFromShearingLootTable(worldserver, LootTables.SHEAR_SNOW_GOLEM, itemstack, (worldserver1, itemstack1) -> { + this.forceDrops = true; // CraftBukkit - this.spawnAtLocation(new ItemStack(Items.CARVED_PUMPKIN), this.getEyeHeight()); + this.spawnAtLocation(worldserver1, itemstack1, this.getEyeHeight()); + this.forceDrops = false; // CraftBukkit - } - + }); } + diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityTurtle.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityTurtle.patch index 379fe48abf..5484958bca 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityTurtle.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityTurtle.patch @@ -1,25 +1,25 @@ --- a/net/minecraft/world/entity/animal/EntityTurtle.java +++ b/net/minecraft/world/entity/animal/EntityTurtle.java -@@ -305,7 +305,9 @@ - protected void ageBoundaryReached() { - super.ageBoundaryReached(); - if (!this.isBaby() && this.level().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { -+ this.forceDrops = true; // CraftBukkit - this.spawnAtLocation(Items.TURTLE_SCUTE, 1); -+ this.forceDrops = false; // CraftBukkit - } +@@ -310,7 +310,9 @@ + WorldServer worldserver = (WorldServer) world; - } -@@ -332,7 +334,7 @@ + if (worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { ++ this.forceDrops = true; // CraftBukkit + this.spawnAtLocation(worldserver, Items.TURTLE_SCUTE, 1); ++ this.forceDrops = false; // CraftBukkit + } + } + } +@@ -339,7 +341,7 @@ @Override public void thunderHit(WorldServer worldserver, EntityLightning entitylightning) { -- this.hurt(this.damageSources().lightningBolt(), Float.MAX_VALUE); -+ this.hurt(this.damageSources().lightningBolt().customEntityDamager(entitylightning), Float.MAX_VALUE); // CraftBukkit +- this.hurtServer(worldserver, this.damageSources().lightningBolt(), Float.MAX_VALUE); ++ this.hurtServer(worldserver, this.damageSources().lightningBolt().customEntityDamager(entitylightning), Float.MAX_VALUE); // CraftBukkit } @Override -@@ -489,12 +491,14 @@ +@@ -496,12 +498,14 @@ } else if (this.turtle.layEggCounter > this.adjustedTickDelay(200)) { World world = this.turtle.level(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityWolf.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityWolf.patch index 62bec7891e..e29a99b4b8 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityWolf.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityWolf.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntityWolf.java +++ b/net/minecraft/world/entity/animal/EntityWolf.java -@@ -90,6 +90,13 @@ +@@ -86,6 +86,13 @@ import net.minecraft.world.level.pathfinder.PathType; import net.minecraft.world.phys.Vec3D; @@ -14,32 +14,31 @@ public class EntityWolf extends EntityTameableAnimal implements IEntityAngerable, VariantHolder> { private static final DataWatcherObject DATA_INTERESTED_ID = DataWatcher.defineId(EntityWolf.class, DataWatcherRegistry.BOOLEAN); -@@ -360,11 +367,14 @@ - if (this.isInvulnerableTo(damagesource)) { +@@ -345,8 +352,14 @@ + if (this.isInvulnerableTo(worldserver, damagesource)) { return false; } else { -- if (!this.level().isClientSide) { + // CraftBukkit start -+ boolean result = super.hurt(damagesource, f); -+ if (!this.level().isClientSide && result) { -+ // CraftBukkit end - this.setOrderedToSit(false); - } - -- return super.hurt(damagesource, f); ++ boolean result = super.hurtServer(worldserver, damagesource, f); ++ if (!result) { ++ return result; ++ } ++ // CraftBukkit end + this.setOrderedToSit(false); +- return super.hurtServer(worldserver, damagesource, f); + return result; // CraftBukkit } } -@@ -374,10 +384,15 @@ +@@ -356,10 +369,15 @@ } @Override -- protected void actuallyHurt(DamageSource damagesource, float f) { -+ public boolean actuallyHurt(DamageSource damagesource, float f, EntityDamageEvent event) { // CraftBukkit - void -> boolean +- protected void actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f) { ++ public boolean actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f, EntityDamageEvent event) { // CraftBukkit - void -> boolean if (!this.canArmorAbsorb(damagesource)) { -- super.actuallyHurt(damagesource, f); -+ return super.actuallyHurt(damagesource, f, event); // CraftBukkit +- super.actuallyHurt(worldserver, damagesource, f); ++ return super.actuallyHurt(worldserver, damagesource, f, event); // CraftBukkit } else { + // CraftBukkit start - SPIGOT-7815: if the damage was cancelled, no need to run the wolf armor behaviour + if (event.isCancelled()) { @@ -49,7 +48,7 @@ ItemStack itemstack = this.getBodyArmorItem(); int i = itemstack.getDamageValue(); int j = itemstack.getMaxDamage(); -@@ -395,6 +410,7 @@ +@@ -371,6 +389,7 @@ } } @@ -57,7 +56,7 @@ } private boolean canArmorAbsorb(DamageSource damagesource) { -@@ -405,7 +421,7 @@ +@@ -381,7 +400,7 @@ protected void applyTamingSideEffects() { if (this.isTame()) { this.getAttribute(GenericAttributes.MAX_HEALTH).setBaseValue(40.0D); @@ -66,35 +65,35 @@ } else { this.getAttribute(GenericAttributes.MAX_HEALTH).setBaseValue(8.0D); } -@@ -432,7 +448,7 @@ +@@ -404,7 +423,7 @@ FoodInfo foodinfo = (FoodInfo) itemstack.get(DataComponents.FOOD); float f = foodinfo != null ? (float) foodinfo.nutrition() : 1.0F; - this.heal(2.0F * f); + this.heal(2.0F * f, EntityRegainHealthEvent.RegainReason.EATING); // CraftBukkit - return EnumInteractionResult.sidedSuccess(this.level().isClientSide()); + return EnumInteractionResult.SUCCESS; } else { if (item instanceof ItemDye) { -@@ -463,7 +479,9 @@ - this.playSound(SoundEffects.ARMOR_UNEQUIP_WOLF); - itemstack1 = this.getBodyArmorItem(); - this.setBodyArmorItem(ItemStack.EMPTY); -+ this.forceDrops = true; // CraftBukkit - this.spawnAtLocation(itemstack1); -+ this.forceDrops = false; // CraftBukkit +@@ -440,7 +459,9 @@ + if (world instanceof WorldServer) { + WorldServer worldserver = (WorldServer) world; + ++ this.forceDrops = true; // CraftBukkit + this.spawnAtLocation(worldserver, itemstack1); ++ this.forceDrops = false; // CraftBukkit + } + return EnumInteractionResult.SUCCESS; - } else if (((RecipeItemStack) ((ArmorMaterial) EnumArmorMaterial.ARMADILLO.value()).repairIngredient().get()).test(itemstack) && this.isInSittingPose() && this.hasArmor() && this.isOwnedBy(entityhuman) && this.getBodyArmorItem().isDamaged()) { - itemstack.shrink(1); -@@ -480,7 +498,7 @@ +@@ -459,7 +480,7 @@ this.setOrderedToSit(!this.isOrderedToSit()); this.jumping = false; this.navigation.stop(); - this.setTarget((EntityLiving) null); + this.setTarget((EntityLiving) null, EntityTargetEvent.TargetReason.FORGOT_TARGET, true); // CraftBukkit - reason - return EnumInteractionResult.SUCCESS_NO_ITEM_USED; + return EnumInteractionResult.SUCCESS.withoutItem(); } else { return enuminteractionresult; -@@ -498,7 +516,8 @@ +@@ -477,7 +498,8 @@ } private void tryToTame(EntityHuman entityhuman) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/allay/Allay.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/allay/Allay.patch index 5ffafed7f8..bb113dd9a6 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/allay/Allay.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/allay/Allay.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/allay/Allay.java +++ b/net/minecraft/world/entity/animal/allay/Allay.java -@@ -101,6 +101,7 @@ +@@ -103,6 +103,7 @@ private float dancingAnimationTicks; private float spinningAnimationTicks; private float spinningAnimationTicks0; @@ -8,7 +8,7 @@ public Allay(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -112,6 +113,12 @@ +@@ -114,6 +115,12 @@ this.dynamicJukeboxListener = new DynamicGameEventListener<>(new Allay.a(this.vibrationUser.getPositionSource(), ((GameEvent) GameEvent.JUKEBOX_PLAY.value()).notificationRadius())); } @@ -21,7 +21,7 @@ @Override protected BehaviorController.b brainProvider() { return BehaviorController.provider(Allay.MEMORY_TYPES, Allay.SENSOR_TYPES); -@@ -124,7 +131,7 @@ +@@ -126,7 +133,7 @@ @Override public BehaviorController getBrain() { @@ -30,7 +30,7 @@ } public static AttributeProvider.Builder createAttributes() { -@@ -225,7 +232,7 @@ +@@ -229,7 +236,7 @@ public void aiStep() { super.aiStep(); if (!this.level().isClientSide && this.isAlive() && this.tickCount % 10 == 0) { @@ -39,10 +39,10 @@ } if (this.isDancing() && this.shouldStopDancing() && this.tickCount % 20 == 0) { -@@ -295,7 +302,12 @@ +@@ -299,7 +306,12 @@ ItemStack itemstack1 = this.getItemInHand(EnumHand.MAIN_HAND); - if (this.isDancing() && this.isDuplicationItem(itemstack) && this.canDuplicate()) { + if (this.isDancing() && itemstack.is(TagsItem.DUPLICATES_ALLAYS) && this.canDuplicate()) { - this.duplicateAllay(); + // CraftBukkit start - handle cancel duplication + Allay allay = this.duplicateAllay(); @@ -53,7 +53,7 @@ this.level().broadcastEntityEvent(this, (byte) 18); this.level().playSound(entityhuman, (Entity) this, SoundEffects.AMETHYST_BLOCK_CHIME, SoundCategory.NEUTRAL, 2.0F, 1.0F); this.removeInteractionItem(entityhuman, itemstack); -@@ -306,7 +318,7 @@ +@@ -310,7 +322,7 @@ this.setItemInHand(EnumHand.MAIN_HAND, itemstack2); this.removeInteractionItem(entityhuman, itemstack); this.level().playSound(entityhuman, (Entity) this, SoundEffects.ALLAY_ITEM_GIVEN, SoundCategory.NEUTRAL, 2.0F, 1.0F); @@ -62,7 +62,7 @@ return EnumInteractionResult.SUCCESS; } else if (!itemstack1.isEmpty() && enumhand == EnumHand.MAIN_HAND && itemstack.isEmpty()) { this.setItemSlot(EnumItemSlot.MAINHAND, ItemStack.EMPTY); -@@ -407,6 +419,7 @@ +@@ -411,6 +423,7 @@ } private boolean shouldStopDancing() { @@ -70,16 +70,16 @@ return this.jukeboxPos == null || !this.jukeboxPos.closerToCenterThan(this.position(), (double) ((GameEvent) GameEvent.JUKEBOX_PLAY.value()).notificationRadius()) || !this.level().getBlockState(this.jukeboxPos).is(Blocks.JUKEBOX); } -@@ -500,7 +513,7 @@ - return Allay.DUPLICATION_ITEM.test(itemstack); +@@ -502,7 +515,7 @@ + } - public void duplicateAllay() { + public Allay duplicateAllay() { // CraftBukkit - return allay - Allay allay = (Allay) EntityTypes.ALLAY.create(this.level()); + Allay allay = (Allay) EntityTypes.ALLAY.create(this.level(), EntitySpawnReason.BREEDING); if (allay != null) { -@@ -508,9 +521,9 @@ +@@ -510,9 +523,9 @@ allay.setPersistenceRequired(); allay.resetDuplicationCooldown(); this.resetDuplicationCooldown(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/armadillo/Armadillo.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/armadillo/Armadillo.patch index 905cd0dc2a..8187e9f14e 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/armadillo/Armadillo.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/armadillo/Armadillo.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/entity/animal/armadillo/Armadillo.java +++ b/net/minecraft/world/entity/animal/armadillo/Armadillo.java -@@ -47,6 +47,10 @@ - import net.minecraft.world.level.block.state.IBlockData; +@@ -48,6 +48,10 @@ import net.minecraft.world.level.gameevent.GameEvent; + import net.minecraft.world.level.storage.loot.LootTables; +// CraftBukkit start +import org.bukkit.event.entity.EntityDamageEvent; @@ -11,33 +11,35 @@ public class Armadillo extends EntityAnimal { public static final float BABY_SCALE = 0.6F; -@@ -132,14 +136,16 @@ - @Override - protected void customServerAiStep() { - this.level().getProfiler().push("armadilloBrain"); -- this.brain.tick((WorldServer) this.level(), this); -+ ((BehaviorController) this.brain).tick((WorldServer) this.level(), this); // CraftBukkit - decompile error - this.level().getProfiler().pop(); - this.level().getProfiler().push("armadilloActivityUpdate"); +@@ -135,16 +139,18 @@ + GameProfilerFiller gameprofilerfiller = Profiler.get(); + + gameprofilerfiller.push("armadilloBrain"); +- this.brain.tick(worldserver, this); ++ ((BehaviorController) this.brain).tick(worldserver, this); // CraftBukkit - decompile error + gameprofilerfiller.pop(); + gameprofilerfiller.push("armadilloActivityUpdate"); ArmadilloAi.updateActivity(this); - this.level().getProfiler().pop(); + gameprofilerfiller.pop(); if (this.isAlive() && !this.isBaby() && --this.scuteTime <= 0) { - this.playSound(SoundEffects.ARMADILLO_SCUTE_DROP, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F); + this.forceDrops = true; // CraftBukkit - this.spawnAtLocation((IMaterial) Items.ARMADILLO_SCUTE); + if (this.dropFromGiftLootTable(worldserver, LootTables.ARMADILLO_SHED, this::spawnAtLocation)) { + this.playSound(SoundEffects.ARMADILLO_SCUTE_DROP, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F); + this.gameEvent(GameEvent.ENTITY_PLACE); + } + this.forceDrops = false; // CraftBukkit - this.gameEvent(GameEvent.ENTITY_PLACE); + this.scuteTime = this.pickNextScuteDropTime(); } -@@ -286,8 +292,13 @@ +@@ -291,8 +297,13 @@ } @Override -- protected void actuallyHurt(DamageSource damagesource, float f) { -- super.actuallyHurt(damagesource, f); +- protected void actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f) { +- super.actuallyHurt(worldserver, damagesource, f); + // CraftBukkit start - void -> boolean -+ public boolean actuallyHurt(DamageSource damagesource, float f, EntityDamageEvent event) { -+ boolean damageResult = super.actuallyHurt(damagesource, f, event); ++ public boolean actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f, EntityDamageEvent event) { ++ boolean damageResult = super.actuallyHurt(worldserver, damagesource, f, event); + if (!damageResult) { + return false; + } @@ -45,7 +47,7 @@ if (!this.isNoAi() && !this.isDeadOrDying()) { if (damagesource.getEntity() instanceof EntityLiving) { this.getBrain().setMemoryWithExpiry(MemoryModuleType.DANGER_DETECTED_RECENTLY, true, 80L); -@@ -299,6 +310,7 @@ +@@ -304,6 +315,7 @@ } } @@ -53,13 +55,22 @@ } @Override -@@ -326,7 +338,9 @@ - if (this.isBaby()) { - return false; - } else { -+ this.forceDrops = true; // CraftBukkit - this.spawnAtLocation(new ItemStack(Items.ARMADILLO_SCUTE)); -+ this.forceDrops = false; // CraftBukkit - this.gameEvent(GameEvent.ENTITY_INTERACT); - this.playSound(SoundEffects.ARMADILLO_BRUSH); - return true; +@@ -327,7 +339,9 @@ + if (world instanceof WorldServer) { + WorldServer worldserver = (WorldServer) world; + ++ this.forceDrops = true; // CraftBukkit + this.spawnAtLocation(worldserver, new ItemStack(Items.ARMADILLO_SCUTE)); ++ this.forceDrops = false; // CraftBukkit + this.gameEvent(GameEvent.ENTITY_INTERACT); + this.playSound(SoundEffects.ARMADILLO_BRUSH); + } +@@ -431,7 +445,7 @@ + } + + public static Armadillo.a fromName(String s) { +- return (Armadillo.a) Armadillo.a.CODEC.byName(s, (Enum) Armadillo.a.IDLE); ++ return (Armadillo.a) Armadillo.a.CODEC.byName(s, Armadillo.a.IDLE); // CraftBukkit - decompile error + } + + @Override diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/axolotl/Axolotl.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/axolotl/Axolotl.patch index f8aec072ea..b975228524 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/axolotl/Axolotl.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/axolotl/Axolotl.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/entity/animal/axolotl/Axolotl.java +++ b/net/minecraft/world/entity/animal/axolotl/Axolotl.java -@@ -68,9 +68,16 @@ +@@ -67,10 +67,17 @@ - public class Axolotl extends EntityAnimal implements LerpingModel, VariantHolder, Bucketable { + public class Axolotl extends EntityAnimal implements VariantHolder, Bucketable { + // CraftBukkit start - SPIGOT-6907: re-implement LivingEntity#setMaximumAir() + @Override @@ -11,6 +11,7 @@ + } + // CraftBukkit end public static final int TOTAL_PLAYDEAD_TIME = 200; + private static final int POSE_ANIMATION_TICKS = 10; protected static final ImmutableList>> SENSOR_TYPES = ImmutableList.of(SensorType.NEAREST_LIVING_ENTITIES, SensorType.NEAREST_ADULT, SensorType.HURT_BY, SensorType.AXOLOTL_ATTACKABLES, SensorType.AXOLOTL_TEMPTATIONS); - protected static final ImmutableList> MEMORY_TYPES = ImmutableList.of(MemoryModuleType.BREED_TARGET, MemoryModuleType.NEAREST_LIVING_ENTITIES, MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, MemoryModuleType.NEAREST_VISIBLE_PLAYER, MemoryModuleType.NEAREST_VISIBLE_ATTACKABLE_PLAYER, MemoryModuleType.LOOK_TARGET, MemoryModuleType.WALK_TARGET, MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE, MemoryModuleType.PATH, MemoryModuleType.ATTACK_TARGET, MemoryModuleType.ATTACK_COOLING_DOWN, MemoryModuleType.NEAREST_VISIBLE_ADULT, new MemoryModuleType[]{MemoryModuleType.HURT_BY_ENTITY, MemoryModuleType.PLAY_DEAD_TICKS, MemoryModuleType.NEAREST_ATTACKABLE, MemoryModuleType.TEMPTING_PLAYER, MemoryModuleType.TEMPTATION_COOLDOWN_TICKS, MemoryModuleType.IS_TEMPTED, MemoryModuleType.HAS_HUNTING_COOLDOWN, MemoryModuleType.IS_PANICKING}); + // CraftBukkit - decompile error @@ -18,7 +19,7 @@ private static final DataWatcherObject DATA_VARIANT = DataWatcher.defineId(Axolotl.class, DataWatcherRegistry.INT); private static final DataWatcherObject DATA_PLAYING_DEAD = DataWatcher.defineId(Axolotl.class, DataWatcherRegistry.BOOLEAN); private static final DataWatcherObject FROM_BUCKET = DataWatcher.defineId(Axolotl.class, DataWatcherRegistry.BOOLEAN); -@@ -187,7 +194,7 @@ +@@ -210,7 +217,7 @@ @Override public int getMaxAirSupply() { @@ -27,7 +28,7 @@ } @Override -@@ -391,7 +398,7 @@ +@@ -414,7 +421,7 @@ int i = mobeffect != null ? mobeffect.getDuration() : 0; int j = Math.min(2400, 100 + i); @@ -36,7 +37,7 @@ } entityhuman.removeEffect(MobEffects.DIG_SLOWDOWN); -@@ -441,7 +448,7 @@ +@@ -464,7 +471,7 @@ @Override public BehaviorController getBrain() { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/camel/Camel.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/camel/Camel.patch index 7d3e9bba11..1c78bcdbab 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/camel/Camel.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/camel/Camel.patch @@ -8,32 +8,32 @@ +import org.bukkit.event.entity.EntityDamageEvent; +// CraftBukkit end + - public class Camel extends EntityHorseAbstract implements IJumpable, ISaddleable { + public class Camel extends EntityHorseAbstract { public static final float BABY_SCALE = 0.45F; -@@ -141,7 +145,7 @@ - @Override - protected void customServerAiStep() { - this.level().getProfiler().push("camelBrain"); +@@ -143,7 +147,7 @@ + GameProfilerFiller gameprofilerfiller = Profiler.get(); + + gameprofilerfiller.push("camelBrain"); - BehaviorController behaviorcontroller = this.getBrain(); + BehaviorController behaviorcontroller = (BehaviorController) this.getBrain(); // CraftBukkit - decompile error - behaviorcontroller.tick((WorldServer) this.level(), this); - this.level().getProfiler().pop(); -@@ -452,9 +456,15 @@ + behaviorcontroller.tick(worldserver, this); + gameprofilerfiller.pop(); +@@ -454,9 +458,15 @@ } @Override -- protected void actuallyHurt(DamageSource damagesource, float f) { +- protected void actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f) { + // CraftBukkit start - void -> boolean -+ public boolean actuallyHurt(DamageSource damagesource, float f, EntityDamageEvent event) { -+ boolean damageResult = super.actuallyHurt(damagesource, f, event); ++ public boolean actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f, EntityDamageEvent event) { ++ boolean damageResult = super.actuallyHurt(worldserver, damagesource, f, event); + if (!damageResult) { + return false; + } + // CraftBukkit end this.standUpInstantly(); -- super.actuallyHurt(damagesource, f); +- super.actuallyHurt(worldserver, damagesource, f); + return true; // CraftBukkit } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/frog/ShootTongue.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/frog/ShootTongue.patch index bbd20a8372..00ad10cb2e 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/frog/ShootTongue.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/frog/ShootTongue.patch @@ -22,7 +22,7 @@ } @@ -85,7 +89,7 @@ if (entity.isAlive()) { - frog.doHurtTarget(entity); + frog.doHurtTarget(worldserver, entity); if (!entity.isAlive()) { - entity.remove(Entity.RemovalReason.KILLED); + entity.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/frog/Tadpole.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/frog/Tadpole.patch index 0903590a82..d8295126db 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/frog/Tadpole.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/frog/Tadpole.patch @@ -1,17 +1,6 @@ --- a/net/minecraft/world/entity/animal/frog/Tadpole.java +++ b/net/minecraft/world/entity/animal/frog/Tadpole.java -@@ -38,6 +38,10 @@ - import net.minecraft.world.item.component.CustomData; - import net.minecraft.world.level.World; - -+// CraftBukkit start -+import org.bukkit.event.entity.EntityRemoveEvent; -+// CraftBukkit end -+ - public class Tadpole extends EntityFish { - - @VisibleForTesting -@@ -71,7 +75,7 @@ +@@ -74,7 +74,7 @@ @Override public BehaviorController getBrain() { @@ -20,22 +9,23 @@ } @Override -@@ -232,10 +236,16 @@ - } +@@ -225,12 +225,17 @@ + World world = this.level(); + if (world instanceof WorldServer worldserver) { +- this.convertTo(EntityTypes.FROG, ConversionParams.single(this, false, false), (frog) -> { ++ Frog converted = this.convertTo(EntityTypes.FROG, ConversionParams.single(this, false, false), (frog) -> { // CraftBukkit + frog.finalizeSpawn(worldserver, this.level().getCurrentDifficultyAt(frog.blockPosition()), EntitySpawnReason.CONVERSION, (GroupDataEntity) null); frog.setPersistenceRequired(); -+ // CraftBukkit start -+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTransformEvent(this, frog, org.bukkit.event.entity.EntityTransformEvent.TransformReason.METAMORPHOSIS).isCancelled()) { -+ this.setAge(0); // Sets the age to 0 for avoid a loop if the event is canceled -+ return; -+ } -+ // CraftBukkit end frog.fudgePositionAfterSizeChange(this.getDimensions(this.getPose())); this.playSound(SoundEffects.TADPOLE_GROW_UP, 0.15F, 1.0F); -- worldserver.addFreshEntityWithPassengers(frog); -- this.discard(); -+ worldserver.addFreshEntityWithPassengers(frog, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.METAMORPHOSIS); // CraftBukkit - add SpawnReason -+ this.discard(EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - add Bukkit remove cause - } +- }); ++ // CraftBukkit start ++ }, org.bukkit.event.entity.EntityTransformEvent.TransformReason.METAMORPHOSIS, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.METAMORPHOSIS); ++ if (converted == null) { ++ this.setAge(0); // Sets the age to 0 for avoid a loop if the event is canceled ++ } ++ // CraftBukkit end } + } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/goat/Goat.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/goat/Goat.patch index dc79b95d3e..fa246c2f2d 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/goat/Goat.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/goat/Goat.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/goat/Goat.java +++ b/net/minecraft/world/entity/animal/goat/Goat.java -@@ -55,6 +55,12 @@ +@@ -54,6 +54,12 @@ import net.minecraft.world.level.pathfinder.PathType; import net.minecraft.world.phys.Vec3D; @@ -13,7 +13,7 @@ public class Goat extends EntityAnimal { public static final EntitySize LONG_JUMPING_DIMENSIONS = EntitySize.scalable(0.9F, 1.3F).scale(0.7F); -@@ -182,7 +188,7 @@ +@@ -184,7 +190,7 @@ @Override public BehaviorController getBrain() { @@ -22,7 +22,7 @@ } @Override -@@ -225,8 +231,15 @@ +@@ -229,8 +235,15 @@ ItemStack itemstack = entityhuman.getItemInHand(enumhand); if (itemstack.is(Items.BUCKET) && !this.isBaby()) { @@ -38,4 +38,4 @@ + ItemStack itemstack1 = ItemLiquidUtil.createFilledResult(itemstack, entityhuman, CraftItemStack.asNMSCopy(event.getItemStack())); // CraftBukkit entityhuman.setItemInHand(enumhand, itemstack1); - return EnumInteractionResult.sidedSuccess(this.level().isClientSide); + return EnumInteractionResult.SUCCESS; diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.patch index cf3814014b..6857727453 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.java +++ b/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.java -@@ -81,6 +81,18 @@ +@@ -79,6 +79,18 @@ import net.minecraft.world.phys.Vec3D; import net.minecraft.world.ticks.ContainerSingleItem; @@ -19,7 +19,7 @@ public abstract class EntityHorseAbstract extends EntityAnimal implements IInventoryListener, HasCustomInventoryScreen, OwnableEntity, IJumpable, ISaddleable { public static final int EQUIPMENT_SLOT_OFFSET = 400; -@@ -158,7 +170,53 @@ +@@ -167,7 +179,53 @@ public boolean stillValid(EntityHuman entityhuman) { return entityhuman.getVehicle() == EntityHorseAbstract.this || entityhuman.canInteractWithEntity((Entity) EntityHorseAbstract.this, 4.0D); } @@ -73,7 +73,7 @@ protected EntityHorseAbstract(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -353,7 +411,7 @@ +@@ -366,7 +424,7 @@ public void createInventory() { InventorySubcontainer inventorysubcontainer = this.inventory; @@ -82,7 +82,7 @@ if (inventorysubcontainer != null) { inventorysubcontainer.removeListener(this); int i = Math.min(inventorysubcontainer.getContainerSize(), this.inventory.getContainerSize()); -@@ -457,7 +515,7 @@ +@@ -470,7 +528,7 @@ } public int getMaxTemper() { @@ -91,7 +91,7 @@ } @Override -@@ -528,7 +586,7 @@ +@@ -541,7 +599,7 @@ } if (this.getHealth() < this.getMaxHealth() && f > 0.0F) { @@ -100,16 +100,16 @@ flag = true; } -@@ -602,7 +660,7 @@ - super.aiStep(); - if (!this.level().isClientSide && this.isAlive()) { - if (this.random.nextInt(900) == 0 && this.deathTime == 0) { -- this.heal(1.0F); -+ this.heal(1.0F, EntityRegainHealthEvent.RegainReason.REGEN); // CraftBukkit - } +@@ -618,7 +676,7 @@ + if (world instanceof WorldServer worldserver) { + if (this.isAlive()) { + if (this.random.nextInt(900) == 0 && this.deathTime == 0) { +- this.heal(1.0F); ++ this.heal(1.0F, EntityRegainHealthEvent.RegainReason.REGEN); // CraftBukkit + } - if (this.canEatGrass()) { -@@ -864,6 +922,7 @@ + if (this.canEatGrass()) { +@@ -883,6 +941,7 @@ if (this.getOwnerUUID() != null) { nbttagcompound.putUUID("Owner", this.getOwnerUUID()); } @@ -117,7 +117,7 @@ if (!this.inventory.getItem(0).isEmpty()) { nbttagcompound.put("SaddleItem", this.inventory.getItem(0).save(this.registryAccess())); -@@ -891,6 +950,11 @@ +@@ -910,6 +969,11 @@ if (uuid != null) { this.setOwnerUUID(uuid); } @@ -129,7 +129,7 @@ if (nbttagcompound.contains("SaddleItem", 10)) { ItemStack itemstack = (ItemStack) ItemStack.parse(this.registryAccess(), nbttagcompound.getCompound("SaddleItem")).orElse(ItemStack.EMPTY); -@@ -993,6 +1057,17 @@ +@@ -1012,6 +1076,17 @@ @Override public void handleStartJump(int i) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityLlama.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityLlama.patch index 865898eebf..edd02d7ad7 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityLlama.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityLlama.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/horse/EntityLlama.java +++ b/net/minecraft/world/entity/animal/horse/EntityLlama.java -@@ -84,6 +84,11 @@ +@@ -82,6 +82,11 @@ return false; } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityLlamaTrader.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityLlamaTrader.patch index 1c56c4bdd9..d43f6038e3 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityLlamaTrader.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityLlamaTrader.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/horse/EntityLlamaTrader.java +++ b/net/minecraft/world/entity/animal/horse/EntityLlamaTrader.java -@@ -19,6 +19,10 @@ +@@ -22,6 +22,10 @@ import net.minecraft.world.level.World; import net.minecraft.world.level.WorldAccess; @@ -11,7 +11,7 @@ public class EntityLlamaTrader extends EntityLlama { private int despawnDelay = 47999; -@@ -87,7 +91,7 @@ +@@ -94,7 +98,7 @@ this.despawnDelay = this.isLeashedToWanderingTrader() ? ((EntityVillagerTrader) this.getLeashHolder()).getDespawnDelay() - 1 : this.despawnDelay - 1; if (this.despawnDelay <= 0) { this.dropLeash(true, false); @@ -20,7 +20,7 @@ } } -@@ -153,7 +157,7 @@ +@@ -160,7 +164,7 @@ @Override public void start() { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/sniffer/Sniffer.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/sniffer/Sniffer.patch index 37f01acf82..a100d9df99 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/sniffer/Sniffer.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/sniffer/Sniffer.patch @@ -1,20 +1,20 @@ --- a/net/minecraft/world/entity/animal/sniffer/Sniffer.java +++ b/net/minecraft/world/entity/animal/sniffer/Sniffer.java -@@ -274,6 +274,13 @@ - ItemStack itemstack = (ItemStack) iterator.next(); - EntityItem entityitem = new EntityItem(worldserver, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), itemstack); +@@ -267,6 +267,13 @@ + this.dropFromGiftLootTable(worldserver, LootTables.SNIFFER_DIGGING, (worldserver1, itemstack) -> { + EntityItem entityitem = new EntityItem(this.level(), (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), itemstack); -+ // CraftBukkit start - handle EntityDropItemEvent -+ org.bukkit.event.entity.EntityDropItemEvent event = new org.bukkit.event.entity.EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) entityitem.getBukkitEntity()); -+ org.bukkit.Bukkit.getPluginManager().callEvent(event); -+ if (event.isCancelled()) { -+ continue; -+ } -+ // CraftBukkit end - entityitem.setDefaultPickUpDelay(); - worldserver.addFreshEntity(entityitem); - } -@@ -313,7 +320,7 @@ ++ // CraftBukkit start - handle EntityDropItemEvent ++ org.bukkit.event.entity.EntityDropItemEvent event = new org.bukkit.event.entity.EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) entityitem.getBukkitEntity()); ++ org.bukkit.Bukkit.getPluginManager().callEvent(event); ++ if (event.isCancelled()) { ++ return; ++ } ++ // CraftBukkit end + entityitem.setDefaultPickUpDelay(); + worldserver1.addFreshEntity(entityitem); + }); +@@ -308,7 +315,7 @@ List list = (List) this.getExploredPositions().limit(20L).collect(Collectors.toList()); list.add(0, GlobalPos.of(this.level().dimension(), blockposition)); @@ -23,7 +23,7 @@ return this; } -@@ -454,7 +461,7 @@ +@@ -444,7 +451,7 @@ @Override public BehaviorController getBrain() { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/boss/enderdragon/EntityEnderCrystal.patch b/paper-server/nms-patches/net/minecraft/world/entity/boss/enderdragon/EntityEnderCrystal.patch index 19695c4495..1bc0b773ef 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/boss/enderdragon/EntityEnderCrystal.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/boss/enderdragon/EntityEnderCrystal.patch @@ -26,10 +26,10 @@ } } -@@ -94,12 +104,26 @@ +@@ -99,12 +109,26 @@ return false; } else { - if (!this.isRemoved() && !this.level().isClientSide) { + if (!this.isRemoved()) { - this.remove(Entity.RemovalReason.KILLED); + // CraftBukkit start - All non-living entities need this + if (CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f, false)) { @@ -39,7 +39,7 @@ if (!damagesource.is(DamageTypeTags.IS_EXPLOSION)) { DamageSource damagesource1 = damagesource.getEntity() != null ? this.damageSources().explosion(this, damagesource.getEntity()) : null; -- this.level().explode(this, damagesource1, (ExplosionDamageCalculator) null, this.getX(), this.getY(), this.getZ(), 6.0F, false, World.a.BLOCK); +- worldserver.explode(this, damagesource1, (ExplosionDamageCalculator) null, this.getX(), this.getY(), this.getZ(), 6.0F, false, World.a.BLOCK); + // CraftBukkit start + ExplosionPrimeEvent event = CraftEventFactory.callExplosionPrimeEvent(this, 6.0F, false); + if (event.isCancelled()) { @@ -47,11 +47,11 @@ + } + + this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.EXPLODE); // CraftBukkit - add Bukkit remove cause -+ this.level().explode(this, damagesource1, (ExplosionDamageCalculator) null, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), World.a.BLOCK); ++ worldserver.explode(this, damagesource1, (ExplosionDamageCalculator) null, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), World.a.BLOCK); + } else { + this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause } + // CraftBukkit end - this.onDestroyedBy(damagesource); + this.onDestroyedBy(worldserver, damagesource); } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.patch b/paper-server/nms-patches/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.patch index 2d60d6a8c6..6b683c7a9c 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.patch @@ -1,12 +1,13 @@ --- a/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.java +++ b/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.java -@@ -52,6 +52,21 @@ +@@ -52,6 +52,22 @@ import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; +// CraftBukkit start +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Explosion; ++import net.minecraft.world.level.ServerExplosion; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.TileEntity; +import net.minecraft.world.level.storage.loot.LootParams; @@ -22,7 +23,7 @@ public class EntityEnderDragon extends EntityInsentient implements IMonster { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -89,6 +104,7 @@ +@@ -88,6 +104,7 @@ private final PathPoint[] nodes; private final int[] nodeAdjacency; private final Path openSet; @@ -30,15 +31,15 @@ public EntityEnderDragon(EntityTypes entitytypes, World world) { super(EntityTypes.ENDER_DRAGON, world); -@@ -110,6 +126,7 @@ +@@ -108,6 +125,7 @@ + this.setHealth(this.getMaxHealth()); this.noPhysics = true; - this.noCulling = true; this.phaseManager = new DragonControllerManager(this); -+ this.explosionSource = new Explosion(world, this, null, null, Double.NaN, Double.NaN, Double.NaN, Float.NaN, true, Explosion.Effect.DESTROY, Particles.EXPLOSION, Particles.EXPLOSION_EMITTER, SoundEffects.GENERIC_EXPLODE); // CraftBukkit ++ this.explosionSource = new ServerExplosion(world.getMinecraftWorld(), this, null, null, new Vec3D(Double.NaN, Double.NaN, Double.NaN), Float.NaN, true, Explosion.Effect.DESTROY); // CraftBukkit } public void setDragonFight(EnderDragonBattle enderdragonbattle) { -@@ -257,7 +274,7 @@ +@@ -218,7 +236,7 @@ Vec3D vec3d1 = idragoncontroller.getFlyTargetLocation(); @@ -47,7 +48,7 @@ double d0 = vec3d1.x - this.getX(); double d1 = vec3d1.y - this.getY(); double d2 = vec3d1.z - this.getZ(); -@@ -404,7 +421,14 @@ +@@ -379,7 +397,14 @@ if (this.nearestCrystal.isRemoved()) { this.nearestCrystal = null; } else if (this.tickCount % 10 == 0 && this.getHealth() < this.getMaxHealth()) { @@ -63,7 +64,7 @@ } } -@@ -489,6 +513,9 @@ +@@ -458,6 +483,9 @@ int j1 = MathHelper.floor(axisalignedbb.maxZ); boolean flag = false; boolean flag1 = false; @@ -73,20 +74,20 @@ for (int k1 = i; k1 <= l; ++k1) { for (int l1 = j; l1 <= i1; ++l1) { -@@ -498,7 +525,11 @@ +@@ -467,7 +495,11 @@ if (!iblockdata.isAir() && !iblockdata.is(TagsBlock.DRAGON_TRANSPARENT)) { - if (this.level().getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) && !iblockdata.is(TagsBlock.DRAGON_IMMUNE)) { -- flag1 = this.level().removeBlock(blockposition, false) || flag1; + if (worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) && !iblockdata.is(TagsBlock.DRAGON_IMMUNE)) { +- flag1 = worldserver.removeBlock(blockposition, false) || flag1; + // CraftBukkit start - Add blocks to list rather than destroying them -+ // flag1 = this.level().removeBlock(blockposition, false) || flag1; ++ // flag1 = worldserver.removeBlock(blockposition, false) || flag1; + flag1 = true; -+ destroyedBlocks.add(CraftBlock.at(this.level(), blockposition)); ++ destroyedBlocks.add(CraftBlock.at(worldserver, blockposition)); + // CraftBukkit end } else { flag = true; } -@@ -507,6 +538,49 @@ +@@ -476,6 +508,49 @@ } } @@ -126,7 +127,7 @@ + }); + craftBlock.getNMS().spawnAfterBreak((WorldServer) this.level(), blockposition, ItemStack.EMPTY, false); + } -+ nmsBlock.wasExploded(this.level(), blockposition, explosionSource); ++ nmsBlock.wasExploded((WorldServer) this.level(), blockposition, explosionSource); + + this.level().removeBlock(blockposition, false); + } @@ -136,24 +137,24 @@ if (flag1) { BlockPosition blockposition1 = new BlockPosition(i + this.random.nextInt(l - i + 1), j + this.random.nextInt(i1 - j + 1), k + this.random.nextInt(j1 - k + 1)); -@@ -562,7 +636,7 @@ +@@ -531,7 +606,7 @@ @Override - public void kill() { + public void kill(WorldServer worldserver) { - this.remove(Entity.RemovalReason.KILLED); + this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause this.gameEvent(GameEvent.ENTITY_DIE); if (this.dragonFight != null) { this.dragonFight.updateDragon(this); -@@ -571,6 +645,21 @@ +@@ -540,6 +615,21 @@ } + // CraftBukkit start - SPIGOT-2420: Special case, the ender dragon drops 12000 xp for the first kill and 500 xp for every other kill and this over time. + @Override -+ public int getExpReward(Entity entity) { ++ public int getExpReward(WorldServer worldserver, Entity entity) { + // CraftBukkit - Moved from #tickDeath method -+ boolean flag = this.level().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT); ++ boolean flag = worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT); + short short0 = 500; + + if (this.dragonFight != null && !this.dragonFight.hasPreviouslyKilledDragon()) { @@ -167,13 +168,12 @@ @Override protected void tickDeath() { if (this.dragonFight != null) { -@@ -586,15 +675,20 @@ +@@ -555,16 +645,21 @@ this.level().addParticle(Particles.EXPLOSION_EMITTER, this.getX() + (double) f, this.getY() + 2.0D + (double) f1, this.getZ() + (double) f2, 0.0D, 0.0D, 0.0D); } + // CraftBukkit start - SPIGOT-2420: Moved up to #getExpReward method + /* - boolean flag = this.level().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT); short short0 = 500; if (this.dragonFight != null && !this.dragonFight.hasPreviouslyKilledDragon()) { @@ -183,31 +183,35 @@ + int short0 = expToDrop; + // CraftBukkit end - if (this.level() instanceof WorldServer) { -- if (this.dragonDeathTime > 150 && this.dragonDeathTime % 5 == 0 && flag) { + World world = this.level(); + + if (world instanceof WorldServer worldserver) { +- if (this.dragonDeathTime > 150 && this.dragonDeathTime % 5 == 0 && worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { + if (this.dragonDeathTime > 150 && this.dragonDeathTime % 5 == 0 && true) { // CraftBukkit - SPIGOT-2420: Already checked for the game rule when calculating the xp - EntityExperienceOrb.award((WorldServer) this.level(), this.position(), MathHelper.floor((float) short0 * 0.08F)); + EntityExperienceOrb.award(worldserver, this.position(), MathHelper.floor((float) short0 * 0.08F)); } -@@ -605,7 +699,7 @@ +@@ -577,8 +672,8 @@ + if (this.dragonDeathTime == 200) { + world = this.level(); + if (world instanceof WorldServer) { +- worldserver = (WorldServer) world; +- if (worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { ++ WorldServer worldserver = (WorldServer) world; // CraftBukkit - decompile error ++ if (true) { // CraftBukkit - SPIGOT-2420: Already checked for the game rule when calculating the xp + EntityExperienceOrb.award(worldserver, this.position(), MathHelper.floor((float) short0 * 0.2F)); + } - this.move(EnumMoveType.SELF, new Vec3D(0.0D, 0.10000000149011612D, 0.0D)); - if (this.dragonDeathTime == 200 && this.level() instanceof WorldServer) { -- if (flag) { -+ if (true) { // CraftBukkit - SPIGOT-2420: Already checked for the game rule when calculating the xp - EntityExperienceOrb.award((WorldServer) this.level(), this.position(), MathHelper.floor((float) short0 * 0.2F)); +@@ -586,7 +681,7 @@ + this.dragonFight.setDragonKilled(this); + } + +- this.remove(Entity.RemovalReason.KILLED); ++ this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause + this.gameEvent(GameEvent.ENTITY_DIE); } - -@@ -613,7 +707,7 @@ - this.dragonFight.setDragonKilled(this); - } - -- this.remove(Entity.RemovalReason.KILLED); -+ this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause - this.gameEvent(GameEvent.ENTITY_DIE); } - -@@ -826,6 +920,7 @@ +@@ -800,6 +895,7 @@ super.addAdditionalSaveData(nbttagcompound); nbttagcompound.putInt("DragonPhase", this.phaseManager.getCurrentPhase().getPhase().getId()); nbttagcompound.putInt("DragonDeathTime", this.dragonDeathTime); @@ -215,7 +219,7 @@ } @Override -@@ -839,6 +934,11 @@ +@@ -813,6 +909,11 @@ this.dragonDeathTime = nbttagcompound.getInt("DragonDeathTime"); } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/boss/enderdragon/phases/DragonControllerLandedFlame.patch b/paper-server/nms-patches/net/minecraft/world/entity/boss/enderdragon/phases/DragonControllerLandedFlame.patch index 8718435f45..b38a3a09c1 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/boss/enderdragon/phases/DragonControllerLandedFlame.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/boss/enderdragon/phases/DragonControllerLandedFlame.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/boss/enderdragon/phases/DragonControllerLandedFlame.java +++ b/net/minecraft/world/entity/boss/enderdragon/phases/DragonControllerLandedFlame.java -@@ -10,6 +10,10 @@ +@@ -11,6 +11,10 @@ import net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon; import net.minecraft.world.phys.Vec3D; @@ -11,7 +11,7 @@ public class DragonControllerLandedFlame extends AbstractDragonControllerLanded { private static final int FLAME_DURATION = 200; -@@ -99,7 +103,7 @@ +@@ -100,7 +104,7 @@ @Override public void end() { if (this.flame != null) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/boss/wither/EntityWither.patch b/paper-server/nms-patches/net/minecraft/world/entity/boss/wither/EntityWither.patch index e27efc7a79..27bbc62a0b 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/boss/wither/EntityWither.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/boss/wither/EntityWither.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/boss/wither/EntityWither.java +++ b/net/minecraft/world/entity/boss/wither/EntityWither.java -@@ -59,6 +59,18 @@ +@@ -57,6 +57,18 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.phys.Vec3D; @@ -16,29 +16,29 @@ +import org.bukkit.event.entity.ExplosionPrimeEvent; +// CraftBukkit end + - public class EntityWither extends EntityMonster implements PowerableMob, IRangedEntity { + public class EntityWither extends EntityMonster implements IRangedEntity { private static final DataWatcherObject DATA_TARGET_A = DataWatcher.defineId(EntityWither.class, DataWatcherRegistry.INT); -@@ -255,15 +267,40 @@ +@@ -253,15 +265,40 @@ i = this.getInvulnerableTicks() - 1; this.bossEvent.setProgress(1.0F - (float) i / 220.0F); if (i <= 0) { -- this.level().explode(this, this.getX(), this.getEyeY(), this.getZ(), 7.0F, false, World.a.MOB); +- worldserver.explode(this, this.getX(), this.getEyeY(), this.getZ(), 7.0F, false, World.a.MOB); + // CraftBukkit start -+ // this.level().explode(this, this.getX(), this.getEyeY(), this.getZ(), 7.0F, false, World.a.MOB); ++ // worldserver.explode(this, this.getX(), this.getEyeY(), this.getZ(), 7.0F, false, World.a.MOB); + ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), 7.0F, false); -+ this.level().getCraftServer().getPluginManager().callEvent(event); ++ worldserver.getCraftServer().getPluginManager().callEvent(event); + + if (!event.isCancelled()) { -+ this.level().explode(this, this.getX(), this.getEyeY(), this.getZ(), event.getRadius(), event.getFire(), World.a.MOB); ++ worldserver.explode(this, this.getX(), this.getEyeY(), this.getZ(), event.getRadius(), event.getFire(), World.a.MOB); + } + // CraftBukkit end + if (!this.isSilent()) { -- this.level().globalLevelEvent(1023, this.blockPosition(), 0); +- worldserver.globalLevelEvent(1023, this.blockPosition(), 0); + // CraftBukkit start - Use relative location for far away sounds -+ // this.level().globalLevelEvent(1023, new BlockPosition(this), 0); -+ int viewDistance = ((WorldServer) this.level()).getCraftServer().getViewDistance() * 16; ++ // worldserver.globalLevelEvent(1023, new BlockPosition(this), 0); ++ int viewDistance = worldserver.getCraftServer().getViewDistance() * 16; + for (EntityPlayer player : (List) MinecraftServer.getServer().getPlayerList().players) { + double deltaX = this.getX() - player.getX(); + double deltaZ = this.getZ() - player.getZ(); @@ -63,7 +63,7 @@ } } else { -@@ -308,6 +345,7 @@ +@@ -306,6 +343,7 @@ if (!list.isEmpty()) { EntityLiving entityliving1 = (EntityLiving) list.get(this.random.nextInt(list.size())); @@ -71,8 +71,8 @@ this.setAlternativeTarget(i, entityliving1.getId()); } } -@@ -334,6 +372,11 @@ - IBlockData iblockdata = this.level().getBlockState(blockposition); +@@ -332,6 +370,11 @@ + IBlockData iblockdata = worldserver.getBlockState(blockposition); if (canDestroy(iblockdata)) { + // CraftBukkit start @@ -80,10 +80,10 @@ + continue; + } + // CraftBukkit end - flag = this.level().destroyBlock(blockposition, true, this) || flag; + flag = worldserver.destroyBlock(blockposition, true, this) || flag; } } -@@ -345,7 +388,7 @@ +@@ -343,7 +386,7 @@ } if (this.tickCount % 20 == 0) { @@ -92,7 +92,7 @@ } this.bossEvent.setProgress(this.getHealth() / this.getMaxHealth()); -@@ -502,7 +545,7 @@ +@@ -500,7 +543,7 @@ @Override public void checkDespawn() { if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL && this.shouldDespawnInPeaceful()) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/decoration/BlockAttachedEntity.patch b/paper-server/nms-patches/net/minecraft/world/entity/decoration/BlockAttachedEntity.patch index 5a159a32fd..27d3b35bb5 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/decoration/BlockAttachedEntity.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/decoration/BlockAttachedEntity.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/decoration/BlockAttachedEntity.java +++ b/net/minecraft/world/entity/decoration/BlockAttachedEntity.java -@@ -15,6 +15,15 @@ +@@ -18,6 +18,15 @@ import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; @@ -16,7 +16,7 @@ public abstract class BlockAttachedEntity extends Entity { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -39,7 +48,25 @@ +@@ -44,7 +53,25 @@ if (this.checkInterval++ == 100) { this.checkInterval = 0; if (!this.isRemoved() && !this.survives()) { @@ -40,13 +40,13 @@ + } + // CraftBukkit end + this.discard(EntityRemoveEvent.Cause.DROP); // CraftBukkit - add Bukkit remove cause - this.dropItem((Entity) null); + this.dropItem(worldserver, (Entity) null); } } -@@ -69,6 +96,22 @@ +@@ -81,6 +108,22 @@ return false; } else { - if (!this.isRemoved() && !this.level().isClientSide) { + if (!this.isRemoved()) { + // CraftBukkit start - fire break events + Entity damager = (damagesource.isDirect()) ? damagesource.getDirectEntity() : damagesource.getEntity(); + HangingBreakEvent event; @@ -63,37 +63,36 @@ + } + // CraftBukkit end + - this.kill(); + this.kill(worldserver); this.markHurt(); - this.dropItem(damagesource.getEntity()); -@@ -81,6 +124,18 @@ - @Override - public void move(EnumMoveType enummovetype, Vec3D vec3d) { - if (!this.level().isClientSide && !this.isRemoved() && vec3d.lengthSqr() > 0.0D) { -+ if (this.isRemoved()) return; // CraftBukkit -+ -+ // CraftBukkit start - fire break events -+ // TODO - Does this need its own cause? Seems to only be triggered by pistons -+ HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.PHYSICS); -+ this.level().getCraftServer().getPluginManager().callEvent(event); -+ -+ if (this.isRemoved() || event.isCancelled()) { -+ return; -+ } -+ // CraftBukkit end -+ - this.kill(); - this.dropItem((Entity) null); - } -@@ -89,13 +144,22 @@ + this.dropItem(worldserver, damagesource.getEntity()); +@@ -101,6 +144,16 @@ - @Override - public void push(double d0, double d1, double d2) { -- if (!this.level().isClientSide && !this.isRemoved() && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) { -+ if (false && !this.level().isClientSide && !this.isRemoved() && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) { // CraftBukkit - not needed - this.kill(); - this.dropItem((Entity) null); - } + if (world instanceof WorldServer worldserver) { + if (!this.isRemoved() && vec3d.lengthSqr() > 0.0D) { ++ // CraftBukkit start - fire break events ++ // TODO - Does this need its own cause? Seems to only be triggered by pistons ++ HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.PHYSICS); ++ this.level().getCraftServer().getPluginManager().callEvent(event); ++ ++ if (this.isRemoved() || event.isCancelled()) { ++ return; ++ } ++ // CraftBukkit end ++ + this.kill(worldserver); + this.dropItem(worldserver, (Entity) null); + } +@@ -113,7 +166,7 @@ + World world = this.level(); + + if (world instanceof WorldServer worldserver) { +- if (!this.isRemoved() && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) { ++ if (false && !this.isRemoved() && d0 * d0 + d1 * d1 + d2 * d2 > 0.0D) { // CraftBukkit - not needed + this.kill(worldserver); + this.dropItem(worldserver, (Entity) null); + } +@@ -121,6 +174,15 @@ } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityArmorStand.patch b/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityArmorStand.patch index 7770160f77..1594547064 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityArmorStand.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityArmorStand.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/decoration/EntityArmorStand.java +++ b/net/minecraft/world/entity/decoration/EntityArmorStand.java -@@ -46,6 +46,16 @@ +@@ -48,6 +48,16 @@ import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; @@ -17,7 +17,7 @@ public class EntityArmorStand extends EntityLiving { public static final int WOBBLE_TIME = 5; -@@ -111,6 +121,13 @@ +@@ -123,6 +133,13 @@ return createLivingAttributes().add(GenericAttributes.STEP_HEIGHT, 0.0D); } @@ -31,7 +31,7 @@ @Override public void refreshDimensions() { double d0 = this.getX(); -@@ -171,13 +188,20 @@ +@@ -183,13 +200,20 @@ @Override public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { @@ -54,9 +54,9 @@ } } -@@ -407,7 +431,25 @@ +@@ -412,7 +436,25 @@ return false; - } else if (itemstack1.isEmpty() && (this.disabledSlots & 1 << enumitemslot.getFilterFlag() + 16) != 0) { + } else if (itemstack1.isEmpty() && (this.disabledSlots & 1 << enumitemslot.getFilterBit(16)) != 0) { return false; - } else if (entityhuman.hasInfiniteMaterials() && itemstack1.isEmpty() && !itemstack.isEmpty()) { + // CraftBukkit start @@ -81,7 +81,7 @@ this.setItemSlot(enumitemslot, itemstack.copyWithCount(1)); return true; } else if (!itemstack.isEmpty() && itemstack.getCount() > 1) { -@@ -422,6 +464,7 @@ +@@ -427,6 +469,7 @@ entityhuman.setItemInHand(enumhand, itemstack1); return true; } @@ -89,60 +89,60 @@ } @Override -@@ -435,12 +478,22 @@ - WorldServer worldserver = (WorldServer) world; +@@ -436,12 +479,22 @@ + } else if (!worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) && damagesource.getEntity() instanceof EntityInsentient) { + return false; + } else if (damagesource.is(DamageTypeTags.BYPASSES_INVULNERABILITY)) { +- this.kill(worldserver); ++ // CraftBukkit start ++ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f)) { ++ return false; ++ } ++ this.kill(worldserver, damagesource); // CraftBukkit ++ // CraftBukkit end + return false; +- } else if (!this.isInvulnerableTo(worldserver, damagesource) && !this.invisible && !this.isMarker()) { ++ } else if (!this.isInvulnerableTo(worldserver, damagesource) && (true || !this.invisible) && !this.isMarker()) { // CraftBukkit ++ // CraftBukkit start ++ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f, true, this.invisible)) { ++ return false; ++ } ++ // CraftBukkit end + if (damagesource.is(DamageTypeTags.IS_EXPLOSION)) { + this.brokenByAnything(worldserver, damagesource); +- this.kill(worldserver); ++ this.kill(worldserver, damagesource); // CraftBukkit + return false; + } else if (damagesource.is(DamageTypeTags.IGNITES_ARMOR_STANDS)) { + if (this.isOnFire()) { +@@ -474,7 +527,7 @@ + if (damagesource.isCreativePlayer()) { + this.playBrokenSound(); + this.showBreakingParticles(); +- this.kill(worldserver); ++ this.kill(worldserver, damagesource); // CraftBukkit + return true; + } else { + long i = worldserver.getGameTime(); +@@ -486,7 +539,7 @@ + } else { + this.brokenByPlayer(worldserver, damagesource); + this.showBreakingParticles(); +- this.kill(worldserver); ++ this.discard(EntityRemoveEvent.Cause.DEATH); // CraftBukkit - SPIGOT-4890: remain as this.discard() since above damagesource method will call death event + } - if (damagesource.is(DamageTypeTags.BYPASSES_INVULNERABILITY)) { -- this.kill(); -+ // CraftBukkit start -+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f)) { -+ return false; -+ } -+ this.kill(damagesource); // CraftBukkit -+ // CraftBukkit end - return false; -- } else if (!this.isInvulnerableTo(damagesource) && !this.invisible && !this.isMarker()) { -+ } else if (!this.isInvulnerableTo(damagesource) && (true || !this.invisible) && !this.isMarker()) { // CraftBukkit -+ // CraftBukkit start -+ if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f, true, this.invisible)) { -+ return false; -+ } -+ // CraftBukkit end - if (damagesource.is(DamageTypeTags.IS_EXPLOSION)) { - this.brokenByAnything(worldserver, damagesource); -- this.kill(); -+ this.kill(damagesource); // CraftBukkit - return false; - } else if (damagesource.is(DamageTypeTags.IGNITES_ARMOR_STANDS)) { - if (this.isOnFire()) { -@@ -473,7 +526,7 @@ - if (damagesource.isCreativePlayer()) { - this.playBrokenSound(); - this.showBreakingParticles(); -- this.kill(); -+ this.kill(damagesource); // CraftBukkit - return true; - } else { - long i = worldserver.getGameTime(); -@@ -485,7 +538,7 @@ - } else { - this.brokenByPlayer(worldserver, damagesource); - this.showBreakingParticles(); -- this.kill(); -+ this.discard(EntityRemoveEvent.Cause.DEATH); // CraftBukkit - SPIGOT-4890: remain as this.discard() since above damagesource method will call death event - } - - return true; -@@ -539,7 +592,7 @@ + return true; +@@ -536,7 +589,7 @@ f1 -= f; if (f1 <= 0.5F) { this.brokenByAnything(worldserver, damagesource); -- this.kill(); -+ this.kill(damagesource); // CraftBukkit +- this.kill(worldserver); ++ this.kill(worldserver, damagesource); // CraftBukkit } else { this.setHealth(f1); this.gameEvent(GameEvent.ENTITY_DAMAGE, damagesource.getEntity()); -@@ -551,13 +604,13 @@ +@@ -548,13 +601,13 @@ ItemStack itemstack = new ItemStack(Items.ARMOR_STAND); itemstack.set(DataComponents.CUSTOM_NAME, this.getCustomName()); @@ -158,7 +158,7 @@ ItemStack itemstack; int i; -@@ -565,7 +618,7 @@ +@@ -562,7 +615,7 @@ for (i = 0; i < this.handItems.size(); ++i) { itemstack = (ItemStack) this.handItems.get(i); if (!itemstack.isEmpty()) { @@ -167,7 +167,7 @@ this.handItems.set(i, ItemStack.EMPTY); } } -@@ -573,10 +626,11 @@ +@@ -570,10 +623,11 @@ for (i = 0; i < this.armorItems.size(); ++i) { itemstack = (ItemStack) this.armorItems.get(i); if (!itemstack.isEmpty()) { @@ -180,7 +180,7 @@ } -@@ -667,9 +721,23 @@ +@@ -664,9 +718,23 @@ return this.isSmall(); } @@ -192,13 +192,13 @@ + // CraftBukkit end + @Override - public void kill() { + public void kill(WorldServer worldserver) { - this.remove(Entity.RemovalReason.KILLED); + // CraftBukkit start - pass DamageSource for kill -+ this.kill(null); ++ this.kill(worldserver, null); + } + -+ public void kill(DamageSource damageSource) { ++ public void kill(WorldServer worldserver, DamageSource damageSource) { + org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDeathEvent(this, (damageSource == null ? this.damageSources().genericKill() : damageSource), drops); // CraftBukkit - call event + this.remove(Entity.RemovalReason.KILLED, EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause + // CraftBukkit end diff --git a/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityItemFrame.patch b/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityItemFrame.patch index 1be425e0ee..26a8dd92d6 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityItemFrame.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityItemFrame.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/decoration/EntityItemFrame.java +++ b/net/minecraft/world/entity/decoration/EntityItemFrame.java -@@ -90,6 +90,12 @@ +@@ -91,6 +91,12 @@ @Override protected AxisAlignedBB calculateBoundingBox(BlockPosition blockposition, EnumDirection enumdirection) { @@ -13,19 +13,19 @@ float f = 0.46875F; Vec3D vec3d = Vec3D.atCenterOf(blockposition).relative(enumdirection, -0.46875D); EnumDirection.EnumAxis enumdirection_enumaxis = enumdirection.getAxis(); -@@ -143,6 +149,11 @@ - return false; - } else if (!damagesource.is(DamageTypeTags.IS_EXPLOSION) && !this.getItem().isEmpty()) { - if (!this.level().isClientSide) { +@@ -155,6 +161,11 @@ + if (this.isInvulnerableToBase(damagesource)) { + return false; + } else if (this.shouldDamageDropItem(damagesource)) { + // CraftBukkit start - fire EntityDamageEvent + if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f, false) || this.isRemoved()) { + return true; + } + // CraftBukkit end - this.dropItem(damagesource.getEntity(), false); + this.dropItem(worldserver, damagesource.getEntity(), false); this.gameEvent(GameEvent.BLOCK_CHANGE, damagesource.getEntity()); this.playSound(this.getRemoveItemSound(), 1.0F, 1.0F); -@@ -255,13 +266,19 @@ +@@ -267,13 +278,19 @@ } public void setItem(ItemStack itemstack, boolean flag) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityLeash.patch b/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityLeash.patch index 2b0db10d68..db338150fc 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityLeash.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityLeash.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/decoration/EntityLeash.java +++ b/net/minecraft/world/entity/decoration/EntityLeash.java -@@ -26,6 +26,13 @@ +@@ -27,6 +27,13 @@ import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; @@ -14,7 +14,7 @@ public class EntityLeash extends BlockAttachedEntity { public static final double OFFSET_Y = 0.375D; -@@ -84,6 +91,15 @@ +@@ -85,6 +92,15 @@ Leashable leashable = (Leashable) iterator.next(); if (leashable.getLeashHolder() == entityhuman) { @@ -30,7 +30,7 @@ leashable.setLeashedTo(this, true); flag = true; } -@@ -92,18 +108,34 @@ +@@ -93,18 +109,34 @@ boolean flag1 = false; if (!flag) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityPainting.patch b/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityPainting.patch index bfdd9a1782..ac5b3f26bd 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityPainting.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityPainting.patch @@ -1,15 +1,15 @@ --- a/net/minecraft/world/entity/decoration/EntityPainting.java +++ b/net/minecraft/world/entity/decoration/EntityPainting.java -@@ -71,7 +71,7 @@ +@@ -72,7 +72,7 @@ public static Optional create(World world, BlockPosition blockposition, EnumDirection enumdirection) { EntityPainting entitypainting = new EntityPainting(world, blockposition); List> list = new ArrayList(); -- Iterable iterable = world.registryAccess().registryOrThrow(Registries.PAINTING_VARIANT).getTagOrEmpty(PaintingVariantTags.PLACEABLE); -+ Iterable> iterable = world.registryAccess().registryOrThrow(Registries.PAINTING_VARIANT).getTagOrEmpty(PaintingVariantTags.PLACEABLE); // CraftBukkit - decompile error +- Iterable iterable = world.registryAccess().lookupOrThrow(Registries.PAINTING_VARIANT).getTagOrEmpty(PaintingVariantTags.PLACEABLE); ++ Iterable> iterable = world.registryAccess().lookupOrThrow(Registries.PAINTING_VARIANT).getTagOrEmpty(PaintingVariantTags.PLACEABLE); // CraftBukkit - decompile error Objects.requireNonNull(list); iterable.forEach(list::add); -@@ -137,22 +137,32 @@ +@@ -138,22 +138,32 @@ @Override protected AxisAlignedBB calculateBoundingBox(BlockPosition blockposition, EnumDirection enumdirection) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/item/EntityFallingBlock.patch b/paper-server/nms-patches/net/minecraft/world/entity/item/EntityFallingBlock.patch index 1c8bbcb541..183c3b9570 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/item/EntityFallingBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/item/EntityFallingBlock.patch @@ -31,7 +31,7 @@ return entityfallingblock; } -@@ -130,7 +142,7 @@ +@@ -139,7 +151,7 @@ @Override public void tick() { if (this.blockState.isAir()) { @@ -40,52 +40,52 @@ } else { Block block = this.blockState.getBlock(); -@@ -159,7 +171,7 @@ - this.spawnAtLocation((IMaterial) block); +@@ -174,7 +186,7 @@ + this.spawnAtLocation(worldserver, (IMaterial) block); + } + +- this.discard(); ++ this.discard(EntityRemoveEvent.Cause.DROP); // CraftBukkit - add Bukkit remove cause } - -- this.discard(); -+ this.discard(EntityRemoveEvent.Cause.DROP); // CraftBukkit - add Bukkit remove cause - } - } else { - IBlockData iblockdata = this.level().getBlockState(blockposition); -@@ -176,9 +188,15 @@ - this.blockState = (IBlockData) this.blockState.setValue(BlockProperties.WATERLOGGED, true); - } - -+ // CraftBukkit start -+ if (!CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, this.blockState)) { -+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // SPIGOT-6586 called before the event in previous versions -+ return; -+ } -+ // CraftBukkit end - if (this.level().setBlock(blockposition, this.blockState, 3)) { - ((WorldServer) this.level()).getChunkSource().chunkMap.broadcast(this, new PacketPlayOutBlockChange(blockposition, this.level().getBlockState(blockposition))); -- this.discard(); -+ this.discard(EntityRemoveEvent.Cause.DESPAWN); - if (block instanceof Fallable) { - ((Fallable) block).onLand(this.level(), blockposition, this.blockState, iblockdata, this); + } else { + IBlockData iblockdata = this.level().getBlockState(blockposition); +@@ -191,9 +203,15 @@ + this.blockState = (IBlockData) this.blockState.setValue(BlockProperties.WATERLOGGED, true); } -@@ -206,19 +224,19 @@ + ++ // CraftBukkit start ++ if (!CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, this.blockState)) { ++ this.discard(EntityRemoveEvent.Cause.DESPAWN); // SPIGOT-6586 called before the event in previous versions ++ return; ++ } ++ // CraftBukkit end + if (this.level().setBlock(blockposition, this.blockState, 3)) { + ((WorldServer) this.level()).getChunkSource().chunkMap.broadcast(this, new PacketPlayOutBlockChange(blockposition, this.level().getBlockState(blockposition))); +- this.discard(); ++ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause + if (block instanceof Fallable) { + ((Fallable) block).onLand(this.level(), blockposition, this.blockState, iblockdata, this); } +@@ -221,19 +239,19 @@ + } + } + } else if (this.dropItem && worldserver.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) { +- this.discard(); ++ this.discard(EntityRemoveEvent.Cause.DROP); // CraftBukkit - add Bukkit remove cause + this.callOnBrokenAfterFall(block, blockposition); + this.spawnAtLocation(worldserver, (IMaterial) block); } - } else if (this.dropItem && this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) { + } else { - this.discard(); + this.discard(EntityRemoveEvent.Cause.DROP); // CraftBukkit - add Bukkit remove cause - this.callOnBrokenAfterFall(block, blockposition); - this.spawnAtLocation((IMaterial) block); + if (this.dropItem && worldserver.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) { + this.callOnBrokenAfterFall(block, blockposition); + this.spawnAtLocation(worldserver, (IMaterial) block); + } } } else { - this.discard(); -+ this.discard(EntityRemoveEvent.Cause.DROP); // CraftBukkit - add Bukkit remove cause - if (this.dropItem && this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) { - this.callOnBrokenAfterFall(block, blockposition); - this.spawnAtLocation((IMaterial) block); - } ++ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause + this.callOnBrokenAfterFall(block, blockposition); } - } else { -- this.discard(); -+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause - this.callOnBrokenAfterFall(block, blockposition); } - } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/item/EntityItem.patch b/paper-server/nms-patches/net/minecraft/world/entity/item/EntityItem.patch index 1613016c17..7dac6e9b40 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/item/EntityItem.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/item/EntityItem.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/entity/item/EntityItem.java +++ b/net/minecraft/world/entity/item/EntityItem.java @@ -34,6 +34,15 @@ - import net.minecraft.world.level.portal.DimensionTransition; + import net.minecraft.world.level.portal.TeleportTransition; import net.minecraft.world.phys.Vec3D; +// CraftBukkit start @@ -44,7 +44,7 @@ this.xo = this.getX(); this.yo = this.getY(); -@@ -187,9 +200,11 @@ +@@ -188,9 +201,11 @@ this.mergeWithNeighbours(); } @@ -56,7 +56,7 @@ this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing(); if (!this.level().isClientSide) { -@@ -201,7 +216,13 @@ +@@ -202,7 +217,13 @@ } if (!this.level().isClientSide && this.age >= 6000) { @@ -71,7 +71,7 @@ } } -@@ -284,11 +305,16 @@ +@@ -287,11 +308,16 @@ } private static void merge(EntityItem entityitem, ItemStack itemstack, EntityItem entityitem1, ItemStack itemstack1) { @@ -89,9 +89,9 @@ } } -@@ -309,12 +335,17 @@ - } else if (this.level().isClientSide) { - return true; +@@ -320,12 +346,17 @@ + } else if (!this.getItem().canBeHurtBy(damagesource)) { + return false; } else { + // CraftBukkit start + if (CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f)) { @@ -108,7 +108,7 @@ } return true; -@@ -366,7 +397,7 @@ +@@ -382,7 +413,7 @@ } if (this.getItem().isEmpty()) { @@ -117,7 +117,7 @@ } } -@@ -378,10 +409,50 @@ +@@ -394,10 +425,50 @@ Item item = itemstack.getItem(); int i = itemstack.getCount(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/item/EntityTNTPrimed.patch b/paper-server/nms-patches/net/minecraft/world/entity/item/EntityTNTPrimed.patch index 75d2442861..d4ea5a67de 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/item/EntityTNTPrimed.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/item/EntityTNTPrimed.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/entity/item/EntityTNTPrimed.java +++ b/net/minecraft/world/entity/item/EntityTNTPrimed.java -@@ -24,6 +24,12 @@ +@@ -27,6 +27,12 @@ import net.minecraft.world.level.material.Fluid; - import net.minecraft.world.level.portal.DimensionTransition; + import net.minecraft.world.level.portal.TeleportTransition; +// CraftBukkit start; +import org.bukkit.craftbukkit.event.CraftEventFactory; @@ -13,16 +13,15 @@ public class EntityTNTPrimed extends Entity implements TraceableEntity { private static final DataWatcherObject DATA_FUSE_ID = DataWatcher.defineId(EntityTNTPrimed.class, DataWatcherRegistry.INT); -@@ -45,6 +51,8 @@ - @Nullable +@@ -51,6 +57,7 @@ public EntityLiving owner; private boolean usedPortal; -+ public float yield = 4; // CraftBukkit - add field + public float explosionPower; + public boolean isIncendiary = false; // CraftBukkit - add field public EntityTNTPrimed(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -99,10 +107,13 @@ +@@ -107,10 +114,13 @@ this.setFuse(i); if (i <= 0) { @@ -37,19 +36,17 @@ } else { this.updateInWaterStateAndDoFluidPushing(); if (this.level().isClientSide) { -@@ -113,9 +124,14 @@ +@@ -121,7 +131,13 @@ } private void explode() { -- float f = 4.0F; +- this.level().explode(this, Explosion.getDefaultDamageSource(this.level(), this), this.usedPortal ? EntityTNTPrimed.USED_PORTAL_DAMAGE_CALCULATOR : null, this.getX(), this.getY(0.0625D), this.getZ(), this.explosionPower, false, World.a.TNT); + // CraftBukkit start -+ // float f = 4.0F; -+ ExplosionPrimeEvent event = CraftEventFactory.callExplosionPrimeEvent((org.bukkit.entity.Explosive)this.getBukkitEntity()); - -- this.level().explode(this, Explosion.getDefaultDamageSource(this.level(), this), this.usedPortal ? EntityTNTPrimed.USED_PORTAL_DAMAGE_CALCULATOR : null, this.getX(), this.getY(0.0625D), this.getZ(), 4.0F, false, World.a.TNT); -+ if (!event.isCancelled()) { -+ this.level().explode(this, Explosion.getDefaultDamageSource(this.level(), this), this.usedPortal ? EntityTNTPrimed.USED_PORTAL_DAMAGE_CALCULATOR : null, this.getX(), this.getY(0.0625D), this.getZ(), event.getRadius(), event.getFire(), World.a.TNT); ++ ExplosionPrimeEvent event = CraftEventFactory.callExplosionPrimeEvent((org.bukkit.entity.Explosive) this.getBukkitEntity()); ++ if (event.isCancelled()) { ++ return; + } ++ this.level().explode(this, Explosion.getDefaultDamageSource(this.level(), this), this.usedPortal ? EntityTNTPrimed.USED_PORTAL_DAMAGE_CALCULATOR : null, this.getX(), this.getY(0.0625D), this.getZ(), event.getRadius(), event.getFire(), World.a.TNT); + // CraftBukkit end } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/Bogged.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/Bogged.patch index 05fc9bf8c8..8a45b0e819 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/Bogged.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/Bogged.patch @@ -1,15 +1,15 @@ --- a/net/minecraft/world/entity/monster/Bogged.java +++ b/net/minecraft/world/entity/monster/Bogged.java @@ -79,6 +79,12 @@ - ItemStack itemstack = entityhuman.getItemInHand(enumhand); + if (world instanceof WorldServer) { + WorldServer worldserver = (WorldServer) world; - if (itemstack.is(Items.SHEARS) && this.readyForShearing()) { -+ // CraftBukkit start -+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handlePlayerShearEntityEvent(entityhuman, this, itemstack, enumhand)) { -+ this.getEntityData().markDirty(Bogged.DATA_SHEARED); // CraftBukkit - mark dirty to restore sheared state to clients -+ return EnumInteractionResult.PASS; -+ } -+ // CraftBukkit end - this.shear(SoundCategory.PLAYERS); - this.gameEvent(GameEvent.SHEAR, entityhuman); - if (!this.level().isClientSide) { ++ // CraftBukkit start ++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handlePlayerShearEntityEvent(entityhuman, this, itemstack, enumhand)) { ++ this.getEntityData().markDirty(Bogged.DATA_SHEARED); // CraftBukkit - mark dirty to restore sheared state to clients ++ return EnumInteractionResult.PASS; ++ } ++ // CraftBukkit end + this.shear(worldserver, SoundCategory.PLAYERS, itemstack); + this.gameEvent(GameEvent.SHEAR, entityhuman); + itemstack.hurtAndBreak(1, entityhuman, getSlotForHand(enumhand)); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityCaveSpider.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityCaveSpider.patch index 9854811931..f70d92bc93 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityCaveSpider.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityCaveSpider.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityCaveSpider.java +++ b/net/minecraft/world/entity/monster/EntityCaveSpider.java -@@ -39,7 +39,7 @@ +@@ -40,7 +40,7 @@ } if (b0 > 0) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityCreeper.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityCreeper.patch index a0cc7042c8..158cbcb19d 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityCreeper.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityCreeper.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityCreeper.java +++ b/net/minecraft/world/entity/monster/EntityCreeper.java -@@ -43,6 +43,13 @@ +@@ -42,6 +42,13 @@ import net.minecraft.world.level.World; import net.minecraft.world.level.gameevent.GameEvent; @@ -11,10 +11,10 @@ +import org.bukkit.event.entity.ExplosionPrimeEvent; +// CraftBukkit end + - public class EntityCreeper extends EntityMonster implements PowerableMob { + public class EntityCreeper extends EntityMonster { private static final DataWatcherObject DATA_SWELL_DIR = DataWatcher.defineId(EntityCreeper.class, DataWatcherRegistry.INT); -@@ -53,6 +60,7 @@ +@@ -52,6 +59,7 @@ public int maxSwell = 30; public int explosionRadius = 3; private int droppedSkulls; @@ -22,7 +22,7 @@ public EntityCreeper(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -216,9 +224,20 @@ +@@ -214,9 +222,20 @@ @Override public void thunderHit(WorldServer worldserver, EntityLightning entitylightning) { super.thunderHit(worldserver, entitylightning); @@ -43,7 +43,7 @@ @Override protected EnumInteractionResult mobInteract(EntityHuman entityhuman, EnumHand enumhand) { ItemStack itemstack = entityhuman.getItemInHand(enumhand); -@@ -228,8 +247,9 @@ +@@ -226,8 +245,9 @@ this.level().playSound(entityhuman, this.getX(), this.getY(), this.getZ(), soundeffect, this.getSoundSource(), 1.0F, this.random.nextFloat() * 0.4F + 0.8F); if (!this.level().isClientSide) { @@ -55,7 +55,7 @@ } else { itemstack.hurtAndBreak(1, entityhuman, getSlotForHand(enumhand)); @@ -246,11 +266,20 @@ - if (!this.level().isClientSide) { + if (world instanceof WorldServer worldserver) { float f = this.isPowered() ? 2.0F : 1.0F; + // CraftBukkit start @@ -63,10 +63,10 @@ + if (!event.isCancelled()) { + // CraftBukkit end this.dead = true; -- this.level().explode(this, this.getX(), this.getY(), this.getZ(), (float) this.explosionRadius * f, World.a.MOB); -+ this.level().explode(this, net.minecraft.world.level.Explosion.getDefaultDamageSource(this.level(), this).customCausingEntityDamager(this.entityIgniter), null, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), World.a.MOB); // CraftBukkit +- worldserver.explode(this, this.getX(), this.getY(), this.getZ(), (float) this.explosionRadius * f, World.a.MOB); ++ worldserver.explode(this, net.minecraft.world.level.Explosion.getDefaultDamageSource(this.level(), this).customCausingEntityDamager(this.entityIgniter), null, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), World.a.MOB); // CraftBukkit this.spawnLingeringCloud(); - this.triggerOnDeathMobEffects(Entity.RemovalReason.KILLED); + this.triggerOnDeathMobEffects(worldserver, Entity.RemovalReason.KILLED); - this.discard(); + this.discard(EntityRemoveEvent.Cause.EXPLODE); // CraftBukkit - add Bukkit remove cause + // CraftBukkit start diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityDrowned.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityDrowned.patch deleted file mode 100644 index 80279ce796..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityDrowned.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/net/minecraft/world/entity/monster/EntityDrowned.java -+++ b/net/minecraft/world/entity/monster/EntityDrowned.java -@@ -247,7 +247,7 @@ - - @Override - public void performRangedAttack(EntityLiving entityliving, float f) { -- EntityThrownTrident entitythrowntrident = new EntityThrownTrident(this.level(), this, new ItemStack(Items.TRIDENT)); -+ EntityThrownTrident entitythrowntrident = new EntityThrownTrident(this.level(), this, this.getItemInHand(net.minecraft.world.entity.projectile.ProjectileHelper.getWeaponHoldingHand(this, Items.TRIDENT))); // CraftBukkit - Use Trident in hand like skeletons (SPIGOT-7025) - double d0 = entityliving.getX() - this.getX(); - double d1 = entityliving.getY(0.3333333333333333D) - entitythrowntrident.getY(); - double d2 = entityliving.getZ() - this.getZ(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityEnderman.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityEnderman.patch index b210296b1b..4f24f25981 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityEnderman.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityEnderman.patch @@ -39,7 +39,7 @@ } -@@ -479,9 +495,11 @@ +@@ -466,9 +482,11 @@ if (iblockdata2 != null) { iblockdata2 = Block.updateFromNeighbourShapes(iblockdata2, this.enderman.level(), blockposition); if (this.canPlaceBlock(world, blockposition, iblockdata2, iblockdata, iblockdata1, blockposition1)) { @@ -51,7 +51,7 @@ } } -@@ -520,9 +538,11 @@ +@@ -507,9 +525,11 @@ boolean flag = movingobjectpositionblock.getBlockPos().equals(blockposition); if (iblockdata.is(TagsBlock.ENDERMAN_HOLDABLE) && flag) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityEvoker.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityEvoker.patch index e49d29c823..5a03340201 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityEvoker.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityEvoker.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityEvoker.java +++ b/net/minecraft/world/entity/monster/EntityEvoker.java -@@ -213,7 +213,7 @@ +@@ -212,7 +212,7 @@ worldserver.getScoreboard().addPlayerToTeam(entityvex.getScoreboardName(), scoreboardteam); } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGhast.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGhast.patch index 9fde325519..69f630ae83 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGhast.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGhast.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityGhast.java +++ b/net/minecraft/world/entity/monster/EntityGhast.java -@@ -332,6 +332,8 @@ +@@ -333,6 +333,8 @@ EntityLargeFireball entitylargefireball = new EntityLargeFireball(world, this.ghast, vec3d1.normalize(), this.ghast.getExplosionPower()); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGuardian.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGuardian.patch index b36812b76d..9090b0c463 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGuardian.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGuardian.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityGuardian.java +++ b/net/minecraft/world/entity/monster/EntityGuardian.java -@@ -59,6 +59,7 @@ +@@ -60,6 +60,7 @@ private boolean clientSideTouchedGround; @Nullable public PathfinderGoalRandomStroll randomStrollGoal; @@ -8,7 +8,7 @@ public EntityGuardian(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -74,7 +75,7 @@ +@@ -75,7 +76,7 @@ PathfinderGoalMoveTowardsRestriction pathfindergoalmovetowardsrestriction = new PathfinderGoalMoveTowardsRestriction(this, 1.0D); this.randomStrollGoal = new PathfinderGoalRandomStroll(this, 1.0D, 80); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGuardianElder.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGuardianElder.patch index c708cf101b..a3cce2e704 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGuardianElder.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityGuardianElder.patch @@ -1,11 +1,11 @@ --- a/net/minecraft/world/entity/monster/EntityGuardianElder.java +++ b/net/minecraft/world/entity/monster/EntityGuardianElder.java @@ -67,7 +67,7 @@ - super.customServerAiStep(); + super.customServerAiStep(worldserver); if ((this.tickCount + this.getId()) % 1200 == 0) { MobEffect mobeffect = new MobEffect(MobEffects.DIG_SLOWDOWN, 6000, 2); -- List list = MobEffectUtil.addEffectToPlayersAround((WorldServer) this.level(), this, this.position(), 50.0D, mobeffect, 1200); -+ List list = MobEffectUtil.addEffectToPlayersAround((WorldServer) this.level(), this, this.position(), 50.0D, mobeffect, 1200, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.ATTACK); // CraftBukkit +- List list = MobEffectUtil.addEffectToPlayersAround(worldserver, this, this.position(), 50.0D, mobeffect, 1200); ++ List list = MobEffectUtil.addEffectToPlayersAround(worldserver, this, this.position(), 50.0D, mobeffect, 1200, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.ATTACK); // CraftBukkit list.forEach((entityplayer) -> { entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.GUARDIAN_ELDER_EFFECT, this.isSilent() ? 0.0F : 1.0F)); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityIllagerIllusioner.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityIllagerIllusioner.patch index e16a1cf3f6..6bcb758d38 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityIllagerIllusioner.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityIllagerIllusioner.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityIllagerIllusioner.java +++ b/net/minecraft/world/entity/monster/EntityIllagerIllusioner.java -@@ -217,7 +217,7 @@ +@@ -218,7 +218,7 @@ @Override protected void performSpellCasting() { @@ -9,7 +9,7 @@ } @Nullable -@@ -268,7 +268,7 @@ +@@ -269,7 +269,7 @@ @Override protected void performSpellCasting() { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityIllagerWizard.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityIllagerWizard.patch index 2ec51fd6fe..0b26a80697 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityIllagerWizard.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityIllagerWizard.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityIllagerWizard.java +++ b/net/minecraft/world/entity/monster/EntityIllagerWizard.java -@@ -17,6 +17,10 @@ +@@ -18,6 +18,10 @@ import net.minecraft.world.entity.ai.goal.PathfinderGoal; import net.minecraft.world.level.World; @@ -11,7 +11,7 @@ public abstract class EntityIllagerWizard extends EntityIllagerAbstract { private static final DataWatcherObject DATA_SPELL_CASTING_ID = DataWatcher.defineId(EntityIllagerWizard.class, DataWatcherRegistry.BYTE); -@@ -158,6 +162,11 @@ +@@ -159,6 +163,11 @@ public void tick() { --this.attackWarmupDelay; if (this.attackWarmupDelay == 0) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityPhantom.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityPhantom.patch index 2889edc24d..94a1d84868 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityPhantom.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityPhantom.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/entity/monster/EntityPhantom.java +++ b/net/minecraft/world/entity/monster/EntityPhantom.java -@@ -521,14 +521,14 @@ - List list = EntityPhantom.this.level().getNearbyPlayers(this.attackTargeting, EntityPhantom.this, EntityPhantom.this.getBoundingBox().inflate(16.0D, 64.0D, 16.0D)); +@@ -522,14 +522,14 @@ + List list = worldserver.getNearbyPlayers(this.attackTargeting, EntityPhantom.this, EntityPhantom.this.getBoundingBox().inflate(16.0D, 64.0D, 16.0D)); if (!list.isEmpty()) { - list.sort(Comparator.comparing(Entity::getY).reversed()); @@ -11,7 +11,7 @@ while (iterator.hasNext()) { EntityHuman entityhuman = (EntityHuman) iterator.next(); - if (EntityPhantom.this.canAttack(entityhuman, PathfinderTargetCondition.DEFAULT)) { + if (EntityPhantom.this.canAttack(worldserver, entityhuman, PathfinderTargetCondition.DEFAULT)) { - EntityPhantom.this.setTarget(entityhuman); + EntityPhantom.this.setTarget(entityhuman, org.bukkit.event.entity.EntityTargetEvent.TargetReason.CLOSEST_PLAYER, true); // CraftBukkit - reason return true; diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityPigZombie.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityPigZombie.patch index 6f3cac8bf9..f0a0fd531d 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityPigZombie.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityPigZombie.patch @@ -41,4 +41,4 @@ + // CraftBukkit end } - public static boolean checkZombifiedPiglinSpawnRules(EntityTypes entitytypes, GeneratorAccess generatoraccess, EnumMobSpawn enummobspawn, BlockPosition blockposition, RandomSource randomsource) { + public static boolean checkZombifiedPiglinSpawnRules(EntityTypes entitytypes, GeneratorAccess generatoraccess, EntitySpawnReason entityspawnreason, BlockPosition blockposition, RandomSource randomsource) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityPillager.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityPillager.patch index 5697e18b0f..45b728cf99 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityPillager.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityPillager.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityPillager.java +++ b/net/minecraft/world/entity/monster/EntityPillager.java -@@ -48,6 +48,10 @@ +@@ -50,6 +50,10 @@ import net.minecraft.world.level.World; import net.minecraft.world.level.WorldAccess; @@ -11,7 +11,7 @@ public class EntityPillager extends EntityIllagerAbstract implements ICrossbow, InventoryCarrier { private static final DataWatcherObject IS_CHARGING_CROSSBOW = DataWatcher.defineId(EntityPillager.class, DataWatcherRegistry.BOOLEAN); -@@ -195,7 +199,7 @@ +@@ -198,7 +202,7 @@ ItemStack itemstack1 = this.inventory.addItem(itemstack); if (itemstack1.isEmpty()) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityRavager.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityRavager.patch index a9687a1527..ac3d0c8513 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityRavager.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityRavager.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityRavager.java +++ b/net/minecraft/world/entity/monster/EntityRavager.java -@@ -43,6 +43,10 @@ +@@ -45,6 +45,10 @@ import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; @@ -10,16 +10,16 @@ + public class EntityRavager extends EntityRaider { - private static final Predicate NO_RAVAGER_AND_ALIVE = (entity) -> { -@@ -147,6 +151,11 @@ - Block block = iblockdata.getBlock(); + private static final Predicate ROAR_TARGET_WITH_GRIEFING = (entity) -> { +@@ -161,6 +165,11 @@ + Block block = iblockdata.getBlock(); - if (block instanceof BlockLeaves) { -+ // CraftBukkit start -+ if (!CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, net.minecraft.world.level.block.Blocks.AIR.defaultBlockState())) { -+ continue; -+ } -+ // CraftBukkit end - flag = this.level().destroyBlock(blockposition, true, this) || flag; + if (block instanceof BlockLeaves) { ++ // CraftBukkit start ++ if (!CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, net.minecraft.world.level.block.Blocks.AIR.defaultBlockState())) { ++ continue; ++ } ++ // CraftBukkit end + flag = worldserver.destroyBlock(blockposition, true, this) || flag; + } } - } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityShulker.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityShulker.patch index 14e78b06de..611d16c842 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityShulker.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityShulker.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityShulker.java +++ b/net/minecraft/world/entity/monster/EntityShulker.java -@@ -58,6 +58,12 @@ +@@ -59,6 +59,12 @@ import net.minecraft.world.phys.Vec3D; import org.joml.Vector3f; @@ -13,7 +13,7 @@ public class EntityShulker extends EntityGolem implements VariantHolder>, IMonster { private static final MinecraftKey COVERED_ARMOR_MODIFIER_ID = MinecraftKey.withDefaultNamespace("covered"); -@@ -401,6 +407,14 @@ +@@ -402,6 +408,14 @@ EnumDirection enumdirection = this.findAttachableSurface(blockposition1); if (enumdirection != null) { @@ -28,7 +28,7 @@ this.unRide(); this.setAttachFace(enumdirection); this.playSound(SoundEffects.SHULKER_TELEPORT, 1.0F, 1.0F); -@@ -471,7 +485,7 @@ +@@ -472,7 +486,7 @@ if (entityshulker != null) { entityshulker.setVariant(this.getVariant()); entityshulker.moveTo(vec3d); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySilverfish.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySilverfish.patch index e1f1759175..e2516beaaa 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySilverfish.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySilverfish.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntitySilverfish.java +++ b/net/minecraft/world/entity/monster/EntitySilverfish.java -@@ -30,6 +30,11 @@ +@@ -31,6 +31,11 @@ import net.minecraft.world.level.block.BlockMonsterEggs; import net.minecraft.world.level.block.state.IBlockData; @@ -12,7 +12,7 @@ public class EntitySilverfish extends EntityMonster { @Nullable -@@ -157,6 +162,11 @@ +@@ -160,6 +165,11 @@ Block block = iblockdata.getBlock(); if (block instanceof BlockMonsterEggs) { @@ -21,10 +21,10 @@ + continue; + } + // CraftBukkit end - if (world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { + if (getServerLevel(world).getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { world.destroyBlock(blockposition1, true, this.silverfish); } else { -@@ -226,9 +236,14 @@ +@@ -229,9 +239,14 @@ IBlockData iblockdata = world.getBlockState(blockposition); if (BlockMonsterEggs.isCompatibleHostBlock(iblockdata)) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySkeleton.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySkeleton.patch index 73a2ea0695..ddc3ae31ae 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySkeleton.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySkeleton.patch @@ -1,11 +1,11 @@ --- a/net/minecraft/world/entity/monster/EntitySkeleton.java +++ b/net/minecraft/world/entity/monster/EntitySkeleton.java -@@ -91,7 +91,7 @@ +@@ -99,7 +99,7 @@ + this.level().levelEvent((EntityHuman) null, 1048, this.blockPosition(), 0); + } + +- }); ++ }, org.bukkit.event.entity.EntityTransformEvent.TransformReason.FROZEN, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.FROZEN); // CraftBukkit - add spawn and transform reasons } - protected void doFreezeConversion() { -- this.convertTo(EntityTypes.STRAY, true); -+ this.convertTo(EntityTypes.STRAY, true, org.bukkit.event.entity.EntityTransformEvent.TransformReason.FROZEN, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.FROZEN); // CraftBukkit - add spawn and transform reasons - if (!this.isSilent()) { - this.level().levelEvent((EntityHuman) null, 1048, this.blockPosition(), 0); - } + @Override diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySkeletonAbstract.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySkeletonAbstract.patch index ba4d0f477d..4fceb68c81 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySkeletonAbstract.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySkeletonAbstract.patch @@ -1,23 +1,21 @@ --- a/net/minecraft/world/entity/monster/EntitySkeletonAbstract.java +++ b/net/minecraft/world/entity/monster/EntitySkeletonAbstract.java -@@ -204,8 +204,19 @@ - double d3 = Math.sqrt(d0 * d0 + d2 * d2); +@@ -207,7 +207,17 @@ + World world = this.level(); - entityarrow.shoot(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F, (float) (14 - this.level().getDifficulty().getId() * 4)); -+ // CraftBukkit start -+ org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(this, this.getMainHandItem(), null, entityarrow, net.minecraft.world.EnumHand.MAIN_HAND, 0.8F, true); -+ if (event.isCancelled()) { -+ event.getProjectile().remove(); -+ return; -+ } + if (world instanceof WorldServer worldserver) { +- IProjectile.spawnProjectileUsingShoot(entityarrow, worldserver, itemstack1, d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F, (float) (14 - worldserver.getDifficulty().getId() * 4)); ++ // CraftBukkit start ++ org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(this, this.getMainHandItem(), null, entityarrow, net.minecraft.world.EnumHand.MAIN_HAND, 0.8F, true); ++ if (event.isCancelled()) { ++ event.getProjectile().remove(); ++ return; ++ } + -+ if (event.getProjectile() == entityarrow.getBukkitEntity()) { -+ this.level().addFreshEntity(entityarrow); -+ } -+ // CraftBukkit end - this.playSound(SoundEffects.SKELETON_SHOOT, 1.0F, 1.0F / (this.getRandom().nextFloat() * 0.4F + 0.8F)); -- this.level().addFreshEntity(entityarrow); -+ // this.level().addFreshEntity(entityarrow); // CraftBukkit - moved up - } ++ if (event.getProjectile() == entityarrow.getBukkitEntity()) { ++ IProjectile.spawnProjectileUsingShoot(entityarrow, worldserver, itemstack1, d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F, (float) (14 - worldserver.getDifficulty().getId() * 4)); ++ } ++ // CraftBukkit end + } - protected EntityArrow getArrow(ItemStack itemstack, float f, @Nullable ItemStack itemstack1) { + this.playSound(SoundEffects.SKELETON_SHOOT, 1.0F, 1.0F / (this.getRandom().nextFloat() * 0.4F + 0.8F)); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySlime.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySlime.patch index 5d98d3aefb..73994c5c62 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySlime.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySlime.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/entity/monster/EntitySlime.java +++ b/net/minecraft/world/entity/monster/EntitySlime.java -@@ -45,6 +45,15 @@ - import net.minecraft.world.level.levelgen.SeededRandom; +@@ -47,6 +47,15 @@ import net.minecraft.world.phys.Vec3D; + import net.minecraft.world.scores.ScoreboardTeam; +// CraftBukkit start +import java.util.ArrayList; @@ -16,7 +16,7 @@ public class EntitySlime extends EntityInsentient implements IMonster { private static final DataWatcherObject ID_SIZE = DataWatcher.defineId(EntitySlime.class, DataWatcherRegistry.INT); -@@ -195,11 +204,18 @@ +@@ -197,11 +206,18 @@ @Override public EntityTypes getType() { @@ -36,9 +36,9 @@ int i = this.getSize(); if (!this.level().isClientSide && i > 1 && this.isDeadOrDying()) { -@@ -210,6 +226,19 @@ - int j = i / 2; +@@ -211,18 +227,45 @@ int k = 2 + this.random.nextInt(3); + ScoreboardTeam scoreboardteam = this.getTeam(); + // CraftBukkit start + SlimeSplitEvent event = new SlimeSplitEvent((org.bukkit.entity.Slime) this.getBukkitEntity(), k); @@ -56,19 +56,24 @@ for (int l = 0; l < k; ++l) { float f2 = ((float) (l % 2) - 0.5F) * f1; float f3 = ((float) (l / 2) - 0.5F) * f1; -@@ -225,12 +254,21 @@ - entityslime.setInvulnerable(this.isInvulnerable()); + +- this.convertTo(this.getType(), new ConversionParams(ConversionType.SPLIT_ON_DEATH, false, false, scoreboardteam), EntitySpawnReason.TRIGGERED, (entityslime) -> { ++ EntitySlime converted = this.convertTo(this.getType(), new ConversionParams(ConversionType.SPLIT_ON_DEATH, false, false, scoreboardteam), EntitySpawnReason.TRIGGERED, (entityslime) -> { // CraftBukkit entityslime.setSize(j, true); entityslime.moveTo(this.getX() + (double) f2, this.getY() + 0.5D, this.getZ() + (double) f3, this.random.nextFloat() * 360.0F, 0.0F); -- this.level().addFreshEntity(entityslime); -+ slimes.add(entityslime); // CraftBukkit - } - } +- }); ++ // CraftBukkit start ++ }, null, null); ++ if (converted != null) { ++ slimes.add(converted); ++ } ++ // CraftBukkit end ++ } + // CraftBukkit start + if (CraftEventFactory.callEntityTransformEvent(this, slimes, EntityTransformEvent.TransformReason.SPLIT).isCancelled()) { + super.remove(entity_removalreason, cause); // CraftBukkit - add Bukkit remove cause + return; -+ } + } + for (EntityLiving living : slimes) { + this.level().addFreshEntity(living, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SLIME_SPLIT); // CraftBukkit - SpawnReason + } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityStrider.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityStrider.patch index 53c7c3088b..a17b5b266e 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityStrider.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityStrider.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityStrider.java +++ b/net/minecraft/world/entity/monster/EntityStrider.java -@@ -351,7 +351,14 @@ +@@ -350,7 +350,14 @@ boolean flag2 = flag1; diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityVex.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityVex.patch index 79cc944e85..4f8bf90a96 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityVex.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityVex.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityVex.java +++ b/net/minecraft/world/entity/monster/EntityVex.java -@@ -383,7 +383,7 @@ +@@ -381,7 +381,7 @@ @Override public void start() { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityWitch.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityWitch.patch index 85c27b27c7..d0b562f1f3 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityWitch.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityWitch.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityWitch.java +++ b/net/minecraft/world/entity/monster/EntityWitch.java -@@ -125,7 +125,7 @@ +@@ -126,7 +126,7 @@ PotionContents potioncontents = (PotionContents) itemstack.get(DataComponents.POTION_CONTENTS); if (itemstack.is(Items.POTION) && potioncontents != null) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombie.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombie.patch index e447f1d8e3..1eed7427bf 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombie.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombie.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityZombie.java +++ b/net/minecraft/world/entity/monster/EntityZombie.java -@@ -65,6 +65,15 @@ +@@ -67,6 +67,15 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.IBlockData; @@ -16,7 +16,7 @@ public class EntityZombie extends EntityMonster { private static final MinecraftKey SPEED_MODIFIER_BABY_ID = MinecraftKey.withDefaultNamespace("baby"); -@@ -89,6 +98,7 @@ +@@ -91,6 +100,7 @@ private boolean canBreakDoors; private int inWaterTime; public int conversionTime; @@ -24,7 +24,7 @@ public EntityZombie(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -205,7 +215,10 @@ +@@ -203,7 +213,10 @@ public void tick() { if (!this.level().isClientSide && this.isAlive() && !this.isNoAi()) { if (this.isUnderWaterConverting()) { @@ -36,7 +36,7 @@ if (this.conversionTime < 0) { this.doUnderWaterConversion(); } -@@ -222,6 +235,7 @@ +@@ -220,6 +233,7 @@ } super.tick(); @@ -44,7 +44,7 @@ } @Override -@@ -256,6 +270,7 @@ +@@ -254,6 +268,7 @@ } public void startUnderWaterConversion(int i) { @@ -52,36 +52,65 @@ this.conversionTime = i; this.getEntityData().set(EntityZombie.DATA_DROWNED_CONVERSION_ID, true); } -@@ -269,11 +284,15 @@ +@@ -267,26 +282,39 @@ } protected void convertToZombieType(EntityTypes entitytypes) { -- EntityZombie entityzombie = (EntityZombie) this.convertTo(entitytypes, true); -+ EntityZombie entityzombie = (EntityZombie) this.convertTo(entitytypes, true, EntityTransformEvent.TransformReason.DROWNED, CreatureSpawnEvent.SpawnReason.DROWNED); - - if (entityzombie != null) { +- this.convertTo(entitytypes, ConversionParams.single(this, true, true), (entityzombie) -> { ++ EntityZombie converted = this.convertTo(entitytypes, ConversionParams.single(this, true, true), (entityzombie) -> { // CraftBukkit entityzombie.handleAttributes(entityzombie.level().getCurrentDifficultyAt(entityzombie.blockPosition()).getSpecialMultiplier()); - entityzombie.setCanBreakDoors(entityzombie.supportsBreakDoorGoal() && this.canBreakDoors()); -+ // CraftBukkit start - SPIGOT-5208: End conversion to stop event spam -+ } else { -+ ((Zombie) getBukkitEntity()).setConversionTime(-1); -+ // CraftBukkit end - } - +- }); ++ // CraftBukkit start ++ }, EntityTransformEvent.TransformReason.DROWNED, CreatureSpawnEvent.SpawnReason.DROWNED); ++ if (converted == null) { ++ ((Zombie) getBukkitEntity()).setConversionTime(-1); // CraftBukkit - SPIGOT-5208: End conversion to stop event spam ++ } ++ // CraftBukkit end } -@@ -312,9 +331,9 @@ - if (EntityPositionTypes.isSpawnPositionOk(entitytypes, this.level(), blockposition) && EntityPositionTypes.checkSpawnRules(entitytypes, worldserver, EnumMobSpawn.REINFORCEMENT, blockposition, this.level().random)) { + + @VisibleForTesting + public boolean convertVillagerToZombieVillager(WorldServer worldserver, EntityVillager entityvillager) { ++ // CraftBukkit start ++ return convertVillagerToZombieVillager(worldserver, entityvillager, this.blockPosition(), this.isSilent(), EntityTransformEvent.TransformReason.INFECTION, CreatureSpawnEvent.SpawnReason.INFECTION) != null; ++ } ++ ++ public static EntityZombieVillager convertVillagerToZombieVillager(WorldServer worldserver, EntityVillager entityvillager, net.minecraft.core.BlockPosition blockPosition, boolean silent, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) { ++ // CraftBukkit end + EntityZombieVillager entityzombievillager = (EntityZombieVillager) entityvillager.convertTo(EntityTypes.ZOMBIE_VILLAGER, ConversionParams.single(entityvillager, true, true), (entityzombievillager1) -> { + entityzombievillager1.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entityzombievillager1.blockPosition()), EntitySpawnReason.CONVERSION, new EntityZombie.GroupDataZombie(false, true)); + entityzombievillager1.setVillagerData(entityvillager.getVillagerData()); + entityzombievillager1.setGossips((NBTBase) entityvillager.getGossips().store(DynamicOpsNBT.INSTANCE)); + entityzombievillager1.setTradeOffers(entityvillager.getOffers().copy()); + entityzombievillager1.setVillagerXp(entityvillager.getVillagerXp()); +- if (!this.isSilent()) { +- worldserver.levelEvent((EntityHuman) null, 1026, this.blockPosition(), 0); ++ // CraftBukkit start ++ if (!silent) { ++ worldserver.levelEvent((EntityHuman) null, 1026, blockPosition, 0); + } + +- }); ++ }, transformReason, spawnReason); + +- return entityzombievillager != null; ++ return entityzombievillager; ++ // CraftBukkit end + } + + protected boolean isSunSensitive() { +@@ -324,9 +352,9 @@ + if (EntityPositionTypes.isSpawnPositionOk(entitytypes, worldserver, blockposition) && EntityPositionTypes.checkSpawnRules(entitytypes, worldserver, EntitySpawnReason.REINFORCEMENT, blockposition, worldserver.random)) { entityzombie.setPos((double) i1, (double) j1, (double) k1); - if (!this.level().hasNearbyAlivePlayer((double) i1, (double) j1, (double) k1, 7.0D) && this.level().isUnobstructed(entityzombie) && this.level().noCollision((Entity) entityzombie) && !this.level().containsAnyLiquid(entityzombie.getBoundingBox())) { + if (!worldserver.hasNearbyAlivePlayer((double) i1, (double) j1, (double) k1, 7.0D) && worldserver.isUnobstructed(entityzombie) && worldserver.noCollision((Entity) entityzombie) && (entityzombie.canSpawnInLiquids() || !worldserver.containsAnyLiquid(entityzombie.getBoundingBox()))) { - entityzombie.setTarget(entityliving); + entityzombie.setTarget(entityliving, EntityTargetEvent.TargetReason.REINFORCEMENT_TARGET, true); // CraftBukkit - entityzombie.finalizeSpawn(worldserver, this.level().getCurrentDifficultyAt(entityzombie.blockPosition()), EnumMobSpawn.REINFORCEMENT, (GroupDataEntity) null); + entityzombie.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entityzombie.blockPosition()), EntitySpawnReason.REINFORCEMENT, (GroupDataEntity) null); - worldserver.addFreshEntityWithPassengers(entityzombie); + worldserver.addFreshEntityWithPassengers(entityzombie, CreatureSpawnEvent.SpawnReason.REINFORCEMENTS); // CraftBukkit AttributeModifiable attributemodifiable = this.getAttribute(GenericAttributes.SPAWN_REINFORCEMENTS_CHANCE); AttributeModifier attributemodifier = attributemodifiable.getModifier(EntityZombie.REINFORCEMENT_CALLER_CHARGE_ID); double d0 = attributemodifier != null ? attributemodifier.amount() : 0.0D; -@@ -340,7 +359,14 @@ +@@ -352,7 +380,14 @@ float f = this.level().getCurrentDifficultyAt(this.blockPosition()).getEffectiveDifficulty(); if (this.getMainHandItem().isEmpty() && this.isOnFire() && this.random.nextFloat() < f * 0.3F) { @@ -97,50 +126,17 @@ } } -@@ -415,8 +441,17 @@ - if (worldserver.getDifficulty() != EnumDifficulty.HARD && this.random.nextBoolean()) { - return flag; - } -+ // CraftBukkit start -+ flag = zombifyVillager(worldserver, entityvillager, this.blockPosition(), this.isSilent(), CreatureSpawnEvent.SpawnReason.INFECTION) == null; -+ } - -- EntityZombieVillager entityzombievillager = (EntityZombieVillager) entityvillager.convertTo(EntityTypes.ZOMBIE_VILLAGER, false); -+ return flag; -+ } -+ -+ public static EntityZombieVillager zombifyVillager(WorldServer worldserver, EntityVillager entityvillager, net.minecraft.core.BlockPosition blockPosition, boolean silent, CreatureSpawnEvent.SpawnReason spawnReason) { -+ { -+ EntityZombieVillager entityzombievillager = (EntityZombieVillager) entityvillager.convertTo(EntityTypes.ZOMBIE_VILLAGER, false, EntityTransformEvent.TransformReason.INFECTION, spawnReason); -+ // CraftBukkit end - - if (entityzombievillager != null) { - entityzombievillager.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entityzombievillager.blockPosition()), EnumMobSpawn.CONVERSION, new EntityZombie.GroupDataZombie(false, true)); -@@ -424,15 +459,17 @@ - entityzombievillager.setGossips((NBTBase) entityvillager.getGossips().store(DynamicOpsNBT.INSTANCE)); - entityzombievillager.setTradeOffers(entityvillager.getOffers().copy()); - entityzombievillager.setVillagerXp(entityvillager.getVillagerXp()); -- if (!this.isSilent()) { -- worldserver.levelEvent((EntityHuman) null, 1026, this.blockPosition(), 0); -+ // CraftBukkit start -+ if (!silent) { -+ worldserver.levelEvent((EntityHuman) null, 1026, blockPosition, 0); - } - -- flag = false; -+ // flag = false; - } -- } - -- return flag; -+ return entityzombievillager; -+ } -+ // CraftBukkit end - } +@@ -385,7 +420,7 @@ @Override -@@ -483,7 +520,7 @@ - entitychicken1.finalizeSpawn(worldaccess, difficultydamagescaler, EnumMobSpawn.JOCKEY, (GroupDataEntity) null); + public EntityTypes getType() { +- return super.getType(); ++ return (EntityTypes) super.getType(); // CraftBukkit - decompile error + } + + protected boolean canSpawnInLiquids() { +@@ -496,7 +531,7 @@ + entitychicken1.finalizeSpawn(worldaccess, difficultydamagescaler, EntitySpawnReason.JOCKEY, (GroupDataEntity) null); entitychicken1.setChickenJockey(true); this.startRiding(entitychicken1); - worldaccess.addFreshEntity(entitychicken1); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombieHusk.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombieHusk.patch index dab22fcd43..ae2ac43bcf 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombieHusk.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombieHusk.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityZombieHusk.java +++ b/net/minecraft/world/entity/monster/EntityZombieHusk.java -@@ -58,7 +58,7 @@ +@@ -59,7 +59,7 @@ if (flag && this.getMainHandItem().isEmpty() && entity instanceof EntityLiving) { float f = this.level().getCurrentDifficultyAt(this.blockPosition()).getEffectiveDifficulty(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombieVillager.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombieVillager.patch index bf1c47dbef..96e3b9c0e2 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombieVillager.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityZombieVillager.patch @@ -1,11 +1,12 @@ --- a/net/minecraft/world/entity/monster/EntityZombieVillager.java +++ b/net/minecraft/world/entity/monster/EntityZombieVillager.java -@@ -51,6 +51,13 @@ +@@ -52,6 +52,14 @@ import net.minecraft.world.level.block.state.IBlockData; import org.slf4j.Logger; +// CraftBukkit start +import net.minecraft.server.MinecraftServer; ++import net.minecraft.world.entity.npc.EntityVillager; +import org.bukkit.entity.ZombieVillager; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityTransformEvent; @@ -14,7 +15,7 @@ public class EntityZombieVillager extends EntityZombie implements VillagerDataHolder { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -68,6 +75,7 @@ +@@ -69,6 +77,7 @@ @Nullable private MerchantRecipeList tradeOffers; private int villagerXp; @@ -22,7 +23,7 @@ public EntityZombieVillager(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -86,7 +94,7 @@ +@@ -87,7 +96,7 @@ @Override public void addAdditionalSaveData(NBTTagCompound nbttagcompound) { super.addAdditionalSaveData(nbttagcompound); @@ -31,7 +32,7 @@ Logger logger = EntityZombieVillager.LOGGER; Objects.requireNonNull(logger); -@@ -121,7 +129,7 @@ +@@ -122,7 +131,7 @@ } if (nbttagcompound.contains("Offers")) { @@ -40,7 +41,7 @@ Logger logger1 = EntityZombieVillager.LOGGER; Objects.requireNonNull(logger1); -@@ -148,6 +156,10 @@ +@@ -149,6 +158,10 @@ public void tick() { if (!this.level().isClientSide && this.isAlive() && this.isConverting()) { int i = this.getConversionProgress(); @@ -51,7 +52,7 @@ this.villagerConversionTime -= i; if (this.villagerConversionTime <= 0) { -@@ -156,6 +168,7 @@ +@@ -157,6 +170,7 @@ } super.tick(); @@ -59,7 +60,7 @@ } @Override -@@ -196,8 +209,10 @@ +@@ -197,8 +211,10 @@ this.conversionStarter = uuid; this.villagerConversionTime = i; this.getEntityData().set(EntityZombieVillager.DATA_CONVERTING_ID, true); @@ -72,29 +73,20 @@ this.level().broadcastEntityEvent(this, (byte) 16); } -@@ -214,12 +229,20 @@ +@@ -215,10 +231,11 @@ } private void finishConversion(WorldServer worldserver) { -- EntityVillager entityvillager = (EntityVillager) this.convertTo(EntityTypes.VILLAGER, false); -+ // CraftBukkit start -+ EntityVillager entityvillager = (EntityVillager) this.convertTo(EntityTypes.VILLAGER, false, EntityTransformEvent.TransformReason.CURED, CreatureSpawnEvent.SpawnReason.CURED); -+ if (entityvillager == null) { -+ ((ZombieVillager) getBukkitEntity()).setConversionTime(-1); // SPIGOT-5208: End conversion to stop event spam -+ return; -+ } -+ // CraftBukkit end - - if (entityvillager != null) { -+ this.forceDrops = true; // CraftBukkit - Iterator iterator = this.dropPreservedEquipment((itemstack) -> { +- this.convertTo(EntityTypes.VILLAGER, ConversionParams.single(this, false, false), (entityvillager) -> { ++ EntityVillager converted = this.convertTo(EntityTypes.VILLAGER, ConversionParams.single(this, false, false), (entityvillager) -> { // CraftBukkit + Iterator iterator = this.dropPreservedEquipment(worldserver, (itemstack) -> { return !EnchantmentManager.has(itemstack, EnchantmentEffectComponents.PREVENT_ARMOR_CHANGE); }).iterator(); + this.forceDrops = false; // CraftBukkit while (iterator.hasNext()) { EnumItemSlot enumitemslot = (EnumItemSlot) iterator.next(); -@@ -249,7 +272,7 @@ +@@ -248,12 +265,16 @@ } } @@ -103,3 +95,14 @@ if (!this.isSilent()) { worldserver.levelEvent((EntityHuman) null, 1027, this.blockPosition(), 0); } +- +- }); ++ // CraftBukkit start ++ }, EntityTransformEvent.TransformReason.CURED, CreatureSpawnEvent.SpawnReason.CURED); ++ if (converted == null) { ++ ((ZombieVillager) getBukkitEntity()).setConversionTime(-1); // SPIGOT-5208: End conversion to stop event spam ++ } ++ // CraftBukkit end + } + + @VisibleForTesting diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/creaking/CreakingTransient.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/creaking/CreakingTransient.patch new file mode 100644 index 0000000000..bbce5b442c --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/creaking/CreakingTransient.patch @@ -0,0 +1,20 @@ +--- a/net/minecraft/world/entity/monster/creaking/CreakingTransient.java ++++ b/net/minecraft/world/entity/monster/creaking/CreakingTransient.java +@@ -97,7 +97,7 @@ + } + } + +- this.setRemoved(Entity.RemovalReason.DISCARDED); ++ this.setRemoved(Entity.RemovalReason.DISCARDED, null); // CraftBukkit - add Bukkit remove cause + return; + } + } +@@ -149,7 +149,7 @@ + } + } + +- this.remove(Entity.RemovalReason.DISCARDED); ++ this.remove(Entity.RemovalReason.DISCARDED, null); // CraftBukkit - add Bukkit remove cause + } + + @Override diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/piglin/EntityPiglin.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/piglin/EntityPiglin.patch index 74c59c4253..a18f0f5845 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/piglin/EntityPiglin.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/piglin/EntityPiglin.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/piglin/EntityPiglin.java +++ b/net/minecraft/world/entity/monster/piglin/EntityPiglin.java -@@ -54,6 +54,18 @@ +@@ -57,6 +57,18 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.IBlockData; @@ -19,7 +19,7 @@ public class EntityPiglin extends EntityPiglinAbstract implements ICrossbow, InventoryCarrier { private static final DataWatcherObject DATA_BABY_ID = DataWatcher.defineId(EntityPiglin.class, DataWatcherRegistry.BOOLEAN); -@@ -73,6 +85,10 @@ +@@ -76,6 +88,10 @@ public boolean cannotHunt; protected static final ImmutableList>> SENSOR_TYPES = ImmutableList.of(SensorType.NEAREST_LIVING_ENTITIES, SensorType.NEAREST_PLAYERS, SensorType.NEAREST_ITEMS, SensorType.HURT_BY, SensorType.PIGLIN_SPECIFIC_SENSOR); protected static final ImmutableList> MEMORY_TYPES = ImmutableList.of(MemoryModuleType.LOOK_TARGET, MemoryModuleType.DOORS_TO_CLOSE, MemoryModuleType.NEAREST_LIVING_ENTITIES, MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, MemoryModuleType.NEAREST_VISIBLE_PLAYER, MemoryModuleType.NEAREST_VISIBLE_ATTACKABLE_PLAYER, MemoryModuleType.NEAREST_VISIBLE_ADULT_PIGLINS, MemoryModuleType.NEARBY_ADULT_PIGLINS, MemoryModuleType.NEAREST_VISIBLE_WANTED_ITEM, MemoryModuleType.ITEM_PICKUP_COOLDOWN_TICKS, MemoryModuleType.HURT_BY, MemoryModuleType.HURT_BY_ENTITY, new MemoryModuleType[]{MemoryModuleType.WALK_TARGET, MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE, MemoryModuleType.ATTACK_TARGET, MemoryModuleType.ATTACK_COOLING_DOWN, MemoryModuleType.INTERACTION_TARGET, MemoryModuleType.PATH, MemoryModuleType.ANGRY_AT, MemoryModuleType.UNIVERSAL_ANGER, MemoryModuleType.AVOID_TARGET, MemoryModuleType.ADMIRING_ITEM, MemoryModuleType.TIME_TRYING_TO_REACH_ADMIRE_ITEM, MemoryModuleType.ADMIRING_DISABLED, MemoryModuleType.DISABLE_WALK_TO_ADMIRE_ITEM, MemoryModuleType.CELEBRATE_LOCATION, MemoryModuleType.DANCING, MemoryModuleType.HUNTED_RECENTLY, MemoryModuleType.NEAREST_VISIBLE_BABY_HOGLIN, MemoryModuleType.NEAREST_VISIBLE_NEMESIS, MemoryModuleType.NEAREST_VISIBLE_ZOMBIFIED, MemoryModuleType.RIDE_TARGET, MemoryModuleType.VISIBLE_ADULT_PIGLIN_COUNT, MemoryModuleType.VISIBLE_ADULT_HOGLIN_COUNT, MemoryModuleType.NEAREST_VISIBLE_HUNTABLE_HOGLIN, MemoryModuleType.NEAREST_TARGETABLE_PLAYER_NOT_WEARING_GOLD, MemoryModuleType.NEAREST_PLAYER_HOLDING_WANTED_ITEM, MemoryModuleType.ATE_RECENTLY, MemoryModuleType.NEAREST_REPELLENT}); @@ -30,7 +30,7 @@ public EntityPiglin(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -91,6 +107,14 @@ +@@ -94,6 +110,14 @@ } this.writeInventoryToTag(nbttagcompound, this.registryAccess()); @@ -45,18 +45,18 @@ } @Override -@@ -99,6 +123,10 @@ +@@ -102,6 +126,10 @@ this.setBaby(nbttagcompound.getBoolean("IsBaby")); this.setCannotHunt(nbttagcompound.getBoolean("CannotHunt")); this.readInventoryFromTag(nbttagcompound, this.registryAccess()); + // CraftBukkit start -+ this.allowedBarterItems = nbttagcompound.getList("Bukkit.BarterList", 8).stream().map(NBTBase::getAsString).map(MinecraftKey::tryParse).map(BuiltInRegistries.ITEM::get).collect(Collectors.toCollection(HashSet::new)); -+ this.interestItems = nbttagcompound.getList("Bukkit.InterestList", 8).stream().map(NBTBase::getAsString).map(MinecraftKey::tryParse).map(BuiltInRegistries.ITEM::get).collect(Collectors.toCollection(HashSet::new)); ++ this.allowedBarterItems = nbttagcompound.getList("Bukkit.BarterList", 8).stream().map(NBTBase::getAsString).map(MinecraftKey::tryParse).map(BuiltInRegistries.ITEM::getValue).collect(Collectors.toCollection(HashSet::new)); ++ this.interestItems = nbttagcompound.getList("Bukkit.InterestList", 8).stream().map(NBTBase::getAsString).map(MinecraftKey::tryParse).map(BuiltInRegistries.ITEM::getValue).collect(Collectors.toCollection(HashSet::new)); + // CraftBukkit end } @VisibleForDebug -@@ -216,7 +244,7 @@ +@@ -221,7 +249,7 @@ @Override public BehaviorController getBrain() { @@ -65,7 +65,7 @@ } @Override -@@ -349,7 +377,7 @@ +@@ -366,7 +394,7 @@ } protected void holdInOffHand(ItemStack itemstack) { @@ -74,7 +74,7 @@ this.setItemSlot(EnumItemSlot.OFFHAND, itemstack); this.setGuaranteedDrop(EnumItemSlot.OFFHAND); } else { -@@ -375,8 +403,8 @@ +@@ -392,8 +420,8 @@ if (EnchantmentManager.has(itemstack1, EnchantmentEffectComponents.PREVENT_ARMOR_CHANGE)) { return false; } else { @@ -83,9 +83,9 @@ + boolean flag = PiglinAI.isLovedItem(itemstack, this) || itemstack.is(Items.CROSSBOW); // CraftBukkit + boolean flag1 = PiglinAI.isLovedItem(itemstack1, this) || itemstack1.is(Items.CROSSBOW); // CraftBukkit - return flag && !flag1 ? true : (!flag && flag1 ? false : (this.isAdult() && !itemstack.is(Items.CROSSBOW) && itemstack1.is(Items.CROSSBOW) ? false : super.canReplaceCurrentItem(itemstack, itemstack1))); + return flag && !flag1 ? true : (!flag && flag1 ? false : (this.isAdult() && !itemstack.is(Items.CROSSBOW) && itemstack1.is(Items.CROSSBOW) ? false : super.canReplaceCurrentItem(itemstack, itemstack1, enumitemslot))); } -@@ -405,7 +433,7 @@ +@@ -422,7 +450,7 @@ @Override protected SoundEffect getAmbientSound() { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/piglin/EntityPiglinAbstract.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/piglin/EntityPiglinAbstract.patch index 0df483cf7f..85d6ba91eb 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/piglin/EntityPiglinAbstract.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/piglin/EntityPiglinAbstract.patch @@ -1,11 +1,11 @@ --- a/net/minecraft/world/entity/monster/piglin/EntityPiglinAbstract.java +++ b/net/minecraft/world/entity/monster/piglin/EntityPiglinAbstract.java -@@ -94,7 +94,7 @@ +@@ -102,7 +102,7 @@ + protected void finishConversion(WorldServer worldserver) { + this.convertTo(EntityTypes.ZOMBIFIED_PIGLIN, ConversionParams.single(this, true, true), (entitypigzombie) -> { + entitypigzombie.addEffect(new MobEffect(MobEffects.CONFUSION, 200, 0)); +- }); ++ }, org.bukkit.event.entity.EntityTransformEvent.TransformReason.PIGLIN_ZOMBIFIED, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.PIGLIN_ZOMBIFIED); // CraftBukkit - add spawn and transform reasons } - protected void finishConversion(WorldServer worldserver) { -- EntityPigZombie entitypigzombie = (EntityPigZombie) this.convertTo(EntityTypes.ZOMBIFIED_PIGLIN, true); -+ EntityPigZombie entitypigzombie = (EntityPigZombie) this.convertTo(EntityTypes.ZOMBIFIED_PIGLIN, true, org.bukkit.event.entity.EntityTransformEvent.TransformReason.PIGLIN_ZOMBIFIED, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.PIGLIN_ZOMBIFIED); // CraftBukkit - add spawn and transform reasons - - if (entitypigzombie != null) { - entitypigzombie.addEffect(new MobEffect(MobEffects.CONFUSION, 200, 0)); + public boolean isAdult() { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/piglin/PiglinAI.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/piglin/PiglinAI.patch index 3150aa5f21..26aa77840c 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/piglin/PiglinAI.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/piglin/PiglinAI.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/piglin/PiglinAI.java +++ b/net/minecraft/world/entity/monster/piglin/PiglinAI.java -@@ -74,6 +74,14 @@ +@@ -72,6 +72,14 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParameters; import net.minecraft.world.phys.Vec3D; @@ -15,7 +15,7 @@ public class PiglinAI { public static final int REPELLENT_DETECTION_RANGE_HORIZONTAL = 8; -@@ -164,7 +172,8 @@ +@@ -166,7 +174,8 @@ } private static void initRideHoglinActivity(BehaviorController behaviorcontroller) { @@ -25,7 +25,7 @@ return true; }), 1)).build())), BehaviorStopRiding.create(8, PiglinAI::wantsToStopRiding)), MemoryModuleType.RIDE_TARGET); } -@@ -174,7 +183,7 @@ +@@ -176,7 +185,7 @@ } private static BehaviorGateSingle createIdleLookBehaviors() { @@ -34,7 +34,7 @@ } private static BehaviorGateSingle createIdleMovementBehaviors() { -@@ -195,13 +204,13 @@ +@@ -197,13 +206,13 @@ protected static void updateActivity(EntityPiglin entitypiglin) { BehaviorController behaviorcontroller = entitypiglin.getBrain(); @@ -51,7 +51,7 @@ Objects.requireNonNull(entitypiglin); optional.ifPresent(entitypiglin::makeSound); -@@ -233,23 +242,27 @@ +@@ -235,23 +244,27 @@ stopWalking(entitypiglin); ItemStack itemstack; @@ -74,17 +74,17 @@ - if (isLovedItem(itemstack)) { + if (isLovedItem(itemstack, entitypiglin)) { // CraftBukkit - Changes to allow for custom payment in bartering entitypiglin.getBrain().eraseMemory(MemoryModuleType.TIME_TRYING_TO_REACH_ADMIRE_ITEM); - holdInOffhand(entitypiglin, itemstack); + holdInOffhand(worldserver, entitypiglin, itemstack); admireGoldItem(entitypiglin); } else if (isFood(itemstack) && !hasEatenRecently(entitypiglin)) { eat(entitypiglin); } else { -- boolean flag = !entitypiglin.equipItemIfPossible(itemstack).equals(ItemStack.EMPTY); -+ boolean flag = !entitypiglin.equipItemIfPossible(itemstack, entityitem).equals(ItemStack.EMPTY); // CraftBukkit +- boolean flag = !entitypiglin.equipItemIfPossible(worldserver, itemstack).equals(ItemStack.EMPTY); ++ boolean flag = !entitypiglin.equipItemIfPossible(worldserver, itemstack, entityitem).equals(ItemStack.EMPTY); // CraftBukkit if (!flag) { putInInventory(entitypiglin, itemstack); -@@ -270,7 +283,7 @@ +@@ -272,7 +285,7 @@ ItemStack itemstack1 = itemstack.split(1); if (itemstack.isEmpty()) { @@ -93,7 +93,7 @@ } else { entityitem.setItem(itemstack); } -@@ -285,9 +298,14 @@ +@@ -287,9 +300,14 @@ boolean flag1; if (entitypiglin.isAdult()) { @@ -108,9 +108,9 @@ + } + // CraftBukkit end } else if (!flag1) { - boolean flag2 = !entitypiglin.equipItemIfPossible(itemstack).isEmpty(); + boolean flag2 = !entitypiglin.equipItemIfPossible(worldserver, itemstack).isEmpty(); -@@ -300,7 +318,7 @@ +@@ -302,7 +320,7 @@ if (!flag1) { ItemStack itemstack1 = entitypiglin.getMainHandItem(); @@ -119,7 +119,7 @@ putInInventory(entitypiglin, itemstack1); } else { throwItems(entitypiglin, Collections.singletonList(itemstack1)); -@@ -377,7 +395,7 @@ +@@ -379,7 +397,7 @@ return false; } else if (isAdmiringDisabled(entitypiglin) && entitypiglin.getBrain().hasMemoryValue(MemoryModuleType.ATTACK_TARGET)) { return false; @@ -128,7 +128,7 @@ return isNotHoldingLovedItemInOffHand(entitypiglin); } else { boolean flag = entitypiglin.canAddToInventory(itemstack); -@@ -386,6 +404,12 @@ +@@ -388,6 +406,12 @@ } } @@ -141,7 +141,7 @@ protected static boolean isLovedItem(ItemStack itemstack) { return itemstack.is(TagsItem.PIGLIN_LOVED); } -@@ -479,7 +503,7 @@ +@@ -481,7 +505,7 @@ } protected static boolean canAdmire(EntityPiglin entitypiglin, ItemStack itemstack) { @@ -149,8 +149,8 @@ + return !isAdmiringDisabled(entitypiglin) && !isAdmiringItem(entitypiglin) && entitypiglin.isAdult() && isBarterCurrency(itemstack, entitypiglin); // CraftBukkit } - protected static void wasHurtBy(EntityPiglin entitypiglin, EntityLiving entityliving) { -@@ -736,6 +760,12 @@ + protected static void wasHurtBy(WorldServer worldserver, EntityPiglin entitypiglin, EntityLiving entityliving) { +@@ -735,6 +759,12 @@ return entitypiglin.getBrain().hasMemoryValue(MemoryModuleType.ADMIRING_ITEM); } @@ -163,7 +163,7 @@ private static boolean isBarterCurrency(ItemStack itemstack) { return itemstack.is(PiglinAI.BARTERING_ITEM); } -@@ -773,7 +803,7 @@ +@@ -772,7 +802,7 @@ } private static boolean isNotHoldingLovedItemInOffHand(EntityPiglin entitypiglin) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/warden/Warden.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/warden/Warden.patch index 385070ba17..45b48afff7 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/warden/Warden.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/warden/Warden.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/warden/Warden.java +++ b/net/minecraft/world/entity/monster/warden/Warden.java -@@ -372,7 +372,7 @@ +@@ -375,7 +375,7 @@ @Override public BehaviorController getBrain() { @@ -9,7 +9,7 @@ } @Override -@@ -409,7 +409,7 @@ +@@ -412,7 +412,7 @@ public static void applyDarknessAround(WorldServer worldserver, Vec3D vec3d, @Nullable Entity entity, int i) { MobEffect mobeffect = new MobEffect(MobEffects.DARKNESS, 260, 0, false, false); @@ -18,7 +18,7 @@ } @Override -@@ -544,7 +544,7 @@ +@@ -547,7 +547,7 @@ public void setAttackTarget(EntityLiving entityliving) { this.getBrain().eraseMemory(MemoryModuleType.ROAR_TARGET); @@ -27,7 +27,7 @@ this.getBrain().eraseMemory(MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE); SonicBoom.setCooldown(this, 200); } -@@ -579,12 +579,12 @@ +@@ -582,12 +582,12 @@ @Override protected NavigationAbstract createNavigation(World world) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/npc/EntityVillager.patch b/paper-server/nms-patches/net/minecraft/world/entity/npc/EntityVillager.patch index a10feb4fc9..0f03f2ba65 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/npc/EntityVillager.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/npc/EntityVillager.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/npc/EntityVillager.java +++ b/net/minecraft/world/entity/npc/EntityVillager.java -@@ -92,6 +92,15 @@ +@@ -93,6 +93,15 @@ import net.minecraft.world.phys.AxisAlignedBB; import org.slf4j.Logger; @@ -25,7 +25,7 @@ } @Override -@@ -233,7 +242,7 @@ +@@ -235,7 +244,7 @@ this.increaseProfessionLevelOnUpdate = false; } @@ -34,7 +34,7 @@ } } -@@ -363,7 +372,13 @@ +@@ -360,7 +369,13 @@ while (iterator.hasNext()) { MerchantRecipe merchantrecipe = (MerchantRecipe) iterator.next(); @@ -49,7 +49,7 @@ } this.resendOffersToTradingPlayer(); -@@ -432,7 +447,13 @@ +@@ -429,7 +444,13 @@ while (iterator.hasNext()) { MerchantRecipe merchantrecipe = (MerchantRecipe) iterator.next(); @@ -64,7 +64,7 @@ } } -@@ -492,7 +513,7 @@ +@@ -489,7 +510,7 @@ @Override public void addAdditionalSaveData(NBTTagCompound nbttagcompound) { super.addAdditionalSaveData(nbttagcompound); @@ -73,7 +73,7 @@ Logger logger = EntityVillager.LOGGER; Objects.requireNonNull(logger); -@@ -515,7 +536,7 @@ +@@ -512,7 +533,7 @@ public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { super.readAdditionalSaveData(nbttagcompound); if (nbttagcompound.contains("VillagerData", 10)) { @@ -82,33 +82,25 @@ Logger logger = EntityVillager.LOGGER; Objects.requireNonNull(logger); -@@ -828,9 +849,14 @@ - } - - entitywitch.setPersistenceRequired(); -- worldserver.addFreshEntityWithPassengers(entitywitch); -+ // CraftBukkit start -+ if (CraftEventFactory.callEntityTransformEvent(this, entitywitch, EntityTransformEvent.TransformReason.LIGHTNING).isCancelled()) { -+ return; -+ } -+ worldserver.addFreshEntityWithPassengers(entitywitch, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING); -+ // CraftBukkit end +@@ -808,7 +829,7 @@ + entitywitch1.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entitywitch1.blockPosition()), EntitySpawnReason.CONVERSION, (GroupDataEntity) null); + entitywitch1.setPersistenceRequired(); this.releaseAllPois(); -- this.discard(); -+ this.discard(EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - add Bukkit remove cause - } else { +- }); ++ }, EntityTransformEvent.TransformReason.LIGHTNING, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.LIGHTNING); // CraftBukkit + + if (entitywitch == null) { super.thunderHit(worldserver, entitylightning); - } -@@ -927,7 +953,7 @@ - }).limit(5L).collect(Collectors.toList()); +@@ -906,7 +927,7 @@ + }).limit(5L).toList(); if (list1.size() >= j) { -- if (!SpawnUtil.trySpawnMob(EntityTypes.IRON_GOLEM, EnumMobSpawn.MOB_SUMMONED, worldserver, this.blockPosition(), 10, 8, 6, SpawnUtil.a.LEGACY_IRON_GOLEM).isEmpty()) { -+ if (!SpawnUtil.trySpawnMob(EntityTypes.IRON_GOLEM, EnumMobSpawn.MOB_SUMMONED, worldserver, this.blockPosition(), 10, 8, 6, SpawnUtil.a.LEGACY_IRON_GOLEM, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.VILLAGE_DEFENSE).isEmpty()) { // CraftBukkit +- if (!SpawnUtil.trySpawnMob(EntityTypes.IRON_GOLEM, EntitySpawnReason.MOB_SUMMONED, worldserver, this.blockPosition(), 10, 8, 6, SpawnUtil.a.LEGACY_IRON_GOLEM).isEmpty()) { ++ if (!SpawnUtil.trySpawnMob(EntityTypes.IRON_GOLEM, EntitySpawnReason.MOB_SUMMONED, worldserver, this.blockPosition(), 10, 8, 6, SpawnUtil.a.LEGACY_IRON_GOLEM, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.VILLAGE_DEFENSE).isEmpty()) { // CraftBukkit list.forEach(SensorGolemLastSeen::golemDetected); } } -@@ -984,7 +1010,7 @@ +@@ -963,7 +984,7 @@ @Override public void startSleeping(BlockPosition blockposition) { super.startSleeping(blockposition); @@ -117,7 +109,7 @@ this.brain.eraseMemory(MemoryModuleType.WALK_TARGET); this.brain.eraseMemory(MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE); } -@@ -992,7 +1018,7 @@ +@@ -971,7 +992,7 @@ @Override public void stopSleeping() { super.stopSleeping(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/npc/EntityVillagerTrader.patch b/paper-server/nms-patches/net/minecraft/world/entity/npc/EntityVillagerTrader.patch index 0c1a8c8083..24ade5e534 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/npc/EntityVillagerTrader.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/npc/EntityVillagerTrader.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/npc/EntityVillagerTrader.java +++ b/net/minecraft/world/entity/npc/EntityVillagerTrader.java -@@ -47,6 +47,14 @@ +@@ -48,6 +48,14 @@ import net.minecraft.world.phys.Vec3D; import org.apache.commons.lang3.tuple.Pair; @@ -12,10 +12,10 @@ +import org.bukkit.event.entity.VillagerAcquireTradeEvent; +// CraftBukkit end + - public class EntityVillagerTrader extends EntityVillagerAbstract { + public class EntityVillagerTrader extends EntityVillagerAbstract implements Consumable.b { private static final int NUMBER_OF_TRADE_OFFERS = 5; -@@ -56,6 +64,7 @@ +@@ -57,6 +65,7 @@ public EntityVillagerTrader(EntityTypes entitytypes, World world) { super(entitytypes, world); @@ -23,7 +23,7 @@ } @Override -@@ -136,7 +145,16 @@ +@@ -137,7 +146,16 @@ MerchantRecipe merchantrecipe = villagertrades_imerchantrecipeoption.getOffer(this, this.random); if (merchantrecipe != null) { @@ -41,7 +41,7 @@ } } -@@ -243,7 +261,7 @@ +@@ -244,7 +262,7 @@ private void maybeDespawn() { if (this.despawnDelay > 0 && !this.isTrading() && --this.despawnDelay == 0) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/npc/InventoryCarrier.patch b/paper-server/nms-patches/net/minecraft/world/entity/npc/InventoryCarrier.patch index 3f06982ab1..fb8c49757d 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/npc/InventoryCarrier.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/npc/InventoryCarrier.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/npc/InventoryCarrier.java +++ b/net/minecraft/world/entity/npc/InventoryCarrier.java -@@ -7,6 +7,10 @@ +@@ -8,6 +8,10 @@ import net.minecraft.world.entity.item.EntityItem; import net.minecraft.world.item.ItemStack; @@ -11,7 +11,7 @@ public interface InventoryCarrier { String TAG_INVENTORY = "Inventory"; -@@ -24,13 +28,20 @@ +@@ -25,13 +29,20 @@ return; } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/npc/MobSpawnerTrader.patch b/paper-server/nms-patches/net/minecraft/world/entity/npc/MobSpawnerTrader.patch index c19f83c2c8..e4987a51d4 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/npc/MobSpawnerTrader.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/npc/MobSpawnerTrader.patch @@ -4,8 +4,8 @@ return false; } -- EntityVillagerTrader entityvillagertrader = (EntityVillagerTrader) EntityTypes.WANDERING_TRADER.spawn(worldserver, blockposition2, EnumMobSpawn.EVENT); -+ EntityVillagerTrader entityvillagertrader = (EntityVillagerTrader) EntityTypes.WANDERING_TRADER.spawn(worldserver, blockposition2, EnumMobSpawn.EVENT, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL); // CraftBukkit +- EntityVillagerTrader entityvillagertrader = (EntityVillagerTrader) EntityTypes.WANDERING_TRADER.spawn(worldserver, blockposition2, EntitySpawnReason.EVENT); ++ EntityVillagerTrader entityvillagertrader = (EntityVillagerTrader) EntityTypes.WANDERING_TRADER.spawn(worldserver, blockposition2, EntitySpawnReason.EVENT, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL); // CraftBukkit if (entityvillagertrader != null) { for (int i = 0; i < 2; ++i) { @@ -22,8 +22,8 @@ BlockPosition blockposition = this.findSpawnPositionNear(worldserver, entityvillagertrader.blockPosition(), i); if (blockposition != null) { -- EntityLlamaTrader entityllamatrader = (EntityLlamaTrader) EntityTypes.TRADER_LLAMA.spawn(worldserver, blockposition, EnumMobSpawn.EVENT); -+ EntityLlamaTrader entityllamatrader = (EntityLlamaTrader) EntityTypes.TRADER_LLAMA.spawn(worldserver, blockposition, EnumMobSpawn.EVENT, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL); // CraftBukkit +- EntityLlamaTrader entityllamatrader = (EntityLlamaTrader) EntityTypes.TRADER_LLAMA.spawn(worldserver, blockposition, EntitySpawnReason.EVENT); ++ EntityLlamaTrader entityllamatrader = (EntityLlamaTrader) EntityTypes.TRADER_LLAMA.spawn(worldserver, blockposition, EntitySpawnReason.EVENT, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL); // CraftBukkit if (entityllamatrader != null) { entityllamatrader.setLeashedTo(entityvillagertrader, true); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/player/EntityHuman.patch b/paper-server/nms-patches/net/minecraft/world/entity/player/EntityHuman.patch index b2a5adcef3..a09799fd3f 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/player/EntityHuman.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/player/EntityHuman.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/player/EntityHuman.java +++ b/net/minecraft/world/entity/player/EntityHuman.java -@@ -115,6 +115,23 @@ +@@ -119,6 +119,19 @@ import net.minecraft.world.scores.ScoreboardTeam; import org.slf4j.Logger; @@ -9,22 +9,18 @@ +import org.bukkit.craftbukkit.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.util.CraftVector; -+import org.bukkit.entity.Item; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.CreatureSpawnEvent; -+import org.bukkit.event.entity.EntityCombustByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityExhaustionEvent; -+import org.bukkit.event.entity.EntityKnockbackEvent; +import org.bukkit.event.entity.EntityRemoveEvent; -+import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerVelocityEvent; +// CraftBukkit end + public abstract class EntityHuman extends EntityLiving { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -135,7 +152,8 @@ +@@ -139,7 +152,8 @@ private static final int CURRENT_IMPULSE_CONTEXT_RESET_GRACE_TIME_TICKS = 40; public static final Vec3D DEFAULT_VEHICLE_ATTACHMENT = new Vec3D(0.0D, 0.6D, 0.0D); public static final EntitySize STANDING_DIMENSIONS = EntitySize.scalable(0.6F, 1.8F).withEyeHeight(1.62F).withAttachments(EntityAttachments.builder().attach(EntityAttachment.VEHICLE, EntityHuman.DEFAULT_VEHICLE_ATTACHMENT)); @@ -34,7 +30,7 @@ private static final DataWatcherObject DATA_PLAYER_ABSORPTION_ID = DataWatcher.defineId(EntityHuman.class, DataWatcherRegistry.FLOAT); private static final DataWatcherObject DATA_SCORE_ID = DataWatcher.defineId(EntityHuman.class, DataWatcherRegistry.INT); protected static final DataWatcherObject DATA_PLAYER_MODE_CUSTOMISATION = DataWatcher.defineId(EntityHuman.class, DataWatcherRegistry.BYTE); -@@ -144,10 +162,10 @@ +@@ -148,7 +162,7 @@ protected static final DataWatcherObject DATA_SHOULDER_RIGHT = DataWatcher.defineId(EntityHuman.class, DataWatcherRegistry.COMPOUND_TAG); private long timeEntitySatOnShoulder; final PlayerInventory inventory = new PlayerInventory(this); @@ -42,12 +38,8 @@ + protected InventoryEnderChest enderChestInventory = new InventoryEnderChest(this); // CraftBukkit - add "this" to constructor public final ContainerPlayer inventoryMenu; public Container containerMenu; -- protected FoodMetaData foodData = new FoodMetaData(); -+ protected FoodMetaData foodData = new FoodMetaData(this); // CraftBukkit - add "this" to constructor - protected int jumpTriggerTime; - public float oBob; - public float bob; -@@ -182,6 +200,16 @@ + protected FoodMetaData foodData = new FoodMetaData(); +@@ -186,6 +200,16 @@ private boolean ignoreFallDamageFromCurrentImpulse; private int currentImpulseContextResetGraceTime; @@ -64,16 +56,16 @@ public EntityHuman(World world, BlockPosition blockposition, float f, GameProfile gameprofile) { super(EntityTypes.PLAYER, world); this.lastItemInMainHand = ItemStack.EMPTY; -@@ -330,7 +358,7 @@ - ItemStack itemstack = this.getItemBySlot(EnumItemSlot.HEAD); - - if (itemstack.is(Items.TURTLE_HELMET) && !this.isEyeInFluid(TagsFluid.WATER)) { -- this.addEffect(new MobEffect(MobEffects.WATER_BREATHING, 200, 0, false, false, true)); -+ this.addEffect(new MobEffect(MobEffects.WATER_BREATHING, 200, 0, false, false, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TURTLE_HELMET); // CraftBukkit - } - +@@ -350,7 +374,7 @@ } -@@ -482,8 +510,14 @@ + + private void turtleHelmetTick() { +- this.addEffect(new MobEffect(MobEffects.WATER_BREATHING, 200, 0, false, false, true)); ++ this.addEffect(new MobEffect(MobEffects.WATER_BREATHING, 200, 0, false, false, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.TURTLE_HELMET); // CraftBukkit + } + + private boolean isEquipped(Item item) { +@@ -520,8 +544,14 @@ public void rideTick() { if (!this.level().isClientSide && this.wantsToStopRiding() && this.isPassenger()) { this.stopRiding(); @@ -90,17 +82,7 @@ super.rideTick(); this.oBob = this.bob; this.bob = 0.0F; -@@ -505,7 +539,8 @@ - - if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL && this.level().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION)) { - if (this.getHealth() < this.getMaxHealth() && this.tickCount % 20 == 0) { -- this.heal(1.0F); -+ // CraftBukkit - added regain reason of "REGEN" for filtering purposes. -+ this.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.REGEN); - } - - if (this.foodData.getSaturationLevel() < 20.0F && this.tickCount % 20 == 0) { -@@ -683,6 +718,13 @@ +@@ -716,6 +746,13 @@ @Nullable public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1) { @@ -111,44 +93,10 @@ + @Nullable + public EntityItem drop(ItemStack itemstack, boolean flag, boolean flag1, boolean callEvent) { + // CraftBukkit end - if (itemstack.isEmpty()) { - return null; - } else { -@@ -717,6 +759,33 @@ - entityitem.setDeltaMovement((double) (-f3 * f2 * 0.3F) + Math.cos((double) f5) * (double) f6, (double) (-f1 * 0.3F + 0.1F + (this.random.nextFloat() - this.random.nextFloat()) * 0.1F), (double) (f4 * f2 * 0.3F) + Math.sin((double) f5) * (double) f6); - } - -+ // CraftBukkit start - fire PlayerDropItemEvent -+ if (!callEvent) { // SPIGOT-2942: Add boolean to call event -+ return entityitem; -+ } -+ Player player = (Player) this.getBukkitEntity(); -+ Item drop = (Item) entityitem.getBukkitEntity(); -+ -+ PlayerDropItemEvent event = new PlayerDropItemEvent(player, drop); -+ this.level().getCraftServer().getPluginManager().callEvent(event); -+ -+ if (event.isCancelled()) { -+ org.bukkit.inventory.ItemStack cur = player.getInventory().getItemInHand(); -+ if (flag1 && (cur == null || cur.getAmount() == 0)) { -+ // The complete stack was dropped -+ player.getInventory().setItemInHand(drop.getItemStack()); -+ } else if (flag1 && cur.isSimilar(drop.getItemStack()) && cur.getAmount() < cur.getMaxStackSize() && drop.getItemStack().getAmount() == 1) { -+ // Only one item is dropped -+ cur.setAmount(cur.getAmount() + 1); -+ player.getInventory().setItemInHand(cur); -+ } else { -+ // Fallback -+ player.getInventory().addItem(drop.getItemStack()); -+ } -+ return null; -+ } -+ // CraftBukkit end -+ - return entityitem; + if (!itemstack.isEmpty() && this.level().isClientSide) { + this.swing(EnumHand.MAIN_HAND); } - } -@@ -803,7 +872,7 @@ +@@ -806,7 +843,7 @@ } if (nbttagcompound.contains("LastDeathLocation", 10)) { @@ -157,7 +105,7 @@ Logger logger = EntityHuman.LOGGER; Objects.requireNonNull(logger); -@@ -811,7 +880,7 @@ +@@ -814,7 +851,7 @@ } if (nbttagcompound.contains("current_explosion_impact_pos", 9)) { @@ -166,7 +114,7 @@ Logger logger1 = EntityHuman.LOGGER; Objects.requireNonNull(logger1); -@@ -848,7 +917,7 @@ +@@ -851,7 +888,7 @@ } this.getLastDeathLocation().flatMap((globalpos) -> { @@ -175,28 +123,26 @@ Logger logger = EntityHuman.LOGGER; Objects.requireNonNull(logger); -@@ -881,12 +950,12 @@ +@@ -883,10 +920,10 @@ + if (this.isDeadOrDying()) { return false; } else { - if (!this.level().isClientSide) { -- this.removeEntitiesOnShoulder(); -+ // this.removeEntitiesOnShoulder(); // CraftBukkit - moved down - } - +- this.removeEntitiesOnShoulder(); ++ // this.removeEntitiesOnShoulder(); // CraftBukkit - moved down if (damagesource.scalesWithDifficulty()) { - if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL) { + if (worldserver.getDifficulty() == EnumDifficulty.PEACEFUL) { - f = 0.0F; + return false; // CraftBukkit - f = 0.0f -> return false } - if (this.level().getDifficulty() == EnumDifficulty.EASY) { -@@ -898,7 +967,13 @@ + if (worldserver.getDifficulty() == EnumDifficulty.EASY) { +@@ -898,7 +935,13 @@ } } -- return f == 0.0F ? false : super.hurt(damagesource, f); +- return f == 0.0F ? false : super.hurtServer(worldserver, damagesource, f); + // CraftBukkit start - Don't filter out 0 damage -+ boolean damaged = super.hurt(damagesource, f); ++ boolean damaged = super.hurtServer(worldserver, damagesource, f); + if (damaged) { + this.removeEntitiesOnShoulder(); + } @@ -205,7 +151,7 @@ } } } -@@ -918,10 +993,29 @@ +@@ -920,10 +963,29 @@ } public boolean canHarmPlayer(EntityHuman entityhuman) { @@ -238,22 +184,22 @@ } @Override -@@ -961,8 +1055,13 @@ +@@ -963,8 +1025,13 @@ } } + // CraftBukkit start @Override -- protected void actuallyHurt(DamageSource damagesource, float f) { -+ protected boolean actuallyHurt(DamageSource damagesource, float f, EntityDamageEvent event) { // void -> boolean +- protected void actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f) { ++ protected boolean actuallyHurt(WorldServer worldserver, DamageSource damagesource, float f, EntityDamageEvent event) { // void -> boolean + if (true) { -+ return super.actuallyHurt(damagesource, f, event); ++ return super.actuallyHurt(worldserver, damagesource, f, event); + } + // CraftBukkit end - if (!this.isInvulnerableTo(damagesource)) { + if (!this.isInvulnerableTo(worldserver, damagesource)) { f = this.getDamageAfterArmorAbsorb(damagesource, f); f = this.getDamageAfterMagicAbsorb(damagesource, f); -@@ -977,7 +1076,7 @@ +@@ -979,7 +1046,7 @@ } if (f != 0.0F) { @@ -262,7 +208,7 @@ this.getCombatTracker().recordDamage(damagesource, f); this.setHealth(this.getHealth() - f); if (f < 3.4028235E37F) { -@@ -987,6 +1086,7 @@ +@@ -989,6 +1056,7 @@ this.gameEvent(GameEvent.ENTITY_DAMAGE); } } @@ -270,7 +216,7 @@ } public boolean isTextFilteringEnabled() { -@@ -1139,10 +1239,15 @@ +@@ -1141,10 +1209,15 @@ f *= 0.2F + f2 * f2 * 0.8F; f1 *= f2; @@ -287,12 +233,12 @@ if (iprojectile.deflect(ProjectileDeflection.AIM_DEFLECT, this, this, true)) { this.level().playSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), SoundEffects.PLAYER_ATTACK_NODAMAGE, this.getSoundSource()); return; -@@ -1218,8 +1323,13 @@ +@@ -1220,8 +1293,13 @@ if (entityliving2 != this && entityliving2 != entity && !this.isAlliedTo((Entity) entityliving2) && (!(entityliving2 instanceof EntityArmorStand) || !((EntityArmorStand) entityliving2).isMarker()) && this.distanceToSqr((Entity) entityliving2) < 9.0D) { float f7 = this.getEnchantedDamage(entityliving2, f6, damagesource) * f2; + // CraftBukkit start - Only apply knockback if the damage hits -+ if (!entityliving2.hurt(this.damageSources().playerAttack(this).sweep(), f7)) { ++ if (!entityliving2.hurtServer((WorldServer) this.level(), this.damageSources().playerAttack(this).sweep(), f7)) { + continue; + } + // CraftBukkit end @@ -302,7 +248,7 @@ World world = this.level(); if (world instanceof WorldServer) { -@@ -1235,9 +1345,26 @@ +@@ -1237,9 +1315,26 @@ } if (entity instanceof EntityPlayer && entity.hurtMarked) { @@ -329,7 +275,7 @@ } if (flag2) { -@@ -1303,9 +1430,14 @@ +@@ -1305,9 +1400,14 @@ } } @@ -345,7 +291,7 @@ } } -@@ -1346,7 +1478,14 @@ +@@ -1348,7 +1448,14 @@ @Override public void remove(Entity.RemovalReason entity_removalreason) { @@ -361,7 +307,7 @@ this.inventoryMenu.removed(this); if (this.containerMenu != null && this.hasContainerOpen()) { this.doCloseContainer(); -@@ -1382,6 +1521,12 @@ +@@ -1388,6 +1495,12 @@ } public Either startSleepInBed(BlockPosition blockposition) { @@ -374,32 +320,7 @@ this.startSleeping(blockposition); this.sleepCounter = 0; return Either.right(Unit.INSTANCE); -@@ -1444,9 +1589,9 @@ - super.jumpFromGround(); - this.awardStat(StatisticList.JUMP); - if (this.isSprinting()) { -- this.causeFoodExhaustion(0.2F); -+ this.causeFoodExhaustion(0.2F, EntityExhaustionEvent.ExhaustionReason.JUMP_SPRINT); // CraftBukkit - EntityExhaustionEvent - } else { -- this.causeFoodExhaustion(0.05F); -+ this.causeFoodExhaustion(0.05F, EntityExhaustionEvent.ExhaustionReason.JUMP); // CraftBukkit - EntityExhaustionEvent - } - - } -@@ -1473,7 +1618,11 @@ - - this.setDeltaMovement(vec3d2.x, d0 * 0.6D, vec3d2.z); - this.resetFallDistance(); -- this.setSharedFlag(7, false); -+ // CraftBukkit start -+ if (getSharedFlag(7) && !org.bukkit.craftbukkit.event.CraftEventFactory.callToggleGlideEvent(this, false).isCancelled()) { -+ this.setSharedFlag(7, false); -+ } -+ // CraftBukkit end - } else { - super.travel(vec3d); - } -@@ -1547,12 +1696,24 @@ +@@ -1542,12 +1655,24 @@ } public void startFallFlying() { @@ -425,7 +346,7 @@ } @Override -@@ -1667,10 +1828,21 @@ +@@ -1662,10 +1787,21 @@ return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2); } @@ -448,7 +369,7 @@ } } -@@ -1756,13 +1928,20 @@ +@@ -1745,13 +1881,20 @@ @Override public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { @@ -472,7 +393,7 @@ } } -@@ -1806,26 +1985,31 @@ +@@ -1795,26 +1938,31 @@ protected void removeEntitiesOnShoulder() { if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) { @@ -495,8 +416,8 @@ - private void respawnEntityOnShoulder(NBTTagCompound nbttagcompound) { + private boolean respawnEntityOnShoulder(NBTTagCompound nbttagcompound) { // CraftBukkit void->boolean if (!this.level().isClientSide && !nbttagcompound.isEmpty()) { -- EntityTypes.create(nbttagcompound, this.level()).ifPresent((entity) -> { -+ return EntityTypes.create(nbttagcompound, this.level()).map((entity) -> { // CraftBukkit +- EntityTypes.create(nbttagcompound, this.level(), EntitySpawnReason.LOAD).ifPresent((entity) -> { ++ return EntityTypes.create(nbttagcompound, this.level(), EntitySpawnReason.LOAD).map((entity) -> { // CraftBukkit if (entity instanceof EntityTameableAnimal) { ((EntityTameableAnimal) entity).setOwnerUUID(this.uuid); } @@ -512,12 +433,3 @@ } @Override -@@ -2040,7 +2224,7 @@ - - @Override - public ItemStack eat(World world, ItemStack itemstack, FoodInfo foodinfo) { -- this.getFoodData().eat(foodinfo); -+ this.getFoodData().eat(itemstack, foodinfo); // CraftBukkit - this.awardStat(StatisticList.ITEM_USED.get(itemstack.getItem())); - world.playSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), SoundEffects.PLAYER_BURP, SoundCategory.PLAYERS, 0.5F, world.random.nextFloat() * 0.1F + 0.9F); - if (this instanceof EntityPlayer) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/player/PlayerInventory.patch b/paper-server/nms-patches/net/minecraft/world/entity/player/PlayerInventory.patch index b790523bb8..1746368ea0 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/player/PlayerInventory.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/player/PlayerInventory.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/player/PlayerInventory.java +++ b/net/minecraft/world/entity/player/PlayerInventory.java -@@ -23,6 +23,13 @@ +@@ -24,6 +24,13 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.IBlockData; @@ -14,7 +14,7 @@ public class PlayerInventory implements IInventory, INamableTileEntity { public static final int POP_TIME_DURATION = 5; -@@ -40,6 +47,54 @@ +@@ -39,6 +46,54 @@ public final EntityHuman player; private int timesChanged; @@ -69,7 +69,7 @@ public PlayerInventory(EntityHuman entityhuman) { this.items = NonNullList.withSize(36, ItemStack.EMPTY); this.armor = NonNullList.withSize(4, ItemStack.EMPTY); -@@ -60,6 +115,28 @@ +@@ -59,6 +114,28 @@ return !itemstack.isEmpty() && ItemStack.isSameItemSameComponents(itemstack, itemstack1) && itemstack.isStackable() && itemstack.getCount() < this.getMaxStackSize(itemstack); } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityArrow.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityArrow.patch index 7788760b8c..b822c09716 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityArrow.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityArrow.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntityArrow.java +++ b/net/minecraft/world/entity/projectile/EntityArrow.java -@@ -52,6 +52,13 @@ +@@ -51,6 +51,13 @@ import net.minecraft.world.phys.Vec3D; import net.minecraft.world.phys.shapes.VoxelShape; @@ -29,7 +29,7 @@ this.pickupItemStack = itemstack.copy(); this.setCustomName((IChatBaseComponent) itemstack.get(DataComponents.CUSTOM_NAME)); Unit unit = (Unit) itemstack.remove(DataComponents.INTANGIBLE_PROJECTILE); -@@ -116,8 +130,8 @@ +@@ -112,8 +126,8 @@ } protected EntityArrow(EntityTypes entitytypes, EntityLiving entityliving, World world, ItemStack itemstack, @Nullable ItemStack itemstack1) { @@ -40,16 +40,16 @@ } public void setSoundEvent(SoundEffect soundeffect) { -@@ -242,7 +256,7 @@ - } +@@ -276,7 +290,7 @@ - if (object != null && !flag) { -- ProjectileDeflection projectiledeflection = this.hitTargetOrDeflectSelf((MovingObjectPosition) object); -+ ProjectileDeflection projectiledeflection = this.preHitTargetOrDeflectSelf((MovingObjectPosition) object); // CraftBukkit - projectile hit event - - this.hasImpulse = true; - if (projectiledeflection != ProjectileDeflection.NONE) { -@@ -333,7 +347,7 @@ + if (movingobjectpositionentity == null) { + if (this.isAlive() && movingobjectpositionblock.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) { +- this.hitTargetOrDeflectSelf(movingobjectpositionblock); ++ this.preHitTargetOrDeflectSelf(movingobjectpositionblock); // CraftBukkit - projectile hit event + this.hasImpulse = true; + } + } else { +@@ -356,7 +370,7 @@ protected void tickDespawn() { ++this.life; if (this.life >= 1200) { @@ -58,7 +58,7 @@ } } -@@ -380,7 +394,7 @@ +@@ -408,7 +422,7 @@ } if (this.piercingIgnoreEntityIds.size() >= this.getPierceLevel() + 1) { @@ -67,7 +67,7 @@ return; } -@@ -401,7 +415,13 @@ +@@ -429,7 +443,13 @@ int k = entity.getRemainingFireTicks(); if (this.isOnFire() && !flag) { @@ -81,8 +81,8 @@ + // CraftBukkit end } - if (entity.hurt(damagesource, (float) i)) { -@@ -447,7 +467,7 @@ + if (entity.hurtOrSimulate(damagesource, (float) i)) { +@@ -475,7 +495,7 @@ this.playSound(this.soundEvent, 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F)); if (this.getPierceLevel() <= 0) { @@ -91,16 +91,16 @@ } } else { entity.setRemainingFireTicks(k); -@@ -458,7 +478,7 @@ - this.spawnAtLocation(this.getPickupItem(), 0.1F); - } +@@ -491,7 +511,7 @@ + this.spawnAtLocation(worldserver2, this.getPickupItem(), 0.1F); + } -- this.discard(); -+ this.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause +- this.discard(); ++ this.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause + } } } - -@@ -614,7 +634,7 @@ +@@ -660,7 +680,7 @@ } if (nbttagcompound.contains("weapon", 10)) { @@ -109,7 +109,7 @@ } else { this.firedFromWeapon = null; } -@@ -627,34 +647,31 @@ +@@ -673,34 +693,31 @@ Entity entity1 = entity; byte b0 = 0; @@ -156,10 +156,10 @@ } this.pickup = entityarrow_pickupstatus; -@@ -663,9 +680,24 @@ +@@ -709,9 +726,24 @@ @Override public void playerTouch(EntityHuman entityhuman) { - if (!this.level().isClientSide && (this.inGround || this.isNoPhysics()) && this.shakeTime <= 0) { + if (!this.level().isClientSide && (this.isInGround() || this.isNoPhysics()) && this.shakeTime <= 0) { - if (this.tryPickup(entityhuman)) { + // CraftBukkit start + ItemStack itemstack = this.getPickupItem(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityDragonFireball.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityDragonFireball.patch index ea87f55e66..806f5d1e16 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityDragonFireball.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityDragonFireball.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntityDragonFireball.java +++ b/net/minecraft/world/entity/projectile/EntityDragonFireball.java -@@ -16,6 +16,10 @@ +@@ -15,6 +15,10 @@ import net.minecraft.world.phys.MovingObjectPositionEntity; import net.minecraft.world.phys.Vec3D; @@ -11,7 +11,7 @@ public class EntityDragonFireball extends EntityFireball { public static final float SPLASH_RANGE = 4.0F; -@@ -62,7 +66,7 @@ +@@ -61,7 +65,7 @@ this.level().levelEvent(2006, this.blockPosition(), this.isSilent() ? -1 : 1); this.level().addFreshEntity(entityareaeffectcloud); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEgg.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEgg.patch index 0bc3653440..025e842e52 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEgg.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEgg.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntityEgg.java +++ b/net/minecraft/world/entity/projectile/EntityEgg.java -@@ -12,6 +12,16 @@ +@@ -14,6 +14,16 @@ import net.minecraft.world.phys.MovingObjectPosition; import net.minecraft.world.phys.MovingObjectPositionEntity; @@ -17,7 +17,7 @@ public class EntityEgg extends EntityProjectileThrowable { private static final EntitySize ZERO_SIZED_DIMENSIONS = EntitySize.fixed(0.0F, 0.0F); -@@ -50,30 +60,58 @@ +@@ -52,30 +62,58 @@ protected void onHit(MovingObjectPosition movingobjectposition) { super.onHit(movingobjectposition); if (!this.level().isClientSide) { @@ -54,7 +54,7 @@ + // CraftBukkit end + for (int i = 0; i < b0; ++i) { -- EntityChicken entitychicken = (EntityChicken) EntityTypes.CHICKEN.create(this.level()); +- EntityChicken entitychicken = (EntityChicken) EntityTypes.CHICKEN.create(this.level(), EntitySpawnReason.TRIGGERED); + Entity entitychicken = this.level().getWorld().makeEntity(new org.bukkit.Location(this.level().getWorld(), this.getX(), this.getY(), this.getZ(), this.getYRot(), 0.0F), hatchingType.getEntityClass()); // CraftBukkit if (entitychicken != null) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEnderPearl.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEnderPearl.patch index 102abdc388..cebde2d249 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEnderPearl.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEnderPearl.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntityEnderPearl.java +++ b/net/minecraft/world/entity/projectile/EntityEnderPearl.java -@@ -21,6 +21,13 @@ +@@ -29,6 +29,13 @@ import net.minecraft.world.phys.MovingObjectPositionEntity; import net.minecraft.world.phys.Vec3D; @@ -13,20 +13,20 @@ + public class EntityEnderPearl extends EntityProjectileThrowable { - public EntityEnderPearl(EntityTypes entitytypes, World world) { -@@ -65,19 +72,26 @@ + private long ticketTimer = 0L; +@@ -140,12 +147,19 @@ EntityPlayer entityplayer = (EntityPlayer) entity; if (entityplayer.connection.isAcceptingMessages()) { + // CraftBukkit start -+ Entity tp = entity.changeDimension(new DimensionTransition(worldserver, this.position(), entity.getDeltaMovement(), entity.getYRot(), entity.getXRot(), DimensionTransition.DO_NOTHING, PlayerTeleportEvent.TeleportCause.ENDER_PEARL)); -+ if (tp == null) { ++ EntityPlayer entityplayer1 = entityplayer.teleport(new TeleportTransition(worldserver, vec3d, Vec3D.ZERO, 0.0F, 0.0F, Relative.union(Relative.ROTATION, Relative.DELTA), TeleportTransition.DO_NOTHING, PlayerTeleportEvent.TeleportCause.ENDER_PEARL)); ++ if (entityplayer1 == null) { + this.discard(EntityRemoveEvent.Cause.HIT); + return; + } + // CraftBukkit end if (this.random.nextFloat() < 0.05F && worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBSPAWNING)) { - EntityEndermite entityendermite = (EntityEndermite) EntityTypes.ENDERMITE.create(worldserver); + EntityEndermite entityendermite = (EntityEndermite) EntityTypes.ENDERMITE.create(worldserver, EntitySpawnReason.TRIGGERED); if (entityendermite != null) { entityendermite.moveTo(entity.getX(), entity.getY(), entity.getZ(), entity.getYRot(), entity.getXRot()); @@ -35,17 +35,23 @@ } } -- entity.changeDimension(new DimensionTransition(worldserver, this.position(), entity.getDeltaMovement(), entity.getYRot(), entity.getXRot(), DimensionTransition.DO_NOTHING)); -+ // entity.changeDimension(new DimensionTransition(worldserver, this.position(), entity.getDeltaMovement(), entity.getYRot(), entity.getXRot(), DimensionTransition.DO_NOTHING)); // CraftBukkit - moved up - entity.resetFallDistance(); - entityplayer.resetCurrentImpulseContext(); -- entity.hurt(this.damageSources().fall(), 5.0F); -+ entity.hurt(this.damageSources().fall().customEntityDamager(this), 5.0F); // CraftBukkit - this.playSound(worldserver, this.position()); - } - } else { -@@ -86,11 +100,11 @@ - this.playSound(worldserver, this.position()); +@@ -153,12 +167,12 @@ + entity.setPortalCooldown(); + } + +- EntityPlayer entityplayer1 = entityplayer.teleport(new TeleportTransition(worldserver, vec3d, Vec3D.ZERO, 0.0F, 0.0F, Relative.union(Relative.ROTATION, Relative.DELTA), TeleportTransition.DO_NOTHING)); ++ // EntityPlayer entityplayer1 = entityplayer.teleport(new TeleportTransition(worldserver, vec3d, Vec3D.ZERO, 0.0F, 0.0F, Relative.union(Relative.ROTATION, Relative.DELTA), TeleportTransition.DO_NOTHING)); // CraftBukkit - moved up + + if (entityplayer1 != null) { + entityplayer1.resetFallDistance(); + entityplayer1.resetCurrentImpulseContext(); +- entityplayer1.hurtServer(entityplayer.serverLevel(), this.damageSources().enderPearl(), 5.0F); ++ entityplayer1.hurtServer(entityplayer.serverLevel(), this.damageSources().enderPearl().customEntityDamager(this), 5.0F); // CraftBukkit + } + + this.playSound(worldserver, vec3d); +@@ -173,11 +187,11 @@ + this.playSound(worldserver, vec3d); } - this.discard(); @@ -58,21 +64,21 @@ return; } } -@@ -116,7 +130,7 @@ - Entity entity = this.getOwner(); - - if (entity instanceof EntityPlayer && !entity.isAlive() && this.level().getGameRules().getBoolean(GameRules.RULE_ENDER_PEARLS_VANISH_ON_DEATH)) { -- this.discard(); -+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause - } else { - super.tick(); - } -@@ -129,7 +143,7 @@ +@@ -210,7 +224,7 @@ + entity = this.getOwner(); + if (entity instanceof EntityPlayer entityplayer) { + if (!entity.isAlive() && entityplayer.serverLevel().getGameRules().getBoolean(GameRules.RULE_ENDER_PEARLS_VANISH_ON_DEATH)) { +- this.discard(); ++ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause + break label30; + } + } +@@ -248,7 +262,7 @@ @Override - public boolean canChangeDimensions(World world, World world1) { -- if (world.dimension() == World.END) { -+ if (world.getTypeKey() == WorldDimension.END) { // CraftBukkit + public boolean canTeleport(World world, World world1) { +- if (world.dimension() == World.END && world1.dimension() == World.OVERWORLD) { ++ if (world.getTypeKey() == WorldDimension.END && world1.getTypeKey() == WorldDimension.OVERWORLD) { // CraftBukkit Entity entity = this.getOwner(); if (entity instanceof EntityPlayer) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEnderSignal.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEnderSignal.patch index 9cd57aaf80..04ffd2f1bd 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEnderSignal.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEnderSignal.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntityEnderSignal.java +++ b/net/minecraft/world/entity/projectile/EntityEnderSignal.java -@@ -16,6 +16,10 @@ +@@ -18,6 +18,10 @@ import net.minecraft.world.level.World; import net.minecraft.world.phys.Vec3D; @@ -10,8 +10,8 @@ + public class EntityEnderSignal extends Entity implements ItemSupplier { - private static final DataWatcherObject DATA_ITEM_STACK = DataWatcher.defineId(EntityEnderSignal.class, DataWatcherRegistry.ITEM_STACK); -@@ -146,7 +150,7 @@ + private static final float MIN_CAMERA_DISTANCE_SQUARED = 12.25F; +@@ -153,7 +157,7 @@ ++this.life; if (this.life > 80 && !this.level().isClientSide) { this.playSound(SoundEffects.ENDER_EYE_DEATH, 1.0F, 1.0F); @@ -20,7 +20,7 @@ if (this.surviveAfterDeath) { this.level().addFreshEntity(new EntityItem(this.level(), this.getX(), this.getY(), this.getZ(), this.getItem())); } else { -@@ -167,7 +171,12 @@ +@@ -174,7 +178,12 @@ @Override public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { if (nbttagcompound.contains("Item", 10)) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFireball.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFireball.patch index 30b743bb2f..45aaffc66b 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFireball.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFireball.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntityFireball.java +++ b/net/minecraft/world/entity/projectile/EntityFireball.java -@@ -18,11 +18,17 @@ +@@ -19,11 +19,17 @@ import net.minecraft.world.phys.MovingObjectPosition; import net.minecraft.world.phys.Vec3D; @@ -18,21 +18,21 @@ protected EntityFireball(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -71,7 +77,7 @@ - Entity entity = this.getOwner(); +@@ -73,7 +79,7 @@ + this.applyInertia(); if (!this.level().isClientSide && (entity != null && entity.isRemoved() || !this.level().hasChunkAt(this.blockPosition()))) { - this.discard(); + this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause } else { - super.tick(); - if (this.shouldBurn()) { -@@ -81,7 +87,7 @@ MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResultOnMoveVector(this, this::canHitEntity, this.getClipType()); + Vec3D vec3d; +@@ -93,7 +99,7 @@ + } - if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) { + if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS && this.isAlive()) { - this.hitTargetOrDeflectSelf(movingobjectposition); + this.preHitTargetOrDeflectSelf(movingobjectposition); // CraftBukkit - projectile hit event } - this.checkInsideBlocks(); + this.createParticleTrail(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFireballFireball.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFireballFireball.patch index 4330cea26b..0c681a09f5 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFireballFireball.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFireballFireball.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntityFireballFireball.java +++ b/net/minecraft/world/entity/projectile/EntityFireballFireball.java -@@ -58,7 +58,12 @@ +@@ -61,7 +61,12 @@ public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { super.readAdditionalSaveData(nbttagcompound); if (nbttagcompound.contains("Item", 10)) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFireworks.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFireworks.patch index 894649a2d4..82af90e23c 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFireworks.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFireworks.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntityFireworks.java +++ b/net/minecraft/world/entity/projectile/EntityFireworks.java -@@ -32,6 +32,10 @@ +@@ -33,6 +33,10 @@ import net.minecraft.world.phys.MovingObjectPositionEntity; import net.minecraft.world.phys.Vec3D; @@ -11,59 +11,60 @@ public class EntityFireworks extends IProjectile implements ItemSupplier { public static final DataWatcherObject DATA_ID_FIREWORKS_ITEM = DataWatcher.defineId(EntityFireworks.class, DataWatcherRegistry.ITEM_STACK); -@@ -148,7 +152,7 @@ - MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResultOnMoveVector(this, this::canHitEntity); +@@ -152,7 +156,7 @@ + } - if (!this.noPhysics) { + if (!this.noPhysics && this.isAlive() && movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) { - this.hitTargetOrDeflectSelf(movingobjectposition); + this.preHitTargetOrDeflectSelf(movingobjectposition); // CraftBukkit - projectile hit event this.hasImpulse = true; } -@@ -163,7 +167,11 @@ +@@ -172,7 +176,11 @@ + if (world instanceof WorldServer) { + WorldServer worldserver = (WorldServer) world; + +- this.explode(worldserver); ++ // CraftBukkit start ++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callFireworkExplodeEvent(this).isCancelled()) { ++ this.explode(worldserver); ++ } ++ // CraftBukkit end + } } - if (!this.level().isClientSide && this.life > this.lifetime) { -- this.explode(); -+ // CraftBukkit start -+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callFireworkExplodeEvent(this).isCancelled()) { -+ this.explode(); -+ } -+ // CraftBukkit end - } - - } -@@ -172,14 +180,18 @@ - this.level().broadcastEntityEvent(this, (byte) 17); +@@ -182,7 +190,7 @@ + worldserver.broadcastEntityEvent(this, (byte) 17); this.gameEvent(GameEvent.EXPLODE, this.getOwner()); - this.dealExplosionDamage(); + this.dealExplosionDamage(worldserver); - this.discard(); + this.discard(EntityRemoveEvent.Cause.EXPLODE); // CraftBukkit - add Bukkit remove cause } @Override - protected void onHitEntity(MovingObjectPositionEntity movingobjectpositionentity) { - super.onHitEntity(movingobjectpositionentity); - if (!this.level().isClientSide) { -- this.explode(); +@@ -191,7 +199,11 @@ + World world = this.level(); + + if (world instanceof WorldServer worldserver) { +- this.explode(worldserver); + // CraftBukkit start + if (!org.bukkit.craftbukkit.event.CraftEventFactory.callFireworkExplodeEvent(this).isCancelled()) { -+ this.explode(); ++ this.explode(worldserver); + } + // CraftBukkit end } + } +@@ -205,7 +217,11 @@ -@@ -189,7 +201,11 @@ - - this.level().getBlockState(blockposition).entityInside(this.level(), blockposition, this); - if (!this.level().isClientSide() && this.hasExplosion()) { -- this.explode(); -+ // CraftBukkit start -+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callFireworkExplodeEvent(this).isCancelled()) { -+ this.explode(); -+ } -+ // CraftBukkit end + if (world instanceof WorldServer worldserver) { + if (this.hasExplosion()) { +- this.explode(worldserver); ++ // CraftBukkit start ++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callFireworkExplodeEvent(this).isCancelled()) { ++ this.explode(worldserver); ++ } ++ // CraftBukkit end + } } - super.onHitBlock(movingobjectpositionblock); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFishingHook.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFishingHook.patch index 9bba800012..48be1a5e00 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFishingHook.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityFishingHook.patch @@ -33,7 +33,7 @@ private EntityFishingHook(EntityTypes entitytypes, World world, int i, int j) { super(entitytypes, world); this.syncronizedRandom = RandomSource.create(); -@@ -148,12 +167,12 @@ +@@ -152,12 +171,12 @@ EntityHuman entityhuman = this.getPlayerOwner(); if (entityhuman == null) { @@ -48,7 +48,7 @@ return; } } else { -@@ -254,7 +273,7 @@ +@@ -259,7 +278,7 @@ if (!entityhuman.isRemoved() && entityhuman.isAlive() && (flag || flag1) && this.distanceToSqr((Entity) entityhuman) <= 1024.0D) { return false; } else { @@ -57,7 +57,7 @@ return true; } } -@@ -262,7 +281,7 @@ +@@ -267,7 +286,7 @@ private void checkCollision() { MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResultOnMoveVector(this, this::canHitEntity); @@ -66,7 +66,7 @@ } @Override -@@ -295,11 +314,11 @@ +@@ -300,11 +319,11 @@ int i = 1; BlockPosition blockposition1 = blockposition.above(); @@ -80,7 +80,7 @@ --i; } -@@ -309,6 +328,10 @@ +@@ -314,6 +333,10 @@ this.timeUntilLured = 0; this.timeUntilHooked = 0; this.getEntityData().set(EntityFishingHook.DATA_BITING, false); @@ -91,7 +91,7 @@ } } else { float f; -@@ -342,6 +365,13 @@ +@@ -347,6 +370,13 @@ worldserver.sendParticles(Particles.FISHING, d0, d1, d2, 0, (double) (-f4), 0.01D, (double) f3, 1.0D); } } else { @@ -105,7 +105,7 @@ this.playSound(SoundEffects.FISHING_BOBBER_SPLASH, 0.25F, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F); double d3 = this.getY() + 0.5D; -@@ -374,12 +404,16 @@ +@@ -379,12 +409,16 @@ } if (this.timeUntilLured <= 0) { @@ -126,7 +126,7 @@ } } -@@ -447,6 +481,14 @@ +@@ -452,6 +486,14 @@ int i = 0; if (this.hookedIn != null) { @@ -141,7 +141,7 @@ this.pullEntity(this.hookedIn); CriterionTriggers.FISHING_ROD_HOOKED.trigger((EntityPlayer) entityhuman, itemstack, this, Collections.emptyList()); this.level().broadcastEntityEvent(this, (byte) 31); -@@ -462,6 +504,15 @@ +@@ -467,6 +509,15 @@ while (iterator.hasNext()) { ItemStack itemstack1 = (ItemStack) iterator.next(); EntityItem entityitem = new EntityItem(this.level(), this.getX(), this.getY(), this.getZ(), itemstack1); @@ -157,7 +157,7 @@ double d0 = entityhuman.getX() - this.getX(); double d1 = entityhuman.getY() - this.getY(); double d2 = entityhuman.getZ() - this.getZ(); -@@ -469,7 +520,11 @@ +@@ -474,7 +525,11 @@ entityitem.setDeltaMovement(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D); this.level().addFreshEntity(entityitem); @@ -170,7 +170,7 @@ if (itemstack1.is(TagsItem.FISHES)) { entityhuman.awardStat(StatisticList.FISH_CAUGHT, 1); } -@@ -479,10 +534,27 @@ +@@ -484,10 +539,27 @@ } if (this.onGround()) { @@ -199,7 +199,7 @@ return i; } else { return 0; -@@ -515,8 +587,15 @@ +@@ -520,8 +592,15 @@ @Override public void remove(Entity.RemovalReason entity_removalreason) { @@ -216,3 +216,12 @@ } @Override +@@ -575,7 +654,7 @@ + int i = packetplayoutspawnentity.getData(); + + EntityFishingHook.LOGGER.error("Failed to recreate fishing hook on client. {} (id: {}) is not a valid owner.", this.level().getEntity(i), i); +- this.discard(); ++ this.discard(null); // CraftBukkit - add Bukkit remove cause + } + + } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityLargeFireball.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityLargeFireball.patch index fe98689743..abd100daf3 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityLargeFireball.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityLargeFireball.patch @@ -15,19 +15,19 @@ public EntityLargeFireball(EntityTypes entitytypes, World world) { super(entitytypes, world); -+ isIncendiary = this.level().getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING); // CraftBukkit ++ isIncendiary = (world instanceof WorldServer worldserver) && worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING); // CraftBukkit } public EntityLargeFireball(World world, EntityLiving entityliving, Vec3D vec3d, int i) { super(EntityTypes.FIREBALL, entityliving, vec3d, world); this.explosionPower = i; -+ isIncendiary = this.level().getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING); // CraftBukkit ++ isIncendiary = (world instanceof WorldServer worldserver) && worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING); // CraftBukkit } @Override -@@ -32,8 +39,16 @@ - if (!this.level().isClientSide) { - boolean flag = this.level().getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING); +@@ -34,8 +41,16 @@ + if (world instanceof WorldServer worldserver) { + boolean flag = worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING); - this.level().explode(this, this.getX(), this.getY(), this.getZ(), (float) this.explosionPower, flag, World.a.MOB); - this.discard(); @@ -44,7 +44,7 @@ } } -@@ -63,7 +78,8 @@ +@@ -65,7 +80,8 @@ public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { super.readAdditionalSaveData(nbttagcompound); if (nbttagcompound.contains("ExplosionPower", 99)) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityLlamaSpit.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityLlamaSpit.patch index 7569e95b90..17a9a26530 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityLlamaSpit.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityLlamaSpit.patch @@ -32,7 +32,7 @@ } else { this.setDeltaMovement(vec3d.scale(0.9900000095367432D)); this.applyGravity(); -@@ -86,7 +90,7 @@ +@@ -83,7 +87,7 @@ protected void onHitBlock(MovingObjectPositionBlock movingobjectpositionblock) { super.onHitBlock(movingobjectpositionblock); if (!this.level().isClientSide) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityPotion.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityPotion.patch index 5045121a60..fce143ac0b 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityPotion.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityPotion.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntityPotion.java +++ b/net/minecraft/world/entity/projectile/EntityPotion.java -@@ -34,6 +34,18 @@ +@@ -35,6 +35,18 @@ import net.minecraft.world.phys.MovingObjectPositionBlock; import net.minecraft.world.phys.MovingObjectPositionEntity; @@ -16,45 +16,45 @@ +import org.bukkit.event.entity.EntityRemoveEvent; +// CraftBukkit end + - public class EntityPotion extends EntityProjectileThrowable implements ItemSupplier { + public class EntityPotion extends EntityProjectileThrowable { public static final double SPLASH_RANGE = 4.0D; -@@ -98,18 +110,18 @@ +@@ -101,18 +113,18 @@ if (potioncontents.is(Potions.WATER)) { - this.applyWater(); + this.applyWater(worldserver); - } else if (potioncontents.hasEffects()) { + } else if (true || potioncontents.hasEffects()) { // CraftBukkit - Call event even if no effects to apply if (this.isLingering()) { - this.makeAreaOfEffectCloud(potioncontents); + this.makeAreaOfEffectCloud(potioncontents, movingobjectposition); // CraftBukkit - Pass MovingObjectPosition } else { -- this.applySplash(potioncontents.getAllEffects(), movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.ENTITY ? ((MovingObjectPositionEntity) movingobjectposition).getEntity() : null); -+ this.applySplash(potioncontents.getAllEffects(), movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.ENTITY ? ((MovingObjectPositionEntity) movingobjectposition).getEntity() : null, movingobjectposition); // CraftBukkit - Pass MovingObjectPosition +- this.applySplash(worldserver, potioncontents.getAllEffects(), movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.ENTITY ? ((MovingObjectPositionEntity) movingobjectposition).getEntity() : null); ++ this.applySplash(worldserver, potioncontents.getAllEffects(), movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.ENTITY ? ((MovingObjectPositionEntity) movingobjectposition).getEntity() : null, movingobjectposition); // CraftBukkit - Pass MovingObjectPosition } } int i = potioncontents.potion().isPresent() && ((PotionRegistry) ((Holder) potioncontents.potion().get()).value()).hasInstantEffects() ? 2007 : 2002; - this.level().levelEvent(i, this.blockPosition(), potioncontents.getColor()); + worldserver.levelEvent(i, this.blockPosition(), potioncontents.getColor()); - this.discard(); + this.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause } } -@@ -144,9 +156,10 @@ +@@ -147,9 +159,10 @@ } -- private void applySplash(Iterable iterable, @Nullable Entity entity) { -+ private void applySplash(Iterable iterable, @Nullable Entity entity, MovingObjectPosition position) { // CraftBukkit - Pass MovingObjectPosition +- private void applySplash(WorldServer worldserver, Iterable iterable, @Nullable Entity entity) { ++ private void applySplash(WorldServer worldserver, Iterable iterable, @Nullable Entity entity, MovingObjectPosition position) { // CraftBukkit - Pass MovingObjectPosition AxisAlignedBB axisalignedbb = this.getBoundingBox().inflate(4.0D, 2.0D, 4.0D); - List list = this.level().getEntitiesOfClass(EntityLiving.class, axisalignedbb); + List list = worldserver.getEntitiesOfClass(EntityLiving.class, axisalignedbb); + Map affected = new HashMap(); // CraftBukkit if (!list.isEmpty()) { Entity entity1 = this.getEffectSource(); -@@ -167,24 +180,50 @@ +@@ -170,24 +183,50 @@ d1 = 1.0D - Math.sqrt(d0) / 4.0D; } @@ -78,7 +78,7 @@ + } - if (((MobEffectList) holder.value()).isInstantenous()) { -- ((MobEffectList) holder.value()).applyInstantenousEffect(this, this.getOwner(), entityliving, mobeffect.getAmplifier(), d1); +- ((MobEffectList) holder.value()).applyInstantenousEffect(worldserver, this, this.getOwner(), entityliving, mobeffect.getAmplifier(), d1); - } else { - int i = mobeffect.mapDuration((j) -> { - return (int) (d1 * (double) j + 0.5D); @@ -108,7 +108,7 @@ + // CraftBukkit end + + if (((MobEffectList) holder.value()).isInstantenous()) { -+ ((MobEffectList) holder.value()).applyInstantenousEffect(this, this.getOwner(), entityliving, mobeffect.getAmplifier(), d1); ++ ((MobEffectList) holder.value()).applyInstantenousEffect(worldserver, this, this.getOwner(), entityliving, mobeffect.getAmplifier(), d1); + } else { + int i = mobeffect.mapDuration((j) -> { + return (int) (d1 * (double) j + 0.5D); @@ -120,7 +120,7 @@ } } } -@@ -193,7 +232,7 @@ +@@ -196,7 +235,7 @@ } @@ -129,7 +129,7 @@ EntityAreaEffectCloud entityareaeffectcloud = new EntityAreaEffectCloud(this.level(), this.getX(), this.getY(), this.getZ()); Entity entity = this.getOwner(); -@@ -206,7 +245,14 @@ +@@ -209,7 +248,14 @@ entityareaeffectcloud.setWaitTime(10); entityareaeffectcloud.setRadiusPerTick(-entityareaeffectcloud.getRadius() / (float) entityareaeffectcloud.getDuration()); entityareaeffectcloud.setPotionContents(potioncontents); @@ -145,7 +145,7 @@ } public boolean isLingering() { -@@ -217,13 +263,25 @@ +@@ -220,13 +266,25 @@ IBlockData iblockdata = this.level().getBlockState(blockposition); if (iblockdata.is(TagsBlock.FIRE)) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityProjectile.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityProjectile.patch index 5943756d78..d6b202b2f3 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityProjectile.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityProjectile.patch @@ -1,11 +1,11 @@ --- a/net/minecraft/world/entity/projectile/EntityProjectile.java +++ b/net/minecraft/world/entity/projectile/EntityProjectile.java -@@ -46,7 +46,7 @@ - MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResultOnMoveVector(this, this::canHitEntity); - - if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) { +@@ -63,7 +63,7 @@ + this.applyEffectsFromBlocks(); + super.tick(); + if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS && this.isAlive()) { - this.hitTargetOrDeflectSelf(movingobjectposition); + this.preHitTargetOrDeflectSelf(movingobjectposition); // CraftBukkit - projectile hit event } - this.checkInsideBlocks(); + } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityProjectileThrowable.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityProjectileThrowable.patch index 58fe9d5207..8ddb29fd1e 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityProjectileThrowable.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityProjectileThrowable.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntityProjectileThrowable.java +++ b/net/minecraft/world/entity/projectile/EntityProjectileThrowable.java -@@ -32,6 +32,12 @@ +@@ -34,6 +34,12 @@ protected abstract Item getDefaultItem(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityShulkerBullet.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityShulkerBullet.patch index 28584287a7..a42348eabc 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityShulkerBullet.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityShulkerBullet.patch @@ -42,16 +42,16 @@ } } -@@ -230,7 +247,7 @@ - MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResultOnMoveVector(this, this::canHitEntity); - - if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) { -- this.hitTargetOrDeflectSelf(movingobjectposition); -+ this.preHitTargetOrDeflectSelf(movingobjectposition); // CraftBukkit - projectile hit event - } +@@ -239,7 +256,7 @@ } -@@ -307,7 +324,7 @@ + if (movingobjectposition != null && this.isAlive() && movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) { +- this.hitTargetOrDeflectSelf(movingobjectposition); ++ this.preHitTargetOrDeflectSelf(movingobjectposition); // CraftBukkit - projectile hit event + } + + ProjectileHelper.rotateTowardsMovement(this, 0.5F); +@@ -312,7 +329,7 @@ if (entity instanceof EntityLiving) { EntityLiving entityliving1 = (EntityLiving) entity; @@ -60,7 +60,7 @@ } } -@@ -321,14 +338,20 @@ +@@ -326,14 +343,20 @@ } private void destroy() { @@ -83,20 +83,19 @@ } @Override -@@ -338,10 +361,15 @@ +@@ -348,9 +371,14 @@ @Override - public boolean hurt(DamageSource damagesource, float f) { + public boolean hurtServer(WorldServer worldserver, DamageSource damagesource, float f) { + // CraftBukkit start + if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f, false)) { + return false; + } + // CraftBukkit end - if (!this.level().isClientSide) { - this.playSound(SoundEffects.SHULKER_BULLET_HURT, 1.0F, 1.0F); - ((WorldServer) this.level()).sendParticles(Particles.CRIT, this.getX(), this.getY(), this.getZ(), 15, 0.2D, 0.2D, 0.2D, 0.0D); -- this.destroy(); -+ this.destroy(EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause - } - + this.playSound(SoundEffects.SHULKER_BULLET_HURT, 1.0F, 1.0F); + worldserver.sendParticles(Particles.CRIT, this.getX(), this.getY(), this.getZ(), 15, 0.2D, 0.2D, 0.2D, 0.0D); +- this.destroy(); ++ this.destroy(EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause return true; + } + diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntitySmallFireball.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntitySmallFireball.patch index ccb7678537..a975722179 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntitySmallFireball.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntitySmallFireball.patch @@ -18,7 +18,7 @@ super(EntityTypes.SMALL_FIREBALL, entityliving, vec3d, world); + // CraftBukkit start + if (this.getOwner() != null && this.getOwner() instanceof EntityInsentient) { -+ isIncendiary = this.level().getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING); ++ isIncendiary = (world instanceof WorldServer worldserver) && worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING); + } + // CraftBukkit end } @@ -39,12 +39,12 @@ + // CraftBukkit end DamageSource damagesource = this.damageSources().fireball(this, entity1); - if (!entity.hurt(damagesource, 5.0F)) { -@@ -58,10 +75,10 @@ - if (!this.level().isClientSide) { + if (!entity.hurtServer(worldserver, damagesource, 5.0F)) { +@@ -60,10 +77,10 @@ + if (world instanceof WorldServer worldserver) { Entity entity = this.getOwner(); -- if (!(entity instanceof EntityInsentient) || this.level().getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { +- if (!(entity instanceof EntityInsentient) || worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { + if (isIncendiary) { // CraftBukkit BlockPosition blockposition = movingobjectpositionblock.getBlockPos().relative(movingobjectpositionblock.getDirection()); @@ -53,7 +53,7 @@ this.level().setBlockAndUpdate(blockposition, BlockFireAbstract.getState(this.level(), blockposition)); } } -@@ -73,7 +90,7 @@ +@@ -75,7 +92,7 @@ protected void onHit(MovingObjectPosition movingobjectposition) { super.onHit(movingobjectposition); if (!this.level().isClientSide) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityThrownExpBottle.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityThrownExpBottle.patch index 2323bc5b8a..ab6f2fdb1c 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityThrownExpBottle.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityThrownExpBottle.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntityThrownExpBottle.java +++ b/net/minecraft/world/entity/projectile/EntityThrownExpBottle.java -@@ -11,6 +11,10 @@ +@@ -12,6 +12,10 @@ import net.minecraft.world.level.World; import net.minecraft.world.phys.MovingObjectPosition; @@ -11,7 +11,7 @@ public class EntityThrownExpBottle extends EntityProjectileThrowable { public EntityThrownExpBottle(EntityTypes entitytypes, World world) { -@@ -39,11 +43,20 @@ +@@ -40,11 +44,20 @@ protected void onHit(MovingObjectPosition movingobjectposition) { super.onHit(movingobjectposition); if (this.level() instanceof WorldServer) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityThrownTrident.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityThrownTrident.patch index 477f3622e5..a4d00d7bc1 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityThrownTrident.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityThrownTrident.patch @@ -11,21 +11,25 @@ public class EntityThrownTrident extends EntityArrow { private static final DataWatcherObject ID_LOYALTY = DataWatcher.defineId(EntityThrownTrident.class, DataWatcherRegistry.BYTE); -@@ -69,7 +73,7 @@ - this.spawnAtLocation(this.getPickupItem(), 0.1F); +@@ -75,10 +79,10 @@ + } } - this.discard(); + this.discard(EntityRemoveEvent.Cause.DROP); // CraftBukkit - add Bukkit remove cause } else { - this.setNoPhysics(true); - Vec3D vec3d = entity.getEyePosition().subtract(this.position()); -@@ -129,7 +133,7 @@ + if (!(entity instanceof EntityHuman) && this.position().distanceTo(entity.getEyePosition()) < (double) entity.getBbWidth() + 1.0D) { +- this.discard(); ++ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause + return; + } + +@@ -136,7 +140,7 @@ world = this.level(); if (world instanceof WorldServer) { - worldserver = (WorldServer) world; + WorldServer worldserver = (WorldServer) world; // CraftBukkit - decompile error - EnchantmentManager.doPostAttackEffectsWithItemSource(worldserver, entity, damagesource, this.getWeaponItem()); - } - + EnchantmentManager.doPostAttackEffectsWithItemSourceOnBreak(worldserver, entity, damagesource, this.getWeaponItem(), (item) -> { + this.kill(worldserver); + }); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/IProjectile.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/IProjectile.patch index 8e05cbf01e..b4c0be0b32 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/IProjectile.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/IProjectile.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/IProjectile.java +++ b/net/minecraft/world/entity/projectile/IProjectile.java -@@ -30,6 +30,10 @@ +@@ -36,6 +36,10 @@ import net.minecraft.world.phys.MovingObjectPositionEntity; import net.minecraft.world.phys.Vec3D; @@ -11,7 +11,7 @@ public abstract class IProjectile extends Entity implements TraceableEntity { @Nullable -@@ -41,6 +45,10 @@ +@@ -47,6 +51,10 @@ @Nullable private Entity lastDeflectedBy; @@ -22,7 +22,7 @@ IProjectile(EntityTypes entitytypes, World world) { super(entitytypes, world); } -@@ -50,6 +58,7 @@ +@@ -56,6 +64,7 @@ this.ownerUUID = entity.getUUID(); this.cachedOwner = entity; } @@ -30,8 +30,17 @@ } -@@ -177,6 +186,17 @@ - this.setDeltaMovement(this.getDeltaMovement().add(vec3d.x, entity.onGround() ? 0.0D : vec3d.y, vec3d.z)); +@@ -213,7 +222,7 @@ + + public static T spawnProjectile(T t0, WorldServer worldserver, ItemStack itemstack, Consumer consumer) { + consumer.accept(t0); +- worldserver.addFreshEntity(t0); ++ if (worldserver.addFreshEntity(t0)) // CraftBukkit + t0.applyOnProjectileSpawned(worldserver, itemstack); + return t0; + } +@@ -232,6 +241,17 @@ + } + // CraftBukkit start - call projectile hit event @@ -48,7 +57,7 @@ protected ProjectileDeflection hitTargetOrDeflectSelf(MovingObjectPosition movingobjectposition) { if (movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.ENTITY) { MovingObjectPositionEntity movingobjectpositionentity = (MovingObjectPositionEntity) movingobjectposition; -@@ -237,6 +257,11 @@ +@@ -309,6 +329,11 @@ protected void onHitEntity(MovingObjectPositionEntity movingobjectpositionentity) {} protected void onHitBlock(MovingObjectPositionBlock movingobjectpositionblock) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/windcharge/AbstractWindCharge.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/windcharge/AbstractWindCharge.patch index b8cf1783a0..1a127fc307 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/windcharge/AbstractWindCharge.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/windcharge/AbstractWindCharge.patch @@ -10,8 +10,8 @@ + public abstract class AbstractWindCharge extends EntityFireball implements ItemSupplier { - public static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new SimpleExplosionDamageCalculator(true, false, Optional.empty(), BuiltInRegistries.BLOCK.getTag(TagsBlock.BLOCKS_WIND_CHARGE_EXPLOSIONS).map(Function.identity())); -@@ -113,7 +117,7 @@ + public static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new SimpleExplosionDamageCalculator(true, false, Optional.empty(), BuiltInRegistries.BLOCK.get(TagsBlock.BLOCKS_WIND_CHARGE_EXPLOSIONS).map(Function.identity())); +@@ -111,7 +115,7 @@ Vec3D vec3d1 = movingobjectpositionblock.getLocation().add(vec3d); this.explode(vec3d1); @@ -20,7 +20,7 @@ } } -@@ -122,7 +126,7 @@ +@@ -120,7 +124,7 @@ protected void onHit(MovingObjectPosition movingobjectposition) { super.onHit(movingobjectposition); if (!this.level().isClientSide) { @@ -29,9 +29,9 @@ } } -@@ -157,7 +161,7 @@ +@@ -155,7 +159,7 @@ public void tick() { - if (!this.level().isClientSide && this.getBlockY() > this.level().getMaxBuildHeight() + 30) { + if (!this.level().isClientSide && this.getBlockY() > this.level().getMaxY() + 30) { this.explode(this.position()); - this.discard(); + this.discard(EntityRemoveEvent.Cause.OUT_OF_WORLD); // CraftBukkit - add Bukkit remove cause diff --git a/paper-server/nms-patches/net/minecraft/world/entity/raid/EntityRaider.patch b/paper-server/nms-patches/net/minecraft/world/entity/raid/EntityRaider.patch index a2c11f8b95..40e734c409 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/raid/EntityRaider.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/raid/EntityRaider.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/entity/raid/EntityRaider.java +++ b/net/minecraft/world/entity/raid/EntityRaider.java -@@ -38,6 +38,10 @@ - import net.minecraft.world.level.WorldAccess; +@@ -41,6 +41,10 @@ + import net.minecraft.world.level.pathfinder.PathEntity; import net.minecraft.world.phys.Vec3D; +// CraftBukkit start @@ -11,7 +11,7 @@ public abstract class EntityRaider extends EntityMonsterPatrolling { protected static final DataWatcherObject IS_CELEBRATING = DataWatcher.defineId(EntityRaider.class, DataWatcherRegistry.BOOLEAN); -@@ -233,7 +237,7 @@ +@@ -236,7 +240,7 @@ this.onItemPickup(entityitem); this.setItemSlot(enumitemslot, itemstack); this.take(entityitem, itemstack.getCount()); @@ -20,16 +20,16 @@ this.getCurrentRaid().setLeader(this.getWave(), this); this.setPatrolLeader(true); } else { -@@ -282,7 +286,7 @@ +@@ -290,7 +294,7 @@ + @Nullable + private EntityItem pursuedBannerItemEntity; - private final T mob; - -- public b(final EntityRaider entityraider, final EntityRaider entityraider1) { -+ public b(final EntityRaider entityraider, final T entityraider1) { // CraftBukkit - decompile error - this.mob = entityraider1; +- public b(final EntityRaider entityraider) { ++ public b(final T entityraider) { // CraftBukkit - decompile error + this.mob = entityraider; this.setFlags(EnumSet.of(PathfinderGoal.Type.MOVE)); } -@@ -475,7 +479,7 @@ +@@ -524,7 +528,7 @@ private final float hostileRadiusSqr; public final PathfinderTargetCondition shoutTargeting = PathfinderTargetCondition.forNonCombat().range(8.0D).ignoreLineOfSight().ignoreInvisibilityTesting(); @@ -38,7 +38,7 @@ this.mob = entityillagerabstract; this.hostileRadiusSqr = f * f; this.setFlags(EnumSet.of(PathfinderGoal.Type.MOVE, PathfinderGoal.Type.LOOK)); -@@ -498,7 +502,7 @@ +@@ -547,7 +551,7 @@ while (iterator.hasNext()) { EntityRaider entityraider = (EntityRaider) iterator.next(); @@ -47,7 +47,7 @@ } } -@@ -515,7 +519,7 @@ +@@ -564,7 +568,7 @@ while (iterator.hasNext()) { EntityRaider entityraider = (EntityRaider) iterator.next(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/raid/Raid.patch b/paper-server/nms-patches/net/minecraft/world/entity/raid/Raid.patch index 25ced26882..cff0acd8fa 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/raid/Raid.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/raid/Raid.patch @@ -38,15 +38,15 @@ this.stop(); return; } -@@ -380,6 +390,7 @@ +@@ -374,6 +384,7 @@ } - if (j > 3) { + if (j > 5) { + org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(this, org.bukkit.event.raid.RaidStopEvent.Reason.UNSPAWNABLE); // CraftBukkit this.stop(); break; } -@@ -392,6 +403,7 @@ +@@ -386,6 +397,7 @@ this.status = Raid.Status.VICTORY; Iterator iterator = this.heroesOfTheVillage.iterator(); @@ -54,7 +54,7 @@ while (iterator.hasNext()) { UUID uuid = (UUID) iterator.next(); Entity entity = this.level.getEntity(uuid); -@@ -406,10 +418,12 @@ +@@ -400,10 +412,12 @@ entityplayer.awardStat(StatisticList.RAID_WIN); CriterionTriggers.RAID_WIN.trigger(entityplayer); @@ -67,7 +67,7 @@ } } -@@ -417,6 +431,7 @@ +@@ -411,6 +425,7 @@ } else if (this.isOver()) { ++this.celebrationTicks; if (this.celebrationTicks >= 600) { @@ -75,7 +75,7 @@ this.stop(); return; } -@@ -553,6 +568,10 @@ +@@ -544,6 +559,10 @@ int j = araid_wave.length; int k = 0; @@ -86,7 +86,7 @@ while (k < j) { Raid.Wave raid_wave = araid_wave[k]; int l = this.getDefaultNumSpawns(raid_wave, i, flag1) + this.getPotentialBonusSpawns(raid_wave, this.random, i, difficultydamagescaler, flag1); -@@ -568,9 +587,11 @@ +@@ -559,9 +578,11 @@ entityraider.setPatrolLeader(true); this.setLeader(i, entityraider); flag = true; @@ -98,7 +98,7 @@ if (raid_wave.entityType == EntityTypes.RAVAGER) { EntityRaider entityraider1 = null; -@@ -589,6 +610,7 @@ +@@ -580,6 +601,7 @@ this.joinRaid(i, entityraider1, blockposition, false); entityraider1.moveTo(blockposition, 0.0F, 0.0F); entityraider1.startRiding(entityraider); @@ -106,7 +106,7 @@ } } -@@ -606,6 +628,7 @@ +@@ -597,6 +619,7 @@ ++this.groupsSpawned; this.updateBossbar(); this.setDirty(); @@ -114,8 +114,8 @@ } public void joinRaid(int i, EntityRaider entityraider, @Nullable BlockPosition blockposition, boolean flag) { -@@ -621,7 +644,7 @@ - entityraider.finalizeSpawn(this.level, this.level.getCurrentDifficultyAt(blockposition), EnumMobSpawn.EVENT, (GroupDataEntity) null); +@@ -612,7 +635,7 @@ + entityraider.finalizeSpawn(this.level, this.level.getCurrentDifficultyAt(blockposition), EntitySpawnReason.EVENT, (GroupDataEntity) null); entityraider.applyRaidBuffs(this.level, i, false); entityraider.setOnGround(true); - this.level.addFreshEntityWithPassengers(entityraider); @@ -123,7 +123,7 @@ } } -@@ -870,6 +893,12 @@ +@@ -865,6 +888,12 @@ this.heroesOfTheVillage.add(entity.getUUID()); } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityBoat.patch b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/AbstractBoat.patch similarity index 68% rename from paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityBoat.patch rename to paper-server/nms-patches/net/minecraft/world/entity/vehicle/AbstractBoat.patch index 44bbb9f2f9..f6c41ac0bf 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityBoat.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/AbstractBoat.patch @@ -1,6 +1,6 @@ ---- a/net/minecraft/world/entity/vehicle/EntityBoat.java -+++ b/net/minecraft/world/entity/vehicle/EntityBoat.java -@@ -55,6 +55,16 @@ +--- a/net/minecraft/world/entity/vehicle/AbstractBoat.java ++++ b/net/minecraft/world/entity/vehicle/AbstractBoat.java +@@ -48,6 +48,15 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapes; @@ -9,17 +9,16 @@ +import org.bukkit.craftbukkit.util.CraftLocation; +import org.bukkit.entity.Vehicle; +import org.bukkit.event.entity.EntityRemoveEvent; -+import org.bukkit.event.vehicle.VehicleDestroyEvent; +import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; +import org.bukkit.event.vehicle.VehicleMoveEvent; +// CraftBukkit end + - public class EntityBoat extends VehicleEntity implements Leashable, VariantHolder { + public abstract class AbstractBoat extends VehicleEntity implements Leashable { - private static final DataWatcherObject DATA_ID_TYPE = DataWatcher.defineId(EntityBoat.class, DataWatcherRegistry.INT); -@@ -94,6 +104,14 @@ - @Nullable + private static final DataWatcherObject DATA_ID_PADDLE_LEFT = DataWatcher.defineId(AbstractBoat.class, DataWatcherRegistry.BOOLEAN); +@@ -87,6 +96,14 @@ private Leashable.a leashData; + private final Supplier dropItem; + // CraftBukkit start + // PAIL: Some of these haven't worked since a few updates, and since 1.9 they are less and less applicable. @@ -29,12 +28,12 @@ + public boolean landBoats = false; + // CraftBukkit end + - public EntityBoat(EntityTypes entitytypes, World world) { + public AbstractBoat(EntityTypes entitytypes, World world, Supplier supplier) { super(entitytypes, world); - this.paddlePositions = new float[2]; -@@ -189,9 +207,29 @@ + this.dropItem = supplier; +@@ -182,9 +199,29 @@ public void push(Entity entity) { - if (entity instanceof EntityBoat) { + if (entity instanceof AbstractBoat) { if (entity.getBoundingBox().minY < this.getBoundingBox().maxY) { + // CraftBukkit start + if (!this.isPassengerOfSameVehicle(entity)) { @@ -62,7 +61,7 @@ super.push(entity); } -@@ -285,6 +323,7 @@ +@@ -247,6 +284,7 @@ return this.getDirection().getClockWise(); } @@ -70,7 +69,7 @@ @Override public void tick() { this.oldStatus = this.status; -@@ -325,6 +364,22 @@ +@@ -287,6 +325,21 @@ this.setDeltaMovement(Vec3D.ZERO); } @@ -89,11 +88,10 @@ + } + lastLocation = vehicle.getLocation(); + // CraftBukkit end -+ + this.applyEffectsFromBlocks(); + this.applyEffectsFromBlocks(); this.tickBubbleColumn(); - - for (int i = 0; i <= 1; ++i) { -@@ -837,11 +892,18 @@ +@@ -790,11 +843,18 @@ @Override public void remove(Entity.RemovalReason entity_removalreason) { @@ -113,23 +111,3 @@ } @Override -@@ -857,6 +919,11 @@ - - this.causeFallDamage(this.fallDistance, 1.0F, this.damageSources().fall()); - if (!this.level().isClientSide && !this.isRemoved()) { -+ // CraftBukkit start -+ Vehicle vehicle = (Vehicle) this.getBukkitEntity(); -+ VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, null); -+ this.level().getCraftServer().getPluginManager().callEvent(destroyEvent); -+ if (!destroyEvent.isCancelled()) { - this.kill(); - if (this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) { - int i; -@@ -870,6 +937,7 @@ - } - } - } -+ } // CraftBukkit end - } - - this.resetFallDistance(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/ChestBoat.patch b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/AbstractChestBoat.patch similarity index 88% rename from paper-server/nms-patches/net/minecraft/world/entity/vehicle/ChestBoat.patch rename to paper-server/nms-patches/net/minecraft/world/entity/vehicle/AbstractChestBoat.patch index 1e7f11f7fd..5b6e2c7ab9 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/ChestBoat.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/AbstractChestBoat.patch @@ -1,6 +1,6 @@ ---- a/net/minecraft/world/entity/vehicle/ChestBoat.java -+++ b/net/minecraft/world/entity/vehicle/ChestBoat.java -@@ -26,6 +26,15 @@ +--- a/net/minecraft/world/entity/vehicle/AbstractChestBoat.java ++++ b/net/minecraft/world/entity/vehicle/AbstractChestBoat.java +@@ -27,6 +27,15 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.level.storage.loot.LootTable; @@ -13,10 +13,10 @@ +import org.bukkit.inventory.InventoryHolder; +// CraftBukkit end + - public class ChestBoat extends EntityBoat implements HasCustomInventoryScreen, ContainerEntity { + public abstract class AbstractChestBoat extends AbstractBoat implements HasCustomInventoryScreen, ContainerEntity { private static final int CONTAINER_SIZE = 27; -@@ -78,11 +87,18 @@ +@@ -70,11 +79,18 @@ @Override public void remove(Entity.RemovalReason entity_removalreason) { @@ -36,7 +36,7 @@ } @Override -@@ -248,4 +264,51 @@ +@@ -212,4 +228,51 @@ public void stopOpen(EntityHuman entityhuman) { this.level().gameEvent((Holder) GameEvent.CONTAINER_CLOSE, this.position(), GameEvent.a.of((Entity) entityhuman)); } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.patch b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.patch index cdcc7248da..55678f5256 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java +++ b/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java -@@ -47,6 +47,14 @@ +@@ -43,6 +43,14 @@ import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; @@ -15,7 +15,7 @@ public abstract class EntityMinecartAbstract extends VehicleEntity { private static final Vec3D LOWERED_PASSENGER_ATTACHMENT = new Vec3D(0.0D, 0.0D, 0.0D); -@@ -86,6 +94,17 @@ +@@ -76,6 +84,17 @@ enummap.put(BlockPropertyTrackPosition.NORTH_EAST, Pair.of(baseblockposition2, baseblockposition1)); }); @@ -32,17 +32,17 @@ + protected EntityMinecartAbstract(EntityTypes entitytypes, World world) { super(entitytypes, world); - this.targetDeltaMovement = Vec3D.ZERO; -@@ -126,7 +145,7 @@ - object = new EntityMinecartRideable(worldserver, d0, d1, d2); - } + this.blocksBuilding = true; +@@ -101,7 +120,7 @@ -- Object object1 = object; -+ EntityMinecartAbstract object1 = (EntityMinecartAbstract) object; // CraftBukkit- decompile error + @Nullable + public static T createMinecart(World world, double d0, double d1, double d2, EntityTypes entitytypes, EntitySpawnReason entityspawnreason, ItemStack itemstack, @Nullable EntityHuman entityhuman) { +- T t0 = (EntityMinecartAbstract) entitytypes.create(world, entityspawnreason); ++ T t0 = (T) entitytypes.create(world, entityspawnreason); // CraftBukkit - decompile error - EntityTypes.createDefaultStackConfig(worldserver, itemstack, entityhuman).accept(object1); - return (EntityMinecartAbstract) object1; -@@ -270,6 +289,14 @@ + if (t0 != null) { + t0.setInitialPos(d0, d1, d2); +@@ -262,6 +281,14 @@ @Override public void tick() { @@ -57,86 +57,29 @@ if (this.getHurtTime() > 0) { this.setHurtTime(this.getHurtTime() - 1); } -@@ -279,7 +306,7 @@ +@@ -271,8 +298,20 @@ } this.checkBelowWorld(); - this.handlePortal(); + // this.handlePortal(); // CraftBukkit - handled in postTick - if (this.level().isClientSide) { - if (this.lerpSteps > 0) { - this.lerpPositionAndRotationStep(this.lerpSteps, this.lerpX, this.lerpY, this.lerpZ, this.lerpYRot, this.lerpXRot); -@@ -332,6 +359,18 @@ - } - - this.setRot(this.getYRot(), this.getXRot()); -+ // CraftBukkit start -+ org.bukkit.World bworld = this.level().getWorld(); -+ Location from = new Location(bworld, prevX, prevY, prevZ, prevYaw, prevPitch); -+ Location to = CraftLocation.toBukkit(this.position(), bworld, this.getYRot(), this.getXRot()); -+ Vehicle vehicle = (Vehicle) this.getBukkitEntity(); + this.behavior.tick(); ++ // CraftBukkit start ++ org.bukkit.World bworld = this.level().getWorld(); ++ Location from = new Location(bworld, prevX, prevY, prevZ, prevYaw, prevPitch); ++ Location to = CraftLocation.toBukkit(this.position(), bworld, this.getYRot(), this.getXRot()); ++ Vehicle vehicle = (Vehicle) this.getBukkitEntity(); + -+ this.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleUpdateEvent(vehicle)); ++ this.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleUpdateEvent(vehicle)); + -+ if (!from.equals(to)) { -+ this.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleMoveEvent(vehicle, from, to)); -+ } -+ // CraftBukkit end - if (this.getMinecartType() == EntityMinecartAbstract.EnumMinecartType.RIDEABLE && this.getDeltaMovement().horizontalDistanceSqr() > 0.01D) { - List list = this.level().getEntities((Entity) this, this.getBoundingBox().inflate(0.20000000298023224D, 0.0D, 0.20000000298023224D), IEntitySelector.pushableBy(this)); - -@@ -342,8 +381,26 @@ - Entity entity = (Entity) iterator.next(); - - if (!(entity instanceof EntityHuman) && !(entity instanceof EntityIronGolem) && !(entity instanceof EntityMinecartAbstract) && !this.isVehicle() && !entity.isPassenger()) { -+ // CraftBukkit start -+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, entity.getBukkitEntity()); -+ this.level().getCraftServer().getPluginManager().callEvent(collisionEvent); -+ -+ if (collisionEvent.isCancelled()) { -+ continue; -+ } -+ // CraftBukkit end - entity.startRiding(this); - } else { -+ // CraftBukkit start -+ if (!this.isPassengerOfSameVehicle(entity)) { -+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, entity.getBukkitEntity()); -+ this.level().getCraftServer().getPluginManager().callEvent(collisionEvent); -+ -+ if (collisionEvent.isCancelled()) { -+ continue; -+ } -+ } -+ // CraftBukkit end - entity.push((Entity) this); - } - } -@@ -355,6 +412,14 @@ - Entity entity1 = (Entity) iterator1.next(); - - if (!this.hasPassenger(entity1) && entity1.isPushable() && entity1 instanceof EntityMinecartAbstract) { -+ // CraftBukkit start -+ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, entity1.getBukkitEntity()); -+ this.level().getCraftServer().getPluginManager().callEvent(collisionEvent); -+ -+ if (collisionEvent.isCancelled()) { -+ continue; -+ } -+ // CraftBukkit end - entity1.push((Entity) this); - } - } -@@ -371,7 +436,7 @@ - } - - protected double getMaxSpeed() { -- return (this.isInWater() ? 4.0D : 8.0D) / 20.0D; -+ return (this.isInWater() ? this.maxSpeed / 2.0D: this.maxSpeed); // CraftBukkit - } - - public void activateMinecart(int i, int j, int k, boolean flag) {} -@@ -382,16 +447,30 @@ ++ if (!from.equals(to)) { ++ this.level().getCraftServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleMoveEvent(vehicle, from, to)); ++ } ++ // CraftBukkit end + this.updateInWaterStateAndDoFluidPushing(); + if (this.isInLava()) { + this.lavaHurt(); +@@ -385,12 +424,16 @@ this.setDeltaMovement(MathHelper.clamp(vec3d.x, -d0, d0), vec3d.y, MathHelper.clamp(vec3d.z, -d0, d0)); if (this.onGround()) { @@ -155,30 +98,7 @@ } } - -+ // CraftBukkit start -+ @Override -+ public Vec3D getKnownMovement() { -+ double d0 = this.getMaxSpeed(); -+ Vec3D vec3d = super.getKnownMovement(); -+ -+ return new Vec3D(MathHelper.clamp(vec3d.x, -d0, d0), vec3d.y, MathHelper.clamp(vec3d.z, -d0, d0)); -+ } -+ // CraftBukkit end -+ - protected void moveAlongTrack(BlockPosition blockposition, IBlockData iblockdata) { - this.resetFallDistance(); - double d0 = this.getX(); -@@ -583,7 +662,7 @@ - } - - protected void applyNaturalSlowdown() { -- double d0 = this.isVehicle() ? 0.997D : 0.96D; -+ double d0 = this.isVehicle() || !this.slowWhenEmpty ? 0.997D : 0.96D; // CraftBukkit - add !this.slowWhenEmpty - Vec3D vec3d = this.getDeltaMovement(); - - vec3d = vec3d.multiply(d0, 0.0D, d0); -@@ -722,6 +801,14 @@ +@@ -521,6 +564,14 @@ if (!this.level().isClientSide) { if (!entity.noPhysics && !this.noPhysics) { if (!this.hasPassenger(entity)) { @@ -193,9 +113,9 @@ double d0 = entity.getX() - this.getX(); double d1 = entity.getZ() - this.getZ(); double d2 = d0 * d0 + d1 * d1; -@@ -896,4 +983,26 @@ - - private EnumMinecartType() {} +@@ -645,4 +696,26 @@ + public boolean isFurnace() { + return false; } + + // CraftBukkit start - Methods for getting and setting flying and derailed velocity modifiers diff --git a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartCommandBlock.patch b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartCommandBlock.patch index fc124c7edf..19b0628ecc 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartCommandBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartCommandBlock.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/vehicle/EntityMinecartCommandBlock.java +++ b/net/minecraft/world/entity/vehicle/EntityMinecartCommandBlock.java -@@ -143,5 +143,12 @@ +@@ -140,5 +140,12 @@ public boolean isValid() { return !EntityMinecartCommandBlock.this.isRemoved(); } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartContainer.patch b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartContainer.patch index 46407b55cd..4966dee1ee 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartContainer.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartContainer.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/entity/vehicle/EntityMinecartContainer.java +++ b/net/minecraft/world/entity/vehicle/EntityMinecartContainer.java -@@ -19,6 +19,15 @@ - import net.minecraft.world.level.World; +@@ -21,6 +21,15 @@ import net.minecraft.world.level.storage.loot.LootTable; + import net.minecraft.world.phys.Vec3D; +// CraftBukkit start +import java.util.List; @@ -16,7 +16,7 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract implements ContainerEntity { private NonNullList itemStacks; -@@ -26,14 +35,55 @@ +@@ -28,9 +37,50 @@ public ResourceKey lootTable; public long lootTableSeed; @@ -67,14 +67,8 @@ + this.itemStacks = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); // CraftBukkit - SPIGOT-3513 } - protected EntityMinecartContainer(EntityTypes entitytypes, double d0, double d1, double d2, World world) { - super(entitytypes, world, d0, d1, d2); -- this.itemStacks = NonNullList.withSize(36, ItemStack.EMPTY); -+ this.itemStacks = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); // CraftBukkit - SPIGOT-3513 - } - @Override -@@ -77,11 +127,18 @@ +@@ -74,11 +124,18 @@ @Override public void remove(Entity.RemovalReason entity_removalreason) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartTNT.patch b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartTNT.patch index 8072b60894..c43684fd34 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartTNT.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityMinecartTNT.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/vehicle/EntityMinecartTNT.java +++ b/net/minecraft/world/entity/vehicle/EntityMinecartTNT.java -@@ -23,6 +23,11 @@ +@@ -26,6 +26,11 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.material.Fluid; @@ -12,20 +12,28 @@ public class EntityMinecartTNT extends EntityMinecartAbstract { private static final byte EVENT_PRIME = 10; -@@ -113,8 +118,16 @@ - d1 = 5.0D; - } +@@ -33,6 +38,7 @@ + private static final float DEFAULT_EXPLOSION_POWER_BASE = 4.0F; + public int fuse = -1; + public float explosionPowerBase = 4.0F; ++ public boolean isIncendiary = false; // CraftBukkit - add field -- this.level().explode(this, damagesource, (ExplosionDamageCalculator) null, this.getX(), this.getY(), this.getZ(), (float) (4.0D + this.random.nextDouble() * 1.5D * d1), false, World.a.TNT); + public EntityMinecartTNT(EntityTypes entitytypes, World world) { + super(entitytypes, world); +@@ -113,8 +119,16 @@ + if (world instanceof WorldServer worldserver) { + double d1 = Math.min(Math.sqrt(d0), 5.0D); + +- worldserver.explode(this, damagesource, (ExplosionDamageCalculator) null, this.getX(), this.getY(), this.getZ(), (float) ((double) this.explosionPowerBase + this.random.nextDouble() * 1.5D * d1), false, World.a.TNT); - this.discard(); + // CraftBukkit start -+ ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), (float) (4.0D + this.random.nextDouble() * 1.5D * d1), false); -+ this.level().getCraftServer().getPluginManager().callEvent(event); ++ ExplosionPrimeEvent event = new ExplosionPrimeEvent(this.getBukkitEntity(), (float) ((double) this.explosionPowerBase + this.random.nextDouble() * 1.5D * d1), this.isIncendiary); ++ worldserver.getCraftServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + fuse = -1; + return; + } -+ this.level().explode(this, damagesource, (ExplosionDamageCalculator) null, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), World.a.TNT); ++ worldserver.explode(this, damagesource, (ExplosionDamageCalculator) null, this.getX(), this.getY(), this.getZ(), event.getRadius(), event.getFire(), World.a.TNT); + // CraftBukkit end + this.discard(EntityRemoveEvent.Cause.EXPLODE); // CraftBukkit - add Bukkit remove cause } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/NewMinecartBehavior.patch b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/NewMinecartBehavior.patch new file mode 100644 index 0000000000..ef0b9564d3 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/NewMinecartBehavior.patch @@ -0,0 +1,70 @@ +--- a/net/minecraft/world/entity/vehicle/NewMinecartBehavior.java ++++ b/net/minecraft/world/entity/vehicle/NewMinecartBehavior.java +@@ -28,6 +28,11 @@ + import net.minecraft.world.phys.AxisAlignedBB; + import net.minecraft.world.phys.Vec3D; + ++// CraftBukkit start ++import org.bukkit.entity.Vehicle; ++import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; ++// CraftBukkit end ++ + public class NewMinecartBehavior extends MinecartBehavior { + + public static final int POS_ROT_LERP_TICKS = 3; +@@ -544,7 +549,7 @@ + + @Override + public double getSlowdownFactor() { +- return this.minecart.isVehicle() ? 0.997D : 0.975D; ++ return this.minecart.isVehicle() || !this.minecart.slowWhenEmpty ? 0.997D : 0.975D; // CraftBukkit - add !this.slowWhenEmpty + } + + @Override +@@ -571,6 +576,14 @@ + Entity entity = (Entity) iterator.next(); + + if (!(entity instanceof EntityHuman) && !(entity instanceof EntityIronGolem) && !(entity instanceof EntityMinecartAbstract) && !this.minecart.isVehicle() && !entity.isPassenger()) { ++ // CraftBukkit start ++ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent((Vehicle) this.minecart.getBukkitEntity(), entity.getBukkitEntity()); ++ this.level().getCraftServer().getPluginManager().callEvent(collisionEvent); ++ ++ if (collisionEvent.isCancelled()) { ++ continue; ++ } ++ // CraftBukkit end + boolean flag = entity.startRiding(this.minecart); + + if (flag) { +@@ -597,6 +610,16 @@ + Entity entity = (Entity) iterator.next(); + + if (entity instanceof EntityHuman || entity instanceof EntityIronGolem || entity instanceof EntityMinecartAbstract || this.minecart.isVehicle() || entity.isPassenger()) { ++ // CraftBukkit start ++ if (!this.minecart.isPassengerOfSameVehicle(entity)) { ++ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent((Vehicle) this.minecart.getBukkitEntity(), entity.getBukkitEntity()); ++ this.level().getCraftServer().getPluginManager().callEvent(collisionEvent); ++ ++ if (collisionEvent.isCancelled()) { ++ continue; ++ } ++ } ++ // CraftBukkit end + entity.push((Entity) this.minecart); + flag = true; + } +@@ -609,6 +632,14 @@ + Entity entity1 = (Entity) iterator1.next(); + + if (!this.minecart.hasPassenger(entity1) && entity1.isPushable() && entity1 instanceof EntityMinecartAbstract) { ++ // CraftBukkit start ++ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent((Vehicle) this.minecart.getBukkitEntity(), entity1.getBukkitEntity()); ++ this.level().getCraftServer().getPluginManager().callEvent(collisionEvent); ++ ++ if (collisionEvent.isCancelled()) { ++ continue; ++ } ++ // CraftBukkit end + entity1.push((Entity) this.minecart); + flag = true; + } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/OldMinecartBehavior.patch b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/OldMinecartBehavior.patch new file mode 100644 index 0000000000..3b43b93d54 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/OldMinecartBehavior.patch @@ -0,0 +1,70 @@ +--- a/net/minecraft/world/entity/vehicle/OldMinecartBehavior.java ++++ b/net/minecraft/world/entity/vehicle/OldMinecartBehavior.java +@@ -25,6 +25,11 @@ + import net.minecraft.world.phys.AxisAlignedBB; + import net.minecraft.world.phys.Vec3D; + ++// CraftBukkit start ++import org.bukkit.entity.Vehicle; ++import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; ++// CraftBukkit end ++ + public class OldMinecartBehavior extends MinecartBehavior { + + private static final double MINECART_RIDABLE_THRESHOLD = 0.01D; +@@ -454,8 +459,26 @@ + Entity entity = (Entity) iterator.next(); + + if (!(entity instanceof EntityHuman) && !(entity instanceof EntityIronGolem) && !(entity instanceof EntityMinecartAbstract) && !this.minecart.isVehicle() && !entity.isPassenger()) { ++ // CraftBukkit start ++ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent((Vehicle) this.minecart.getBukkitEntity(), entity.getBukkitEntity()); ++ this.level().getCraftServer().getPluginManager().callEvent(collisionEvent); ++ ++ if (collisionEvent.isCancelled()) { ++ continue; ++ } ++ // CraftBukkit end + entity.startRiding(this.minecart); + } else { ++ // CraftBukkit start ++ if (!this.minecart.isPassengerOfSameVehicle(entity)) { ++ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent((Vehicle) this.minecart.getBukkitEntity(), entity.getBukkitEntity()); ++ this.level().getCraftServer().getPluginManager().callEvent(collisionEvent); ++ ++ if (collisionEvent.isCancelled()) { ++ continue; ++ } ++ } ++ // CraftBukkit end + entity.push((Entity) this.minecart); + } + } +@@ -467,6 +490,14 @@ + Entity entity1 = (Entity) iterator1.next(); + + if (!this.minecart.hasPassenger(entity1) && entity1.isPushable() && entity1 instanceof EntityMinecartAbstract) { ++ // CraftBukkit start ++ VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent((Vehicle) this.minecart.getBukkitEntity(), entity1.getBukkitEntity()); ++ this.level().getCraftServer().getPluginManager().callEvent(collisionEvent); ++ ++ if (collisionEvent.isCancelled()) { ++ continue; ++ } ++ // CraftBukkit end + entity1.push((Entity) this.minecart); + } + } +@@ -487,11 +518,11 @@ + + @Override + public double getMaxSpeed(WorldServer worldserver) { +- return this.minecart.isInWater() ? 0.2D : 0.4D; ++ return (this.minecart.isInWater() ? this.minecart.maxSpeed / 2.0D: this.minecart.maxSpeed); // CraftBukkit + } + + @Override + public double getSlowdownFactor() { +- return this.minecart.isVehicle() ? 0.997D : 0.96D; ++ return this.minecart.isVehicle() || !this.minecart.slowWhenEmpty ? 0.997D : 0.96D; // CraftBukkit - add !this.slowWhenEmpty + } + } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/VehicleEntity.patch b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/VehicleEntity.patch index 69de92da46..7f20fdff30 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/VehicleEntity.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/VehicleEntity.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/vehicle/VehicleEntity.java +++ b/net/minecraft/world/entity/vehicle/VehicleEntity.java -@@ -14,6 +14,13 @@ +@@ -17,6 +17,13 @@ import net.minecraft.world.level.World; import net.minecraft.world.level.gameevent.GameEvent; @@ -14,42 +14,30 @@ public abstract class VehicleEntity extends Entity { protected static final DataWatcherObject DATA_ID_HURT = DataWatcher.defineId(VehicleEntity.class, DataWatcherRegistry.INT); -@@ -30,6 +37,18 @@ - if (this.isInvulnerableTo(damagesource)) { - return false; - } else { -+ // CraftBukkit start -+ Vehicle vehicle = (Vehicle) this.getBukkitEntity(); -+ org.bukkit.entity.Entity attacker = (damagesource.getEntity() == null) ? null : damagesource.getEntity().getBukkitEntity(); +@@ -40,6 +47,18 @@ + return false; + } else { + boolean flag; ++ // CraftBukkit start ++ Vehicle vehicle = (Vehicle) this.getBukkitEntity(); ++ org.bukkit.entity.Entity attacker = (damagesource.getEntity() == null) ? null : damagesource.getEntity().getBukkitEntity(); + -+ VehicleDamageEvent event = new VehicleDamageEvent(vehicle, attacker, (double) f); -+ this.level().getCraftServer().getPluginManager().callEvent(event); ++ VehicleDamageEvent event = new VehicleDamageEvent(vehicle, attacker, (double) f); ++ this.level().getCraftServer().getPluginManager().callEvent(event); + -+ if (event.isCancelled()) { -+ return false; -+ } -+ f = (float) event.getDamage(); -+ // CraftBukkit end ++ if (event.isCancelled()) { ++ return false; ++ } ++ f = (float) event.getDamage(); ++ // CraftBukkit end + label32: + { this.setHurtDir(-this.getHurtDir()); - this.setHurtTime(10); - this.markHurt(); -@@ -39,9 +58,27 @@ +@@ -65,9 +84,27 @@ - if ((flag || this.getDamage() <= 40.0F) && !this.shouldSourceDestroy(damagesource)) { - if (flag) { -- this.discard(); -+ // CraftBukkit start -+ VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, attacker); -+ this.level().getCraftServer().getPluginManager().callEvent(destroyEvent); -+ -+ if (destroyEvent.isCancelled()) { -+ this.setDamage(40.0F); // Maximize damage so this doesn't get triggered again right away -+ return true; -+ } -+ // CraftBukkit end -+ this.discard(EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause - } - } else { + if ((flag1 || this.getDamage() <= 40.0F) && !this.shouldSourceDestroy(damagesource)) { + if (flag1) { +- this.discard(); + // CraftBukkit start + VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, attacker); + this.level().getCraftServer().getPluginManager().callEvent(destroyEvent); @@ -59,6 +47,18 @@ + return true; + } + // CraftBukkit end - this.destroy(damagesource); ++ this.discard(EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause } + } else { ++ // CraftBukkit start ++ VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, attacker); ++ this.level().getCraftServer().getPluginManager().callEvent(destroyEvent); ++ ++ if (destroyEvent.isCancelled()) { ++ this.setDamage(40.0F); // Maximize damage so this doesn't get triggered again right away ++ return true; ++ } ++ // CraftBukkit end + this.destroy(worldserver, damagesource); + } diff --git a/paper-server/nms-patches/net/minecraft/world/food/FoodInfo.patch b/paper-server/nms-patches/net/minecraft/world/food/FoodInfo.patch new file mode 100644 index 0000000000..294900c931 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/food/FoodInfo.patch @@ -0,0 +1,22 @@ +--- a/net/minecraft/world/food/FoodInfo.java ++++ b/net/minecraft/world/food/FoodInfo.java +@@ -18,6 +18,10 @@ + import net.minecraft.world.item.component.ConsumableListener; + import net.minecraft.world.level.World; + ++// CraftBukkit start ++import net.minecraft.server.level.EntityPlayer; ++// CraftBukkit end ++ + public record FoodInfo(int nutrition, float saturation, boolean canAlwaysEat) implements ConsumableListener { + + public static final Codec DIRECT_CODEC = RecordCodecBuilder.create((instance) -> { +@@ -31,7 +35,7 @@ + + world.playSound((EntityHuman) null, entityliving.getX(), entityliving.getY(), entityliving.getZ(), (SoundEffect) consumable.sound().value(), SoundCategory.NEUTRAL, 1.0F, randomsource.triangle(1.0F, 0.4F)); + if (entityliving instanceof EntityHuman entityhuman) { +- entityhuman.getFoodData().eat(this); ++ entityhuman.getFoodData().eat(this, itemstack, (EntityPlayer) entityhuman); // CraftBukkit + world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.PLAYER_BURP, SoundCategory.PLAYERS, 0.5F, MathHelper.randomBetween(randomsource, 0.9F, 1.0F)); + } + diff --git a/paper-server/nms-patches/net/minecraft/world/food/FoodMetaData.patch b/paper-server/nms-patches/net/minecraft/world/food/FoodMetaData.patch index a697f51d2c..dc73325ee0 100644 --- a/paper-server/nms-patches/net/minecraft/world/food/FoodMetaData.patch +++ b/paper-server/nms-patches/net/minecraft/world/food/FoodMetaData.patch @@ -1,12 +1,11 @@ --- a/net/minecraft/world/food/FoodMetaData.java +++ b/net/minecraft/world/food/FoodMetaData.java -@@ -6,15 +6,34 @@ - import net.minecraft.world.entity.player.EntityHuman; +@@ -7,12 +7,22 @@ + import net.minecraft.world.EnumDifficulty; import net.minecraft.world.level.GameRules; +// CraftBukkit start +import net.minecraft.network.protocol.game.PacketPlayOutUpdateHealth; -+import net.minecraft.server.level.EntityPlayer; +import net.minecraft.world.item.ItemStack; +// CraftBukkit end + @@ -17,93 +16,81 @@ public float exhaustionLevel; private int tickTimer; + // CraftBukkit start -+ private EntityHuman entityhuman; + public int saturatedRegenRate = 10; + public int unsaturatedRegenRate = 80; + public int starvationRate = 80; + // CraftBukkit end - private int lastFoodLevel = 20; -- public FoodMetaData() {} -+ public FoodMetaData() { throw new AssertionError("Whoopsie, we missed the bukkit."); } // CraftBukkit start - throw an error -+ -+ // CraftBukkit start - added EntityHuman constructor -+ public FoodMetaData(EntityHuman entityhuman) { -+ org.apache.commons.lang.Validate.notNull(entityhuman); -+ this.entityhuman = entityhuman; -+ } -+ // CraftBukkit end + public FoodMetaData() {} - private void add(int i, float f) { - this.foodLevel = MathHelper.clamp(i + this.foodLevel, 0, 20); -@@ -29,6 +48,20 @@ +@@ -29,6 +39,20 @@ this.add(foodinfo.nutrition(), foodinfo.saturation()); } + // CraftBukkit start -+ public void eat(ItemStack itemstack, FoodInfo foodinfo) { ++ public void eat(FoodInfo foodinfo, ItemStack itemstack, EntityPlayer entityplayer) { + int oldFoodLevel = foodLevel; + -+ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, foodinfo.nutrition() + oldFoodLevel, itemstack); ++ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityplayer, foodinfo.nutrition() + oldFoodLevel, itemstack); + + if (!event.isCancelled()) { + this.add(event.getFoodLevel() - oldFoodLevel, foodinfo.saturation()); + } + -+ ((EntityPlayer) entityhuman).getBukkitEntity().sendHealthUpdate(); ++ entityplayer.getBukkitEntity().sendHealthUpdate(); + } + // CraftBukkit end + - public void tick(EntityHuman entityhuman) { - EnumDifficulty enumdifficulty = entityhuman.level().getDifficulty(); - -@@ -38,7 +71,15 @@ + public void tick(EntityPlayer entityplayer) { + WorldServer worldserver = entityplayer.serverLevel(); + EnumDifficulty enumdifficulty = worldserver.getDifficulty(); +@@ -38,7 +62,15 @@ if (this.saturationLevel > 0.0F) { this.saturationLevel = Math.max(this.saturationLevel - 1.0F, 0.0F); } else if (enumdifficulty != EnumDifficulty.PEACEFUL) { - this.foodLevel = Math.max(this.foodLevel - 1, 0); + // CraftBukkit start -+ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, Math.max(this.foodLevel - 1, 0)); ++ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityplayer, Math.max(this.foodLevel - 1, 0)); + + if (!event.isCancelled()) { + this.foodLevel = event.getFoodLevel(); + } + -+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutUpdateHealth(((EntityPlayer) entityhuman).getBukkitEntity().getScaledHealth(), this.foodLevel, this.saturationLevel)); ++ entityplayer.connection.send(new PacketPlayOutUpdateHealth(entityplayer.getBukkitEntity().getScaledHealth(), this.foodLevel, this.saturationLevel)); + // CraftBukkit end } } -@@ -46,23 +87,25 @@ +@@ -46,23 +78,25 @@ - if (flag && this.saturationLevel > 0.0F && entityhuman.isHurt() && this.foodLevel >= 20) { + if (flag && this.saturationLevel > 0.0F && entityplayer.isHurt() && this.foodLevel >= 20) { ++this.tickTimer; - if (this.tickTimer >= 10) { + if (this.tickTimer >= this.saturatedRegenRate) { // CraftBukkit float f = Math.min(this.saturationLevel, 6.0F); -- entityhuman.heal(f / 6.0F); +- entityplayer.heal(f / 6.0F); - this.addExhaustion(f); -+ entityhuman.heal(f / 6.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason ++ entityplayer.heal(f / 6.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason + // this.addExhaustion(f); CraftBukkit - EntityExhaustionEvent -+ entityhuman.causeFoodExhaustion(f, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent ++ entityplayer.causeFoodExhaustion(f, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent this.tickTimer = 0; } - } else if (flag && this.foodLevel >= 18 && entityhuman.isHurt()) { + } else if (flag && this.foodLevel >= 18 && entityplayer.isHurt()) { ++this.tickTimer; - if (this.tickTimer >= 80) { -- entityhuman.heal(1.0F); +- entityplayer.heal(1.0F); - this.addExhaustion(6.0F); + if (this.tickTimer >= this.unsaturatedRegenRate) { // CraftBukkit - add regen rate manipulation -+ entityhuman.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason -+ // this.a(6.0F); CraftBukkit - EntityExhaustionEvent -+ entityhuman.causeFoodExhaustion(6.0f, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent ++ entityplayer.heal(1.0F, org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.SATIATED); // CraftBukkit - added RegainReason ++ // this.addExhaustion(6.0F); CraftBukkit - EntityExhaustionEvent ++ entityplayer.causeFoodExhaustion(6.0f, org.bukkit.event.entity.EntityExhaustionEvent.ExhaustionReason.REGEN); // CraftBukkit - EntityExhaustionEvent this.tickTimer = 0; } } else if (this.foodLevel <= 0) { ++this.tickTimer; - if (this.tickTimer >= 80) { + if (this.tickTimer >= this.starvationRate) { // CraftBukkit - add regen rate manipulation - if (entityhuman.getHealth() > 10.0F || enumdifficulty == EnumDifficulty.HARD || entityhuman.getHealth() > 1.0F && enumdifficulty == EnumDifficulty.NORMAL) { - entityhuman.hurt(entityhuman.damageSources().starve(), 1.0F); + if (entityplayer.getHealth() > 10.0F || enumdifficulty == EnumDifficulty.HARD || entityplayer.getHealth() > 1.0F && enumdifficulty == EnumDifficulty.NORMAL) { + entityplayer.hurtServer(worldserver, entityplayer.damageSources().starve(), 1.0F); } diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/AbstractCraftingMenu.patch b/paper-server/nms-patches/net/minecraft/world/inventory/AbstractCraftingMenu.patch new file mode 100644 index 0000000000..d0ab6955ca --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/inventory/AbstractCraftingMenu.patch @@ -0,0 +1,41 @@ +--- a/net/minecraft/world/inventory/AbstractCraftingMenu.java ++++ b/net/minecraft/world/inventory/AbstractCraftingMenu.java +@@ -13,14 +13,17 @@ + + private final int width; + private final int height; +- public final InventoryCrafting craftSlots; ++ public final TransientCraftingContainer craftSlots; // CraftBukkit + public final InventoryCraftResult resultSlots = new InventoryCraftResult(); + +- public AbstractCraftingMenu(Containers containers, int i, int j, int k) { ++ public AbstractCraftingMenu(Containers containers, int i, int j, int k, PlayerInventory playerInventory) { // CraftBukkit + super(containers, i); + this.width = j; + this.height = k; +- this.craftSlots = new TransientCraftingContainer(this, j, k); ++ // CraftBukkit start ++ this.craftSlots = new TransientCraftingContainer(this, j, k, playerInventory.player); // CraftBukkit - pass player ++ this.craftSlots.resultInventory = this.resultSlots; // CraftBukkit - let InventoryCrafting know about its result slot ++ // CraftBukkit end + } + + protected Slot addResultSlot(EntityHuman entityhuman, int i, int j) { +@@ -38,7 +41,7 @@ + + @Override + public ContainerRecipeBook.a handlePlacement(boolean flag, boolean flag1, RecipeHolder recipeholder, WorldServer worldserver, PlayerInventory playerinventory) { +- RecipeHolder recipeholder1 = recipeholder; ++ RecipeHolder recipeholder1 = (RecipeHolder) recipeholder; // CraftBukkit - decompile error + + this.beginPlacingRecipe(); + +@@ -65,7 +68,7 @@ + } + }, this.width, this.height, list, list, playerinventory, recipeholder1, flag, flag1); + } finally { +- this.finishPlacingRecipe(worldserver, recipeholder); ++ this.finishPlacingRecipe(worldserver, recipeholder1); // CraftBukkit - decompile error + } + + return containerrecipebook_a; diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/Container.patch b/paper-server/nms-patches/net/minecraft/world/inventory/Container.patch index 9e3afe1d72..89229c657f 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/Container.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/Container.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/Container.java +++ b/net/minecraft/world/inventory/Container.java -@@ -33,6 +33,20 @@ +@@ -35,6 +35,20 @@ import net.minecraft.world.level.block.entity.TileEntity; import org.slf4j.Logger; @@ -21,7 +21,7 @@ public abstract class Container { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -63,6 +77,27 @@ +@@ -67,6 +81,27 @@ private ContainerSynchronizer synchronizer; private boolean suppressRemoteUpdates; @@ -49,7 +49,7 @@ protected Container(@Nullable Containers containers, int i) { this.carried = ItemStack.EMPTY; this.remoteSlots = NonNullList.create(); -@@ -164,6 +199,15 @@ +@@ -192,6 +227,15 @@ } @@ -65,7 +65,7 @@ public void removeSlotListener(ICrafting icrafting) { this.containerListeners.remove(icrafting); } -@@ -380,7 +424,7 @@ +@@ -417,7 +461,7 @@ } } else if (this.quickcraftStatus == 2) { if (!this.quickcraftSlots.isEmpty()) { @@ -74,7 +74,7 @@ k = ((Slot) this.quickcraftSlots.iterator().next()).index; this.resetQuickCraft(); this.doClick(k, this.quickcraftType, InventoryClickType.PICKUP, entityhuman); -@@ -396,6 +440,7 @@ +@@ -433,6 +477,7 @@ l = this.getCarried().getCount(); Iterator iterator = this.quickcraftSlots.iterator(); @@ -82,7 +82,7 @@ while (iterator.hasNext()) { Slot slot1 = (Slot) iterator.next(); ItemStack itemstack2 = this.getCarried(); -@@ -406,12 +451,48 @@ +@@ -443,12 +488,48 @@ int l1 = Math.min(getQuickCraftPlaceCount(this.quickcraftSlots, this.quickcraftType, itemstack1) + j1, k1); l -= l1 - j1; @@ -134,7 +134,7 @@ } this.resetQuickCraft(); -@@ -429,8 +510,11 @@ +@@ -466,8 +547,11 @@ if (i == -999) { if (!this.getCarried().isEmpty()) { if (clickaction == ClickAction.PRIMARY) { @@ -147,7 +147,7 @@ } else { entityhuman.drop(this.getCarried().split(1), true); } -@@ -493,6 +577,15 @@ +@@ -530,6 +614,15 @@ } slot.setChanged(); @@ -163,23 +163,18 @@ } } else { int j2; -@@ -609,13 +702,14 @@ +@@ -662,8 +755,9 @@ ItemStack itemstack = this.getCarried(); if (!itemstack.isEmpty()) { + this.setCarried(ItemStack.EMPTY); // CraftBukkit - SPIGOT-4556 - from below - if (entityhuman.isAlive() && !((EntityPlayer) entityhuman).hasDisconnected()) { - entityhuman.getInventory().placeItemBackInInventory(itemstack); - } else { - entityhuman.drop(itemstack, false); - } - + dropOrPlaceInInventory(entityhuman, itemstack); - this.setCarried(ItemStack.EMPTY); + // this.setCarried(ItemStack.EMPTY); // CraftBukkit - moved up } - } -@@ -830,6 +924,11 @@ + } +@@ -893,6 +987,11 @@ } public ItemStack getCarried() { diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvil.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvil.patch index 7cf494102d..74393b2c85 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvil.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvil.patch @@ -11,7 +11,7 @@ public class ContainerAnvil extends ContainerAnvilAbstract { public static final int INPUT_SLOT = 0; -@@ -44,6 +48,11 @@ +@@ -45,6 +49,11 @@ private static final int ADDITIONAL_SLOT_X_PLACEMENT = 76; private static final int RESULT_SLOT_X_PLACEMENT = 134; private static final int SLOT_Y_PLACEMENT = 47; @@ -23,7 +23,7 @@ public ContainerAnvil(int i, PlayerInventory playerinventory) { this(i, playerinventory, ContainerAccess.NULL); -@@ -71,7 +80,7 @@ +@@ -72,7 +81,7 @@ @Override protected boolean mayPickup(EntityHuman entityhuman, boolean flag) { @@ -38,11 +38,11 @@ - this.cost.set(0); + this.cost.set(DEFAULT_DENIED_COST); // CraftBukkit - use a variable for set a cost for denied item + this.inputSlots.setItem(0, ItemStack.EMPTY); this.access.execute((world, blockposition) -> { IBlockData iblockdata = world.getBlockState(blockposition); - -@@ -141,8 +150,8 @@ - if (itemstack1.isDamageableItem() && itemstack1.getItem().isValidRepairItem(itemstack, itemstack2)) { +@@ -143,8 +152,8 @@ + if (itemstack1.isDamageableItem() && itemstack.isValidRepairItem(itemstack2)) { k = Math.min(itemstack1.getDamageValue(), itemstack1.getMaxDamage() / 4); if (k <= 0) { - this.resultSlots.setItem(0, ItemStack.EMPTY); @@ -52,7 +52,7 @@ return; } -@@ -156,8 +165,8 @@ +@@ -158,8 +167,8 @@ this.repairItemCountCost = i1; } else { if (!flag && (!itemstack1.is(itemstack2.getItem()) || !itemstack1.isDamageableItem())) { @@ -63,7 +63,7 @@ return; } -@@ -231,8 +240,8 @@ +@@ -233,8 +242,8 @@ } if (flag2 && !flag1) { @@ -74,14 +74,17 @@ return; } } -@@ -257,11 +266,11 @@ - itemstack1 = ItemStack.EMPTY; +@@ -260,14 +269,14 @@ } -- if (b0 == i && b0 > 0 && this.cost.get() >= 40) { -- this.cost.set(39); -+ if (b0 == i && b0 > 0 && this.cost.get() >= maximumRepairCost) { // CraftBukkit -+ this.cost.set(maximumRepairCost - 1); // CraftBukkit + if (b0 == i && b0 > 0) { +- if (this.cost.get() >= 40) { +- this.cost.set(39); ++ if (this.cost.get() >= maximumRepairCost) { // CraftBukkit ++ this.cost.set(maximumRepairCost - 1); // CraftBukkit + } + + this.onlyRenaming = true; } - if (this.cost.get() >= 40 && !this.player.getAbilities().instabuild) { @@ -89,7 +92,7 @@ itemstack1 = ItemStack.EMPTY; } -@@ -279,11 +288,12 @@ +@@ -285,11 +294,12 @@ EnchantmentManager.setEnchantments(itemstack1, itemenchantments_a.toImmutable()); } @@ -105,7 +108,7 @@ } } -@@ -323,4 +333,19 @@ +@@ -329,4 +339,19 @@ public int getCost() { return this.cost.get(); } diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvilAbstract.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvilAbstract.patch index 4c76c0b1b8..204c7d1c05 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvilAbstract.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvilAbstract.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/ContainerAnvilAbstract.java +++ b/net/minecraft/world/inventory/ContainerAnvilAbstract.java -@@ -47,7 +47,7 @@ +@@ -50,7 +50,7 @@ while (iterator.hasNext()) { final ItemCombinerMenuSlotDefinition.b itemcombinermenuslotdefinition_b = (ItemCombinerMenuSlotDefinition.b) iterator.next(); @@ -9,7 +9,7 @@ @Override public boolean mayPlace(ItemStack itemstack) { return itemcombinermenuslotdefinition_b.mayPlace().test(itemstack); -@@ -124,6 +124,7 @@ +@@ -110,6 +110,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerBeacon.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerBeacon.patch index 363244fc4f..b15494388c 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerBeacon.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerBeacon.patch @@ -33,7 +33,7 @@ @Override public boolean canPlaceItem(int j, ItemStack itemstack) { return itemstack.is(TagsItem.BEACON_PAYMENT_ITEMS); -@@ -83,6 +93,7 @@ +@@ -69,6 +79,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { @@ -41,7 +41,7 @@ return stillValid(this.access, entityhuman, Blocks.BEACON); } -@@ -164,8 +175,8 @@ +@@ -150,8 +161,8 @@ public void updateEffects(Optional> optional, Optional> optional1) { if (this.paymentSlot.hasItem()) { @@ -52,7 +52,7 @@ this.paymentSlot.remove(1); this.access.execute(World::blockEntityChanged); } -@@ -192,4 +203,17 @@ +@@ -178,4 +189,17 @@ return 1; } } diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerBrewingStand.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerBrewingStand.patch index 0c45c771e2..ea84f45258 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerBrewingStand.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerBrewingStand.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/ContainerBrewingStand.java +++ b/net/minecraft/world/inventory/ContainerBrewingStand.java -@@ -15,6 +15,11 @@ +@@ -16,6 +16,11 @@ import net.minecraft.world.item.alchemy.PotionContents; import net.minecraft.world.item.alchemy.PotionRegistry; @@ -12,7 +12,7 @@ public class ContainerBrewingStand extends Container { private static final int BOTTLE_SLOT_START = 0; -@@ -31,12 +36,18 @@ +@@ -32,12 +37,18 @@ private final IContainerProperties brewingStandData; private final Slot ingredientSlot; @@ -31,7 +31,7 @@ checkContainerSize(iinventory, 5); checkContainerDataCount(icontainerproperties, 2); this.brewingStand = iinventory; -@@ -66,6 +77,7 @@ +@@ -55,6 +66,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { @@ -39,8 +39,8 @@ return this.brewingStand.stillValid(entityhuman); } -@@ -196,4 +208,17 @@ - return itemstack.is(Items.BLAZE_POWDER); +@@ -185,4 +197,17 @@ + return itemstack.is(TagsItem.BREWING_FUEL); } } + diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerCartography.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerCartography.patch index fce0e9670a..3872eb8c69 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerCartography.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerCartography.patch @@ -62,7 +62,7 @@ + this.addSlot(new Slot(this.container, 0, 15, 15) { // CraftBukkit - decompile error @Override public boolean mayPlace(ItemStack itemstack) { - return itemstack.is(Items.FILLED_MAP); + return itemstack.has(DataComponents.MAP_ID); } }); - this.addSlot(new Slot(this, this.container, 1, 15, 52) { @@ -70,10 +70,10 @@ @Override public boolean mayPlace(ItemStack itemstack) { return itemstack.is(Items.PAPER) || itemstack.is(Items.MAP) || itemstack.is(Items.GLASS_PANE); -@@ -97,10 +133,12 @@ - this.addSlot(new Slot(playerinventory, j, 8 + j * 18, 142)); - } - +@@ -85,10 +121,12 @@ + } + }); + this.addStandardInventorySlots(playerinventory, 8, 84); + player = (Player) playerinventory.player.getBukkitEntity(); // CraftBukkit } diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerChest.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerChest.patch index e955215fd1..cdc889f17a 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerChest.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerChest.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/ContainerChest.java +++ b/net/minecraft/world/inventory/ContainerChest.java -@@ -6,11 +6,40 @@ +@@ -6,10 +6,39 @@ import net.minecraft.world.entity.player.PlayerInventory; import net.minecraft.world.item.ItemStack; @@ -12,7 +12,6 @@ + public class ContainerChest extends Container { - private static final int SLOTS_PER_ROW = 9; private final IInventory container; private final int containerRows; + // CraftBukkit start @@ -41,18 +40,17 @@ private ContainerChest(Containers containers, int i, PlayerInventory playerinventory, int j) { this(containers, i, playerinventory, new InventorySubcontainer(9 * j), j); -@@ -56,6 +85,10 @@ +@@ -53,6 +82,9 @@ + this.container = iinventory; + this.containerRows = j; iinventory.startOpen(playerinventory.player); - int k = (this.containerRows - 4) * 18; - + // CraftBukkit start - Save player + this.player = playerinventory; + // CraftBukkit end -+ - int l; - int i1; + boolean flag = true; -@@ -79,6 +112,7 @@ + this.addChestGrid(iinventory, 8, 18); +@@ -72,6 +104,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerDispenser.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerDispenser.patch index a678f092ce..682cb82ec5 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerDispenser.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerDispenser.patch @@ -34,7 +34,7 @@ checkContainerSize(iinventory, 9); this.dispenser = iinventory; iinventory.startOpen(playerinventory.player); -@@ -48,6 +61,7 @@ +@@ -41,6 +54,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { @@ -42,7 +42,7 @@ return this.dispenser.stillValid(entityhuman); } -@@ -89,4 +103,17 @@ +@@ -82,4 +96,17 @@ super.removed(entityhuman); this.dispenser.stopOpen(entityhuman); } diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerEnchantTable.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerEnchantTable.patch index 6b02e272ec..b30ed5ecb9 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerEnchantTable.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerEnchantTable.patch @@ -61,7 +61,7 @@ @Override public boolean mayPlace(ItemStack itemstack) { return itemstack.is(Items.LAPIS_LAZULI); -@@ -101,6 +125,9 @@ +@@ -89,6 +113,9 @@ this.addDataSlot(ContainerProperty.shared(this.levelClue, 0)); this.addDataSlot(ContainerProperty.shared(this.levelClue, 1)); this.addDataSlot(ContainerProperty.shared(this.levelClue, 2)); @@ -71,16 +71,16 @@ } @Override -@@ -108,7 +135,7 @@ +@@ -96,7 +123,7 @@ if (iinventory == this.enchantSlots) { ItemStack itemstack = iinventory.getItem(0); - if (!itemstack.isEmpty() && itemstack.isEnchantable()) { + if (!itemstack.isEmpty()) { // CraftBukkit - relax condition this.access.execute((world, blockposition) -> { - Registry> registry = world.registryAccess().registryOrThrow(Registries.ENCHANTMENT).asHolderIdMap(); + Registry> registry = world.registryAccess().lookupOrThrow(Registries.ENCHANTMENT).asHolderIdMap(); int i = 0; -@@ -148,6 +175,41 @@ +@@ -136,6 +163,41 @@ } } @@ -122,14 +122,14 @@ this.broadcastChanges(); }); } else { -@@ -175,21 +237,46 @@ +@@ -163,21 +225,46 @@ ItemStack itemstack2 = itemstack; List list = this.getEnchantmentList(world.registryAccess(), itemstack, i, this.costs[i]); - if (!list.isEmpty()) { - entityhuman.onEnchantmentPerformed(itemstack, j); + // CraftBukkit start -+ Registry> registry = world.registryAccess().registryOrThrow(Registries.ENCHANTMENT).asHolderIdMap(); ++ Registry> registry = world.registryAccess().lookupOrThrow(Registries.ENCHANTMENT).asHolderIdMap(); + if (true || !list.isEmpty()) { + // entityhuman.onEnchantmentPerformed(itemstack, j); // Moved down + Map enchants = new java.util.HashMap(); @@ -175,7 +175,7 @@ itemstack1.consume(j, entityhuman); if (itemstack1.isEmpty()) { this.enchantSlots.setItem(1, ItemStack.EMPTY); -@@ -256,6 +343,7 @@ +@@ -244,6 +331,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { @@ -183,7 +183,7 @@ return stillValid(this.access, entityhuman, Blocks.ENCHANTING_TABLE); } -@@ -306,4 +394,17 @@ +@@ -294,4 +382,17 @@ return itemstack; } diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerFurnace.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerFurnace.patch index 2bffe3f9c3..9720bf6a9f 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerFurnace.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerFurnace.patch @@ -1,19 +1,20 @@ --- a/net/minecraft/world/inventory/ContainerFurnace.java +++ b/net/minecraft/world/inventory/ContainerFurnace.java -@@ -14,6 +14,11 @@ +@@ -18,6 +18,12 @@ + import net.minecraft.world.item.crafting.SingleRecipeInput; import net.minecraft.world.level.World; - import net.minecraft.world.level.block.entity.TileEntityFurnace; +// CraftBukkit start ++import net.minecraft.world.level.block.entity.TileEntityFurnace; +import org.bukkit.craftbukkit.inventory.CraftInventoryFurnace; +import org.bukkit.craftbukkit.inventory.view.CraftFurnaceView; +// CraftBukkit end + - public abstract class ContainerFurnace extends ContainerRecipeBook { + public abstract class ContainerFurnace extends ContainerRecipeBook { public static final int INGREDIENT_SLOT = 0; -@@ -31,6 +36,22 @@ - private final Recipes recipeType; +@@ -36,6 +42,22 @@ + private final RecipePropertySet acceptedInputs; private final RecipeBookType recipeBookType; + // CraftBukkit start @@ -32,18 +33,18 @@ + } + // CraftBukkit end + - protected ContainerFurnace(Containers containers, Recipes recipes, RecipeBookType recipebooktype, int i, PlayerInventory playerinventory) { - this(containers, recipes, recipebooktype, i, playerinventory, new InventorySubcontainer(3), new ContainerProperties(4)); + protected ContainerFurnace(Containers containers, Recipes recipes, ResourceKey resourcekey, RecipeBookType recipebooktype, int i, PlayerInventory playerinventory) { + this(containers, recipes, resourcekey, recipebooktype, i, playerinventory, new InventorySubcontainer(3), new ContainerProperties(4)); } -@@ -47,6 +68,7 @@ +@@ -53,6 +75,7 @@ this.addSlot(new Slot(iinventory, 0, 56, 17)); this.addSlot(new SlotFurnaceFuel(this, iinventory, 1, 56, 53)); this.addSlot(new SlotFurnaceResult(playerinventory.player, iinventory, 2, 116, 35)); + this.player = playerinventory; // CraftBukkit - save player - - int j; - -@@ -104,6 +126,7 @@ + this.addStandardInventorySlots(playerinventory, 8, 84); + this.addDataSlots(icontainerproperties); + } +@@ -71,6 +94,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { @@ -51,3 +52,11 @@ return this.container.stillValid(entityhuman); } +@@ -180,6 +204,6 @@ + public boolean recipeMatches(RecipeHolder recipeholder1) { + return ((RecipeCooking) recipeholder1.value()).matches(new SingleRecipeInput(ContainerFurnace.this.container.getItem(0)), worldserver); + } +- }, 1, 1, List.of(this.getSlot(0)), list, playerinventory, recipeholder, flag, flag1); ++ }, 1, 1, List.of(this.getSlot(0)), list, playerinventory, (RecipeHolder) recipeholder, flag, flag1); // CraftBukkit - decompile error + } + } diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerGrindstone.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerGrindstone.patch index e35e128c0c..2ad13b2149 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerGrindstone.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerGrindstone.patch @@ -56,15 +56,15 @@ @Override public boolean mayPlace(ItemStack itemstack) { return itemstack.isDamageableItem() || EnchantmentManager.hasAnyEnchantments(itemstack); -@@ -125,6 +154,7 @@ - this.addSlot(new Slot(playerinventory, j, 8 + j * 18, 142)); - } - +@@ -113,6 +142,7 @@ + } + }); + this.addStandardInventorySlots(playerinventory, 8, 84); + player = (Player) playerinventory.player.getBukkitEntity(); // CraftBukkit } @Override -@@ -137,7 +167,8 @@ +@@ -125,7 +155,8 @@ } private void createResult() { @@ -74,7 +74,7 @@ this.broadcastChanges(); } -@@ -239,6 +270,7 @@ +@@ -227,6 +258,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerHopper.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerHopper.patch index 1a6a55058d..4f0fd9ab09 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerHopper.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerHopper.patch @@ -40,8 +40,8 @@ + this.player = playerinventory; // CraftBukkit - save player checkContainerSize(iinventory, 5); iinventory.startOpen(playerinventory.player); - boolean flag = true; -@@ -42,6 +64,7 @@ + +@@ -30,6 +52,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerHorse.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerHorse.patch index 88d6bafdb2..ef136c313f 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerHorse.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerHorse.patch @@ -12,7 +12,7 @@ public class ContainerHorse extends Container { private final IInventory horseContainer; -@@ -18,8 +23,23 @@ +@@ -18,13 +23,28 @@ private static final int SLOT_BODY_ARMOR = 1; private static final int SLOT_HORSE_INVENTORY_START = 2; @@ -36,16 +36,13 @@ this.horseContainer = iinventory; this.armorContainer = entityhorseabstract.getBodyArmorAccess(); this.horse = entityhorseabstract; -@@ -28,7 +48,7 @@ iinventory.startOpen(playerinventory.player); - boolean flag1 = true; - - this.addSlot(new Slot(this, iinventory, 0, 8, 18) { + this.addSlot(new Slot(iinventory, 0, 8, 18) { // CraftBukkit - decompile error @Override public boolean mayPlace(ItemStack itemstack) { return itemstack.is(Items.SADDLE) && !this.hasItem() && entityhorseabstract.isSaddleable(); -@@ -39,7 +59,7 @@ +@@ -35,7 +55,7 @@ return entityhorseabstract.isSaddleable(); } }); @@ -53,4 +50,4 @@ + this.addSlot(new ArmorSlot(this.armorContainer, entityhorseabstract, EnumItemSlot.BODY, 0, 8, 36, (MinecraftKey) null) { // CraftBukkit - decompile error @Override public boolean mayPlace(ItemStack itemstack) { - return entityhorseabstract.isBodyArmorItem(itemstack); + return entityhorseabstract.isEquippableInSlot(itemstack, EnumItemSlot.BODY); diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerLoom.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerLoom.patch index 002f671a44..ff61f6da0f 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerLoom.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerLoom.patch @@ -77,8 +77,8 @@ @Override public boolean mayPlace(ItemStack itemstack) { return itemstack.getItem() instanceof ItemBannerPattern; -@@ -128,10 +164,12 @@ - +@@ -116,10 +152,12 @@ + this.addStandardInventorySlots(playerinventory, 8, 84); this.addDataSlot(this.selectedBannerPatternIndex); this.patternGetter = playerinventory.player.registryAccess().lookupOrThrow(Registries.BANNER_PATTERN); + player = (Player) playerinventory.player.getBukkitEntity(); // CraftBukkit @@ -90,7 +90,7 @@ return stillValid(this.access, entityhuman, Blocks.LOOM); } -@@ -306,6 +344,11 @@ +@@ -294,6 +332,11 @@ EnumColor enumcolor = ((ItemDye) itemstack1.getItem()).getDyeColor(); itemstack2.update(DataComponents.BANNER_PATTERNS, BannerPatternLayers.EMPTY, (bannerpatternlayers) -> { diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerMerchant.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerMerchant.patch index c7e8e5cd92..6f8db52e2d 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerMerchant.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerMerchant.patch @@ -34,10 +34,10 @@ this.addSlot(new Slot(this.tradeContainer, 1, 162, 37)); this.addSlot(new SlotMerchantResult(playerinventory.player, imerchant, this.tradeContainer, 2, 220, 37)); + this.player = playerinventory; // CraftBukkit - save player + this.addStandardInventorySlots(playerinventory, 108, 84); + } - int j; - -@@ -155,7 +171,7 @@ +@@ -143,7 +159,7 @@ } private void playTradeSound() { diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerPlayer.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerPlayer.patch index 0c5eaf1b27..f66a82c799 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerPlayer.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerPlayer.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/inventory/ContainerPlayer.java +++ b/net/minecraft/world/inventory/ContainerPlayer.java @@ -13,6 +13,12 @@ - import net.minecraft.world.item.crafting.RecipeCrafting; import net.minecraft.world.item.crafting.RecipeHolder; + import net.minecraft.world.level.World; +// CraftBukkit start +import net.minecraft.network.chat.IChatBaseComponent; @@ -10,52 +10,38 @@ +import org.bukkit.craftbukkit.inventory.CraftInventoryView; +// CraftBukkit end + - public class ContainerPlayer extends ContainerRecipeBook { + public class ContainerPlayer extends AbstractCraftingMenu { public static final int CONTAINER_ID = 0; -@@ -36,15 +42,28 @@ - public static final MinecraftKey EMPTY_ARMOR_SLOT_SHIELD = MinecraftKey.withDefaultNamespace("item/empty_armor_slot_shield"); - private static final Map TEXTURE_EMPTY_SLOTS = Map.of(EnumItemSlot.FEET, ContainerPlayer.EMPTY_ARMOR_SLOT_BOOTS, EnumItemSlot.LEGS, ContainerPlayer.EMPTY_ARMOR_SLOT_LEGGINGS, EnumItemSlot.CHEST, ContainerPlayer.EMPTY_ARMOR_SLOT_CHESTPLATE, EnumItemSlot.HEAD, ContainerPlayer.EMPTY_ARMOR_SLOT_HELMET); +@@ -40,9 +46,15 @@ private static final EnumItemSlot[] SLOT_IDS = new EnumItemSlot[]{EnumItemSlot.HEAD, EnumItemSlot.CHEST, EnumItemSlot.LEGS, EnumItemSlot.FEET}; -- private final InventoryCrafting craftSlots = new TransientCraftingContainer(this, 2, 2); -- private final InventoryCraftResult resultSlots = new InventoryCraftResult(); -+ // CraftBukkit start -+ private final TransientCraftingContainer craftSlots; -+ private final InventoryCraftResult resultSlots; -+ // CraftBukkit end public final boolean active; private final EntityHuman owner; + // CraftBukkit start + private CraftInventoryView bukkitEntity = null; -+ private PlayerInventory player; + // CraftBukkit end public ContainerPlayer(PlayerInventory playerinventory, boolean flag, final EntityHuman entityhuman) { - super((Containers) null, 0); - this.active = flag; - this.owner = entityhuman; +- super((Containers) null, 0, 2, 2); + // CraftBukkit start -+ this.resultSlots = new InventoryCraftResult(); // CraftBukkit - moved to before InventoryCrafting construction -+ this.craftSlots = new TransientCraftingContainer(this, 2, 2, playerinventory.player); // CraftBukkit - pass player -+ this.craftSlots.resultInventory = this.resultSlots; // CraftBukkit - let InventoryCrafting know about its result slot -+ this.player = playerinventory; // CraftBukkit - save player ++ super((Containers) null, 0, 2, 2, playerinventory); // CraftBukkit - save player + setTitle(IChatBaseComponent.translatable("container.crafting")); // SPIGOT-4722: Allocate title for player inventory + // CraftBukkit end - this.addSlot(new SlotResult(playerinventory.player, this.craftSlots, this.resultSlots, 0, 154, 28)); - - int i; -@@ -73,7 +92,7 @@ - this.addSlot(new Slot(playerinventory, i, 8 + i * 18, 142)); + this.active = flag; + this.owner = entityhuman; + this.addResultSlot(entityhuman, 154, 28); +@@ -56,7 +68,7 @@ } + this.addStandardInventorySlots(playerinventory, 8, 84); - this.addSlot(new Slot(this, playerinventory, 40, 77, 62) { + this.addSlot(new Slot(playerinventory, 40, 77, 62) { // CraftBukkit - decompile error @Override public void setByPlayer(ItemStack itemstack, ItemStack itemstack1) { entityhuman.onEquipItem(EnumItemSlot.OFFHAND, itemstack1, itemstack); -@@ -230,4 +249,17 @@ - public boolean shouldMoveToInventory(int i) { - return i != this.getResultSlotIndex(); +@@ -192,4 +204,17 @@ + protected EntityHuman owner() { + return this.owner; } + + // CraftBukkit start @@ -66,7 +52,7 @@ + } + + CraftInventoryCrafting inventory = new CraftInventoryCrafting(this.craftSlots, this.resultSlots); -+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this); ++ bukkitEntity = new CraftInventoryView(this.owner.getBukkitEntity(), inventory, this); + return bukkitEntity; + } + // CraftBukkit end diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerShulkerBox.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerShulkerBox.patch index 19429ef381..5109b7b8e9 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerShulkerBox.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerShulkerBox.patch @@ -38,7 +38,7 @@ iinventory.startOpen(playerinventory.player); boolean flag = true; boolean flag1 = true; -@@ -46,6 +66,7 @@ +@@ -34,6 +54,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerSmithing.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerSmithing.patch index 5d29097d80..39be79fcec 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerSmithing.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerSmithing.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/ContainerSmithing.java +++ b/net/minecraft/world/inventory/ContainerSmithing.java -@@ -14,6 +14,8 @@ +@@ -18,6 +18,8 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.IBlockData; @@ -9,39 +9,39 @@ public class ContainerSmithing extends ContainerAnvilAbstract { public static final int TEMPLATE_SLOT = 0; -@@ -29,6 +31,9 @@ - @Nullable - private RecipeHolder selectedRecipe; - private final List> recipes; +@@ -34,6 +36,9 @@ + private final RecipePropertySet templateItemTest; + private final RecipePropertySet additionItemTest; + private final ContainerProperty hasRecipeError; + // CraftBukkit start + private CraftInventoryView bukkitEntity; + // CraftBukkit end public ContainerSmithing(int i, PlayerInventory playerinventory) { this(i, playerinventory, ContainerAccess.NULL); -@@ -103,7 +108,7 @@ - List> list = this.level.getRecipeManager().getRecipesFor(Recipes.SMITHING, smithingrecipeinput, this.level); +@@ -117,7 +122,7 @@ + public void createResult() { + SmithingRecipeInput smithingrecipeinput = this.createRecipeInput(); + World world = this.level; +- Optional optional; ++ Optional> optional; // CraftBukkit - decompile error - if (list.isEmpty()) { -- this.resultSlots.setItem(0, ItemStack.EMPTY); -+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit - } else { - RecipeHolder recipeholder = (RecipeHolder) list.get(0); + if (world instanceof WorldServer worldserver) { + optional = worldserver.recipeAccess().getRecipeFor(Recipes.SMITHING, smithingrecipeinput, worldserver); +@@ -129,7 +134,9 @@ ItemStack itemstack = ((SmithingRecipe) recipeholder.value()).assemble(smithingrecipeinput, this.level.registryAccess()); -@@ -111,7 +116,9 @@ - if (itemstack.isItemEnabled(this.level.enabledFeatures())) { - this.selectedRecipe = recipeholder; - this.resultSlots.setRecipeUsed(recipeholder); -- this.resultSlots.setItem(0, itemstack); -+ // CraftBukkit start -+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), itemstack); -+ // CraftBukkit end - } - } -@@ -143,4 +150,18 @@ - return !this.getSlot(i).hasItem(); - }).findFirst(); + this.resultSlots.setRecipeUsed(recipeholder); +- this.resultSlots.setItem(0, itemstack); ++ // CraftBukkit start ++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareSmithingEvent(getBukkitView(), itemstack); ++ // CraftBukkit end + }, () -> { + this.resultSlots.setRecipeUsed((RecipeHolder) null); + this.resultSlots.setItem(0, ItemStack.EMPTY); +@@ -149,4 +156,18 @@ + public boolean hasRecipeError() { + return this.hasRecipeError.get() > 0; } + + // CraftBukkit start diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerStonecutter.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerStonecutter.patch index ac843b875d..e3c0b04af6 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerStonecutter.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerStonecutter.patch @@ -50,15 +50,15 @@ }; this.resultContainer = new InventoryCraftResult(); this.access = containeraccess; -@@ -106,6 +135,7 @@ - } - +@@ -94,6 +123,7 @@ + }); + this.addStandardInventorySlots(playerinventory, 8, 84); this.addDataSlot(this.selectedRecipeIndex); + player = (Player) playerinventory.player.getBukkitEntity(); // CraftBukkit } public int getSelectedRecipeIndex() { -@@ -126,6 +156,7 @@ +@@ -114,6 +144,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { @@ -66,3 +66,12 @@ return stillValid(this.access, entityhuman, Blocks.STONECUTTER); } +@@ -154,7 +185,7 @@ + } + + void setupResultSlot(int i) { +- Optional optional; ++ Optional> optional; // CraftBukkit - decompile error + + if (!this.recipesForInput.isEmpty() && this.isValidRecipeIndex(i)) { + SelectableRecipe.a selectablerecipe_a = (SelectableRecipe.a) this.recipesForInput.entries().get(i); diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerWorkbench.patch b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerWorkbench.patch index a3acf03d3f..4e456f854d 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerWorkbench.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerWorkbench.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/inventory/ContainerWorkbench.java +++ b/net/minecraft/world/inventory/ContainerWorkbench.java @@ -16,6 +16,12 @@ - import net.minecraft.world.level.World; + import net.minecraft.world.item.crafting.Recipes; import net.minecraft.world.level.block.Blocks; +// CraftBukkit start @@ -10,16 +10,10 @@ +import org.bukkit.craftbukkit.inventory.CraftInventoryView; +// CraftBukkit end + - public class ContainerWorkbench extends ContainerRecipeBook { + public class ContainerWorkbench extends AbstractCraftingMenu { - public static final int RESULT_SLOT = 0; -@@ -25,11 +31,14 @@ - private static final int INV_SLOT_END = 37; - private static final int USE_ROW_SLOT_START = 37; - private static final int USE_ROW_SLOT_END = 46; -- public final InventoryCrafting craftSlots; -+ public final TransientCraftingContainer craftSlots; // CraftBukkit - public final InventoryCraftResult resultSlots; + private static final int CRAFTING_GRID_WIDTH = 3; +@@ -31,13 +37,16 @@ public final ContainerAccess access; private final EntityHuman player; private boolean placingRecipe; @@ -29,36 +23,31 @@ public ContainerWorkbench(int i, PlayerInventory playerinventory) { this(i, playerinventory, ContainerAccess.NULL); -@@ -37,8 +46,11 @@ + } public ContainerWorkbench(int i, PlayerInventory playerinventory, ContainerAccess containeraccess) { - super(Containers.CRAFTING, i); -- this.craftSlots = new TransientCraftingContainer(this, 3, 3); -+ // CraftBukkit start - Switched order of IInventory construction and stored player - this.resultSlots = new InventoryCraftResult(); -+ this.craftSlots = new TransientCraftingContainer(this, 3, 3, playerinventory.player); // CraftBukkit - pass player -+ this.craftSlots.resultInventory = this.resultSlots; -+ // CraftBukkit end +- super(Containers.CRAFTING, i, 3, 3); ++ super(Containers.CRAFTING, i, 3, 3, playerinventory); // CraftBukkit - pass player this.access = containeraccess; this.player = playerinventory.player; - this.addSlot(new SlotResult(playerinventory.player, this.craftSlots, this.resultSlots, 0, 124, 35)); -@@ -70,6 +82,7 @@ - EntityPlayer entityplayer = (EntityPlayer) entityhuman; - ItemStack itemstack = ItemStack.EMPTY; - Optional> optional = world.getServer().getRecipeManager().getRecipeFor(Recipes.CRAFTING, craftinginput, world, recipeholder); -+ inventorycrafting.setCurrentRecipe(optional.orElse(null)); // CraftBukkit + this.addResultSlot(this.player, 124, 35); +@@ -50,6 +59,7 @@ + EntityPlayer entityplayer = (EntityPlayer) entityhuman; + ItemStack itemstack = ItemStack.EMPTY; + Optional> optional = worldserver.getServer().getRecipeManager().getRecipeFor(Recipes.CRAFTING, craftinginput, worldserver, recipeholder); ++ inventorycrafting.setCurrentRecipe(optional.orElse(null)); // CraftBukkit - if (optional.isPresent()) { - RecipeHolder recipeholder1 = (RecipeHolder) optional.get(); -@@ -83,6 +96,7 @@ - } + if (optional.isPresent()) { + RecipeHolder recipeholder1 = (RecipeHolder) optional.get(); +@@ -63,6 +73,7 @@ } } -+ itemstack = org.bukkit.craftbukkit.event.CraftEventFactory.callPreCraftEvent(inventorycrafting, inventorycraftresult, itemstack, container.getBukkitView(), optional.map(RecipeHolder::value).orElse(null) instanceof RecipeRepair); // CraftBukkit + } ++ itemstack = org.bukkit.craftbukkit.event.CraftEventFactory.callPreCraftEvent(inventorycrafting, inventorycraftresult, itemstack, container.getBukkitView(), optional.map(RecipeHolder::value).orElse(null) instanceof RecipeRepair); // CraftBukkit - inventorycraftresult.setItem(0, itemstack); - container.setRemoteSlot(0, itemstack); -@@ -139,6 +153,7 @@ + inventorycraftresult.setItem(0, itemstack); + container.setRemoteSlot(0, itemstack); +@@ -103,6 +114,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { @@ -66,9 +55,9 @@ return stillValid(this.access, entityhuman, Blocks.CRAFTING_TABLE); } -@@ -227,4 +242,17 @@ - public boolean shouldMoveToInventory(int i) { - return i != this.getResultSlotIndex(); +@@ -181,4 +193,17 @@ + protected EntityHuman owner() { + return this.player; } + + // CraftBukkit start diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/CrafterMenu.patch b/paper-server/nms-patches/net/minecraft/world/inventory/CrafterMenu.patch index 2340a444eb..0f552abaaa 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/CrafterMenu.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/CrafterMenu.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/inventory/CrafterMenu.java +++ b/net/minecraft/world/inventory/CrafterMenu.java @@ -10,8 +10,27 @@ - import net.minecraft.world.level.World; + import net.minecraft.world.item.crafting.RecipeCrafting; import net.minecraft.world.level.block.CrafterBlock; +// CraftBukkit start @@ -28,7 +28,7 @@ protected static final int SLOT_COUNT = 9; private static final int INV_SLOT_START = 9; private static final int INV_SLOT_END = 36; -@@ -118,6 +137,7 @@ +@@ -106,6 +125,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/TransientCraftingContainer.patch b/paper-server/nms-patches/net/minecraft/world/inventory/TransientCraftingContainer.patch index 87f4eec5f1..7c539ac590 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/TransientCraftingContainer.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/TransientCraftingContainer.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/inventory/TransientCraftingContainer.java +++ b/net/minecraft/world/inventory/TransientCraftingContainer.java @@ -8,6 +8,16 @@ - import net.minecraft.world.entity.player.EntityHuman; + import net.minecraft.world.entity.player.StackedItemContents; import net.minecraft.world.item.ItemStack; +// CraftBukkit start diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemBlock.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemBlock.patch index 1234a88aac..9669523947 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemBlock.patch @@ -14,7 +14,7 @@ public class ItemBlock extends Item { /** @deprecated */ -@@ -68,6 +75,12 @@ +@@ -62,6 +69,12 @@ return EnumInteractionResult.FAIL; } else { IBlockData iblockdata = this.getPlacementState(blockactioncontext1); @@ -27,7 +27,7 @@ if (iblockdata == null) { return EnumInteractionResult.FAIL; -@@ -85,6 +98,19 @@ +@@ -79,6 +92,19 @@ this.updateCustomBlockEntityTag(blockposition, world, entityhuman, itemstack, iblockdata1); updateBlockEntityComponents(world, blockposition, itemstack); iblockdata1.getBlock().setPlacedBy(world, blockposition, iblockdata1, entityhuman, itemstack); @@ -47,7 +47,7 @@ if (entityhuman instanceof EntityPlayer) { CriterionTriggers.PLACED_BLOCK.trigger((EntityPlayer) entityhuman, blockposition, itemstack); } -@@ -92,7 +118,7 @@ +@@ -86,7 +112,7 @@ SoundEffectType soundeffecttype = iblockdata1.getSoundType(); @@ -55,8 +55,8 @@ + // world.playSound(entityhuman, blockposition, this.getPlaceSound(iblockdata1), SoundCategory.BLOCKS, (soundeffecttype.getVolume() + 1.0F) / 2.0F, soundeffecttype.getPitch() * 0.8F); world.gameEvent((Holder) GameEvent.BLOCK_PLACE, blockposition, GameEvent.a.of(entityhuman, iblockdata1)); itemstack.consume(1, entityhuman); - return EnumInteractionResult.sidedSuccess(world.isClientSide); -@@ -150,8 +176,15 @@ + return EnumInteractionResult.SUCCESS; +@@ -144,8 +170,15 @@ protected boolean canPlace(BlockActionContext blockactioncontext, IBlockData iblockdata) { EntityHuman entityhuman = blockactioncontext.getPlayer(); VoxelShapeCollision voxelshapecollision = entityhuman == null ? VoxelShapeCollision.empty() : VoxelShapeCollision.of(entityhuman); diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemBoat.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemBoat.patch index dc6429b010..5ab0387a04 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemBoat.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemBoat.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemBoat.java +++ b/net/minecraft/world/item/ItemBoat.java -@@ -61,6 +61,13 @@ +@@ -58,6 +58,13 @@ } if (movingobjectpositionblock.getType() == MovingObjectPosition.EnumMovingObjectType.BLOCK) { @@ -8,35 +8,26 @@ + org.bukkit.event.player.PlayerInteractEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent(entityhuman, org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getBlockPos(), movingobjectpositionblock.getDirection(), itemstack, false, enumhand, movingobjectpositionblock.getLocation()); + + if (event.isCancelled()) { -+ return InteractionResultWrapper.pass(itemstack); ++ return EnumInteractionResult.PASS; + } + // CraftBukkit end - EntityBoat entityboat = this.getBoat(world, movingobjectpositionblock, itemstack, entityhuman); + AbstractBoat abstractboat = this.getBoat(world, movingobjectpositionblock, itemstack, entityhuman); - entityboat.setVariant(this.type); -@@ -69,7 +76,15 @@ - return InteractionResultWrapper.fail(itemstack); - } else { - if (!world.isClientSide) { -- world.addFreshEntity(entityboat); -+ // CraftBukkit start -+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPlaceEvent(world, movingobjectpositionblock.getBlockPos(), movingobjectpositionblock.getDirection(), entityhuman, entityboat, enumhand).isCancelled()) { -+ return InteractionResultWrapper.fail(itemstack); -+ } + if (abstractboat == null) { +@@ -68,7 +75,15 @@ + return EnumInteractionResult.FAIL; + } else { + if (!world.isClientSide) { +- world.addFreshEntity(abstractboat); ++ // CraftBukkit start ++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPlaceEvent(world, movingobjectpositionblock.getBlockPos(), movingobjectpositionblock.getDirection(), entityhuman, abstractboat, enumhand).isCancelled()) { ++ return EnumInteractionResult.FAIL; ++ } + -+ if (!world.addFreshEntity(entityboat)) { -+ return InteractionResultWrapper.pass(itemstack); -+ } -+ // CraftBukkit end - world.gameEvent((Entity) entityhuman, (Holder) GameEvent.ENTITY_PLACE, movingobjectpositionblock.getLocation()); - itemstack.consume(1, entityhuman); - } -@@ -85,7 +100,7 @@ - - private EntityBoat getBoat(World world, MovingObjectPosition movingobjectposition, ItemStack itemstack, EntityHuman entityhuman) { - Vec3D vec3d = movingobjectposition.getLocation(); -- Object object = this.hasChest ? new ChestBoat(world, vec3d.x, vec3d.y, vec3d.z) : new EntityBoat(world, vec3d.x, vec3d.y, vec3d.z); -+ EntityBoat object = this.hasChest ? new ChestBoat(world, vec3d.x, vec3d.y, vec3d.z) : new EntityBoat(world, vec3d.x, vec3d.y, vec3d.z); // CraftBukkit - decompile error - - if (world instanceof WorldServer worldserver) { - EntityTypes.createDefaultStackConfig(worldserver, itemstack, entityhuman).accept(object); ++ if (!world.addFreshEntity(abstractboat)) { ++ return EnumInteractionResult.PASS; ++ } ++ // CraftBukkit end + world.gameEvent((Entity) entityhuman, (Holder) GameEvent.ENTITY_PLACE, movingobjectpositionblock.getLocation()); + itemstack.consume(1, entityhuman); + } diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemBucket.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemBucket.patch index 418749bd0e..63994725b4 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemBucket.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemBucket.patch @@ -23,13 +23,13 @@ IFluidSource ifluidsource = (IFluidSource) block; + // CraftBukkit start + ItemStack dummyFluid = ifluidsource.pickupBlock(entityhuman, DummyGeneratorAccess.INSTANCE, blockposition, iblockdata); -+ if (dummyFluid.isEmpty()) return InteractionResultWrapper.fail(itemstack); // Don't fire event if the bucket won't be filled. ++ if (dummyFluid.isEmpty()) return EnumInteractionResult.FAIL; // Don't fire event if the bucket won't be filled. + PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((WorldServer) world, entityhuman, blockposition, blockposition, movingobjectpositionblock.getDirection(), itemstack, dummyFluid.getItem(), enumhand); + + if (event.isCancelled()) { + ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-5163 (see PlayerInteractManager) + ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541 -+ return InteractionResultWrapper.fail(itemstack); ++ return EnumInteractionResult.FAIL; + } + // CraftBukkit end diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemChorusFruit.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemChorusFruit.patch deleted file mode 100644 index c012769586..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemChorusFruit.patch +++ /dev/null @@ -1,20 +0,0 @@ ---- a/net/minecraft/world/item/ItemChorusFruit.java -+++ b/net/minecraft/world/item/ItemChorusFruit.java -@@ -36,7 +36,16 @@ - - Vec3D vec3d = entityliving.position(); - -- if (entityliving.randomTeleport(d0, d1, d2, true)) { -+ // CraftBukkit start - handle canceled status of teleport event -+ java.util.Optional status = entityliving.randomTeleport(d0, d1, d2, true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT); -+ -+ if (!status.isPresent()) { -+ // teleport event was canceled, no more tries -+ break; -+ } -+ -+ if (status.get()) { -+ // CraftBukkit end - world.gameEvent((Holder) GameEvent.TELEPORT, vec3d, GameEvent.a.of((Entity) entityliving)); - SoundEffect soundeffect; - SoundCategory soundcategory; diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemEgg.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemEgg.patch index 363eb91660..185fb658eb 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemEgg.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemEgg.patch @@ -1,23 +1,19 @@ --- a/net/minecraft/world/item/ItemEgg.java +++ b/net/minecraft/world/item/ItemEgg.java -@@ -22,14 +22,22 @@ - public InteractionResultWrapper use(World world, EntityHuman entityhuman, EnumHand enumhand) { +@@ -23,10 +23,18 @@ + public EnumInteractionResult use(World world, EntityHuman entityhuman, EnumHand enumhand) { ItemStack itemstack = entityhuman.getItemInHand(enumhand); - world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)); + // world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.EGG_THROW, SoundCategory.PLAYERS, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)); // CraftBukkit - moved down - if (!world.isClientSide) { - EntityEgg entityegg = new EntityEgg(world, entityhuman); - - entityegg.setItem(itemstack); - entityegg.shootFromRotation(entityhuman, entityhuman.getXRot(), entityhuman.getYRot(), 0.0F, 1.5F, 1.0F); -- world.addFreshEntity(entityegg); + if (world instanceof WorldServer worldserver) { +- IProjectile.spawnProjectileFromRotation(EntityEgg::new, worldserver, itemstack, entityhuman, 0.0F, 1.5F, 1.0F); + // CraftBukkit start -+ if (!world.addFreshEntity(entityegg)) { ++ if (IProjectile.spawnProjectileFromRotation(EntityEgg::new, worldserver, itemstack, entityhuman, 0.0F, 1.5F, 1.0F).isRemoved()) { + if (entityhuman instanceof net.minecraft.server.level.EntityPlayer) { + ((net.minecraft.server.level.EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); + } -+ return InteractionResultWrapper.fail(itemstack); ++ return EnumInteractionResult.FAIL; + } + // CraftBukkit end } diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemEnderEye.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemEnderEye.patch index 9050013b43..7549f81705 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemEnderEye.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemEnderEye.patch @@ -1,15 +1,15 @@ --- a/net/minecraft/world/item/ItemEnderEye.java +++ b/net/minecraft/world/item/ItemEnderEye.java -@@ -97,7 +97,11 @@ - entityendersignal.setItem(itemstack); - entityendersignal.signalTo(blockposition); - world.gameEvent((Holder) GameEvent.PROJECTILE_SHOOT, entityendersignal.position(), GameEvent.a.of((Entity) entityhuman)); -- world.addFreshEntity(entityendersignal); -+ // CraftBukkit start -+ if (!world.addFreshEntity(entityendersignal)) { -+ return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack); -+ } -+ // CraftBukkit end - if (entityhuman instanceof EntityPlayer) { - EntityPlayer entityplayer = (EntityPlayer) entityhuman; +@@ -99,7 +99,11 @@ + entityendersignal.setItem(itemstack); + entityendersignal.signalTo(blockposition); + world.gameEvent((Holder) GameEvent.PROJECTILE_SHOOT, entityendersignal.position(), GameEvent.a.of((Entity) entityhuman)); +- world.addFreshEntity(entityendersignal); ++ // CraftBukkit start ++ if (!world.addFreshEntity(entityendersignal)) { ++ return EnumInteractionResult.FAIL; ++ } ++ // CraftBukkit end + if (entityhuman instanceof EntityPlayer) { + EntityPlayer entityplayer = (EntityPlayer) entityhuman; diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemEnderPearl.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemEnderPearl.patch index 21f3d9275e..fc2a620745 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemEnderPearl.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemEnderPearl.patch @@ -1,30 +1,22 @@ --- a/net/minecraft/world/item/ItemEnderPearl.java +++ b/net/minecraft/world/item/ItemEnderPearl.java -@@ -19,16 +19,24 @@ - public InteractionResultWrapper use(World world, EntityHuman entityhuman, EnumHand enumhand) { +@@ -21,10 +21,17 @@ + public EnumInteractionResult use(World world, EntityHuman entityhuman, EnumHand enumhand) { ItemStack itemstack = entityhuman.getItemInHand(enumhand); - world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)); -- entityhuman.getCooldowns().addCooldown(this, 20); -+ // CraftBukkit start - change order - if (!world.isClientSide) { - EntityEnderPearl entityenderpearl = new EntityEnderPearl(world, entityhuman); - - entityenderpearl.setItem(itemstack); - entityenderpearl.shootFromRotation(entityhuman, entityhuman.getXRot(), entityhuman.getYRot(), 0.0F, 1.5F, 1.0F); -- world.addFreshEntity(entityenderpearl); -+ if (!world.addFreshEntity(entityenderpearl)) { + if (world instanceof WorldServer worldserver) { +- IProjectile.spawnProjectileFromRotation(EntityEnderPearl::new, worldserver, itemstack, entityhuman, 0.0F, 1.5F, 1.0F); ++ // CraftBukkit start ++ if (IProjectile.spawnProjectileFromRotation(EntityEnderPearl::new, worldserver, itemstack, entityhuman, 0.0F, 1.5F, 1.0F).isRemoved()) { + if (entityhuman instanceof net.minecraft.server.level.EntityPlayer) { + ((net.minecraft.server.level.EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); + } -+ return InteractionResultWrapper.fail(itemstack); ++ return EnumInteractionResult.FAIL; + } } - + world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)); -+ entityhuman.getCooldowns().addCooldown(this, 20); + // CraftBukkit end -+ + entityhuman.awardStat(StatisticList.ITEM_USED.get(this)); itemstack.consume(1, entityhuman); - return InteractionResultWrapper.sidedSuccess(itemstack, world.isClientSide()); diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemFishingRod.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemFishingRod.patch index 0977a96c1f..80a8d1b9db 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemFishingRod.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemFishingRod.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemFishingRod.java +++ b/net/minecraft/world/item/ItemFishingRod.java -@@ -13,6 +13,11 @@ +@@ -14,6 +14,11 @@ import net.minecraft.world.level.World; import net.minecraft.world.level.gameevent.GameEvent; @@ -12,7 +12,7 @@ public class ItemFishingRod extends Item { public ItemFishingRod(Item.Info item_info) { -@@ -33,13 +38,24 @@ +@@ -34,13 +39,24 @@ world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.FISHING_BOBBER_RETRIEVE, SoundCategory.NEUTRAL, 1.0F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)); entityhuman.gameEvent(GameEvent.ITEM_INTERACT_FINISH); } else { @@ -23,18 +23,18 @@ int j = (int) (EnchantmentManager.getFishingTimeReduction(worldserver, itemstack, entityhuman) * 20.0F); int k = EnchantmentManager.getFishingLuckBonus(worldserver, itemstack, entityhuman); -- world.addFreshEntity(new EntityFishingHook(entityhuman, world, k, j)); +- IProjectile.spawnProjectile(new EntityFishingHook(entityhuman, world, k, j, itemstack), worldserver, itemstack); + // CraftBukkit start -+ EntityFishingHook entityfishinghook = new EntityFishingHook(entityhuman, world, k, j); ++ EntityFishingHook entityfishinghook = new EntityFishingHook(entityhuman, world, k, j, itemstack); + PlayerFishEvent playerFishEvent = new PlayerFishEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), null, (org.bukkit.entity.FishHook) entityfishinghook.getBukkitEntity(), CraftEquipmentSlot.getHand(enumhand), PlayerFishEvent.State.FISHING); + world.getCraftServer().getPluginManager().callEvent(playerFishEvent); + + if (playerFishEvent.isCancelled()) { + entityhuman.fishing = null; -+ return InteractionResultWrapper.pass(itemstack); ++ return EnumInteractionResult.PASS; + } + world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.FISHING_BOBBER_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)); -+ world.addFreshEntity(entityfishinghook); ++ IProjectile.spawnProjectile(entityfishinghook, worldserver, itemstack); + // CraftBukkit end } diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemHanging.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemHanging.patch index 4c64f39fed..5dcb4a2844 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemHanging.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemHanging.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemHanging.java +++ b/net/minecraft/world/item/ItemHanging.java -@@ -24,6 +24,11 @@ +@@ -25,6 +25,11 @@ import net.minecraft.world.level.World; import net.minecraft.world.level.gameevent.GameEvent; @@ -12,7 +12,7 @@ public class ItemHanging extends Item { private static final IChatBaseComponent TOOLTIP_RANDOM_VARIANT = IChatBaseComponent.translatable("painting.random").withStyle(EnumChatFormat.GRAY); -@@ -74,6 +79,19 @@ +@@ -75,6 +80,19 @@ if (((EntityHanging) object).survives()) { if (!world.isClientSide) { @@ -32,3 +32,12 @@ ((EntityHanging) object).playPlacementSound(); world.gameEvent((Entity) entityhuman, (Holder) GameEvent.ENTITY_PLACE, ((EntityHanging) object).position()); world.addFreshEntity((Entity) object); +@@ -102,7 +120,7 @@ + + if (!customdata.isEmpty()) { + customdata.read(holderlookup_a.createSerializationContext(DynamicOpsNBT.INSTANCE), EntityPainting.VARIANT_MAP_CODEC).result().ifPresentOrElse((holder) -> { +- Optional optional = ((PaintingVariant) holder.value()).title(); ++ Optional optional = ((PaintingVariant) holder.value()).title(); // CraftBukkit - decompile error + + Objects.requireNonNull(list); + optional.ifPresent(list::add); diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemLeash.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemLeash.patch index d26c8aac0e..38caf51bfa 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemLeash.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemLeash.patch @@ -13,17 +13,16 @@ public class ItemLeash extends Item { public ItemLeash(Item.Info item_info) { -@@ -35,7 +41,7 @@ +@@ -35,14 +41,14 @@ EntityHuman entityhuman = itemactioncontext.getPlayer(); if (!world.isClientSide && entityhuman != null) { -- bindPlayerMobs(entityhuman, world, blockposition); -+ bindPlayerMobs(entityhuman, world, blockposition, itemactioncontext.getHand()); // CraftBukkit - Pass hand +- return bindPlayerMobs(entityhuman, world, blockposition); ++ return bindPlayerMobs(entityhuman, world, blockposition, itemactioncontext.getHand()); // CraftBukkit - Pass hand } - - return EnumInteractionResult.sidedSuccess(world.isClientSide); -@@ -44,7 +50,7 @@ } + + return EnumInteractionResult.PASS; } - public static EnumInteractionResult bindPlayerMobs(EntityHuman entityhuman, World world, BlockPosition blockposition) { @@ -31,7 +30,7 @@ EntityLeash entityleash = null; List list = leashableInArea(world, blockposition, (leashable) -> { return leashable.getLeashHolder() == entityhuman; -@@ -52,22 +58,55 @@ +@@ -50,22 +56,55 @@ Leashable leashable; @@ -68,7 +67,7 @@ if (!list.isEmpty()) { world.gameEvent((Holder) GameEvent.BLOCK_ATTACH, blockposition, GameEvent.a.of((Entity) entityhuman)); - return EnumInteractionResult.SUCCESS; + return EnumInteractionResult.SUCCESS_SERVER; } else { + // CraftBukkit start- remove leash if we do not leash any entity because of the cancelled event + if (entityleash != null) { diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemMilkBucket.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemMilkBucket.patch deleted file mode 100644 index 57a4d3646d..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemMilkBucket.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/net/minecraft/world/item/ItemMilkBucket.java -+++ b/net/minecraft/world/item/ItemMilkBucket.java -@@ -25,7 +25,7 @@ - } - - if (!world.isClientSide) { -- entityliving.removeAllEffects(); -+ entityliving.removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause.MILK); // CraftBukkit - } - - if (entityliving instanceof EntityHuman entityhuman) { diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemMinecart.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemMinecart.patch index 856e6f4114..f5a66c7ae4 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemMinecart.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemMinecart.patch @@ -1,72 +1,16 @@ --- a/net/minecraft/world/item/ItemMinecart.java +++ b/net/minecraft/world/item/ItemMinecart.java -@@ -20,6 +20,12 @@ - import net.minecraft.world.level.gameevent.GameEvent; - import net.minecraft.world.phys.Vec3D; +@@ -67,7 +67,12 @@ + if (world instanceof WorldServer) { + WorldServer worldserver = (WorldServer) world; -+// CraftBukkit start -+import org.bukkit.craftbukkit.block.CraftBlock; -+import org.bukkit.craftbukkit.inventory.CraftItemStack; -+import org.bukkit.event.block.BlockDispenseEvent; -+// CraftBukkit end -+ - public class ItemMinecart extends Item { - - private static final IDispenseBehavior DISPENSE_ITEM_BEHAVIOR = new DispenseBehaviorItem() { -@@ -59,10 +65,39 @@ +- worldserver.addFreshEntity(entityminecartabstract); ++ // CraftBukkit start ++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPlaceEvent(itemactioncontext, entityminecartabstract).isCancelled()) { ++ return EnumInteractionResult.FAIL; ++ } ++ // CraftBukkit end ++ if (!worldserver.addFreshEntity(entityminecartabstract)) return EnumInteractionResult.PASS; // CraftBukkit + worldserver.gameEvent((Holder) GameEvent.ENTITY_PLACE, blockposition, GameEvent.a.of(itemactioncontext.getPlayer(), worldserver.getBlockState(blockposition.below()))); } - } - -- EntityMinecartAbstract entityminecartabstract = EntityMinecartAbstract.createMinecart(worldserver, d0, d1 + d3, d2, ((ItemMinecart) itemstack.getItem()).type, itemstack, (EntityHuman) null); -+ // CraftBukkit start -+ // EntityMinecartAbstract entityminecartabstract = EntityMinecartAbstract.createMinecart(worldserver, d0, d1 + d3, d2, ((ItemMinecart) itemstack.getItem()).type); -+ ItemStack itemstack1 = itemstack.split(1); -+ org.bukkit.block.Block block2 = CraftBlock.at(worldserver, sourceblock.pos()); -+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1); - -- worldserver.addFreshEntity(entityminecartabstract); -- itemstack.shrink(1); -+ BlockDispenseEvent event = new BlockDispenseEvent(block2, craftItem.clone(), new org.bukkit.util.Vector(d0, d1 + d3, d2)); -+ if (!BlockDispenser.eventFired) { -+ worldserver.getCraftServer().getPluginManager().callEvent(event); -+ } -+ -+ if (event.isCancelled()) { -+ itemstack.grow(1); -+ return itemstack; -+ } -+ -+ if (!event.getItem().equals(craftItem)) { -+ itemstack.grow(1); -+ // Chain to handler for new item -+ ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem()); -+ IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.DISPENSER_REGISTRY.get(eventStack.getItem()); -+ if (idispensebehavior != IDispenseBehavior.NOOP && idispensebehavior != this) { -+ idispensebehavior.dispense(sourceblock, eventStack); -+ return itemstack; -+ } -+ } -+ -+ itemstack1 = CraftItemStack.asNMSCopy(event.getItem()); -+ EntityMinecartAbstract entityminecartabstract = EntityMinecartAbstract.createMinecart(worldserver, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), ((ItemMinecart) itemstack1.getItem()).type, itemstack1, (EntityHuman) null); -+ -+ if (!worldserver.addFreshEntity(entityminecartabstract)) itemstack.grow(1); -+ // itemstack.shrink(1); // CraftBukkit - handled during event processing -+ // CraftBukkit end - return itemstack; - } - -@@ -101,7 +136,12 @@ - - EntityMinecartAbstract entityminecartabstract = EntityMinecartAbstract.createMinecart(worldserver, (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.0625D + d0, (double) blockposition.getZ() + 0.5D, this.type, itemstack, itemactioncontext.getPlayer()); - -- worldserver.addFreshEntity(entityminecartabstract); -+ // CraftBukkit start -+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPlaceEvent(itemactioncontext, entityminecartabstract).isCancelled()) { -+ return EnumInteractionResult.FAIL; -+ } -+ // CraftBukkit end -+ if (!worldserver.addFreshEntity(entityminecartabstract)) return EnumInteractionResult.PASS; // CraftBukkit - worldserver.gameEvent((Holder) GameEvent.ENTITY_PLACE, blockposition, GameEvent.a.of(itemactioncontext.getPlayer(), worldserver.getBlockState(blockposition.below()))); - } diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemMonsterEgg.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemMonsterEgg.patch index a56361ee5a..c76355cfd4 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemMonsterEgg.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemMonsterEgg.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemMonsterEgg.java +++ b/net/minecraft/world/item/ItemMonsterEgg.java -@@ -177,10 +177,10 @@ +@@ -176,10 +176,10 @@ return Optional.empty(); } else { ((EntityInsentient) object).moveTo(vec3d.x(), vec3d.y(), vec3d.z(), 0.0F, 0.0F); diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemPotion.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemPotion.patch deleted file mode 100644 index cfbb4bb5ea..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemPotion.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/net/minecraft/world/item/ItemPotion.java -+++ b/net/minecraft/world/item/ItemPotion.java -@@ -62,7 +62,7 @@ - if (((MobEffectList) mobeffect.getEffect().value()).isInstantenous()) { - ((MobEffectList) mobeffect.getEffect().value()).applyInstantenousEffect(entityhuman, entityhuman, entityliving, mobeffect.getAmplifier(), 1.0D); - } else { -- entityliving.addEffect(mobeffect); -+ entityliving.addEffect(mobeffect, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.POTION_DRINK); // CraftBukkit - } - - }); diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemProjectileWeapon.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemProjectileWeapon.patch index a3aaf32f97..8b56069605 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemProjectileWeapon.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemProjectileWeapon.patch @@ -1,11 +1,16 @@ --- a/net/minecraft/world/item/ItemProjectileWeapon.java +++ b/net/minecraft/world/item/ItemProjectileWeapon.java -@@ -62,7 +62,22 @@ - IProjectile iprojectile = this.createProjectile(worldserver, entityliving, itemstack, itemstack1, flag); +@@ -54,9 +54,25 @@ + float f6 = f4 + f5 * (float) ((i + 1) / 2) * f3; - this.shootProjectile(entityliving, iprojectile, i, f, f1, f6, entityliving1); -- worldserver.addFreshEntity(iprojectile); + f5 = -f5; +- IProjectile.spawnProjectile(this.createProjectile(worldserver, entityliving, itemstack, itemstack1, flag), worldserver, itemstack1, (iprojectile) -> { +- this.shootProjectile(entityliving, iprojectile, i, f, f1, f6, entityliving1); +- }); + // CraftBukkit start ++ IProjectile iprojectile = this.createProjectile(worldserver, entityliving, itemstack, itemstack1, flag); ++ this.shootProjectile(entityliving, iprojectile, i, f, f1, f6, entityliving1); ++ + org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(entityliving, itemstack, itemstack1, iprojectile, enumhand, f, true); + if (event.isCancelled()) { + event.getProjectile().remove(); @@ -13,7 +18,7 @@ + } + + if (event.getProjectile() == iprojectile.getBukkitEntity()) { -+ if (!worldserver.addFreshEntity(iprojectile)) { ++ if (IProjectile.spawnProjectile(iprojectile, worldserver, itemstack1).isRemoved()) { + if (entityliving instanceof net.minecraft.server.level.EntityPlayer) { + ((net.minecraft.server.level.EntityPlayer) entityliving).getBukkitEntity().updateInventory(); + } diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemSign.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemSign.patch index 2b304e15d8..a972332727 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemSign.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemSign.patch @@ -6,8 +6,8 @@ + public static BlockPosition openSign; // CraftBukkit + - public ItemSign(Item.Info item_info, Block block, Block block1) { - super(block, block1, item_info, EnumDirection.DOWN); + public ItemSign(Block block, Block block1, Item.Info item_info) { + super(block, block1, EnumDirection.DOWN, item_info); } @@ -35,7 +37,10 @@ if (block instanceof BlockSign) { diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemSnowball.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemSnowball.patch index d8cb71efb6..b670cf0f83 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemSnowball.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemSnowball.patch @@ -1,31 +1,27 @@ --- a/net/minecraft/world/item/ItemSnowball.java +++ b/net/minecraft/world/item/ItemSnowball.java -@@ -22,17 +22,25 @@ - public InteractionResultWrapper use(World world, EntityHuman entityhuman, EnumHand enumhand) { +@@ -23,13 +23,21 @@ + public EnumInteractionResult use(World world, EntityHuman entityhuman, EnumHand enumhand) { ItemStack itemstack = entityhuman.getItemInHand(enumhand); - world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)); -+ // CraftBukkit - moved down ++ // CraftBukkit start - moved down + // world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)); - if (!world.isClientSide) { - EntitySnowball entitysnowball = new EntitySnowball(world, entityhuman); - - entitysnowball.setItem(itemstack); - entitysnowball.shootFromRotation(entityhuman, entityhuman.getXRot(), entityhuman.getYRot(), 0.0F, 1.5F, 1.0F); -- world.addFreshEntity(entitysnowball); -+ if (world.addFreshEntity(entitysnowball)) { + if (world instanceof WorldServer worldserver) { +- IProjectile.spawnProjectileFromRotation(EntitySnowball::new, worldserver, itemstack, entityhuman, 0.0F, 1.5F, 1.0F); ++ if (IProjectile.spawnProjectileFromRotation(EntitySnowball::new, worldserver, itemstack, entityhuman, 0.0F, 1.5F, 1.0F).isAlive()) { + itemstack.consume(1, entityhuman); + + world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F)); + } else if (entityhuman instanceof net.minecraft.server.level.EntityPlayer) { + ((net.minecraft.server.level.EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); + } ++ // CraftBukkit end } -+ // CraftBukkit end entityhuman.awardStat(StatisticList.ITEM_USED.get(this)); - itemstack.consume(1, entityhuman); + // itemstack.consume(1, entityhuman); // CraftBukkit - moved up - return InteractionResultWrapper.sidedSuccess(itemstack, world.isClientSide()); + return EnumInteractionResult.SUCCESS; } diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemStack.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemStack.patch index 1ea1ce3ee1..bf9aba516c 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemStack.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemStack.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemStack.java +++ b/net/minecraft/world/item/ItemStack.java -@@ -91,6 +91,40 @@ +@@ -96,17 +96,51 @@ import org.apache.commons.lang3.mutable.MutableBoolean; import org.slf4j.Logger; @@ -40,14 +40,10 @@ + public final class ItemStack implements DataComponentHolder { - public static final Codec> ITEM_NON_AIR_CODEC = BuiltInRegistries.ITEM.holderByNameCodec().validate((holder) -> { -@@ -99,14 +133,14 @@ - }) : DataResult.success(holder); - }); public static final Codec CODEC = Codec.lazyInitialized(() -> { - return RecordCodecBuilder.create((instance) -> { + return RecordCodecBuilder.create((instance) -> { // CraftBukkit - decompile error - return instance.group(ItemStack.ITEM_NON_AIR_CODEC.fieldOf("id").forGetter(ItemStack::getItemHolder), ExtraCodecs.intRange(1, 99).fieldOf("count").orElse(1).forGetter(ItemStack::getCount), DataComponentPatch.CODEC.optionalFieldOf("components", DataComponentPatch.EMPTY).forGetter((itemstack) -> { + return instance.group(Item.CODEC.fieldOf("id").forGetter(ItemStack::getItemHolder), ExtraCodecs.intRange(1, 99).fieldOf("count").orElse(1).forGetter(ItemStack::getCount), DataComponentPatch.CODEC.optionalFieldOf("components", DataComponentPatch.EMPTY).forGetter((itemstack) -> { return itemstack.components.asPatch(); })).apply(instance, ItemStack::new); }); @@ -55,7 +51,7 @@ public static final Codec SINGLE_ITEM_CODEC = Codec.lazyInitialized(() -> { - return RecordCodecBuilder.create((instance) -> { + return RecordCodecBuilder.create((instance) -> { // CraftBukkit - decompile error - return instance.group(ItemStack.ITEM_NON_AIR_CODEC.fieldOf("id").forGetter(ItemStack::getItemHolder), DataComponentPatch.CODEC.optionalFieldOf("components", DataComponentPatch.EMPTY).forGetter((itemstack) -> { + return instance.group(Item.CODEC.fieldOf("id").forGetter(ItemStack::getItemHolder), DataComponentPatch.CODEC.optionalFieldOf("components", DataComponentPatch.EMPTY).forGetter((itemstack) -> { return itemstack.components.asPatch(); })).apply(instance, (holder, datacomponentpatch) -> { @@ -131,19 +165,25 @@ @@ -88,7 +84,7 @@ DataComponentPatch.STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.components.asPatch()); } } -@@ -187,7 +227,7 @@ +@@ -186,7 +226,7 @@ return dataresult.isError() ? dataresult.map((unit) -> { return itemstack; @@ -97,7 +93,7 @@ int i = itemstack.getCount(); return "Item stack with stack size of " + i + " was larger than maximum: " + itemstack.getMaxStackSize(); -@@ -286,8 +326,9 @@ +@@ -289,8 +329,9 @@ j = itemstack.getMaxStackSize(); } while (i <= j); @@ -108,7 +104,7 @@ }); } } -@@ -369,11 +410,169 @@ +@@ -372,15 +413,173 @@ return EnumInteractionResult.PASS; } else { Item item = this.getItem(); @@ -171,108 +167,112 @@ + } + world.captureTreeGeneration = false; - if (entityhuman != null && enuminteractionresult.indicateItemUse()) { -- entityhuman.awardStat(StatisticList.ITEM_USED.get(item)); -+ EnumHand enumhand = itemactioncontext.getHand(); -+ org.bukkit.event.block.BlockPlaceEvent placeEvent = null; -+ List blocks = new java.util.ArrayList<>(world.capturedBlockStates.values()); -+ world.capturedBlockStates.clear(); -+ if (blocks.size() > 1) { -+ placeEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockMultiPlaceEvent(world, entityhuman, enumhand, blocks, blockposition.getX(), blockposition.getY(), blockposition.getZ()); -+ } else if (blocks.size() == 1) { -+ placeEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent(world, entityhuman, enumhand, blocks.get(0), blockposition.getX(), blockposition.getY(), blockposition.getZ()); -+ } -+ -+ if (placeEvent != null && (placeEvent.isCancelled() || !placeEvent.canBuild())) { -+ enuminteractionresult = EnumInteractionResult.FAIL; // cancel placement -+ // PAIL: Remove this when MC-99075 fixed -+ placeEvent.getPlayer().updateInventory(); -+ // revert back all captured blocks -+ world.preventPoiUpdated = true; // CraftBukkit - SPIGOT-5710 -+ for (BlockState blockstate : blocks) { -+ blockstate.update(true, false); -+ } -+ world.preventPoiUpdated = false; -+ -+ // Brute force all possible updates -+ BlockPosition placedPos = ((CraftBlock) placeEvent.getBlock()).getPosition(); -+ for (EnumDirection dir : EnumDirection.values()) { -+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutBlockChange(world, placedPos.relative(dir))); -+ } -+ ItemSign.openSign = null; // SPIGOT-6758 - Reset on early return -+ } else { -+ // Change the stack to its new contents if it hasn't been tampered with. -+ if (this.getCount() == oldCount && Objects.equals(this.components.asPatch(), oldData)) { -+ this.restorePatch(newData); -+ this.setCount(newCount); + if (entityhuman != null && enuminteractionresult instanceof EnumInteractionResult.d) { + EnumInteractionResult.d enuminteractionresult_d = (EnumInteractionResult.d) enuminteractionresult; + + if (enuminteractionresult_d.wasItemInteraction()) { +- entityhuman.awardStat(StatisticList.ITEM_USED.get(item)); ++ EnumHand enumhand = itemactioncontext.getHand(); ++ org.bukkit.event.block.BlockPlaceEvent placeEvent = null; ++ List blocks = new java.util.ArrayList<>(world.capturedBlockStates.values()); ++ world.capturedBlockStates.clear(); ++ if (blocks.size() > 1) { ++ placeEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockMultiPlaceEvent(world, entityhuman, enumhand, blocks, blockposition.getX(), blockposition.getY(), blockposition.getZ()); ++ } else if (blocks.size() == 1) { ++ placeEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent(world, entityhuman, enumhand, blocks.get(0), blockposition.getX(), blockposition.getY(), blockposition.getZ()); + } + -+ for (Map.Entry e : world.capturedTileEntities.entrySet()) { -+ world.setBlockEntity(e.getValue()); -+ } ++ if (placeEvent != null && (placeEvent.isCancelled() || !placeEvent.canBuild())) { ++ enuminteractionresult = EnumInteractionResult.FAIL; // cancel placement ++ // PAIL: Remove this when MC-99075 fixed ++ placeEvent.getPlayer().updateInventory(); ++ // revert back all captured blocks ++ world.preventPoiUpdated = true; // CraftBukkit - SPIGOT-5710 ++ for (BlockState blockstate : blocks) { ++ blockstate.update(true, false); ++ } ++ world.preventPoiUpdated = false; + -+ for (BlockState blockstate : blocks) { -+ int updateFlag = ((CraftBlockState) blockstate).getFlag(); -+ IBlockData oldBlock = ((CraftBlockState) blockstate).getHandle(); -+ BlockPosition newblockposition = ((CraftBlockState) blockstate).getPosition(); -+ IBlockData block = world.getBlockState(newblockposition); -+ -+ if (!(block.getBlock() instanceof BlockTileEntity)) { // Containers get placed automatically -+ block.onPlace(world, newblockposition, oldBlock, true, itemactioncontext); ++ // Brute force all possible updates ++ BlockPosition placedPos = ((CraftBlock) placeEvent.getBlock()).getPosition(); ++ for (EnumDirection dir : EnumDirection.values()) { ++ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutBlockChange(world, placedPos.relative(dir))); ++ } ++ ItemSign.openSign = null; // SPIGOT-6758 - Reset on early return ++ } else { ++ // Change the stack to its new contents if it hasn't been tampered with. ++ if (this.getCount() == oldCount && Objects.equals(this.components.asPatch(), oldData)) { ++ this.restorePatch(newData); ++ this.setCount(newCount); + } + -+ world.notifyAndUpdatePhysics(newblockposition, null, oldBlock, block, world.getBlockState(newblockposition), updateFlag, 512); // send null chunk as chunk.k() returns false by this point -+ } ++ for (Map.Entry e : world.capturedTileEntities.entrySet()) { ++ world.setBlockEntity(e.getValue()); ++ } + -+ if (this.item == Items.WITHER_SKELETON_SKULL) { // Special case skulls to allow wither spawns to be cancelled -+ BlockPosition bp = blockposition; -+ if (!world.getBlockState(blockposition).canBeReplaced()) { -+ if (!world.getBlockState(blockposition).isSolid()) { -+ bp = null; -+ } else { -+ bp = bp.relative(itemactioncontext.getClickedFace()); ++ for (BlockState blockstate : blocks) { ++ int updateFlag = ((CraftBlockState) blockstate).getFlag(); ++ IBlockData oldBlock = ((CraftBlockState) blockstate).getHandle(); ++ BlockPosition newblockposition = ((CraftBlockState) blockstate).getPosition(); ++ IBlockData block = world.getBlockState(newblockposition); ++ ++ if (!(block.getBlock() instanceof BlockTileEntity)) { // Containers get placed automatically ++ block.onPlace(world, newblockposition, oldBlock, true, itemactioncontext); + } -+ } -+ if (bp != null) { -+ TileEntity te = world.getBlockEntity(bp); -+ if (te instanceof TileEntitySkull) { -+ BlockWitherSkull.checkSpawn(world, bp, (TileEntitySkull) te); -+ } -+ } -+ } + -+ // SPIGOT-4678 -+ if (this.item instanceof ItemSign && ItemSign.openSign != null) { -+ try { -+ if (world.getBlockEntity(ItemSign.openSign) instanceof TileEntitySign tileentitysign) { -+ if (world.getBlockState(ItemSign.openSign).getBlock() instanceof BlockSign blocksign) { -+ blocksign.openTextEdit(entityhuman, tileentitysign, true, org.bukkit.event.player.PlayerSignOpenEvent.Cause.PLACE); // Craftbukkit ++ world.notifyAndUpdatePhysics(newblockposition, null, oldBlock, block, world.getBlockState(newblockposition), updateFlag, 512); // send null chunk as chunk.k() returns false by this point ++ } ++ ++ if (this.item == Items.WITHER_SKELETON_SKULL) { // Special case skulls to allow wither spawns to be cancelled ++ BlockPosition bp = blockposition; ++ if (!world.getBlockState(blockposition).canBeReplaced()) { ++ if (!world.getBlockState(blockposition).isSolid()) { ++ bp = null; ++ } else { ++ bp = bp.relative(itemactioncontext.getClickedFace()); ++ } ++ } ++ if (bp != null) { ++ TileEntity te = world.getBlockEntity(bp); ++ if (te instanceof TileEntitySkull) { ++ BlockWitherSkull.checkSpawn(world, bp, (TileEntitySkull) te); + } + } -+ } finally { -+ ItemSign.openSign = null; + } -+ } + -+ // SPIGOT-7315: Moved from BlockBed#setPlacedBy -+ if (placeEvent != null && this.item instanceof ItemBed) { -+ BlockPosition position = ((CraftBlock) placeEvent.getBlock()).getPosition(); -+ IBlockData blockData = world.getBlockState(position); -+ -+ if (blockData.getBlock() instanceof BlockBed) { -+ world.blockUpdated(position, Blocks.AIR); -+ blockData.updateNeighbourShapes(world, position, 3); ++ // SPIGOT-4678 ++ if (this.item instanceof ItemSign && ItemSign.openSign != null) { ++ try { ++ if (world.getBlockEntity(ItemSign.openSign) instanceof TileEntitySign tileentitysign) { ++ if (world.getBlockState(ItemSign.openSign).getBlock() instanceof BlockSign blocksign) { ++ blocksign.openTextEdit(entityhuman, tileentitysign, true, org.bukkit.event.player.PlayerSignOpenEvent.Cause.PLACE); // Craftbukkit ++ } ++ } ++ } finally { ++ ItemSign.openSign = null; ++ } + } -+ } + -+ // SPIGOT-1288 - play sound stripped from ItemBlock -+ if (this.item instanceof ItemBlock) { -+ SoundEffectType soundeffecttype = ((ItemBlock) this.item).getBlock().defaultBlockState().getSoundType(); // TODO: not strictly correct, however currently only affects decorated pots -+ world.playSound(entityhuman, blockposition, soundeffecttype.getPlaceSound(), SoundCategory.BLOCKS, (soundeffecttype.getVolume() + 1.0F) / 2.0F, soundeffecttype.getPitch() * 0.8F); -+ } ++ // SPIGOT-7315: Moved from BlockBed#setPlacedBy ++ if (placeEvent != null && this.item instanceof ItemBed) { ++ BlockPosition position = ((CraftBlock) placeEvent.getBlock()).getPosition(); ++ IBlockData blockData = world.getBlockState(position); + -+ entityhuman.awardStat(StatisticList.ITEM_USED.get(item)); -+ } ++ if (blockData.getBlock() instanceof BlockBed) { ++ world.blockUpdated(position, Blocks.AIR); ++ blockData.updateNeighbourShapes(world, position, 3); ++ } ++ } ++ ++ // SPIGOT-1288 - play sound stripped from ItemBlock ++ if (this.item instanceof ItemBlock) { ++ SoundEffectType soundeffecttype = ((ItemBlock) this.item).getBlock().defaultBlockState().getSoundType(); // TODO: not strictly correct, however currently only affects decorated pots ++ world.playSound(entityhuman, blockposition, soundeffecttype.getPlaceSound(), SoundCategory.BLOCKS, (soundeffecttype.getVolume() + 1.0F) / 2.0F, soundeffecttype.getPitch() * 0.8F); ++ } ++ ++ entityhuman.awardStat(StatisticList.ITEM_USED.get(item)); ++ } + } } + world.capturedTileEntities.clear(); + world.capturedBlockStates.clear(); @@ -280,41 +280,41 @@ return enuminteractionresult; } -@@ -444,6 +643,21 @@ - if (entityplayer == null || !entityplayer.hasInfiniteMaterials()) { - if (i > 0) { - i = EnchantmentManager.processDurabilityChange(worldserver, this, i); -+ // CraftBukkit start -+ if (entityplayer != null) { -+ PlayerItemDamageEvent event = new PlayerItemDamageEvent(entityplayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), i); -+ event.getPlayer().getServer().getPluginManager().callEvent(event); -+ -+ if (i != event.getDamage() || event.isCancelled()) { -+ event.getPlayer().updateInventory(); -+ } -+ if (event.isCancelled()) { -+ return; -+ } -+ -+ i = event.getDamage(); -+ } -+ // CraftBukkit end - if (i <= 0) { - return; - } -@@ -458,6 +672,11 @@ - this.setDamageValue(j); - if (j >= this.getMaxDamage()) { - Item item = this.getItem(); -+ // CraftBukkit start - Check for item breaking -+ if (this.count == 1 && entityplayer != null) { -+ org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent(entityplayer, this); -+ } -+ // CraftBukkit end +@@ -487,6 +686,21 @@ - this.shrink(1); - consumer.accept(item); -@@ -693,6 +912,12 @@ + public void hurtAndBreak(int i, WorldServer worldserver, @Nullable EntityPlayer entityplayer, Consumer consumer) { + int j = this.processDurabilityChange(i, worldserver, entityplayer); ++ // CraftBukkit start ++ if (entityplayer != null) { ++ PlayerItemDamageEvent event = new PlayerItemDamageEvent(entityplayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), j); ++ event.getPlayer().getServer().getPluginManager().callEvent(event); ++ ++ if (j != event.getDamage() || event.isCancelled()) { ++ event.getPlayer().updateInventory(); ++ } ++ if (event.isCancelled()) { ++ return; ++ } ++ ++ j = event.getDamage(); ++ } ++ // CraftBukkit end + + if (j != 0) { + this.applyDamage(this.getDamageValue() + j, entityplayer, consumer); +@@ -506,6 +720,11 @@ + this.setDamageValue(i); + if (this.isBroken()) { + Item item = this.getItem(); ++ // CraftBukkit start - Check for item breaking ++ if (this.count == 1 && entityplayer != null) { ++ org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent(entityplayer, this); ++ } ++ // CraftBukkit end + + this.shrink(1); + consumer.accept(item); +@@ -765,6 +984,12 @@ return this.getItem().useOnRelease(this); } @@ -327,7 +327,7 @@ @Nullable public T set(DataComponentType datacomponenttype, @Nullable T t0) { return this.components.set(datacomponenttype, t0); -@@ -752,7 +977,7 @@ +@@ -846,7 +1071,7 @@ } private void addToTooltip(DataComponentType datacomponenttype, Item.b item_b, Consumer consumer, TooltipFlag tooltipflag) { @@ -336,7 +336,7 @@ if (t0 != null) { t0.addToTooltip(item_b, consumer, tooltipflag); -@@ -992,6 +1217,13 @@ +@@ -1073,6 +1298,13 @@ EnchantmentManager.forEachModifier(this, enumitemslot, biconsumer); } @@ -350,7 +350,7 @@ public IChatBaseComponent getDisplayName() { IChatMutableComponent ichatmutablecomponent = IChatBaseComponent.empty().append(this.getHoverName()); -@@ -1054,7 +1286,7 @@ +@@ -1135,7 +1367,7 @@ } public void consume(int i, @Nullable EntityLiving entityliving) { diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemSuspiciousStew.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemSuspiciousStew.patch deleted file mode 100644 index 9cf5dbbbcc..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemSuspiciousStew.patch +++ /dev/null @@ -1,18 +0,0 @@ ---- a/net/minecraft/world/item/ItemSuspiciousStew.java -+++ b/net/minecraft/world/item/ItemSuspiciousStew.java -@@ -53,4 +53,15 @@ - - return super.finishUsingItem(itemstack, world, entityliving); - } -+ -+ // CraftBukkit start -+ public void cancelUsingItem(net.minecraft.server.level.EntityPlayer entityplayer, ItemStack itemstack) { -+ SuspiciousStewEffects suspicioussteweffects = (SuspiciousStewEffects) itemstack.getOrDefault(DataComponents.SUSPICIOUS_STEW_EFFECTS, SuspiciousStewEffects.EMPTY); -+ -+ for (SuspiciousStewEffects.a suspicioussteweffects_a : suspicioussteweffects.effects()) { -+ entityplayer.connection.send(new net.minecraft.network.protocol.game.PacketPlayOutRemoveEntityEffect(entityplayer.getId(), suspicioussteweffects_a.effect())); -+ } -+ entityplayer.server.getPlayerList().sendActivePlayerEffects(entityplayer); -+ } -+ // CraftBukkit end - } diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemTrident.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemTrident.patch index f645aecb26..dcc3a868c9 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemTrident.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemTrident.patch @@ -1,47 +1,42 @@ --- a/net/minecraft/world/item/ItemTrident.java +++ b/net/minecraft/world/item/ItemTrident.java -@@ -77,7 +77,7 @@ - Holder holder = (Holder) EnchantmentManager.pickHighestLevel(itemstack, EnchantmentEffectComponents.TRIDENT_SOUND).orElse(SoundEffects.TRIDENT_THROW); +@@ -85,9 +85,19 @@ + if (world instanceof WorldServer) { + WorldServer worldserver = (WorldServer) world; - if (!world.isClientSide) { -- itemstack.hurtAndBreak(1, entityhuman, EntityLiving.getSlotForHand(entityliving.getUsedItemHand())); -+ // itemstack.hurtAndBreak(1, entityhuman, EntityLiving.getSlotForHand(entityliving.getUsedItemHand())); // CraftBukkit - moved down - if (f == 0.0F) { - EntityThrownTrident entitythrowntrident = new EntityThrownTrident(world, entityhuman, itemstack); - -@@ -86,11 +86,26 @@ - entitythrowntrident.pickup = EntityArrow.PickupStatus.CREATIVE_ONLY; - } - -- world.addFreshEntity(entitythrowntrident); -+ // CraftBukkit start -+ if (!world.addFreshEntity(entitythrowntrident)) { -+ if (entityhuman instanceof net.minecraft.server.level.EntityPlayer) { -+ ((net.minecraft.server.level.EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); -+ } -+ return; +- itemstack.hurtWithoutBreaking(1, entityhuman); ++ // itemstack.hurtWithoutBreaking(1, entityhuman); // CraftBukkit - moved down + if (f == 0.0F) { + EntityThrownTrident entitythrowntrident = (EntityThrownTrident) IProjectile.spawnProjectileFromRotation(EntityThrownTrident::new, worldserver, itemstack, entityhuman, 0.0F, 2.5F, 1.0F); ++ // CraftBukkit start ++ if (entitythrowntrident.isRemoved()) { ++ if (entityhuman instanceof net.minecraft.server.level.EntityPlayer) { ++ ((net.minecraft.server.level.EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); + } -+ -+ itemstack.hurtAndBreak(1, entityhuman, EntityLiving.getSlotForHand(entityliving.getUsedItemHand())); -+ entitythrowntrident.pickupItemStack = itemstack.copy(); // SPIGOT-4511 update since damage call moved -+ // CraftBukkit end -+ - world.playSound((EntityHuman) null, (Entity) entitythrowntrident, (SoundEffect) holder.value(), SoundCategory.PLAYERS, 1.0F, 1.0F); - if (!entityhuman.hasInfiniteMaterials()) { - entityhuman.getInventory().removeItem(itemstack); - } -+ // CraftBukkit start - SPIGOT-5458 also need in this branch :( -+ } else { -+ itemstack.hurtAndBreak(1, entityhuman, EntityLiving.getSlotForHand(entityliving.getUsedItemHand())); -+ // CraftBukkkit end - } - } ++ return false; ++ } ++ itemstack.hurtWithoutBreaking(1, entityhuman); ++ entitythrowntrident.pickupItemStack = itemstack.copy(); // SPIGOT-4511 update since damage call moved ++ // CraftBukkit end -@@ -106,6 +121,7 @@ - f3 *= f / f6; - f4 *= f / f6; - f5 *= f / f6; -+ org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerRiptideEvent(entityhuman, itemstack, f3, f4, f5); // CraftBukkit - entityhuman.push((double) f3, (double) f4, (double) f5); - entityhuman.startAutoSpinAttack(20, 8.0F, itemstack); - if (entityhuman.onGround()) { + if (entityhuman.hasInfiniteMaterials()) { + entitythrowntrident.pickup = EntityArrow.PickupStatus.CREATIVE_ONLY; +@@ -97,6 +107,10 @@ + + world.playSound((EntityHuman) null, (Entity) entitythrowntrident, (SoundEffect) holder.value(), SoundCategory.PLAYERS, 1.0F, 1.0F); + return true; ++ // CraftBukkit start - SPIGOT-5458 also need in this branch :( ++ } else { ++ itemstack.hurtWithoutBreaking(1, entityhuman); ++ // CraftBukkkit end + } + } + +@@ -112,6 +126,7 @@ + f3 *= f / f6; + f4 *= f / f6; + f5 *= f / f6; ++ org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerRiptideEvent(entityhuman, itemstack, f3, f4, f5); // CraftBukkit + entityhuman.push((double) f3, (double) f4, (double) f5); + entityhuman.startAutoSpinAttack(20, 8.0F, itemstack); + if (entityhuman.onGround()) { diff --git a/paper-server/nms-patches/net/minecraft/world/item/alchemy/PotionContents.patch b/paper-server/nms-patches/net/minecraft/world/item/alchemy/PotionContents.patch new file mode 100644 index 0000000000..a6181a2c5b --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/item/alchemy/PotionContents.patch @@ -0,0 +1,20 @@ +--- a/net/minecraft/world/item/alchemy/PotionContents.java ++++ b/net/minecraft/world/item/alchemy/PotionContents.java +@@ -93,7 +93,7 @@ + } + + public PotionContents withEffectAdded(MobEffect mobeffect) { +- return new PotionContents(this.potion, this.customColor, SystemUtils.copyAndAdd(this.customEffects, (Object) mobeffect), this.customName); ++ return new PotionContents(this.potion, this.customColor, SystemUtils.copyAndAdd(this.customEffects, mobeffect), this.customName); // CraftBukkit - decompile error + } + + public int getColor() { +@@ -176,7 +176,7 @@ + if (((MobEffectList) mobeffect.getEffect().value()).isInstantenous()) { + ((MobEffectList) mobeffect.getEffect().value()).applyInstantenousEffect(worldserver, entityhuman2, entityhuman2, entityliving, mobeffect.getAmplifier(), 1.0D); + } else { +- entityliving.addEffect(mobeffect); ++ entityliving.addEffect(mobeffect, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.POTION_DRINK); // CraftBukkit + } + + }); diff --git a/paper-server/nms-patches/net/minecraft/world/item/component/Consumable.patch b/paper-server/nms-patches/net/minecraft/world/item/component/Consumable.patch new file mode 100644 index 0000000000..67770c3264 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/item/component/Consumable.patch @@ -0,0 +1,51 @@ +--- a/net/minecraft/world/item/component/Consumable.java ++++ b/net/minecraft/world/item/component/Consumable.java +@@ -29,6 +29,11 @@ + import net.minecraft.world.level.World; + import net.minecraft.world.level.gameevent.GameEvent; + ++// CraftBukkit start ++import net.minecraft.world.item.Items; ++import org.bukkit.event.entity.EntityPotionEffectEvent; ++// CraftBukkit end ++ + public record Consumable(float consumeSeconds, ItemUseAnimation animation, Holder sound, boolean hasConsumeParticles, List onConsumeEffects) { + + public static final float DEFAULT_CONSUME_SECONDS = 1.6F; +@@ -69,8 +74,19 @@ + consumablelistener.onConsume(world, entityliving, itemstack, this); + }); + if (!world.isClientSide) { ++ // CraftBukkit start ++ EntityPotionEffectEvent.Cause cause; ++ if (itemstack.is(Items.MILK_BUCKET)) { ++ cause = EntityPotionEffectEvent.Cause.MILK; ++ } else if (itemstack.is(Items.POTION)) { ++ cause = EntityPotionEffectEvent.Cause.POTION_DRINK; ++ } else { ++ cause = EntityPotionEffectEvent.Cause.FOOD; ++ } ++ + this.onConsumeEffects.forEach((consumeeffect) -> { +- consumeeffect.apply(world, itemstack, entityliving); ++ consumeeffect.apply(world, itemstack, entityliving, cause); ++ // CraftBukkit end + }); + } + +@@ -79,6 +95,15 @@ + return itemstack; + } + ++ // CraftBukkit start ++ public void cancelUsingItem(net.minecraft.server.level.EntityPlayer entityplayer, ItemStack itemstack) { ++ itemstack.getAllOfType(ConsumableListener.class).forEach((consumablelistener) -> { ++ consumablelistener.cancelUsingItem(entityplayer, itemstack); ++ }); ++ entityplayer.server.getPlayerList().sendActivePlayerEffects(entityplayer); ++ } ++ // CraftBukkit end ++ + public boolean canConsume(EntityLiving entityliving, ItemStack itemstack) { + FoodInfo foodinfo = (FoodInfo) itemstack.get(DataComponents.FOOD); + diff --git a/paper-server/nms-patches/net/minecraft/world/item/component/ConsumableListener.patch b/paper-server/nms-patches/net/minecraft/world/item/component/ConsumableListener.patch new file mode 100644 index 0000000000..d3e222f45c --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/item/component/ConsumableListener.patch @@ -0,0 +1,9 @@ +--- a/net/minecraft/world/item/component/ConsumableListener.java ++++ b/net/minecraft/world/item/component/ConsumableListener.java +@@ -7,4 +7,6 @@ + public interface ConsumableListener { + + void onConsume(World world, EntityLiving entityliving, ItemStack itemstack, Consumable consumable); ++ ++ default void cancelUsingItem(net.minecraft.server.level.EntityPlayer entityplayer, ItemStack itemstack) {} // CraftBukkit + } diff --git a/paper-server/nms-patches/net/minecraft/world/item/component/DeathProtection.patch b/paper-server/nms-patches/net/minecraft/world/item/component/DeathProtection.patch new file mode 100644 index 0000000000..14197c4bd0 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/item/component/DeathProtection.patch @@ -0,0 +1,22 @@ +--- a/net/minecraft/world/item/component/DeathProtection.java ++++ b/net/minecraft/world/item/component/DeathProtection.java +@@ -15,6 +15,10 @@ + import net.minecraft.world.item.consume_effects.ClearAllStatusEffectsConsumeEffect; + import net.minecraft.world.item.consume_effects.ConsumeEffect; + ++// CraftBukkit start ++import org.bukkit.event.entity.EntityPotionEffectEvent; ++// CraftBukkit end ++ + public record DeathProtection(List deathEffects) { + + public static final Codec CODEC = RecordCodecBuilder.create((instance) -> { +@@ -29,7 +33,7 @@ + while (iterator.hasNext()) { + ConsumeEffect consumeeffect = (ConsumeEffect) iterator.next(); + +- consumeeffect.apply(entityliving.level(), itemstack, entityliving); ++ consumeeffect.apply(entityliving.level(), itemstack, entityliving, EntityPotionEffectEvent.Cause.TOTEM); // CraftBukkit + } + + } diff --git a/paper-server/nms-patches/net/minecraft/world/item/component/SuspiciousStewEffects.patch b/paper-server/nms-patches/net/minecraft/world/item/component/SuspiciousStewEffects.patch new file mode 100644 index 0000000000..b8ba7b7f0f --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/item/component/SuspiciousStewEffects.patch @@ -0,0 +1,27 @@ +--- a/net/minecraft/world/item/component/SuspiciousStewEffects.java ++++ b/net/minecraft/world/item/component/SuspiciousStewEffects.java +@@ -29,7 +29,7 @@ + public static final StreamCodec STREAM_CODEC = SuspiciousStewEffects.a.STREAM_CODEC.apply(ByteBufCodecs.list()).map(SuspiciousStewEffects::new, SuspiciousStewEffects::effects); + + public SuspiciousStewEffects withEffectAdded(SuspiciousStewEffects.a suspicioussteweffects_a) { +- return new SuspiciousStewEffects(SystemUtils.copyAndAdd(this.effects, (Object) suspicioussteweffects_a)); ++ return new SuspiciousStewEffects(SystemUtils.copyAndAdd(this.effects, suspicioussteweffects_a)); // CraftBukkit - decompile error + } + + @Override +@@ -44,6 +44,15 @@ + + } + ++ // CraftBukkit start ++ @Override ++ public void cancelUsingItem(net.minecraft.server.level.EntityPlayer entityplayer, ItemStack itemstack) { ++ for (SuspiciousStewEffects.a suspicioussteweffects_a : this.effects) { ++ entityplayer.connection.send(new net.minecraft.network.protocol.game.PacketPlayOutRemoveEntityEffect(entityplayer.getId(), suspicioussteweffects_a.effect())); ++ } ++ } ++ // CraftBukkit end ++ + @Override + public void addToTooltip(Item.b item_b, Consumer consumer, TooltipFlag tooltipflag) { + if (tooltipflag.isCreative()) { diff --git a/paper-server/nms-patches/net/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffect.patch b/paper-server/nms-patches/net/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffect.patch new file mode 100644 index 0000000000..2b3e144706 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffect.patch @@ -0,0 +1,31 @@ +--- a/net/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffect.java ++++ b/net/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffect.java +@@ -13,6 +13,10 @@ + import net.minecraft.world.item.ItemStack; + import net.minecraft.world.level.World; + ++// CraftBukkit start ++import org.bukkit.event.entity.EntityPotionEffectEvent; ++// CraftBukkit end ++ + public record ApplyStatusEffectsConsumeEffect(List effects, float probability) implements ConsumeEffect { + + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { +@@ -38,7 +42,7 @@ + } + + @Override +- public boolean apply(World world, ItemStack itemstack, EntityLiving entityliving) { ++ public boolean apply(World world, ItemStack itemstack, EntityLiving entityliving, EntityPotionEffectEvent.Cause cause) { // CraftBukkit + if (entityliving.getRandom().nextFloat() >= this.probability) { + return false; + } else { +@@ -48,7 +52,7 @@ + while (iterator.hasNext()) { + MobEffect mobeffect = (MobEffect) iterator.next(); + +- if (entityliving.addEffect(new MobEffect(mobeffect))) { ++ if (entityliving.addEffect(new MobEffect(mobeffect), cause)) { // CraftBukkit + flag = true; + } + } diff --git a/paper-server/nms-patches/net/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffect.patch b/paper-server/nms-patches/net/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffect.patch new file mode 100644 index 0000000000..50d8037bb5 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffect.patch @@ -0,0 +1,25 @@ +--- a/net/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffect.java ++++ b/net/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffect.java +@@ -7,6 +7,10 @@ + import net.minecraft.world.item.ItemStack; + import net.minecraft.world.level.World; + ++// CraftBukkit start ++import org.bukkit.event.entity.EntityPotionEffectEvent; ++// CraftBukkit end ++ + public record ClearAllStatusEffectsConsumeEffect() implements ConsumeEffect { + + public static final ClearAllStatusEffectsConsumeEffect INSTANCE = new ClearAllStatusEffectsConsumeEffect(); +@@ -19,7 +23,9 @@ + } + + @Override +- public boolean apply(World world, ItemStack itemstack, EntityLiving entityliving) { +- return entityliving.removeAllEffects(); ++ // CraftBukkit start ++ public boolean apply(World world, ItemStack itemstack, EntityLiving entityliving, EntityPotionEffectEvent.Cause cause) { ++ return entityliving.removeAllEffects(cause); ++ // CraftBukkit end + } + } diff --git a/paper-server/nms-patches/net/minecraft/world/item/consume_effects/ConsumeEffect.patch b/paper-server/nms-patches/net/minecraft/world/item/consume_effects/ConsumeEffect.patch new file mode 100644 index 0000000000..d85f91059c --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/item/consume_effects/ConsumeEffect.patch @@ -0,0 +1,30 @@ +--- a/net/minecraft/world/item/consume_effects/ConsumeEffect.java ++++ b/net/minecraft/world/item/consume_effects/ConsumeEffect.java +@@ -12,6 +12,10 @@ + import net.minecraft.world.item.ItemStack; + import net.minecraft.world.level.World; + ++// CraftBukkit start ++import org.bukkit.event.entity.EntityPotionEffectEvent; ++// CraftBukkit end ++ + public interface ConsumeEffect { + + Codec CODEC = BuiltInRegistries.CONSUME_EFFECT_TYPE.byNameCodec().dispatch(ConsumeEffect::getType, ConsumeEffect.a::codec); +@@ -19,7 +23,15 @@ + + ConsumeEffect.a getType(); + +- boolean apply(World world, ItemStack itemstack, EntityLiving entityliving); ++ // CraftBukkit start ++ default boolean apply(World world, ItemStack itemstack, EntityLiving entityliving) { ++ return this.apply(world, itemstack, entityliving, EntityPotionEffectEvent.Cause.UNKNOWN); ++ } ++ ++ default boolean apply(World world, ItemStack itemstack, EntityLiving entityliving, EntityPotionEffectEvent.Cause cause) { ++ return this.apply(world, itemstack, entityliving); ++ } ++ // CraftBukkit end + + public static record a(MapCodec codec, StreamCodec streamCodec) { + diff --git a/paper-server/nms-patches/net/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffect.patch b/paper-server/nms-patches/net/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffect.patch new file mode 100644 index 0000000000..4e7586f72a --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffect.patch @@ -0,0 +1,30 @@ +--- a/net/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffect.java ++++ b/net/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffect.java +@@ -15,6 +15,10 @@ + import net.minecraft.world.item.ItemStack; + import net.minecraft.world.level.World; + ++// CraftBukkit start ++import org.bukkit.event.entity.EntityPotionEffectEvent; ++// CraftBukkit end ++ + public record RemoveStatusEffectsConsumeEffect(HolderSet effects) implements ConsumeEffect { + + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { +@@ -32,14 +36,14 @@ + } + + @Override +- public boolean apply(World world, ItemStack itemstack, EntityLiving entityliving) { ++ public boolean apply(World world, ItemStack itemstack, EntityLiving entityliving, EntityPotionEffectEvent.Cause cause) { // CraftBukkit + boolean flag = false; + Iterator iterator = this.effects.iterator(); + + while (iterator.hasNext()) { + Holder holder = (Holder) iterator.next(); + +- if (entityliving.removeEffect(holder)) { ++ if (entityliving.removeEffect(holder, cause)) { // CraftBukkit + flag = true; + } + } diff --git a/paper-server/nms-patches/net/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffect.patch b/paper-server/nms-patches/net/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffect.patch new file mode 100644 index 0000000000..b8af6a41f5 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffect.patch @@ -0,0 +1,20 @@ +--- a/net/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffect.java ++++ b/net/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffect.java +@@ -53,7 +53,16 @@ + + Vec3D vec3d = entityliving.position(); + +- if (entityliving.randomTeleport(d0, d1, d2, true)) { ++ // CraftBukkit start - handle canceled status of teleport event ++ java.util.Optional status = entityliving.randomTeleport(d0, d1, d2, true, org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT); ++ ++ if (!status.isPresent()) { ++ // teleport event was canceled, no more tries ++ break; ++ } ++ ++ if (status.get()) { ++ // CraftBukkit end + world.gameEvent((Holder) GameEvent.TELEPORT, vec3d, GameEvent.a.of((Entity) entityliving)); + SoundEffect soundeffect; + SoundCategory soundcategory; diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/CraftingManager.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/CraftingManager.patch index 17bd7807a9..3653f81f89 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/crafting/CraftingManager.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/CraftingManager.patch @@ -1,108 +1,87 @@ --- a/net/minecraft/world/item/crafting/CraftingManager.java +++ b/net/minecraft/world/item/crafting/CraftingManager.java -@@ -34,6 +34,11 @@ +@@ -38,6 +38,10 @@ import net.minecraft.world.level.World; import org.slf4j.Logger; +// CraftBukkit start -+import com.google.common.collect.LinkedHashMultimap; -+import com.google.common.collect.Maps; ++import java.util.Collections; +// CraftBukkit end + - public class CraftingManager extends ResourceDataJson { + public class CraftingManager extends ResourceDataAbstract implements RecipeAccess { - private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create(); -@@ -70,11 +75,26 @@ - } - } - -- this.byType = builder.build(); -- this.byName = com_google_common_collect_immutablemap_builder.build(); -+ // CraftBukkit start - mutable -+ this.byType = LinkedHashMultimap.create(builder.build()); -+ this.byName = Maps.newHashMap(com_google_common_collect_immutablemap_builder.build()); -+ // CraftBukkit end - CraftingManager.LOGGER.info("Loaded {} recipes", this.byType.size()); + private static final Logger LOGGER = LogUtils.getLogger(); +@@ -109,7 +113,23 @@ + CraftingManager.LOGGER.info("Loaded {} recipes", recipemap.values().size()); } + // CraftBukkit start + public void addRecipe(RecipeHolder irecipe) { -+ Collection> map = this.byType.get(irecipe.value().getType()); // CraftBukkit ++ this.recipes.addRecipe(irecipe); ++ finalizeRecipeLoading(); ++ } + -+ if (byName.containsKey(irecipe.id())) { -+ throw new IllegalStateException("Duplicate recipe ignored with ID " + irecipe.id()); -+ } else { -+ map.add(irecipe); -+ byName.put(irecipe.id(), irecipe); ++ private FeatureFlagSet featureflagset; ++ ++ public void finalizeRecipeLoading() { ++ if (featureflagset != null) { ++ finalizeRecipeLoading(featureflagset); + } + } -+ // CraftBukkit end + - public boolean hadErrorsLoading() { - return this.hasErrors; - } -@@ -90,9 +110,13 @@ + public void finalizeRecipeLoading(FeatureFlagSet featureflagset) { ++ this.featureflagset = featureflagset; ++ // CraftBukkit end + List> list = new ArrayList(); + List list1 = CraftingManager.RECIPE_PROPERTY_SETS.entrySet().stream().map((entry) -> { + return new CraftingManager.b((ResourceKey) entry.getKey(), (CraftingManager.c) entry.getValue()); +@@ -128,7 +148,7 @@ + RecipeStonecutting recipestonecutting = (RecipeStonecutting) irecipe; + + if (isIngredientEnabled(featureflagset, recipestonecutting.input()) && recipestonecutting.resultDisplay().isEnabled(featureflagset)) { +- list.add(new SelectableRecipe.a<>(recipestonecutting.input(), new SelectableRecipe<>(recipestonecutting.resultDisplay(), Optional.of(recipeholder)))); ++ list.add(new SelectableRecipe.a(recipestonecutting.input(), new SelectableRecipe<>(recipestonecutting.resultDisplay(), Optional.of((RecipeHolder) recipeholder)))); // CraftBukkit - decompile error + } + } + +@@ -170,7 +190,10 @@ } - public > Optional> getRecipeFor(Recipes recipes, I i0, World world, @Nullable RecipeHolder recipeholder) { -- return i0.isEmpty() ? Optional.empty() : (recipeholder != null && recipeholder.value().matches(i0, world) ? Optional.of(recipeholder) : this.byType(recipes).stream().filter((recipeholder1) -> { + public > Optional> getRecipeFor(Recipes recipes, I i0, World world) { +- return this.recipes.getRecipesFor(recipes, i0, world).findFirst(); + // CraftBukkit start -+ List> list = this.byType(recipes).stream().filter((recipeholder1) -> { - return recipeholder1.value().matches(i0, world); -- }).findFirst()); -+ }).toList(); -+ Optional> recipe = (list.isEmpty() || i0.isEmpty()) ? Optional.empty() : (recipeholder != null && recipeholder.value().matches(i0, world) ? Optional.of(recipeholder) : Optional.of(list.getLast())); // CraftBukkit - SPIGOT-4638: last recipe gets priority -+ return recipe; ++ List> list = this.recipes.getRecipesFor(recipes, i0, world).toList(); ++ return (list.isEmpty()) ? Optional.empty() : Optional.of(list.getLast()); // CraftBukkit - SPIGOT-4638: last recipe gets priority + // CraftBukkit end } - public > List> getAllRecipesFor(Recipes recipes) { -@@ -108,7 +132,7 @@ - } - - private > Collection> byType(Recipes recipes) { -- return this.byType.get(recipes); -+ return (Collection) this.byType.get(recipes); // CraftBukkit - decompile error - } - - public > NonNullList getRemainingItemsFor(Recipes recipes, I i0, World world) { -@@ -135,7 +159,7 @@ - private > RecipeHolder byKeyTyped(Recipes recipes, MinecraftKey minecraftkey) { - RecipeHolder recipeholder = (RecipeHolder) this.byName.get(minecraftkey); + public Optional> byKey(ResourceKey> resourcekey) { +@@ -181,7 +204,7 @@ + private > RecipeHolder byKeyTyped(Recipes recipes, ResourceKey> resourcekey) { + RecipeHolder recipeholder = this.recipes.byKey(resourcekey); - return recipeholder != null && recipeholder.value().getType().equals(recipes) ? recipeholder : null; + return recipeholder != null && recipeholder.value().getType().equals(recipes) ? (RecipeHolder) recipeholder : null; // CraftBukkit - decompile error } - public Collection> getOrderedRecipes() { -@@ -171,10 +195,31 @@ - com_google_common_collect_immutablemap_builder.put(recipeholder.id(), recipeholder); - } - -- this.byType = builder.build(); -- this.byName = com_google_common_collect_immutablemap_builder.build(); -+ // CraftBukkit start - mutable -+ this.byType = LinkedHashMultimap.create(builder.build()); -+ this.byName = Maps.newHashMap(com_google_common_collect_immutablemap_builder.build()); -+ // CraftBukkit end -+ } -+ -+ // CraftBukkit start -+ public boolean removeRecipe(MinecraftKey mcKey) { -+ Iterator> iter = byType.values().iterator(); -+ while (iter.hasNext()) { -+ RecipeHolder recipe = iter.next(); -+ if (recipe.id().equals(mcKey)) { -+ iter.remove(); -+ } -+ } -+ -+ return byName.remove(mcKey) != null; + public Map, RecipePropertySet> getSynchronizedItemProperties() { +@@ -229,6 +252,22 @@ + return new RecipeHolder<>(resourcekey, irecipe); } ++ // CraftBukkit start ++ public boolean removeRecipe(ResourceKey> mcKey) { ++ boolean removed = this.recipes.removeRecipe(mcKey); ++ if (removed) { ++ finalizeRecipeLoading(); ++ } ++ ++ return removed; ++ } ++ + public void clearRecipes() { -+ this.byType = LinkedHashMultimap.create(); -+ this.byName = Maps.newHashMap(); ++ this.recipes = RecipeMap.create(Collections.emptyList()); ++ finalizeRecipeLoading(); + } + // CraftBukkit end + diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/FurnaceRecipe.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/FurnaceRecipe.patch index 30ac7e9127..d69f2a7b64 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/crafting/FurnaceRecipe.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/FurnaceRecipe.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/item/crafting/FurnaceRecipe.java +++ b/net/minecraft/world/item/crafting/FurnaceRecipe.java -@@ -3,6 +3,14 @@ +@@ -4,6 +4,14 @@ import net.minecraft.world.item.ItemStack; - import net.minecraft.world.level.block.Blocks; + import net.minecraft.world.item.Items; +// CraftBukkit start +import org.bukkit.NamespacedKey; @@ -15,18 +15,18 @@ public class FurnaceRecipe extends RecipeCooking { public FurnaceRecipe(String s, CookingBookCategory cookingbookcategory, RecipeItemStack recipeitemstack, ItemStack itemstack, float f, int i) { -@@ -18,4 +26,17 @@ - public RecipeSerializer getSerializer() { - return RecipeSerializer.SMELTING_RECIPE; +@@ -45,4 +53,17 @@ + + return recipebookcategory; } + + // CraftBukkit start + @Override + public Recipe toBukkitRecipe(NamespacedKey id) { -+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result); ++ CraftItemStack result = CraftItemStack.asCraftMirror(this.result()); + -+ CraftFurnaceRecipe recipe = new CraftFurnaceRecipe(id, result, CraftRecipe.toBukkit(this.ingredient), this.experience, this.cookingTime); -+ recipe.setGroup(this.group); ++ CraftFurnaceRecipe recipe = new CraftFurnaceRecipe(id, result, CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime()); ++ recipe.setGroup(this.group()); + recipe.setCategory(CraftRecipe.getCategory(this.category())); + + return recipe; diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/IRecipe.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/IRecipe.patch index 85949adca2..4d92b7060a 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/crafting/IRecipe.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/IRecipe.patch @@ -1,9 +1,9 @@ --- a/net/minecraft/world/item/crafting/IRecipe.java +++ b/net/minecraft/world/item/crafting/IRecipe.java -@@ -71,4 +71,6 @@ - return recipeitemstack.getItems().length == 0; - }); +@@ -44,4 +44,6 @@ } + + RecipeBookCategory recipeBookCategory(); + + org.bukkit.inventory.Recipe toBukkitRecipe(org.bukkit.NamespacedKey id); // CraftBukkit } diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/IRecipeComplex.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/IRecipeComplex.patch index 4087f9ddb6..911c079072 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/crafting/IRecipeComplex.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/IRecipeComplex.patch @@ -1,11 +1,11 @@ --- a/net/minecraft/world/item/crafting/IRecipeComplex.java +++ b/net/minecraft/world/item/crafting/IRecipeComplex.java -@@ -3,6 +3,15 @@ - import net.minecraft.core.HolderLookup; - import net.minecraft.world.item.ItemStack; +@@ -8,6 +8,15 @@ + import net.minecraft.network.RegistryFriendlyByteBuf; + import net.minecraft.network.codec.StreamCodec; +// CraftBukkit start -+import net.minecraft.core.IRegistryCustom; ++import net.minecraft.world.item.ItemStack; +import org.bukkit.NamespacedKey; +import org.bukkit.craftbukkit.inventory.CraftComplexRecipe; +import org.bukkit.craftbukkit.inventory.CraftItemStack; @@ -16,21 +16,39 @@ public abstract class IRecipeComplex implements RecipeCrafting { private final CraftingBookCategory category; -@@ -25,4 +34,17 @@ - public CraftingBookCategory category() { - return this.category; - } -+ +@@ -34,6 +43,19 @@ + @Override + public abstract RecipeSerializer getSerializer(); + + // CraftBukkit start + @Override + public Recipe toBukkitRecipe(NamespacedKey id) { -+ CraftItemStack result = CraftItemStack.asCraftMirror(getResultItem(IRegistryCustom.EMPTY)); ++ CraftItemStack result = CraftItemStack.asCraftMirror(ItemStack.EMPTY); + + CraftComplexRecipe recipe = new CraftComplexRecipe(id, result, this); -+ recipe.setGroup(this.getGroup()); ++ recipe.setGroup(this.group()); + recipe.setCategory(CraftRecipe.getCategory(this.category())); + + return recipe; + } + // CraftBukkit end - } ++ + public static class Serializer implements RecipeSerializer { + + private final MapCodec codec; +@@ -41,13 +63,13 @@ + + public Serializer(IRecipeComplex.Serializer.Factory irecipecomplex_serializer_factory) { + this.codec = RecordCodecBuilder.mapCodec((instance) -> { +- P1 p1 = instance.group(CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter(RecipeCrafting::category)); ++ P1, CraftingBookCategory> p1 = instance.group(CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter(RecipeCrafting::category)); // CraftBukkit - decompile error + + Objects.requireNonNull(irecipecomplex_serializer_factory); + return p1.apply(instance, irecipecomplex_serializer_factory::create); + }); + StreamCodec streamcodec = CraftingBookCategory.STREAM_CODEC; +- Function function = RecipeCrafting::category; ++ Function function = RecipeCrafting::category; // CraftBukkit - decompile error + + Objects.requireNonNull(irecipecomplex_serializer_factory); + this.streamCodec = StreamCodec.composite(streamcodec, function, irecipecomplex_serializer_factory::create); diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeBlasting.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeBlasting.patch index daa0c936b0..3adff4ba81 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeBlasting.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeBlasting.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/item/crafting/RecipeBlasting.java +++ b/net/minecraft/world/item/crafting/RecipeBlasting.java -@@ -3,6 +3,14 @@ +@@ -4,6 +4,14 @@ import net.minecraft.world.item.ItemStack; - import net.minecraft.world.level.block.Blocks; + import net.minecraft.world.item.Items; +// CraftBukkit start +import org.bukkit.NamespacedKey; @@ -15,18 +15,18 @@ public class RecipeBlasting extends RecipeCooking { public RecipeBlasting(String s, CookingBookCategory cookingbookcategory, RecipeItemStack recipeitemstack, ItemStack itemstack, float f, int i) { -@@ -18,4 +26,17 @@ - public RecipeSerializer getSerializer() { - return RecipeSerializer.BLASTING_RECIPE; +@@ -43,4 +51,17 @@ + + return recipebookcategory; } + + // CraftBukkit start + @Override + public Recipe toBukkitRecipe(NamespacedKey id) { -+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result); ++ CraftItemStack result = CraftItemStack.asCraftMirror(this.result()); + -+ CraftBlastingRecipe recipe = new CraftBlastingRecipe(id, result, CraftRecipe.toBukkit(this.ingredient), this.experience, this.cookingTime); -+ recipe.setGroup(this.group); ++ CraftBlastingRecipe recipe = new CraftBlastingRecipe(id, result, CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime()); ++ recipe.setGroup(this.group()); + recipe.setCategory(CraftRecipe.getCategory(this.category())); + + return recipe; diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeCampfire.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeCampfire.patch index fa7909db0b..17887eef2f 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeCampfire.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeCampfire.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/item/crafting/RecipeCampfire.java +++ b/net/minecraft/world/item/crafting/RecipeCampfire.java -@@ -3,6 +3,14 @@ +@@ -4,6 +4,14 @@ import net.minecraft.world.item.ItemStack; - import net.minecraft.world.level.block.Blocks; + import net.minecraft.world.item.Items; +// CraftBukkit start +import org.bukkit.NamespacedKey; @@ -15,18 +15,18 @@ public class RecipeCampfire extends RecipeCooking { public RecipeCampfire(String s, CookingBookCategory cookingbookcategory, RecipeItemStack recipeitemstack, ItemStack itemstack, float f, int i) { -@@ -18,4 +26,17 @@ - public RecipeSerializer getSerializer() { - return RecipeSerializer.CAMPFIRE_COOKING_RECIPE; +@@ -29,4 +37,17 @@ + public RecipeBookCategory recipeBookCategory() { + return RecipeBookCategories.CAMPFIRE; } + + // CraftBukkit start + @Override + public Recipe toBukkitRecipe(NamespacedKey id) { -+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result); ++ CraftItemStack result = CraftItemStack.asCraftMirror(this.result()); + -+ CraftCampfireRecipe recipe = new CraftCampfireRecipe(id, result, CraftRecipe.toBukkit(this.ingredient), this.experience, this.cookingTime); -+ recipe.setGroup(this.group); ++ CraftCampfireRecipe recipe = new CraftCampfireRecipe(id, result, CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime()); ++ recipe.setGroup(this.group()); + recipe.setCategory(CraftRecipe.getCategory(this.category())); + + return recipe; diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeHolder.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeHolder.patch index 6ded93bb2d..e6d62f7081 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeHolder.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeHolder.patch @@ -1,22 +1,22 @@ --- a/net/minecraft/world/item/crafting/RecipeHolder.java +++ b/net/minecraft/world/item/crafting/RecipeHolder.java -@@ -4,8 +4,19 @@ +@@ -5,8 +5,19 @@ import net.minecraft.network.codec.StreamCodec; - import net.minecraft.resources.MinecraftKey; + import net.minecraft.resources.ResourceKey; +// CraftBukkit start +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.inventory.Recipe; +// CraftBukkit end + - public record RecipeHolder>(MinecraftKey id, T value) { + public record RecipeHolder>(ResourceKey> id, T value) { + // CraftBukkit start + public final Recipe toBukkitRecipe() { -+ return this.value.toBukkitRecipe(CraftNamespacedKey.fromMinecraft(this.id)); ++ return this.value.toBukkitRecipe(CraftNamespacedKey.fromMinecraft(this.id.location())); + } + // CraftBukkit end + - public static final StreamCodec> STREAM_CODEC = StreamCodec.composite(MinecraftKey.STREAM_CODEC, RecipeHolder::id, IRecipe.STREAM_CODEC, RecipeHolder::value, RecipeHolder::new); + public static final StreamCodec> STREAM_CODEC = StreamCodec.composite(ResourceKey.streamCodec(Registries.RECIPE), RecipeHolder::id, IRecipe.STREAM_CODEC, RecipeHolder::value, RecipeHolder::new); public boolean equals(Object object) { diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeItemStack.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeItemStack.patch index 3141f27343..0d36ff3da8 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeItemStack.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeItemStack.patch @@ -1,26 +1,52 @@ --- a/net/minecraft/world/item/crafting/RecipeItemStack.java +++ b/net/minecraft/world/item/crafting/RecipeItemStack.java -@@ -40,6 +40,7 @@ - public ItemStack[] itemStacks; +@@ -42,6 +42,24 @@ + private final HolderSet values; @Nullable - private IntList stackingIds; -+ public boolean exact; // CraftBukkit - public static final Codec CODEC = codec(true); - public static final Codec CODEC_NONEMPTY = codec(false); - -@@ -77,6 +78,15 @@ - for (int j = 0; j < i; ++j) { - ItemStack itemstack1 = aitemstack[j]; - -+ // CraftBukkit start -+ if (exact) { -+ if (itemstack1.getItem() == itemstack.getItem() && ItemStack.isSameItemSameComponents(itemstack, itemstack1)) { -+ return true; -+ } + private List> items; ++ // CraftBukkit start ++ @Nullable ++ private List itemStacks; + -+ continue; ++ public boolean isExact() { ++ return this.itemStacks != null; ++ } ++ ++ public List itemStacks() { ++ return this.itemStacks; ++ } ++ ++ public static RecipeItemStack ofStacks(Stream stacks) { ++ RecipeItemStack recipe = RecipeItemStack.of(stacks.map(ItemStack::getItem)); ++ recipe.itemStacks = stacks.toList(); ++ return recipe; ++ } ++ // CraftBukkit end + + private RecipeItemStack(HolderSet holderset) { + holderset.unwrap().ifRight((list) -> { +@@ -72,6 +90,15 @@ + } + + public boolean test(ItemStack itemstack) { ++ // CraftBukkit start ++ if (this.isExact()) { ++ for (ItemStack itemstack1 : this.itemStacks()) { ++ if (itemstack1.getItem() == itemstack.getItem() && ItemStack.isSameItemSameComponents(itemstack, itemstack1)) { ++ return true; + } -+ // CraftBukkit end - if (itemstack1.is(itemstack.getItem())) { - return true; - } ++ } ++ } ++ // CraftBukkit end + List> list = this.items(); + + for (int i = 0; i < list.size(); ++i) { +@@ -85,7 +112,7 @@ + + public boolean equals(Object object) { + if (object instanceof RecipeItemStack recipeitemstack) { +- return Objects.equals(this.values, recipeitemstack.values); ++ return Objects.equals(this.values, recipeitemstack.values) && Objects.equals(this.itemStacks, recipeitemstack.itemStacks); // CraftBukkit + } else { + return false; + } diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeMap.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeMap.patch new file mode 100644 index 0000000000..7a21b05a74 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeMap.patch @@ -0,0 +1,56 @@ +--- a/net/minecraft/world/item/crafting/RecipeMap.java ++++ b/net/minecraft/world/item/crafting/RecipeMap.java +@@ -12,6 +12,11 @@ + import net.minecraft.resources.ResourceKey; + import net.minecraft.world.level.World; + ++// CraftBukkit start ++import com.google.common.collect.LinkedHashMultimap; ++import com.google.common.collect.Maps; ++// CraftBukkit end ++ + public class RecipeMap { + + public static final RecipeMap EMPTY = new RecipeMap(ImmutableMultimap.of(), Map.of()); +@@ -35,11 +40,39 @@ + com_google_common_collect_immutablemap_builder.put(recipeholder.id(), recipeholder); + } + +- return new RecipeMap(builder.build(), com_google_common_collect_immutablemap_builder.build()); ++ // CraftBukkit start - mutable ++ return new RecipeMap(LinkedHashMultimap.create(builder.build()), Maps.newHashMap(com_google_common_collect_immutablemap_builder.build())); ++ } ++ ++ public void addRecipe(RecipeHolder irecipe) { ++ Collection> map = this.byType.get(irecipe.value().getType()); ++ ++ if (byKey.containsKey(irecipe.id())) { ++ throw new IllegalStateException("Duplicate recipe ignored with ID " + irecipe.id()); ++ } else { ++ map.add(irecipe); ++ byKey.put(irecipe.id(), irecipe); ++ } + } + ++ public boolean removeRecipe(ResourceKey> mcKey) { ++ boolean removed = false; ++ Iterator> iter = byType.values().iterator(); ++ while (iter.hasNext()) { ++ RecipeHolder recipe = iter.next(); ++ if (recipe.id().equals(mcKey)) { ++ iter.remove(); ++ removed = true; ++ } ++ } ++ removed |= byKey.remove(mcKey) != null; ++ ++ return removed; ++ } ++ // CraftBukkit end ++ + public > Collection> byType(Recipes recipes) { +- return this.byType.get(recipes); ++ return (Collection) this.byType.get(recipes); // CraftBukkit - decompile error + } + + public Collection> values() { diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeSmoking.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeSmoking.patch index 2fe0991274..d168b47569 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeSmoking.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeSmoking.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/item/crafting/RecipeSmoking.java +++ b/net/minecraft/world/item/crafting/RecipeSmoking.java -@@ -3,6 +3,14 @@ +@@ -4,6 +4,14 @@ import net.minecraft.world.item.ItemStack; - import net.minecraft.world.level.block.Blocks; + import net.minecraft.world.item.Items; +// CraftBukkit start +import org.bukkit.NamespacedKey; @@ -15,18 +15,18 @@ public class RecipeSmoking extends RecipeCooking { public RecipeSmoking(String s, CookingBookCategory cookingbookcategory, RecipeItemStack recipeitemstack, ItemStack itemstack, float f, int i) { -@@ -18,4 +26,17 @@ - public RecipeSerializer getSerializer() { - return RecipeSerializer.SMOKING_RECIPE; +@@ -29,4 +37,17 @@ + public RecipeBookCategory recipeBookCategory() { + return RecipeBookCategories.SMOKER_FOOD; } + + // CraftBukkit start + @Override + public Recipe toBukkitRecipe(NamespacedKey id) { -+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result); ++ CraftItemStack result = CraftItemStack.asCraftMirror(this.result()); + -+ CraftSmokingRecipe recipe = new CraftSmokingRecipe(id, result, CraftRecipe.toBukkit(this.ingredient), this.experience, this.cookingTime); -+ recipe.setGroup(this.group); ++ CraftSmokingRecipe recipe = new CraftSmokingRecipe(id, result, CraftRecipe.toBukkit(this.input()), this.experience(), this.cookingTime()); ++ recipe.setGroup(this.group()); + recipe.setCategory(CraftRecipe.getCategory(this.category())); + + return recipe; diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeStonecutting.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeStonecutting.patch index 21b2a7fe2b..41726d8c86 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeStonecutting.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/RecipeStonecutting.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/item/crafting/RecipeStonecutting.java +++ b/net/minecraft/world/item/crafting/RecipeStonecutting.java -@@ -4,6 +4,14 @@ - import net.minecraft.world.level.World; - import net.minecraft.world.level.block.Blocks; +@@ -7,6 +7,14 @@ + import net.minecraft.world.item.crafting.display.SlotDisplay; + import net.minecraft.world.item.crafting.display.StonecutterRecipeDisplay; +// CraftBukkit start +import org.bukkit.NamespacedKey; @@ -15,18 +15,18 @@ public class RecipeStonecutting extends RecipeSingleItem { public RecipeStonecutting(String s, RecipeItemStack recipeitemstack, ItemStack itemstack) { -@@ -18,4 +26,16 @@ - public ItemStack getToastSymbol() { - return new ItemStack(Blocks.STONECUTTER); +@@ -36,4 +44,16 @@ + public RecipeBookCategory recipeBookCategory() { + return RecipeBookCategories.STONECUTTER; } + + // CraftBukkit start + @Override + public Recipe toBukkitRecipe(NamespacedKey id) { -+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result); ++ CraftItemStack result = CraftItemStack.asCraftMirror(this.result()); + -+ CraftStonecuttingRecipe recipe = new CraftStonecuttingRecipe(id, result, CraftRecipe.toBukkit(this.ingredient)); -+ recipe.setGroup(this.group); ++ CraftStonecuttingRecipe recipe = new CraftStonecuttingRecipe(id, result, CraftRecipe.toBukkit(this.input())); ++ recipe.setGroup(this.group()); + + return recipe; + } diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/ShapedRecipes.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/ShapedRecipes.patch index a9a8c24aa0..26816fcf72 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/crafting/ShapedRecipes.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/ShapedRecipes.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/item/crafting/ShapedRecipes.java +++ b/net/minecraft/world/item/crafting/ShapedRecipes.java -@@ -10,6 +10,14 @@ - import net.minecraft.world.item.ItemStack; +@@ -17,6 +17,14 @@ + import net.minecraft.world.item.crafting.display.SlotDisplay; import net.minecraft.world.level.World; +// CraftBukkit start @@ -15,7 +15,7 @@ public class ShapedRecipes implements RecipeCrafting { final ShapedRecipePattern pattern; -@@ -30,6 +38,68 @@ +@@ -39,6 +47,68 @@ this(s, craftingbookcategory, shapedrecipepattern, itemstack, true); } @@ -69,7 +69,7 @@ + break; + } + char c = 'a'; -+ for (RecipeItemStack list : this.pattern.ingredients()) { ++ for (Optional list : this.pattern.ingredients()) { + RecipeChoice choice = CraftRecipe.toBukkit(list); + if (choice != null) { + recipe.setIngredient(c, choice); @@ -82,5 +82,5 @@ + // CraftBukkit end + @Override - public RecipeSerializer getSerializer() { + public RecipeSerializer getSerializer() { return RecipeSerializer.SHAPED_RECIPE; diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/ShapelessRecipes.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/ShapelessRecipes.patch index 68bf0e1eed..1045293ac2 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/crafting/ShapelessRecipes.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/ShapelessRecipes.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/item/crafting/ShapelessRecipes.java +++ b/net/minecraft/world/item/crafting/ShapelessRecipes.java -@@ -13,6 +13,13 @@ - import net.minecraft.world.item.ItemStack; +@@ -17,6 +17,13 @@ + import net.minecraft.world.item.crafting.display.SlotDisplay; import net.minecraft.world.level.World; +// CraftBukkit start @@ -14,8 +14,8 @@ public class ShapelessRecipes implements RecipeCrafting { final String group; -@@ -27,6 +34,22 @@ - this.ingredients = nonnulllist; +@@ -33,6 +40,22 @@ + this.ingredients = list; } + // CraftBukkit start @@ -35,5 +35,5 @@ + // CraftBukkit end + @Override - public RecipeSerializer getSerializer() { + public RecipeSerializer getSerializer() { return RecipeSerializer.SHAPELESS_RECIPE; diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/SmithingTransformRecipe.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/SmithingTransformRecipe.patch index 30f56c61d3..5594867ed5 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/crafting/SmithingTransformRecipe.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/SmithingTransformRecipe.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/item/crafting/SmithingTransformRecipe.java +++ b/net/minecraft/world/item/crafting/SmithingTransformRecipe.java -@@ -9,6 +9,14 @@ - import net.minecraft.world.item.ItemStack; - import net.minecraft.world.level.World; +@@ -14,6 +14,14 @@ + import net.minecraft.world.item.crafting.display.SlotDisplay; + import net.minecraft.world.item.crafting.display.SmithingRecipeDisplay; +// CraftBukkit start +import org.bukkit.NamespacedKey; @@ -14,9 +14,9 @@ + public class SmithingTransformRecipe implements SmithingRecipe { - final RecipeItemStack template; -@@ -64,6 +72,17 @@ - return Stream.of(this.template, this.base, this.addition).anyMatch(RecipeItemStack::isEmpty); + final Optional template; +@@ -71,6 +79,17 @@ + return List.of(new SmithingRecipeDisplay(RecipeItemStack.optionalIngredientToDisplay(this.template), RecipeItemStack.optionalIngredientToDisplay(this.base), RecipeItemStack.optionalIngredientToDisplay(this.addition), new SlotDisplay.f(this.result), new SlotDisplay.d(Items.SMITHING_TABLE))); } + // CraftBukkit start diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/SmithingTrimRecipe.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/SmithingTrimRecipe.patch index 3cf830349c..3b2a1c61e9 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/crafting/SmithingTrimRecipe.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/SmithingTrimRecipe.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/item/crafting/SmithingTrimRecipe.java +++ b/net/minecraft/world/item/crafting/SmithingTrimRecipe.java -@@ -19,6 +19,13 @@ - import net.minecraft.world.item.armortrim.TrimPatterns; - import net.minecraft.world.level.World; +@@ -21,6 +21,13 @@ + import net.minecraft.world.item.equipment.trim.TrimPattern; + import net.minecraft.world.item.equipment.trim.TrimPatterns; +// CraftBukkit start +import org.bukkit.NamespacedKey; @@ -13,9 +13,9 @@ + public class SmithingTrimRecipe implements SmithingRecipe { - final RecipeItemStack template; + final Optional template; @@ -97,6 +104,13 @@ - return Stream.of(this.template, this.base, this.addition).anyMatch(RecipeItemStack::isEmpty); + return List.of(new SmithingRecipeDisplay(slotdisplay2, slotdisplay, slotdisplay1, new SlotDisplay.g(slotdisplay, slotdisplay1, slotdisplay2), new SlotDisplay.d(Items.SMITHING_TABLE))); } + // CraftBukkit start diff --git a/paper-server/nms-patches/net/minecraft/world/item/crafting/TransmuteRecipe.patch b/paper-server/nms-patches/net/minecraft/world/item/crafting/TransmuteRecipe.patch new file mode 100644 index 0000000000..b650fe6196 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/item/crafting/TransmuteRecipe.patch @@ -0,0 +1,31 @@ +--- a/net/minecraft/world/item/crafting/TransmuteRecipe.java ++++ b/net/minecraft/world/item/crafting/TransmuteRecipe.java +@@ -20,6 +20,14 @@ + import net.minecraft.world.level.IMaterial; + import net.minecraft.world.level.World; + ++// CraftBukkit start ++import org.bukkit.NamespacedKey; ++import org.bukkit.craftbukkit.inventory.CraftItemType; ++import org.bukkit.craftbukkit.inventory.CraftRecipe; ++import org.bukkit.craftbukkit.inventory.CraftTransmuteRecipe; ++import org.bukkit.inventory.Recipe; ++// CraftBukkit end ++ + public class TransmuteRecipe implements RecipeCrafting { + + final String group; +@@ -84,6 +92,13 @@ + return List.of(new ShapelessCraftingRecipeDisplay(List.of(this.input.display(), this.material.display()), new SlotDisplay.d(this.result), new SlotDisplay.d(Items.CRAFTING_TABLE))); + } + ++ // CraftBukkit start ++ @Override ++ public Recipe toBukkitRecipe(NamespacedKey id) { ++ return new CraftTransmuteRecipe(id, CraftItemType.minecraftToBukkit(this.result.value()), CraftRecipe.toBukkit(this.input), CraftRecipe.toBukkit(this.material)); ++ } ++ // CraftBukkit end ++ + @Override + public RecipeSerializer getSerializer() { + return RecipeSerializer.TRANSMUTE; diff --git a/paper-server/nms-patches/net/minecraft/world/item/enchantment/effects/SummonEntityEffect.patch b/paper-server/nms-patches/net/minecraft/world/item/enchantment/effects/SummonEntityEffect.patch index b95be72a12..60e640d240 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/enchantment/effects/SummonEntityEffect.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/enchantment/effects/SummonEntityEffect.patch @@ -17,8 +17,8 @@ Optional>> optional = this.entityTypes().getRandomElement(worldserver.getRandom()); if (!optional.isEmpty()) { -- Entity entity1 = ((EntityTypes) ((Holder) optional.get()).value()).spawn(worldserver, blockposition, EnumMobSpawn.TRIGGERED); -+ Entity entity1 = ((EntityTypes) ((Holder) optional.get()).value()).create(worldserver, null, blockposition, EnumMobSpawn.TRIGGERED, false, false); // CraftBukkit +- Entity entity1 = ((EntityTypes) ((Holder) optional.get()).value()).spawn(worldserver, blockposition, EntitySpawnReason.TRIGGERED); ++ Entity entity1 = ((EntityTypes) ((Holder) optional.get()).value()).create(worldserver, null, blockposition, EntitySpawnReason.TRIGGERED, false, false); // CraftBukkit if (entity1 != null) { if (entity1 instanceof EntityLightning) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/Explosion.patch b/paper-server/nms-patches/net/minecraft/world/level/Explosion.patch deleted file mode 100644 index 76c609ba3f..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/level/Explosion.patch +++ /dev/null @@ -1,198 +0,0 @@ ---- a/net/minecraft/world/level/Explosion.java -+++ b/net/minecraft/world/level/Explosion.java -@@ -41,6 +41,16 @@ - import net.minecraft.world.phys.MovingObjectPosition; - import net.minecraft.world.phys.Vec3D; - -+// CraftBukkit start -+import net.minecraft.world.entity.boss.EntityComplexPart; -+import net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon; -+import net.minecraft.world.level.block.Blocks; -+import org.bukkit.craftbukkit.event.CraftEventFactory; -+import org.bukkit.event.entity.EntityExplodeEvent; -+import org.bukkit.Location; -+import org.bukkit.event.block.BlockExplodeEvent; -+// CraftBukkit end -+ - public class Explosion { - - private static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new ExplosionDamageCalculator(); -@@ -62,6 +72,10 @@ - private final Holder explosionSound; - private final ObjectArrayList toBlow; - private final Map hitPlayers; -+ // CraftBukkit - add field -+ public boolean wasCanceled = false; -+ public float yield; -+ // CraftBukkit end - - public static DamageSource getDefaultDamageSource(World world, @Nullable Entity entity) { - return world.damageSources().explosion(entity, getIndirectSourceEntityInternal(entity)); -@@ -87,7 +101,7 @@ - this.hitPlayers = Maps.newHashMap(); - this.level = world; - this.source = entity; -- this.radius = f; -+ this.radius = (float) Math.max(f, 0.0); // CraftBukkit - clamp bad values - this.x = d0; - this.y = d1; - this.z = d2; -@@ -98,6 +112,7 @@ - this.smallExplosionParticles = particleparam; - this.largeExplosionParticles = particleparam1; - this.explosionSound = holder; -+ this.yield = this.blockInteraction == Explosion.Effect.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F; // CraftBukkit - } - - private ExplosionDamageCalculator makeDamageCalculator(@Nullable Entity entity) { -@@ -148,6 +163,11 @@ - } - - public void explode() { -+ // CraftBukkit start -+ if (this.radius < 0.1F) { -+ return; -+ } -+ // CraftBukkit end - this.level.gameEvent(this.source, (Holder) GameEvent.EXPLODE, new Vec3D(this.x, this.y, this.z)); - Set set = Sets.newHashSet(); - boolean flag = true; -@@ -230,7 +250,35 @@ - d9 /= d11; - d10 /= d11; - if (this.damageCalculator.shouldDamageEntity(this, entity)) { -- entity.hurt(this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity)); -+ // CraftBukkit start -+ -+ // Special case ender dragon only give knockback if no damage is cancelled -+ // Thinks to note: -+ // - Setting a velocity to a ComplexEntityPart is ignored (and therefore not needed) -+ // - Damaging ComplexEntityPart while forward the damage to EntityEnderDragon -+ // - Damaging EntityEnderDragon does nothing -+ // - EntityEnderDragon hitbock always covers the other parts and is therefore always present -+ if (entity instanceof EntityComplexPart) { -+ continue; -+ } -+ -+ entity.lastDamageCancelled = false; -+ -+ if (entity instanceof EntityEnderDragon) { -+ for (EntityComplexPart entityComplexPart : ((EntityEnderDragon) entity).subEntities) { -+ // Calculate damage separately for each EntityComplexPart -+ if (list.contains(entityComplexPart)) { -+ entityComplexPart.hurt(this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity)); -+ } -+ } -+ } else { -+ entity.hurt(this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity)); -+ } -+ -+ if (entity.lastDamageCancelled) { // SPIGOT-5339, SPIGOT-6252, SPIGOT-6777: Skip entity if damage event was cancelled -+ continue; -+ } -+ // CraftBukkit end - } - - double d12 = (1.0D - d7) * (double) getSeenPercent(vec3d, entity) * (double) this.damageCalculator.getKnockbackMultiplier(entity); -@@ -249,6 +297,17 @@ - d10 *= d13; - Vec3D vec3d1 = new Vec3D(d8, d9, d10); - -+ // CraftBukkit start - Call EntityKnockbackEvent -+ if (entity instanceof EntityLiving) { -+ Vec3D result = entity.getDeltaMovement().add(vec3d1); -+ org.bukkit.event.entity.EntityKnockbackEvent event = CraftEventFactory.callEntityKnockbackEvent((org.bukkit.craftbukkit.entity.CraftLivingEntity) entity.getBukkitEntity(), source, org.bukkit.event.entity.EntityKnockbackEvent.KnockbackCause.EXPLOSION, d13, vec3d1, result.x, result.y, result.z); -+ -+ // SPIGOT-7640: Need to subtract entity movement from the event result, -+ // since the code below (the setDeltaMovement call as well as the hitPlayers map) -+ // want the vector to be the relative velocity will the event provides the absolute velocity -+ vec3d1 = (event.isCancelled()) ? Vec3D.ZERO : new Vec3D(event.getFinalKnockback().getX(), event.getFinalKnockback().getY(), event.getFinalKnockback().getZ()).subtract(entity.getDeltaMovement()); -+ } -+ // CraftBukkit end - entity.setDeltaMovement(entity.getDeltaMovement().add(vec3d1)); - if (entity instanceof EntityHuman) { - EntityHuman entityhuman = (EntityHuman) entity; -@@ -291,9 +350,62 @@ - - SystemUtils.shuffle(this.toBlow, this.level.random); - ObjectListIterator objectlistiterator = this.toBlow.iterator(); -+ // CraftBukkit start -+ org.bukkit.World bworld = this.level.getWorld(); -+ Location location = new Location(bworld, this.x, this.y, this.z); -+ -+ List blockList = new ObjectArrayList<>(); -+ for (int i1 = this.toBlow.size() - 1; i1 >= 0; i1--) { -+ BlockPosition cpos = this.toBlow.get(i1); -+ org.bukkit.block.Block bblock = bworld.getBlockAt(cpos.getX(), cpos.getY(), cpos.getZ()); -+ if (!bblock.getType().isAir()) { -+ blockList.add(bblock); -+ } -+ } -+ -+ List bukkitBlocks; -+ -+ if (this.source != null) { -+ EntityExplodeEvent event = CraftEventFactory.callEntityExplodeEvent(this.source, blockList, this.yield, getBlockInteraction()); -+ this.wasCanceled = event.isCancelled(); -+ bukkitBlocks = event.blockList(); -+ this.yield = event.getYield(); -+ } else { -+ org.bukkit.block.Block block = location.getBlock(); -+ org.bukkit.block.BlockState blockState = (damageSource.getDirectBlockState() != null) ? damageSource.getDirectBlockState() : block.getState(); -+ BlockExplodeEvent event = CraftEventFactory.callBlockExplodeEvent(block, blockState, blockList, this.yield, getBlockInteraction()); -+ this.wasCanceled = event.isCancelled(); -+ bukkitBlocks = event.blockList(); -+ this.yield = event.getYield(); -+ } -+ -+ this.toBlow.clear(); -+ -+ for (org.bukkit.block.Block bblock : bukkitBlocks) { -+ BlockPosition coords = new BlockPosition(bblock.getX(), bblock.getY(), bblock.getZ()); -+ toBlow.add(coords); -+ } -+ -+ if (this.wasCanceled) { -+ return; -+ } -+ // CraftBukkit end -+ objectlistiterator = this.toBlow.iterator(); - - while (objectlistiterator.hasNext()) { - BlockPosition blockposition = (BlockPosition) objectlistiterator.next(); -+ // CraftBukkit start - TNTPrimeEvent -+ IBlockData iblockdata = this.level.getBlockState(blockposition); -+ Block block = iblockdata.getBlock(); -+ if (block instanceof net.minecraft.world.level.block.BlockTNT) { -+ Entity sourceEntity = source == null ? null : source; -+ BlockPosition sourceBlock = sourceEntity == null ? BlockPosition.containing(this.x, this.y, this.z) : null; -+ if (!CraftEventFactory.callTNTPrimeEvent(this.level, blockposition, org.bukkit.event.block.TNTPrimeEvent.PrimeCause.EXPLOSION, sourceEntity, sourceBlock)) { -+ this.level.sendBlockUpdated(blockposition, Blocks.AIR.defaultBlockState(), iblockdata, 3); // Update the block on the client -+ continue; -+ } -+ } -+ // CraftBukkit end - - this.level.getBlockState(blockposition).onExplosionHit(this.level, blockposition, this, (itemstack, blockposition1) -> { - addOrAppendStack(list, itemstack, blockposition1); -@@ -318,7 +430,11 @@ - BlockPosition blockposition1 = (BlockPosition) objectlistiterator1.next(); - - if (this.random.nextInt(3) == 0 && this.level.getBlockState(blockposition1).isAir() && this.level.getBlockState(blockposition1.below()).isSolidRender(this.level, blockposition1.below())) { -- this.level.setBlockAndUpdate(blockposition1, BlockFireAbstract.getState(this.level, blockposition1)); -+ // CraftBukkit start - Ignition by explosion -+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(this.level, blockposition1, this).isCancelled()) { -+ this.level.setBlockAndUpdate(blockposition1, BlockFireAbstract.getState(this.level, blockposition1)); -+ } -+ // CraftBukkit end - } - } - } -@@ -326,6 +442,7 @@ - } - - private static void addOrAppendStack(List> list, ItemStack itemstack, BlockPosition blockposition) { -+ if (itemstack.isEmpty()) return; // CraftBukkit - SPIGOT-5425 - for (int i = 0; i < list.size(); ++i) { - Pair pair = (Pair) list.get(i); - ItemStack itemstack1 = (ItemStack) pair.getFirst(); diff --git a/paper-server/nms-patches/net/minecraft/world/level/GameRules.patch b/paper-server/nms-patches/net/minecraft/world/level/GameRules.patch index c67fbace54..c239883925 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/GameRules.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/GameRules.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/GameRules.java +++ b/net/minecraft/world/level/GameRules.java -@@ -55,7 +55,7 @@ +@@ -58,7 +58,7 @@ public static final GameRules.GameRuleKey RULE_SENDCOMMANDFEEDBACK = register("sendCommandFeedback", GameRules.GameRuleCategory.CHAT, GameRules.GameRuleBoolean.create(true)); public static final GameRules.GameRuleKey RULE_REDUCEDDEBUGINFO = register("reducedDebugInfo", GameRules.GameRuleCategory.MISC, GameRules.GameRuleBoolean.create(false, (minecraftserver, gamerules_gameruleboolean) -> { int i = gamerules_gameruleboolean.get() ? 22 : 23; @@ -9,7 +9,7 @@ while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer) iterator.next(); -@@ -70,7 +70,7 @@ +@@ -74,7 +74,7 @@ public static final GameRules.GameRuleKey RULE_MAX_ENTITY_CRAMMING = register("maxEntityCramming", GameRules.GameRuleCategory.MOBS, GameRules.GameRuleInt.create(24)); public static final GameRules.GameRuleKey RULE_WEATHER_CYCLE = register("doWeatherCycle", GameRules.GameRuleCategory.UPDATES, GameRules.GameRuleBoolean.create(true)); public static final GameRules.GameRuleKey RULE_LIMITED_CRAFTING = register("doLimitedCrafting", GameRules.GameRuleCategory.PLAYER, GameRules.GameRuleBoolean.create(false, (minecraftserver, gamerules_gameruleboolean) -> { @@ -18,7 +18,7 @@ while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer) iterator.next(); -@@ -86,7 +86,7 @@ +@@ -90,7 +90,7 @@ public static final GameRules.GameRuleKey RULE_DISABLE_RAIDS = register("disableRaids", GameRules.GameRuleCategory.MOBS, GameRules.GameRuleBoolean.create(false)); public static final GameRules.GameRuleKey RULE_DOINSOMNIA = register("doInsomnia", GameRules.GameRuleCategory.SPAWNING, GameRules.GameRuleBoolean.create(true)); public static final GameRules.GameRuleKey RULE_DO_IMMEDIATE_RESPAWN = register("doImmediateRespawn", GameRules.GameRuleCategory.PLAYER, GameRules.GameRuleBoolean.create(false, (minecraftserver, gamerules_gameruleboolean) -> { @@ -27,25 +27,25 @@ while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer) iterator.next(); -@@ -117,7 +117,7 @@ - public static final GameRules.GameRuleKey RULE_DO_VINES_SPREAD = register("doVinesSpread", GameRules.GameRuleCategory.UPDATES, GameRules.GameRuleBoolean.create(true)); - public static final GameRules.GameRuleKey RULE_ENDER_PEARLS_VANISH_ON_DEATH = register("enderPearlsVanishOnDeath", GameRules.GameRuleCategory.PLAYER, GameRules.GameRuleBoolean.create(true)); - public static final GameRules.GameRuleKey RULE_SPAWN_CHUNK_RADIUS = register("spawnChunkRadius", GameRules.GameRuleCategory.MISC, GameRules.GameRuleInt.create(2, 0, 32, (minecraftserver, gamerules_gameruleint) -> { +@@ -123,7 +123,7 @@ + public static final GameRules.GameRuleKey RULE_MINECART_MAX_SPEED = register("minecartMaxSpeed", GameRules.GameRuleCategory.MISC, GameRules.GameRuleInt.create(8, 1, 1000, FeatureFlagSet.of(FeatureFlags.MINECART_IMPROVEMENTS), (minecraftserver, gamerules_gameruleint) -> { + })); + public static final GameRules.GameRuleKey RULE_SPAWN_CHUNK_RADIUS = register("spawnChunkRadius", GameRules.GameRuleCategory.MISC, GameRules.GameRuleInt.create(2, 0, 32, FeatureFlagSet.of(), (minecraftserver, gamerules_gameruleint) -> { - WorldServer worldserver = minecraftserver.overworld(); + WorldServer worldserver = minecraftserver; // CraftBukkit - per-world worldserver.setDefaultSpawnPos(worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle()); })); -@@ -150,7 +150,7 @@ +@@ -164,7 +164,7 @@ } public > T getRule(GameRules.GameRuleKey gamerules_gamerulekey) { -- return (GameRules.GameRuleValue) this.rules.get(gamerules_gamerulekey); -+ return (T) this.rules.get(gamerules_gamerulekey); // CraftBukkit - decompile error - } +- T t0 = (GameRules.GameRuleValue) this.rules.get(gamerules_gamerulekey); ++ T t0 = (T) this.rules.get(gamerules_gamerulekey); // CraftBukkit - decompile error - public NBTTagCompound createTag() { -@@ -164,7 +164,7 @@ + if (t0 == null) { + throw new IllegalArgumentException("Tried to access invalid game rule"); +@@ -184,7 +184,7 @@ private void loadFromTag(DynamicLike dynamiclike) { this.rules.forEach((gamerules_gamerulekey, gamerules_gamerulevalue) -> { @@ -54,14 +54,16 @@ Objects.requireNonNull(gamerules_gamerulevalue); dataresult.ifSuccess(gamerules_gamerulevalue::deserialize); -@@ -184,17 +184,17 @@ - } +@@ -205,19 +205,19 @@ + + private > void callVisitorCap(GameRules.GameRuleVisitor gamerules_gamerulevisitor, GameRules.GameRuleKey gamerules_gamerulekey, GameRules.GameRuleDefinition gamerules_gameruledefinition) { + if (gamerules_gameruledefinition.requiredFeatures.isSubsetOf(this.enabledFeatures)) { +- gamerules_gamerulevisitor.visit(gamerules_gamerulekey, gamerules_gameruledefinition); +- gamerules_gameruledefinition.callVisitor(gamerules_gamerulevisitor, gamerules_gamerulekey); ++ gamerules_gamerulevisitor.visit((GameRules.GameRuleKey) gamerules_gamerulekey, (GameRules.GameRuleDefinition) gamerules_gameruledefinition); // CraftBukkit - decompile error ++ ((GameRules.GameRuleDefinition) gamerules_gameruledefinition).callVisitor(gamerules_gamerulevisitor, (GameRules.GameRuleKey) gamerules_gamerulekey); // CraftBukkit - decompile error + } - private static > void callVisitorCap(GameRules.GameRuleVisitor gamerules_gamerulevisitor, GameRules.GameRuleKey gamerules_gamerulekey, GameRules.GameRuleDefinition gamerules_gameruledefinition) { -- gamerules_gamerulevisitor.visit(gamerules_gamerulekey, gamerules_gameruledefinition); -- gamerules_gameruledefinition.callVisitor(gamerules_gamerulevisitor, gamerules_gamerulekey); -+ gamerules_gamerulevisitor.visit((GameRules.GameRuleKey) gamerules_gamerulekey, (GameRules.GameRuleDefinition) gamerules_gameruledefinition); // CraftBukkit - decompile error -+ ((GameRules.GameRuleDefinition) gamerules_gameruledefinition).callVisitor(gamerules_gamerulevisitor, (GameRules.GameRuleKey) gamerules_gamerulekey); // CraftBukkit - decompile error } - public void assignFrom(GameRules gamerules, @Nullable MinecraftServer minecraftserver) { @@ -76,20 +78,21 @@ T t0 = gamerules.getRule(gamerules_gamerulekey); this.getRule(gamerules_gamerulekey).setFrom(t0, minecraftserver); -@@ -262,10 +262,10 @@ +@@ -285,11 +285,11 @@ final Supplier> argument; private final Function, T> constructor; - final BiConsumer callback; + final BiConsumer callback; // CraftBukkit - per-world private final GameRules.h visitorCaller; + final FeatureFlagSet requiredFeatures; -- GameRuleDefinition(Supplier> supplier, Function, T> function, BiConsumer biconsumer, GameRules.h gamerules_h) { -+ GameRuleDefinition(Supplier> supplier, Function, T> function, BiConsumer biconsumer, GameRules.h gamerules_h) { // CraftBukkit - per-world +- GameRuleDefinition(Supplier> supplier, Function, T> function, BiConsumer biconsumer, GameRules.h gamerules_h, FeatureFlagSet featureflagset) { ++ GameRuleDefinition(Supplier> supplier, Function, T> function, BiConsumer biconsumer, GameRules.h gamerules_h, FeatureFlagSet featureflagset) { // CraftBukkit - per-world this.argument = supplier; this.constructor = function; this.callback = biconsumer; -@@ -277,7 +277,7 @@ +@@ -302,7 +302,7 @@ } public T createRule() { @@ -98,7 +101,7 @@ } public void callVisitor(GameRules.GameRuleVisitor gamerules_gamerulevisitor, GameRules.GameRuleKey gamerules_gamerulekey) { -@@ -297,17 +297,17 @@ +@@ -326,17 +326,17 @@ public void setFromArgument(CommandContext commandcontext, String s) { this.updateFromArgument(commandcontext, s); @@ -119,7 +122,7 @@ public abstract String serialize(); -@@ -321,7 +321,7 @@ +@@ -350,7 +350,7 @@ protected abstract T copy(); @@ -128,7 +131,7 @@ } public interface GameRuleVisitor { -@@ -337,7 +337,7 @@ +@@ -366,7 +366,7 @@ private boolean value; @@ -136,8 +139,8 @@ + static GameRules.GameRuleDefinition create(boolean flag, BiConsumer biconsumer) { // CraftBukkit - per-world return new GameRules.GameRuleDefinition<>(BoolArgumentType::bool, (gamerules_gameruledefinition) -> { return new GameRules.GameRuleBoolean(gamerules_gameruledefinition, flag); - }, biconsumer, GameRules.GameRuleVisitor::visitBoolean); -@@ -362,7 +362,7 @@ + }, biconsumer, GameRules.GameRuleVisitor::visitBoolean, FeatureFlagSet.of()); +@@ -391,7 +391,7 @@ return this.value; } @@ -146,7 +149,7 @@ this.value = flag; this.onChanged(minecraftserver); } -@@ -373,7 +373,7 @@ +@@ -402,7 +402,7 @@ } @Override @@ -155,7 +158,7 @@ this.value = Boolean.parseBoolean(s); } -@@ -392,7 +392,7 @@ +@@ -421,7 +421,7 @@ return new GameRules.GameRuleBoolean(this.type, this.value); } @@ -164,7 +167,7 @@ this.value = gamerules_gameruleboolean.value; this.onChanged(minecraftserver); } -@@ -402,13 +402,13 @@ +@@ -431,13 +431,13 @@ private int value; @@ -172,15 +175,15 @@ + private static GameRules.GameRuleDefinition create(int i, BiConsumer biconsumer) { // CraftBukkit - per-world return new GameRules.GameRuleDefinition<>(IntegerArgumentType::integer, (gamerules_gameruledefinition) -> { return new GameRules.GameRuleInt(gamerules_gameruledefinition, i); - }, biconsumer, GameRules.GameRuleVisitor::visitInteger); + }, biconsumer, GameRules.GameRuleVisitor::visitInteger, FeatureFlagSet.of()); } -- static GameRules.GameRuleDefinition create(int i, int j, int k, BiConsumer biconsumer) { -+ static GameRules.GameRuleDefinition create(int i, int j, int k, BiConsumer biconsumer) { // CraftBukkit - per-world +- static GameRules.GameRuleDefinition create(int i, int j, int k, FeatureFlagSet featureflagset, BiConsumer biconsumer) { ++ static GameRules.GameRuleDefinition create(int i, int j, int k, FeatureFlagSet featureflagset, BiConsumer biconsumer) { // CraftBukkit - per-world return new GameRules.GameRuleDefinition<>(() -> { return IntegerArgumentType.integer(j, k); }, (gamerules_gameruledefinition) -> { -@@ -435,7 +435,7 @@ +@@ -464,7 +464,7 @@ return this.value; } @@ -189,7 +192,7 @@ this.value = i; this.onChanged(minecraftserver); } -@@ -446,7 +446,7 @@ +@@ -475,7 +475,7 @@ } @Override @@ -198,7 +201,7 @@ this.value = safeParse(s); } -@@ -488,7 +488,7 @@ +@@ -517,7 +517,7 @@ return new GameRules.GameRuleInt(this.type, this.value); } diff --git a/paper-server/nms-patches/net/minecraft/world/level/GeneratorAccess.patch b/paper-server/nms-patches/net/minecraft/world/level/GeneratorAccess.patch index 5df5b1c2ac..ff57d08fb9 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/GeneratorAccess.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/GeneratorAccess.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/level/GeneratorAccess.java +++ b/net/minecraft/world/level/GeneratorAccess.java -@@ -121,4 +121,6 @@ +@@ -101,4 +101,6 @@ default void gameEvent(ResourceKey resourcekey, BlockPosition blockposition, GameEvent.a gameevent_a) { - this.gameEvent((Holder) this.registryAccess().registryOrThrow(Registries.GAME_EVENT).getHolderOrThrow(resourcekey), blockposition, gameevent_a); + this.gameEvent((Holder) this.registryAccess().lookupOrThrow(Registries.GAME_EVENT).getOrThrow(resourcekey), blockposition, gameevent_a); } + + net.minecraft.server.level.WorldServer getMinecraftWorld(); // CraftBukkit diff --git a/paper-server/nms-patches/net/minecraft/world/level/IBlockAccess.patch b/paper-server/nms-patches/net/minecraft/world/level/IBlockAccess.patch index 15e1b1d7c4..0e30f8b40a 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/IBlockAccess.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/IBlockAccess.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/IBlockAccess.java +++ b/net/minecraft/world/level/IBlockAccess.java -@@ -26,7 +26,7 @@ +@@ -31,7 +31,7 @@ default Optional getBlockEntity(BlockPosition blockposition, TileEntityTypes tileentitytypes) { TileEntity tileentity = this.getBlockEntity(blockposition); @@ -9,7 +9,7 @@ } IBlockData getBlockState(BlockPosition blockposition); -@@ -58,8 +58,8 @@ +@@ -59,8 +59,8 @@ }); } @@ -20,7 +20,7 @@ IBlockData iblockdata = this.getBlockState(blockposition); Fluid fluid = this.getFluidState(blockposition); Vec3D vec3d = raytrace1.getFrom(); -@@ -72,6 +72,12 @@ +@@ -73,6 +73,12 @@ double d1 = movingobjectpositionblock1 == null ? Double.MAX_VALUE : raytrace1.getFrom().distanceToSqr(movingobjectpositionblock1.getLocation()); return d0 <= d1 ? movingobjectpositionblock : movingobjectpositionblock1; @@ -33,7 +33,7 @@ }, (raytrace1) -> { Vec3D vec3d = raytrace1.getFrom().subtract(raytrace1.getTo()); -@@ -144,7 +150,7 @@ +@@ -145,7 +151,7 @@ double d13 = d10 * (i1 > 0 ? 1.0D - MathHelper.frac(d4) : MathHelper.frac(d4)); double d14 = d11 * (j1 > 0 ? 1.0D - MathHelper.frac(d5) : MathHelper.frac(d5)); diff --git a/paper-server/nms-patches/net/minecraft/world/level/MobSpawnerAbstract.patch b/paper-server/nms-patches/net/minecraft/world/level/MobSpawnerAbstract.patch index 45bf2cf9ac..7e6badc7e0 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/MobSpawnerAbstract.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/MobSpawnerAbstract.patch @@ -9,7 +9,7 @@ private boolean isNearPlayer(World world, BlockPosition blockposition) { @@ -157,13 +158,18 @@ - ((EntityInsentient) entity).finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entity.blockPosition()), EnumMobSpawn.SPAWNER, (GroupDataEntity) null); + ((EntityInsentient) entity).finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entity.blockPosition()), EntitySpawnReason.SPAWNER, (GroupDataEntity) null); } - Optional optional1 = mobspawnerdata.getEquipment(); diff --git a/paper-server/nms-patches/net/minecraft/world/level/ServerExplosion.patch b/paper-server/nms-patches/net/minecraft/world/level/ServerExplosion.patch new file mode 100644 index 0000000000..e2c17adb06 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/level/ServerExplosion.patch @@ -0,0 +1,193 @@ +--- a/net/minecraft/world/level/ServerExplosion.java ++++ b/net/minecraft/world/level/ServerExplosion.java +@@ -35,6 +35,17 @@ + import net.minecraft.world.phys.MovingObjectPosition; + import net.minecraft.world.phys.Vec3D; + ++// CraftBukkit start ++import net.minecraft.world.entity.boss.EntityComplexPart; ++import net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon; ++import net.minecraft.world.level.block.Blocks; ++import org.bukkit.craftbukkit.event.CraftEventFactory; ++import org.bukkit.craftbukkit.util.CraftLocation; ++import org.bukkit.event.entity.EntityExplodeEvent; ++import org.bukkit.Location; ++import org.bukkit.event.block.BlockExplodeEvent; ++// CraftBukkit end ++ + public class ServerExplosion implements Explosion { + + private static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new ExplosionDamageCalculator(); +@@ -50,16 +61,21 @@ + private final DamageSource damageSource; + private final ExplosionDamageCalculator damageCalculator; + private final Map hitPlayers = new HashMap(); ++ // CraftBukkit - add field ++ public boolean wasCanceled = false; ++ public float yield; ++ // CraftBukkit end + + public ServerExplosion(WorldServer worldserver, @Nullable Entity entity, @Nullable DamageSource damagesource, @Nullable ExplosionDamageCalculator explosiondamagecalculator, Vec3D vec3d, float f, boolean flag, Explosion.Effect explosion_effect) { + this.level = worldserver; + this.source = entity; +- this.radius = f; ++ this.radius = (float) Math.max(f, 0.0); // CraftBukkit - clamp bad values + this.center = vec3d; + this.fire = flag; + this.blockInteraction = explosion_effect; + this.damageSource = damagesource == null ? worldserver.damageSources().explosion(this) : damagesource; + this.damageCalculator = explosiondamagecalculator == null ? this.makeDamageCalculator(entity) : explosiondamagecalculator; ++ this.yield = this.blockInteraction == Explosion.Effect.DESTROY_WITH_DECAY ? 1.0F / this.radius : 1.0F; // CraftBukkit + } + + private ExplosionDamageCalculator makeDamageCalculator(@Nullable Entity entity) { +@@ -195,7 +211,35 @@ + float f2 = !flag && f1 == 0.0F ? 0.0F : getSeenPercent(this.center, entity); + + if (flag) { +- entity.hurtServer(this.level, this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity, f2)); ++ // CraftBukkit start ++ ++ // Special case ender dragon only give knockback if no damage is cancelled ++ // Thinks to note: ++ // - Setting a velocity to a ComplexEntityPart is ignored (and therefore not needed) ++ // - Damaging ComplexEntityPart while forward the damage to EntityEnderDragon ++ // - Damaging EntityEnderDragon does nothing ++ // - EntityEnderDragon hitbock always covers the other parts and is therefore always present ++ if (entity instanceof EntityComplexPart) { ++ continue; ++ } ++ ++ entity.lastDamageCancelled = false; ++ ++ if (entity instanceof EntityEnderDragon) { ++ for (EntityComplexPart entityComplexPart : ((EntityEnderDragon) entity).subEntities) { ++ // Calculate damage separately for each EntityComplexPart ++ if (list.contains(entityComplexPart)) { ++ entityComplexPart.hurtServer(this.level, this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity, f2)); ++ } ++ } ++ } else { ++ entity.hurtServer(this.level, this.damageSource, this.damageCalculator.getEntityDamageAmount(this, entity, f2)); ++ } ++ ++ if (entity.lastDamageCancelled) { // SPIGOT-5339, SPIGOT-6252, SPIGOT-6777: Skip entity if damage event was cancelled ++ continue; ++ } ++ // CraftBukkit end + } + + double d5 = (1.0D - d0) * (double) f2 * (double) f1; +@@ -214,6 +258,17 @@ + d3 *= d6; + Vec3D vec3d = new Vec3D(d1, d2, d3); + ++ // CraftBukkit start - Call EntityKnockbackEvent ++ if (entity instanceof EntityLiving) { ++ Vec3D result = entity.getDeltaMovement().add(vec3d); ++ org.bukkit.event.entity.EntityKnockbackEvent event = CraftEventFactory.callEntityKnockbackEvent((org.bukkit.craftbukkit.entity.CraftLivingEntity) entity.getBukkitEntity(), source, org.bukkit.event.entity.EntityKnockbackEvent.KnockbackCause.EXPLOSION, d6, vec3d, result.x, result.y, result.z); ++ ++ // SPIGOT-7640: Need to subtract entity movement from the event result, ++ // since the code below (the setDeltaMovement call as well as the hitPlayers map) ++ // want the vector to be the relative velocity will the event provides the absolute velocity ++ vec3d = (event.isCancelled()) ? Vec3D.ZERO : new Vec3D(event.getFinalKnockback().getX(), event.getFinalKnockback().getY(), event.getFinalKnockback().getZ()).subtract(entity.getDeltaMovement()); ++ } ++ // CraftBukkit end + entity.setDeltaMovement(entity.getDeltaMovement().add(vec3d)); + if (entity instanceof EntityHuman) { + EntityHuman entityhuman = (EntityHuman) entity; +@@ -235,10 +290,62 @@ + List list1 = new ArrayList(); + + SystemUtils.shuffle(list, this.level.random); ++ // CraftBukkit start ++ org.bukkit.World bworld = this.level.getWorld(); ++ Location location = CraftLocation.toBukkit(this.center, bworld); ++ ++ List blockList = new ObjectArrayList<>(); ++ for (int i1 = list.size() - 1; i1 >= 0; i1--) { ++ BlockPosition cpos = list.get(i1); ++ org.bukkit.block.Block bblock = bworld.getBlockAt(cpos.getX(), cpos.getY(), cpos.getZ()); ++ if (!bblock.getType().isAir()) { ++ blockList.add(bblock); ++ } ++ } ++ ++ List bukkitBlocks; ++ ++ if (this.source != null) { ++ EntityExplodeEvent event = CraftEventFactory.callEntityExplodeEvent(this.source, blockList, this.yield, getBlockInteraction()); ++ this.wasCanceled = event.isCancelled(); ++ bukkitBlocks = event.blockList(); ++ this.yield = event.getYield(); ++ } else { ++ org.bukkit.block.Block block = location.getBlock(); ++ org.bukkit.block.BlockState blockState = (damageSource.getDirectBlockState() != null) ? damageSource.getDirectBlockState() : block.getState(); ++ BlockExplodeEvent event = CraftEventFactory.callBlockExplodeEvent(block, blockState, blockList, this.yield, getBlockInteraction()); ++ this.wasCanceled = event.isCancelled(); ++ bukkitBlocks = event.blockList(); ++ this.yield = event.getYield(); ++ } ++ ++ list.clear(); ++ ++ for (org.bukkit.block.Block bblock : bukkitBlocks) { ++ BlockPosition coords = new BlockPosition(bblock.getX(), bblock.getY(), bblock.getZ()); ++ list.add(coords); ++ } ++ ++ if (this.wasCanceled) { ++ return; ++ } ++ // CraftBukkit end + Iterator iterator = list.iterator(); + + while (iterator.hasNext()) { + BlockPosition blockposition = (BlockPosition) iterator.next(); ++ // CraftBukkit start - TNTPrimeEvent ++ IBlockData iblockdata = this.level.getBlockState(blockposition); ++ Block block = iblockdata.getBlock(); ++ if (block instanceof net.minecraft.world.level.block.BlockTNT) { ++ Entity sourceEntity = source == null ? null : source; ++ BlockPosition sourceBlock = sourceEntity == null ? BlockPosition.containing(this.center) : null; ++ if (!CraftEventFactory.callTNTPrimeEvent(this.level, blockposition, org.bukkit.event.block.TNTPrimeEvent.PrimeCause.EXPLOSION, sourceEntity, sourceBlock)) { ++ this.level.sendBlockUpdated(blockposition, Blocks.AIR.defaultBlockState(), iblockdata, 3); // Update the block on the client ++ continue; ++ } ++ } ++ // CraftBukkit end + + this.level.getBlockState(blockposition).onExplosionHit(this.level, blockposition, this, (itemstack, blockposition1) -> { + addOrAppendStack(list1, itemstack, blockposition1); +@@ -262,13 +369,22 @@ + BlockPosition blockposition = (BlockPosition) iterator.next(); + + if (this.level.random.nextInt(3) == 0 && this.level.getBlockState(blockposition).isAir() && this.level.getBlockState(blockposition.below()).isSolidRender()) { +- this.level.setBlockAndUpdate(blockposition, BlockFireAbstract.getState(this.level, blockposition)); ++ // CraftBukkit start - Ignition by explosion ++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(this.level, blockposition, this).isCancelled()) { ++ this.level.setBlockAndUpdate(blockposition, BlockFireAbstract.getState(this.level, blockposition)); ++ } ++ // CraftBukkit end + } + } + + } + + public void explode() { ++ // CraftBukkit start ++ if (this.radius < 0.1F) { ++ return; ++ } ++ // CraftBukkit end + this.level.gameEvent(this.source, (Holder) GameEvent.EXPLODE, this.center); + List list = this.calculateExplodedPositions(); + +@@ -288,6 +404,7 @@ + } + + private static void addOrAppendStack(List list, ItemStack itemstack, BlockPosition blockposition) { ++ if (itemstack.isEmpty()) return; // CraftBukkit - SPIGOT-5425 + Iterator iterator = list.iterator(); + + do { diff --git a/paper-server/nms-patches/net/minecraft/world/level/SpawnerCreature.patch b/paper-server/nms-patches/net/minecraft/world/level/SpawnerCreature.patch index 36cf6bf5ff..d2b2e265e2 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/SpawnerCreature.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/SpawnerCreature.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/SpawnerCreature.java +++ b/net/minecraft/world/level/SpawnerCreature.java -@@ -46,6 +46,13 @@ +@@ -50,6 +50,13 @@ import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; @@ -14,12 +14,19 @@ public final class SpawnerCreature { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -108,10 +115,25 @@ +@@ -107,15 +114,31 @@ + return (BiomeBase) ichunkaccess.getNoiseBiome(QuartPos.fromBlock(blockposition.getX()), QuartPos.fromBlock(blockposition.getY()), QuartPos.fromBlock(blockposition.getZ())).value(); + } + +- public static List getFilteredSpawningCategories(SpawnerCreature.d spawnercreature_d, boolean flag, boolean flag1, boolean flag2) { ++ // CraftBukkit start - add server ++ public static List getFilteredSpawningCategories(SpawnerCreature.d spawnercreature_d, boolean flag, boolean flag1, boolean flag2, WorldServer worldserver) { ++ WorldData worlddata = worldserver.getLevelData(); // CraftBukkit - Other mob type spawn tick rate ++ // CraftBukkit end + List list = new ArrayList(SpawnerCreature.SPAWNING_CATEGORIES.length); EnumCreatureType[] aenumcreaturetype = SpawnerCreature.SPAWNING_CATEGORIES; int i = aenumcreaturetype.length; -+ WorldData worlddata = worldserver.getLevelData(); // CraftBukkit - Other mob type spawn tick rate -+ for (int j = 0; j < i; ++j) { EnumCreatureType enumcreaturetype = aenumcreaturetype[j]; + // CraftBukkit start - Use per-world spawn limits @@ -31,20 +38,20 @@ + limit = worldserver.getWorld().getSpawnLimit(spawnCategory); + } -- if ((flag || !enumcreaturetype.isFriendly()) && (flag1 || enumcreaturetype.isFriendly()) && (flag2 || !enumcreaturetype.isPersistent()) && spawnercreature_d.canSpawnForCategory(enumcreaturetype, chunk.getPos())) { +- if ((flag || !enumcreaturetype.isFriendly()) && (flag1 || enumcreaturetype.isFriendly()) && (flag2 || !enumcreaturetype.isPersistent()) && spawnercreature_d.canSpawnForCategoryGlobal(enumcreaturetype)) { + if (!spawnThisTick || limit == 0) { + continue; + } + -+ if ((flag || !enumcreaturetype.isFriendly()) && (flag1 || enumcreaturetype.isFriendly()) && (flag2 || !enumcreaturetype.isPersistent()) && spawnercreature_d.canSpawnForCategory(enumcreaturetype, chunk.getPos(), limit)) { ++ if ((flag || !enumcreaturetype.isFriendly()) && (flag1 || enumcreaturetype.isFriendly()) && (flag2 || !enumcreaturetype.isPersistent()) && spawnercreature_d.canSpawnForCategoryGlobal(enumcreaturetype, limit)) { + // CraftBukkit end - Objects.requireNonNull(spawnercreature_d); - SpawnerCreature.c spawnercreature_c = spawnercreature_d::canSpawn; - -@@ -196,10 +218,15 @@ + list.add(enumcreaturetype); + } + } +@@ -217,10 +240,15 @@ entityinsentient.moveTo(d0, (double) i, d1, worldserver.random.nextFloat() * 360.0F, 0.0F); if (isValidPositionForMob(worldserver, entityinsentient, d2)) { - groupdataentity = entityinsentient.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entityinsentient.blockPosition()), EnumMobSpawn.NATURAL, groupdataentity); + groupdataentity = entityinsentient.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entityinsentient.blockPosition()), EntitySpawnReason.NATURAL, groupdataentity); - ++j; - ++k1; - worldserver.addFreshEntityWithPassengers(entityinsentient); @@ -61,25 +68,25 @@ if (j >= entityinsentient.getMaxSpawnClusterSize()) { return; } -@@ -348,7 +375,7 @@ +@@ -369,7 +397,7 @@ - if (entityinsentient.checkSpawnRules(worldaccess, EnumMobSpawn.CHUNK_GENERATION) && entityinsentient.checkSpawnObstruction(worldaccess)) { - groupdataentity = entityinsentient.finalizeSpawn(worldaccess, worldaccess.getCurrentDifficultyAt(entityinsentient.blockPosition()), EnumMobSpawn.CHUNK_GENERATION, groupdataentity); + if (entityinsentient.checkSpawnRules(worldaccess, EntitySpawnReason.CHUNK_GENERATION) && entityinsentient.checkSpawnObstruction(worldaccess)) { + groupdataentity = entityinsentient.finalizeSpawn(worldaccess, worldaccess.getCurrentDifficultyAt(entityinsentient.blockPosition()), EntitySpawnReason.CHUNK_GENERATION, groupdataentity); - worldaccess.addFreshEntityWithPassengers(entityinsentient); + worldaccess.addFreshEntityWithPassengers(entityinsentient, SpawnReason.CHUNK_GEN); // CraftBukkit flag = true; } } -@@ -461,8 +488,10 @@ +@@ -482,8 +510,10 @@ return this.unmodifiableMobCategoryCounts; } -- boolean canSpawnForCategory(EnumCreatureType enumcreaturetype, ChunkCoordIntPair chunkcoordintpair) { +- boolean canSpawnForCategoryGlobal(EnumCreatureType enumcreaturetype) { - int i = enumcreaturetype.getMaxInstancesPerChunk() * this.spawnableChunkCount / SpawnerCreature.MAGIC_NUMBER; + // CraftBukkit start -+ boolean canSpawnForCategory(EnumCreatureType enumcreaturetype, ChunkCoordIntPair chunkcoordintpair, int limit) { ++ boolean canSpawnForCategoryGlobal(EnumCreatureType enumcreaturetype, int limit) { + int i = limit * this.spawnableChunkCount / SpawnerCreature.MAGIC_NUMBER; + // CraftBukkit end - return this.mobCategoryCounts.getInt(enumcreaturetype) >= i ? false : this.localMobCapCalculator.canSpawn(enumcreaturetype, chunkcoordintpair); + return this.mobCategoryCounts.getInt(enumcreaturetype) < i; } diff --git a/paper-server/nms-patches/net/minecraft/world/level/World.patch b/paper-server/nms-patches/net/minecraft/world/level/World.patch index 80116f14b3..1fdff914ea 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/World.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/World.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/World.java +++ b/net/minecraft/world/level/World.java -@@ -78,6 +78,28 @@ +@@ -80,6 +80,28 @@ import net.minecraft.world.phys.Vec3D; import net.minecraft.world.scores.Scoreboard; @@ -29,11 +29,11 @@ public abstract class World implements GeneratorAccess, AutoCloseable { public static final Codec> RESOURCE_KEY_CODEC = ResourceKey.codec(Registries.DIMENSION); -@@ -119,7 +141,42 @@ +@@ -120,7 +142,42 @@ private final DamageSources damageSources; private long subTickCount; -- protected World(WorldDataMutable worlddatamutable, ResourceKey resourcekey, IRegistryCustom iregistrycustom, Holder holder, Supplier supplier, boolean flag, boolean flag1, long i, int j) { +- protected World(WorldDataMutable worlddatamutable, ResourceKey resourcekey, IRegistryCustom iregistrycustom, Holder holder, boolean flag, boolean flag1, long i, int j) { + // CraftBukkit start Added the following + private final CraftWorld world; + public boolean pvpMode; @@ -58,7 +58,7 @@ + + public abstract ResourceKey getTypeKey(); + -+ protected World(WorldDataMutable worlddatamutable, ResourceKey resourcekey, IRegistryCustom iregistrycustom, Holder holder, Supplier supplier, boolean flag, boolean flag1, long i, int j, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env) { ++ protected World(WorldDataMutable worlddatamutable, ResourceKey resourcekey, IRegistryCustom iregistrycustom, Holder holder, boolean flag, boolean flag1, long i, int j, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env) { + this.generator = gen; + this.world = new CraftWorld((WorldServer) this, gen, biomeProvider, env); + @@ -70,9 +70,9 @@ + } + + // CraftBukkit end - this.profiler = supplier; this.levelData = worlddatamutable; this.dimensionTypeRegistration = holder; + final DimensionManager dimensionmanager = (DimensionManager) holder.value(); @@ -128,15 +185,15 @@ this.dimension = resourcekey; this.isClientSide = flag; @@ -255,7 +255,7 @@ public void onBlockStateChange(BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1) {} @Override -@@ -337,6 +515,14 @@ +@@ -339,6 +517,14 @@ @Override public IBlockData getBlockState(BlockPosition blockposition) { @@ -270,19 +270,7 @@ if (this.isOutsideBuildHeight(blockposition)) { return Blocks.VOID_AIR.defaultBlockState(); } else { -@@ -523,6 +709,11 @@ - case 4: - explosion_effect = Explosion.Effect.TRIGGER_BLOCK; - break; -+ // CraftBukkit start - handle custom explosion type -+ case 5: -+ explosion_effect = Explosion.Effect.DESTROY; -+ break; -+ // CraftBukkit end - default: - throw new MatchException((String) null, (Throwable) null); - } -@@ -544,6 +735,16 @@ +@@ -509,6 +695,16 @@ @Nullable @Override public TileEntity getBlockEntity(BlockPosition blockposition) { @@ -299,7 +287,7 @@ return this.isOutsideBuildHeight(blockposition) ? null : (!this.isClientSide && Thread.currentThread() != this.thread ? null : this.getChunkAt(blockposition).getBlockEntity(blockposition, Chunk.EnumTileEntityState.IMMEDIATE)); } -@@ -551,6 +752,12 @@ +@@ -516,6 +712,12 @@ BlockPosition blockposition = tileentity.getBlockPos(); if (!this.isOutsideBuildHeight(blockposition)) { @@ -312,7 +300,7 @@ this.getChunkAt(blockposition).addAndRegisterBlockEntity(tileentity); } } -@@ -680,7 +887,7 @@ +@@ -645,7 +847,7 @@ for (int k = 0; k < j; ++k) { EntityComplexPart entitycomplexpart = aentitycomplexpart[k]; @@ -321,7 +309,7 @@ if (t0 != null && predicate.test(t0)) { list.add(t0); -@@ -958,7 +1165,7 @@ +@@ -912,7 +1114,7 @@ public static enum a implements INamable { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/AbstractCandleBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/AbstractCandleBlock.patch index 4bcfac0994..a11c361b84 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/AbstractCandleBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/AbstractCandleBlock.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/AbstractCandleBlock.java +++ b/net/minecraft/world/level/block/AbstractCandleBlock.java -@@ -46,6 +46,11 @@ +@@ -47,6 +47,11 @@ @Override protected void onProjectileHit(World world, IBlockData iblockdata, MovingObjectPositionBlock movingobjectpositionblock, IProjectile iprojectile) { if (!world.isClientSide && iprojectile.isOnFire() && this.canBeLit(iblockdata)) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BigDripleafBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BigDripleafBlock.patch index 901605a23a..791bcfe2cb 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BigDripleafBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BigDripleafBlock.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BigDripleafBlock.java +++ b/net/minecraft/world/level/block/BigDripleafBlock.java -@@ -43,6 +43,11 @@ +@@ -45,6 +45,11 @@ import net.minecraft.world.phys.shapes.VoxelShapeCollision; import net.minecraft.world.phys.shapes.VoxelShapes; @@ -12,7 +12,7 @@ public class BigDripleafBlock extends BlockFacingHorizontal implements IBlockFragilePlantElement, IBlockWaterlogged { public static final MapCodec CODEC = simpleCodec(BigDripleafBlock::new); -@@ -117,7 +122,7 @@ +@@ -119,7 +124,7 @@ @Override protected void onProjectileHit(World world, IBlockData iblockdata, MovingObjectPositionBlock movingobjectpositionblock, IProjectile iprojectile) { @@ -21,7 +21,7 @@ } @Override -@@ -176,7 +181,20 @@ +@@ -178,7 +183,20 @@ protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { if (!world.isClientSide) { if (iblockdata.getValue(BigDripleafBlock.TILT) == Tilt.NONE && canEntityTilt(blockposition, entity) && !world.hasNeighborSignal(blockposition)) { @@ -43,7 +43,7 @@ } } -@@ -190,9 +208,9 @@ +@@ -192,9 +210,9 @@ Tilt tilt = (Tilt) iblockdata.getValue(BigDripleafBlock.TILT); if (tilt == Tilt.UNSTABLE) { @@ -55,7 +55,7 @@ } else if (tilt == Tilt.FULL) { resetTilt(iblockdata, worldserver, blockposition); } -@@ -218,8 +236,10 @@ +@@ -220,8 +238,10 @@ return entity.onGround() && entity.position().y > (double) ((float) blockposition.getY() + 0.6875F); } @@ -68,7 +68,7 @@ if (soundeffect != null) { playTiltSound(world, blockposition, soundeffect); } -@@ -233,14 +253,21 @@ +@@ -235,14 +255,21 @@ } private static void resetTilt(IBlockData iblockdata, World world, BlockPosition blockposition) { @@ -92,7 +92,7 @@ Tilt tilt1 = (Tilt) iblockdata.getValue(BigDripleafBlock.TILT); world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BigDripleafBlock.TILT, tilt), 2); -@@ -248,6 +275,7 @@ +@@ -250,6 +277,7 @@ world.gameEvent((Entity) null, (Holder) GameEvent.BLOCK_CHANGE, blockposition); } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/Block.patch b/paper-server/nms-patches/net/minecraft/world/level/block/Block.patch index 5bb1b6171e..fe2c722992 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/Block.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/Block.patch @@ -1,21 +1,21 @@ --- a/net/minecraft/world/level/block/Block.java +++ b/net/minecraft/world/level/block/Block.java @@ -340,7 +340,13 @@ - EntityItem entityitem = (EntityItem) supplier.get(); + EntityItem entityitem = (EntityItem) supplier.get(); - entityitem.setDefaultPickUpDelay(); -- world.addFreshEntity(entityitem); -+ // CraftBukkit start -+ if (world.captureDrops != null) { -+ world.captureDrops.add(entityitem); -+ } else { -+ world.addFreshEntity(entityitem); -+ } -+ // CraftBukkit end + entityitem.setDefaultPickUpDelay(); +- world.addFreshEntity(entityitem); ++ // CraftBukkit start ++ if (world.captureDrops != null) { ++ world.captureDrops.add(entityitem); ++ } else { ++ world.addFreshEntity(entityitem); ++ } ++ // CraftBukkit end + return; + } } - } - -@@ -366,7 +372,7 @@ +@@ -369,7 +375,7 @@ public void playerDestroy(World world, EntityHuman entityhuman, BlockPosition blockposition, IBlockData iblockdata, @Nullable TileEntity tileentity, ItemStack itemstack) { entityhuman.awardStat(StatisticList.BLOCK_MINED.get(this)); @@ -24,7 +24,7 @@ dropResources(iblockdata, world, blockposition, tileentity, entityhuman, itemstack); } -@@ -499,15 +505,23 @@ +@@ -494,15 +500,23 @@ return this.builtInRegistryHolder; } @@ -47,6 +47,6 @@ + } + // CraftBukkit end + - public static final class a { + private static record a(VoxelShape first, VoxelShape second) { - private final IBlockData first; + public boolean equals(Object object) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockBamboo.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockBamboo.patch index 4d6cca39ca..b18e8d3716 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockBamboo.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockBamboo.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockBamboo.java +++ b/net/minecraft/world/level/block/BlockBamboo.java -@@ -187,7 +187,7 @@ +@@ -183,7 +183,7 @@ BlockPosition blockposition1 = blockposition.above(i); IBlockData iblockdata1 = worldserver.getBlockState(blockposition1); @@ -9,7 +9,7 @@ return; } -@@ -208,14 +208,18 @@ +@@ -204,14 +204,18 @@ BlockPosition blockposition1 = blockposition.below(2); IBlockData iblockdata2 = world.getBlockState(blockposition1); BlockPropertyBambooSize blockpropertybamboosize = BlockPropertyBambooSize.NONE; @@ -30,7 +30,7 @@ } } } else { -@@ -226,7 +230,14 @@ +@@ -222,7 +226,14 @@ int j = (Integer) iblockdata.getValue(BlockBamboo.AGE) != 1 && !iblockdata2.is(Blocks.BAMBOO) ? 0 : 1; int k = (i < 11 || randomsource.nextFloat() >= 0.25F) && i != 15 ? 0 : 1; diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockBambooSapling.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockBambooSapling.patch index e734aac68c..9bfc7a5cb3 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockBambooSapling.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockBambooSapling.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockBambooSapling.java +++ b/net/minecraft/world/level/block/BlockBambooSapling.java -@@ -95,6 +95,6 @@ +@@ -87,6 +87,6 @@ } protected void growBamboo(World world, BlockPosition blockposition) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockBed.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockBed.patch index 9f9c5700f1..87549359ab 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockBed.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockBed.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockBed.java +++ b/net/minecraft/world/level/block/BlockBed.java -@@ -93,7 +93,8 @@ +@@ -95,7 +95,8 @@ } } @@ -10,9 +10,9 @@ world.removeBlock(blockposition, false); BlockPosition blockposition1 = blockposition.relative(((EnumDirection) iblockdata.getValue(BlockBed.FACING)).getOpposite()); -@@ -112,7 +113,16 @@ +@@ -114,7 +115,16 @@ - return EnumInteractionResult.SUCCESS; + return EnumInteractionResult.SUCCESS_SERVER; } else { + // CraftBukkit start + IBlockData finaliblockdata = iblockdata; @@ -27,7 +27,7 @@ if (entityhuman_enumbedresult.getMessage() != null) { entityhuman.displayClientMessage(entityhuman_enumbedresult.getMessage(), true); } -@@ -123,8 +133,30 @@ +@@ -125,8 +135,30 @@ } } @@ -59,7 +59,7 @@ } private boolean kickVillagerOutOfBed(World world, BlockPosition blockposition) { -@@ -323,6 +355,11 @@ +@@ -325,6 +357,11 @@ BlockPosition blockposition1 = blockposition.relative((EnumDirection) iblockdata.getValue(BlockBed.FACING)); world.setBlock(blockposition1, (IBlockData) iblockdata.setValue(BlockBed.PART, BlockPropertyBedPart.HEAD), 3); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockBeehive.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockBeehive.patch index fb02245270..7ad5aa9850 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockBeehive.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockBeehive.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockBeehive.java +++ b/net/minecraft/world/level/block/BlockBeehive.java -@@ -119,7 +119,7 @@ +@@ -133,7 +133,7 @@ if (entitybee.getTarget() == null) { EntityHuman entityhuman = (EntityHuman) SystemUtils.getRandom(list1, world.random); @@ -9,12 +9,12 @@ } } } -@@ -287,7 +287,7 @@ - ItemStack itemstack = new ItemStack(this); +@@ -302,7 +302,7 @@ + ItemStack itemstack = new ItemStack(this); - itemstack.applyComponents(tileentitybeehive.collectComponents()); -- itemstack.set(DataComponents.BLOCK_STATE, BlockItemStateProperties.EMPTY.with(BlockBeehive.HONEY_LEVEL, (Comparable) i)); -+ itemstack.set(DataComponents.BLOCK_STATE, BlockItemStateProperties.EMPTY.with(BlockBeehive.HONEY_LEVEL, i)); // CraftBukkit - decompile error - EntityItem entityitem = new EntityItem(world, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), itemstack); + itemstack.applyComponents(tileentitybeehive.collectComponents()); +- itemstack.set(DataComponents.BLOCK_STATE, BlockItemStateProperties.EMPTY.with(BlockBeehive.HONEY_LEVEL, (Comparable) i)); ++ itemstack.set(DataComponents.BLOCK_STATE, BlockItemStateProperties.EMPTY.with(BlockBeehive.HONEY_LEVEL, i)); // CraftBukkit - decompile error + EntityItem entityitem = new EntityItem(world, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), itemstack); - entityitem.setDefaultPickUpDelay(); + entityitem.setDefaultPickUpDelay(); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockBell.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockBell.patch index 76a048508f..cdf7e1e8b9 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockBell.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockBell.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockBell.java +++ b/net/minecraft/world/level/block/BlockBell.java -@@ -146,6 +146,11 @@ +@@ -148,6 +148,11 @@ if (enumdirection == null) { enumdirection = (EnumDirection) world.getBlockState(blockposition).getValue(BlockBell.FACING); } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockButtonAbstract.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockButtonAbstract.patch index ebc661f7c3..5000b862d0 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockButtonAbstract.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockButtonAbstract.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockButtonAbstract.java +++ b/net/minecraft/world/level/block/BlockButtonAbstract.java -@@ -33,6 +33,11 @@ +@@ -35,6 +35,11 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -12,7 +12,7 @@ public class BlockButtonAbstract extends BlockAttachable { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { -@@ -124,6 +129,19 @@ +@@ -126,6 +131,19 @@ if ((Boolean) iblockdata.getValue(BlockButtonAbstract.POWERED)) { return EnumInteractionResult.CONSUME; } else { @@ -30,9 +30,9 @@ + } + // CraftBukkit end this.press(iblockdata, world, blockposition, entityhuman); - return EnumInteractionResult.sidedSuccess(world.isClientSide); + return EnumInteractionResult.SUCCESS; } -@@ -195,11 +213,36 @@ +@@ -197,11 +215,36 @@ } protected void checkPressed(IBlockData iblockdata, World world, BlockPosition blockposition) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCactus.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCactus.patch index 586d292377..b7357ae0e2 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCactus.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCactus.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockCactus.java +++ b/net/minecraft/world/level/block/BlockCactus.java -@@ -22,6 +22,8 @@ +@@ -23,6 +23,8 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -9,7 +9,7 @@ public class BlockCactus extends Block { public static final MapCodec CODEC = simpleCodec(BlockCactus::new); -@@ -64,7 +66,7 @@ +@@ -65,7 +67,7 @@ int j = (Integer) iblockdata.getValue(BlockCactus.AGE); if (j == 15) { @@ -18,7 +18,7 @@ IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockCactus.AGE, 0); worldserver.setBlock(blockposition, iblockdata1, 4); -@@ -119,7 +121,7 @@ +@@ -120,7 +122,7 @@ @Override protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCake.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCake.patch index f7dbcd4f6b..85c0511550 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCake.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCake.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockCake.java +++ b/net/minecraft/world/level/block/BlockCake.java -@@ -97,7 +97,18 @@ +@@ -98,7 +98,18 @@ return EnumInteractionResult.PASS; } else { entityhuman.awardStat(StatisticList.EAT_CAKE_SLICE); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCampfire.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCampfire.patch index 434f54515b..dcc6445b40 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCampfire.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCampfire.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockCampfire.java +++ b/net/minecraft/world/level/block/BlockCampfire.java -@@ -105,7 +105,7 @@ +@@ -113,7 +113,7 @@ @Override protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { if ((Boolean) iblockdata.getValue(BlockCampfire.LIT) && entity instanceof EntityLiving) { @@ -9,15 +9,15 @@ } super.entityInside(iblockdata, world, blockposition, entity); -@@ -215,6 +215,11 @@ - BlockPosition blockposition = movingobjectpositionblock.getBlockPos(); +@@ -224,6 +224,11 @@ - if (!world.isClientSide && iprojectile.isOnFire() && iprojectile.mayInteract(world, blockposition) && !(Boolean) iblockdata.getValue(BlockCampfire.LIT) && !(Boolean) iblockdata.getValue(BlockCampfire.WATERLOGGED)) { -+ // CraftBukkit start -+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition, iprojectile).isCancelled()) { -+ return; -+ } -+ // CraftBukkit end - world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockProperties.LIT, true), 11); + if (world instanceof WorldServer worldserver) { + if (iprojectile.isOnFire() && iprojectile.mayInteract(worldserver, blockposition) && !(Boolean) iblockdata.getValue(BlockCampfire.LIT) && !(Boolean) iblockdata.getValue(BlockCampfire.WATERLOGGED)) { ++ // CraftBukkit start ++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition, iprojectile).isCancelled()) { ++ return; ++ } ++ // CraftBukkit end + world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockProperties.LIT, true), 11); + } } - diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockChest.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockChest.patch index f3931bf517..4f8016bc7f 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockChest.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockChest.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockChest.java +++ b/net/minecraft/world/level/block/BlockChest.java -@@ -90,24 +90,7 @@ +@@ -91,24 +91,7 @@ public Optional acceptDouble(final TileEntityChest tileentitychest, final TileEntityChest tileentitychest1) { final InventoryLargeChest inventorylargechest = new InventoryLargeChest(tileentitychest, tileentitychest1); @@ -26,7 +26,7 @@ } public Optional acceptSingle(TileEntityChest tileentitychest) { -@@ -120,6 +103,38 @@ +@@ -121,6 +104,38 @@ } }; @@ -65,7 +65,7 @@ @Override public MapCodec codec() { return BlockChest.CODEC; -@@ -263,7 +278,7 @@ +@@ -262,7 +277,7 @@ @Override public DoubleBlockFinder.Result combine(IBlockData iblockdata, World world, BlockPosition blockposition, boolean flag) { @@ -74,7 +74,7 @@ if (flag) { bipredicate = (generatoraccess, blockposition1) -> { -@@ -279,7 +294,14 @@ +@@ -278,7 +293,14 @@ @Nullable @Override protected ITileInventory getMenuProvider(IBlockData iblockdata, World world, BlockPosition blockposition) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockChorusFlower.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockChorusFlower.patch index 69451ae16f..04cac1d358 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockChorusFlower.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockChorusFlower.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockChorusFlower.java +++ b/net/minecraft/world/level/block/BlockChorusFlower.java -@@ -22,6 +22,8 @@ +@@ -23,6 +23,8 @@ import net.minecraft.world.phys.MovingObjectPositionBlock; import net.minecraft.world.phys.shapes.VoxelShape; @@ -9,7 +9,7 @@ public class BlockChorusFlower extends Block { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { -@@ -102,8 +104,12 @@ +@@ -103,8 +105,12 @@ } if (flag && allNeighborsEmpty(worldserver, blockposition1, (EnumDirection) null) && worldserver.isEmptyBlock(blockposition.above(2))) { @@ -24,7 +24,7 @@ } else if (i < 4) { j = randomsource.nextInt(4); if (flag1) { -@@ -117,18 +123,30 @@ +@@ -118,18 +124,30 @@ BlockPosition blockposition2 = blockposition.relative(enumdirection); if (worldserver.isEmptyBlock(blockposition2) && worldserver.isEmptyBlock(blockposition2.below()) && allNeighborsEmpty(worldserver, blockposition2, enumdirection.getOpposite())) { @@ -59,15 +59,15 @@ } } -@@ -265,6 +283,11 @@ - BlockPosition blockposition = movingobjectpositionblock.getBlockPos(); +@@ -267,6 +285,11 @@ - if (!world.isClientSide && iprojectile.mayInteract(world, blockposition) && iprojectile.mayBreak(world)) { -+ // CraftBukkit -+ if (!CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, Blocks.AIR.defaultBlockState())) { -+ return; -+ } -+ // CraftBukkit end - world.destroyBlock(blockposition, true, iprojectile); + if (world instanceof WorldServer worldserver) { + if (iprojectile.mayInteract(worldserver, blockposition) && iprojectile.mayBreak(worldserver)) { ++ // CraftBukkit ++ if (!CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, Blocks.AIR.defaultBlockState())) { ++ return; ++ } ++ // CraftBukkit end + world.destroyBlock(blockposition, true, iprojectile); + } } - diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCommand.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCommand.patch index f931c492f0..3984b69d9a 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCommand.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCommand.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockCommand.java +++ b/net/minecraft/world/level/block/BlockCommand.java -@@ -29,6 +29,8 @@ +@@ -31,6 +31,8 @@ import net.minecraft.world.phys.MovingObjectPositionBlock; import org.slf4j.Logger; @@ -9,19 +9,19 @@ public class BlockCommand extends BlockTileEntity implements GameMasterBlock { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { -@@ -69,6 +71,15 @@ - TileEntityCommand tileentitycommand = (TileEntityCommand) tileentity; - boolean flag1 = world.hasNeighborSignal(blockposition); - boolean flag2 = tileentitycommand.isPowered(); -+ // CraftBukkit start -+ org.bukkit.block.Block bukkitBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); -+ int old = flag2 ? 15 : 0; -+ int current = flag1 ? 15 : 0; -+ -+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bukkitBlock, old, current); -+ world.getCraftServer().getPluginManager().callEvent(eventRedstone); -+ flag1 = eventRedstone.getNewCurrent() > 0; -+ // CraftBukkit end +@@ -78,6 +80,15 @@ - tileentitycommand.setPowered(flag1); - if (!flag2 && !tileentitycommand.isAutomatic() && tileentitycommand.getMode() != TileEntityCommand.Type.SEQUENCE) { + private void setPoweredAndUpdate(World world, BlockPosition blockposition, TileEntityCommand tileentitycommand, boolean flag) { + boolean flag1 = tileentitycommand.isPowered(); ++ // CraftBukkit start ++ org.bukkit.block.Block bukkitBlock = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); ++ int old = flag1 ? 15 : 0; ++ int current = flag ? 15 : 0; ++ ++ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(bukkitBlock, old, current); ++ world.getCraftServer().getPluginManager().callEvent(eventRedstone); ++ flag = eventRedstone.getNewCurrent() > 0; ++ // CraftBukkit end + + if (flag != flag1) { + tileentitycommand.setPowered(flag); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockComposter.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockComposter.patch index a53c644294..e858180ce0 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockComposter.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockComposter.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockComposter.java +++ b/net/minecraft/world/level/block/BlockComposter.java -@@ -43,6 +43,11 @@ +@@ -42,6 +42,11 @@ import net.minecraft.world.phys.shapes.VoxelShapeCollision; import net.minecraft.world.phys.shapes.VoxelShapes; @@ -12,7 +12,7 @@ public class BlockComposter extends Block implements IInventoryHolder { public static final MapCodec CODEC = simpleCodec(BlockComposter::new); -@@ -263,7 +268,14 @@ +@@ -267,7 +272,14 @@ int i = (Integer) iblockdata.getValue(BlockComposter.LEVEL); if (i < 7 && BlockComposter.COMPOSTABLES.containsKey(itemstack.getItem())) { @@ -28,7 +28,7 @@ itemstack.shrink(1); return iblockdata1; -@@ -273,6 +285,14 @@ +@@ -277,6 +289,14 @@ } public static IBlockData extractProduce(Entity entity, IBlockData iblockdata, World world, BlockPosition blockposition) { @@ -43,7 +43,7 @@ if (!world.isClientSide) { Vec3D vec3d = Vec3D.atLowerCornerWithOffset(blockposition, 0.5D, 1.01D, 0.5D).offsetRandom(world.random, 0.7F); EntityItem entityitem = new EntityItem(world, vec3d.x(), vec3d.y(), vec3d.z(), new ItemStack(Items.BONE_MEAL)); -@@ -296,10 +316,16 @@ +@@ -300,10 +320,16 @@ } static IBlockData addItem(@Nullable Entity entity, IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition, ItemStack itemstack) { @@ -61,7 +61,7 @@ return iblockdata; } else { int j = i + 1; -@@ -348,7 +374,8 @@ +@@ -352,7 +378,8 @@ public IWorldInventory getContainer(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) { int i = (Integer) iblockdata.getValue(BlockComposter.LEVEL); @@ -71,7 +71,7 @@ } public static class ContainerOutput extends InventorySubcontainer implements IWorldInventory { -@@ -363,6 +390,7 @@ +@@ -367,6 +394,7 @@ this.state = iblockdata; this.level = generatoraccess; this.pos = blockposition; @@ -79,7 +79,7 @@ } @Override -@@ -387,8 +415,15 @@ +@@ -391,8 +419,15 @@ @Override public void setChanged() { @@ -95,7 +95,7 @@ } } -@@ -401,6 +436,7 @@ +@@ -405,6 +440,7 @@ public ContainerInput(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) { super(1); @@ -103,7 +103,7 @@ this.state = iblockdata; this.level = generatoraccess; this.pos = blockposition; -@@ -443,8 +479,9 @@ +@@ -447,8 +483,9 @@ public static class ContainerEmpty extends InventorySubcontainer implements IWorldInventory { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockConcretePowder.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockConcretePowder.patch index ba1b0d0ed3..f828b830d0 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockConcretePowder.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockConcretePowder.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockConcretePowder.java +++ b/net/minecraft/world/level/block/BlockConcretePowder.java -@@ -14,6 +14,12 @@ +@@ -16,6 +16,12 @@ import net.minecraft.world.level.block.state.BlockBase; import net.minecraft.world.level.block.state.IBlockData; @@ -13,7 +13,7 @@ public class BlockConcretePowder extends BlockFalling { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { -@@ -36,7 +42,7 @@ +@@ -38,7 +44,7 @@ @Override public void onLand(World world, BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1, EntityFallingBlock entityfallingblock) { if (shouldSolidify(world, blockposition, iblockdata1)) { @@ -22,7 +22,7 @@ } } -@@ -47,7 +53,24 @@ +@@ -49,7 +55,24 @@ BlockPosition blockposition = blockactioncontext.getClickedPos(); IBlockData iblockdata = world.getBlockState(blockposition); @@ -48,29 +48,29 @@ } private static boolean shouldSolidify(IBlockAccess iblockaccess, BlockPosition blockposition, IBlockData iblockdata) { -@@ -83,7 +106,25 @@ +@@ -85,7 +108,25 @@ @Override - protected IBlockData updateShape(IBlockData iblockdata, EnumDirection enumdirection, IBlockData iblockdata1, GeneratorAccess generatoraccess, BlockPosition blockposition, BlockPosition blockposition1) { -- return touchesLiquid(generatoraccess, blockposition) ? this.concrete.defaultBlockState() : super.updateShape(iblockdata, enumdirection, iblockdata1, generatoraccess, blockposition, blockposition1); + protected IBlockData updateShape(IBlockData iblockdata, IWorldReader iworldreader, ScheduledTickAccess scheduledtickaccess, BlockPosition blockposition, EnumDirection enumdirection, BlockPosition blockposition1, IBlockData iblockdata1, RandomSource randomsource) { +- return touchesLiquid(iworldreader, blockposition) ? this.concrete.defaultBlockState() : super.updateShape(iblockdata, iworldreader, scheduledtickaccess, blockposition, enumdirection, blockposition1, iblockdata1, randomsource); + // CraftBukkit start -+ if (touchesLiquid(generatoraccess, blockposition)) { ++ if (touchesLiquid(iworldreader, blockposition)) { + // Suppress during worldgen -+ if (!(generatoraccess instanceof World)) { ++ if (!(iworldreader instanceof World world)) { + return this.concrete.defaultBlockState(); + } -+ CraftBlockState blockState = CraftBlockStates.getBlockState(generatoraccess, blockposition); ++ CraftBlockState blockState = CraftBlockStates.getBlockState(world, blockposition); + blockState.setData(this.concrete.defaultBlockState()); + + BlockFormEvent event = new BlockFormEvent(blockState.getBlock(), blockState); -+ ((World) generatoraccess).getCraftServer().getPluginManager().callEvent(event); ++ world.getCraftServer().getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + return blockState.getHandle(); + } + } + -+ return super.updateShape(iblockdata, enumdirection, iblockdata1, generatoraccess, blockposition, blockposition1); ++ return super.updateShape(iblockdata, iworldreader, scheduledtickaccess, blockposition, enumdirection, blockposition1, iblockdata1, randomsource); + // CraftBukkit end } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoral.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoral.patch index c42075fac2..17128dac88 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoral.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoral.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockCoral.java +++ b/net/minecraft/world/level/block/BlockCoral.java -@@ -39,6 +39,11 @@ +@@ -40,6 +40,11 @@ @Override protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if (!this.scanForWater(worldserver, blockposition)) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoralFan.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoralFan.patch index 7651d1e6fb..d885679e85 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoralFan.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoralFan.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockCoralFan.java +++ b/net/minecraft/world/level/block/BlockCoralFan.java -@@ -40,6 +40,11 @@ +@@ -41,6 +41,11 @@ @Override protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if (!scanForWater(iblockdata, worldserver, blockposition)) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoralFanWall.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoralFanWall.patch index bff8af0a1c..304e1b5381 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoralFanWall.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoralFanWall.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockCoralFanWall.java +++ b/net/minecraft/world/level/block/BlockCoralFanWall.java -@@ -40,6 +40,11 @@ +@@ -41,6 +41,11 @@ @Override protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if (!scanForWater(iblockdata, worldserver, blockposition)) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoralPlant.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoralPlant.patch index 3eedfdef8c..44e06a2491 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoralPlant.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCoralPlant.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockCoralPlant.java +++ b/net/minecraft/world/level/block/BlockCoralPlant.java -@@ -45,6 +45,11 @@ +@@ -46,6 +46,11 @@ @Override protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if (!scanForWater(iblockdata, worldserver, blockposition)) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCrops.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCrops.patch index 92dfca5bb1..bf16556b8e 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCrops.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCrops.patch @@ -27,12 +27,12 @@ } protected int getBonemealAgeIncrease(World world) { -@@ -160,7 +162,7 @@ - +@@ -161,7 +163,7 @@ @Override protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { -- if (entity instanceof EntityRavager && world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { -+ if (entity instanceof EntityRavager && CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR.defaultBlockState(), !world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))) { // CraftBukkit - world.destroyBlock(blockposition, true, entity); + if (world instanceof WorldServer worldserver) { +- if (entity instanceof EntityRavager && worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { ++ if (entity instanceof EntityRavager && CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR.defaultBlockState(), !worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))) { // CraftBukkit + worldserver.destroyBlock(blockposition, true, entity); + } } - diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockDiodeAbstract.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockDiodeAbstract.patch index 6f3a7b9965..1b54785c3c 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockDiodeAbstract.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockDiodeAbstract.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockDiodeAbstract.java +++ b/net/minecraft/world/level/block/BlockDiodeAbstract.java -@@ -21,6 +21,8 @@ +@@ -24,6 +24,8 @@ import net.minecraft.world.phys.shapes.VoxelShapeCollision; import net.minecraft.world.ticks.TickListPriority; @@ -9,7 +9,7 @@ public abstract class BlockDiodeAbstract extends BlockFacingHorizontal { protected static final VoxelShape SHAPE = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 2.0D, 16.0D); -@@ -56,8 +58,18 @@ +@@ -59,8 +61,18 @@ boolean flag1 = this.shouldTurnOn(worldserver, blockposition, iblockdata); if (flag && !flag1) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockDispenser.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockDispenser.patch index 6d78a69b3a..8b0139e08a 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockDispenser.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockDispenser.patch @@ -1,14 +1,14 @@ --- a/net/minecraft/world/level/block/BlockDispenser.java +++ b/net/minecraft/world/level/block/BlockDispenser.java -@@ -51,6 +51,7 @@ - object2objectopenhashmap.defaultReturnValue(BlockDispenser.DEFAULT_BEHAVIOR); - }); +@@ -52,6 +52,7 @@ + private static final DispenseBehaviorItem DEFAULT_BEHAVIOR = new DispenseBehaviorItem(); + public static final Map DISPENSER_REGISTRY = new IdentityHashMap(); private static final int TRIGGER_DURATION = 4; + public static boolean eventFired = false; // CraftBukkit @Override public MapCodec codec() { -@@ -91,7 +92,7 @@ +@@ -88,7 +89,7 @@ } public void dispenseFrom(WorldServer worldserver, IBlockData iblockdata, BlockPosition blockposition) { @@ -17,7 +17,7 @@ if (tileentitydispenser == null) { BlockDispenser.LOGGER.warn("Ignoring dispensing attempt for Dispenser without matching block entity at {}", blockposition); -@@ -107,6 +108,7 @@ +@@ -104,6 +105,7 @@ IDispenseBehavior idispensebehavior = this.getDispenseMethod(worldserver, itemstack); if (idispensebehavior != IDispenseBehavior.NOOP) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockDoor.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockDoor.patch index a6c3d841a4..d62163d035 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockDoor.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockDoor.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockDoor.java +++ b/net/minecraft/world/level/block/BlockDoor.java -@@ -37,6 +37,8 @@ +@@ -39,6 +39,8 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -9,10 +9,10 @@ public class BlockDoor extends Block { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { -@@ -220,9 +222,24 @@ +@@ -222,9 +224,24 @@ @Override - protected void neighborChanged(IBlockData iblockdata, World world, BlockPosition blockposition, Block block, BlockPosition blockposition1, boolean flag) { + protected void neighborChanged(IBlockData iblockdata, World world, BlockPosition blockposition, Block block, @Nullable Orientation orientation, boolean flag) { - boolean flag1 = world.hasNeighborSignal(blockposition) || world.hasNeighborSignal(blockposition.relative(iblockdata.getValue(BlockDoor.HALF) == BlockPropertyDoubleBlockHalf.LOWER ? EnumDirection.UP : EnumDirection.DOWN)); + // CraftBukkit start + BlockPosition otherHalf = blockposition.relative(iblockdata.getValue(BlockDoor.HALF) == BlockPropertyDoubleBlockHalf.LOWER ? EnumDirection.UP : EnumDirection.DOWN); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockEndGateway.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockEndGateway.patch index 97412076c1..d4318f235d 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockEndGateway.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockEndGateway.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/level/block/BlockEndGateway.java +++ b/net/minecraft/world/level/block/BlockEndGateway.java -@@ -21,6 +21,10 @@ - import net.minecraft.world.level.portal.DimensionTransition; +@@ -23,6 +23,10 @@ + import net.minecraft.world.level.portal.TeleportTransition; import net.minecraft.world.phys.Vec3D; +// CraftBukkit start @@ -11,12 +11,12 @@ public class BlockEndGateway extends BlockTileEntity implements Portal { public static final MapCodec CODEC = simpleCodec(BlockEndGateway::new); -@@ -110,7 +114,7 @@ +@@ -112,7 +116,7 @@ if (tileentity instanceof TileEntityEndGateway tileentityendgateway) { Vec3D vec3d = tileentityendgateway.getPortalPosition(worldserver, blockposition); -- return vec3d != null ? new DimensionTransition(worldserver, vec3d, calculateExitMovement(entity), entity.getYRot(), entity.getXRot(), DimensionTransition.PLACE_PORTAL_TICKET) : null; -+ return vec3d != null ? new DimensionTransition(worldserver, vec3d, calculateExitMovement(entity), entity.getYRot(), entity.getXRot(), DimensionTransition.PLACE_PORTAL_TICKET, PlayerTeleportEvent.TeleportCause.END_GATEWAY) : null; // CraftBukkit +- return vec3d == null ? null : (entity instanceof EntityEnderPearl ? new TeleportTransition(worldserver, vec3d, Vec3D.ZERO, 0.0F, 0.0F, Set.of(), TeleportTransition.PLACE_PORTAL_TICKET) : new TeleportTransition(worldserver, vec3d, Vec3D.ZERO, 0.0F, 0.0F, Relative.union(Relative.DELTA, Relative.ROTATION), TeleportTransition.PLACE_PORTAL_TICKET)); ++ return vec3d == null ? null : (entity instanceof EntityEnderPearl ? new TeleportTransition(worldserver, vec3d, Vec3D.ZERO, 0.0F, 0.0F, Set.of(), TeleportTransition.PLACE_PORTAL_TICKET, PlayerTeleportEvent.TeleportCause.END_GATEWAY) : new TeleportTransition(worldserver, vec3d, Vec3D.ZERO, 0.0F, 0.0F, Relative.union(Relative.DELTA, Relative.ROTATION), TeleportTransition.PLACE_PORTAL_TICKET, PlayerTeleportEvent.TeleportCause.END_GATEWAY)); // CraftBukkit } else { return null; } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockEnderPortal.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockEnderPortal.patch index efe0c0080f..85f651ffb3 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockEnderPortal.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockEnderPortal.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/level/block/BlockEnderPortal.java +++ b/net/minecraft/world/level/block/BlockEnderPortal.java @@ -26,6 +26,19 @@ + import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; - import net.minecraft.world.phys.shapes.VoxelShapes; +// CraftBukkit start +import java.util.List; @@ -20,10 +20,10 @@ public class BlockEnderPortal extends BlockTileEntity implements Portal { public static final MapCodec CODEC = simpleCodec(BlockEnderPortal::new); -@@ -53,6 +66,10 @@ +@@ -58,6 +71,10 @@ @Override protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { - if (entity.canUsePortal(false) && VoxelShapes.joinIsNotEmpty(VoxelShapes.create(entity.getBoundingBox().move((double) (-blockposition.getX()), (double) (-blockposition.getY()), (double) (-blockposition.getZ()))), iblockdata.getShape(world, blockposition), OperatorBoolean.AND)) { + if (entity.canUsePortal(false)) { + // CraftBukkit start - Entity in portal + EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ())); + world.getCraftServer().getPluginManager().callEvent(event); @@ -31,41 +31,41 @@ if (!world.isClientSide && world.dimension() == World.END && entity instanceof EntityPlayer) { EntityPlayer entityplayer = (EntityPlayer) entity; -@@ -69,11 +86,11 @@ +@@ -74,11 +91,11 @@ @Override - public DimensionTransition getPortalDestination(WorldServer worldserver, Entity entity, BlockPosition blockposition) { + public TeleportTransition getPortalDestination(WorldServer worldserver, Entity entity, BlockPosition blockposition) { - ResourceKey resourcekey = worldserver.dimension() == World.END ? World.OVERWORLD : World.END; + ResourceKey resourcekey = worldserver.getTypeKey() == WorldDimension.END ? World.OVERWORLD : World.END; // CraftBukkit - SPIGOT-6152: send back to main overworld in custom ends WorldServer worldserver1 = worldserver.getServer().getLevel(resourcekey); if (worldserver1 == null) { - return null; -+ return new DimensionTransition(PlayerTeleportEvent.TeleportCause.END_PORTAL); // CraftBukkit- always fire event in case plugins wish to change it ++ return new TeleportTransition(PlayerTeleportEvent.TeleportCause.END_PORTAL); // CraftBukkit- always fire event in case plugins wish to change it } else { boolean flag = resourcekey == World.END; BlockPosition blockposition1 = flag ? WorldServer.END_SPAWN_POINT : worldserver1.getSharedSpawnPos(); -@@ -81,7 +98,7 @@ - float f = entity.getYRot(); +@@ -87,7 +104,7 @@ + Set set; if (flag) { - EndPlatformFeature.createEndPlatform(worldserver1, BlockPosition.containing(vec3d).below(), true); + EndPlatformFeature.createEndPlatform(worldserver1, BlockPosition.containing(vec3d).below(), true, entity); // CraftBukkit f = EnumDirection.WEST.toYRot(); + set = Relative.union(Relative.DELTA, Set.of(Relative.X_ROT)); if (entity instanceof EntityPlayer) { - vec3d = vec3d.subtract(0.0D, 1.0D, 0.0D); -@@ -90,13 +107,21 @@ +@@ -99,13 +116,21 @@ if (entity instanceof EntityPlayer) { EntityPlayer entityplayer = (EntityPlayer) entity; -- return entityplayer.findRespawnPositionAndUseSpawnBlock(false, DimensionTransition.DO_NOTHING); -+ return entityplayer.findRespawnPositionAndUseSpawnBlock(false, DimensionTransition.DO_NOTHING, PlayerRespawnEvent.RespawnReason.END_PORTAL); // CraftBukkit +- return entityplayer.findRespawnPositionAndUseSpawnBlock(false, TeleportTransition.DO_NOTHING); ++ return entityplayer.findRespawnPositionAndUseSpawnBlock(false, TeleportTransition.DO_NOTHING, PlayerRespawnEvent.RespawnReason.END_PORTAL); // CraftBukkit } vec3d = entity.adjustSpawnLocation(worldserver1, blockposition1).getBottomCenter(); } -- return new DimensionTransition(worldserver1, vec3d, entity.getDeltaMovement(), f, entity.getXRot(), DimensionTransition.PLAY_PORTAL_SOUND.then(DimensionTransition.PLACE_PORTAL_TICKET)); +- return new TeleportTransition(worldserver1, vec3d, Vec3D.ZERO, f, 0.0F, set, TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET)); + // CraftBukkit start + CraftPortalEvent event = entity.callPortalEvent(entity, CraftLocation.toBukkit(vec3d, worldserver1.getWorld(), f, entity.getXRot()), PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0); + if (event == null) { @@ -73,7 +73,7 @@ + } + Location to = event.getTo(); + -+ return new DimensionTransition(((CraftWorld) to.getWorld()).getHandle(), CraftLocation.toVec3D(to), entity.getDeltaMovement(), to.getYaw(), to.getPitch(), DimensionTransition.PLAY_PORTAL_SOUND.then(DimensionTransition.PLACE_PORTAL_TICKET), PlayerTeleportEvent.TeleportCause.END_PORTAL); ++ return new TeleportTransition(((CraftWorld) to.getWorld()).getHandle(), CraftLocation.toVec3D(to), entity.getDeltaMovement(), to.getYaw(), to.getPitch(), set, TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET), PlayerTeleportEvent.TeleportCause.END_PORTAL); + // CraftBukkit end } } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockFenceGate.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockFenceGate.patch index 9cedb87742..9665e2b120 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockFenceGate.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockFenceGate.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/level/block/BlockFenceGate.java +++ b/net/minecraft/world/level/block/BlockFenceGate.java -@@ -168,6 +168,17 @@ - protected void neighborChanged(IBlockData iblockdata, World world, BlockPosition blockposition, Block block, BlockPosition blockposition1, boolean flag) { +@@ -173,6 +173,17 @@ + protected void neighborChanged(IBlockData iblockdata, World world, BlockPosition blockposition, Block block, @Nullable Orientation orientation, boolean flag) { if (!world.isClientSide) { boolean flag1 = world.hasNeighborSignal(blockposition); + // CraftBukkit start diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockFire.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockFire.patch index a783ad8ddb..beab20b976 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockFire.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockFire.patch @@ -19,25 +19,25 @@ @@ -100,7 +109,24 @@ @Override - protected IBlockData updateShape(IBlockData iblockdata, EnumDirection enumdirection, IBlockData iblockdata1, GeneratorAccess generatoraccess, BlockPosition blockposition, BlockPosition blockposition1) { -- return this.canSurvive(iblockdata, generatoraccess, blockposition) ? this.getStateWithAge(generatoraccess, blockposition, (Integer) iblockdata.getValue(BlockFire.AGE)) : Blocks.AIR.defaultBlockState(); + protected IBlockData updateShape(IBlockData iblockdata, IWorldReader iworldreader, ScheduledTickAccess scheduledtickaccess, BlockPosition blockposition, EnumDirection enumdirection, BlockPosition blockposition1, IBlockData iblockdata1, RandomSource randomsource) { +- return this.canSurvive(iblockdata, iworldreader, blockposition) ? this.getStateWithAge(iworldreader, blockposition, (Integer) iblockdata.getValue(BlockFire.AGE)) : Blocks.AIR.defaultBlockState(); + // CraftBukkit start -+ if (!this.canSurvive(iblockdata, generatoraccess, blockposition)) { ++ if (!this.canSurvive(iblockdata, iworldreader, blockposition)) { + // Suppress during worldgen -+ if (!(generatoraccess instanceof World)) { ++ if (!(iworldreader instanceof World world)) { + return Blocks.AIR.defaultBlockState(); + } -+ CraftBlockState blockState = CraftBlockStates.getBlockState(generatoraccess, blockposition); ++ CraftBlockState blockState = CraftBlockStates.getBlockState(world, blockposition); + blockState.setData(Blocks.AIR.defaultBlockState()); + + BlockFadeEvent event = new BlockFadeEvent(blockState.getBlock(), blockState); -+ ((World) generatoraccess).getCraftServer().getPluginManager().callEvent(event); ++ world.getCraftServer().getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + return blockState.getHandle(); + } + } -+ return this.getStateWithAge(generatoraccess, blockposition, (Integer) iblockdata.getValue(BlockFire.AGE)); ++ return this.getStateWithAge(iworldreader, blockposition, (Integer) iblockdata.getValue(BlockFire.AGE)); + // CraftBukkit end } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockFireAbstract.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockFireAbstract.patch index 7e7020ba83..639176c455 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockFireAbstract.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockFireAbstract.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockFireAbstract.java +++ b/net/minecraft/world/level/block/BlockFireAbstract.java -@@ -19,6 +19,10 @@ +@@ -20,6 +20,10 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -11,10 +11,10 @@ public abstract class BlockFireAbstract extends Block { private static final int SECONDS_ON_FIRE = 8; -@@ -127,7 +131,14 @@ - if (!entity.fireImmune()) { - entity.setRemainingFireTicks(entity.getRemainingFireTicks() + 1); - if (entity.getRemainingFireTicks() == 0) { +@@ -137,7 +141,14 @@ + } + + if (entity.getRemainingFireTicks() >= 0) { - entity.igniteForSeconds(8.0F); + // CraftBukkit start + org.bukkit.event.entity.EntityCombustEvent event = new org.bukkit.event.entity.EntityCombustByBlockEvent(org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition), entity.getBukkitEntity(), 8.0F); @@ -27,7 +27,7 @@ } } -@@ -136,26 +147,26 @@ +@@ -146,26 +157,26 @@ } @Override @@ -38,8 +38,8 @@ Optional optional = BlockPortalShape.findEmptyPortalShape(world, blockposition, EnumDirection.EnumAxis.X); if (optional.isPresent()) { -- ((BlockPortalShape) optional.get()).createPortalBlocks(); -+ ((BlockPortalShape) optional.get()).createPortalBlocks((context == null) ? null : context.getPlayer()); // CraftBukkit - player +- ((BlockPortalShape) optional.get()).createPortalBlocks(world); ++ ((BlockPortalShape) optional.get()).createPortalBlocks(world, (context == null) ? null : context.getPlayer()); // CraftBukkit - player return; } } @@ -58,7 +58,7 @@ } @Override -@@ -203,4 +214,12 @@ +@@ -213,4 +224,12 @@ } } } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockFluids.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockFluids.patch index addd5dfa3b..db927b8cf7 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockFluids.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockFluids.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockFluids.java +++ b/net/minecraft/world/level/block/BlockFluids.java -@@ -39,7 +39,7 @@ +@@ -42,7 +42,7 @@ public class BlockFluids extends Block implements IFluidSource { private static final Codec FLOWING_FLUID = BuiltInRegistries.FLUID.byNameCodec().comapFlatMap((fluidtype) -> { @@ -9,7 +9,7 @@ if (fluidtype instanceof FluidTypeFlowing fluidtypeflowing) { dataresult = DataResult.success(fluidtypeflowing); -@@ -172,14 +172,20 @@ +@@ -175,14 +175,20 @@ if (world.getFluidState(blockposition1).is(TagsFluid.WATER)) { Block block = world.getFluidState(blockposition).isSource() ? Blocks.OBSIDIAN : Blocks.COBBLESTONE; diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockIce.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockIce.patch index 7164cce2f7..4c22d943b1 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockIce.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockIce.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockIce.java +++ b/net/minecraft/world/level/block/BlockIce.java -@@ -59,6 +59,11 @@ +@@ -60,6 +60,11 @@ } protected void melt(IBlockData iblockdata, World world, BlockPosition blockposition) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockLeaves.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockLeaves.patch index c3ca72ab33..31ae1d4895 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockLeaves.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockLeaves.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockLeaves.java +++ b/net/minecraft/world/level/block/BlockLeaves.java -@@ -25,6 +25,8 @@ +@@ -27,6 +27,8 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapes; @@ -9,7 +9,7 @@ public class BlockLeaves extends Block implements IBlockWaterlogged { public static final MapCodec CODEC = simpleCodec(BlockLeaves::new); -@@ -57,6 +59,14 @@ +@@ -59,6 +61,14 @@ @Override protected void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if (this.decaying(iblockdata)) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockLectern.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockLectern.patch index 645c4d73f0..2e2f29d8df 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockLectern.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockLectern.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockLectern.java +++ b/net/minecraft/world/level/block/BlockLectern.java -@@ -208,11 +208,12 @@ +@@ -211,11 +211,12 @@ } private void popBook(IBlockData iblockdata, World world, BlockPosition blockposition) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockLever.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockLever.patch index 19b5501471..32219f9395 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockLever.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockLever.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockLever.java +++ b/net/minecraft/world/level/block/BlockLever.java -@@ -29,6 +29,8 @@ +@@ -32,6 +32,8 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -9,9 +9,9 @@ public class BlockLever extends BlockAttachable { public static final MapCodec CODEC = simpleCodec(BlockLever::new); -@@ -101,6 +103,20 @@ - - return EnumInteractionResult.SUCCESS; +@@ -102,6 +104,20 @@ + makeParticle(iblockdata1, world, blockposition, 1.0F); + } } else { + // CraftBukkit start - Interact Lever + boolean powered = iblockdata.getValue(BlockLever.POWERED); // Old powered state @@ -28,5 +28,5 @@ + // CraftBukkit end + this.pull(iblockdata, world, blockposition, (EntityHuman) null); - return EnumInteractionResult.CONSUME; } + diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockMagma.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockMagma.patch index 708bbfa85d..8c863e49d3 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockMagma.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockMagma.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockMagma.java +++ b/net/minecraft/world/level/block/BlockMagma.java -@@ -29,7 +29,7 @@ +@@ -30,7 +30,7 @@ @Override public void stepOn(World world, BlockPosition blockposition, IBlockData iblockdata, Entity entity) { if (!entity.isSteppingCarefully() && entity instanceof EntityLiving) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockMinecartDetector.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockMinecartDetector.patch index 0abacadda9..0029fbfc6d 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockMinecartDetector.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockMinecartDetector.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/level/block/BlockMinecartDetector.java +++ b/net/minecraft/world/level/block/BlockMinecartDetector.java -@@ -26,6 +26,8 @@ - import net.minecraft.world.level.block.state.properties.IBlockState; +@@ -27,6 +27,8 @@ + import net.minecraft.world.level.redstone.Orientation; import net.minecraft.world.phys.AxisAlignedBB; +import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit @@ -9,7 +9,7 @@ public class BlockMinecartDetector extends BlockMinecartTrackAbstract { public static final MapCodec CODEC = simpleCodec(BlockMinecartDetector::new); -@@ -87,6 +89,16 @@ +@@ -88,6 +90,16 @@ } IBlockData iblockdata1; diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockMonsterEggs.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockMonsterEggs.patch index d77107faf6..894857deda 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockMonsterEggs.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockMonsterEggs.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockMonsterEggs.java +++ b/net/minecraft/world/level/block/BlockMonsterEggs.java -@@ -19,6 +19,8 @@ +@@ -20,6 +20,8 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.block.state.properties.IBlockState; @@ -9,7 +9,7 @@ public class BlockMonsterEggs extends Block { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { -@@ -53,7 +55,7 @@ +@@ -54,7 +56,7 @@ if (entitysilverfish != null) { entitysilverfish.moveTo((double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D, 0.0F, 0.0F); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockNote.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockNote.patch index 6fa812480a..74c8339fc9 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockNote.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockNote.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockNote.java +++ b/net/minecraft/world/level/block/BlockNote.java -@@ -83,6 +83,7 @@ +@@ -85,6 +85,7 @@ if (flag1 != (Boolean) iblockdata.getValue(BlockNote.POWERED)) { if (flag1) { this.playNote((Entity) null, iblockdata, world, blockposition); @@ -8,7 +8,7 @@ } world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockNote.POWERED, flag1), 3); -@@ -92,6 +93,12 @@ +@@ -94,6 +95,12 @@ private void playNote(@Nullable Entity entity, IBlockData iblockdata, World world, BlockPosition blockposition) { if (((BlockPropertyInstrument) iblockdata.getValue(BlockNote.INSTRUMENT)).worksAboveNoteBlock() || world.getBlockState(blockposition.above()).isAir()) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockObserver.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockObserver.patch index 3db9cb18f4..b76c2f04f0 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockObserver.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockObserver.patch @@ -1,15 +1,15 @@ --- a/net/minecraft/world/level/block/BlockObserver.java +++ b/net/minecraft/world/level/block/BlockObserver.java -@@ -15,6 +15,8 @@ - import net.minecraft.world.level.block.state.properties.BlockProperties; - import net.minecraft.world.level.block.state.properties.BlockStateBoolean; +@@ -18,6 +18,8 @@ + import net.minecraft.world.level.redstone.ExperimentalRedstoneUtils; + import net.minecraft.world.level.redstone.Orientation; +import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit + public class BlockObserver extends BlockDirectional { public static final MapCodec CODEC = simpleCodec(BlockObserver::new); -@@ -48,8 +50,18 @@ +@@ -51,8 +53,18 @@ @Override protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if ((Boolean) iblockdata.getValue(BlockObserver.POWERED)) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockPlant.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockPlant.patch index c7ded8557d..274403a394 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockPlant.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockPlant.patch @@ -1,17 +1,29 @@ --- a/net/minecraft/world/level/block/BlockPlant.java +++ b/net/minecraft/world/level/block/BlockPlant.java -@@ -26,7 +26,14 @@ +@@ -12,6 +12,10 @@ + import net.minecraft.world.level.block.state.IBlockData; + import net.minecraft.world.level.pathfinder.PathMode; + ++// CraftBukkit start ++import net.minecraft.world.level.World; ++// CraftBukkit end ++ + public abstract class BlockPlant extends Block { + + protected BlockPlant(BlockBase.Info blockbase_info) { +@@ -27,7 +31,15 @@ @Override - protected IBlockData updateShape(IBlockData iblockdata, EnumDirection enumdirection, IBlockData iblockdata1, GeneratorAccess generatoraccess, BlockPosition blockposition, BlockPosition blockposition1) { -- return !iblockdata.canSurvive(generatoraccess, blockposition) ? Blocks.AIR.defaultBlockState() : super.updateShape(iblockdata, enumdirection, iblockdata1, generatoraccess, blockposition, blockposition1); + protected IBlockData updateShape(IBlockData iblockdata, IWorldReader iworldreader, ScheduledTickAccess scheduledtickaccess, BlockPosition blockposition, EnumDirection enumdirection, BlockPosition blockposition1, IBlockData iblockdata1, RandomSource randomsource) { +- return !iblockdata.canSurvive(iworldreader, blockposition) ? Blocks.AIR.defaultBlockState() : super.updateShape(iblockdata, iworldreader, scheduledtickaccess, blockposition, enumdirection, blockposition1, iblockdata1, randomsource); + // CraftBukkit start -+ if (!iblockdata.canSurvive(generatoraccess, blockposition)) { -+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPhysicsEvent(generatoraccess, blockposition).isCancelled()) { ++ if (!iblockdata.canSurvive(iworldreader, blockposition)) { ++ // Suppress during worldgen ++ if (!(iworldreader instanceof World world) || !org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPhysicsEvent(world, blockposition).isCancelled()) { + return Blocks.AIR.defaultBlockState(); + } + } -+ return super.updateShape(iblockdata, enumdirection, iblockdata1, generatoraccess, blockposition, blockposition1); ++ return super.updateShape(iblockdata, iworldreader, scheduledtickaccess, blockposition, enumdirection, blockposition1, iblockdata1, randomsource); + // CraftBukkit end } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockPortal.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockPortal.patch index 0c279c6e03..70f5f61d95 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockPortal.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockPortal.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockPortal.java +++ b/net/minecraft/world/level/block/BlockPortal.java -@@ -38,6 +38,15 @@ +@@ -39,6 +39,15 @@ import net.minecraft.world.phys.shapes.VoxelShapeCollision; import org.slf4j.Logger; @@ -16,17 +16,17 @@ public class BlockPortal extends Block implements Portal { public static final MapCodec CODEC = simpleCodec(BlockPortal::new); -@@ -76,7 +85,8 @@ +@@ -77,7 +86,8 @@ } if (worldserver.getBlockState(blockposition).isValidSpawn(worldserver, blockposition, EntityTypes.ZOMBIFIED_PIGLIN)) { -- Entity entity = EntityTypes.ZOMBIFIED_PIGLIN.spawn(worldserver, blockposition.above(), EnumMobSpawn.STRUCTURE); +- Entity entity = EntityTypes.ZOMBIFIED_PIGLIN.spawn(worldserver, blockposition.above(), EntitySpawnReason.STRUCTURE); + // CraftBukkit - set spawn reason to NETHER_PORTAL -+ Entity entity = EntityTypes.ZOMBIFIED_PIGLIN.spawn(worldserver, blockposition.above(), EnumMobSpawn.STRUCTURE, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NETHER_PORTAL); ++ Entity entity = EntityTypes.ZOMBIFIED_PIGLIN.spawn(worldserver, blockposition.above(), EntitySpawnReason.STRUCTURE, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NETHER_PORTAL); if (entity != null) { entity.setPortalCooldown(); -@@ -98,6 +108,10 @@ +@@ -104,6 +114,10 @@ @Override protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { if (entity.canUsePortal(false)) { @@ -37,10 +37,10 @@ entity.setAsInsidePortal(this, blockposition); } -@@ -115,24 +129,34 @@ +@@ -121,24 +135,34 @@ @Nullable @Override - public DimensionTransition getPortalDestination(WorldServer worldserver, Entity entity, BlockPosition blockposition) { + public TeleportTransition getPortalDestination(WorldServer worldserver, Entity entity, BlockPosition blockposition) { - ResourceKey resourcekey = worldserver.dimension() == World.NETHER ? World.OVERWORLD : World.NETHER; + // CraftBukkit start + ResourceKey resourcekey = worldserver.getTypeKey() == WorldDimension.NETHER ? World.OVERWORLD : World.NETHER; @@ -48,7 +48,7 @@ if (worldserver1 == null) { - return null; -+ return new DimensionTransition(PlayerTeleportEvent.TeleportCause.NETHER_PORTAL); // always fire event in case plugins wish to change it ++ return new TeleportTransition(PlayerTeleportEvent.TeleportCause.NETHER_PORTAL); // always fire event in case plugins wish to change it } else { - boolean flag = worldserver1.dimension() == World.NETHER; + boolean flag = worldserver1.getTypeKey() == WorldDimension.NETHER; @@ -71,15 +71,15 @@ } @Nullable -- private DimensionTransition getExitPortal(WorldServer worldserver, Entity entity, BlockPosition blockposition, BlockPosition blockposition1, boolean flag, WorldBorder worldborder) { +- private TeleportTransition getExitPortal(WorldServer worldserver, Entity entity, BlockPosition blockposition, BlockPosition blockposition1, boolean flag, WorldBorder worldborder) { - Optional optional = worldserver.getPortalForcer().findClosestPortalPosition(blockposition1, flag, worldborder); -+ private DimensionTransition getExitPortal(WorldServer worldserver, Entity entity, BlockPosition blockposition, BlockPosition blockposition1, boolean flag, WorldBorder worldborder, int searchRadius, boolean canCreatePortal, int createRadius) { ++ private TeleportTransition getExitPortal(WorldServer worldserver, Entity entity, BlockPosition blockposition, BlockPosition blockposition1, boolean flag, WorldBorder worldborder, int searchRadius, boolean canCreatePortal, int createRadius) { + Optional optional = worldserver.getPortalForcer().findClosestPortalPosition(blockposition1, worldborder, searchRadius); BlockUtil.Rectangle blockutil_rectangle; - DimensionTransition.a dimensiontransition_a; + TeleportTransition.a teleporttransition_a; -@@ -146,17 +170,22 @@ - dimensiontransition_a = DimensionTransition.PLAY_PORTAL_SOUND.then((entity1) -> { +@@ -152,17 +176,22 @@ + teleporttransition_a = TeleportTransition.PLAY_PORTAL_SOUND.then((entity1) -> { entity1.placePortalTicket(blockposition2); }); - } else { @@ -96,20 +96,20 @@ } blockutil_rectangle = (BlockUtil.Rectangle) optional1.get(); - dimensiontransition_a = DimensionTransition.PLAY_PORTAL_SOUND.then(DimensionTransition.PLACE_PORTAL_TICKET); + teleporttransition_a = TeleportTransition.PLAY_PORTAL_SOUND.then(TeleportTransition.PLACE_PORTAL_TICKET); + // CraftBukkit start + } else { + return null; + // CraftBukkit end } - return getDimensionTransitionFromExit(entity, blockposition, blockutil_rectangle, worldserver, dimensiontransition_a); -@@ -198,7 +227,7 @@ - Vec3D vec3d3 = new Vec3D((double) blockposition.getX() + (flag ? d2 : d4), (double) blockposition.getY() + d3, (double) blockposition.getZ() + (flag ? d4 : d2)); - Vec3D vec3d4 = BlockPortalShape.findCollisionFreePosition(vec3d3, worldserver, entity, entitysize); + return getDimensionTransitionFromExit(entity, blockposition, blockutil_rectangle, worldserver, teleporttransition_a); +@@ -203,7 +232,7 @@ + Vec3D vec3d1 = new Vec3D((double) blockposition.getX() + (flag ? d2 : d4), (double) blockposition.getY() + d3, (double) blockposition.getZ() + (flag ? d4 : d2)); + Vec3D vec3d2 = BlockPortalShape.findCollisionFreePosition(vec3d1, worldserver, entity, entitysize); -- return new DimensionTransition(worldserver, vec3d4, vec3d2, f + (float) i, f1, dimensiontransition_a); -+ return new DimensionTransition(worldserver, vec3d4, vec3d2, f + (float) i, f1, dimensiontransition_a, PlayerTeleportEvent.TeleportCause.NETHER_PORTAL); // CraftBukkit +- return new TeleportTransition(worldserver, vec3d2, Vec3D.ZERO, (float) i, 0.0F, Relative.union(Relative.DELTA, Relative.ROTATION), teleporttransition_a); ++ return new TeleportTransition(worldserver, vec3d2, Vec3D.ZERO, (float) i, 0.0F, Relative.union(Relative.DELTA, Relative.ROTATION), teleporttransition_a, PlayerTeleportEvent.TeleportCause.NETHER_PORTAL); // CraftBukkit } @Override diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockPoweredRail.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockPoweredRail.patch index 96b338866d..2870194ef8 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockPoweredRail.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockPoweredRail.patch @@ -22,4 +22,4 @@ + // CraftBukkit end world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockPoweredRail.POWERED, flag1), 3); world.updateNeighborsAt(blockposition.below(), this); - if (((BlockPropertyTrackPosition) iblockdata.getValue(BlockPoweredRail.SHAPE)).isAscending()) { + if (((BlockPropertyTrackPosition) iblockdata.getValue(BlockPoweredRail.SHAPE)).isSlope()) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockPumpkinCarved.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockPumpkinCarved.patch index 82f7a792e7..c7033e7a12 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockPumpkinCarved.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockPumpkinCarved.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/level/block/BlockPumpkinCarved.java +++ b/net/minecraft/world/level/block/BlockPumpkinCarved.java -@@ -24,6 +24,10 @@ +@@ -25,6 +25,10 @@ import net.minecraft.world.level.block.state.predicate.BlockStatePredicate; - import net.minecraft.world.level.block.state.properties.BlockStateDirection; + import net.minecraft.world.level.block.state.properties.BlockStateEnum; +// CraftBukkit start +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; @@ -11,7 +11,7 @@ public class BlockPumpkinCarved extends BlockFacingHorizontal { public static final MapCodec CODEC = simpleCodec(BlockPumpkinCarved::new); -@@ -86,9 +90,14 @@ +@@ -87,9 +91,14 @@ } private static void spawnGolemInWorld(World world, ShapeDetector.ShapeDetectorCollection shapedetector_shapedetectorcollection, Entity entity, BlockPosition blockposition) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneComparator.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneComparator.patch index 79f53d0f30..dc9826b6d0 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneComparator.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneComparator.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockRedstoneComparator.java +++ b/net/minecraft/world/level/block/BlockRedstoneComparator.java -@@ -27,6 +27,8 @@ +@@ -28,6 +28,8 @@ import net.minecraft.world.phys.MovingObjectPositionBlock; import net.minecraft.world.ticks.TickListPriority; @@ -9,7 +9,7 @@ public class BlockRedstoneComparator extends BlockDiodeAbstract implements ITileEntity { public static final MapCodec CODEC = simpleCodec(BlockRedstoneComparator::new); -@@ -109,7 +111,8 @@ +@@ -110,7 +112,8 @@ @Nullable private EntityItemFrame getItemFrame(World world, EnumDirection enumdirection, BlockPosition blockposition) { @@ -19,7 +19,7 @@ return entityitemframe != null && entityitemframe.getDirection() == enumdirection; }); -@@ -162,8 +165,18 @@ +@@ -163,8 +166,18 @@ boolean flag1 = (Boolean) iblockdata.getValue(BlockRedstoneComparator.POWERED); if (flag1 && !flag) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneLamp.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneLamp.patch index dce344c8b4..c90e00522d 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneLamp.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneLamp.patch @@ -1,15 +1,15 @@ --- a/net/minecraft/world/level/block/BlockRedstoneLamp.java +++ b/net/minecraft/world/level/block/BlockRedstoneLamp.java -@@ -12,6 +12,8 @@ - import net.minecraft.world.level.block.state.IBlockData; +@@ -13,6 +13,8 @@ import net.minecraft.world.level.block.state.properties.BlockStateBoolean; + import net.minecraft.world.level.redstone.Orientation; +import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit + public class BlockRedstoneLamp extends Block { public static final MapCodec CODEC = simpleCodec(BlockRedstoneLamp::new); -@@ -42,6 +44,11 @@ +@@ -43,6 +45,11 @@ if (flag1) { world.scheduleTick(blockposition, (Block) this, 4); } else { @@ -21,7 +21,7 @@ world.setBlock(blockposition, (IBlockData) iblockdata.cycle(BlockRedstoneLamp.LIT), 2); } } -@@ -52,6 +59,11 @@ +@@ -53,6 +60,11 @@ @Override protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if ((Boolean) iblockdata.getValue(BlockRedstoneLamp.LIT) && !worldserver.hasNeighborSignal(blockposition)) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneOre.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneOre.patch index cb76dcb3b9..1bd1a91b4f 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneOre.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneOre.patch @@ -50,7 +50,7 @@ + interact(iblockdata, world, blockposition, entityhuman); // CraftBukkit - add entityhuman } - return itemstack.getItem() instanceof ItemBlock && (new BlockActionContext(entityhuman, enumhand, itemstack, movingobjectpositionblock)).canPlace() ? ItemInteractionResult.SKIP_DEFAULT_BLOCK_INTERACTION : ItemInteractionResult.SUCCESS; + return (EnumInteractionResult) (itemstack.getItem() instanceof ItemBlock && (new BlockActionContext(entityhuman, enumhand, itemstack, movingobjectpositionblock)).canPlace() ? EnumInteractionResult.PASS : EnumInteractionResult.SUCCESS); } - private static void interact(IBlockData iblockdata, World world, BlockPosition blockposition) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneTorch.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneTorch.patch index e6c3fb386a..8d82d10337 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneTorch.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneTorch.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/level/block/BlockRedstoneTorch.java +++ b/net/minecraft/world/level/block/BlockRedstoneTorch.java -@@ -19,6 +19,8 @@ - import net.minecraft.world.level.block.state.properties.BlockProperties; - import net.minecraft.world.level.block.state.properties.BlockStateBoolean; +@@ -22,6 +22,8 @@ + import net.minecraft.world.level.redstone.ExperimentalRedstoneUtils; + import net.minecraft.world.level.redstone.Orientation; +import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit + diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneWire.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneWire.patch deleted file mode 100644 index 40407a286b..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneWire.patch +++ /dev/null @@ -1,29 +0,0 @@ ---- a/net/minecraft/world/level/block/BlockRedstoneWire.java -+++ b/net/minecraft/world/level/block/BlockRedstoneWire.java -@@ -36,6 +36,8 @@ - import net.minecraft.world.phys.shapes.VoxelShapeCollision; - import net.minecraft.world.phys.shapes.VoxelShapes; - -+import org.bukkit.event.block.BlockRedstoneEvent; // CraftBukkit -+ - public class BlockRedstoneWire extends Block { - - public static final MapCodec CODEC = simpleCodec(BlockRedstoneWire::new); -@@ -260,7 +262,16 @@ - private void updatePowerStrength(World world, BlockPosition blockposition, IBlockData iblockdata) { - int i = this.calculateTargetStrength(world, blockposition); - -- if ((Integer) iblockdata.getValue(BlockRedstoneWire.POWER) != i) { -+ // CraftBukkit start -+ int oldPower = (Integer) iblockdata.getValue(BlockRedstoneWire.POWER); -+ if (oldPower != i) { -+ BlockRedstoneEvent event = new BlockRedstoneEvent(world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), oldPower, i); -+ world.getCraftServer().getPluginManager().callEvent(event); -+ -+ i = event.getNewCurrent(); -+ } -+ if (oldPower != i) { -+ // CraftBukkit end - if (world.getBlockState(blockposition) == iblockdata) { - world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockRedstoneWire.POWER, i), 2); - } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockRespawnAnchor.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockRespawnAnchor.patch index 30a49ff43d..3dc1bbb4f1 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockRespawnAnchor.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockRespawnAnchor.patch @@ -1,15 +1,15 @@ --- a/net/minecraft/world/level/block/BlockRespawnAnchor.java +++ b/net/minecraft/world/level/block/BlockRespawnAnchor.java -@@ -89,7 +89,7 @@ +@@ -88,7 +88,7 @@ EntityPlayer entityplayer = (EntityPlayer) entityhuman; if (entityplayer.getRespawnDimension() != world.dimension() || !blockposition.equals(entityplayer.getRespawnPosition())) { - entityplayer.setRespawnPosition(world.dimension(), blockposition, 0.0F, false, true); + entityplayer.setRespawnPosition(world.dimension(), blockposition, 0.0F, false, true, org.bukkit.event.player.PlayerSpawnChangeEvent.Cause.RESPAWN_ANCHOR); // CraftBukkit world.playSound((EntityHuman) null, (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, SoundEffects.RESPAWN_ANCHOR_SET_SPAWN, SoundCategory.BLOCKS, 1.0F, 1.0F); - return EnumInteractionResult.SUCCESS; + return EnumInteractionResult.SUCCESS_SERVER; } -@@ -128,15 +128,16 @@ +@@ -127,15 +127,16 @@ } private void explode(IBlockData iblockdata, World world, final BlockPosition blockposition) { @@ -28,7 +28,7 @@ @Override public Optional getBlockExplosionResistance(Explosion explosion, IBlockAccess iblockaccess, BlockPosition blockposition1, IBlockData iblockdata1, Fluid fluid) { return blockposition1.equals(blockposition) && flag1 ? Optional.of(Blocks.WATER.getExplosionResistance()) : super.getBlockExplosionResistance(explosion, iblockaccess, blockposition1, iblockdata1, fluid); -@@ -144,7 +145,7 @@ +@@ -143,7 +144,7 @@ }; Vec3D vec3d = blockposition.getCenter(); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockSign.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockSign.patch index bd27f5de6d..677b87be0b 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockSign.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockSign.patch @@ -1,15 +1,15 @@ --- a/net/minecraft/world/level/block/BlockSign.java +++ b/net/minecraft/world/level/block/BlockSign.java -@@ -139,7 +139,7 @@ +@@ -140,7 +140,7 @@ } else if (flag1) { - return EnumInteractionResult.SUCCESS; + return EnumInteractionResult.SUCCESS_SERVER; } else if (!this.otherPlayerIsEditingSign(entityhuman, tileentitysign) && entityhuman.mayBuild() && this.hasEditableText(entityhuman, tileentitysign, flag)) { - this.openTextEdit(entityhuman, tileentitysign, flag); + this.openTextEdit(entityhuman, tileentitysign, flag, org.bukkit.event.player.PlayerSignOpenEvent.Cause.INTERACT); // CraftBukkit - return EnumInteractionResult.SUCCESS; + return EnumInteractionResult.SUCCESS_SERVER; } else { return EnumInteractionResult.PASS; -@@ -185,6 +185,15 @@ +@@ -186,6 +186,15 @@ } public void openTextEdit(EntityHuman entityhuman, TileEntitySign tileentitysign, boolean flag) { @@ -25,7 +25,7 @@ tileentitysign.setAllowedPlayerEditor(entityhuman.getUUID()); entityhuman.openTextEdit(tileentitysign, flag); } -@@ -198,6 +207,6 @@ +@@ -199,6 +208,6 @@ @Nullable @Override public BlockEntityTicker getTicker(World world, IBlockData iblockdata, TileEntityTypes tileentitytypes) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockSoil.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockSoil.patch index fb1d9e8fb6..4f6c91e2d8 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockSoil.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockSoil.patch @@ -12,7 +12,7 @@ public class BlockSoil extends Block { public static final MapCodec CODEC = simpleCodec(BlockSoil::new); -@@ -92,26 +97,49 @@ +@@ -92,28 +97,51 @@ if (!isNearWater(worldserver, blockposition) && !worldserver.isRainingAt(blockposition.above())) { if (i > 0) { @@ -31,25 +31,27 @@ @Override public void fallOn(World world, IBlockData iblockdata, BlockPosition blockposition, Entity entity, float f) { + super.fallOn(world, iblockdata, blockposition, entity, f); // CraftBukkit - moved here as game rules / events shouldn't affect fall damage. - if (!world.isClientSide && world.random.nextFloat() < f - 0.5F && entity instanceof EntityLiving && (entity instanceof EntityHuman || world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) && entity.getBbWidth() * entity.getBbWidth() * entity.getBbHeight() > 0.512F) { -+ // CraftBukkit start - Interact soil -+ org.bukkit.event.Cancellable cancellable; -+ if (entity instanceof EntityHuman) { -+ cancellable = CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null); -+ } else { -+ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ())); -+ world.getCraftServer().getPluginManager().callEvent((EntityInteractEvent) cancellable); -+ } + if (world instanceof WorldServer worldserver) { + if (world.random.nextFloat() < f - 0.5F && entity instanceof EntityLiving && (entity instanceof EntityHuman || worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) && entity.getBbWidth() * entity.getBbWidth() * entity.getBbHeight() > 0.512F) { ++ // CraftBukkit start - Interact soil ++ org.bukkit.event.Cancellable cancellable; ++ if (entity instanceof EntityHuman) { ++ cancellable = CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null); ++ } else { ++ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ())); ++ world.getCraftServer().getPluginManager().callEvent((EntityInteractEvent) cancellable); ++ } + -+ if (cancellable.isCancelled()) { -+ return; -+ } ++ if (cancellable.isCancelled()) { ++ return; ++ } + -+ if (!CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.DIRT.defaultBlockState())) { -+ return; -+ } -+ // CraftBukkit end - turnToDirt(entity, iblockdata, world, blockposition); ++ if (!CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.DIRT.defaultBlockState())) { ++ return; ++ } ++ // CraftBukkit end + turnToDirt(entity, iblockdata, world, blockposition); + } } - super.fallOn(world, iblockdata, blockposition, entity, f); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockSponge.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockSponge.patch index ae282d2920..cb7d20fd1b 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockSponge.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockSponge.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/level/block/BlockSponge.java +++ b/net/minecraft/world/level/block/BlockSponge.java -@@ -13,6 +13,13 @@ - import net.minecraft.world.level.block.state.IBlockData; +@@ -15,6 +15,13 @@ import net.minecraft.world.level.material.Fluid; + import net.minecraft.world.level.redstone.Orientation; +// CraftBukkit start +import java.util.List; @@ -14,7 +14,7 @@ public class BlockSponge extends Block { public static final MapCodec CODEC = simpleCodec(BlockSponge::new); -@@ -51,7 +58,8 @@ +@@ -53,7 +60,8 @@ } private boolean removeWaterBreadthFirstSearch(World world, BlockPosition blockposition) { @@ -24,7 +24,7 @@ EnumDirection[] aenumdirection = BlockSponge.ALL_DIRECTIONS; int i = aenumdirection.length; -@@ -65,8 +73,10 @@ +@@ -67,8 +75,10 @@ if (blockposition1.equals(blockposition)) { return true; } else { @@ -37,7 +37,7 @@ if (!fluid.is(TagsFluid.WATER)) { return false; -@@ -76,27 +86,64 @@ +@@ -78,27 +88,64 @@ if (block instanceof IFluidSource) { IFluidSource ifluidsource = (IFluidSource) block; diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockSweetBerryBush.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockSweetBerryBush.patch index e3d7501e2f..a2a2f3145f 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockSweetBerryBush.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockSweetBerryBush.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockSweetBerryBush.java +++ b/net/minecraft/world/level/block/BlockSweetBerryBush.java -@@ -30,6 +30,13 @@ +@@ -29,6 +29,13 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -14,7 +14,7 @@ public class BlockSweetBerryBush extends BlockPlant implements IBlockFragilePlantElement { public static final MapCodec CODEC = simpleCodec(BlockSweetBerryBush::new); -@@ -71,7 +78,7 @@ +@@ -70,7 +77,7 @@ if (i < 3 && randomsource.nextInt(5) == 0 && worldserver.getRawBrightness(blockposition.above(), 0) >= 9) { IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockSweetBerryBush.AGE, i + 1); @@ -23,16 +23,16 @@ worldserver.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1)); } -@@ -86,7 +93,7 @@ - double d1 = Math.abs(entity.getZ() - entity.zOld); +@@ -91,7 +98,7 @@ + double d1 = Math.abs(vec3d.z()); - if (d0 >= 0.003000000026077032D || d1 >= 0.003000000026077032D) { -- entity.hurt(world.damageSources().sweetBerryBush(), 1.0F); -+ entity.hurt(world.damageSources().sweetBerryBush().directBlock(world, blockposition), 1.0F); // CraftBukkit - } - } + if (d0 >= 0.003000000026077032D || d1 >= 0.003000000026077032D) { +- entity.hurtServer(worldserver, world.damageSources().sweetBerryBush(), 1.0F); ++ entity.hurtServer(worldserver, world.damageSources().sweetBerryBush().directBlock(world, blockposition), 1.0F); // CraftBukkit + } + } -@@ -109,7 +116,15 @@ +@@ -118,7 +125,15 @@ if (i > 1) { int j = 1 + world.random.nextInt(2); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockTNT.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockTNT.patch index a01659be10..9c74457272 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockTNT.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockTNT.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/level/block/BlockTNT.java +++ b/net/minecraft/world/level/block/BlockTNT.java -@@ -27,6 +27,11 @@ - import net.minecraft.world.level.gameevent.GameEvent; +@@ -29,6 +29,11 @@ + import net.minecraft.world.level.redstone.Orientation; import net.minecraft.world.phys.MovingObjectPositionBlock; +// CraftBukkit start @@ -12,7 +12,7 @@ public class BlockTNT extends Block { public static final MapCodec CODEC = simpleCodec(BlockTNT::new); -@@ -45,7 +50,7 @@ +@@ -47,7 +52,7 @@ @Override protected void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) { if (!iblockdata1.is(iblockdata.getBlock())) { @@ -21,16 +21,16 @@ explode(world, blockposition); world.removeBlock(blockposition, false); } -@@ -55,7 +60,7 @@ +@@ -57,7 +62,7 @@ @Override - protected void neighborChanged(IBlockData iblockdata, World world, BlockPosition blockposition, Block block, BlockPosition blockposition1, boolean flag) { + protected void neighborChanged(IBlockData iblockdata, World world, BlockPosition blockposition, Block block, @Nullable Orientation orientation, boolean flag) { - if (world.hasNeighborSignal(blockposition)) { -+ if (world.hasNeighborSignal(blockposition) && CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.REDSTONE, null, blockposition1)) { // CraftBukkit - TNTPrimeEvent ++ if (world.hasNeighborSignal(blockposition) && CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.REDSTONE, null, null)) { // CraftBukkit - TNTPrimeEvent explode(world, blockposition); world.removeBlock(blockposition, false); } -@@ -64,7 +69,7 @@ +@@ -66,7 +71,7 @@ @Override public IBlockData playerWillDestroy(World world, BlockPosition blockposition, IBlockData iblockdata, EntityHuman entityhuman) { @@ -45,7 +45,7 @@ } else { + // CraftBukkit start - TNTPrimeEvent + if (!CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.PLAYER, entityhuman, null)) { -+ return ItemInteractionResult.CONSUME; ++ return EnumInteractionResult.CONSUME; + } + // CraftBukkit end explode(world, blockposition, entityhuman); @@ -54,7 +54,7 @@ @@ -123,6 +133,11 @@ Entity entity = iprojectile.getOwner(); - if (iprojectile.isOnFire() && iprojectile.mayInteract(world, blockposition)) { + if (iprojectile.isOnFire() && iprojectile.mayInteract(worldserver, blockposition)) { + // CraftBukkit start + if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, Blocks.AIR.defaultBlockState()) || !CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.PROJECTILE, iprojectile, null)) { + return; diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockTallPlant.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockTallPlant.patch index 975c30491b..af55991d89 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockTallPlant.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockTallPlant.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockTallPlant.java +++ b/net/minecraft/world/level/block/BlockTallPlant.java -@@ -101,6 +101,11 @@ +@@ -103,6 +103,11 @@ } protected static void preventDropFromBottomPart(World world, BlockPosition blockposition, IBlockData iblockdata, EntityHuman entityhuman) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockTrapdoor.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockTrapdoor.patch index fb5c64d9e6..f9c7facd15 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockTrapdoor.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockTrapdoor.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockTrapdoor.java +++ b/net/minecraft/world/level/block/BlockTrapdoor.java -@@ -34,6 +34,8 @@ +@@ -38,6 +38,8 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -9,7 +9,7 @@ public class BlockTrapdoor extends BlockFacingHorizontal implements IBlockWaterlogged { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { -@@ -139,6 +141,19 @@ +@@ -143,6 +145,19 @@ boolean flag1 = world.hasNeighborSignal(blockposition); if (flag1 != (Boolean) iblockdata.getValue(BlockTrapdoor.POWERED)) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockTripwire.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockTripwire.patch index c611141f9c..bc230018b5 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockTripwire.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockTripwire.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockTripwire.java +++ b/net/minecraft/world/level/block/BlockTripwire.java -@@ -28,6 +28,8 @@ +@@ -29,6 +29,8 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -9,7 +9,7 @@ public class BlockTripwire extends Block { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { -@@ -167,6 +169,40 @@ +@@ -179,6 +181,40 @@ } } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockTripwireHook.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockTripwireHook.patch index a05ad28081..01475895a5 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockTripwireHook.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockTripwireHook.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockTripwireHook.java +++ b/net/minecraft/world/level/block/BlockTripwireHook.java -@@ -30,6 +30,11 @@ +@@ -32,6 +32,11 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -12,7 +12,7 @@ public class BlockTripwireHook extends Block { public static final MapCodec CODEC = simpleCodec(BlockTripwireHook::new); -@@ -174,6 +179,15 @@ +@@ -176,6 +181,15 @@ emitState(world, blockposition1, flag4, flag5, flag2, flag3); } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockTurtleEgg.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockTurtleEgg.patch index 7b3381fc71..f9aedfa840 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockTurtleEgg.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockTurtleEgg.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockTurtleEgg.java +++ b/net/minecraft/world/level/block/BlockTurtleEgg.java -@@ -31,6 +31,12 @@ +@@ -32,6 +32,12 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -13,27 +13,27 @@ public class BlockTurtleEgg extends Block { public static final MapCodec CODEC = simpleCodec(BlockTurtleEgg::new); -@@ -73,6 +79,19 @@ +@@ -74,6 +80,19 @@ private void destroyEgg(World world, IBlockData iblockdata, BlockPosition blockposition, Entity entity, int i) { - if (this.canDestroyEgg(world, entity)) { - if (!world.isClientSide && world.random.nextInt(i) == 0 && iblockdata.is(Blocks.TURTLE_EGG)) { + if (iblockdata.is(Blocks.TURTLE_EGG) && world instanceof WorldServer worldserver) { + if (this.canDestroyEgg(worldserver, entity) && world.random.nextInt(i) == 0) { + // CraftBukkit start - Step on eggs + org.bukkit.event.Cancellable cancellable; + if (entity instanceof EntityHuman) { + cancellable = CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null); + } else { -+ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), CraftBlock.at(world, blockposition)); -+ world.getCraftServer().getPluginManager().callEvent((EntityInteractEvent) cancellable); ++ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), CraftBlock.at(worldserver, blockposition)); ++ worldserver.getCraftServer().getPluginManager().callEvent((EntityInteractEvent) cancellable); + } + + if (cancellable.isCancelled()) { + return; + } + // CraftBukkit end - this.decreaseEggs(world, blockposition, iblockdata); + this.decreaseEggs(worldserver, blockposition, iblockdata); } - -@@ -99,10 +118,20 @@ + } +@@ -100,10 +119,20 @@ int i = (Integer) iblockdata.getValue(BlockTurtleEgg.HATCH); if (i < 2) { @@ -55,7 +55,7 @@ worldserver.playSound((EntityHuman) null, blockposition, SoundEffects.TURTLE_EGG_HATCH, SoundCategory.BLOCKS, 0.7F, 0.9F + randomsource.nextFloat() * 0.2F); worldserver.removeBlock(blockposition, false); worldserver.gameEvent((Holder) GameEvent.BLOCK_DESTROY, blockposition, GameEvent.a.of(iblockdata)); -@@ -115,7 +144,7 @@ +@@ -116,7 +145,7 @@ entityturtle.setAge(-24000); entityturtle.setHomePos(blockposition); entityturtle.moveTo((double) blockposition.getX() + 0.3D + (double) j * 0.2D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.3D, 0.0F, 0.0F); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockVine.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockVine.patch index 907a641fa3..7ebaef3b43 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockVine.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockVine.patch @@ -44,7 +44,7 @@ } } else { - if (enumdirection == EnumDirection.UP && blockposition.getY() < worldserver.getMaxBuildHeight() - 1) { + if (enumdirection == EnumDirection.UP && blockposition.getY() < worldserver.getMaxY()) { if (this.canSupportAtFace(worldserver, blockposition, enumdirection)) { - worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockVine.UP, true), 2); + CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, (IBlockData) iblockdata.setValue(BlockVine.UP, true), 2); // CraftBukkit diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockWaterLily.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockWaterLily.patch index 9251f6af79..6423b8bbd9 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockWaterLily.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockWaterLily.patch @@ -14,7 +14,7 @@ @@ -32,6 +36,11 @@ protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { super.entityInside(iblockdata, world, blockposition, entity); - if (world instanceof WorldServer && entity instanceof EntityBoat) { + if (world instanceof WorldServer && entity instanceof AbstractBoat) { + // CraftBukkit start + if (!CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR.defaultBlockState())) { + return; diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockWitherRose.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockWitherRose.patch index e3999a628b..355fb68c3d 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockWitherRose.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockWitherRose.patch @@ -1,11 +1,11 @@ --- a/net/minecraft/world/level/block/BlockWitherRose.java +++ b/net/minecraft/world/level/block/BlockWitherRose.java -@@ -67,7 +67,7 @@ - EntityLiving entityliving = (EntityLiving) entity; - - if (!entityliving.isInvulnerableTo(world.damageSources().wither())) { +@@ -66,7 +66,7 @@ + if (world instanceof WorldServer worldserver) { + if (world.getDifficulty() != EnumDifficulty.PEACEFUL && entity instanceof EntityLiving entityliving) { + if (!entityliving.isInvulnerableTo(worldserver, world.damageSources().wither())) { - entityliving.addEffect(new MobEffect(MobEffects.WITHER, 40)); + entityliving.addEffect(new MobEffect(MobEffects.WITHER, 40), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.WITHER_ROSE); // CraftBukkit } } - + } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockWitherSkull.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockWitherSkull.patch index 780efc1b74..099a259f25 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockWitherSkull.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockWitherSkull.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockWitherSkull.java +++ b/net/minecraft/world/level/block/BlockWitherSkull.java -@@ -25,6 +25,10 @@ +@@ -26,6 +26,10 @@ import net.minecraft.world.level.block.state.pattern.ShapeDetectorBuilder; import net.minecraft.world.level.block.state.predicate.BlockStatePredicate; @@ -11,7 +11,7 @@ public class BlockWitherSkull extends BlockSkull { public static final MapCodec CODEC = simpleCodec(BlockWitherSkull::new); -@@ -57,6 +61,7 @@ +@@ -58,6 +62,7 @@ } public static void checkSpawn(World world, BlockPosition blockposition, TileEntitySkull tileentityskull) { @@ -19,8 +19,8 @@ if (!world.isClientSide) { IBlockData iblockdata = tileentityskull.getBlockState(); boolean flag = iblockdata.is(Blocks.WITHER_SKELETON_SKULL) || iblockdata.is(Blocks.WITHER_SKELETON_WALL_SKULL); -@@ -68,12 +73,18 @@ - EntityWither entitywither = (EntityWither) EntityTypes.WITHER.create(world); +@@ -69,12 +74,18 @@ + EntityWither entitywither = (EntityWither) EntityTypes.WITHER.create(world, EntitySpawnReason.TRIGGERED); if (entitywither != null) { - BlockPumpkinCarved.clearPatternBlocks(world, shapedetector_shapedetectorcollection); @@ -39,7 +39,7 @@ Iterator iterator = world.getEntitiesOfClass(EntityPlayer.class, entitywither.getBoundingBox().inflate(50.0D)).iterator(); while (iterator.hasNext()) { -@@ -82,7 +93,7 @@ +@@ -83,7 +94,7 @@ CriterionTriggers.SUMMONED_ENTITY.trigger(entityplayer, (Entity) entitywither); } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/CeilingHangingSignBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/CeilingHangingSignBlock.patch index 99ec4d1385..66912c1a49 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/CeilingHangingSignBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/CeilingHangingSignBlock.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/CeilingHangingSignBlock.java +++ b/net/minecraft/world/level/block/CeilingHangingSignBlock.java -@@ -158,6 +158,6 @@ +@@ -159,6 +159,6 @@ @Nullable @Override public BlockEntityTicker getTicker(World world, IBlockData iblockdata, TileEntityTypes tileentitytypes) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/CrafterBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/CrafterBlock.patch index d0ada7204f..fb402f84db 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/CrafterBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/CrafterBlock.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/CrafterBlock.java +++ b/net/minecraft/world/level/block/CrafterBlock.java -@@ -39,6 +39,15 @@ +@@ -40,6 +40,15 @@ import net.minecraft.world.phys.MovingObjectPositionBlock; import net.minecraft.world.phys.Vec3D; @@ -16,7 +16,7 @@ public class CrafterBlock extends BlockTileEntity { public static final MapCodec CODEC = simpleCodec(CrafterBlock::new); -@@ -188,6 +197,13 @@ +@@ -189,6 +198,13 @@ RecipeHolder recipeholder = (RecipeHolder) optional.get(); ItemStack itemstack = ((RecipeCrafting) recipeholder.value()).assemble(craftinginput, worldserver.registryAccess()); @@ -30,7 +30,7 @@ if (itemstack.isEmpty()) { worldserver.levelEvent(1050, blockposition, 0); } else { -@@ -226,7 +242,25 @@ +@@ -227,7 +243,25 @@ ItemStack itemstack1 = itemstack.copy(); if (iinventory != null && (iinventory instanceof CrafterBlockEntity || itemstack.getCount() > iinventory.getMaxStackSize(itemstack))) { @@ -56,7 +56,7 @@ ItemStack itemstack2 = itemstack1.copyWithCount(1); ItemStack itemstack3 = TileEntityHopper.addItem(crafterblockentity, iinventory, itemstack2, enumdirection.getOpposite()); -@@ -237,7 +271,25 @@ +@@ -238,7 +272,25 @@ itemstack1.shrink(1); } } else if (iinventory != null) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/DecoratedPotBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/DecoratedPotBlock.patch index 4d646728df..a10aad16dd 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/DecoratedPotBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/DecoratedPotBlock.patch @@ -1,14 +1,14 @@ --- a/net/minecraft/world/level/block/DecoratedPotBlock.java +++ b/net/minecraft/world/level/block/DecoratedPotBlock.java -@@ -239,6 +239,11 @@ - BlockPosition blockposition = movingobjectpositionblock.getBlockPos(); +@@ -240,6 +240,11 @@ - if (!world.isClientSide && iprojectile.mayInteract(world, blockposition) && iprojectile.mayBreak(world)) { -+ // CraftBukkit start - call EntityChangeBlockEvent -+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, this.getFluidState(iblockdata).createLegacyBlock())) { -+ return; -+ } -+ // CraftBukkit end - world.setBlock(blockposition, (IBlockData) iblockdata.setValue(DecoratedPotBlock.CRACKED, true), 4); - world.destroyBlock(blockposition, true, iprojectile); - } + if (world instanceof WorldServer worldserver) { + if (iprojectile.mayInteract(worldserver, blockposition) && iprojectile.mayBreak(worldserver)) { ++ // CraftBukkit start - call EntityChangeBlockEvent ++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, this.getFluidState(iblockdata).createLegacyBlock())) { ++ return; ++ } ++ // CraftBukkit end + world.setBlock(blockposition, (IBlockData) iblockdata.setValue(DecoratedPotBlock.CRACKED, true), 4); + world.destroyBlock(blockposition, true, iprojectile); + } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/LayeredCauldronBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/LayeredCauldronBlock.patch index 9c5e2bf82e..f2eebd0606 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/LayeredCauldronBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/LayeredCauldronBlock.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/LayeredCauldronBlock.java +++ b/net/minecraft/world/level/block/LayeredCauldronBlock.java -@@ -17,6 +17,12 @@ +@@ -18,6 +18,12 @@ import net.minecraft.world.level.material.FluidType; import net.minecraft.world.level.material.FluidTypes; @@ -13,24 +13,37 @@ public class LayeredCauldronBlock extends AbstractCauldronBlock { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { -@@ -62,10 +68,14 @@ - @Override +@@ -64,39 +70,67 @@ protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { - if (!world.isClientSide && entity.isOnFire() && this.isEntityInsideContent(iblockdata, blockposition, entity)) { -- entity.clearFire(); -+ // CraftBukkit start - if (entity.mayInteract(world, blockposition)) { -- this.handleEntityOnFireInside(iblockdata, world, blockposition); -+ if (!lowerFillLevel(iblockdata, world, blockposition, entity, CauldronLevelChangeEvent.ChangeReason.EXTINGUISH)) { -+ return; -+ } + if (world instanceof WorldServer worldserver) { + if (entity.isOnFire() && this.isEntityInsideContent(iblockdata, blockposition, entity)) { +- entity.clearFire(); ++ // CraftBukkit start - moved down ++ // entity.clearFire(); + if (entity.mayInteract(worldserver, blockposition)) { +- this.handleEntityOnFireInside(iblockdata, world, blockposition); ++ if (this.handleEntityOnFireInside(iblockdata, world, blockposition, entity)) { ++ entity.clearFire(); ++ } ++ // CraftBukkit end + } } -+ entity.clearFire(); -+ // CraftBukkit end } } -@@ -80,20 +90,42 @@ + +- private void handleEntityOnFireInside(IBlockData iblockdata, World world, BlockPosition blockposition) { ++ // CraftBukkit start ++ private boolean handleEntityOnFireInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { + if (this.precipitationType == BiomeBase.Precipitation.SNOW) { +- lowerFillLevel((IBlockData) Blocks.WATER_CAULDRON.defaultBlockState().setValue(LayeredCauldronBlock.LEVEL, (Integer) iblockdata.getValue(LayeredCauldronBlock.LEVEL)), world, blockposition); ++ return lowerFillLevel((IBlockData) Blocks.WATER_CAULDRON.defaultBlockState().setValue(LayeredCauldronBlock.LEVEL, (Integer) iblockdata.getValue(LayeredCauldronBlock.LEVEL)), world, blockposition, entity, CauldronLevelChangeEvent.ChangeReason.EXTINGUISH); + } else { +- lowerFillLevel(iblockdata, world, blockposition); ++ return lowerFillLevel(iblockdata, world, blockposition, entity, CauldronLevelChangeEvent.ChangeReason.EXTINGUISH); ++ // CraftBukkit end + } + } public static void lowerFillLevel(IBlockData iblockdata, World world, BlockPosition blockposition) { @@ -77,7 +90,7 @@ } } -@@ -112,8 +144,11 @@ +@@ -115,8 +149,11 @@ if (!this.isFull(iblockdata)) { IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(LayeredCauldronBlock.LEVEL, (Integer) iblockdata.getValue(LayeredCauldronBlock.LEVEL) + 1); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/LightningRodBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/LightningRodBlock.patch index f0665b99fe..8a36902c04 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/LightningRodBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/LightningRodBlock.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/level/block/LightningRodBlock.java +++ b/net/minecraft/world/level/block/LightningRodBlock.java -@@ -22,6 +22,11 @@ - import net.minecraft.world.level.material.FluidType; +@@ -24,6 +24,11 @@ import net.minecraft.world.level.material.FluidTypes; + import net.minecraft.world.level.redstone.ExperimentalRedstoneUtils; +// CraftBukkit start +import org.bukkit.craftbukkit.block.CraftBlock; @@ -12,7 +12,7 @@ public class LightningRodBlock extends RodBlock implements IBlockWaterlogged { public static final MapCodec CODEC = simpleCodec(LightningRodBlock::new); -@@ -74,6 +79,18 @@ +@@ -76,6 +81,18 @@ } public void onLightningStrike(IBlockData iblockdata, World world, BlockPosition blockposition) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/PointedDripstoneBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/PointedDripstoneBlock.patch index a90a954ad8..0ce0a1738f 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/PointedDripstoneBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/PointedDripstoneBlock.patch @@ -1,18 +1,18 @@ --- a/net/minecraft/world/level/block/PointedDripstoneBlock.java +++ b/net/minecraft/world/level/block/PointedDripstoneBlock.java -@@ -133,6 +133,11 @@ - BlockPosition blockposition = movingobjectpositionblock.getBlockPos(); +@@ -136,6 +136,11 @@ + WorldServer worldserver = (WorldServer) world; - if (iprojectile.mayInteract(world, blockposition) && iprojectile.mayBreak(world) && iprojectile instanceof EntityThrownTrident && iprojectile.getDeltaMovement().length() > 0.6D) { -+ // CraftBukkit start -+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, Blocks.AIR.defaultBlockState())) { -+ return; -+ } -+ // CraftBukkit end - world.destroyBlock(blockposition, true); + if (iprojectile.mayInteract(worldserver, blockposition) && iprojectile.mayBreak(worldserver) && iprojectile instanceof EntityThrownTrident && iprojectile.getDeltaMovement().length() > 0.6D) { ++ // CraftBukkit start ++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(iprojectile, blockposition, Blocks.AIR.defaultBlockState())) { ++ return; ++ } ++ // CraftBukkit end + world.destroyBlock(blockposition, true); + } } - -@@ -142,7 +147,7 @@ +@@ -146,7 +151,7 @@ @Override public void fallOn(World world, IBlockData iblockdata, BlockPosition blockposition, Entity entity, float f) { if (iblockdata.getValue(PointedDripstoneBlock.TIP_DIRECTION) == EnumDirection.UP && iblockdata.getValue(PointedDripstoneBlock.THICKNESS) == DripstoneThickness.TIP) { @@ -21,7 +21,7 @@ } else { super.fallOn(world, iblockdata, blockposition, entity, f); } -@@ -387,15 +392,15 @@ +@@ -391,15 +396,15 @@ if (isUnmergedTipWithDirection(iblockdata, enumdirection.getOpposite())) { createMergedTips(iblockdata, worldserver, blockposition1); } else if (iblockdata.isAir() || iblockdata.is(Blocks.WATER)) { @@ -40,7 +40,7 @@ } private static void createMergedTips(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) { -@@ -410,8 +415,8 @@ +@@ -414,8 +419,8 @@ blockposition1 = blockposition.below(); } @@ -51,7 +51,7 @@ } public static void spawnDripParticle(World world, BlockPosition blockposition, IBlockData iblockdata) { -@@ -444,7 +449,7 @@ +@@ -448,7 +453,7 @@ return (BlockPosition) findBlockVertical(generatoraccess, blockposition, enumdirection.getAxisDirection(), bipredicate, (iblockdata1) -> { return isTip(iblockdata1, flag); @@ -60,7 +60,7 @@ } } -@@ -560,7 +565,7 @@ +@@ -564,7 +569,7 @@ return canDripThrough(world, blockposition1, iblockdata); }; @@ -69,7 +69,7 @@ } @Nullable -@@ -569,7 +574,7 @@ +@@ -573,7 +578,7 @@ return canDripThrough(world, blockposition1, iblockdata); }; diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/PowderSnowBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/PowderSnowBlock.patch index 3897c7400e..54416b3685 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/PowderSnowBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/PowderSnowBlock.patch @@ -1,13 +1,13 @@ --- a/net/minecraft/world/level/block/PowderSnowBlock.java +++ b/net/minecraft/world/level/block/PowderSnowBlock.java -@@ -77,7 +77,12 @@ +@@ -73,7 +73,12 @@ entity.setIsInPowderSnow(true); - if (!world.isClientSide) { -- if (entity.isOnFire() && (world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) || entity instanceof EntityHuman) && entity.mayInteract(world, blockposition)) { + if (world instanceof WorldServer worldserver) { +- if (entity.isOnFire() && (worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) || entity instanceof EntityHuman) && entity.mayInteract(worldserver, blockposition)) { + // CraftBukkit start -+ if (entity.isOnFire() && entity.mayInteract(world, blockposition)) { -+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR.defaultBlockState(), !(world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) || entity instanceof EntityHuman))) { ++ if (entity.isOnFire() && entity.mayInteract(worldserver, blockposition)) { ++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR.defaultBlockState(), !(worldserver.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) || entity instanceof EntityHuman))) { + return; + } + // CraftBukkit end diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/SculkSensorBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/SculkSensorBlock.patch index 98237a7c53..d66c4e3ea6 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/SculkSensorBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/SculkSensorBlock.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/SculkSensorBlock.java +++ b/net/minecraft/world/level/block/SculkSensorBlock.java -@@ -43,6 +43,11 @@ +@@ -44,6 +44,11 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -12,7 +12,7 @@ public class SculkSensorBlock extends BlockTileEntity implements IBlockWaterlogged { public static final MapCodec CODEC = simpleCodec(SculkSensorBlock::new); -@@ -103,6 +108,18 @@ +@@ -104,6 +109,18 @@ @Override public void stepOn(World world, BlockPosition blockposition, IBlockData iblockdata, Entity entity) { if (!world.isClientSide() && canActivate(iblockdata) && entity.getType() != EntityTypes.WARDEN) { @@ -31,7 +31,7 @@ TileEntity tileentity = world.getBlockEntity(blockposition); if (tileentity instanceof SculkSensorBlockEntity) { -@@ -206,6 +223,15 @@ +@@ -207,6 +224,15 @@ } public static void deactivate(World world, BlockPosition blockposition, IBlockData iblockdata) { @@ -47,7 +47,7 @@ world.setBlock(blockposition, (IBlockData) ((IBlockData) iblockdata.setValue(SculkSensorBlock.PHASE, SculkSensorPhase.COOLDOWN)).setValue(SculkSensorBlock.POWER, 0), 3); world.scheduleTick(blockposition, iblockdata.getBlock(), 10); updateNeighbours(world, blockposition, iblockdata); -@@ -217,6 +243,15 @@ +@@ -218,6 +244,15 @@ } public void activate(@Nullable Entity entity, World world, BlockPosition blockposition, IBlockData iblockdata, int i, int j) { @@ -63,7 +63,7 @@ world.setBlock(blockposition, (IBlockData) ((IBlockData) iblockdata.setValue(SculkSensorBlock.PHASE, SculkSensorPhase.ACTIVE)).setValue(SculkSensorBlock.POWER, i), 3); world.scheduleTick(blockposition, iblockdata.getBlock(), this.getActiveTicks()); updateNeighbours(world, blockposition, iblockdata); -@@ -297,9 +332,16 @@ +@@ -298,9 +333,16 @@ @Override protected void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) { super.spawnAfterBreak(iblockdata, worldserver, blockposition, itemstack, flag); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/SculkShriekerBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/SculkShriekerBlock.patch index 02dbc8945d..41ec5aee1c 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/SculkShriekerBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/SculkShriekerBlock.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/SculkShriekerBlock.java +++ b/net/minecraft/world/level/block/SculkShriekerBlock.java -@@ -62,6 +62,7 @@ +@@ -63,6 +63,7 @@ EntityPlayer entityplayer = SculkShriekerBlockEntity.tryGetPlayer(entity); if (entityplayer != null) { @@ -8,7 +8,7 @@ worldserver.getBlockEntity(blockposition, TileEntityTypes.SCULK_SHRIEKER).ifPresent((sculkshriekerblockentity) -> { sculkshriekerblockentity.tryShriek(worldserver, entityplayer); }); -@@ -144,10 +145,17 @@ +@@ -145,10 +146,17 @@ @Override protected void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) { super.spawnAfterBreak(iblockdata, worldserver, blockposition, itemstack, flag); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/SculkSpreader.patch b/paper-server/nms-patches/net/minecraft/world/level/block/SculkSpreader.patch index f7fdd0b5b4..0a02154d46 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/SculkSpreader.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/SculkSpreader.patch @@ -15,7 +15,7 @@ public class SculkSpreader { public static final int MAX_GROWTH_RATE_RADIUS = 24; -@@ -56,6 +64,7 @@ +@@ -57,6 +65,7 @@ private final int additionalDecayRate; private List cursors = new ArrayList(); private static final Logger LOGGER = LogUtils.getLogger(); @@ -23,7 +23,7 @@ public SculkSpreader(boolean flag, TagKey tagkey, int i, int j, int k, int l) { this.isWorldGeneration = flag; -@@ -110,7 +119,7 @@ +@@ -111,7 +120,7 @@ public void load(NBTTagCompound nbttagcompound) { if (nbttagcompound.contains("cursors", 9)) { this.cursors.clear(); @@ -32,7 +32,7 @@ Logger logger = SculkSpreader.LOGGER; Objects.requireNonNull(logger); -@@ -125,7 +134,7 @@ +@@ -126,7 +135,7 @@ } public void save(NBTTagCompound nbttagcompound) { @@ -41,7 +41,7 @@ Logger logger = SculkSpreader.LOGGER; Objects.requireNonNull(logger); -@@ -146,6 +155,19 @@ +@@ -147,6 +156,19 @@ private void addCursor(SculkSpreader.a sculkspreader_a) { if (this.cursors.size() < 32) { @@ -61,7 +61,7 @@ this.cursors.add(sculkspreader_a); } } -@@ -241,7 +263,7 @@ +@@ -244,7 +266,7 @@ this.charge = i; this.decayDelay = j; this.updateDelay = k; diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/SculkVeinBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/SculkVeinBlock.patch index 73b7016900..f9aa1f541a 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/SculkVeinBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/SculkVeinBlock.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/SculkVeinBlock.java +++ b/net/minecraft/world/level/block/SculkVeinBlock.java -@@ -108,10 +108,11 @@ +@@ -110,10 +110,11 @@ @Override public int attemptUseCharge(SculkSpreader.a sculkspreader_a, GeneratorAccess generatoraccess, BlockPosition blockposition, RandomSource randomsource, SculkSpreader sculkspreader, boolean flag) { @@ -14,7 +14,7 @@ IBlockData iblockdata = generatoraccess.getBlockState(blockposition); TagKey tagkey = sculkspreader.replaceableBlocks(); Iterator iterator = EnumDirection.allShuffled(randomsource).iterator(); -@@ -126,7 +127,11 @@ +@@ -128,7 +129,11 @@ if (iblockdata1.is(tagkey)) { IBlockData iblockdata2 = Blocks.SCULK.defaultBlockState(); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/WallHangingSignBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/WallHangingSignBlock.patch index 7e8844060f..4fad718c22 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/WallHangingSignBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/WallHangingSignBlock.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/WallHangingSignBlock.java +++ b/net/minecraft/world/level/block/WallHangingSignBlock.java -@@ -183,6 +183,6 @@ +@@ -179,6 +179,6 @@ @Nullable @Override public BlockEntityTicker getTicker(World world, IBlockData iblockdata, TileEntityTypes tileentitytypes) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/BrushableBlockEntity.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/BrushableBlockEntity.patch index 95cc62d72f..3b5b8926a2 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/BrushableBlockEntity.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/BrushableBlockEntity.patch @@ -13,15 +13,15 @@ public class BrushableBlockEntity extends TileEntity { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -156,7 +162,10 @@ - EntityItem entityitem = new EntityItem(this.level, d3, d4, d5, this.item.split(this.level.random.nextInt(21) + 10)); +@@ -151,7 +157,10 @@ + EntityItem entityitem = new EntityItem(worldserver, d3, d4, d5, this.item.split(worldserver.random.nextInt(21) + 10)); - entityitem.setDeltaMovement(Vec3D.ZERO); -- this.level.addFreshEntity(entityitem); -+ // CraftBukkit start -+ org.bukkit.block.Block bblock = CraftBlock.at(this.level, this.worldPosition); -+ CraftEventFactory.handleBlockDropItemEvent(bblock, bblock.getState(), (EntityPlayer) entityhuman, Arrays.asList(entityitem)); -+ // CraftBukkit end - this.item = ItemStack.EMPTY; - } + entityitem.setDeltaMovement(Vec3D.ZERO); +- worldserver.addFreshEntity(entityitem); ++ // CraftBukkit start ++ org.bukkit.block.Block bblock = CraftBlock.at(this.level, this.worldPosition); ++ CraftEventFactory.handleBlockDropItemEvent(bblock, bblock.getState(), (EntityPlayer) entityhuman, Arrays.asList(entityitem)); ++ // CraftBukkit end + this.item = ItemStack.EMPTY; + } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntity.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntity.patch index d1005ab871..28bcd24247 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntity.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntity.patch @@ -49,7 +49,7 @@ return nbttagcompound; } -@@ -276,12 +300,18 @@ +@@ -277,12 +301,18 @@ } public final void applyComponents(DataComponentMap datacomponentmap, DataComponentPatch datacomponentpatch) { @@ -69,7 +69,7 @@ @Nullable @Override public T get(DataComponentType datacomponenttype) { -@@ -299,6 +329,10 @@ +@@ -300,6 +330,10 @@ DataComponentPatch datacomponentpatch1 = datacomponentpatch.forget(set::contains); this.components = datacomponentpatch1.split().added(); @@ -80,7 +80,7 @@ } protected void collectImplicitComponents(DataComponentMap.a datacomponentmap_a) {} -@@ -333,6 +367,15 @@ +@@ -334,6 +368,15 @@ } } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBeacon.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBeacon.patch index 2ffc59b373..fa7669c3fd 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBeacon.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBeacon.patch @@ -120,8 +120,8 @@ if (nbttagcompound.contains(s, 8)) { MinecraftKey minecraftkey = MinecraftKey.tryParse(nbttagcompound.getString(s)); -- return minecraftkey == null ? null : (Holder) BuiltInRegistries.MOB_EFFECT.getHolder(minecraftkey).map(TileEntityBeacon::filterEffect).orElse((Object) null); -+ return minecraftkey == null ? null : (Holder) BuiltInRegistries.MOB_EFFECT.getHolder(minecraftkey).orElse(null); // CraftBukkit - persist manually set non-default beacon effects (SPIGOT-3598) +- return minecraftkey == null ? null : (Holder) BuiltInRegistries.MOB_EFFECT.get(minecraftkey).map(TileEntityBeacon::filterEffect).orElse((Object) null); ++ return minecraftkey == null ? null : (Holder) BuiltInRegistries.MOB_EFFECT.get(minecraftkey).orElse(null); // CraftBukkit - persist manually set non-default beacon effects (SPIGOT-3598) } else { return null; } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBeehive.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBeehive.patch index ca50649d6b..8874e64496 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBeehive.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBeehive.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityBeehive.java +++ b/net/minecraft/world/level/block/entity/TileEntityBeehive.java -@@ -42,6 +42,10 @@ +@@ -43,6 +43,10 @@ import net.minecraft.world.level.gameevent.GameEvent; import org.slf4j.Logger; @@ -11,7 +11,7 @@ public class TileEntityBeehive extends TileEntity { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -55,6 +59,7 @@ +@@ -56,6 +60,7 @@ private List stored = Lists.newArrayList(); @Nullable public BlockPosition savedFlowerPos; @@ -19,7 +19,7 @@ public TileEntityBeehive(BlockPosition blockposition, IBlockData iblockdata) { super(TileEntityTypes.BEEHIVE, blockposition, iblockdata); -@@ -94,7 +99,7 @@ +@@ -95,7 +100,7 @@ } public boolean isFull() { @@ -28,7 +28,7 @@ } public void emptyAllLivingFromHive(@Nullable EntityHuman entityhuman, IBlockData iblockdata, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus) { -@@ -111,7 +116,7 @@ +@@ -112,7 +117,7 @@ if (entityhuman.position().distanceToSqr(entity.position()) <= 16.0D) { if (!this.isSedated()) { @@ -37,7 +37,7 @@ } else { entitybee.setStayOutOfHiveCountdown(400); } -@@ -123,10 +128,16 @@ +@@ -124,10 +129,16 @@ } private List releaseAllOccupants(IBlockData iblockdata, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus) { @@ -55,7 +55,7 @@ }); if (!list.isEmpty()) { super.setChanged(); -@@ -150,7 +161,19 @@ +@@ -151,7 +162,19 @@ } public void addOccupant(Entity entity) { @@ -76,7 +76,7 @@ entity.stopRiding(); entity.ejectPassengers(); this.storeBee(TileEntityBeehive.c.of(entity)); -@@ -169,7 +192,7 @@ +@@ -170,7 +193,7 @@ this.level.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(entity, this.getBlockState())); } @@ -85,22 +85,22 @@ super.setChanged(); } } -@@ -179,7 +202,13 @@ +@@ -180,7 +203,13 @@ } private static boolean releaseOccupant(World world, BlockPosition blockposition, IBlockData iblockdata, TileEntityBeehive.c tileentitybeehive_c, @Nullable List list, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus, @Nullable BlockPosition blockposition1) { -- if ((world.isNight() || world.isRaining()) && tileentitybeehive_releasestatus != TileEntityBeehive.ReleaseStatus.EMERGENCY) { +- if (EntityBee.isNightOrRaining(world) && tileentitybeehive_releasestatus != TileEntityBeehive.ReleaseStatus.EMERGENCY) { + // CraftBukkit start - This allows us to bypass the night/rain/emergency check + return releaseOccupant(world, blockposition, iblockdata, tileentitybeehive_c, list, tileentitybeehive_releasestatus, blockposition1, false); + } + + private static boolean releaseOccupant(World world, BlockPosition blockposition, IBlockData iblockdata, TileEntityBeehive.c tileentitybeehive_c, @Nullable List list, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus, @Nullable BlockPosition blockposition1, boolean force) { -+ if (!force && (world.isNight() || world.isRaining()) && tileentitybeehive_releasestatus != TileEntityBeehive.ReleaseStatus.EMERGENCY) { ++ if (!force && EntityBee.isNightOrRaining(world) && tileentitybeehive_releasestatus != TileEntityBeehive.ReleaseStatus.EMERGENCY) { + // CraftBukkit end return false; } else { EnumDirection enumdirection = (EnumDirection) iblockdata.getValue(BlockBeehive.FACING); -@@ -192,6 +221,18 @@ +@@ -193,6 +222,18 @@ Entity entity = tileentitybeehive_c.createEntity(world, blockposition); if (entity != null) { @@ -119,7 +119,7 @@ if (entity instanceof EntityBee) { EntityBee entitybee = (EntityBee) entity; -@@ -222,6 +263,7 @@ +@@ -223,6 +264,7 @@ list.add(entitybee); } @@ -127,7 +127,7 @@ float f = entity.getBbWidth(); double d0 = flag ? 0.0D : 0.55D + (double) (f / 2.0F); double d1 = (double) blockposition.getX() + 0.5D + d0 * (double) enumdirection.getStepX(); -@@ -229,11 +271,12 @@ +@@ -230,11 +272,12 @@ double d3 = (double) blockposition.getZ() + 0.5D + d0 * (double) enumdirection.getStepZ(); entity.moveTo(d1, d2, d3, entity.getYRot(), entity.getXRot()); @@ -141,7 +141,7 @@ } else { return false; } -@@ -258,6 +301,10 @@ +@@ -259,6 +302,10 @@ if (releaseOccupant(world, blockposition, iblockdata, tileentitybeehive_hivebee.toOccupant(), (List) null, tileentitybeehive_releasestatus, blockposition1)) { flag = true; iterator.remove(); @@ -152,7 +152,7 @@ } } } -@@ -284,7 +331,7 @@ +@@ -285,7 +332,7 @@ @Override protected void loadAdditional(NBTTagCompound nbttagcompound, HolderLookup.a holderlookup_a) { super.loadAdditional(nbttagcompound, holderlookup_a); @@ -161,7 +161,7 @@ if (nbttagcompound.contains("bees")) { TileEntityBeehive.c.LIST_CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("bees")).resultOrPartial((s) -> { TileEntityBeehive.LOGGER.error("Failed to parse bees: '{}'", s); -@@ -293,7 +340,12 @@ +@@ -294,7 +341,12 @@ }); } @@ -175,7 +175,7 @@ } @Override -@@ -303,13 +355,14 @@ +@@ -304,13 +356,14 @@ if (this.hasSavedFlowerPos()) { nbttagcompound.put("flower_pos", GameProfileSerializer.writeBlockPos(this.savedFlowerPos)); } @@ -191,7 +191,7 @@ List list = (List) tileentity_b.getOrDefault(DataComponents.BEES, List.of()); list.forEach(this::storeBee); -@@ -350,7 +403,7 @@ +@@ -351,7 +404,7 @@ NBTTagCompound nbttagcompound = new NBTTagCompound(); entity.save(nbttagcompound); @@ -200,7 +200,7 @@ Objects.requireNonNull(nbttagcompound); list.forEach(nbttagcompound::remove); -@@ -369,7 +422,7 @@ +@@ -370,7 +423,7 @@ @Nullable public Entity createEntity(World world, BlockPosition blockposition) { NBTTagCompound nbttagcompound = this.entityData.copyTag(); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBrewingStand.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBrewingStand.patch index 6a15e04531..002abf3405 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBrewingStand.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBrewingStand.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityBrewingStand.java +++ b/net/minecraft/world/level/block/entity/TileEntityBrewingStand.java -@@ -23,6 +23,20 @@ +@@ -24,6 +24,20 @@ import net.minecraft.world.level.block.BlockBrewingStand; import net.minecraft.world.level.block.state.IBlockData; @@ -21,7 +21,7 @@ public class TileEntityBrewingStand extends TileEntityContainer implements IWorldInventory { private static final int INGREDIENT_SLOT = 3; -@@ -40,6 +54,36 @@ +@@ -41,6 +55,36 @@ private Item ingredient; public int fuel; protected final IContainerProperties dataAccess; @@ -58,10 +58,10 @@ public TileEntityBrewingStand(BlockPosition blockposition, IBlockData iblockdata) { super(TileEntityTypes.BREWING_STAND, blockposition, iblockdata); -@@ -106,8 +150,19 @@ +@@ -107,8 +151,19 @@ ItemStack itemstack = (ItemStack) tileentitybrewingstand.items.get(4); - if (tileentitybrewingstand.fuel <= 0 && itemstack.is(Items.BLAZE_POWDER)) { + if (tileentitybrewingstand.fuel <= 0 && itemstack.is(TagsItem.BREWING_FUEL)) { - tileentitybrewingstand.fuel = 20; - itemstack.shrink(1); + // CraftBukkit start @@ -80,7 +80,7 @@ setChanged(world, blockposition, iblockdata); } -@@ -115,12 +170,17 @@ +@@ -116,12 +171,17 @@ boolean flag1 = tileentitybrewingstand.brewTime > 0; ItemStack itemstack1 = (ItemStack) tileentitybrewingstand.items.get(3); @@ -101,7 +101,7 @@ } else if (!flag || !itemstack1.is(tileentitybrewingstand.ingredient)) { tileentitybrewingstand.brewTime = 0; } -@@ -128,7 +188,11 @@ +@@ -129,7 +189,11 @@ setChanged(world, blockposition, iblockdata); } else if (flag && tileentitybrewingstand.fuel > 0) { --tileentitybrewingstand.fuel; @@ -114,7 +114,7 @@ tileentitybrewingstand.ingredient = itemstack1.getItem(); setChanged(world, blockposition, iblockdata); } -@@ -184,12 +248,34 @@ +@@ -185,12 +249,34 @@ } } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityCampfire.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityCampfire.patch index 5fe4b5dc0e..ec68f7a9b3 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityCampfire.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityCampfire.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityCampfire.java +++ b/net/minecraft/world/level/block/entity/TileEntityCampfire.java -@@ -30,6 +30,14 @@ +@@ -31,6 +31,14 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.gameevent.GameEvent; @@ -15,16 +15,16 @@ public class TileEntityCampfire extends TileEntity implements Clearable { private static final int BURN_COOL_SPEED = 2; -@@ -64,6 +72,20 @@ +@@ -63,6 +71,20 @@ }).orElse(itemstack); - if (itemstack1.isItemEnabled(world.enabledFeatures())) { + if (itemstack1.isItemEnabled(worldserver.enabledFeatures())) { + // CraftBukkit start - fire BlockCookEvent + CraftItemStack source = CraftItemStack.asCraftMirror(itemstack); + org.bukkit.inventory.ItemStack result = CraftItemStack.asBukkitCopy(itemstack1); + -+ BlockCookEvent blockCookEvent = new BlockCookEvent(CraftBlock.at(world, blockposition), source, result); -+ world.getCraftServer().getPluginManager().callEvent(blockCookEvent); ++ BlockCookEvent blockCookEvent = new BlockCookEvent(CraftBlock.at(worldserver, blockposition), source, result); ++ worldserver.getCraftServer().getPluginManager().callEvent(blockCookEvent); + + if (blockCookEvent.isCancelled()) { + return; @@ -33,19 +33,19 @@ + result = blockCookEvent.getResult(); + itemstack1 = CraftItemStack.asNMSCopy(result); + // CraftBukkit end - InventoryUtils.dropItemStack(world, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), itemstack1); + InventoryUtils.dropItemStack(worldserver, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), itemstack1); tileentitycampfire.items.set(i, ItemStack.EMPTY); - world.sendBlockUpdated(blockposition, iblockdata, iblockdata, 3); -@@ -176,7 +198,11 @@ - ItemStack itemstack1 = (ItemStack) this.items.get(j); + worldserver.sendBlockUpdated(blockposition, iblockdata, iblockdata, 3); +@@ -177,7 +199,11 @@ + return false; + } - if (itemstack1.isEmpty()) { -- this.cookingTime[j] = i; +- this.cookingTime[i] = ((RecipeCampfire) ((RecipeHolder) optional.get()).value()).cookingTime(); + // CraftBukkit start -+ CampfireStartEvent event = new CampfireStartEvent(CraftBlock.at(this.level,this.worldPosition), CraftItemStack.asCraftMirror(itemstack), (CampfireRecipe) getCookableRecipe(itemstack).get().toBukkitRecipe()); ++ CampfireStartEvent event = new CampfireStartEvent(CraftBlock.at(this.level,this.worldPosition), CraftItemStack.asCraftMirror(itemstack), (CampfireRecipe) optional.get().toBukkitRecipe()); + this.level.getCraftServer().getPluginManager().callEvent(event); -+ this.cookingTime[j] = event.getTotalCookTime(); // i -> event.getTotalCookTime() ++ this.cookingTime[i] = event.getTotalCookTime(); // i -> event.getTotalCookTime() + // CraftBukkit end - this.cookingProgress[j] = 0; - this.items.set(j, itemstack.consumeAndReturn(1, entityliving)); - this.level.gameEvent((Holder) GameEvent.BLOCK_CHANGE, this.getBlockPos(), GameEvent.a.of(entityliving, this.getBlockState())); + this.cookingProgress[i] = 0; + this.items.set(i, itemstack.consumeAndReturn(1, entityliving)); + worldserver.gameEvent((Holder) GameEvent.BLOCK_CHANGE, this.getBlockPos(), GameEvent.a.of(entityliving, this.getBlockState())); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityConduit.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityConduit.patch index 775a44667d..033b3ba2d9 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityConduit.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityConduit.patch @@ -1,6 +1,17 @@ --- a/net/minecraft/world/level/block/entity/TileEntityConduit.java +++ b/net/minecraft/world/level/block/entity/TileEntityConduit.java -@@ -187,8 +187,20 @@ +@@ -28,6 +28,10 @@ + import net.minecraft.world.phys.AxisAlignedBB; + import net.minecraft.world.phys.Vec3D; + ++// CraftBukkit start ++import net.minecraft.server.level.WorldServer; ++// CraftBukkit end ++ + public class TileEntityConduit extends TileEntity { + + private static final int BLOCK_REFRESH_RATE = 2; +@@ -187,8 +191,20 @@ } private static void applyEffects(World world, BlockPosition blockposition, List list) { @@ -21,7 +32,7 @@ int k = blockposition.getX(); int l = blockposition.getY(); int i1 = blockposition.getZ(); -@@ -202,7 +214,7 @@ +@@ -202,7 +218,7 @@ EntityHuman entityhuman = (EntityHuman) iterator.next(); if (blockposition.closerThan(entityhuman.blockPosition(), (double) j) && entityhuman.isInWaterOrRain()) { @@ -30,7 +41,7 @@ } } -@@ -210,6 +222,12 @@ +@@ -210,6 +226,12 @@ } private static void updateDestroyTarget(World world, BlockPosition blockposition, IBlockData iblockdata, List list, TileEntityConduit tileentityconduit) { @@ -43,7 +54,7 @@ EntityLiving entityliving = tileentityconduit.destroyTarget; int i = list.size(); -@@ -230,9 +248,12 @@ +@@ -230,9 +252,12 @@ tileentityconduit.destroyTarget = null; } @@ -52,7 +63,7 @@ - tileentityconduit.destroyTarget.hurt(world.damageSources().magic(), 4.0F); + // CraftBukkit start + if (damageTarget && tileentityconduit.destroyTarget != null) { -+ if (tileentityconduit.destroyTarget.hurt(world.damageSources().magic().directBlock(world, blockposition), 4.0F)) { ++ if (tileentityconduit.destroyTarget.hurtServer((WorldServer) world, world.damageSources().magic().directBlock(world, blockposition), 4.0F)) { + world.playSound(null, tileentityconduit.destroyTarget.getX(), tileentityconduit.destroyTarget.getY(), tileentityconduit.destroyTarget.getZ(), SoundEffects.CONDUIT_ATTACK_TARGET, SoundCategory.BLOCKS, 1.0F, 1.0F); + } + // CraftBukkit end diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityContainer.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityContainer.patch index 0d23226a1b..cf27b35391 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityContainer.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityContainer.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/level/block/entity/TileEntityContainer.java +++ b/net/minecraft/world/level/block/entity/TileEntityContainer.java @@ -178,4 +178,12 @@ - nbttagcompound.remove("Lock"); + nbttagcompound.remove("lock"); nbttagcompound.remove("Items"); } + diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityFurnace.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityFurnace.patch index fd6b054cb4..be3111dcd8 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityFurnace.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityFurnace.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityFurnace.java +++ b/net/minecraft/world/level/block/entity/TileEntityFurnace.java -@@ -48,6 +48,21 @@ +@@ -42,6 +42,21 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.phys.Vec3D; @@ -22,19 +22,14 @@ public abstract class TileEntityFurnace extends TileEntityContainer implements IWorldInventory, RecipeCraftingHolder, AutoRecipeOutput { protected static final int SLOT_INPUT = 0; -@@ -118,7 +133,7 @@ +@@ -112,9 +127,39 @@ } }; - this.recipesUsed = new Object2IntOpenHashMap(); + this.recipesUsed = new Reference2IntOpenHashMap(); - this.quickCheck = CraftingManager.createCheck(recipes); + this.quickCheck = CraftingManager.createCheck((Recipes) recipes); // CraftBukkit - decompile error // Eclipse fail - } - - public static void invalidateCache() { -@@ -197,6 +212,40 @@ - } - } - ++ } ++ + // CraftBukkit start - add fields and methods + private int maxStack = MAX_STACK; + public List transaction = new java.util.ArrayList(); @@ -53,8 +48,8 @@ + + public List getViewers() { + return transaction; -+ } -+ + } + + @Override + public int getMaxStackSize() { + return maxStack; @@ -63,34 +58,30 @@ + public void setMaxStackSize(int size) { + maxStack = size; + } -+ -+ public Object2IntOpenHashMap getRecipesUsed() { -+ return this.recipesUsed; // PAIL private -> public -+ } + // CraftBukkit end + - private static boolean isNeverAFurnaceFuel(Item item) { - return item.builtInRegistryHolder().is(TagsItem.NON_FLAMMABLE_WOOD); + private boolean isLit() { + return this.litTime > 0; } -@@ -286,7 +335,7 @@ +@@ -180,7 +225,7 @@ RecipeHolder recipeholder; if (flag2) { -- recipeholder = (RecipeHolder) tileentityfurnace.quickCheck.getRecipeFor(new SingleRecipeInput(itemstack1), world).orElse((Object) null); -+ recipeholder = (RecipeHolder) tileentityfurnace.quickCheck.getRecipeFor(new SingleRecipeInput(itemstack1), world).orElse(null); // CraftBukkit - decompile error +- recipeholder = (RecipeHolder) tileentityfurnace.quickCheck.getRecipeFor(singlerecipeinput, worldserver).orElse((Object) null); ++ recipeholder = (RecipeHolder) tileentityfurnace.quickCheck.getRecipeFor(singlerecipeinput, worldserver).orElse(null); // CraftBukkit - decompile error } else { recipeholder = null; } -@@ -294,9 +343,20 @@ +@@ -188,9 +233,20 @@ int i = tileentityfurnace.getMaxStackSize(); - if (!tileentityfurnace.isLit() && canBurn(world.registryAccess(), recipeholder, tileentityfurnace.items, i)) { -- tileentityfurnace.litTime = tileentityfurnace.getBurnDuration(itemstack); + if (!tileentityfurnace.isLit() && canBurn(worldserver.registryAccess(), recipeholder, singlerecipeinput, tileentityfurnace.items, i)) { +- tileentityfurnace.litTime = tileentityfurnace.getBurnDuration(worldserver.fuelValues(), itemstack); + // CraftBukkit start + CraftItemStack fuel = CraftItemStack.asCraftMirror(itemstack); + -+ FurnaceBurnEvent furnaceBurnEvent = new FurnaceBurnEvent(CraftBlock.at(world, blockposition), fuel, tileentityfurnace.getBurnDuration(itemstack)); -+ world.getCraftServer().getPluginManager().callEvent(furnaceBurnEvent); ++ FurnaceBurnEvent furnaceBurnEvent = new FurnaceBurnEvent(CraftBlock.at(worldserver, blockposition), fuel, tileentityfurnace.getBurnDuration(worldserver.fuelValues(), itemstack)); ++ worldserver.getCraftServer().getPluginManager().callEvent(furnaceBurnEvent); + + if (furnaceBurnEvent.isCancelled()) { + return; @@ -104,17 +95,17 @@ flag1 = true; if (flag3) { Item item = itemstack.getItem(); -@@ -312,11 +372,23 @@ +@@ -204,11 +260,23 @@ } - if (tileentityfurnace.isLit() && canBurn(world.registryAccess(), recipeholder, tileentityfurnace.items, i)) { + if (tileentityfurnace.isLit() && canBurn(worldserver.registryAccess(), recipeholder, singlerecipeinput, tileentityfurnace.items, i)) { + // CraftBukkit start + if (recipeholder != null && tileentityfurnace.cookingProgress == 0) { + CraftItemStack source = CraftItemStack.asCraftMirror(tileentityfurnace.items.get(0)); + CookingRecipe recipe = (CookingRecipe) recipeholder.toBukkitRecipe(); + -+ FurnaceStartSmeltEvent event = new FurnaceStartSmeltEvent(CraftBlock.at(world, blockposition), source, recipe); -+ world.getCraftServer().getPluginManager().callEvent(event); ++ FurnaceStartSmeltEvent event = new FurnaceStartSmeltEvent(CraftBlock.at(worldserver, blockposition), source, recipe); ++ worldserver.getCraftServer().getPluginManager().callEvent(event); + + tileentityfurnace.cookingTotalTime = event.getTotalCookTime(); + } @@ -123,21 +114,21 @@ ++tileentityfurnace.cookingProgress; if (tileentityfurnace.cookingProgress == tileentityfurnace.cookingTotalTime) { tileentityfurnace.cookingProgress = 0; - tileentityfurnace.cookingTotalTime = getTotalCookTime(world, tileentityfurnace); -- if (burn(world.registryAccess(), recipeholder, tileentityfurnace.items, i)) { -+ if (burn(tileentityfurnace.level, tileentityfurnace.worldPosition, world.registryAccess(), recipeholder, tileentityfurnace.items, i)) { // CraftBukkit + tileentityfurnace.cookingTotalTime = getTotalCookTime(worldserver, tileentityfurnace); +- if (burn(worldserver.registryAccess(), recipeholder, singlerecipeinput, tileentityfurnace.items, i)) { ++ if (burn(tileentityfurnace.level, tileentityfurnace.worldPosition, worldserver.registryAccess(), recipeholder, singlerecipeinput, tileentityfurnace.items, i)) { // CraftBukkit tileentityfurnace.setRecipeUsed(recipeholder); } -@@ -355,17 +427,44 @@ +@@ -247,17 +315,44 @@ } } -- private static boolean burn(IRegistryCustom iregistrycustom, @Nullable RecipeHolder recipeholder, NonNullList nonnulllist, int i) { -+ private static boolean burn(World world, BlockPosition blockposition, IRegistryCustom iregistrycustom, @Nullable RecipeHolder recipeholder, NonNullList nonnulllist, int i) { // CraftBukkit - if (recipeholder != null && canBurn(iregistrycustom, recipeholder, nonnulllist, i)) { +- private static boolean burn(IRegistryCustom iregistrycustom, @Nullable RecipeHolder recipeholder, SingleRecipeInput singlerecipeinput, NonNullList nonnulllist, int i) { ++ private static boolean burn(World world, BlockPosition blockposition, IRegistryCustom iregistrycustom, @Nullable RecipeHolder recipeholder, SingleRecipeInput singlerecipeinput, NonNullList nonnulllist, int i) { // CraftBukkit + if (recipeholder != null && canBurn(iregistrycustom, recipeholder, singlerecipeinput, nonnulllist, i)) { ItemStack itemstack = (ItemStack) nonnulllist.get(0); - ItemStack itemstack1 = recipeholder.value().getResultItem(iregistrycustom); + ItemStack itemstack1 = ((RecipeCooking) recipeholder.value()).assemble(singlerecipeinput, iregistrycustom); ItemStack itemstack2 = (ItemStack) nonnulllist.get(2); + // CraftBukkit start - fire FurnaceSmeltEvent @@ -175,15 +166,15 @@ if (itemstack.is(Blocks.WET_SPONGE.asItem()) && !((ItemStack) nonnulllist.get(1)).isEmpty() && ((ItemStack) nonnulllist.get(1)).is(Items.BUCKET)) { nonnulllist.set(1, new ItemStack(Items.WATER_BUCKET)); -@@ -389,6 +488,7 @@ +@@ -275,6 +370,7 @@ } - private static int getTotalCookTime(World world, TileEntityFurnace tileentityfurnace) { -+ if (world == null) return 200; // CraftBukkit - SPIGOT-4302 + private static int getTotalCookTime(WorldServer worldserver, TileEntityFurnace tileentityfurnace) { ++ if (worldserver == null) return 200; // CraftBukkit - SPIGOT-4302 SingleRecipeInput singlerecipeinput = new SingleRecipeInput(tileentityfurnace.getItem(0)); - return (Integer) tileentityfurnace.quickCheck.getRecipeFor(singlerecipeinput, world).map((recipeholder) -> { -@@ -477,8 +577,8 @@ + return (Integer) tileentityfurnace.quickCheck.getRecipeFor(singlerecipeinput, worldserver).map((recipeholder) -> { +@@ -365,8 +461,8 @@ @Override public void awardUsedRecipes(EntityHuman entityhuman, List list) {} @@ -194,7 +185,7 @@ entityplayer.awardRecipes(list); Iterator iterator = list.iterator(); -@@ -495,6 +595,12 @@ +@@ -383,22 +479,28 @@ } public List> getRecipesToAwardAndPopExperience(WorldServer worldserver, Vec3D vec3d) { @@ -205,14 +196,16 @@ + public List> getRecipesToAwardAndPopExperience(WorldServer worldserver, Vec3D vec3d, BlockPosition blockposition, EntityPlayer entityplayer, ItemStack itemstack, int amount) { + // CraftBukkit end List> list = Lists.newArrayList(); - ObjectIterator objectiterator = this.recipesUsed.object2IntEntrySet().iterator(); + ObjectIterator objectiterator = this.recipesUsed.reference2IntEntrySet().iterator(); -@@ -503,14 +609,14 @@ + while (objectiterator.hasNext()) { + Entry>> entry = (Entry) objectiterator.next(); - worldserver.getRecipeManager().byKey((MinecraftKey) entry.getKey()).ifPresent((recipeholder) -> { +- worldserver.recipeAccess().byKey((ResourceKey) entry.getKey()).ifPresent((recipeholder) -> { ++ worldserver.recipeAccess().byKey(entry.getKey()).ifPresent((recipeholder) -> { // CraftBukkit - decompile error list.add(recipeholder); -- createExperience(worldserver, vec3d, entry.getIntValue(), ((RecipeCooking) recipeholder.value()).getExperience()); -+ createExperience(worldserver, vec3d, entry.getIntValue(), ((RecipeCooking) recipeholder.value()).getExperience(), blockposition, entityplayer, itemstack, amount); // CraftBukkit +- createExperience(worldserver, vec3d, entry.getIntValue(), ((RecipeCooking) recipeholder.value()).experience()); ++ createExperience(worldserver, vec3d, entry.getIntValue(), ((RecipeCooking) recipeholder.value()).experience(), blockposition, entityplayer, itemstack, amount); // CraftBukkit }); } @@ -224,7 +217,7 @@ int j = MathHelper.floor((float) i * f); float f1 = MathHelper.frac((float) i * f); -@@ -518,6 +624,17 @@ +@@ -406,6 +508,17 @@ ++j; } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityJukeBox.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityJukeBox.patch index b3d264bf5a..cd40785808 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityJukeBox.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityJukeBox.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityJukeBox.java +++ b/net/minecraft/world/level/block/entity/TileEntityJukeBox.java -@@ -20,12 +20,56 @@ +@@ -19,12 +19,56 @@ import net.minecraft.world.phys.Vec3D; import net.minecraft.world.ticks.ContainerSingleItem; @@ -12,7 +12,7 @@ +import org.bukkit.entity.HumanEntity; +// CraftBukkit end + - public class TileEntityJukeBox extends TileEntity implements Clearable, ContainerSingleItem.a { + public class TileEntityJukeBox extends TileEntity implements ContainerSingleItem.a { public static final String SONG_ITEM_TAG_ID = "RecordItem"; public static final String TICKS_SINCE_SONG_STARTED_TAG_ID = "ticks_since_song_started"; @@ -57,7 +57,7 @@ public TileEntityJukeBox(BlockPosition blockposition, IBlockData iblockdata) { super(TileEntityTypes.JUKEBOX, blockposition, iblockdata); -@@ -134,7 +178,7 @@ +@@ -133,7 +177,7 @@ @Override public int getMaxStackSize() { @@ -66,7 +66,7 @@ } @Override -@@ -153,12 +197,17 @@ +@@ -152,12 +196,17 @@ } @VisibleForTesting diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityLectern.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityLectern.patch index de231effe2..9ac9529fb7 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityLectern.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityLectern.patch @@ -4,7 +4,6 @@ import net.minecraft.world.phys.Vec2F; import net.minecraft.world.phys.Vec3D; --public class TileEntityLectern extends TileEntity implements Clearable, ITileInventory { +// CraftBukkit start +import java.util.ArrayList; +import java.util.Arrays; @@ -17,7 +16,7 @@ +import org.bukkit.inventory.InventoryHolder; +// CraftBukkit end + -+public class TileEntityLectern extends TileEntity implements Clearable, ITileInventory, ICommandListener { // CraftBukkit - ICommandListener + public class TileEntityLectern extends TileEntity implements Clearable, ITileInventory { public static final int DATA_PAGE = 0; public static final int NUM_DATA = 1; @@ -107,50 +106,53 @@ } } -@@ -187,6 +255,32 @@ +@@ -189,6 +257,35 @@ return itemstack; } + // CraftBukkit start -+ @Override -+ public void sendSystemMessage(IChatBaseComponent ichatbasecomponent) { -+ } ++ private final ICommandListener commandSource = new ICommandListener() { + -+ @Override -+ public org.bukkit.command.CommandSender getBukkitSender(CommandListenerWrapper wrapper) { -+ return wrapper.getEntity() != null ? wrapper.getEntity().getBukkitSender(wrapper) : new org.bukkit.craftbukkit.command.CraftBlockCommandSender(wrapper, this); -+ } ++ @Override ++ public void sendSystemMessage(IChatBaseComponent ichatbasecomponent) { ++ } + -+ @Override -+ public boolean acceptsSuccess() { -+ return false; -+ } ++ @Override ++ public org.bukkit.command.CommandSender getBukkitSender(CommandListenerWrapper wrapper) { ++ return wrapper.getEntity() != null ? wrapper.getEntity().getBukkitEntity() : new org.bukkit.craftbukkit.command.CraftBlockCommandSender(wrapper, TileEntityLectern.this); ++ } + -+ @Override -+ public boolean acceptsFailure() { -+ return false; -+ } ++ @Override ++ public boolean acceptsSuccess() { ++ return false; ++ } + -+ @Override -+ public boolean shouldInformAdmins() { -+ return false; -+ } ++ @Override ++ public boolean acceptsFailure() { ++ return false; ++ } + ++ @Override ++ public boolean shouldInformAdmins() { ++ return false; ++ } ++ }; + // CraftBukkit end - private CommandListenerWrapper createCommandSourceStack(@Nullable EntityHuman entityhuman) { ++ + private CommandListenerWrapper createCommandSourceStack(@Nullable EntityHuman entityhuman, WorldServer worldserver) { String s; Object object; -@@ -201,7 +295,8 @@ +@@ -203,7 +300,8 @@ Vec3D vec3d = Vec3D.atCenterOf(this.worldPosition); -- return new CommandListenerWrapper(ICommandListener.NULL, vec3d, Vec2F.ZERO, (WorldServer) this.level, 2, s, (IChatBaseComponent) object, this.level.getServer(), entityhuman); -+ // CraftBukkit - this -+ return new CommandListenerWrapper(this, vec3d, Vec2F.ZERO, (WorldServer) this.level, 2, s, (IChatBaseComponent) object, this.level.getServer(), entityhuman); +- return new CommandListenerWrapper(ICommandListener.NULL, vec3d, Vec2F.ZERO, worldserver, 2, s, (IChatBaseComponent) object, worldserver.getServer(), entityhuman); ++ // CraftBukkit - commandSource ++ return new CommandListenerWrapper(commandSource, vec3d, Vec2F.ZERO, worldserver, 2, s, (IChatBaseComponent) object, worldserver.getServer(), entityhuman); } @Override -@@ -239,7 +334,7 @@ +@@ -241,7 +339,7 @@ @Override public Container createMenu(int i, PlayerInventory playerinventory, EntityHuman entityhuman) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntitySign.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntitySign.patch index 933fece896..4c2e6b7344 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntitySign.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntitySign.patch @@ -1,10 +1,9 @@ --- a/net/minecraft/world/level/block/entity/TileEntitySign.java +++ b/net/minecraft/world/level/block/entity/TileEntitySign.java -@@ -36,7 +36,17 @@ +@@ -36,6 +36,16 @@ import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; --public class TileEntitySign extends TileEntity { +// CraftBukkit start +import net.minecraft.nbt.NBTBase; +import net.minecraft.server.level.EntityPlayer; @@ -15,10 +14,9 @@ +import org.bukkit.event.block.SignChangeEvent; +// CraftBukkit end + -+public class TileEntitySign extends TileEntity implements ICommandListener { // CraftBukkit - implements + public class TileEntitySign extends TileEntity { private static final Logger LOGGER = LogUtils.getLogger(); - private static final int MAX_TEXT_LINE_WIDTH = 90; @@ -101,7 +111,7 @@ protected void saveAdditional(NBTTagCompound nbttagcompound, HolderLookup.a holderlookup_a) { super.saveAdditional(nbttagcompound, holderlookup_a); @@ -92,34 +90,37 @@ return signtext; } -@@ -250,11 +285,37 @@ +@@ -250,11 +285,40 @@ return flag1; } - private static CommandListenerWrapper createCommandSourceStack(@Nullable EntityHuman entityhuman, World world, BlockPosition blockposition) { + // CraftBukkit start -+ @Override -+ public void sendSystemMessage(IChatBaseComponent ichatbasecomponent) {} ++ private final ICommandListener commandSource = new ICommandListener() { + -+ @Override -+ public org.bukkit.command.CommandSender getBukkitSender(CommandListenerWrapper wrapper) { -+ return wrapper.getEntity() != null ? wrapper.getEntity().getBukkitSender(wrapper) : new org.bukkit.craftbukkit.command.CraftBlockCommandSender(wrapper, this); -+ } ++ @Override ++ public void sendSystemMessage(IChatBaseComponent ichatbasecomponent) {} + -+ @Override -+ public boolean acceptsSuccess() { -+ return false; -+ } ++ @Override ++ public org.bukkit.command.CommandSender getBukkitSender(CommandListenerWrapper wrapper) { ++ return wrapper.getEntity() != null ? wrapper.getEntity().getBukkitEntity() : new org.bukkit.craftbukkit.command.CraftBlockCommandSender(wrapper, TileEntitySign.this); ++ } + -+ @Override -+ public boolean acceptsFailure() { -+ return false; -+ } ++ @Override ++ public boolean acceptsSuccess() { ++ return false; ++ } + -+ @Override -+ public boolean shouldInformAdmins() { -+ return false; -+ } ++ @Override ++ public boolean acceptsFailure() { ++ return false; ++ } ++ ++ @Override ++ public boolean shouldInformAdmins() { ++ return false; ++ } ++ }; + + private CommandListenerWrapper createCommandSourceStack(@Nullable EntityHuman entityhuman, World world, BlockPosition blockposition) { + // CraftBukkit end @@ -127,12 +128,12 @@ Object object = entityhuman == null ? IChatBaseComponent.literal("Sign") : entityhuman.getDisplayName(); - return new CommandListenerWrapper(ICommandListener.NULL, Vec3D.atCenterOf(blockposition), Vec2F.ZERO, (WorldServer) world, 2, s, (IChatBaseComponent) object, world.getServer(), entityhuman); -+ // CraftBukkit - this -+ return new CommandListenerWrapper(this, Vec3D.atCenterOf(blockposition), Vec2F.ZERO, (WorldServer) world, 2, s, (IChatBaseComponent) object, world.getServer(), entityhuman); ++ // CraftBukkit - commandSource ++ return new CommandListenerWrapper(commandSource, Vec3D.atCenterOf(blockposition), Vec2F.ZERO, (WorldServer) world, 2, s, (IChatBaseComponent) object, world.getServer(), entityhuman); } @Override -@@ -278,12 +339,17 @@ +@@ -278,12 +342,17 @@ @Nullable public UUID getPlayerWhoMayEdit() { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerData.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerData.patch index 518244325e..d9d12313b6 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerData.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerData.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerData.java +++ b/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerData.java -@@ -206,7 +206,7 @@ +@@ -211,7 +211,7 @@ } public void resetAfterBecomingOminous(TrialSpawner trialspawner, WorldServer worldserver) { @@ -9,8 +9,8 @@ Objects.requireNonNull(worldserver); stream.map(worldserver::getEntity).forEach((entity) -> { -@@ -218,7 +218,7 @@ - entityinsentient.dropPreservedEquipment(); +@@ -223,7 +223,7 @@ + entityinsentient.dropPreservedEquipment(worldserver); } - entity.remove(Entity.RemovalReason.DISCARDED); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.patch index 8cf5a218b5..a44d02ca05 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java +++ b/net/minecraft/world/level/block/entity/vault/VaultBlockEntity.java -@@ -47,6 +47,13 @@ +@@ -46,6 +46,13 @@ import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; @@ -14,7 +14,7 @@ public class VaultBlockEntity extends TileEntity { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -97,18 +104,18 @@ +@@ -96,18 +103,18 @@ dataresult = VaultServerData.CODEC.parse(dynamicops, nbttagcompound.get("server_data")); logger = VaultBlockEntity.LOGGER; Objects.requireNonNull(logger); @@ -36,7 +36,7 @@ this.config = vaultconfig; }); } -@@ -117,11 +124,11 @@ +@@ -116,11 +123,11 @@ dataresult = VaultSharedData.CODEC.parse(dynamicops, nbttagcompound.get("shared_data")); logger = VaultBlockEntity.LOGGER; Objects.requireNonNull(logger); @@ -50,7 +50,7 @@ } } -@@ -321,6 +328,14 @@ +@@ -320,6 +327,14 @@ if (!list.isEmpty()) { entityhuman.awardStat(StatisticList.ITEM_USED.get(itemstack.getItem())); itemstack.consume(vaultconfig.keyItem().getCount(), entityhuman); @@ -65,7 +65,7 @@ unlock(worldserver, iblockdata, blockposition, vaultconfig, vaultserverdata, vaultshareddata, list); vaultserverdata.addToRewardedPlayers(entityhuman); vaultshareddata.updateConnectedPlayersWithinRange(worldserver, blockposition, vaultserverdata, vaultconfig, vaultconfig.deactivationRange()); -@@ -342,6 +357,14 @@ +@@ -341,6 +356,14 @@ vaultshareddata.setDisplayItem(ItemStack.EMPTY); } else { ItemStack itemstack = getRandomDisplayItemFromLootTable(worldserver, blockposition, (ResourceKey) vaultconfig.overrideLootTableToDisplay().orElse(vaultconfig.lootTable())); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/grower/WorldGenTreeProvider.patch b/paper-server/nms-patches/net/minecraft/world/level/block/grower/WorldGenTreeProvider.patch index 61f547d2a9..0a01485870 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/grower/WorldGenTreeProvider.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/grower/WorldGenTreeProvider.patch @@ -13,7 +13,7 @@ public final class WorldGenTreeProvider { private static final Map GROWERS = new Object2ObjectArrayMap(); -@@ -74,21 +80,22 @@ +@@ -75,21 +81,22 @@ } } @@ -31,20 +31,20 @@ ResourceKey> resourcekey = this.getConfiguredMegaFeature(randomsource); if (resourcekey != null) { -- Holder> holder = (Holder) worldserver.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).getHolder(resourcekey).orElse((Object) null); -+ Holder> holder = (Holder) worldserver.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).getHolder(resourcekey).orElse(null); // CraftBukkit - decompile error +- Holder> holder = (Holder) worldserver.registryAccess().lookupOrThrow(Registries.CONFIGURED_FEATURE).get(resourcekey).orElse((Object) null); ++ Holder> holder = (Holder) worldserver.registryAccess().lookupOrThrow(Registries.CONFIGURED_FEATURE).get(resourcekey).orElse(null); // CraftBukkit - decompile error if (holder != null) { + setTreeType(holder); // CraftBukkit for (int i = 0; i >= -1; --i) { for (int j = 0; j >= -1; --j) { if (isTwoByTwoSapling(iblockdata, worldserver, blockposition, i, j)) { -@@ -119,11 +126,12 @@ +@@ -120,11 +127,12 @@ if (resourcekey1 == null) { return false; } else { -- Holder> holder1 = (Holder) worldserver.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).getHolder(resourcekey1).orElse((Object) null); -+ Holder> holder1 = (Holder) worldserver.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).getHolder(resourcekey1).orElse(null); // CraftBukkit - decompile error +- Holder> holder1 = (Holder) worldserver.registryAccess().lookupOrThrow(Registries.CONFIGURED_FEATURE).get(resourcekey1).orElse((Object) null); ++ Holder> holder1 = (Holder) worldserver.registryAccess().lookupOrThrow(Registries.CONFIGURED_FEATURE).get(resourcekey1).orElse(null); // CraftBukkit - decompile error if (holder1 == null) { return false; @@ -53,7 +53,7 @@ WorldGenFeatureConfigured worldgenfeatureconfigured1 = (WorldGenFeatureConfigured) holder1.value(); IBlockData iblockdata2 = worldserver.getFluidState(blockposition).createLegacyBlock(); -@@ -164,11 +172,62 @@ +@@ -165,11 +173,62 @@ return true; } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/piston/BlockPiston.patch b/paper-server/nms-patches/net/minecraft/world/level/block/piston/BlockPiston.patch index ca610a7bc5..7b2160e5ec 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/piston/BlockPiston.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/piston/BlockPiston.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/piston/BlockPiston.java +++ b/net/minecraft/world/level/block/piston/BlockPiston.java -@@ -42,6 +42,14 @@ +@@ -45,6 +45,14 @@ import net.minecraft.world.phys.shapes.VoxelShapeCollision; import net.minecraft.world.phys.shapes.VoxelShapes; @@ -15,7 +15,7 @@ public class BlockPiston extends BlockDirectional { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { -@@ -152,6 +160,18 @@ +@@ -155,6 +163,18 @@ } } @@ -34,7 +34,7 @@ world.blockEvent(blockposition, this, b0, enumdirection.get3DDataValue()); } -@@ -332,6 +352,48 @@ +@@ -335,6 +355,48 @@ IBlockData[] aiblockdata = new IBlockData[list.size() + list2.size()]; EnumDirection enumdirection1 = flag ? enumdirection : enumdirection.getOpposite(); int i = 0; diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/state/BlockBase.patch b/paper-server/nms-patches/net/minecraft/world/level/block/state/BlockBase.patch index 9b91c97270..bc6135f2f2 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/state/BlockBase.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/state/BlockBase.patch @@ -1,17 +1,18 @@ --- a/net/minecraft/world/level/block/state/BlockBase.java +++ b/net/minecraft/world/level/block/state/BlockBase.java -@@ -81,6 +81,10 @@ +@@ -84,6 +84,11 @@ import net.minecraft.world.phys.shapes.VoxelShapeCollision; import net.minecraft.world.phys.shapes.VoxelShapes; +// CraftBukkit start +import net.minecraft.world.item.context.ItemActionContext; ++import net.minecraft.world.level.ServerExplosion; +// CraftBukkit end + public abstract class BlockBase implements FeatureElement { protected static final EnumDirection[] UPDATE_SHAPE_ORDER = new EnumDirection[]{EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH, EnumDirection.DOWN, EnumDirection.UP}; -@@ -156,6 +160,12 @@ +@@ -158,6 +163,12 @@ protected void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {} @@ -24,20 +25,20 @@ protected void onRemove(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) { if (iblockdata.hasBlockEntity() && !iblockdata.is(iblockdata1.getBlock())) { world.removeBlockEntity(blockposition); -@@ -173,8 +183,10 @@ - TileEntity tileentity = iblockdata.hasBlockEntity() ? world.getBlockEntity(blockposition) : null; +@@ -174,8 +185,10 @@ + TileEntity tileentity = iblockdata.hasBlockEntity() ? worldserver.getBlockEntity(blockposition) : null; LootParams.a lootparams_a = (new LootParams.a(worldserver)).withParameter(LootContextParameters.ORIGIN, Vec3D.atCenterOf(blockposition)).withParameter(LootContextParameters.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParameters.BLOCK_ENTITY, tileentity).withOptionalParameter(LootContextParameters.THIS_ENTITY, explosion.getDirectSourceEntity()); - if (explosion.getBlockInteraction() == Explosion.Effect.DESTROY_WITH_DECAY) { - lootparams_a.withParameter(LootContextParameters.EXPLOSION_RADIUS, explosion.radius()); + // CraftBukkit start - add yield -+ if (explosion.yield < 1.0F) { -+ lootparams_a.withParameter(LootContextParameters.EXPLOSION_RADIUS, 1.0F / explosion.yield); ++ if (explosion instanceof ServerExplosion serverExplosion && serverExplosion.yield < 1.0F) { ++ lootparams_a.withParameter(LootContextParameters.EXPLOSION_RADIUS, 1.0F / serverExplosion.yield); + // CraftBukkit end } iblockdata.spawnAfterBreak(worldserver, blockposition, ItemStack.EMPTY, flag); -@@ -1066,7 +1078,13 @@ +@@ -1121,7 +1134,13 @@ } public void onPlace(World world, BlockPosition blockposition, IBlockData iblockdata, boolean flag) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/border/WorldBorder.patch b/paper-server/nms-patches/net/minecraft/world/level/border/WorldBorder.patch index e3d8ca0c46..732d68c4d2 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/border/WorldBorder.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/border/WorldBorder.patch @@ -8,7 +8,7 @@ public WorldBorder() {} -@@ -181,6 +182,7 @@ +@@ -189,6 +190,7 @@ } public void addListener(IWorldBorderListener iworldborderlistener) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/chunk/Chunk.patch b/paper-server/nms-patches/net/minecraft/world/level/chunk/Chunk.patch index 4df6567e6e..245064ce44 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/chunk/Chunk.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/chunk/Chunk.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/chunk/Chunk.java +++ b/net/minecraft/world/level/chunk/Chunk.java -@@ -77,7 +77,7 @@ +@@ -78,7 +78,7 @@ }; private final Map tickersInLevel; public boolean loaded; @@ -9,16 +9,16 @@ @Nullable private Supplier fullStatus; @Nullable -@@ -93,7 +93,7 @@ - public Chunk(World world, ChunkCoordIntPair chunkcoordintpair, ChunkConverter chunkconverter, LevelChunkTicks levelchunkticks, LevelChunkTicks levelchunkticks1, long i, @Nullable ChunkSection[] achunksection, @Nullable Chunk.c chunk_c, @Nullable BlendingData blendingdata) { - super(chunkcoordintpair, chunkconverter, world, world.registryAccess().registryOrThrow(Registries.BIOME), i, achunksection, blendingdata); +@@ -97,7 +97,7 @@ this.tickersInLevel = Maps.newHashMap(); + this.unsavedListener = (chunkcoordintpair1) -> { + }; - this.level = world; + this.level = (WorldServer) world; // CraftBukkit - type this.gameEventListenerRegistrySections = new Int2ObjectOpenHashMap(); HeightMap.Type[] aheightmap_type = HeightMap.Type.values(); int j = aheightmap_type.length; -@@ -111,6 +111,11 @@ +@@ -115,6 +115,11 @@ this.fluidTicks = levelchunkticks1; } @@ -30,18 +30,18 @@ public Chunk(WorldServer worldserver, ProtoChunk protochunk, @Nullable Chunk.c chunk_c) { this(worldserver, protochunk.getPos(), protochunk.getUpgradeData(), protochunk.unpackBlockTicks(), protochunk.unpackFluidTicks(), protochunk.getInhabitedTime(), protochunk.getSections(), chunk_c, protochunk.getBlendingData()); Iterator iterator = protochunk.getBlockEntities().values().iterator(); -@@ -142,6 +147,10 @@ +@@ -146,6 +151,10 @@ this.skyLightSources = protochunk.skyLightSources; this.setLightCorrect(protochunk.isLightCorrect()); - this.unsaved = true; + this.markUnsaved(); + this.needsDecoration = true; // CraftBukkit + // CraftBukkit start + this.persistentDataContainer = protochunk.persistentDataContainer; // SPIGOT-6814: copy PDC to account for 1.17 to 1.18 chunk upgrading. + // CraftBukkit end } - @Override -@@ -244,9 +253,16 @@ + public void setUnsavedListener(Chunk.e chunk_e) { +@@ -267,9 +276,16 @@ } } @@ -58,7 +58,7 @@ int i = blockposition.getY(); ChunkSection chunksection = this.getSection(this.getSectionIndex(i)); boolean flag1 = chunksection.hasOnlyAir(); -@@ -295,7 +311,8 @@ +@@ -319,7 +335,8 @@ if (!chunksection.getBlockState(j, k, l).is(block)) { return null; } else { @@ -68,7 +68,7 @@ iblockdata.onPlace(this.level, blockposition, iblockdata1, flag); } -@@ -345,7 +362,12 @@ +@@ -370,7 +387,12 @@ @Nullable public TileEntity getBlockEntity(BlockPosition blockposition, Chunk.EnumTileEntityState chunk_enumtileentitystate) { @@ -82,7 +82,7 @@ if (tileentity == null) { NBTTagCompound nbttagcompound = (NBTTagCompound) this.pendingBlockEntities.remove(blockposition); -@@ -417,6 +439,7 @@ +@@ -442,6 +464,7 @@ if (!iblockdata.hasBlockEntity()) { Chunk.LOGGER.warn("Trying to set block entity {} at position {}, but state {} does not allow it", new Object[]{tileentity, blockposition, iblockdata}); @@ -90,7 +90,7 @@ } else { IBlockData iblockdata1 = tileentity.getBlockState(); -@@ -470,6 +493,12 @@ +@@ -495,6 +518,12 @@ if (this.isInLevel()) { TileEntity tileentity = (TileEntity) this.blockEntities.remove(blockposition); @@ -103,7 +103,7 @@ if (tileentity != null) { World world = this.level; -@@ -523,6 +552,57 @@ +@@ -548,6 +577,57 @@ } @@ -161,7 +161,7 @@ public boolean isEmpty() { return false; } -@@ -718,7 +798,7 @@ +@@ -745,7 +825,7 @@ private void updateBlockEntityTicker(T t0) { IBlockData iblockdata = t0.getBlockState(); @@ -170,7 +170,7 @@ if (blockentityticker == null) { this.removeBlockEntityTicker(t0.getBlockPos()); -@@ -803,7 +883,7 @@ +@@ -836,7 +916,7 @@ private boolean loggedInvalidBlockState; a(final TileEntity tileentity, final BlockEntityTicker blockentityticker) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkSection.patch b/paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkSection.patch index 2978daa498..72784c4b5e 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkSection.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkSection.patch @@ -1,20 +1,24 @@ --- a/net/minecraft/world/level/chunk/ChunkSection.java +++ b/net/minecraft/world/level/chunk/ChunkSection.java -@@ -23,9 +23,11 @@ +@@ -23,7 +23,7 @@ private short tickingBlockCount; private short tickingFluidCount; private final DataPaletteBlock states; - private PalettedContainerRO> biomes; -+ // CraftBukkit start - read/write -+ private DataPaletteBlock> biomes; ++ private DataPaletteBlock> biomes; // CraftBukkit - read/write + + private ChunkSection(ChunkSection chunksection) { + this.nonEmptyBlockCount = chunksection.nonEmptyBlockCount; +@@ -33,7 +33,7 @@ + this.biomes = chunksection.biomes.copy(); + } - public ChunkSection(DataPaletteBlock datapaletteblock, PalettedContainerRO> palettedcontainerro) { -+ public ChunkSection(DataPaletteBlock datapaletteblock, DataPaletteBlock> palettedcontainerro) { -+ // CraftBukkit end ++ public ChunkSection(DataPaletteBlock datapaletteblock, DataPaletteBlock> palettedcontainerro) { // CraftBukkit - read/write this.states = datapaletteblock; this.biomes = palettedcontainerro; this.recalcBlockCounts(); -@@ -188,6 +190,12 @@ +@@ -196,6 +196,12 @@ return (Holder) this.biomes.get(i, j, k); } diff --git a/paper-server/nms-patches/net/minecraft/world/level/chunk/IChunkAccess.patch b/paper-server/nms-patches/net/minecraft/world/level/chunk/IChunkAccess.patch index 715e6fbb9e..b8d23e44e8 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/chunk/IChunkAccess.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/chunk/IChunkAccess.patch @@ -24,11 +24,15 @@ private static void replaceMissingSections(IRegistry iregistry, ChunkSection[] achunksection) { for (int i = 0; i < achunksection.length; ++i) { -@@ -270,10 +279,11 @@ - - public void setUnsaved(boolean flag) { - this.unsaved = flag; -+ if (!flag) this.persistentDataContainer.dirty(false); // CraftBukkit - SPIGOT-6814: chunk was saved, pdc is no longer dirty +@@ -275,6 +284,7 @@ + public boolean tryMarkSaved() { + if (this.unsaved) { + this.unsaved = false; ++ this.persistentDataContainer.dirty(false); // CraftBukkit - SPIGOT-6814: chunk was saved, pdc is no longer dirty + return true; + } else { + return false; +@@ -282,7 +292,7 @@ } public boolean isUnsaved() { @@ -37,14 +41,14 @@ } public abstract ChunkStatus getPersistedStatus(); -@@ -449,6 +459,27 @@ +@@ -458,6 +468,27 @@ } } + // CraftBukkit start + public void setBiome(int i, int j, int k, Holder biome) { + try { -+ int l = QuartPos.fromBlock(this.getMinBuildHeight()); ++ int l = QuartPos.fromBlock(this.getMinY()); + int i1 = l + QuartPos.fromBlock(this.getHeight()) - 1; + int j1 = MathHelper.clamp(j, l, i1); + int k1 = this.getSectionIndex(QuartPos.toBlock(j1)); diff --git a/paper-server/nms-patches/net/minecraft/world/level/chunk/status/ChunkStatusTasks.patch b/paper-server/nms-patches/net/minecraft/world/level/chunk/status/ChunkStatusTasks.patch index e8d99c2b75..520b5c69c5 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/chunk/status/ChunkStatusTasks.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/chunk/status/ChunkStatusTasks.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java +++ b/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java -@@ -38,7 +38,7 @@ +@@ -36,7 +36,7 @@ static CompletableFuture generateStructureStarts(WorldGenContext worldgencontext, ChunkStep chunkstep, StaticCache2D staticcache2d, IChunkAccess ichunkaccess) { WorldServer worldserver = worldgencontext.level(); @@ -9,20 +9,16 @@ worldgencontext.generator().createStructures(worldserver.registryAccess(), worldserver.getChunkSource().getGeneratorState(), worldserver.structureManager(), ichunkaccess, worldgencontext.structureManager()); } -@@ -177,7 +177,21 @@ +@@ -170,7 +170,17 @@ private static void postLoadProtoChunk(WorldServer worldserver, List list) { if (!list.isEmpty()) { -- worldserver.addWorldGenChunkEntities(EntityTypes.loadEntitiesRecursive(list, worldserver)); +- worldserver.addWorldGenChunkEntities(EntityTypes.loadEntitiesRecursive(list, worldserver, EntitySpawnReason.LOAD)); + // CraftBukkit start - these are spawned serialized (DefinedStructure) and we don't call an add event below at the moment due to ordering complexities -+ worldserver.addWorldGenChunkEntities(EntityTypes.loadEntitiesRecursive(list, worldserver).filter((entity) -> { ++ worldserver.addWorldGenChunkEntities(EntityTypes.loadEntitiesRecursive(list, worldserver, EntitySpawnReason.LOAD).filter((entity) -> { + boolean needsRemoval = false; + net.minecraft.server.dedicated.DedicatedServer server = worldserver.getCraftServer().getServer(); -+ if (!server.areNpcsEnabled() && entity instanceof net.minecraft.world.entity.npc.NPC) { -+ entity.discard(null); // CraftBukkit - add Bukkit remove cause -+ needsRemoval = true; -+ } -+ if (!server.isSpawningAnimals() && (entity instanceof net.minecraft.world.entity.animal.EntityAnimal || entity instanceof net.minecraft.world.entity.animal.EntityWaterAnimal)) { ++ if (!worldserver.getChunkSource().spawnFriendlies && (entity instanceof net.minecraft.world.entity.animal.EntityAnimal || entity instanceof net.minecraft.world.entity.animal.EntityWaterAnimal)) { + entity.discard(null); // CraftBukkit - add Bukkit remove cause + needsRemoval = true; + } diff --git a/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/ChunkRegionLoader.patch b/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/ChunkRegionLoader.patch deleted file mode 100644 index f8b2d18345..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/ChunkRegionLoader.patch +++ /dev/null @@ -1,111 +0,0 @@ ---- a/net/minecraft/world/level/chunk/storage/ChunkRegionLoader.java -+++ b/net/minecraft/world/level/chunk/storage/ChunkRegionLoader.java -@@ -105,7 +105,7 @@ - ChunkProviderServer chunkproviderserver = worldserver.getChunkSource(); - LevelLightEngine levellightengine = chunkproviderserver.getLightEngine(); - IRegistry iregistry = worldserver.registryAccess().registryOrThrow(Registries.BIOME); -- Codec>> codec = makeBiomeCodec(iregistry); -+ Codec>> codec = makeBiomeCodecRW(iregistry); // CraftBukkit - read/write - boolean flag2 = false; - - for (int j = 0; j < nbttaglist.size(); ++j) { -@@ -124,17 +124,17 @@ - datapaletteblock = new DataPaletteBlock<>(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), DataPaletteBlock.d.SECTION_STATES); - } - -- Object object; -+ DataPaletteBlock object; // CraftBukkit - read/write - - if (nbttagcompound1.contains("biomes", 10)) { -- object = (PalettedContainerRO) codec.parse(DynamicOpsNBT.INSTANCE, nbttagcompound1.getCompound("biomes")).promotePartial((s) -> { -+ object = codec.parse(DynamicOpsNBT.INSTANCE, nbttagcompound1.getCompound("biomes")).promotePartial((s) -> { // CraftBukkit - decompile error - logErrors(chunkcoordintpair, b0, s); - }).getOrThrow(ChunkRegionLoader.a::new); - } else { - object = new DataPaletteBlock<>(iregistry.asHolderIdMap(), iregistry.getHolderOrThrow(Biomes.PLAINS), DataPaletteBlock.d.SECTION_BIOMES); - } - -- ChunkSection chunksection = new ChunkSection(datapaletteblock, (PalettedContainerRO) object); -+ ChunkSection chunksection = new ChunkSection(datapaletteblock, (DataPaletteBlock) object); // CraftBukkit - read/write - - achunksection[k] = chunksection; - SectionPosition sectionposition = SectionPosition.of(chunkcoordintpair, b0); -@@ -171,7 +171,7 @@ - dataresult = BlendingData.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.getCompound("blending_data"))); - logger = ChunkRegionLoader.LOGGER; - Objects.requireNonNull(logger); -- blendingdata = (BlendingData) dataresult.resultOrPartial(logger::error).orElse((Object) null); -+ blendingdata = (BlendingData) ((DataResult) dataresult).resultOrPartial(logger::error).orElse(null); // CraftBukkit - decompile error - } else { - blendingdata = null; - } -@@ -202,7 +202,7 @@ - dataresult = BelowZeroRetrogen.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.getCompound("below_zero_retrogen"))); - logger = ChunkRegionLoader.LOGGER; - Objects.requireNonNull(logger); -- Optional optional = dataresult.resultOrPartial(logger::error); -+ Optional optional = ((DataResult) dataresult).resultOrPartial(logger::error); // CraftBukkit - decompile error - - Objects.requireNonNull(protochunk); - optional.ifPresent(protochunk::setBelowZeroRetrogen); -@@ -216,6 +216,13 @@ - } - } - -+ // CraftBukkit start - load chunk persistent data from nbt - SPIGOT-6814: Already load PDC here to account for 1.17 to 1.18 chunk upgrading. -+ net.minecraft.nbt.NBTBase persistentBase = nbttagcompound.get("ChunkBukkitValues"); -+ if (persistentBase instanceof NBTTagCompound) { -+ ((IChunkAccess) object1).persistentDataContainer.putAll((NBTTagCompound) persistentBase); -+ } -+ // CraftBukkit end -+ - ((IChunkAccess) object1).setLightCorrect(flag); - NBTTagCompound nbttagcompound2 = nbttagcompound.getCompound("Heightmaps"); - EnumSet enumset = EnumSet.noneOf(HeightMap.Type.class); -@@ -295,6 +302,12 @@ - return DataPaletteBlock.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), DataPaletteBlock.d.SECTION_BIOMES, iregistry.getHolderOrThrow(Biomes.PLAINS)); - } - -+ // CraftBukkit start - read/write -+ private static Codec>> makeBiomeCodecRW(IRegistry iregistry) { -+ return DataPaletteBlock.codecRW(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), DataPaletteBlock.d.SECTION_BIOMES, iregistry.getHolderOrThrow(Biomes.PLAINS)); -+ } -+ // CraftBukkit end -+ - public static NBTTagCompound write(WorldServer worldserver, IChunkAccess ichunkaccess) { - ChunkCoordIntPair chunkcoordintpair = ichunkaccess.getPos(); - NBTTagCompound nbttagcompound = GameProfileSerializer.addCurrentDataVersion(new NBTTagCompound()); -@@ -306,7 +319,7 @@ - nbttagcompound.putLong("InhabitedTime", ichunkaccess.getInhabitedTime()); - nbttagcompound.putString("Status", BuiltInRegistries.CHUNK_STATUS.getKey(ichunkaccess.getPersistedStatus()).toString()); - BlendingData blendingdata = ichunkaccess.getBlendingData(); -- DataResult dataresult; -+ DataResult dataresult; // CraftBukkit - decompile error - Logger logger; - - if (blendingdata != null) { -@@ -430,6 +443,11 @@ - - nbttagcompound.put("Heightmaps", nbttagcompound3); - nbttagcompound.put("structures", packStructureData(StructurePieceSerializationContext.fromLevel(worldserver), chunkcoordintpair, ichunkaccess.getAllStarts(), ichunkaccess.getAllReferences())); -+ // CraftBukkit start - store chunk persistent data in nbt -+ if (!ichunkaccess.persistentDataContainer.isEmpty()) { // SPIGOT-6814: Always save PDC to account for 1.17 to 1.18 chunk upgrading. -+ nbttagcompound.put("ChunkBukkitValues", ichunkaccess.persistentDataContainer.toTagCompound()); -+ } -+ // CraftBukkit end - return nbttagcompound; - } - -@@ -534,6 +552,12 @@ - StructureStart structurestart = StructureStart.loadStaticStart(structurepieceserializationcontext, nbttagcompound1.getCompound(s), i); - - if (structurestart != null) { -+ // CraftBukkit start - load persistent data for structure start -+ net.minecraft.nbt.NBTBase persistentBase = nbttagcompound1.getCompound(s).get("StructureBukkitValues"); -+ if (persistentBase instanceof NBTTagCompound) { -+ structurestart.persistentDataContainer.putAll((NBTTagCompound) persistentBase); -+ } -+ // CraftBukkit end - map.put(structure, structurestart); - } - } diff --git a/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/SerializableChunkData.patch b/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/SerializableChunkData.patch new file mode 100644 index 0000000000..ccd848a8e2 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/SerializableChunkData.patch @@ -0,0 +1,146 @@ +--- a/net/minecraft/world/level/chunk/storage/SerializableChunkData.java ++++ b/net/minecraft/world/level/chunk/storage/SerializableChunkData.java +@@ -76,7 +76,8 @@ + import net.minecraft.world.ticks.TickListChunk; + import org.slf4j.Logger; + +-public record SerializableChunkData(IRegistry biomeRegistry, ChunkCoordIntPair chunkPos, int minSectionY, long lastUpdateTime, long inhabitedTime, ChunkStatus chunkStatus, @Nullable BlendingData.d blendingData, @Nullable BelowZeroRetrogen belowZeroRetrogen, ChunkConverter upgradeData, @Nullable long[] carvingMask, Map heightmaps, IChunkAccess.a packedTicks, ShortList[] postProcessingSections, boolean lightCorrect, List sectionData, List entities, List blockEntities, NBTTagCompound structureData) { ++// CraftBukkit - persistentDataContainer ++public record SerializableChunkData(IRegistry biomeRegistry, ChunkCoordIntPair chunkPos, int minSectionY, long lastUpdateTime, long inhabitedTime, ChunkStatus chunkStatus, @Nullable BlendingData.d blendingData, @Nullable BelowZeroRetrogen belowZeroRetrogen, ChunkConverter upgradeData, @Nullable long[] carvingMask, Map heightmaps, IChunkAccess.a packedTicks, ShortList[] postProcessingSections, boolean lightCorrect, List sectionData, List entities, List blockEntities, NBTTagCompound structureData, @Nullable NBTBase persistentDataContainer) { + + public static final Codec> BLOCK_STATE_CODEC = DataPaletteBlock.codecRW(Block.BLOCK_STATE_REGISTRY, IBlockData.CODEC, DataPaletteBlock.d.SECTION_STATES, Blocks.AIR.defaultBlockState()); + private static final Logger LOGGER = LogUtils.getLogger(); +@@ -110,7 +111,7 @@ + dataresult = BlendingData.d.CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.getCompound("blending_data")); + logger = SerializableChunkData.LOGGER; + Objects.requireNonNull(logger); +- blendingdata_d = (BlendingData.d) dataresult.resultOrPartial(logger::error).orElse((Object) null); ++ blendingdata_d = (BlendingData.d) ((DataResult) dataresult).resultOrPartial(logger::error).orElse(null); // CraftBukkit - decompile error + } else { + blendingdata_d = null; + } +@@ -121,7 +122,7 @@ + dataresult = BelowZeroRetrogen.CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.getCompound("below_zero_retrogen")); + logger = SerializableChunkData.LOGGER; + Objects.requireNonNull(logger); +- belowzeroretrogen = (BelowZeroRetrogen) dataresult.resultOrPartial(logger::error).orElse((Object) null); ++ belowzeroretrogen = (BelowZeroRetrogen) ((DataResult) dataresult).resultOrPartial(logger::error).orElse(null); // CraftBukkit - decompile error + } else { + belowzeroretrogen = null; + } +@@ -178,7 +179,7 @@ + NBTTagList nbttaglist2 = nbttagcompound.getList("sections", 10); + List list4 = new ArrayList(nbttaglist2.size()); + IRegistry iregistry = iregistrycustom.lookupOrThrow(Registries.BIOME); +- Codec>> codec = makeBiomeCodec(iregistry); ++ Codec>> codec = makeBiomeCodecRW(iregistry); // CraftBukkit - read/write + + for (int i1 = 0; i1 < nbttaglist2.size(); ++i1) { + NBTTagCompound nbttagcompound3 = nbttaglist2.getCompound(i1); +@@ -196,17 +197,17 @@ + datapaletteblock = new DataPaletteBlock<>(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), DataPaletteBlock.d.SECTION_STATES); + } + +- Object object; ++ DataPaletteBlock object; // CraftBukkit - read/write + + if (nbttagcompound3.contains("biomes", 10)) { +- object = (PalettedContainerRO) codec.parse(DynamicOpsNBT.INSTANCE, nbttagcompound3.getCompound("biomes")).promotePartial((s1) -> { ++ object = codec.parse(DynamicOpsNBT.INSTANCE, nbttagcompound3.getCompound("biomes")).promotePartial((s1) -> { // CraftBukkit - read/write + logErrors(chunkcoordintpair, b0, s1); + }).getOrThrow(SerializableChunkData.a::new); + } else { + object = new DataPaletteBlock<>(iregistry.asHolderIdMap(), iregistry.getOrThrow(Biomes.PLAINS), DataPaletteBlock.d.SECTION_BIOMES); + } + +- chunksection = new ChunkSection(datapaletteblock, (PalettedContainerRO) object); ++ chunksection = new ChunkSection(datapaletteblock, (DataPaletteBlock) object); // CraftBukkit - read/write + } else { + chunksection = null; + } +@@ -217,7 +218,8 @@ + list4.add(new SerializableChunkData.b(b0, chunksection, nibblearray, nibblearray1)); + } + +- return new SerializableChunkData(iregistry, chunkcoordintpair, levelheightaccessor.getMinSectionY(), i, j, chunkstatus, blendingdata_d, belowzeroretrogen, chunkconverter, along, map, ichunkaccess_a, ashortlist, flag, list4, list2, list3, nbttagcompound2); ++ // CraftBukkit - ChunkBukkitValues ++ return new SerializableChunkData(iregistry, chunkcoordintpair, levelheightaccessor.getMinSectionY(), i, j, chunkstatus, blendingdata_d, belowzeroretrogen, chunkconverter, along, map, ichunkaccess_a, ashortlist, flag, list4, list2, list3, nbttagcompound2, nbttagcompound.get("ChunkBukkitValues")); + } + } + +@@ -289,6 +291,12 @@ + } + } + ++ // CraftBukkit start - load chunk persistent data from nbt - SPIGOT-6814: Already load PDC here to account for 1.17 to 1.18 chunk upgrading. ++ if (persistentDataContainer instanceof NBTTagCompound) { ++ ((IChunkAccess) object).persistentDataContainer.putAll((NBTTagCompound) persistentDataContainer); ++ } ++ // CraftBukkit end ++ + ((IChunkAccess) object).setLightCorrect(this.lightCorrect); + EnumSet enumset = EnumSet.noneOf(HeightMap.Type.class); + Iterator iterator1 = ((IChunkAccess) object).getPersistedStatus().heightmapsAfter().iterator(); +@@ -348,6 +356,12 @@ + return DataPaletteBlock.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), DataPaletteBlock.d.SECTION_BIOMES, iregistry.getOrThrow(Biomes.PLAINS)); + } + ++ // CraftBukkit start - read/write ++ private static Codec>> makeBiomeCodecRW(IRegistry iregistry) { ++ return DataPaletteBlock.codecRW(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), DataPaletteBlock.d.SECTION_BIOMES, iregistry.getOrThrow(Biomes.PLAINS)); ++ } ++ // CraftBukkit end ++ + public static SerializableChunkData copyOf(WorldServer worldserver, IChunkAccess ichunkaccess) { + if (!ichunkaccess.canBeSerialized()) { + throw new IllegalArgumentException("Chunk can't be serialized: " + String.valueOf(ichunkaccess)); +@@ -419,7 +433,14 @@ + }); + NBTTagCompound nbttagcompound1 = packStructureData(StructurePieceSerializationContext.fromLevel(worldserver), chunkcoordintpair, ichunkaccess.getAllStarts(), ichunkaccess.getAllReferences()); + +- return new SerializableChunkData(worldserver.registryAccess().lookupOrThrow(Registries.BIOME), chunkcoordintpair, ichunkaccess.getMinSectionY(), worldserver.getGameTime(), ichunkaccess.getInhabitedTime(), ichunkaccess.getPersistedStatus(), (BlendingData.d) Optionull.map(ichunkaccess.getBlendingData(), BlendingData::pack), ichunkaccess.getBelowZeroRetrogen(), ichunkaccess.getUpgradeData().copy(), along, map, ichunkaccess_a, ashortlist, ichunkaccess.isLightCorrect(), list, list2, list1, nbttagcompound1); ++ // CraftBukkit start - store chunk persistent data in nbt ++ NBTTagCompound persistentDataContainer = null; ++ if (!ichunkaccess.persistentDataContainer.isEmpty()) { // SPIGOT-6814: Always save PDC to account for 1.17 to 1.18 chunk upgrading. ++ persistentDataContainer = ichunkaccess.persistentDataContainer.toTagCompound(); ++ } ++ ++ return new SerializableChunkData(worldserver.registryAccess().lookupOrThrow(Registries.BIOME), chunkcoordintpair, ichunkaccess.getMinSectionY(), worldserver.getGameTime(), ichunkaccess.getInhabitedTime(), ichunkaccess.getPersistedStatus(), (BlendingData.d) Optionull.map(ichunkaccess.getBlendingData(), BlendingData::pack), ichunkaccess.getBelowZeroRetrogen(), ichunkaccess.getUpgradeData().copy(), along, map, ichunkaccess_a, ashortlist, ichunkaccess.isLightCorrect(), list, list2, list1, nbttagcompound1, persistentDataContainer); ++ // CraftBukkit end + } + } + +@@ -432,7 +453,7 @@ + nbttagcompound.putLong("LastUpdate", this.lastUpdateTime); + nbttagcompound.putLong("InhabitedTime", this.inhabitedTime); + nbttagcompound.putString("Status", BuiltInRegistries.CHUNK_STATUS.getKey(this.chunkStatus).toString()); +- DataResult dataresult; ++ DataResult dataresult; // CraftBukkit - decompile error + Logger logger; + + if (this.blendingData != null) { +@@ -513,6 +534,11 @@ + }); + nbttagcompound.put("Heightmaps", nbttagcompound2); + nbttagcompound.put("structures", this.structureData); ++ // CraftBukkit start - store chunk persistent data in nbt ++ if (persistentDataContainer != null) { // SPIGOT-6814: Always save PDC to account for 1.17 to 1.18 chunk upgrading. ++ nbttagcompound.put("ChunkBukkitValues", persistentDataContainer); ++ } ++ // CraftBukkit end + return nbttagcompound; + } + +@@ -623,6 +649,12 @@ + StructureStart structurestart = StructureStart.loadStaticStart(structurepieceserializationcontext, nbttagcompound1.getCompound(s), i); + + if (structurestart != null) { ++ // CraftBukkit start - load persistent data for structure start ++ net.minecraft.nbt.NBTBase persistentBase = nbttagcompound1.getCompound(s).get("StructureBukkitValues"); ++ if (persistentBase instanceof NBTTagCompound) { ++ structurestart.persistentDataContainer.putAll((NBTTagCompound) persistentBase); ++ } ++ // CraftBukkit end + map.put(structure, structurestart); + } + } diff --git a/paper-server/nms-patches/net/minecraft/world/level/dimension/end/EnderDragonBattle.patch b/paper-server/nms-patches/net/minecraft/world/level/dimension/end/EnderDragonBattle.patch index 86ffe4aca4..ad62a4bf22 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/dimension/end/EnderDragonBattle.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/dimension/end/EnderDragonBattle.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/dimension/end/EnderDragonBattle.java +++ b/net/minecraft/world/level/dimension/end/EnderDragonBattle.java -@@ -110,14 +110,14 @@ +@@ -111,14 +111,14 @@ this.origin = blockposition; this.validPlayer = IEntitySelector.ENTITY_STILL_ALIVE.and(IEntitySelector.withinDistance((double) blockposition.getX(), (double) (128 + blockposition.getY()), (double) blockposition.getZ(), 192.0D)); this.needsStateScanning = enderdragonbattle_a.needsStateScanning; @@ -17,7 +17,7 @@ this.gateways.addAll((Collection) enderdragonbattle_a.gateways.orElseGet(() -> { ObjectArrayList objectarraylist = new ObjectArrayList(ContiguousSet.create(Range.closedOpen(0, 20), DiscreteDomain.integers())); -@@ -207,7 +207,7 @@ +@@ -208,7 +208,7 @@ this.dragonKilled = false; if (!flag) { EnderDragonBattle.LOGGER.info("But we didn't have a portal, let's remove it."); @@ -26,7 +26,7 @@ this.dragonUUID = null; } } -@@ -510,7 +510,7 @@ +@@ -513,7 +513,7 @@ return this.previouslyKilled; } @@ -35,7 +35,7 @@ if (this.dragonKilled && this.respawnStage == null) { BlockPosition blockposition = this.portalLocation; -@@ -537,19 +537,19 @@ +@@ -540,19 +540,19 @@ List list1 = this.level.getEntitiesOfClass(EntityEnderCrystal.class, new AxisAlignedBB(blockposition1.relative(enumdirection, 2))); if (list1.isEmpty()) { @@ -59,7 +59,7 @@ if (this.dragonKilled && this.respawnStage == null) { for (ShapeDetector.ShapeDetectorCollection shapedetector_shapedetectorcollection = this.findExitPortal(); shapedetector_shapedetectorcollection != null; shapedetector_shapedetectorcollection = this.findExitPortal()) { for (int i = 0; i < this.exitPortalPattern.getWidth(); ++i) { -@@ -569,8 +569,9 @@ +@@ -572,8 +572,9 @@ this.respawnTime = 0; this.spawnExitPortal(false); this.respawnCrystals = list; diff --git a/paper-server/nms-patches/net/minecraft/world/level/levelgen/MobSpawnerPatrol.patch b/paper-server/nms-patches/net/minecraft/world/level/levelgen/MobSpawnerPatrol.patch index 6d10880de8..c2787a531f 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/levelgen/MobSpawnerPatrol.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/levelgen/MobSpawnerPatrol.patch @@ -3,7 +3,7 @@ @@ -116,7 +116,7 @@ entitymonsterpatrolling.setPos((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ()); - entitymonsterpatrolling.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(blockposition), EnumMobSpawn.PATROL, (GroupDataEntity) null); + entitymonsterpatrolling.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(blockposition), EntitySpawnReason.PATROL, (GroupDataEntity) null); - worldserver.addFreshEntityWithPassengers(entitymonsterpatrolling); + worldserver.addFreshEntityWithPassengers(entitymonsterpatrolling, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.PATROL); // CraftBukkit return true; diff --git a/paper-server/nms-patches/net/minecraft/world/level/levelgen/MobSpawnerPhantom.patch b/paper-server/nms-patches/net/minecraft/world/level/levelgen/MobSpawnerPhantom.patch index ac5104bff4..35c075ea14 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/levelgen/MobSpawnerPhantom.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/levelgen/MobSpawnerPhantom.patch @@ -3,7 +3,7 @@ @@ -74,7 +74,7 @@ if (entityphantom != null) { entityphantom.moveTo(blockposition1, 0.0F, 0.0F); - groupdataentity = entityphantom.finalizeSpawn(worldserver, difficultydamagescaler, EnumMobSpawn.NATURAL, groupdataentity); + groupdataentity = entityphantom.finalizeSpawn(worldserver, difficultydamagescaler, EntitySpawnReason.NATURAL, groupdataentity); - worldserver.addFreshEntityWithPassengers(entityphantom); + worldserver.addFreshEntityWithPassengers(entityphantom, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL); // CraftBukkit ++i; diff --git a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/PersistentStructureLegacy.patch b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/PersistentStructureLegacy.patch index 1c6fcf5985..a8d3bc86d1 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/PersistentStructureLegacy.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/PersistentStructureLegacy.patch @@ -11,7 +11,7 @@ public class PersistentStructureLegacy { private static final Map CURRENT_TO_LEGACY_MAP = (Map) SystemUtils.make(Maps.newHashMap(), (hashmap) -> { -@@ -236,16 +240,16 @@ +@@ -233,16 +237,16 @@ } } diff --git a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/StructurePiece.patch b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/StructurePiece.patch index d4be33f99e..e9a1240028 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/StructurePiece.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/StructurePiece.patch @@ -4,8 +4,8 @@ private EnumBlockRotation rotation; protected int genDepth; private final WorldGenFeatureStructurePieceType type; -- private static final Set SHAPE_CHECK_BLOCKS = ImmutableSet.builder().add(Blocks.NETHER_BRICK_FENCE).add(Blocks.TORCH).add(Blocks.WALL_TORCH).add(Blocks.OAK_FENCE).add(Blocks.SPRUCE_FENCE).add(Blocks.DARK_OAK_FENCE).add(Blocks.ACACIA_FENCE).add(Blocks.BIRCH_FENCE).add(Blocks.JUNGLE_FENCE).add(Blocks.LADDER).add(Blocks.IRON_BARS).build(); -+ public static final Set SHAPE_CHECK_BLOCKS = ImmutableSet.builder().add(Blocks.NETHER_BRICK_FENCE).add(Blocks.TORCH).add(Blocks.WALL_TORCH).add(Blocks.OAK_FENCE).add(Blocks.SPRUCE_FENCE).add(Blocks.DARK_OAK_FENCE).add(Blocks.ACACIA_FENCE).add(Blocks.BIRCH_FENCE).add(Blocks.JUNGLE_FENCE).add(Blocks.LADDER).add(Blocks.IRON_BARS).build(); // CraftBukkit - decompile error / PAIL private -> public +- private static final Set SHAPE_CHECK_BLOCKS = ImmutableSet.builder().add(Blocks.NETHER_BRICK_FENCE).add(Blocks.TORCH).add(Blocks.WALL_TORCH).add(Blocks.OAK_FENCE).add(Blocks.SPRUCE_FENCE).add(Blocks.DARK_OAK_FENCE).add(Blocks.PALE_OAK_FENCE).add(Blocks.ACACIA_FENCE).add(Blocks.BIRCH_FENCE).add(Blocks.JUNGLE_FENCE).add(Blocks.LADDER).add(Blocks.IRON_BARS).build(); ++ public static final Set SHAPE_CHECK_BLOCKS = ImmutableSet.builder().add(Blocks.NETHER_BRICK_FENCE).add(Blocks.TORCH).add(Blocks.WALL_TORCH).add(Blocks.OAK_FENCE).add(Blocks.SPRUCE_FENCE).add(Blocks.DARK_OAK_FENCE).add(Blocks.PALE_OAK_FENCE).add(Blocks.ACACIA_FENCE).add(Blocks.BIRCH_FENCE).add(Blocks.JUNGLE_FENCE).add(Blocks.LADDER).add(Blocks.IRON_BARS).build(); // CraftBukkit - decompile error / PAIL private -> public protected StructurePiece(WorldGenFeatureStructurePieceType worldgenfeaturestructurepiecetype, int i, StructureBoundingBox structureboundingbox) { this.type = worldgenfeaturestructurepiecetype; diff --git a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/StructureStart.patch b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/StructureStart.patch index d951f9772c..cf6f6199a5 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/StructureStart.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/StructureStart.patch @@ -52,4 +52,4 @@ + // CraftBukkit end if (this.isValid()) { - nbttagcompound.putString("id", structurepieceserializationcontext.registryAccess().registryOrThrow(Registries.STRUCTURE).getKey(this.structure).toString()); + nbttagcompound.putString("id", structurepieceserializationcontext.registryAccess().lookupOrThrow(Registries.STRUCTURE).getKey(this.structure).toString()); diff --git a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/EndCityPieces.patch b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/EndCityPieces.patch index de8fd65afb..9aea52419b 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/EndCityPieces.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/EndCityPieces.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/levelgen/structure/structures/EndCityPieces.java +++ b/net/minecraft/world/level/levelgen/structure/structures/EndCityPieces.java -@@ -284,7 +284,12 @@ +@@ -285,7 +285,12 @@ BlockPosition blockposition1 = blockposition.below(); if (structureboundingbox.isInside(blockposition1)) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/MineshaftPieces.patch b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/MineshaftPieces.patch index ed2f4037a5..086c189cf8 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/MineshaftPieces.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/MineshaftPieces.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/levelgen/structure/structures/MineshaftPieces.java +++ b/net/minecraft/world/level/levelgen/structure/structures/MineshaftPieces.java -@@ -43,6 +43,10 @@ +@@ -44,6 +44,10 @@ import net.minecraft.world.level.storage.loot.LootTables; import org.slf4j.Logger; @@ -11,7 +11,7 @@ public class MineshaftPieces { static final Logger LOGGER = LogUtils.getLogger(); -@@ -515,6 +519,8 @@ +@@ -520,6 +524,8 @@ if (structureboundingbox.isInside(blockposition_mutableblockposition) && this.isInterior(generatoraccessseed, 1, 0, l, structureboundingbox)) { this.hasPlacedSpider = true; @@ -20,7 +20,7 @@ generatoraccessseed.setBlock(blockposition_mutableblockposition, Blocks.SPAWNER.defaultBlockState(), 2); TileEntity tileentity = generatoraccessseed.getBlockEntity(blockposition_mutableblockposition); -@@ -523,6 +529,9 @@ +@@ -528,6 +534,9 @@ tileentitymobspawner.setEntityId(EntityTypes.CAVE_SPIDER, randomsource); } @@ -30,7 +30,7 @@ } } } -@@ -814,11 +823,11 @@ +@@ -819,11 +828,11 @@ public d(NBTTagCompound nbttagcompound) { super(WorldGenFeatureStructurePieceType.MINE_SHAFT_ROOM, nbttagcompound); @@ -44,7 +44,7 @@ List list = this.childEntranceBoxes; Objects.requireNonNull(this.childEntranceBoxes); -@@ -924,7 +933,7 @@ +@@ -929,7 +938,7 @@ @Override protected void addAdditionalSaveData(StructurePieceSerializationContext structurepieceserializationcontext, NBTTagCompound nbttagcompound) { super.addAdditionalSaveData(structurepieceserializationcontext, nbttagcompound); diff --git a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/OceanRuinPieces.patch b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/OceanRuinPieces.patch index e8ae59bee6..bfb61781f9 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/OceanRuinPieces.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/OceanRuinPieces.patch @@ -19,5 +19,5 @@ + placeCraftBlockEntity(worldaccess, blockposition, craftChest, 2); + // CraftBukkit end } else if ("drowned".equals(s)) { - EntityDrowned entitydrowned = (EntityDrowned) EntityTypes.DROWNED.create(worldaccess.getLevel()); + EntityDrowned entitydrowned = (EntityDrowned) EntityTypes.DROWNED.create(worldaccess.getLevel(), EntitySpawnReason.STRUCTURE); diff --git a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/SwampHutPiece.patch b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/SwampHutPiece.patch index 9767269c61..d46ee75786 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/SwampHutPiece.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/SwampHutPiece.patch @@ -3,7 +3,7 @@ @@ -100,7 +100,7 @@ entitywitch.setPersistenceRequired(); entitywitch.moveTo((double) blockposition_mutableblockposition.getX() + 0.5D, (double) blockposition_mutableblockposition.getY(), (double) blockposition_mutableblockposition.getZ() + 0.5D, 0.0F, 0.0F); - entitywitch.finalizeSpawn(generatoraccessseed, generatoraccessseed.getCurrentDifficultyAt(blockposition_mutableblockposition), EnumMobSpawn.STRUCTURE, (GroupDataEntity) null); + entitywitch.finalizeSpawn(generatoraccessseed, generatoraccessseed.getCurrentDifficultyAt(blockposition_mutableblockposition), EntitySpawnReason.STRUCTURE, (GroupDataEntity) null); - generatoraccessseed.addFreshEntityWithPassengers(entitywitch); + generatoraccessseed.addFreshEntityWithPassengers(entitywitch, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CHUNK_GEN); // CraftBukkit - add SpawnReason } @@ -12,7 +12,7 @@ @@ -121,7 +121,7 @@ entitycat.setPersistenceRequired(); entitycat.moveTo((double) blockposition_mutableblockposition.getX() + 0.5D, (double) blockposition_mutableblockposition.getY(), (double) blockposition_mutableblockposition.getZ() + 0.5D, 0.0F, 0.0F); - entitycat.finalizeSpawn(worldaccess, worldaccess.getCurrentDifficultyAt(blockposition_mutableblockposition), EnumMobSpawn.STRUCTURE, (GroupDataEntity) null); + entitycat.finalizeSpawn(worldaccess, worldaccess.getCurrentDifficultyAt(blockposition_mutableblockposition), EntitySpawnReason.STRUCTURE, (GroupDataEntity) null); - worldaccess.addFreshEntityWithPassengers(entitycat); + worldaccess.addFreshEntityWithPassengers(entitycat, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.CHUNK_GEN); // CraftBukkit - add SpawnReason } diff --git a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructure.patch b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructure.patch index 3525993f5e..f8027cf9fd 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructure.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructure.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructure.java +++ b/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructure.java -@@ -52,6 +52,12 @@ +@@ -56,6 +56,12 @@ import net.minecraft.world.phys.shapes.VoxelShapeBitSet; import net.minecraft.world.phys.shapes.VoxelShapeDiscrete; @@ -13,7 +13,7 @@ public class DefinedStructure { public static final String PALETTE_TAG = "palette"; -@@ -70,6 +76,11 @@ +@@ -74,6 +80,11 @@ private BaseBlockPosition size; private String author; @@ -25,7 +25,7 @@ public DefinedStructure() { this.size = BaseBlockPosition.ZERO; this.author = "?"; -@@ -143,7 +154,7 @@ +@@ -147,7 +158,7 @@ } private static List buildInfoList(List list, List list1, List list2) { @@ -34,7 +34,7 @@ return definedstructure_blockinfo.pos.getY(); }).thenComparingInt((definedstructure_blockinfo) -> { return definedstructure_blockinfo.pos.getX(); -@@ -229,6 +240,19 @@ +@@ -253,6 +264,19 @@ if (this.palettes.isEmpty()) { return false; } else { @@ -54,7 +54,7 @@ List list = definedstructureinfo.getRandomPalette(this.palettes, blockposition).blocks(); if ((!list.isEmpty() || !definedstructureinfo.isIgnoreEntities() && !this.entityInfoList.isEmpty()) && this.size.getX() >= 1 && this.size.getY() >= 1 && this.size.getZ() >= 1) { -@@ -260,6 +284,20 @@ +@@ -284,6 +308,20 @@ Clearable.tryClear(tileentity); worldaccess.setBlock(blockposition2, Blocks.BARRIER.defaultBlockState(), 20); } @@ -75,7 +75,7 @@ if (worldaccess.setBlock(blockposition2, iblockdata, i)) { j = Math.min(j, blockposition2.getX()); -@@ -272,7 +310,7 @@ +@@ -296,7 +334,7 @@ if (definedstructure_blockinfo.nbt != null) { tileentity = worldaccess.getBlockEntity(blockposition2); if (tileentity != null) { @@ -84,7 +84,7 @@ definedstructure_blockinfo.nbt.putLong("LootTableSeed", randomsource.nextLong()); } -@@ -377,7 +415,7 @@ +@@ -401,7 +439,7 @@ } if (!definedstructureinfo.isIgnoreEntities()) { @@ -93,14 +93,14 @@ } return true; -@@ -479,11 +517,13 @@ +@@ -503,11 +541,13 @@ } private static Optional createEntityIgnoreException(WorldAccess worldaccess, NBTTagCompound nbttagcompound) { - try { + // CraftBukkit start + // try { - return EntityTypes.create(nbttagcompound, worldaccess.getLevel()); + return EntityTypes.create(nbttagcompound, worldaccess.getLevel(), EntitySpawnReason.STRUCTURE); - } catch (Exception exception) { - return Optional.empty(); - } @@ -111,7 +111,7 @@ } public BaseBlockPosition getSize(EnumBlockRotation enumblockrotation) { -@@ -697,6 +737,11 @@ +@@ -721,6 +761,11 @@ nbttagcompound.put("entities", nbttaglist3); nbttagcompound.put("size", this.newIntegerList(this.size.getX(), this.size.getY(), this.size.getZ())); @@ -123,7 +123,7 @@ return GameProfileSerializer.addCurrentDataVersion(nbttagcompound); } -@@ -736,6 +781,12 @@ +@@ -760,6 +805,12 @@ } } @@ -136,11 +136,11 @@ } private void loadPalette(HolderGetter holdergetter, NBTTagList nbttaglist, NBTTagList nbttaglist1) { -@@ -865,7 +916,7 @@ +@@ -924,7 +975,7 @@ public IBlockData stateFor(int i) { IBlockData iblockdata = (IBlockData) this.ids.byId(i); -- return iblockdata == null ? DefinedStructure.b.DEFAULT_BLOCK_STATE : iblockdata; +- return iblockdata == null ? DefinedStructure.c.DEFAULT_BLOCK_STATE : iblockdata; + return iblockdata == null ? DEFAULT_BLOCK_STATE : iblockdata; // CraftBukkit - decompile error } diff --git a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructureInfo.patch b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructureInfo.patch index 08f32d6b1c..4eee99d57f 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructureInfo.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/templatesystem/DefinedStructureInfo.patch @@ -21,5 +21,5 @@ + return list.get(this.palette); + // CraftBukkit end } else { - return (DefinedStructure.a) list.get(this.getRandom(blockposition).nextInt(i)); + return (DefinedStructure.b) list.get(this.getRandom(blockposition).nextInt(i)); } diff --git a/paper-server/nms-patches/net/minecraft/world/level/material/FluidTypeFlowing.patch b/paper-server/nms-patches/net/minecraft/world/level/material/FluidTypeFlowing.patch index 753e886f19..0cff368d6c 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/material/FluidTypeFlowing.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/material/FluidTypeFlowing.patch @@ -16,62 +16,60 @@ public abstract class FluidTypeFlowing extends FluidType { public static final BlockStateBoolean FALLING = BlockProperties.FALLING; -@@ -132,6 +141,15 @@ - Fluid fluid1 = this.getNewLiquid(world, blockposition1, iblockdata1); +@@ -135,6 +144,15 @@ + FluidType fluidtype = fluid2.getType(); - if (this.canSpreadTo(world, blockposition, iblockdata, EnumDirection.DOWN, blockposition1, iblockdata1, world.getFluidState(blockposition1), fluid1.getType())) { -+ // CraftBukkit start -+ org.bukkit.block.Block source = CraftBlock.at(world, blockposition); -+ BlockFromToEvent event = new BlockFromToEvent(source, BlockFace.DOWN); -+ world.getCraftServer().getPluginManager().callEvent(event); -+ -+ if (event.isCancelled()) { -+ return; -+ } -+ // CraftBukkit end - this.spreadTo(world, blockposition1, iblockdata1, EnumDirection.DOWN, fluid1); - if (this.sourceNeighborCount(world, blockposition) >= 3) { - this.spreadToSides(world, blockposition, fluid, iblockdata); -@@ -162,6 +180,15 @@ - IBlockData iblockdata1 = world.getBlockState(blockposition1); - - if (this.canSpreadTo(world, blockposition, iblockdata, enumdirection, blockposition1, iblockdata1, world.getFluidState(blockposition1), fluid1.getType())) { + if (fluid1.canBeReplacedWith(worldserver, blockposition1, fluidtype, EnumDirection.DOWN) && canHoldSpecificFluid(worldserver, blockposition1, iblockdata1, fluidtype)) { + // CraftBukkit start -+ org.bukkit.block.Block source = CraftBlock.at(world, blockposition); -+ BlockFromToEvent event = new BlockFromToEvent(source, org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(enumdirection)); -+ world.getCraftServer().getPluginManager().callEvent(event); ++ org.bukkit.block.Block source = CraftBlock.at(worldserver, blockposition); ++ BlockFromToEvent event = new BlockFromToEvent(source, BlockFace.DOWN); ++ worldserver.getCraftServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) { -+ continue; ++ return; + } + // CraftBukkit end - this.spreadTo(world, blockposition1, iblockdata1, enumdirection, fluid1); - } - } -@@ -436,12 +463,23 @@ + this.spreadTo(worldserver, blockposition1, iblockdata1, EnumDirection.DOWN, fluid2); + if (this.sourceNeighborCount(worldserver, blockposition) >= 3) { + this.spreadToSides(worldserver, blockposition, fluid, iblockdata); +@@ -168,6 +186,15 @@ + Fluid fluid1 = (Fluid) entry.getValue(); + BlockPosition blockposition1 = blockposition.relative(enumdirection); ++ // CraftBukkit start ++ org.bukkit.block.Block source = CraftBlock.at(worldserver, blockposition); ++ BlockFromToEvent event = new BlockFromToEvent(source, org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(enumdirection)); ++ worldserver.getCraftServer().getPluginManager().callEvent(event); ++ ++ if (event.isCancelled()) { ++ continue; ++ } ++ // CraftBukkit end + this.spreadTo(worldserver, blockposition1, worldserver.getBlockState(blockposition1), enumdirection, fluid1); + } + +@@ -444,10 +471,24 @@ if (fluid1.isEmpty()) { fluid = fluid1; -- world.setBlock(blockposition, Blocks.AIR.defaultBlockState(), 3); + iblockdata = Blocks.AIR.defaultBlockState(); + // CraftBukkit start -+ FluidLevelChangeEvent event = CraftEventFactory.callFluidLevelChangeEvent(world, blockposition, Blocks.AIR.defaultBlockState()); ++ FluidLevelChangeEvent event = CraftEventFactory.callFluidLevelChangeEvent(worldserver, blockposition, iblockdata); + if (event.isCancelled()) { + return; + } -+ world.setBlock(blockposition, ((CraftBlockData) event.getNewData()).getState(), 3); ++ iblockdata = ((CraftBlockData) event.getNewData()).getState(); + // CraftBukkit end + worldserver.setBlock(blockposition, iblockdata, 3); } else if (!fluid1.equals(fluid)) { fluid = fluid1; - IBlockData iblockdata = fluid1.createLegacyBlock(); -- -- world.setBlock(blockposition, iblockdata, 2); + iblockdata = fluid1.createLegacyBlock(); + // CraftBukkit start -+ FluidLevelChangeEvent event = CraftEventFactory.callFluidLevelChangeEvent(world, blockposition, iblockdata); ++ FluidLevelChangeEvent event = CraftEventFactory.callFluidLevelChangeEvent(worldserver, blockposition, iblockdata); + if (event.isCancelled()) { + return; + } -+ world.setBlock(blockposition, ((CraftBlockData) event.getNewData()).getState(), 2); ++ iblockdata = ((CraftBlockData) event.getNewData()).getState(); + // CraftBukkit end - world.scheduleTick(blockposition, fluid1.getType(), i); - world.updateNeighborsAt(blockposition, iblockdata.getBlock()); + worldserver.setBlock(blockposition, iblockdata, 3); + worldserver.scheduleTick(blockposition, fluid1.getType(), i); } diff --git a/paper-server/nms-patches/net/minecraft/world/level/material/FluidTypeLava.patch b/paper-server/nms-patches/net/minecraft/world/level/material/FluidTypeLava.patch index d696818519..b77cab1de6 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/material/FluidTypeLava.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/material/FluidTypeLava.patch @@ -1,35 +1,35 @@ --- a/net/minecraft/world/level/material/FluidTypeLava.java +++ b/net/minecraft/world/level/material/FluidTypeLava.java -@@ -84,6 +84,13 @@ +@@ -85,6 +85,13 @@ if (iblockdata.isAir()) { - if (this.hasFlammableNeighbours(world, blockposition1)) { + if (this.hasFlammableNeighbours(worldserver, blockposition1)) { + // CraftBukkit start - Prevent lava putting something on fire -+ if (world.getBlockState(blockposition1).getBlock() != Blocks.FIRE) { -+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition1, blockposition).isCancelled()) { ++ if (worldserver.getBlockState(blockposition1).getBlock() != Blocks.FIRE) { ++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(worldserver, blockposition1, blockposition).isCancelled()) { + continue; + } + } + // CraftBukkit end - world.setBlockAndUpdate(blockposition1, BlockFireAbstract.getState(world, blockposition1)); + worldserver.setBlockAndUpdate(blockposition1, BlockFireAbstract.getState(worldserver, blockposition1)); return; } -@@ -100,6 +107,14 @@ +@@ -101,6 +108,14 @@ } - if (world.isEmptyBlock(blockposition2.above()) && this.isFlammable(world, blockposition2)) { + if (worldserver.isEmptyBlock(blockposition2.above()) && this.isFlammable(worldserver, blockposition2)) { + // CraftBukkit start - Prevent lava putting something on fire + BlockPosition up = blockposition2.above(); -+ if (world.getBlockState(up).getBlock() != Blocks.FIRE) { -+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, up, blockposition).isCancelled()) { ++ if (worldserver.getBlockState(up).getBlock() != Blocks.FIRE) { ++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(worldserver, up, blockposition).isCancelled()) { + continue; + } + } + // CraftBukkit end - world.setBlockAndUpdate(blockposition2.above(), BlockFireAbstract.getState(world, blockposition2)); + worldserver.setBlockAndUpdate(blockposition2.above(), BlockFireAbstract.getState(worldserver, blockposition2)); } } -@@ -195,7 +210,11 @@ +@@ -196,7 +211,11 @@ if (this.is(TagsFluid.LAVA) && fluid1.is(TagsFluid.WATER)) { if (iblockdata.getBlock() instanceof BlockFluids) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/portal/BlockPortalShape.patch b/paper-server/nms-patches/net/minecraft/world/level/portal/BlockPortalShape.patch index 0a345134dd..903517a86a 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/portal/BlockPortalShape.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/portal/BlockPortalShape.patch @@ -1,75 +1,154 @@ --- a/net/minecraft/world/level/portal/BlockPortalShape.java +++ b/net/minecraft/world/level/portal/BlockPortalShape.java -@@ -21,6 +21,10 @@ - import net.minecraft.world.phys.shapes.VoxelShape; +@@ -23,6 +23,11 @@ import net.minecraft.world.phys.shapes.VoxelShapes; + import org.apache.commons.lang3.mutable.MutableInt; +// CraftBukkit start ++import org.bukkit.craftbukkit.util.BlockStateListPopulator; +import org.bukkit.event.world.PortalCreateEvent; +// CraftBukkit end + public class BlockPortalShape { private static final int MIN_WIDTH = 2; -@@ -40,6 +44,7 @@ - private BlockPosition bottomLeft; - private int height; +@@ -40,8 +45,12 @@ + private final BlockPosition bottomLeft; + private final int height; private final int width; -+ org.bukkit.craftbukkit.util.BlockStateListPopulator blocks; // CraftBukkit - add field ++ // CraftBukkit start - add field ++ private final BlockStateListPopulator blocks; - public static Optional findEmptyPortalShape(GeneratorAccess generatoraccess, BlockPosition blockposition, EnumDirection.EnumAxis enumdirection_enumaxis) { - return findPortalShape(generatoraccess, blockposition, (blockportalshape) -> { -@@ -60,6 +65,7 @@ +- private BlockPortalShape(EnumDirection.EnumAxis enumdirection_enumaxis, int i, EnumDirection enumdirection, BlockPosition blockposition, int j, int k) { ++ private BlockPortalShape(EnumDirection.EnumAxis enumdirection_enumaxis, int i, EnumDirection enumdirection, BlockPosition blockposition, int j, int k, BlockStateListPopulator blocks) { ++ this.blocks = blocks; ++ // CraftBukkit end + this.axis = enumdirection_enumaxis; + this.numPortalBlocks = i; + this.rightDir = enumdirection; +@@ -69,44 +78,45 @@ } - public BlockPortalShape(GeneratorAccess generatoraccess, BlockPosition blockposition, EnumDirection.EnumAxis enumdirection_enumaxis) { -+ blocks = new org.bukkit.craftbukkit.util.BlockStateListPopulator(generatoraccess.getMinecraftWorld()); // CraftBukkit - this.level = generatoraccess; - this.axis = enumdirection_enumaxis; - this.rightDir = enumdirection_enumaxis == EnumDirection.EnumAxis.X ? EnumDirection.WEST : EnumDirection.SOUTH; -@@ -104,6 +110,7 @@ + public static BlockPortalShape findAnyShape(IBlockAccess iblockaccess, BlockPosition blockposition, EnumDirection.EnumAxis enumdirection_enumaxis) { ++ BlockStateListPopulator blocks = new BlockStateListPopulator(((GeneratorAccess) iblockaccess).getMinecraftWorld()); // CraftBukkit + EnumDirection enumdirection = enumdirection_enumaxis == EnumDirection.EnumAxis.X ? EnumDirection.WEST : EnumDirection.SOUTH; +- BlockPosition blockposition1 = calculateBottomLeft(iblockaccess, enumdirection, blockposition); ++ BlockPosition blockposition1 = calculateBottomLeft(iblockaccess, enumdirection, blockposition, blocks); // CraftBukkit + + if (blockposition1 == null) { +- return new BlockPortalShape(enumdirection_enumaxis, 0, enumdirection, blockposition, 0, 0); ++ return new BlockPortalShape(enumdirection_enumaxis, 0, enumdirection, blockposition, 0, 0, blocks); // CraftBukkit + } else { +- int i = calculateWidth(iblockaccess, blockposition1, enumdirection); ++ int i = calculateWidth(iblockaccess, blockposition1, enumdirection, blocks); // CraftBukkit + + if (i == 0) { +- return new BlockPortalShape(enumdirection_enumaxis, 0, enumdirection, blockposition1, 0, 0); ++ return new BlockPortalShape(enumdirection_enumaxis, 0, enumdirection, blockposition1, 0, 0, blocks); // CraftBukkit + } else { + MutableInt mutableint = new MutableInt(); +- int j = calculateHeight(iblockaccess, blockposition1, enumdirection, i, mutableint); ++ int j = calculateHeight(iblockaccess, blockposition1, enumdirection, i, mutableint, blocks); // CraftBukkit + +- return new BlockPortalShape(enumdirection_enumaxis, mutableint.getValue(), enumdirection, blockposition1, i, j); ++ return new BlockPortalShape(enumdirection_enumaxis, mutableint.getValue(), enumdirection, blockposition1, i, j, blocks); // CraftBukkit + } + } + } + + @Nullable +- private static BlockPosition calculateBottomLeft(IBlockAccess iblockaccess, EnumDirection enumdirection, BlockPosition blockposition) { ++ private static BlockPosition calculateBottomLeft(IBlockAccess iblockaccess, EnumDirection enumdirection, BlockPosition blockposition, BlockStateListPopulator blocks) { // CraftBukkit + for (int i = Math.max(iblockaccess.getMinY(), blockposition.getY() - 21); blockposition.getY() > i && isEmpty(iblockaccess.getBlockState(blockposition.below())); blockposition = blockposition.below()) { + ; + } + + EnumDirection enumdirection1 = enumdirection.getOpposite(); +- int j = getDistanceUntilEdgeAboveFrame(iblockaccess, blockposition, enumdirection1) - 1; ++ int j = getDistanceUntilEdgeAboveFrame(iblockaccess, blockposition, enumdirection1, blocks) - 1; // CraftBukkit + + return j < 0 ? null : blockposition.relative(enumdirection1, j); + } + +- private static int calculateWidth(IBlockAccess iblockaccess, BlockPosition blockposition, EnumDirection enumdirection) { +- int i = getDistanceUntilEdgeAboveFrame(iblockaccess, blockposition, enumdirection); ++ private static int calculateWidth(IBlockAccess iblockaccess, BlockPosition blockposition, EnumDirection enumdirection, BlockStateListPopulator blocks) { // CraftBukkit ++ int i = getDistanceUntilEdgeAboveFrame(iblockaccess, blockposition, enumdirection, blocks); // CraftBukkit + + return i >= 2 && i <= 21 ? i : 0; + } + +- private static int getDistanceUntilEdgeAboveFrame(IBlockAccess iblockaccess, BlockPosition blockposition, EnumDirection enumdirection) { ++ private static int getDistanceUntilEdgeAboveFrame(IBlockAccess iblockaccess, BlockPosition blockposition, EnumDirection enumdirection, BlockStateListPopulator blocks) { // CraftBukkit + BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition(); + + for (int i = 0; i <= 21; ++i) { +@@ -115,6 +125,7 @@ if (!isEmpty(iblockdata)) { - if (BlockPortalShape.FRAME.test(iblockdata, this.level, blockposition_mutableblockposition)) { + if (BlockPortalShape.FRAME.test(iblockdata, iblockaccess, blockposition_mutableblockposition)) { + blocks.setBlock(blockposition_mutableblockposition, iblockdata, 18); // CraftBukkit - lower left / right return i; } break; -@@ -114,6 +121,7 @@ - if (!BlockPortalShape.FRAME.test(iblockdata1, this.level, blockposition_mutableblockposition)) { +@@ -125,31 +136,33 @@ + if (!BlockPortalShape.FRAME.test(iblockdata1, iblockaccess, blockposition_mutableblockposition)) { break; } + blocks.setBlock(blockposition_mutableblockposition, iblockdata1, 18); // CraftBukkit - bottom row } return 0; -@@ -133,6 +141,7 @@ - if (!BlockPortalShape.FRAME.test(this.level.getBlockState(blockposition_mutableblockposition1), this.level, blockposition_mutableblockposition1)) { + } + +- private static int calculateHeight(IBlockAccess iblockaccess, BlockPosition blockposition, EnumDirection enumdirection, int i, MutableInt mutableint) { ++ private static int calculateHeight(IBlockAccess iblockaccess, BlockPosition blockposition, EnumDirection enumdirection, int i, MutableInt mutableint, BlockStateListPopulator blocks) { // CraftBukkit + BlockPosition.MutableBlockPosition blockposition_mutableblockposition = new BlockPosition.MutableBlockPosition(); +- int j = getDistanceUntilTop(iblockaccess, blockposition, enumdirection, blockposition_mutableblockposition, i, mutableint); ++ int j = getDistanceUntilTop(iblockaccess, blockposition, enumdirection, blockposition_mutableblockposition, i, mutableint, blocks); // CraftBukkit + +- return j >= 3 && j <= 21 && hasTopFrame(iblockaccess, blockposition, enumdirection, blockposition_mutableblockposition, i, j) ? j : 0; ++ return j >= 3 && j <= 21 && hasTopFrame(iblockaccess, blockposition, enumdirection, blockposition_mutableblockposition, i, j, blocks) ? j : 0; // CraftBukkit + } + +- private static boolean hasTopFrame(IBlockAccess iblockaccess, BlockPosition blockposition, EnumDirection enumdirection, BlockPosition.MutableBlockPosition blockposition_mutableblockposition, int i, int j) { ++ private static boolean hasTopFrame(IBlockAccess iblockaccess, BlockPosition blockposition, EnumDirection enumdirection, BlockPosition.MutableBlockPosition blockposition_mutableblockposition, int i, int j, BlockStateListPopulator blocks) { // CraftBukkit + for (int k = 0; k < i; ++k) { + BlockPosition.MutableBlockPosition blockposition_mutableblockposition1 = blockposition_mutableblockposition.set(blockposition).move(EnumDirection.UP, j).move(enumdirection, k); + + if (!BlockPortalShape.FRAME.test(iblockaccess.getBlockState(blockposition_mutableblockposition1), iblockaccess, blockposition_mutableblockposition1)) { return false; } -+ blocks.setBlock(blockposition_mutableblockposition1, this.level.getBlockState(blockposition_mutableblockposition1), 18); // CraftBukkit - upper row ++ blocks.setBlock(blockposition_mutableblockposition1, iblockaccess.getBlockState(blockposition_mutableblockposition1), 18); // CraftBukkit - upper row } return true; -@@ -162,6 +171,10 @@ - ++this.numPortalBlocks; + } + +- private static int getDistanceUntilTop(IBlockAccess iblockaccess, BlockPosition blockposition, EnumDirection enumdirection, BlockPosition.MutableBlockPosition blockposition_mutableblockposition, int i, MutableInt mutableint) { ++ private static int getDistanceUntilTop(IBlockAccess iblockaccess, BlockPosition blockposition, EnumDirection enumdirection, BlockPosition.MutableBlockPosition blockposition_mutableblockposition, int i, MutableInt mutableint, BlockStateListPopulator blocks) { // CraftBukkit + for (int j = 0; j < 21; ++j) { + blockposition_mutableblockposition.set(blockposition).move(EnumDirection.UP, j).move(enumdirection, -1); + if (!BlockPortalShape.FRAME.test(iblockaccess.getBlockState(blockposition_mutableblockposition), iblockaccess, blockposition_mutableblockposition)) { +@@ -173,6 +186,10 @@ + mutableint.increment(); } } + // CraftBukkit start - left and right -+ blocks.setBlock(blockposition_mutableblockposition.set(this.bottomLeft).move(EnumDirection.UP, i).move(this.rightDir, -1), this.level.getBlockState(blockposition_mutableblockposition), 18); -+ blocks.setBlock(blockposition_mutableblockposition.set(this.bottomLeft).move(EnumDirection.UP, i).move(this.rightDir, this.width), this.level.getBlockState(blockposition_mutableblockposition), 18); ++ blocks.setBlock(blockposition_mutableblockposition.set(blockposition).move(EnumDirection.UP, j).move(enumdirection, -1), iblockaccess.getBlockState(blockposition_mutableblockposition), 18); ++ blocks.setBlock(blockposition_mutableblockposition.set(blockposition).move(EnumDirection.UP, j).move(enumdirection, i), iblockaccess.getBlockState(blockposition_mutableblockposition), 18); + // CraftBukkit end } return 21; -@@ -175,12 +188,28 @@ - return this.bottomLeft != null && this.width >= 2 && this.width <= 21 && this.height >= 3 && this.height <= 21; +@@ -186,12 +203,28 @@ + return this.width >= 2 && this.width <= 21 && this.height >= 3 && this.height <= 21; } -- public void createPortalBlocks() { +- public void createPortalBlocks(GeneratorAccess generatoraccess) { + // CraftBukkit start - return boolean, add entity -+ public boolean createPortalBlocks(Entity entity) { -+ org.bukkit.World bworld = this.level.getMinecraftWorld().getWorld(); ++ public boolean createPortalBlocks(GeneratorAccess generatoraccess, Entity entity) { ++ org.bukkit.World bworld = generatoraccess.getMinecraftWorld().getWorld(); + + // Copy below for loop IBlockData iblockdata = (IBlockData) Blocks.NETHER_PORTAL.defaultBlockState().setValue(BlockPortal.AXIS, this.axis); @@ -79,14 +158,14 @@ + }); + + PortalCreateEvent event = new PortalCreateEvent((java.util.List) (java.util.List) blocks.getList(), bworld, (entity == null) ? null : entity.getBukkitEntity(), PortalCreateEvent.CreateReason.FIRE); -+ this.level.getMinecraftWorld().getServer().server.getPluginManager().callEvent(event); ++ generatoraccess.getMinecraftWorld().getServer().server.getPluginManager().callEvent(event); + + if (event.isCancelled()) { + return false; + } + // CraftBukkit end + BlockPosition.betweenClosed(this.bottomLeft, this.bottomLeft.relative(EnumDirection.UP, this.height - 1).relative(this.rightDir, this.width - 1)).forEach((blockposition) -> { - this.level.setBlock(blockposition, iblockdata, 18); + generatoraccess.setBlock(blockposition, iblockdata, 18); }); + return true; // CraftBukkit } diff --git a/paper-server/nms-patches/net/minecraft/world/level/portal/DimensionTransition.patch b/paper-server/nms-patches/net/minecraft/world/level/portal/DimensionTransition.patch deleted file mode 100644 index 2b377bae08..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/level/portal/DimensionTransition.patch +++ /dev/null @@ -1,47 +0,0 @@ ---- a/net/minecraft/world/level/portal/DimensionTransition.java -+++ b/net/minecraft/world/level/portal/DimensionTransition.java -@@ -7,7 +7,19 @@ - import net.minecraft.world.entity.Entity; - import net.minecraft.world.phys.Vec3D; - --public record DimensionTransition(WorldServer newLevel, Vec3D pos, Vec3D speed, float yRot, float xRot, boolean missingRespawnBlock, DimensionTransition.a postDimensionTransition) { -+// CraftBukkit start -+import org.bukkit.event.player.PlayerTeleportEvent; -+ -+public record DimensionTransition(WorldServer newLevel, Vec3D pos, Vec3D speed, float yRot, float xRot, boolean missingRespawnBlock, DimensionTransition.a postDimensionTransition, PlayerTeleportEvent.TeleportCause cause) { -+ -+ public DimensionTransition(WorldServer newLevel, Vec3D pos, Vec3D speed, float yRot, float xRot, boolean missingRespawnBlock, DimensionTransition.a postDimensionTransition) { -+ this(newLevel, pos, speed, yRot, xRot, missingRespawnBlock, postDimensionTransition, PlayerTeleportEvent.TeleportCause.UNKNOWN); -+ } -+ -+ public DimensionTransition(PlayerTeleportEvent.TeleportCause cause) { -+ this(null, Vec3D.ZERO, Vec3D.ZERO, 0.0F, 0.0F, false, DO_NOTHING, cause); -+ } -+ // CraftBukkit end - - public static final DimensionTransition.a DO_NOTHING = (entity) -> { - }; -@@ -15,11 +27,21 @@ - public static final DimensionTransition.a PLACE_PORTAL_TICKET = DimensionTransition::placePortalTicket; - - public DimensionTransition(WorldServer worldserver, Vec3D vec3d, Vec3D vec3d1, float f, float f1, DimensionTransition.a dimensiontransition_a) { -- this(worldserver, vec3d, vec3d1, f, f1, false, dimensiontransition_a); -+ // CraftBukkit start -+ this(worldserver, vec3d, vec3d1, f, f1, dimensiontransition_a, PlayerTeleportEvent.TeleportCause.UNKNOWN); -+ } -+ -+ public DimensionTransition(WorldServer worldserver, Vec3D vec3d, Vec3D vec3d1, float f, float f1, DimensionTransition.a dimensiontransition_a, PlayerTeleportEvent.TeleportCause cause) { -+ this(worldserver, vec3d, vec3d1, f, f1, false, dimensiontransition_a, cause); - } - - public DimensionTransition(WorldServer worldserver, Entity entity, DimensionTransition.a dimensiontransition_a) { -- this(worldserver, findAdjustedSharedSpawnPos(worldserver, entity), Vec3D.ZERO, 0.0F, 0.0F, false, dimensiontransition_a); -+ this(worldserver, entity, dimensiontransition_a, PlayerTeleportEvent.TeleportCause.UNKNOWN); -+ } -+ -+ public DimensionTransition(WorldServer worldserver, Entity entity, DimensionTransition.a dimensiontransition_a, PlayerTeleportEvent.TeleportCause cause) { -+ this(worldserver, findAdjustedSharedSpawnPos(worldserver, entity), Vec3D.ZERO, 0.0F, 0.0F, false, dimensiontransition_a, cause); -+ // CraftBukkit end - } - - private static void playPortalSound(Entity entity) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/portal/PortalTravelAgent.patch b/paper-server/nms-patches/net/minecraft/world/level/portal/PortalTravelAgent.patch index 43293e1343..0f5b050ab4 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/portal/PortalTravelAgent.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/portal/PortalTravelAgent.patch @@ -40,7 +40,7 @@ double d0 = -1.0D; BlockPosition blockposition1 = null; @@ -69,7 +81,7 @@ - int i = Math.min(this.level.getMaxBuildHeight(), this.level.getMinBuildHeight() + this.level.getLogicalHeight()) - 1; + int i = Math.min(this.level.getMaxY(), this.level.getMinY() + this.level.getLogicalHeight() - 1); boolean flag = true; BlockPosition.MutableBlockPosition blockposition_mutableblockposition = blockposition.mutable(); - Iterator iterator = BlockPosition.spiralAround(blockposition, 16, EnumDirection.EAST, EnumDirection.SOUTH).iterator(); @@ -54,7 +54,7 @@ + org.bukkit.craftbukkit.util.BlockStateListPopulator blockList = new org.bukkit.craftbukkit.util.BlockStateListPopulator(this.level); // CraftBukkit - Use BlockStateListPopulator if (d0 == -1.0D) { - j1 = Math.max(this.level.getMinBuildHeight() - -1, 70); + j1 = Math.max(this.level.getMinY() - -1, 70); k1 = i - 9; @@ -139,7 +152,7 @@ IBlockData iblockdata = i1 < 0 ? Blocks.OBSIDIAN.defaultBlockState() : Blocks.AIR.defaultBlockState(); diff --git a/paper-server/nms-patches/net/minecraft/world/level/portal/TeleportTransition.patch b/paper-server/nms-patches/net/minecraft/world/level/portal/TeleportTransition.patch new file mode 100644 index 0000000000..26b742340f --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/level/portal/TeleportTransition.patch @@ -0,0 +1,60 @@ +--- a/net/minecraft/world/level/portal/TeleportTransition.java ++++ b/net/minecraft/world/level/portal/TeleportTransition.java +@@ -9,7 +9,19 @@ + import net.minecraft.world.entity.Relative; + import net.minecraft.world.phys.Vec3D; + +-public record TeleportTransition(WorldServer newLevel, Vec3D position, Vec3D deltaMovement, float yRot, float xRot, boolean missingRespawnBlock, boolean asPassenger, Set relatives, TeleportTransition.a postTeleportTransition) { ++// CraftBukkit start ++import org.bukkit.event.player.PlayerTeleportEvent; ++ ++public record TeleportTransition(WorldServer newLevel, Vec3D position, Vec3D deltaMovement, float yRot, float xRot, boolean missingRespawnBlock, boolean asPassenger, Set relatives, TeleportTransition.a postTeleportTransition, PlayerTeleportEvent.TeleportCause cause) { ++ ++ public TeleportTransition(WorldServer newLevel, Vec3D position, Vec3D deltaMovement, float yRot, float xRot, boolean missingRespawnBlock, boolean asPassenger, Set relatives, TeleportTransition.a postTeleportTransition) { ++ this(newLevel, position, deltaMovement, yRot, xRot, missingRespawnBlock, asPassenger, relatives, postTeleportTransition, PlayerTeleportEvent.TeleportCause.UNKNOWN); ++ } ++ ++ public TeleportTransition(PlayerTeleportEvent.TeleportCause cause) { ++ this(null, Vec3D.ZERO, Vec3D.ZERO, 0.0F, 0.0F, false, false, Set.of(), DO_NOTHING, cause); ++ } ++ // CraftBukkit end + + public static final TeleportTransition.a DO_NOTHING = (entity) -> { + }; +@@ -17,15 +29,33 @@ + public static final TeleportTransition.a PLACE_PORTAL_TICKET = TeleportTransition::placePortalTicket; + + public TeleportTransition(WorldServer worldserver, Vec3D vec3d, Vec3D vec3d1, float f, float f1, TeleportTransition.a teleporttransition_a) { +- this(worldserver, vec3d, vec3d1, f, f1, Set.of(), teleporttransition_a); ++ // CraftBukkit start ++ this(worldserver, vec3d, vec3d1, f, f1, teleporttransition_a, PlayerTeleportEvent.TeleportCause.UNKNOWN); ++ } ++ ++ public TeleportTransition(WorldServer worldserver, Vec3D vec3d, Vec3D vec3d1, float f, float f1, TeleportTransition.a teleporttransition_a, PlayerTeleportEvent.TeleportCause cause) { ++ this(worldserver, vec3d, vec3d1, f, f1, Set.of(), teleporttransition_a, cause); ++ // CraftBukkit end + } + + public TeleportTransition(WorldServer worldserver, Vec3D vec3d, Vec3D vec3d1, float f, float f1, Set set, TeleportTransition.a teleporttransition_a) { +- this(worldserver, vec3d, vec3d1, f, f1, false, false, set, teleporttransition_a); ++ // CraftBukkit start ++ this(worldserver, vec3d, vec3d1, f, f1, set, teleporttransition_a, PlayerTeleportEvent.TeleportCause.UNKNOWN); ++ } ++ ++ public TeleportTransition(WorldServer worldserver, Vec3D vec3d, Vec3D vec3d1, float f, float f1, Set set, TeleportTransition.a teleporttransition_a, PlayerTeleportEvent.TeleportCause cause) { ++ this(worldserver, vec3d, vec3d1, f, f1, false, false, set, teleporttransition_a, cause); ++ // CraftBukkit end + } + + public TeleportTransition(WorldServer worldserver, Entity entity, TeleportTransition.a teleporttransition_a) { +- this(worldserver, findAdjustedSharedSpawnPos(worldserver, entity), Vec3D.ZERO, 0.0F, 0.0F, false, false, Set.of(), teleporttransition_a); ++ // CraftBukkit start ++ this(worldserver, entity, teleporttransition_a, PlayerTeleportEvent.TeleportCause.UNKNOWN); ++ } ++ ++ public TeleportTransition(WorldServer worldserver, Entity entity, TeleportTransition.a teleporttransition_a, PlayerTeleportEvent.TeleportCause cause) { ++ this(worldserver, findAdjustedSharedSpawnPos(worldserver, entity), Vec3D.ZERO, 0.0F, 0.0F, false, false, Set.of(), teleporttransition_a, cause); ++ // CraftBukkit end + } + + private static void playPortalSound(Entity entity) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.patch b/paper-server/nms-patches/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.patch new file mode 100644 index 0000000000..c98450b075 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.patch @@ -0,0 +1,32 @@ +--- a/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java ++++ b/net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator.java +@@ -10,6 +10,11 @@ + import net.minecraft.world.level.block.BlockRedstoneWire; + import net.minecraft.world.level.block.state.IBlockData; + ++// CraftBukkit start ++import org.bukkit.craftbukkit.block.CraftBlock; ++import org.bukkit.event.block.BlockRedstoneEvent; ++// CraftBukkit end ++ + public class DefaultRedstoneWireEvaluator extends RedstoneWireEvaluator { + + public DefaultRedstoneWireEvaluator(BlockRedstoneWire blockredstonewire) { +@@ -20,7 +25,16 @@ + public void updatePowerStrength(World world, BlockPosition blockposition, IBlockData iblockdata, @Nullable Orientation orientation, boolean flag) { + int i = this.calculateTargetStrength(world, blockposition); + +- if ((Integer) iblockdata.getValue(BlockRedstoneWire.POWER) != i) { ++ // CraftBukkit start ++ int oldPower = iblockdata.getValue(BlockRedstoneWire.POWER); ++ if (oldPower != i) { ++ BlockRedstoneEvent event = new BlockRedstoneEvent(CraftBlock.at(world, blockposition), oldPower, i); ++ world.getCraftServer().getPluginManager().callEvent(event); ++ ++ i = event.getNewCurrent(); ++ } ++ if (oldPower != i) { ++ // CraftBukkit end + if (world.getBlockState(blockposition) == iblockdata) { + world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockRedstoneWire.POWER, i), 2); + } diff --git a/paper-server/nms-patches/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.patch b/paper-server/nms-patches/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.patch new file mode 100644 index 0000000000..1639970766 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.patch @@ -0,0 +1,32 @@ +--- a/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java ++++ b/net/minecraft/world/level/redstone/ExperimentalRedstoneWireEvaluator.java +@@ -17,6 +17,11 @@ + import net.minecraft.world.level.block.state.properties.BlockPropertyRedstoneSide; + import net.minecraft.world.level.block.state.properties.BlockStateEnum; + ++// CraftBukkit start ++import org.bukkit.craftbukkit.block.CraftBlock; ++import org.bukkit.event.block.BlockRedstoneEvent; ++// CraftBukkit end ++ + public class ExperimentalRedstoneWireEvaluator extends RedstoneWireEvaluator { + + private final Deque wiresToTurnOff = new ArrayDeque(); +@@ -41,7 +46,16 @@ + int j = unpackPower(i); + IBlockData iblockdata1 = world.getBlockState(blockposition1); + +- if (iblockdata1.is((Block) this.wireBlock) && !((Integer) iblockdata1.getValue(BlockRedstoneWire.POWER)).equals(j)) { ++ // CraftBukkit start ++ int oldPower = iblockdata.getValue(BlockRedstoneWire.POWER); ++ if (oldPower != j) { ++ BlockRedstoneEvent event = new BlockRedstoneEvent(CraftBlock.at(world, blockposition1), oldPower, j); ++ world.getCraftServer().getPluginManager().callEvent(event); ++ ++ j = event.getNewCurrent(); ++ } ++ if (iblockdata1.is((Block) this.wireBlock) && oldPower != j) { ++ // CraftBukkit end + int k = 2; + + if (!flag || !flag1) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/redstone/NeighborUpdater.patch b/paper-server/nms-patches/net/minecraft/world/level/redstone/NeighborUpdater.patch index ad8bebcf1f..3d8cac6f43 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/redstone/NeighborUpdater.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/redstone/NeighborUpdater.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/level/redstone/NeighborUpdater.java +++ b/net/minecraft/world/level/redstone/NeighborUpdater.java -@@ -12,6 +12,13 @@ - import net.minecraft.world.level.World; +@@ -13,6 +13,13 @@ import net.minecraft.world.level.block.Block; + import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.IBlockData; +// CraftBukkit start +import net.minecraft.server.level.WorldServer; @@ -14,14 +14,14 @@ public interface NeighborUpdater { -@@ -46,6 +53,17 @@ +@@ -50,6 +57,17 @@ - static void executeUpdate(World world, IBlockData iblockdata, BlockPosition blockposition, Block block, BlockPosition blockposition1, boolean flag) { + static void executeUpdate(World world, IBlockData iblockdata, BlockPosition blockposition, Block block, @Nullable Orientation orientation, boolean flag) { try { + // CraftBukkit start + CraftWorld cworld = ((WorldServer) world).getWorld(); + if (cworld != null) { -+ BlockPhysicsEvent event = new BlockPhysicsEvent(CraftBlock.at(world, blockposition), CraftBlockData.fromData(iblockdata), CraftBlock.at(world, blockposition1)); ++ BlockPhysicsEvent event = new BlockPhysicsEvent(CraftBlock.at(world, blockposition), CraftBlockData.fromData(iblockdata)); + ((WorldServer) world).getCraftServer().getPluginManager().callEvent(event); + + if (event.isCancelled()) { @@ -29,6 +29,6 @@ + } + } + // CraftBukkit end - iblockdata.handleNeighborChanged(world, blockposition, block, blockposition1, flag); + iblockdata.handleNeighborChanged(world, blockposition, block, orientation, flag); } catch (Throwable throwable) { CrashReport crashreport = CrashReport.forThrowable(throwable, "Exception while updating neighbours"); diff --git a/paper-server/nms-patches/net/minecraft/world/level/saveddata/maps/WorldMap.patch b/paper-server/nms-patches/net/minecraft/world/level/saveddata/maps/WorldMap.patch index 9aa14f1c1b..88ce770f53 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/saveddata/maps/WorldMap.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/saveddata/maps/WorldMap.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/saveddata/maps/WorldMap.java +++ b/net/minecraft/world/level/saveddata/maps/WorldMap.java -@@ -44,6 +44,17 @@ +@@ -47,6 +47,17 @@ import net.minecraft.world.level.saveddata.PersistentBase; import org.slf4j.Logger; @@ -18,7 +18,7 @@ public class WorldMap extends PersistentBase { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -67,6 +78,13 @@ +@@ -70,6 +81,13 @@ private final Map frameMarkers = Maps.newHashMap(); private int trackedDecorationCount; @@ -32,10 +32,10 @@ public static PersistentBase.a factory() { return new PersistentBase.a<>(() -> { throw new IllegalStateException("Should never create an empty map saved data"); -@@ -82,6 +100,10 @@ +@@ -84,6 +102,10 @@ + this.trackingPosition = flag; this.unlimitedTracking = flag1; this.locked = flag2; - this.setDirty(); + // CraftBukkit start + mapView = new CraftMapView(this); + server = (CraftServer) org.bukkit.Bukkit.getServer(); @@ -43,7 +43,7 @@ } public static WorldMap createFresh(double d0, double d1, byte b0, boolean flag, boolean flag1, ResourceKey resourcekey) { -@@ -99,12 +121,30 @@ +@@ -101,12 +123,30 @@ } public static WorldMap load(NBTTagCompound nbttagcompound, HolderLookup.a holderlookup_a) { @@ -77,7 +77,7 @@ }); int i = nbttagcompound.getInt("xCenter"); int j = nbttagcompound.getInt("zCenter"); -@@ -129,7 +169,8 @@ +@@ -131,7 +171,8 @@ MapIconBanner mapiconbanner = (MapIconBanner) iterator.next(); worldmap.bannerMarkers.put(mapiconbanner.getId(), mapiconbanner); @@ -87,7 +87,7 @@ } NBTTagList nbttaglist = nbttagcompound.getList("frames", 10); -@@ -148,13 +189,32 @@ +@@ -150,13 +191,32 @@ @Override public NBTTagCompound save(NBTTagCompound nbttagcompound, HolderLookup.a holderlookup_a) { @@ -121,7 +121,7 @@ nbttagcompound.putInt("xCenter", this.centerX); nbttagcompound.putInt("zCenter", this.centerZ); nbttagcompound.putByte("scale", this.scale); -@@ -409,7 +469,7 @@ +@@ -443,7 +503,7 @@ if (!this.isTrackedCountOverLimit(256)) { this.bannerMarkers.put(mapiconbanner.getId(), mapiconbanner); @@ -130,16 +130,16 @@ return true; } } -@@ -519,7 +579,7 @@ +@@ -554,7 +614,7 @@ this.player = entityhuman; } -- private WorldMap.b createPatch() { -+ private WorldMap.b createPatch(byte[] buffer) { // CraftBukkit +- private WorldMap.c createPatch() { ++ private WorldMap.c createPatch(byte[] buffer) { // CraftBukkit int i = this.minDirtyX; int j = this.minDirtyY; int k = this.maxDirtyX + 1 - this.minDirtyX; -@@ -528,7 +588,7 @@ +@@ -563,7 +623,7 @@ for (int i1 = 0; i1 < k; ++i1) { for (int j1 = 0; j1 < l; ++j1) { @@ -148,18 +148,18 @@ } } -@@ -538,19 +598,29 @@ +@@ -573,19 +633,29 @@ @Nullable Packet nextUpdatePacket(MapId mapid) { - WorldMap.b worldmap_b; + WorldMap.c worldmap_c; + org.bukkit.craftbukkit.map.RenderData render = WorldMap.this.mapView.render((org.bukkit.craftbukkit.entity.CraftPlayer) this.player.getBukkitEntity()); // CraftBukkit if (this.dirtyData) { this.dirtyData = false; -- worldmap_b = this.createPatch(); -+ worldmap_b = this.createPatch(render.buffer); // CraftBukkit +- worldmap_c = this.createPatch(); ++ worldmap_c = this.createPatch(render.buffer); // CraftBukkit } else { - worldmap_b = null; + worldmap_c = null; } Collection collection; diff --git a/paper-server/nms-patches/net/minecraft/world/level/storage/Convertable.patch b/paper-server/nms-patches/net/minecraft/world/level/storage/Convertable.patch index da71086f1a..c2b8131482 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/storage/Convertable.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/storage/Convertable.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/storage/Convertable.java +++ b/net/minecraft/world/level/storage/Convertable.java -@@ -77,6 +77,10 @@ +@@ -78,6 +78,10 @@ import net.minecraft.world.level.validation.PathAllowList; import org.slf4j.Logger; @@ -11,7 +11,7 @@ public class Convertable { static final Logger LOGGER = LogUtils.getLogger(); -@@ -148,7 +152,7 @@ +@@ -149,7 +153,7 @@ } public static WorldDataConfiguration readDataConfig(Dynamic dynamic) { @@ -20,9 +20,9 @@ Logger logger = Convertable.LOGGER; Objects.requireNonNull(logger); -@@ -167,6 +171,7 @@ +@@ -168,6 +172,7 @@ WorldDimensions.b worlddimensions_b = generatorsettings.dimensions().bake(iregistry); - Lifecycle lifecycle = worlddimensions_b.lifecycle().add(iregistrycustom_dimension.allRegistriesLifecycle()); + Lifecycle lifecycle = worlddimensions_b.lifecycle().add(holderlookup_a.allRegistriesLifecycle()); WorldDataServer worlddataserver = WorldDataServer.parse(dynamic1, worldsettings, worlddimensions_b.specialWorldProperty(), generatorsettings.options(), lifecycle); + worlddataserver.pdc = ((Dynamic) dynamic1).getElement("BukkitValues", null); // CraftBukkit - Add PDC to world diff --git a/paper-server/nms-patches/net/minecraft/world/level/storage/WorldDataServer.patch b/paper-server/nms-patches/net/minecraft/world/level/storage/WorldDataServer.patch index 12b9022034..cf2dffac97 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/storage/WorldDataServer.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/storage/WorldDataServer.patch @@ -73,7 +73,7 @@ GameProfileSerializer.addCurrentDataVersion(nbttagcompound); DynamicOps dynamicops = iregistrycustom.createSerializationContext(DynamicOpsNBT.INSTANCE); - DataResult dataresult = GeneratorSettings.encode(dynamicops, this.worldOptions, iregistrycustom); -+ DataResult dataresult = GeneratorSettings.encode(dynamicops, this.worldOptions, new WorldDimensions(this.customDimensions != null ? this.customDimensions : iregistrycustom.registryOrThrow(Registries.LEVEL_STEM))); // CraftBukkit ++ DataResult dataresult = GeneratorSettings.encode(dynamicops, this.worldOptions, new WorldDimensions(this.customDimensions != null ? this.customDimensions : iregistrycustom.lookupOrThrow(Registries.LEVEL_STEM))); // CraftBukkit Logger logger = WorldDataServer.LOGGER; Objects.requireNonNull(logger); diff --git a/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootDataType.patch b/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootDataType.patch index 56748563b5..86e7c6ff30 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootDataType.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootDataType.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/level/storage/loot/LootDataType.java +++ b/net/minecraft/world/level/storage/loot/LootDataType.java -@@ -15,6 +15,11 @@ +@@ -9,6 +9,11 @@ + import net.minecraft.world.level.storage.loot.functions.LootItemFunctions; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; - import org.slf4j.Logger; +// CraftBukkit start +import org.bukkit.craftbukkit.CraftLootTable; @@ -11,11 +11,11 @@ + public record LootDataType(ResourceKey> registryKey, Codec codec, LootDataType.a validator) { - private static final Logger LOGGER = LogUtils.getLogger(); -@@ -48,6 +53,7 @@ + public static final LootDataType PREDICATE = new LootDataType<>(Registries.PREDICATE, LootItemCondition.DIRECT_CODEC, createSimpleValidator()); +@@ -32,6 +37,7 @@ private static LootDataType.a createLootTableValidator() { return (lootcollector, resourcekey, loottable) -> { - loottable.validate(lootcollector.setParams(loottable.getParamSet()).enterElement("{" + String.valueOf(resourcekey.registry()) + "/" + String.valueOf(resourcekey.location()) + "}", resourcekey)); + loottable.validate(lootcollector.setContextKeySet(loottable.getParamSet()).enterElement("{" + String.valueOf(resourcekey.registry()) + "/" + String.valueOf(resourcekey.location()) + "}", resourcekey)); + loottable.craftLootTable = new CraftLootTable(CraftNamespacedKey.fromMinecraft(resourcekey.location()), loottable); // CraftBukkit }; } diff --git a/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootTable.patch b/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootTable.patch index 3b5177ef01..827b4ca441 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootTable.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootTable.patch @@ -20,8 +20,8 @@ private final BiFunction compositeFunction; + public CraftLootTable craftLootTable; // CraftBukkit - LootTable(LootContextParameterSet lootcontextparameterset, Optional optional, List list, List list1) { - this.paramSet = lootcontextparameterset; + LootTable(ContextKeySet contextkeyset, Optional optional, List list, List list1) { + this.paramSet = contextkeyset; @@ -157,9 +165,22 @@ } diff --git a/paper-server/nms-patches/net/minecraft/world/level/storage/loot/predicates/LootItemConditionSurvivesExplosion.patch b/paper-server/nms-patches/net/minecraft/world/level/storage/loot/predicates/LootItemConditionSurvivesExplosion.patch index d0a4a03dbb..48c4a881b6 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/storage/loot/predicates/LootItemConditionSurvivesExplosion.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/storage/loot/predicates/LootItemConditionSurvivesExplosion.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/storage/loot/predicates/LootItemConditionSurvivesExplosion.java +++ b/net/minecraft/world/level/storage/loot/predicates/LootItemConditionSurvivesExplosion.java -@@ -32,7 +32,8 @@ +@@ -31,7 +31,8 @@ RandomSource randomsource = loottableinfo.getRandom(); float f = 1.0F / ofloat; diff --git a/paper-server/pom.xml b/paper-server/pom.xml index 1ed5ad2f4e..a228e5f615 100644 --- a/paper-server/pom.xml +++ b/paper-server/pom.xml @@ -4,7 +4,7 @@ org.bukkit craftbukkit jar - 1.21.1-R0.1-SNAPSHOT + 1.21.2-R0.1-SNAPSHOT CraftBukkit https://www.spigotmc.org/ @@ -14,7 +14,7 @@ UTF-8 unknown git - 1_21_R1 + 1_21_R2 21 @@ -57,23 +57,53 @@ 9.7.1 compile - + + + com.fasterxml.jackson.core + jackson-annotations + 2.13.4 + compile + + + com.fasterxml.jackson.core + jackson-core + 2.13.4 + compile + + + com.fasterxml.jackson.core + jackson-databind + 2.13.4.2 + compile + com.github.oshi oshi-core 6.4.10 compile + + com.github.stephenc.jcip + jcip-annotations + 1.0-1 + compile + + + com.microsoft.azure + msal4j + 1.15.0 + compile + com.mojang authlib - 6.0.54 + 6.0.55 compile com.mojang brigadier - 1.2.9 + 1.3.10 compile @@ -82,10 +112,40 @@ 8.0.16 compile + + com.mojang + jtracy + 1.0.29 + compile + com.mojang logging - 1.2.7 + 1.4.9 + compile + + + com.nimbusds + content-type + 2.3 + compile + + + com.nimbusds + lang-tag + 1.7 + compile + + + com.nimbusds + nimbus-jose-jwt + 9.37.3 + compile + + + com.nimbusds + oauth2-oidc-sdk + 11.9.1 compile @@ -174,6 +234,18 @@ 5.14.0 compile + + net.minidev + accessors-smart + 2.5.0 + compile + + + net.minidev + json-smart + 2.5.0 + compile + net.sf.jopt-simple jopt-simple @@ -186,6 +258,12 @@ 3.14.0 compile + + org.apache.logging.log4j + log4j-api + 2.22.1 + compile + org.apache.logging.log4j log4j-core @@ -198,18 +276,19 @@ 2.22.1 compile - - org.slf4j - slf4j-api - 2.0.9 - compile - org.lz4 lz4-java 1.8.0 compile + + org.slf4j + slf4j-api + 2.0.9 + compile + + commons-lang @@ -233,13 +312,13 @@ org.xerial sqlite-jdbc - 3.46.0.0 + 3.46.1.3 runtime com.mysql mysql-connector-j - 8.4.0 + 9.1.0 runtime diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java index 4271f0a9c8..b786d5aefb 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java @@ -17,7 +17,7 @@ import net.minecraft.core.registries.Registries; import net.minecraft.nbt.DynamicOpsNBT; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.level.WorldServer; -import net.minecraft.util.thread.ThreadedMailbox; +import net.minecraft.util.thread.ConsecutiveExecutor; import net.minecraft.world.level.ChunkCoordIntPair; import net.minecraft.world.level.EnumSkyBlock; import net.minecraft.world.level.biome.BiomeBase; @@ -31,8 +31,8 @@ import net.minecraft.world.level.chunk.NibbleArray; import net.minecraft.world.level.chunk.PalettedContainerRO; import net.minecraft.world.level.chunk.ProtoChunkExtension; import net.minecraft.world.level.chunk.status.ChunkStatus; -import net.minecraft.world.level.chunk.storage.ChunkRegionLoader; import net.minecraft.world.level.chunk.storage.EntityStorage; +import net.minecraft.world.level.chunk.storage.SerializableChunkData; import net.minecraft.world.level.entity.PersistentEntitySectionManager; import net.minecraft.world.level.levelgen.HeightMap; import net.minecraft.world.level.levelgen.SeededRandom; @@ -111,7 +111,7 @@ public class CraftChunk implements Chunk { @Override public Block getBlock(int x, int y, int z) { - validateChunkCoordinates(worldServer.getMinBuildHeight(), worldServer.getMaxBuildHeight(), x, y, z); + validateChunkCoordinates(worldServer.getMinY(), worldServer.getMaxY(), x, y, z); return new CraftBlock(worldServer, new BlockPosition((this.x << 4) | x, y, (this.z << 4) | z)); } @@ -139,7 +139,7 @@ public class CraftChunk implements Chunk { entityManager.ensureChunkQueuedForLoad(pair); // Start entity loading // SPIGOT-6772: Use entity mailbox and re-schedule entities if they get unloaded - ThreadedMailbox mailbox = ((EntityStorage) entityManager.permanentStorage).entityDeserializerQueue; + ConsecutiveExecutor mailbox = ((EntityStorage) entityManager.permanentStorage).entityDeserializerQueue; BooleanSupplier supplier = () -> { // only execute inbox if our entities are not present if (entityManager.areEntitiesLoaded(pair)) { @@ -310,14 +310,14 @@ public class CraftChunk implements Chunk { boolean[] sectionEmpty = new boolean[cs.length]; PalettedContainerRO>[] biome = (includeBiome || includeBiomeTempRain) ? new DataPaletteBlock[cs.length] : null; - IRegistry iregistry = worldServer.registryAccess().registryOrThrow(Registries.BIOME); - Codec>> biomeCodec = DataPaletteBlock.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), DataPaletteBlock.d.SECTION_BIOMES, iregistry.getHolderOrThrow(Biomes.PLAINS)); + IRegistry iregistry = worldServer.registryAccess().lookupOrThrow(Registries.BIOME); + Codec>> biomeCodec = DataPaletteBlock.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), DataPaletteBlock.d.SECTION_BIOMES, iregistry.getOrThrow(Biomes.PLAINS)); for (int i = 0; i < cs.length; i++) { NBTTagCompound data = new NBTTagCompound(); - data.put("block_states", ChunkRegionLoader.BLOCK_STATE_CODEC.encodeStart(DynamicOpsNBT.INSTANCE, cs[i].getStates()).getOrThrow()); - sectionBlockIDs[i] = ChunkRegionLoader.BLOCK_STATE_CODEC.parse(DynamicOpsNBT.INSTANCE, data.getCompound("block_states")).getOrThrow(ChunkRegionLoader.a::new); + data.put("block_states", SerializableChunkData.BLOCK_STATE_CODEC.encodeStart(DynamicOpsNBT.INSTANCE, cs[i].getStates()).getOrThrow()); + sectionBlockIDs[i] = SerializableChunkData.BLOCK_STATE_CODEC.parse(DynamicOpsNBT.INSTANCE, data.getCompound("block_states")).getOrThrow(SerializableChunkData.a::new); sectionEmpty[i] = cs[i].hasOnlyAir(); LevelLightEngine lightengine = worldServer.getLightEngine(); @@ -338,7 +338,7 @@ public class CraftChunk implements Chunk { if (biome != null) { data.put("biomes", biomeCodec.encodeStart(DynamicOpsNBT.INSTANCE, cs[i].getBiomes()).getOrThrow()); - biome[i] = biomeCodec.parse(DynamicOpsNBT.INSTANCE, data.getCompound("biomes")).getOrThrow(ChunkRegionLoader.a::new); + biome[i] = biomeCodec.parse(DynamicOpsNBT.INSTANCE, data.getCompound("biomes")).getOrThrow(SerializableChunkData.a::new); } } @@ -350,7 +350,7 @@ public class CraftChunk implements Chunk { } World world = getWorld(); - return new CraftChunkSnapshot(getX(), getZ(), chunk.getMinBuildHeight(), chunk.getMaxBuildHeight(), world.getName(), world.getFullTime(), sectionBlockIDs, sectionSkyLights, sectionEmitLights, sectionEmpty, hmap, iregistry, biome); + return new CraftChunkSnapshot(getX(), getZ(), chunk.getMinY(), chunk.getMaxY(), world.getSeaLevel(), world.getName(), world.getFullTime(), sectionBlockIDs, sectionSkyLights, sectionEmitLights, sectionEmpty, hmap, iregistry, biome); } @Override @@ -411,9 +411,9 @@ public class CraftChunk implements Chunk { byte[][] skyLight = new byte[hSection][]; byte[][] emitLight = new byte[hSection][]; boolean[] empty = new boolean[hSection]; - IRegistry iregistry = world.getHandle().registryAccess().registryOrThrow(Registries.BIOME); + IRegistry iregistry = world.getHandle().registryAccess().lookupOrThrow(Registries.BIOME); DataPaletteBlock>[] biome = (includeBiome || includeBiomeTempRain) ? new DataPaletteBlock[hSection] : null; - Codec>> biomeCodec = DataPaletteBlock.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), DataPaletteBlock.d.SECTION_BIOMES, iregistry.getHolderOrThrow(Biomes.PLAINS)); + Codec>> biomeCodec = DataPaletteBlock.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), DataPaletteBlock.d.SECTION_BIOMES, iregistry.getOrThrow(Biomes.PLAINS)); for (int i = 0; i < hSection; i++) { blockIDs[i] = emptyBlockIDs; @@ -422,11 +422,11 @@ public class CraftChunk implements Chunk { empty[i] = true; if (biome != null) { - biome[i] = (DataPaletteBlock>) biomeCodec.parse(DynamicOpsNBT.INSTANCE, biomeCodec.encodeStart(DynamicOpsNBT.INSTANCE, actual.getSection(i).getBiomes()).getOrThrow()).getOrThrow(ChunkRegionLoader.a::new); + biome[i] = (DataPaletteBlock>) biomeCodec.parse(DynamicOpsNBT.INSTANCE, biomeCodec.encodeStart(DynamicOpsNBT.INSTANCE, actual.getSection(i).getBiomes()).getOrThrow()).getOrThrow(SerializableChunkData.a::new); } } - return new CraftChunkSnapshot(x, z, world.getMinHeight(), world.getMaxHeight(), world.getName(), world.getFullTime(), blockIDs, skyLight, emitLight, empty, new HeightMap(actual, HeightMap.Type.MOTION_BLOCKING), iregistry, biome); + return new CraftChunkSnapshot(x, z, world.getMinHeight(), world.getMaxHeight(), world.getSeaLevel(), world.getName(), world.getFullTime(), blockIDs, skyLight, emitLight, empty, new HeightMap(actual, HeightMap.Type.MOTION_BLOCKING), iregistry, biome); } static void validateChunkCoordinates(int minY, int maxY, int x, int y, int z) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java index c8852808f6..971b5fd152 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java @@ -26,7 +26,7 @@ import org.bukkit.craftbukkit.util.CraftMagicNumbers; */ public class CraftChunkSnapshot implements ChunkSnapshot { private final int x, z; - private final int minHeight, maxHeight; + private final int minHeight, maxHeight, seaLevel; private final String worldname; private final DataPaletteBlock[] blockids; private final byte[][] skylight; @@ -37,11 +37,12 @@ public class CraftChunkSnapshot implements ChunkSnapshot { private final IRegistry biomeRegistry; private final PalettedContainerRO>[] biome; - CraftChunkSnapshot(int x, int z, int minHeight, int maxHeight, String wname, long wtime, DataPaletteBlock[] sectionBlockIDs, byte[][] sectionSkyLights, byte[][] sectionEmitLights, boolean[] sectionEmpty, HeightMap hmap, IRegistry biomeRegistry, PalettedContainerRO>[] biome) { + CraftChunkSnapshot(int x, int z, int minHeight, int maxHeight, int seaLevel, String wname, long wtime, DataPaletteBlock[] sectionBlockIDs, byte[][] sectionSkyLights, byte[][] sectionEmitLights, boolean[] sectionEmpty, HeightMap hmap, IRegistry biomeRegistry, PalettedContainerRO>[] biome) { this.x = x; this.z = z; this.minHeight = minHeight; this.maxHeight = maxHeight; + this.seaLevel = seaLevel; this.worldname = wname; this.captureFulltime = wtime; this.blockids = sectionBlockIDs; @@ -166,7 +167,7 @@ public class CraftChunkSnapshot implements ChunkSnapshot { validateChunkCoordinates(x, y, z); PalettedContainerRO> biome = this.biome[getSectionIndex(y)]; // SPIGOT-7188: Don't need to convert y to biome coordinate scale since it is bound to the block chunk section - return biome.get(x >> 2, (y & 0xF) >> 2, z >> 2).value().getTemperature(new BlockPosition((this.x << 4) | x, y, (this.z << 4) | z)); + return biome.get(x >> 2, (y & 0xF) >> 2, z >> 2).value().getTemperature(new BlockPosition((this.x << 4) | x, y, (this.z << 4) | z), seaLevel); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java index 74b48a48e4..f8de98e034 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java @@ -9,14 +9,14 @@ import net.minecraft.core.registries.Registries; import net.minecraft.resources.MinecraftKey; import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.WorldServer; +import net.minecraft.util.context.ContextKey; +import net.minecraft.util.context.ContextKeySet; import net.minecraft.world.IInventory; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.EntityHuman; import net.minecraft.world.level.storage.loot.LootParams; import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.level.storage.loot.LootTableInfo; -import net.minecraft.world.level.storage.loot.parameters.LootContextParameter; -import net.minecraft.world.level.storage.loot.parameters.LootContextParameterSet; import net.minecraft.world.level.storage.loot.parameters.LootContextParameters; import net.minecraft.world.phys.Vec3D; import org.bukkit.Bukkit; @@ -132,12 +132,12 @@ public class CraftLootTable implements org.bukkit.loot.LootTable { } // SPIGOT-5603 - Avoid IllegalArgumentException in LootTableInfo#build() - LootContextParameterSet.Builder nmsBuilder = new LootContextParameterSet.Builder(); - for (LootContextParameter param : getHandle().getParamSet().getRequired()) { + ContextKeySet.a nmsBuilder = new ContextKeySet.a(); + for (ContextKey param : getHandle().getParamSet().required()) { nmsBuilder.required(param); } - for (LootContextParameter param : getHandle().getParamSet().getAllowed()) { - if (!getHandle().getParamSet().getRequired().contains(param)) { + for (ContextKey param : getHandle().getParamSet().allowed()) { + if (!getHandle().getParamSet().required().contains(param)) { nmsBuilder.optional(param); } } @@ -145,29 +145,29 @@ public class CraftLootTable implements org.bukkit.loot.LootTable { return builder.create(getHandle().getParamSet()); } - private void setMaybe(LootParams.a builder, LootContextParameter param, T value) { - if (getHandle().getParamSet().getRequired().contains(param) || getHandle().getParamSet().getAllowed().contains(param)) { + private void setMaybe(LootParams.a builder, ContextKey param, T value) { + if (getHandle().getParamSet().required().contains(param) || getHandle().getParamSet().allowed().contains(param)) { builder.withParameter(param, value); } } public static LootContext convertContext(LootTableInfo info) { - Vec3D position = info.getParamOrNull(LootContextParameters.ORIGIN); + Vec3D position = info.getOptionalParameter(LootContextParameters.ORIGIN); if (position == null) { - position = info.getParamOrNull(LootContextParameters.THIS_ENTITY).position(); // Every vanilla context has origin or this_entity, see LootContextParameterSets + position = info.getOptionalParameter(LootContextParameters.THIS_ENTITY).position(); // Every vanilla context has origin or this_entity, see LootContextParameterSets } Location location = CraftLocation.toBukkit(position, info.getLevel().getWorld()); LootContext.Builder contextBuilder = new LootContext.Builder(location); - if (info.hasParam(LootContextParameters.ATTACKING_ENTITY)) { - CraftEntity killer = info.getParamOrNull(LootContextParameters.ATTACKING_ENTITY).getBukkitEntity(); + if (info.hasParameter(LootContextParameters.ATTACKING_ENTITY)) { + CraftEntity killer = info.getOptionalParameter(LootContextParameters.ATTACKING_ENTITY).getBukkitEntity(); if (killer instanceof CraftHumanEntity) { contextBuilder.killer((CraftHumanEntity) killer); } } - if (info.hasParam(LootContextParameters.THIS_ENTITY)) { - contextBuilder.lootedEntity(info.getParamOrNull(LootContextParameters.THIS_ENTITY).getBukkitEntity()); + if (info.hasParameter(LootContextParameters.THIS_ENTITY)) { + contextBuilder.lootedEntity(info.getOptionalParameter(LootContextParameters.THIS_ENTITY).getBukkitEntity()); } contextBuilder.luck(info.getLuck()); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java index bf1c5d0504..14364d6d0f 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java @@ -14,6 +14,7 @@ import net.minecraft.core.particles.ParticleParamRedstone; import net.minecraft.core.particles.ParticleType; import net.minecraft.core.particles.SculkChargeParticleOptions; import net.minecraft.core.particles.ShriekParticleOption; +import net.minecraft.core.particles.TargetColorParticleOption; import net.minecraft.core.particles.VibrationParticleOption; import net.minecraft.core.registries.Registries; import net.minecraft.world.entity.Entity; @@ -37,7 +38,6 @@ import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; -import org.joml.Vector3f; public abstract class CraftParticle implements Keyed { @@ -124,7 +124,7 @@ public abstract class CraftParticle implements Keyed { @Override public ParticleParam createParticleParam(Particle.DustOptions data) { Color color = data.getColor(); - return new ParticleParamRedstone(new Vector3f(color.getRed() / 255.0f, color.getGreen() / 255.0f, color.getBlue() / 255.0f), data.getSize()); + return new ParticleParamRedstone(color.asRGB(), data.getSize()); } }; @@ -147,7 +147,7 @@ public abstract class CraftParticle implements Keyed { public ParticleParam createParticleParam(Particle.DustTransition data) { Color from = data.getColor(); Color to = data.getToColor(); - return new DustColorTransitionOptions(new Vector3f(from.getRed() / 255.0f, from.getGreen() / 255.0f, from.getBlue() / 255.0f), new Vector3f(to.getRed() / 255.0f, to.getGreen() / 255.0f, to.getBlue() / 255.0f), data.getSize()); + return new DustColorTransitionOptions(from.asRGB(), to.asRGB(), data.getSize()); } }; @@ -190,6 +190,13 @@ public abstract class CraftParticle implements Keyed { } }; + BiFunction, CraftParticle> targetColorFunction = (name, particle) -> new CraftParticle<>(name, particle, Particle.TargetColor.class) { + @Override + public ParticleParam createParticleParam(Particle.TargetColor data) { + return new TargetColorParticleOption(CraftLocation.toVec3D(data.getTarget()), data.getColor().asRGB()); + } + }; + add("dust", dustOptionsFunction); add("item", itemStackFunction); add("block", blockDataFunction); @@ -201,6 +208,8 @@ public abstract class CraftParticle implements Keyed { add("block_marker", blockDataFunction); add("entity_effect", colorFunction); add("dust_pillar", blockDataFunction); + add("block_crumble", blockDataFunction); + add("trail", targetColorFunction); } private static void add(String name, BiFunction, CraftParticle> function) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java index 5d8e491cfa..2222b8a265 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java @@ -14,7 +14,7 @@ import net.minecraft.data.worldgen.features.TreeFeatures; import net.minecraft.resources.ResourceKey; import net.minecraft.util.RandomSource; import net.minecraft.world.entity.EntityInsentient; -import net.minecraft.world.entity.EnumMobSpawn; +import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.GroupDataEntity; import net.minecraft.world.entity.projectile.EntityPotion; import net.minecraft.world.level.GeneratorAccessSeed; @@ -24,7 +24,7 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.WorldGenFeatureConfigured; -import net.minecraft.world.level.portal.DimensionTransition; +import net.minecraft.world.level.portal.TeleportTransition; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.RegionAccessor; @@ -280,7 +280,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor { break; } - Holder> holder = access.registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).getHolder(gen).orElse(null); + Holder> holder = access.registryAccess().lookupOrThrow(Registries.CONFIGURED_FEATURE).get(gen).orElse(null); return (holder != null) ? holder.value().place(access, chunkGenerator, random, pos) : false; } @@ -419,7 +419,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor { Preconditions.checkArgument(!entity.isInWorld(), "Entity has already been added to a world"); net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle(); if (nmsEntity.level() != getHandle().getLevel()) { - nmsEntity = nmsEntity.changeDimension(new DimensionTransition(getHandle().getLevel(), nmsEntity, DimensionTransition.DO_NOTHING)); + nmsEntity = nmsEntity.teleport(new TeleportTransition(getHandle().getLevel(), nmsEntity, TeleportTransition.DO_NOTHING)); } addEntityWithPassengers(nmsEntity, CreatureSpawnEvent.SpawnReason.CUSTOM); @@ -436,7 +436,7 @@ public abstract class CraftRegionAccessor implements RegionAccessor { Preconditions.checkArgument(entity != null, "Cannot spawn null entity"); if (randomizeData && entity instanceof EntityInsentient) { - ((EntityInsentient) entity).finalizeSpawn(getHandle(), getHandle().getCurrentDifficultyAt(entity.blockPosition()), EnumMobSpawn.COMMAND, (GroupDataEntity) null); + ((EntityInsentient) entity).finalizeSpawn(getHandle(), getHandle().getCurrentDifficultyAt(entity.blockPosition()), EntitySpawnReason.COMMAND, (GroupDataEntity) null); } if (!isNormalWorld()) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java index 614f8fdeda..a0d0dfcc42 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java @@ -73,7 +73,7 @@ public class CraftRegistry implements Registry { } public static IRegistry getMinecraftRegistry(ResourceKey> key) { - return getMinecraftRegistry().registryOrThrow(key); + return getMinecraftRegistry().lookupOrThrow(key); } /** @@ -132,64 +132,64 @@ public class CraftRegistry implements Registry { */ public static Registry createRegistry(Class bukkitClass, IRegistryCustom registryHolder) { if (bukkitClass == Enchantment.class) { - return new CraftRegistry<>(Enchantment.class, registryHolder.registryOrThrow(Registries.ENCHANTMENT), CraftEnchantment::new, FieldRename.ENCHANTMENT_RENAME); + return new CraftRegistry<>(Enchantment.class, registryHolder.lookupOrThrow(Registries.ENCHANTMENT), CraftEnchantment::new, FieldRename.ENCHANTMENT_RENAME); } if (bukkitClass == GameEvent.class) { - return new CraftRegistry<>(GameEvent.class, registryHolder.registryOrThrow(Registries.GAME_EVENT), CraftGameEvent::new, FieldRename.NONE); + return new CraftRegistry<>(GameEvent.class, registryHolder.lookupOrThrow(Registries.GAME_EVENT), CraftGameEvent::new, FieldRename.NONE); } if (bukkitClass == MusicInstrument.class) { - return new CraftRegistry<>(MusicInstrument.class, registryHolder.registryOrThrow(Registries.INSTRUMENT), CraftMusicInstrument::new, FieldRename.NONE); + return new CraftRegistry<>(MusicInstrument.class, registryHolder.lookupOrThrow(Registries.INSTRUMENT), CraftMusicInstrument::new, FieldRename.NONE); } if (bukkitClass == MenuType.class) { - return new CraftRegistry<>(MenuType.class, registryHolder.registryOrThrow(Registries.MENU), CraftMenuType::new, FieldRename.NONE); + return new CraftRegistry<>(MenuType.class, registryHolder.lookupOrThrow(Registries.MENU), CraftMenuType::new, FieldRename.NONE); } if (bukkitClass == PotionEffectType.class) { - return new CraftRegistry<>(PotionEffectType.class, registryHolder.registryOrThrow(Registries.MOB_EFFECT), CraftPotionEffectType::new, FieldRename.NONE); + return new CraftRegistry<>(PotionEffectType.class, registryHolder.lookupOrThrow(Registries.MOB_EFFECT), CraftPotionEffectType::new, FieldRename.NONE); } if (bukkitClass == Structure.class) { - return new CraftRegistry<>(Structure.class, registryHolder.registryOrThrow(Registries.STRUCTURE), CraftStructure::new, FieldRename.NONE); + return new CraftRegistry<>(Structure.class, registryHolder.lookupOrThrow(Registries.STRUCTURE), CraftStructure::new, FieldRename.NONE); } if (bukkitClass == StructureType.class) { - return new CraftRegistry<>(StructureType.class, registryHolder.registryOrThrow(Registries.STRUCTURE_TYPE), CraftStructureType::new, FieldRename.NONE); + return new CraftRegistry<>(StructureType.class, registryHolder.lookupOrThrow(Registries.STRUCTURE_TYPE), CraftStructureType::new, FieldRename.NONE); } if (bukkitClass == Villager.Type.class) { - return new CraftRegistry<>(Villager.Type.class, registryHolder.registryOrThrow(Registries.VILLAGER_TYPE), CraftVillager.CraftType::new, FieldRename.NONE); + return new CraftRegistry<>(Villager.Type.class, registryHolder.lookupOrThrow(Registries.VILLAGER_TYPE), CraftVillager.CraftType::new, FieldRename.NONE); } if (bukkitClass == Villager.Profession.class) { - return new CraftRegistry<>(Villager.Profession.class, registryHolder.registryOrThrow(Registries.VILLAGER_PROFESSION), CraftVillager.CraftProfession::new, FieldRename.NONE); + return new CraftRegistry<>(Villager.Profession.class, registryHolder.lookupOrThrow(Registries.VILLAGER_PROFESSION), CraftVillager.CraftProfession::new, FieldRename.NONE); } if (bukkitClass == TrimMaterial.class) { - return new CraftRegistry<>(TrimMaterial.class, registryHolder.registryOrThrow(Registries.TRIM_MATERIAL), CraftTrimMaterial::new, FieldRename.NONE); + return new CraftRegistry<>(TrimMaterial.class, registryHolder.lookupOrThrow(Registries.TRIM_MATERIAL), CraftTrimMaterial::new, FieldRename.NONE); } if (bukkitClass == TrimPattern.class) { - return new CraftRegistry<>(TrimPattern.class, registryHolder.registryOrThrow(Registries.TRIM_PATTERN), CraftTrimPattern::new, FieldRename.NONE); + return new CraftRegistry<>(TrimPattern.class, registryHolder.lookupOrThrow(Registries.TRIM_PATTERN), CraftTrimPattern::new, FieldRename.NONE); } if (bukkitClass == DamageType.class) { - return new CraftRegistry<>(DamageType.class, registryHolder.registryOrThrow(Registries.DAMAGE_TYPE), CraftDamageType::new, FieldRename.NONE); + return new CraftRegistry<>(DamageType.class, registryHolder.lookupOrThrow(Registries.DAMAGE_TYPE), CraftDamageType::new, FieldRename.NONE); } if (bukkitClass == JukeboxSong.class) { - return new CraftRegistry<>(JukeboxSong.class, registryHolder.registryOrThrow(Registries.JUKEBOX_SONG), CraftJukeboxSong::new, FieldRename.NONE); + return new CraftRegistry<>(JukeboxSong.class, registryHolder.lookupOrThrow(Registries.JUKEBOX_SONG), CraftJukeboxSong::new, FieldRename.NONE); } if (bukkitClass == Wolf.Variant.class) { - return new CraftRegistry<>(Wolf.Variant.class, registryHolder.registryOrThrow(Registries.WOLF_VARIANT), CraftWolf.CraftVariant::new, FieldRename.NONE); + return new CraftRegistry<>(Wolf.Variant.class, registryHolder.lookupOrThrow(Registries.WOLF_VARIANT), CraftWolf.CraftVariant::new, FieldRename.NONE); } if (bukkitClass == BlockType.class) { - return new CraftRegistry<>(BlockType.class, registryHolder.registryOrThrow(Registries.BLOCK), CraftBlockType::new, FieldRename.NONE); + return new CraftRegistry<>(BlockType.class, registryHolder.lookupOrThrow(Registries.BLOCK), CraftBlockType::new, FieldRename.NONE); } if (bukkitClass == ItemType.class) { - return new CraftRegistry<>(ItemType.class, registryHolder.registryOrThrow(Registries.ITEM), CraftItemType::new, FieldRename.NONE); + return new CraftRegistry<>(ItemType.class, registryHolder.lookupOrThrow(Registries.ITEM), CraftItemType::new, FieldRename.NONE); } if (bukkitClass == Frog.Variant.class) { - return new CraftRegistry<>(Frog.Variant.class, registryHolder.registryOrThrow(Registries.FROG_VARIANT), CraftFrog.CraftVariant::new, FieldRename.NONE); + return new CraftRegistry<>(Frog.Variant.class, registryHolder.lookupOrThrow(Registries.FROG_VARIANT), CraftFrog.CraftVariant::new, FieldRename.NONE); } if (bukkitClass == Cat.Type.class) { - return new CraftRegistry<>(Cat.Type.class, registryHolder.registryOrThrow(Registries.CAT_VARIANT), CraftCat.CraftType::new, FieldRename.NONE); + return new CraftRegistry<>(Cat.Type.class, registryHolder.lookupOrThrow(Registries.CAT_VARIANT), CraftCat.CraftType::new, FieldRename.NONE); } if (bukkitClass == MapCursor.Type.class) { - return new CraftRegistry<>(MapCursor.Type.class, registryHolder.registryOrThrow(Registries.MAP_DECORATION_TYPE), CraftMapCursor.CraftType::new, FieldRename.NONE); + return new CraftRegistry<>(MapCursor.Type.class, registryHolder.lookupOrThrow(Registries.MAP_DECORATION_TYPE), CraftMapCursor.CraftType::new, FieldRename.NONE); } if (bukkitClass == PatternType.class) { - return new CraftRegistry<>(PatternType.class, registryHolder.registryOrThrow(Registries.BANNER_PATTERN), CraftPatternType::new, FieldRename.NONE); + return new CraftRegistry<>(PatternType.class, registryHolder.lookupOrThrow(Registries.BANNER_PATTERN), CraftPatternType::new, FieldRename.NONE); } return null; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java index abf3a28010..0217535a2b 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -51,7 +51,6 @@ import net.minecraft.commands.arguments.ArgumentEntity; import net.minecraft.core.BlockPosition; import net.minecraft.core.IRegistry; import net.minecraft.core.IRegistryCustom; -import net.minecraft.core.NonNullList; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.NbtException; @@ -80,6 +79,7 @@ import net.minecraft.tags.TagKey; import net.minecraft.util.ChatDeserializer; import net.minecraft.util.datafix.DataConverterRegistry; import net.minecraft.world.EnumDifficulty; +import net.minecraft.world.damagesource.DamageType; import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.entity.ai.village.VillageSiege; import net.minecraft.world.entity.npc.MobSpawnerCat; @@ -180,6 +180,7 @@ import org.bukkit.craftbukkit.inventory.CraftSmithingTransformRecipe; import org.bukkit.craftbukkit.inventory.CraftSmithingTrimRecipe; import org.bukkit.craftbukkit.inventory.CraftSmokingRecipe; import org.bukkit.craftbukkit.inventory.CraftStonecuttingRecipe; +import org.bukkit.craftbukkit.inventory.CraftTransmuteRecipe; import org.bukkit.craftbukkit.inventory.RecipeIterator; import org.bukkit.craftbukkit.inventory.util.CraftInventoryCreator; import org.bukkit.craftbukkit.map.CraftMapColorCache; @@ -196,6 +197,7 @@ import org.bukkit.craftbukkit.scoreboard.CraftCriteria; import org.bukkit.craftbukkit.scoreboard.CraftScoreboardManager; import org.bukkit.craftbukkit.structure.CraftStructureManager; import org.bukkit.craftbukkit.tag.CraftBlockTag; +import org.bukkit.craftbukkit.tag.CraftDamageTag; import org.bukkit.craftbukkit.tag.CraftEntityTag; import org.bukkit.craftbukkit.tag.CraftFluidTag; import org.bukkit.craftbukkit.tag.CraftItemTag; @@ -240,6 +242,7 @@ import org.bukkit.inventory.SmithingTransformRecipe; import org.bukkit.inventory.SmithingTrimRecipe; import org.bukkit.inventory.SmokingRecipe; import org.bukkit.inventory.StonecuttingRecipe; +import org.bukkit.inventory.TransmuteRecipe; import org.bukkit.loot.LootTable; import org.bukkit.map.MapPalette; import org.bukkit.map.MapView; @@ -946,7 +949,7 @@ public final class CraftServer implements Server { for (WorldServer world : console.getAllLevels()) { world.serverLevelData.setDifficulty(config.difficulty); - world.setSpawnSettings(config.spawnMonsters, config.spawnAnimals); + world.setSpawnSettings(config.spawnMonsters); for (SpawnCategory spawnCategory : SpawnCategory.values()) { if (CraftSpawnCategory.isValidForLimits(spawnCategory)) { @@ -1169,7 +1172,7 @@ public final class CraftServer implements Server { WorldDataServer worlddata; WorldLoader.a worldloader_a = console.worldLoader; IRegistryCustom.Dimension iregistrycustom_dimension = worldloader_a.datapackDimensions(); - IRegistry iregistry = iregistrycustom_dimension.registryOrThrow(Registries.LEVEL_STEM); + IRegistry iregistry = iregistrycustom_dimension.lookupOrThrow(Registries.LEVEL_STEM); if (dynamic != null) { LevelDataAndDimensions leveldataanddimensions = Convertable.getLevelDataAndDimensions(dynamic, worldloader_a.dataConfiguration(), iregistry, worldloader_a.datapackWorldgen()); @@ -1182,7 +1185,7 @@ public final class CraftServer implements Server { DedicatedServerProperties.WorldDimensionData properties = new DedicatedServerProperties.WorldDimensionData(ChatDeserializer.parse((creator.generatorSettings().isEmpty()) ? "{}" : creator.generatorSettings()), creator.type().name().toLowerCase(Locale.ROOT)); - worldsettings = new WorldSettings(name, EnumGamemode.byId(getDefaultGameMode().getValue()), hardcore, EnumDifficulty.EASY, false, new GameRules(), worldloader_a.dataConfiguration()); + worldsettings = new WorldSettings(name, EnumGamemode.byId(getDefaultGameMode().getValue()), hardcore, EnumDifficulty.EASY, false, new GameRules(worldloader_a.dataConfiguration().enabledFeatures()), worldloader_a.dataConfiguration()); worlddimensions = properties.create(worldloader_a.datapackWorldgen()); WorldDimensions.b worlddimensions_b = worlddimensions.bake(iregistry); @@ -1191,7 +1194,7 @@ public final class CraftServer implements Server { worlddata = new WorldDataServer(worldsettings, worldoptions, worlddimensions_b.specialWorldProperty(), lifecycle); iregistrycustom_dimension = worlddimensions_b.dimensionsRegistryAccess(); } - iregistry = iregistrycustom_dimension.registryOrThrow(Registries.LEVEL_STEM); + iregistry = iregistrycustom_dimension.lookupOrThrow(Registries.LEVEL_STEM); worlddata.customDimensions = iregistry; worlddata.checkName(name); worlddata.setModdedInfo(console.getServerModName(), console.getModdedStatus().shouldReportAsModified()); @@ -1202,7 +1205,7 @@ public final class CraftServer implements Server { long j = BiomeManager.obfuscateSeed(creator.seed()); List list = ImmutableList.of(new MobSpawnerPhantom(), new MobSpawnerPatrol(), new MobSpawnerCat(), new VillageSiege(), new MobSpawnerTrader(worlddata)); - WorldDimension worlddimension = iregistry.get(actualDimension); + WorldDimension worlddimension = iregistry.getValue(actualDimension); WorldInfo worldInfo = new CraftWorldInfo(worlddata, worldSession, creator.environment(), worlddimension.type().value()); if (biomeProvider == null && generator != null) { @@ -1232,7 +1235,7 @@ public final class CraftServer implements Server { console.initWorld(internal, worlddata, worlddata, worlddata.worldGenOptions()); - internal.setSpawnSettings(true, true); + internal.setSpawnSettings(true); console.addLevel(internal); getServer().prepareLevels(internal.getChunkSource().chunkMap.progressListener, internal); @@ -1376,6 +1379,8 @@ public final class CraftServer implements Server { toAdd = CraftSmithingTransformRecipe.fromBukkitRecipe((SmithingTransformRecipe) recipe); } else if (recipe instanceof SmithingTrimRecipe) { toAdd = CraftSmithingTrimRecipe.fromBukkitRecipe((SmithingTrimRecipe) recipe); + } else if (recipe instanceof TransmuteRecipe) { + toAdd = CraftTransmuteRecipe.fromBukkitRecipe((TransmuteRecipe) recipe); } else if (recipe instanceof ComplexRecipe) { throw new UnsupportedOperationException("Cannot add custom complex recipe"); } else { @@ -1409,7 +1414,7 @@ public final class CraftServer implements Server { public Recipe getRecipe(NamespacedKey recipeKey) { Preconditions.checkArgument(recipeKey != null, "NamespacedKey recipeKey cannot be null"); - return getServer().getRecipeManager().byKey(CraftNamespacedKey.toMinecraft(recipeKey)).map(RecipeHolder::toBukkitRecipe).orElse(null); + return getServer().getRecipeManager().byKey(CraftRecipe.toMinecraft(recipeKey)).map(RecipeHolder::toBukkitRecipe).orElse(null); } private InventoryCrafting createInventoryCrafting() { @@ -1464,7 +1469,7 @@ public final class CraftServer implements Server { if (recipe.isPresent()) { RecipeHolder recipeCrafting = recipe.get(); - if (craftResult.setRecipeUsed(craftWorld.getHandle(), craftPlayer.getHandle(), recipeCrafting)) { + if (craftResult.setRecipeUsed(craftPlayer.getHandle(), recipeCrafting)) { itemstack = recipeCrafting.value().assemble(inventoryCrafting.asCraftInput(), craftWorld.getHandle().registryAccess()); } } @@ -1472,7 +1477,7 @@ public final class CraftServer implements Server { // Call Bukkit event to check for matrix/result changes. net.minecraft.world.item.ItemStack result = CraftEventFactory.callPreCraftEvent(inventoryCrafting, craftResult, itemstack, container.getBukkitView(), recipe.map(RecipeHolder::value).orElse(null) instanceof RecipeRepair); - return createItemCraftResult(CraftItemStack.asBukkitCopy(result), inventoryCrafting, craftWorld.getHandle()); + return createItemCraftResult(recipe, CraftItemStack.asBukkitCopy(result), inventoryCrafting, craftWorld.getHandle()); } @Override @@ -1498,34 +1503,34 @@ public final class CraftServer implements Server { itemStack = recipe.get().value().assemble(inventoryCrafting.asCraftInput(), craftWorld.getHandle().registryAccess()); } - return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle()); + return createItemCraftResult(recipe, CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle()); } - private CraftItemCraftResult createItemCraftResult(ItemStack itemStack, InventoryCrafting inventoryCrafting, WorldServer worldServer) { + private CraftItemCraftResult createItemCraftResult(Optional> recipe, ItemStack itemStack, InventoryCrafting inventoryCrafting, WorldServer worldServer) { CraftItemCraftResult craftItemResult = new CraftItemCraftResult(itemStack); - NonNullList remainingItems = getServer().getRecipeManager().getRemainingItemsFor(Recipes.CRAFTING, inventoryCrafting.asCraftInput(), worldServer); + recipe.map((holder) -> holder.value().getRemainingItems(inventoryCrafting.asCraftInput())).ifPresent((remainingItems) -> { + // Set the resulting matrix items and overflow items + for (int i = 0; i < remainingItems.size(); ++i) { + net.minecraft.world.item.ItemStack itemstack1 = inventoryCrafting.getItem(i); + net.minecraft.world.item.ItemStack itemstack2 = (net.minecraft.world.item.ItemStack) remainingItems.get(i); - // Set the resulting matrix items and overflow items - for (int i = 0; i < remainingItems.size(); ++i) { - net.minecraft.world.item.ItemStack itemstack1 = inventoryCrafting.getItem(i); - net.minecraft.world.item.ItemStack itemstack2 = (net.minecraft.world.item.ItemStack) remainingItems.get(i); + if (!itemstack1.isEmpty()) { + inventoryCrafting.removeItem(i, 1); + itemstack1 = inventoryCrafting.getItem(i); + } - if (!itemstack1.isEmpty()) { - inventoryCrafting.removeItem(i, 1); - itemstack1 = inventoryCrafting.getItem(i); - } - - if (!itemstack2.isEmpty()) { - if (itemstack1.isEmpty()) { - inventoryCrafting.setItem(i, itemstack2); - } else if (net.minecraft.world.item.ItemStack.isSameItemSameComponents(itemstack1, itemstack2)) { - itemstack2.grow(itemstack1.getCount()); - inventoryCrafting.setItem(i, itemstack2); - } else { - craftItemResult.getOverflowItems().add(CraftItemStack.asBukkitCopy(itemstack2)); + if (!itemstack2.isEmpty()) { + if (itemstack1.isEmpty()) { + inventoryCrafting.setItem(i, itemstack2); + } else if (net.minecraft.world.item.ItemStack.isSameItemSameComponents(itemstack1, itemstack2)) { + itemstack2.grow(itemstack1.getCount()); + inventoryCrafting.setItem(i, itemstack2); + } else { + craftItemResult.getOverflowItems().add(CraftItemStack.asBukkitCopy(itemstack2)); + } } } - } + }); for (int i = 0; i < inventoryCrafting.getContents().size(); i++) { craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i))); @@ -1565,8 +1570,7 @@ public final class CraftServer implements Server { public boolean removeRecipe(NamespacedKey recipeKey) { Preconditions.checkArgument(recipeKey != null, "recipeKey == null"); - MinecraftKey mcKey = CraftNamespacedKey.toMinecraft(recipeKey); - return getServer().getRecipeManager().removeRecipe(mcKey); + return getServer().getRecipeManager().removeRecipe(CraftRecipe.toMinecraft(recipeKey)); } @Override @@ -2292,7 +2296,7 @@ public final class CraftServer implements Server { public ChunkGenerator.ChunkData createChunkData(World world) { Preconditions.checkArgument(world != null, "World cannot be null"); WorldServer handle = ((CraftWorld) world).getHandle(); - return new OldCraftChunkData(world.getMinHeight(), world.getMaxHeight(), handle.registryAccess().registryOrThrow(Registries.BIOME)); + return new OldCraftChunkData(world.getMinHeight(), world.getMaxHeight(), handle.registryAccess().lookupOrThrow(Registries.BIOME)); } @Override @@ -2428,31 +2432,39 @@ public final class CraftServer implements Server { case org.bukkit.Tag.REGISTRY_BLOCKS -> { Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Block namespace (%s) must have material type", clazz.getName()); TagKey blockTagKey = TagKey.create(Registries.BLOCK, key); - if (BuiltInRegistries.BLOCK.getTag(blockTagKey).isPresent()) { + if (BuiltInRegistries.BLOCK.get(blockTagKey).isPresent()) { return (org.bukkit.Tag) new CraftBlockTag(BuiltInRegistries.BLOCK, blockTagKey); } } case org.bukkit.Tag.REGISTRY_ITEMS -> { Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Item namespace (%s) must have material type", clazz.getName()); TagKey itemTagKey = TagKey.create(Registries.ITEM, key); - if (BuiltInRegistries.ITEM.getTag(itemTagKey).isPresent()) { + if (BuiltInRegistries.ITEM.get(itemTagKey).isPresent()) { return (org.bukkit.Tag) new CraftItemTag(BuiltInRegistries.ITEM, itemTagKey); } } case org.bukkit.Tag.REGISTRY_FLUIDS -> { Preconditions.checkArgument(clazz == org.bukkit.Fluid.class, "Fluid namespace (%s) must have fluid type", clazz.getName()); TagKey fluidTagKey = TagKey.create(Registries.FLUID, key); - if (BuiltInRegistries.FLUID.getTag(fluidTagKey).isPresent()) { + if (BuiltInRegistries.FLUID.get(fluidTagKey).isPresent()) { return (org.bukkit.Tag) new CraftFluidTag(BuiltInRegistries.FLUID, fluidTagKey); } } case org.bukkit.Tag.REGISTRY_ENTITY_TYPES -> { Preconditions.checkArgument(clazz == org.bukkit.entity.EntityType.class, "Entity type namespace (%s) must have entity type", clazz.getName()); TagKey> entityTagKey = TagKey.create(Registries.ENTITY_TYPE, key); - if (BuiltInRegistries.ENTITY_TYPE.getTag(entityTagKey).isPresent()) { + if (BuiltInRegistries.ENTITY_TYPE.get(entityTagKey).isPresent()) { return (org.bukkit.Tag) new CraftEntityTag(BuiltInRegistries.ENTITY_TYPE, entityTagKey); } } + case org.bukkit.tag.DamageTypeTags.REGISTRY_DAMAGE_TYPES -> { + Preconditions.checkArgument(clazz == org.bukkit.damage.DamageType.class, "Damage type namespace (%s) must have damage type", clazz.getName()); + TagKey damageTagKey = TagKey.create(Registries.DAMAGE_TYPE, key); + IRegistry damageRegistry = CraftRegistry.getMinecraftRegistry(Registries.DAMAGE_TYPE); + if (damageRegistry.get(damageTagKey).isPresent()) { + return (org.bukkit.Tag) new CraftDamageTag(damageRegistry, damageTagKey); + } + } default -> throw new IllegalArgumentException(); } @@ -2468,22 +2480,27 @@ public final class CraftServer implements Server { case org.bukkit.Tag.REGISTRY_BLOCKS -> { Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Block namespace (%s) must have material type", clazz.getName()); IRegistry blockTags = BuiltInRegistries.BLOCK; - return blockTags.getTags().map(pair -> (org.bukkit.Tag) new CraftBlockTag(blockTags, pair.getFirst())).collect(ImmutableList.toImmutableList()); + return blockTags.getTags().map(pair -> (org.bukkit.Tag) new CraftBlockTag(blockTags, pair.key())).collect(ImmutableList.toImmutableList()); } case org.bukkit.Tag.REGISTRY_ITEMS -> { Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Item namespace (%s) must have material type", clazz.getName()); IRegistry itemTags = BuiltInRegistries.ITEM; - return itemTags.getTags().map(pair -> (org.bukkit.Tag) new CraftItemTag(itemTags, pair.getFirst())).collect(ImmutableList.toImmutableList()); + return itemTags.getTags().map(pair -> (org.bukkit.Tag) new CraftItemTag(itemTags, pair.key())).collect(ImmutableList.toImmutableList()); } case org.bukkit.Tag.REGISTRY_FLUIDS -> { Preconditions.checkArgument(clazz == org.bukkit.Material.class, "Fluid namespace (%s) must have fluid type", clazz.getName()); IRegistry fluidTags = BuiltInRegistries.FLUID; - return fluidTags.getTags().map(pair -> (org.bukkit.Tag) new CraftFluidTag(fluidTags, pair.getFirst())).collect(ImmutableList.toImmutableList()); + return fluidTags.getTags().map(pair -> (org.bukkit.Tag) new CraftFluidTag(fluidTags, pair.key())).collect(ImmutableList.toImmutableList()); } case org.bukkit.Tag.REGISTRY_ENTITY_TYPES -> { Preconditions.checkArgument(clazz == org.bukkit.entity.EntityType.class, "Entity type namespace (%s) must have entity type", clazz.getName()); IRegistry> entityTags = BuiltInRegistries.ENTITY_TYPE; - return entityTags.getTags().map(pair -> (org.bukkit.Tag) new CraftEntityTag(entityTags, pair.getFirst())).collect(ImmutableList.toImmutableList()); + return entityTags.getTags().map(pair -> (org.bukkit.Tag) new CraftEntityTag(entityTags, pair.key())).collect(ImmutableList.toImmutableList()); + } + case org.bukkit.tag.DamageTypeTags.REGISTRY_DAMAGE_TYPES -> { + Preconditions.checkArgument(clazz == org.bukkit.damage.DamageType.class, "Damage type namespace (%s) must have damage type", clazz.getName()); + IRegistry damageTags = CraftRegistry.getMinecraftRegistry(Registries.DAMAGE_TYPE); + return damageTags.getTags().map(pair -> (org.bukkit.Tag) new CraftDamageTag(damageTags, pair.key())).collect(ImmutableList.toImmutableList()); } default -> throw new IllegalArgumentException(); } @@ -2493,7 +2510,7 @@ public final class CraftServer implements Server { public LootTable getLootTable(NamespacedKey key) { Preconditions.checkArgument(key != null, "NamespacedKey key cannot be null"); - ReloadableServerRegistries.b registry = getServer().reloadableRegistries(); + ReloadableServerRegistries.a registry = getServer().reloadableRegistries(); return registry.lookup().lookup(Registries.LOOT_TABLE) .flatMap((lookup) -> lookup.get(CraftLootTable.bukkitKeyToMinecraft(key))) .map((holder) -> new CraftLootTable(key, holder.value())) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index f851cdf66b..0cffbfaac3 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -28,6 +28,7 @@ import net.minecraft.core.BlockPosition; import net.minecraft.core.Holder; import net.minecraft.core.HolderSet; import net.minecraft.core.IRegistry; +import net.minecraft.core.particles.Particles; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; @@ -46,10 +47,12 @@ import net.minecraft.server.level.TicketType; import net.minecraft.server.level.WorldServer; import net.minecraft.sounds.SoundCategory; import net.minecraft.sounds.SoundEffect; +import net.minecraft.sounds.SoundEffects; import net.minecraft.util.ArraySetSorted; import net.minecraft.util.Unit; import net.minecraft.world.EnumDifficulty; import net.minecraft.world.entity.EntityLightning; +import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.entity.item.EntityFallingBlock; import net.minecraft.world.entity.item.EntityItem; @@ -57,6 +60,7 @@ import net.minecraft.world.entity.player.EntityHuman; import net.minecraft.world.entity.projectile.EntityArrow; import net.minecraft.world.entity.raid.PersistentRaid; import net.minecraft.world.level.ChunkCoordIntPair; +import net.minecraft.world.level.Explosion; import net.minecraft.world.level.GameRules; import net.minecraft.world.level.RayTrace; import net.minecraft.world.level.biome.BiomeBase; @@ -296,7 +300,9 @@ public class CraftWorld extends CraftRegionAccessor implements World { } net.minecraft.world.level.chunk.Chunk chunk = world.getChunk(x, z); - chunk.setUnsaved(!save); // Use method call to account for persistentDataContainer + if (!save) { + chunk.tryMarkSaved(); // Use method call to account for persistentDataContainer + } unloadChunkRequest(x, z); world.getChunkSource().purgeUnload(); @@ -582,14 +588,14 @@ public class CraftWorld extends CraftRegionAccessor implements World { EntityArrow arrow; if (TippedArrow.class.isAssignableFrom(clazz)) { - arrow = EntityTypes.ARROW.create(world); + arrow = EntityTypes.ARROW.create(world, EntitySpawnReason.COMMAND); ((Arrow) arrow.getBukkitEntity()).setBasePotionType(PotionType.WATER); } else if (SpectralArrow.class.isAssignableFrom(clazz)) { - arrow = EntityTypes.SPECTRAL_ARROW.create(world); + arrow = EntityTypes.SPECTRAL_ARROW.create(world, EntitySpawnReason.COMMAND); } else if (Trident.class.isAssignableFrom(clazz)) { - arrow = EntityTypes.TRIDENT.create(world); + arrow = EntityTypes.TRIDENT.create(world, EntitySpawnReason.COMMAND); } else { - arrow = EntityTypes.ARROW.create(world); + arrow = EntityTypes.ARROW.create(world, EntitySpawnReason.COMMAND); } arrow.moveTo(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); @@ -611,7 +617,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { private LightningStrike strikeLightning0(Location loc, boolean isVisual) { Preconditions.checkArgument(loc != null, "Location cannot be null"); - EntityLightning lightning = EntityTypes.LIGHTNING_BOLT.create(world); + EntityLightning lightning = EntityTypes.LIGHTNING_BOLT.create(world, EntitySpawnReason.COMMAND); lightning.moveTo(loc.getX(), loc.getY(), loc.getZ()); lightning.setVisualOnly(isVisual); world.strikeLightning(lightning, LightningStrikeEvent.Cause.CUSTOM); @@ -702,7 +708,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { CraftPlayer cp = (CraftPlayer) p; if (cp.getHandle().connection == null) continue; - cp.getHandle().connection.send(new PacketPlayOutUpdateTime(cp.getHandle().level().getGameTime(), cp.getHandle().getPlayerTime(), cp.getHandle().level().getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); + cp.getHandle().connection.send(new PacketPlayOutUpdateTime(cp.getHandle().level().getGameTime(), cp.getHandle().getPlayerTime(), cp.getHandle().serverLevel().getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); } } @@ -737,7 +743,8 @@ public class CraftWorld extends CraftRegionAccessor implements World { explosionType = net.minecraft.world.level.World.a.MOB; // Respect mobGriefing gamerule } - return !world.explode(source == null ? null : ((CraftEntity) source).getHandle(), x, y, z, power, setFire, explosionType).wasCanceled; + net.minecraft.world.entity.Entity entity = (source == null) ? null : ((CraftEntity) source).getHandle(); + return !world.explode0(entity, Explosion.getDefaultDamageSource(world, entity), null, x, y, z, power, setFire, explosionType, Particles.EXPLOSION, Particles.EXPLOSION_EMITTER, SoundEffects.GENERIC_EXPLODE).wasCanceled; } @Override @@ -847,7 +854,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { if (chunk != null) { chunk.setBiome(x >> 2, y >> 2, z >> 2, bb); - chunk.setUnsaved(true); // SPIGOT-2890 + chunk.markUnsaved(); // SPIGOT-2890 } } } @@ -860,7 +867,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public double getTemperature(int x, int y, int z) { BlockPosition pos = new BlockPosition(x, y, z); - return this.world.getNoiseBiome(x >> 2, y >> 2, z >> 2).value().getTemperature(pos); + return this.world.getNoiseBiome(x >> 2, y >> 2, z >> 2).value().getTemperature(pos, this.world.getSeaLevel()); } @Override @@ -1268,7 +1275,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void setSpawnFlags(boolean allowMonsters, boolean allowAnimals) { - world.setSpawnSettings(allowMonsters, allowAnimals); + world.getChunkSource().setSpawnSettings(allowMonsters, allowAnimals); } @Override @@ -1283,12 +1290,12 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public int getMinHeight() { - return world.getMinBuildHeight(); + return world.getMinY(); } @Override public int getMaxHeight() { - return world.getMaxBuildHeight(); + return world.getMaxY(); } @Override @@ -1709,38 +1716,41 @@ public class CraftWorld extends CraftRegionAccessor implements World { } } - private static Map> gamerules; - public static synchronized Map> getGameRulesNMS() { + private Map> gamerules; + public synchronized Map> getGameRulesNMS() { if (gamerules != null) { return gamerules; } + return this.gamerules = getGameRulesNMS(getHandle().getGameRules()); + } + + public static Map> getGameRulesNMS(GameRules gameRules) { Map> gamerules = new HashMap<>(); - GameRules.visitGameRuleTypes(new GameRules.GameRuleVisitor() { + gameRules.visitGameRuleTypes(new GameRules.GameRuleVisitor() { @Override public > void visit(GameRules.GameRuleKey gamerules_gamerulekey, GameRules.GameRuleDefinition gamerules_gameruledefinition) { gamerules.put(gamerules_gamerulekey.getId(), gamerules_gamerulekey); } }); - - return CraftWorld.gamerules = gamerules; + return gamerules; } - private static Map> gameruleDefinitions; - public static synchronized Map> getGameRuleDefinitions() { + private Map> gameruleDefinitions; + public synchronized Map> getGameRuleDefinitions() { if (gameruleDefinitions != null) { return gameruleDefinitions; } Map> gameruleDefinitions = new HashMap<>(); - GameRules.visitGameRuleTypes(new GameRules.GameRuleVisitor() { + getHandle().getGameRules().visitGameRuleTypes(new GameRules.GameRuleVisitor() { @Override public > void visit(GameRules.GameRuleKey gamerules_gamerulekey, GameRules.GameRuleDefinition gamerules_gameruledefinition) { gameruleDefinitions.put(gamerules_gamerulekey.getId(), gamerules_gameruledefinition); } }); - return CraftWorld.gameruleDefinitions = gameruleDefinitions; + return this.gameruleDefinitions = gameruleDefinitions; } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/Main.java b/paper-server/src/main/java/org/bukkit/craftbukkit/Main.java index e86627060f..5c9f30730b 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/Main.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/Main.java @@ -190,11 +190,11 @@ public class Main { useConsole = false; } - if (false && Main.class.getPackage().getImplementationVendor() != null && System.getProperty("IReallyKnowWhatIAmDoingISwear") == null) { + if (Main.class.getPackage().getImplementationVendor() != null && System.getProperty("IReallyKnowWhatIAmDoingISwear") == null) { Date buildDate = new Date(Integer.parseInt(Main.class.getPackage().getImplementationVendor()) * 1000L); Calendar deadline = Calendar.getInstance(); - deadline.add(Calendar.DAY_OF_YEAR, -28); + deadline.add(Calendar.DAY_OF_YEAR, -3); if (buildDate.before(deadline.getTime())) { System.err.println("*** Error, this build is outdated ***"); System.err.println("*** Please download a new build as per instructions from https://www.spigotmc.org/go/outdated-spigot ***"); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java index 6d2fb9c36e..e6bc7d5d09 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBeacon.java @@ -2,6 +2,13 @@ package org.bukkit.craftbukkit.block; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import net.minecraft.advancements.critereon.CriterionConditionItem; +import net.minecraft.advancements.critereon.CriterionConditionValue; +import net.minecraft.core.component.DataComponentPredicate; +import net.minecraft.core.component.DataComponents; +import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.world.ChestLock; import net.minecraft.world.entity.player.EntityHuman; import net.minecraft.world.level.block.entity.TileEntity; @@ -9,9 +16,11 @@ import net.minecraft.world.level.block.entity.TileEntityBeacon; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Beacon; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.potion.CraftPotionEffectType; import org.bukkit.craftbukkit.util.CraftChatMessage; import org.bukkit.entity.LivingEntity; +import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -85,17 +94,33 @@ public class CraftBeacon extends CraftBlockEntityState impleme @Override public boolean isLocked() { - return !this.getSnapshot().lockKey.key().isEmpty(); + return this.getSnapshot().lockKey != ChestLock.NO_LOCK; } @Override public String getLock() { - return this.getSnapshot().lockKey.key(); + Optional customName = this.getSnapshot().lockKey.predicate().components().asPatch().get(DataComponents.CUSTOM_NAME); + + return (customName != null) ? customName.map(CraftChatMessage::fromComponent).orElse("") : ""; } @Override public void setLock(String key) { - this.getSnapshot().lockKey = (key == null) ? ChestLock.NO_LOCK : new ChestLock(key); + if (key == null) { + this.getSnapshot().lockKey = ChestLock.NO_LOCK; + } else { + DataComponentPredicate predicate = DataComponentPredicate.builder().expect(DataComponents.CUSTOM_NAME, CraftChatMessage.fromStringOrNull(key)).build(); + this.getSnapshot().lockKey = new ChestLock(new CriterionConditionItem(Optional.empty(), CriterionConditionValue.IntegerRange.ANY, predicate, Collections.emptyMap())); + } + } + + @Override + public void setLockItem(ItemStack key) { + if (key == null) { + this.getSnapshot().lockKey = ChestLock.NO_LOCK; + } else { + this.getSnapshot().lockKey = new ChestLock(CraftItemStack.asCriterionConditionItem(key)); + } } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index fe75a6ea82..6ac71753fc 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -341,7 +341,7 @@ public class CraftBlock implements Block { @Override public double getTemperature() { - return world.getBiome(position).value().getTemperature(position); + return world.getBiome(position).value().getTemperature(position, world.getSeaLevel()); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java index 08787a5711..c683a83050 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java @@ -18,6 +18,7 @@ import net.minecraft.world.level.block.entity.BrushableBlockEntity; import net.minecraft.world.level.block.entity.CalibratedSculkSensorBlockEntity; import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity; import net.minecraft.world.level.block.entity.CrafterBlockEntity; +import net.minecraft.world.level.block.entity.CreakingHeartBlockEntity; import net.minecraft.world.level.block.entity.DecoratedPotBlockEntity; import net.minecraft.world.level.block.entity.HangingSignBlockEntity; import net.minecraft.world.level.block.entity.SculkCatalystBlockEntity; @@ -150,6 +151,8 @@ public final class CraftBlockStates { Material.MANGROVE_WALL_SIGN, Material.OAK_SIGN, Material.OAK_WALL_SIGN, + Material.PALE_OAK_SIGN, + Material.PALE_OAK_WALL_SIGN, Material.SPRUCE_SIGN, Material.SPRUCE_WALL_SIGN, Material.WARPED_SIGN, @@ -177,6 +180,8 @@ public final class CraftBlockStates { Material.MANGROVE_WALL_HANGING_SIGN, Material.OAK_HANGING_SIGN, Material.OAK_WALL_HANGING_SIGN, + Material.PALE_OAK_HANGING_SIGN, + Material.PALE_OAK_WALL_HANGING_SIGN, Material.SPRUCE_HANGING_SIGN, Material.SPRUCE_WALL_HANGING_SIGN, Material.WARPED_HANGING_SIGN, @@ -314,6 +319,7 @@ public final class CraftBlockStates { register(Material.CHISELED_BOOKSHELF, CraftChiseledBookshelf.class, CraftChiseledBookshelf::new, ChiseledBookShelfBlockEntity::new); register(Material.COMPARATOR, CraftComparator.class, CraftComparator::new, TileEntityComparator::new); register(Material.CONDUIT, CraftConduit.class, CraftConduit::new, TileEntityConduit::new); + register(Material.CREAKING_HEART, CraftCreakingHeart.class, CraftCreakingHeart::new, CreakingHeartBlockEntity::new); register(Material.DAYLIGHT_DETECTOR, CraftDaylightDetector.class, CraftDaylightDetector::new, TileEntityLightDetector::new); register(Material.DECORATED_POT, CraftDecoratedPot.class, CraftDecoratedPot::new, DecoratedPotBlockEntity::new); register(Material.DISPENSER, CraftDispenser.class, CraftDispenser::new, TileEntityDispenser::new); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java index ff442beb20..75212d9996 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftContainer.java @@ -1,11 +1,20 @@ package org.bukkit.craftbukkit.block; +import java.util.Collections; +import java.util.Optional; +import net.minecraft.advancements.critereon.CriterionConditionItem; +import net.minecraft.advancements.critereon.CriterionConditionValue; +import net.minecraft.core.component.DataComponentPredicate; +import net.minecraft.core.component.DataComponents; +import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.world.ChestLock; import net.minecraft.world.level.block.entity.TileEntityContainer; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Container; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.util.CraftChatMessage; +import org.bukkit.inventory.ItemStack; public abstract class CraftContainer extends CraftBlockEntityState implements Container { @@ -19,17 +28,33 @@ public abstract class CraftContainer extends Craf @Override public boolean isLocked() { - return !this.getSnapshot().lockKey.key().isEmpty(); + return this.getSnapshot().lockKey != ChestLock.NO_LOCK; } @Override public String getLock() { - return this.getSnapshot().lockKey.key(); + Optional customName = this.getSnapshot().lockKey.predicate().components().asPatch().get(DataComponents.CUSTOM_NAME); + + return (customName != null) ? customName.map(CraftChatMessage::fromComponent).orElse("") : ""; } @Override public void setLock(String key) { - this.getSnapshot().lockKey = (key == null) ? ChestLock.NO_LOCK : new ChestLock(key); + if (key == null) { + this.getSnapshot().lockKey = ChestLock.NO_LOCK; + } else { + DataComponentPredicate predicate = DataComponentPredicate.builder().expect(DataComponents.CUSTOM_NAME, CraftChatMessage.fromStringOrNull(key)).build(); + this.getSnapshot().lockKey = new ChestLock(new CriterionConditionItem(Optional.empty(), CriterionConditionValue.IntegerRange.ANY, predicate, Collections.emptyMap())); + } + } + + @Override + public void setLockItem(ItemStack key) { + if (key == null) { + this.getSnapshot().lockKey = ChestLock.NO_LOCK; + } else { + this.getSnapshot().lockKey = new ChestLock(CraftItemStack.asCriterionConditionItem(key)); + } } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreakingHeart.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreakingHeart.java new file mode 100644 index 0000000000..e7108cd3f4 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreakingHeart.java @@ -0,0 +1,27 @@ +package org.bukkit.craftbukkit.block; + +import net.minecraft.world.level.block.entity.CreakingHeartBlockEntity; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.CreakingHeart; + +public class CraftCreakingHeart extends CraftBlockEntityState implements CreakingHeart { + + public CraftCreakingHeart(World world, CreakingHeartBlockEntity tileEntity) { + super(world, tileEntity); + } + + protected CraftCreakingHeart(CraftCreakingHeart state, Location location) { + super(state, location); + } + + @Override + public CraftCreakingHeart copy() { + return new CraftCreakingHeart(this, null); + } + + @Override + public CraftCreakingHeart copy(Location location) { + return new CraftCreakingHeart(this, location); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java index 905db9fbd5..9b0c39bd47 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftFurnace.java @@ -2,7 +2,6 @@ package org.bukkit.craftbukkit.block; import com.google.common.collect.ImmutableMap; import java.util.Map; -import net.minecraft.resources.MinecraftKey; import net.minecraft.world.level.block.BlockFurnace; import net.minecraft.world.level.block.entity.TileEntityFurnace; import org.bukkit.Bukkit; @@ -74,12 +73,12 @@ public abstract class CraftFurnace extends CraftCon @Override public Map, Integer> getRecipesUsed() { ImmutableMap.Builder, Integer> recipesUsed = ImmutableMap.builder(); - for (Map.Entry entrySet : this.getSnapshot().getRecipesUsed().object2IntEntrySet()) { - Recipe recipe = Bukkit.getRecipe(CraftNamespacedKey.fromMinecraft(entrySet.getKey())); + this.getSnapshot().recipesUsed.reference2IntEntrySet().fastForEach(entrySet -> { + Recipe recipe = Bukkit.getRecipe(CraftNamespacedKey.fromMinecraft(entrySet.getKey().location())); if (recipe instanceof CookingRecipe cookingRecipe) { recipesUsed.put(cookingRecipe, entrySet.getValue()); } - } + }); return recipesUsed.build(); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftTrialSpawner.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftTrialSpawner.java index b2e49031d7..5ece537e10 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftTrialSpawner.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftTrialSpawner.java @@ -4,6 +4,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import java.util.Collection; import java.util.UUID; +import net.minecraft.core.Holder; import net.minecraft.world.level.block.TrialSpawnerBlock; import net.minecraft.world.level.block.entity.TrialSpawnerBlockEntity; import net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerData; @@ -151,8 +152,8 @@ public class CraftTrialSpawner extends CraftBlockEntityState CREAKING = getEnum("creaking"); + + @Override + public org.bukkit.block.data.type.CreakingHeart.Creaking getCreaking() { + return get(CREAKING, org.bukkit.block.data.type.CreakingHeart.Creaking.class); + } + + @Override + public void setCreaking(org.bukkit.block.data.type.CreakingHeart.Creaking creaking) { + set(CREAKING, creaking); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftHangingMoss.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftHangingMoss.java new file mode 100644 index 0000000000..1c81156c03 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftHangingMoss.java @@ -0,0 +1,19 @@ +package org.bukkit.craftbukkit.block.data.type; + +import org.bukkit.block.data.type.HangingMoss; +import org.bukkit.craftbukkit.block.data.CraftBlockData; + +public abstract class CraftHangingMoss extends CraftBlockData implements HangingMoss { + + private static final net.minecraft.world.level.block.state.properties.BlockStateBoolean TIP = getBoolean("tip"); + + @Override + public boolean isTip() { + return get(TIP); + } + + @Override + public void setTip(boolean tip) { + set(TIP, tip); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftMossyCarpet.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftMossyCarpet.java new file mode 100644 index 0000000000..462fc498eb --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftMossyCarpet.java @@ -0,0 +1,32 @@ +package org.bukkit.craftbukkit.block.data.type; + +import org.bukkit.block.data.type.MossyCarpet; +import org.bukkit.craftbukkit.block.data.CraftBlockData; + +public abstract class CraftMossyCarpet extends CraftBlockData implements MossyCarpet { + + private static final net.minecraft.world.level.block.state.properties.BlockStateBoolean BOTTOM = getBoolean("bottom"); + private static final net.minecraft.world.level.block.state.properties.BlockStateEnum[] HEIGHTS = new net.minecraft.world.level.block.state.properties.BlockStateEnum[]{ + getEnum("north"), getEnum("east"), getEnum("south"), getEnum("west") + }; + + @Override + public boolean isBottom() { + return get(BOTTOM); + } + + @Override + public void setBottom(boolean up) { + set(BOTTOM, up); + } + + @Override + public org.bukkit.block.data.type.MossyCarpet.Height getHeight(org.bukkit.block.BlockFace face) { + return get(HEIGHTS[face.ordinal()], org.bukkit.block.data.type.MossyCarpet.Height.class); + } + + @Override + public void setHeight(org.bukkit.block.BlockFace face, org.bukkit.block.data.type.MossyCarpet.Height height) { + set(HEIGHTS[face.ordinal()], height); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftCreakingHeart.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftCreakingHeart.java new file mode 100644 index 0000000000..3d01917e53 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftCreakingHeart.java @@ -0,0 +1,48 @@ +/** + * Automatically generated file, changes will be lost. + */ +package org.bukkit.craftbukkit.block.impl; + +public final class CraftCreakingHeart extends org.bukkit.craftbukkit.block.data.CraftBlockData implements org.bukkit.block.data.type.CreakingHeart, org.bukkit.block.data.Orientable { + + public CraftCreakingHeart() { + super(); + } + + public CraftCreakingHeart(net.minecraft.world.level.block.state.IBlockData state) { + super(state); + } + + // org.bukkit.craftbukkit.block.data.type.CraftCreakingHeart + + private static final net.minecraft.world.level.block.state.properties.BlockStateEnum CREAKING = getEnum(net.minecraft.world.level.block.CreakingHeartBlock.class, "creaking"); + + @Override + public org.bukkit.block.data.type.CreakingHeart.Creaking getCreaking() { + return get(CREAKING, org.bukkit.block.data.type.CreakingHeart.Creaking.class); + } + + @Override + public void setCreaking(org.bukkit.block.data.type.CreakingHeart.Creaking creaking) { + set(CREAKING, creaking); + } + + // org.bukkit.craftbukkit.block.data.CraftOrientable + + private static final net.minecraft.world.level.block.state.properties.BlockStateEnum AXIS = getEnum(net.minecraft.world.level.block.CreakingHeartBlock.class, "axis"); + + @Override + public org.bukkit.Axis getAxis() { + return get(AXIS, org.bukkit.Axis.class); + } + + @Override + public void setAxis(org.bukkit.Axis axis) { + set(AXIS, axis); + } + + @Override + public java.util.Set getAxes() { + return getValues(AXIS, org.bukkit.Axis.class); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftEquipableCarvedPumpkin.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftEquipableCarvedPumpkin.java deleted file mode 100644 index 11cb5f2626..0000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftEquipableCarvedPumpkin.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Automatically generated file, changes will be lost. - */ -package org.bukkit.craftbukkit.block.impl; - -public final class CraftEquipableCarvedPumpkin extends org.bukkit.craftbukkit.block.data.CraftBlockData implements org.bukkit.block.data.Directional { - - public CraftEquipableCarvedPumpkin() { - super(); - } - - public CraftEquipableCarvedPumpkin(net.minecraft.world.level.block.state.IBlockData state) { - super(state); - } - - // org.bukkit.craftbukkit.block.data.CraftDirectional - - private static final net.minecraft.world.level.block.state.properties.BlockStateEnum FACING = getEnum(net.minecraft.world.level.block.EquipableCarvedPumpkinBlock.class, "facing"); - - @Override - public org.bukkit.block.BlockFace getFacing() { - return get(FACING, org.bukkit.block.BlockFace.class); - } - - @Override - public void setFacing(org.bukkit.block.BlockFace facing) { - set(FACING, facing); - } - - @Override - public java.util.Set getFaces() { - return getValues(FACING, org.bukkit.block.BlockFace.class); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftHangingMoss.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftHangingMoss.java new file mode 100644 index 0000000000..40a59ddd60 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftHangingMoss.java @@ -0,0 +1,29 @@ +/** + * Automatically generated file, changes will be lost. + */ +package org.bukkit.craftbukkit.block.impl; + +public final class CraftHangingMoss extends org.bukkit.craftbukkit.block.data.CraftBlockData implements org.bukkit.block.data.type.HangingMoss { + + public CraftHangingMoss() { + super(); + } + + public CraftHangingMoss(net.minecraft.world.level.block.state.IBlockData state) { + super(state); + } + + // org.bukkit.craftbukkit.block.data.type.CraftHangingMoss + + private static final net.minecraft.world.level.block.state.properties.BlockStateBoolean TIP = getBoolean(net.minecraft.world.level.block.HangingMossBlock.class, "tip"); + + @Override + public boolean isTip() { + return get(TIP); + } + + @Override + public void setTip(boolean tip) { + set(TIP, tip); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftMossyCarpet.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftMossyCarpet.java new file mode 100644 index 0000000000..ea190657d4 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftMossyCarpet.java @@ -0,0 +1,42 @@ +/** + * Automatically generated file, changes will be lost. + */ +package org.bukkit.craftbukkit.block.impl; + +public final class CraftMossyCarpet extends org.bukkit.craftbukkit.block.data.CraftBlockData implements org.bukkit.block.data.type.MossyCarpet { + + public CraftMossyCarpet() { + super(); + } + + public CraftMossyCarpet(net.minecraft.world.level.block.state.IBlockData state) { + super(state); + } + + // org.bukkit.craftbukkit.block.data.type.CraftMossyCarpet + + private static final net.minecraft.world.level.block.state.properties.BlockStateBoolean BOTTOM = getBoolean(net.minecraft.world.level.block.MossyCarpetBlock.class, "bottom"); + private static final net.minecraft.world.level.block.state.properties.BlockStateEnum[] HEIGHTS = new net.minecraft.world.level.block.state.properties.BlockStateEnum[]{ + getEnum(net.minecraft.world.level.block.MossyCarpetBlock.class, "north"), getEnum(net.minecraft.world.level.block.MossyCarpetBlock.class, "east"), getEnum(net.minecraft.world.level.block.MossyCarpetBlock.class, "south"), getEnum(net.minecraft.world.level.block.MossyCarpetBlock.class, "west") + }; + + @Override + public boolean isBottom() { + return get(BOTTOM); + } + + @Override + public void setBottom(boolean up) { + set(BOTTOM, up); + } + + @Override + public org.bukkit.block.data.type.MossyCarpet.Height getHeight(org.bukkit.block.BlockFace face) { + return get(HEIGHTS[face.ordinal()], org.bukkit.block.data.type.MossyCarpet.Height.class); + } + + @Override + public void setHeight(org.bukkit.block.BlockFace face, org.bukkit.block.data.type.MossyCarpet.Height height) { + set(HEIGHTS[face.ordinal()], height); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java b/paper-server/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java index f17f5f61e9..6b2ddc3378 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/command/VanillaCommandWrapper.java @@ -9,6 +9,7 @@ import java.util.Collections; import java.util.List; import net.minecraft.commands.CommandDispatcher; import net.minecraft.commands.CommandListenerWrapper; +import net.minecraft.server.level.WorldServer; import net.minecraft.world.entity.vehicle.EntityMinecartCommandBlock; import org.bukkit.Location; import org.bukkit.command.BlockCommandSender; @@ -20,7 +21,6 @@ import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftMinecartCommand; -import org.bukkit.entity.Entity; import org.bukkit.entity.minecart.CommandMinecart; public final class VanillaCommandWrapper extends BukkitCommand { @@ -62,12 +62,12 @@ public final class VanillaCommandWrapper extends BukkitCommand { } public static CommandListenerWrapper getListener(CommandSender sender) { - if (sender instanceof Entity) { + if (sender instanceof CraftEntity entity) { if (sender instanceof CommandMinecart) { return ((EntityMinecartCommandBlock) ((CraftMinecartCommand) sender).getHandle()).getCommandBlock().createCommandSourceStack(); } - return ((CraftEntity) sender).getHandle().createCommandSourceStack(); + return entity.getHandle().createCommandSourceStackForNameResolution((WorldServer) entity.getHandle().level()); } if (sender instanceof BlockCommandSender) { return ((CraftBlockCommandSender) sender).getWrapper(); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractArrow.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractArrow.java index d6ae586dbc..c0c800a55c 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractArrow.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractArrow.java @@ -3,6 +3,7 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; import net.minecraft.core.BlockPosition; import net.minecraft.world.entity.projectile.EntityArrow; +import net.minecraft.world.item.Items; import org.bukkit.block.Block; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.inventory.CraftItemStack; @@ -76,7 +77,7 @@ public class CraftAbstractArrow extends AbstractProjectile implements AbstractAr @Override public boolean isInBlock() { - return getHandle().inGround; + return getHandle().isInGround(); } @Override @@ -110,7 +111,9 @@ public class CraftAbstractArrow extends AbstractProjectile implements AbstractAr @Override public boolean isShotFromCrossbow() { - return getHandle().shotFromCrossbow(); + net.minecraft.world.item.ItemStack firedFromWeapon = getHandle().getWeaponItem(); + + return firedFromWeapon != null && firedFromWeapon.is(Items.CROSSBOW); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAreaEffectCloud.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAreaEffectCloud.java index e80cccac15..218e98746b 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAreaEffectCloud.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAreaEffectCloud.java @@ -133,7 +133,7 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud @Override public void setColor(Color color) { PotionContents old = getHandle().potionContents; - getHandle().setPotionContents(new PotionContents(old.potion(), Optional.of(color.asRGB()), old.customEffects())); + getHandle().setPotionContents(new PotionContents(old.potion(), Optional.of(color.asRGB()), old.customEffects(), old.customName())); } @Override @@ -152,7 +152,7 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud @Override public void clearCustomEffects() { PotionContents old = getHandle().potionContents; - getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), List.of())); + getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), List.of(), old.customName())); getHandle().updateColor(); } @@ -188,7 +188,7 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud Holder minecraft = CraftPotionEffectType.bukkitToMinecraftHolder(effect); PotionContents old = getHandle().potionContents; - getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), old.customEffects().stream().filter((mobEffect) -> !mobEffect.getEffect().equals(minecraft)).toList())); + getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), old.customEffects().stream().filter((mobEffect) -> !mobEffect.getEffect().equals(minecraft)).toList(), old.customName())); return true; } @@ -208,7 +208,7 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud getHandle().setPotionContents(getHandle().potionContents.withPotion(CraftPotionType.bukkitToMinecraftHolder(potionType))); } else { PotionContents old = getHandle().potionContents; - getHandle().setPotionContents(new PotionContents(Optional.empty(), old.customColor(), old.customEffects())); + getHandle().setPotionContents(new PotionContents(Optional.empty(), old.customColor(), old.customEffects(), old.customName())); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java index f4534bf39a..33f8cd2c8b 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArmorStand.java @@ -138,7 +138,7 @@ public class CraftArmorStand extends CraftLivingEntity implements ArmorStand { @Override public boolean hasBasePlate() { - return !getHandle().isNoBasePlate(); + return getHandle().showBasePlate(); } @Override @@ -165,7 +165,7 @@ public class CraftArmorStand extends CraftLivingEntity implements ArmorStand { @Override public boolean hasArms() { - return getHandle().isShowArms(); + return getHandle().showArms(); } @Override @@ -211,16 +211,16 @@ public class CraftArmorStand extends CraftLivingEntity implements ArmorStand { @Override public void addEquipmentLock(EquipmentSlot equipmentSlot, LockType lockType) { - getHandle().disabledSlots |= (1 << CraftEquipmentSlot.getNMS(equipmentSlot).getFilterFlag() + lockType.ordinal() * 8); + getHandle().disabledSlots |= (1 << CraftEquipmentSlot.getNMS(equipmentSlot).getFilterBit(lockType.ordinal() * 8)); } @Override public void removeEquipmentLock(EquipmentSlot equipmentSlot, LockType lockType) { - getHandle().disabledSlots &= ~(1 << CraftEquipmentSlot.getNMS(equipmentSlot).getFilterFlag() + lockType.ordinal() * 8); + getHandle().disabledSlots &= ~(1 << CraftEquipmentSlot.getNMS(equipmentSlot).getFilterBit(lockType.ordinal() * 8)); } @Override public boolean hasEquipmentLock(EquipmentSlot equipmentSlot, LockType lockType) { - return (getHandle().disabledSlots & (1 << CraftEquipmentSlot.getNMS(equipmentSlot).getFilterFlag() + lockType.ordinal() * 8)) != 0; + return (getHandle().disabledSlots & (1 << CraftEquipmentSlot.getNMS(equipmentSlot).getFilterBit(lockType.ordinal() * 8))) != 0; } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java index 464d4c4507..980b295bd8 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArrow.java @@ -51,7 +51,7 @@ public class CraftArrow extends CraftAbstractArrow implements Arrow { @Override public void clearCustomEffects() { PotionContents old = getHandle().getPotionContents(); - getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), List.of())); + getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), List.of(), old.customName())); getHandle().updateColor(); } @@ -87,7 +87,7 @@ public class CraftArrow extends CraftAbstractArrow implements Arrow { Holder minecraft = CraftPotionEffectType.bukkitToMinecraftHolder(effect); PotionContents old = getHandle().getPotionContents(); - getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), old.customEffects().stream().filter((mobEffect) -> !mobEffect.getEffect().equals(minecraft)).toList())); + getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), old.customEffects().stream().filter((mobEffect) -> !mobEffect.getEffect().equals(minecraft)).toList(), old.customName())); return true; } @@ -107,7 +107,7 @@ public class CraftArrow extends CraftAbstractArrow implements Arrow { getHandle().setPotionContents(getHandle().getPotionContents().withPotion(CraftPotionType.bukkitToMinecraftHolder(potionType))); } else { PotionContents old = getHandle().getPotionContents(); - getHandle().setPotionContents(new PotionContents(Optional.empty(), old.customColor(), old.customEffects())); + getHandle().setPotionContents(new PotionContents(Optional.empty(), old.customColor(), old.customEffects(), old.customName())); } } @@ -120,7 +120,7 @@ public class CraftArrow extends CraftAbstractArrow implements Arrow { public void setColor(Color color) { int colorRGB = (color == null) ? -1 : color.asRGB(); PotionContents old = getHandle().getPotionContents(); - getHandle().setPotionContents(new PotionContents(old.potion(), Optional.of(colorRGB), old.customEffects())); + getHandle().setPotionContents(new PotionContents(old.potion(), Optional.of(colorRGB), old.customEffects(), old.customName())); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java index 1eb6d2a125..d92cc51ec8 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBoat.java @@ -1,39 +1,38 @@ package org.bukkit.craftbukkit.entity; -import com.google.common.base.Preconditions; import java.util.stream.Collectors; +import net.minecraft.world.entity.EntityTypes; +import net.minecraft.world.entity.vehicle.AbstractBoat; import net.minecraft.world.entity.vehicle.EntityBoat; import org.bukkit.TreeSpecies; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Boat; import org.bukkit.entity.Entity; -public class CraftBoat extends CraftVehicle implements Boat { +public abstract class CraftBoat extends CraftVehicle implements Boat { - public CraftBoat(CraftServer server, EntityBoat entity) { + public CraftBoat(CraftServer server, AbstractBoat entity) { super(server, entity); } @Override public TreeSpecies getWoodType() { - return getTreeSpecies(getHandle().getVariant()); + return getTreeSpecies(getHandle().getType()); } @Override public void setWoodType(TreeSpecies species) { - getHandle().setVariant(getBoatType(species)); + throw new UnsupportedOperationException("Not supported - you must spawn a new entity to change boat type."); } @Override public Type getBoatType() { - return boatTypeFromNms(getHandle().getVariant()); + return boatTypeFromNms(getHandle().getType()); } @Override public void setBoatType(Type type) { - Preconditions.checkArgument(type != null, "Boat.Type cannot be null"); - - getHandle().setVariant(boatTypeToNms(type)); + throw new UnsupportedOperationException("Not supported - you must spawn a new entity to change boat type."); } @Override @@ -86,8 +85,8 @@ public class CraftBoat extends CraftVehicle implements Boat { } @Override - public EntityBoat getHandle() { - return (EntityBoat) entity; + public AbstractBoat getHandle() { + return (AbstractBoat) entity; } @Override @@ -95,34 +94,44 @@ public class CraftBoat extends CraftVehicle implements Boat { return "CraftBoat{boatType=" + getBoatType() + ",status=" + getStatus() + ",passengers=" + getPassengers().stream().map(Entity::toString).collect(Collectors.joining("-", "{", "}")) + "}"; } - public static Boat.Type boatTypeFromNms(EntityBoat.EnumBoatType boatType) { - return switch (boatType) { - default -> throw new EnumConstantNotPresentException(Type.class, boatType.name()); - case OAK -> Type.OAK; - case BIRCH -> Type.BIRCH; - case ACACIA -> Type.ACACIA; - case CHERRY -> Type.CHERRY; - case JUNGLE -> Type.JUNGLE; - case SPRUCE -> Type.SPRUCE; - case DARK_OAK -> Type.DARK_OAK; - case MANGROVE -> Type.MANGROVE; - case BAMBOO -> Type.BAMBOO; - }; - } + public static Boat.Type boatTypeFromNms(EntityTypes boatType) { + if (boatType == EntityTypes.OAK_BOAT || boatType == EntityTypes.OAK_CHEST_BOAT) { + return Type.OAK; + } - public static EntityBoat.EnumBoatType boatTypeToNms(Boat.Type type) { - return switch (type) { - default -> throw new EnumConstantNotPresentException(EntityBoat.EnumBoatType.class, type.name()); - case BAMBOO -> EntityBoat.EnumBoatType.BAMBOO; - case MANGROVE -> EntityBoat.EnumBoatType.MANGROVE; - case SPRUCE -> EntityBoat.EnumBoatType.SPRUCE; - case DARK_OAK -> EntityBoat.EnumBoatType.DARK_OAK; - case JUNGLE -> EntityBoat.EnumBoatType.JUNGLE; - case CHERRY -> EntityBoat.EnumBoatType.CHERRY; - case ACACIA -> EntityBoat.EnumBoatType.ACACIA; - case BIRCH -> EntityBoat.EnumBoatType.BIRCH; - case OAK -> EntityBoat.EnumBoatType.OAK; - }; + if (boatType == EntityTypes.BIRCH_BOAT || boatType == EntityTypes.BIRCH_CHEST_BOAT) { + return Type.BIRCH; + } + + if (boatType == EntityTypes.ACACIA_BOAT || boatType == EntityTypes.ACACIA_CHEST_BOAT) { + return Type.ACACIA; + } + + if (boatType == EntityTypes.CHERRY_BOAT || boatType == EntityTypes.CHERRY_CHEST_BOAT) { + return Type.CHERRY; + } + + if (boatType == EntityTypes.JUNGLE_BOAT || boatType == EntityTypes.JUNGLE_CHEST_BOAT) { + return Type.JUNGLE; + } + + if (boatType == EntityTypes.SPRUCE_BOAT || boatType == EntityTypes.SPRUCE_CHEST_BOAT) { + return Type.SPRUCE; + } + + if (boatType == EntityTypes.DARK_OAK_BOAT || boatType == EntityTypes.DARK_OAK_CHEST_BOAT) { + return Type.DARK_OAK; + } + + if (boatType == EntityTypes.MANGROVE_BOAT || boatType == EntityTypes.MANGROVE_CHEST_BOAT) { + return Type.MANGROVE; + } + + if (boatType == EntityTypes.BAMBOO_RAFT || boatType == EntityTypes.BAMBOO_CHEST_RAFT) { + return Type.BAMBOO; + } + + throw new EnumConstantNotPresentException(Type.class, boatType.toString()); } public static Status boatStatusFromNms(EntityBoat.EnumStatus enumStatus) { @@ -137,40 +146,27 @@ public class CraftBoat extends CraftVehicle implements Boat { } @Deprecated - public static TreeSpecies getTreeSpecies(EntityBoat.EnumBoatType boatType) { - switch (boatType) { - case SPRUCE: - return TreeSpecies.REDWOOD; - case BIRCH: - return TreeSpecies.BIRCH; - case JUNGLE: - return TreeSpecies.JUNGLE; - case ACACIA: - return TreeSpecies.ACACIA; - case DARK_OAK: - return TreeSpecies.DARK_OAK; - case OAK: - default: - return TreeSpecies.GENERIC; + public static TreeSpecies getTreeSpecies(EntityTypes boatType) { + if (boatType == EntityTypes.SPRUCE_BOAT || boatType == EntityTypes.SPRUCE_CHEST_BOAT) { + return TreeSpecies.REDWOOD; } - } - @Deprecated - public static EntityBoat.EnumBoatType getBoatType(TreeSpecies species) { - switch (species) { - case REDWOOD: - return EntityBoat.EnumBoatType.SPRUCE; - case BIRCH: - return EntityBoat.EnumBoatType.BIRCH; - case JUNGLE: - return EntityBoat.EnumBoatType.JUNGLE; - case ACACIA: - return EntityBoat.EnumBoatType.ACACIA; - case DARK_OAK: - return EntityBoat.EnumBoatType.DARK_OAK; - case GENERIC: - default: - return EntityBoat.EnumBoatType.OAK; + if (boatType == EntityTypes.BIRCH_BOAT || boatType == EntityTypes.BIRCH_CHEST_BOAT) { + return TreeSpecies.BIRCH; } + + if (boatType == EntityTypes.JUNGLE_BOAT || boatType == EntityTypes.JUNGLE_CHEST_BOAT) { + return TreeSpecies.JUNGLE; + } + + if (boatType == EntityTypes.ACACIA_BOAT || boatType == EntityTypes.ACACIA_CHEST_BOAT) { + return TreeSpecies.ACACIA; + } + + if (boatType == EntityTypes.DARK_OAK_BOAT || boatType == EntityTypes.DARK_OAK_CHEST_BOAT) { + return TreeSpecies.DARK_OAK; + } + + return TreeSpecies.GENERIC; } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftChestBoat.java index 99f3c53b09..a359e8a26e 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftChestBoat.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftChestBoat.java @@ -1,24 +1,24 @@ package org.bukkit.craftbukkit.entity; -import net.minecraft.world.entity.vehicle.ChestBoat; +import net.minecraft.world.entity.vehicle.AbstractChestBoat; import org.bukkit.craftbukkit.CraftLootTable; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.inventory.Inventory; import org.bukkit.loot.LootTable; -public class CraftChestBoat extends CraftBoat implements org.bukkit.entity.ChestBoat { +public abstract class CraftChestBoat extends CraftBoat implements org.bukkit.entity.ChestBoat { private final Inventory inventory; - public CraftChestBoat(CraftServer server, ChestBoat entity) { + public CraftChestBoat(CraftServer server, AbstractChestBoat entity) { super(server, entity); inventory = new CraftInventory(entity); } @Override - public ChestBoat getHandle() { - return (ChestBoat) entity; + public AbstractChestBoat getHandle() { + return (AbstractChestBoat) entity; } @Override @@ -38,7 +38,7 @@ public class CraftChestBoat extends CraftBoat implements org.bukkit.entity.Chest @Override public LootTable getLootTable() { - return CraftLootTable.minecraftToBukkit(getHandle().getLootTable()); + return CraftLootTable.minecraftToBukkit(getHandle().getContainerLootTable()); } @Override @@ -48,11 +48,11 @@ public class CraftChestBoat extends CraftBoat implements org.bukkit.entity.Chest @Override public long getSeed() { - return getHandle().getLootTableSeed(); + return getHandle().getContainerLootTableSeed(); } private void setLootTable(LootTable table, long seed) { - getHandle().setLootTable(CraftLootTable.bukkitToMinecraft(table)); - getHandle().setLootTableSeed(seed); + getHandle().setContainerLootTable(CraftLootTable.bukkitToMinecraft(table)); + getHandle().setContainerLootTableSeed(seed); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCreaking.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCreaking.java new file mode 100644 index 0000000000..a896da43b8 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCreaking.java @@ -0,0 +1,21 @@ +package org.bukkit.craftbukkit.entity; + +import net.minecraft.world.entity.monster.creaking.Creaking; +import org.bukkit.craftbukkit.CraftServer; + +public class CraftCreaking extends CraftMonster implements org.bukkit.entity.Creaking { + + public CraftCreaking(CraftServer server, Creaking entity) { + super(server, entity); + } + + @Override + public Creaking getHandle() { + return (Creaking) entity; + } + + @Override + public String toString() { + return "CraftCreaking"; + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCreakingTransient.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCreakingTransient.java new file mode 100644 index 0000000000..4366c35849 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCreakingTransient.java @@ -0,0 +1,21 @@ +package org.bukkit.craftbukkit.entity; + +import net.minecraft.world.entity.monster.creaking.CreakingTransient; +import org.bukkit.craftbukkit.CraftServer; + +public class CraftCreakingTransient extends CraftCreaking implements org.bukkit.entity.CreakingTransient { + + public CraftCreakingTransient(CraftServer server, CreakingTransient entity) { + super(server, entity); + } + + @Override + public CreakingTransient getHandle() { + return (CreakingTransient) entity; + } + + @Override + public String toString() { + return "CraftCreakingTransient"; + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftDolphin.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftDolphin.java index 12b316b58b..13ee061e14 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftDolphin.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftDolphin.java @@ -4,7 +4,7 @@ import net.minecraft.world.entity.animal.EntityDolphin; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Dolphin; -public class CraftDolphin extends CraftWaterMob implements Dolphin { +public class CraftDolphin extends CraftAgeable implements Dolphin { public CraftDolphin(CraftServer server, EntityDolphin entity) { super(server, entity); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index 0d56f8658b..1ffd115276 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java @@ -16,12 +16,13 @@ import net.minecraft.server.level.PlayerChunkMap; import net.minecraft.server.level.WorldServer; import net.minecraft.server.network.ServerPlayerConnection; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.entity.boss.EntityComplexPart; import net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon; import net.minecraft.world.entity.player.EntityHuman; import net.minecraft.world.entity.projectile.EntityArrow; -import net.minecraft.world.level.portal.DimensionTransition; +import net.minecraft.world.level.portal.TeleportTransition; import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; import org.bukkit.EntityEffect; @@ -153,7 +154,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { @Override public boolean isOnGround() { if (entity instanceof EntityArrow) { - return ((EntityArrow) entity).inGround; + return ((EntityArrow) entity).isInGround(); } return entity.onGround(); } @@ -204,7 +205,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { if (location.getWorld() != null && !location.getWorld().equals(getWorld())) { // Prevent teleportation to an other world during world generation Preconditions.checkState(!entity.generation, "Cannot teleport entity to an other world during world generation"); - entity.changeDimension(new DimensionTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), Vec3D.ZERO, location.getPitch(), location.getYaw(), DimensionTransition.DO_NOTHING, TeleportCause.PLUGIN)); + entity.teleport(new TeleportTransition(((CraftWorld) location.getWorld()).getHandle(), CraftLocation.toVec3D(location), Vec3D.ZERO, location.getPitch(), location.getYaw(), Set.of(), TeleportTransition.DO_NOTHING, TeleportCause.PLUGIN)); return true; } @@ -703,7 +704,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { @Override public boolean isInvulnerable() { - return getHandle().isInvulnerableTo(getHandle().damageSources().generic()); + return getHandle().isInvulnerableToBase(getHandle().damageSources().generic()); } @Override @@ -820,7 +821,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { NBTTagCompound compoundTag = new NBTTagCompound(); getHandle().saveAsPassenger(compoundTag, false); - return EntityTypes.loadEntityRecursive(compoundTag, level, java.util.function.Function.identity()); + return EntityTypes.loadEntityRecursive(compoundTag, level, EntitySpawnReason.LOAD, java.util.function.Function.identity()); } public void storeBukkitValues(NBTTagCompound c) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntitySnapshot.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntitySnapshot.java index 79c56e731a..b3409ee182 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntitySnapshot.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntitySnapshot.java @@ -3,6 +3,7 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; import java.util.function.Function; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.EntityTypes; import org.bukkit.Location; import org.bukkit.World; @@ -49,9 +50,9 @@ public class CraftEntitySnapshot implements EntitySnapshot { private net.minecraft.world.entity.Entity createInternal(World world) { net.minecraft.world.level.World nms = ((CraftWorld) world).getHandle(); - net.minecraft.world.entity.Entity internal = EntityTypes.loadEntityRecursive(data, nms, Function.identity()); + net.minecraft.world.entity.Entity internal = EntityTypes.loadEntityRecursive(data, nms, EntitySpawnReason.LOAD, Function.identity()); if (internal == null) { // Try creating by type - internal = CraftEntityType.bukkitToMinecraft(type).create(nms); + internal = CraftEntityType.bukkitToMinecraft(type).create(nms, EntitySpawnReason.LOAD); } Preconditions.checkArgument(internal != null, "Error creating new entity."); // This should only fail if the stored NBTTagCompound is malformed. diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java index 511523d9c7..a561fd00b8 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityType.java @@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; import java.util.Locale; +import net.minecraft.core.Holder; import net.minecraft.core.IRegistry; import net.minecraft.core.registries.Registries; import net.minecraft.world.entity.EntityTypes; @@ -33,6 +34,19 @@ public class CraftEntityType { .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); } + public static Holder> bukkitToMinecraftHolder(EntityType bukkit) { + Preconditions.checkArgument(bukkit != null); + + IRegistry> registry = CraftRegistry.getMinecraftRegistry(Registries.ENTITY_TYPE); + + if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c> holder) { + return holder; + } + + throw new IllegalArgumentException("No Reference holder found for " + bukkit + + ", this can happen if a plugin creates its own sound effect with out properly registering it."); + } + public static String bukkitToString(EntityType bukkit) { Preconditions.checkArgument(bukkit != null); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityTypes.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityTypes.java index 45691e2c6f..1105204f77 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityTypes.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntityTypes.java @@ -12,6 +12,7 @@ import net.minecraft.core.BlockPosition; import net.minecraft.core.EnumDirection; import net.minecraft.world.entity.EntityAreaEffectCloud; import net.minecraft.world.entity.EntityExperienceOrb; +import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.entity.boss.enderdragon.EntityEnderDragon; import net.minecraft.world.entity.decoration.EntityHanging; @@ -28,13 +29,8 @@ import net.minecraft.world.entity.projectile.EntityFireball; import net.minecraft.world.entity.projectile.EntityFireworks; import net.minecraft.world.entity.projectile.EntityPotion; import net.minecraft.world.entity.projectile.EntitySnowball; -import net.minecraft.world.entity.vehicle.EntityMinecartChest; -import net.minecraft.world.entity.vehicle.EntityMinecartCommandBlock; -import net.minecraft.world.entity.vehicle.EntityMinecartFurnace; -import net.minecraft.world.entity.vehicle.EntityMinecartHopper; -import net.minecraft.world.entity.vehicle.EntityMinecartMobSpawner; -import net.minecraft.world.entity.vehicle.EntityMinecartRideable; -import net.minecraft.world.entity.vehicle.EntityMinecartTNT; +import net.minecraft.world.entity.vehicle.EntityMinecartAbstract; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.GeneratorAccessSeed; import net.minecraft.world.level.World; @@ -44,11 +40,29 @@ import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.block.CraftBlock; -import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.entity.boat.CraftAcaciaBoat; +import org.bukkit.craftbukkit.entity.boat.CraftAcaciaChestBoat; +import org.bukkit.craftbukkit.entity.boat.CraftBambooChestRaft; +import org.bukkit.craftbukkit.entity.boat.CraftBambooRaft; +import org.bukkit.craftbukkit.entity.boat.CraftBirchBoat; +import org.bukkit.craftbukkit.entity.boat.CraftBirchChestBoat; +import org.bukkit.craftbukkit.entity.boat.CraftCherryBoat; +import org.bukkit.craftbukkit.entity.boat.CraftCherryChestBoat; +import org.bukkit.craftbukkit.entity.boat.CraftDarkOakBoat; +import org.bukkit.craftbukkit.entity.boat.CraftDarkOakChestBoat; +import org.bukkit.craftbukkit.entity.boat.CraftJungleBoat; +import org.bukkit.craftbukkit.entity.boat.CraftJungleChestBoat; +import org.bukkit.craftbukkit.entity.boat.CraftMangroveBoat; +import org.bukkit.craftbukkit.entity.boat.CraftMangroveChestBoat; +import org.bukkit.craftbukkit.entity.boat.CraftOakBoat; +import org.bukkit.craftbukkit.entity.boat.CraftOakChestBoat; +import org.bukkit.craftbukkit.entity.boat.CraftPaleOakBoat; +import org.bukkit.craftbukkit.entity.boat.CraftPaleOakChestBoat; +import org.bukkit.craftbukkit.entity.boat.CraftSpruceBoat; +import org.bukkit.craftbukkit.entity.boat.CraftSpruceChestBoat; import org.bukkit.entity.Allay; import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.Armadillo; @@ -59,17 +73,17 @@ import org.bukkit.entity.Bat; import org.bukkit.entity.Bee; import org.bukkit.entity.Blaze; import org.bukkit.entity.BlockDisplay; -import org.bukkit.entity.Boat; import org.bukkit.entity.Bogged; import org.bukkit.entity.Breeze; import org.bukkit.entity.BreezeWindCharge; import org.bukkit.entity.Camel; import org.bukkit.entity.Cat; import org.bukkit.entity.CaveSpider; -import org.bukkit.entity.ChestBoat; import org.bukkit.entity.Chicken; import org.bukkit.entity.Cod; import org.bukkit.entity.Cow; +import org.bukkit.entity.Creaking; +import org.bukkit.entity.CreakingTransient; import org.bukkit.entity.Creeper; import org.bukkit.entity.Dolphin; import org.bukkit.entity.Donkey; @@ -175,6 +189,26 @@ import org.bukkit.entity.Zoglin; import org.bukkit.entity.Zombie; import org.bukkit.entity.ZombieHorse; import org.bukkit.entity.ZombieVillager; +import org.bukkit.entity.boat.AcaciaBoat; +import org.bukkit.entity.boat.AcaciaChestBoat; +import org.bukkit.entity.boat.BambooChestRaft; +import org.bukkit.entity.boat.BambooRaft; +import org.bukkit.entity.boat.BirchBoat; +import org.bukkit.entity.boat.BirchChestBoat; +import org.bukkit.entity.boat.CherryBoat; +import org.bukkit.entity.boat.CherryChestBoat; +import org.bukkit.entity.boat.DarkOakBoat; +import org.bukkit.entity.boat.DarkOakChestBoat; +import org.bukkit.entity.boat.JungleBoat; +import org.bukkit.entity.boat.JungleChestBoat; +import org.bukkit.entity.boat.MangroveBoat; +import org.bukkit.entity.boat.MangroveChestBoat; +import org.bukkit.entity.boat.OakBoat; +import org.bukkit.entity.boat.OakChestBoat; +import org.bukkit.entity.boat.PaleOakBoat; +import org.bukkit.entity.boat.PaleOakChestBoat; +import org.bukkit.entity.boat.SpruceBoat; +import org.bukkit.entity.boat.SpruceChestBoat; import org.bukkit.entity.minecart.CommandMinecart; import org.bukkit.entity.minecart.ExplosiveMinecart; import org.bukkit.entity.minecart.HopperMinecart; @@ -182,7 +216,6 @@ import org.bukkit.entity.minecart.PoweredMinecart; import org.bukkit.entity.minecart.RideableMinecart; import org.bukkit.entity.minecart.SpawnerMinecart; import org.bukkit.entity.minecart.StorageMinecart; -import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; public final class CraftEntityTypes { @@ -317,6 +350,8 @@ public final class CraftEntityTypes { register(new EntityTypeData<>(EntityType.SNIFFER, Sniffer.class, CraftSniffer::new, createLiving(EntityTypes.SNIFFER))); register(new EntityTypeData<>(EntityType.BREEZE, Breeze.class, CraftBreeze::new, createLiving(EntityTypes.BREEZE))); register(new EntityTypeData<>(EntityType.ARMADILLO, Armadillo.class, CraftArmadillo::new, createLiving(EntityTypes.ARMADILLO))); + register(new EntityTypeData<>(EntityType.CREAKING, Creaking.class, CraftCreaking::new, createLiving(EntityTypes.CREAKING))); + register(new EntityTypeData<>(EntityType.CREAKING_TRANSIENT, CreakingTransient.class, CraftCreakingTransient::new, createLiving(EntityTypes.CREAKING_TRANSIENT))); Function dragonFunction = createLiving(EntityTypes.ENDER_DRAGON); register(new EntityTypeData<>(EntityType.ENDER_DRAGON, EnderDragon.class, CraftEnderDragon::new, spawnData -> { @@ -358,10 +393,29 @@ public final class CraftEntityTypes { // Move register(new EntityTypeData<>(EntityType.SHULKER_BULLET, ShulkerBullet.class, CraftShulkerBullet::new, createAndMove(EntityTypes.SHULKER_BULLET))); - register(new EntityTypeData<>(EntityType.BOAT, Boat.class, CraftBoat::new, createAndMove(EntityTypes.BOAT))); register(new EntityTypeData<>(EntityType.LLAMA_SPIT, LlamaSpit.class, CraftLlamaSpit::new, createAndMove(EntityTypes.LLAMA_SPIT))); - register(new EntityTypeData<>(EntityType.CHEST_BOAT, ChestBoat.class, CraftChestBoat::new, createAndMove(EntityTypes.CHEST_BOAT))); register(new EntityTypeData<>(EntityType.OMINOUS_ITEM_SPAWNER, OminousItemSpawner.class, CraftOminousItemSpawner::new, createAndMove(EntityTypes.OMINOUS_ITEM_SPAWNER))); + // Move (boats) + register(new EntityTypeData<>(EntityType.ACACIA_BOAT, AcaciaBoat.class, CraftAcaciaBoat::new, createAndMove(EntityTypes.ACACIA_BOAT))); + register(new EntityTypeData<>(EntityType.ACACIA_CHEST_BOAT, AcaciaChestBoat.class, CraftAcaciaChestBoat::new, createAndMove(EntityTypes.ACACIA_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.BAMBOO_RAFT, BambooRaft.class, CraftBambooRaft::new, createAndMove(EntityTypes.BAMBOO_RAFT))); + register(new EntityTypeData<>(EntityType.BAMBOO_CHEST_RAFT, BambooChestRaft.class, CraftBambooChestRaft::new, createAndMove(EntityTypes.BAMBOO_CHEST_RAFT))); + register(new EntityTypeData<>(EntityType.BIRCH_BOAT, BirchBoat.class, CraftBirchBoat::new, createAndMove(EntityTypes.BIRCH_BOAT))); + register(new EntityTypeData<>(EntityType.BIRCH_CHEST_BOAT, BirchChestBoat.class, CraftBirchChestBoat::new, createAndMove(EntityTypes.BIRCH_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.CHERRY_BOAT, CherryBoat.class, CraftCherryBoat::new, createAndMove(EntityTypes.CHERRY_BOAT))); + register(new EntityTypeData<>(EntityType.CHERRY_CHEST_BOAT, CherryChestBoat.class, CraftCherryChestBoat::new, createAndMove(EntityTypes.CHERRY_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.DARK_OAK_BOAT, DarkOakBoat.class, CraftDarkOakBoat::new, createAndMove(EntityTypes.DARK_OAK_BOAT))); + register(new EntityTypeData<>(EntityType.DARK_OAK_CHEST_BOAT, DarkOakChestBoat.class, CraftDarkOakChestBoat::new, createAndMove(EntityTypes.DARK_OAK_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.JUNGLE_BOAT, JungleBoat.class, CraftJungleBoat::new, createAndMove(EntityTypes.JUNGLE_BOAT))); + register(new EntityTypeData<>(EntityType.JUNGLE_CHEST_BOAT, JungleChestBoat.class, CraftJungleChestBoat::new, createAndMove(EntityTypes.JUNGLE_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.MANGROVE_BOAT, MangroveBoat.class, CraftMangroveBoat::new, createAndMove(EntityTypes.MANGROVE_BOAT))); + register(new EntityTypeData<>(EntityType.MANGROVE_CHEST_BOAT, MangroveChestBoat.class, CraftMangroveChestBoat::new, createAndMove(EntityTypes.MANGROVE_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.OAK_BOAT, OakBoat.class, CraftOakBoat::new, createAndMove(EntityTypes.OAK_BOAT))); + register(new EntityTypeData<>(EntityType.OAK_CHEST_BOAT, OakChestBoat.class, CraftOakChestBoat::new, createAndMove(EntityTypes.OAK_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.PALE_OAK_BOAT, PaleOakBoat.class, CraftPaleOakBoat::new, createAndMove(EntityTypes.PALE_OAK_BOAT))); + register(new EntityTypeData<>(EntityType.PALE_OAK_CHEST_BOAT, PaleOakChestBoat.class, CraftPaleOakChestBoat::new, createAndMove(EntityTypes.PALE_OAK_CHEST_BOAT))); + register(new EntityTypeData<>(EntityType.SPRUCE_BOAT, SpruceBoat.class, CraftSpruceBoat::new, createAndMove(EntityTypes.SPRUCE_BOAT))); + register(new EntityTypeData<>(EntityType.SPRUCE_CHEST_BOAT, SpruceChestBoat.class, CraftSpruceChestBoat::new, createAndMove(EntityTypes.SPRUCE_CHEST_BOAT))); // Set pos register(new EntityTypeData<>(EntityType.MARKER, Marker.class, CraftMarker::new, createAndSetPos(EntityTypes.MARKER))); @@ -384,13 +438,12 @@ public final class CraftEntityTypes { spawnData -> new EntityExperienceOrb(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), 0) )); register(new EntityTypeData<>(EntityType.AREA_EFFECT_CLOUD, AreaEffectCloud.class, CraftAreaEffectCloud::new, spawnData -> new EntityAreaEffectCloud(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z()))); - register(new EntityTypeData<>(EntityType.EGG, Egg.class, CraftEgg::new, spawnData -> new EntityEgg(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z()))); + register(new EntityTypeData<>(EntityType.EGG, Egg.class, CraftEgg::new, spawnData -> new EntityEgg(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), new net.minecraft.world.item.ItemStack(Items.EGG)))); register(new EntityTypeData<>(EntityType.LEASH_KNOT, LeashHitch.class, CraftLeash::new, spawnData -> new EntityLeash(spawnData.minecraftWorld(), BlockPosition.containing(spawnData.x(), spawnData.y(), spawnData.z())))); // SPIGOT-5732: LeashHitch has no direction and is always centered at a block - register(new EntityTypeData<>(EntityType.SNOWBALL, Snowball.class, CraftSnowball::new, spawnData -> new EntitySnowball(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z()))); + register(new EntityTypeData<>(EntityType.SNOWBALL, Snowball.class, CraftSnowball::new, spawnData -> new EntitySnowball(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), new net.minecraft.world.item.ItemStack(Items.SNOWBALL)))); register(new EntityTypeData<>(EntityType.EYE_OF_ENDER, EnderSignal.class, CraftEnderSignal::new, spawnData -> new EntityEnderSignal(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z()))); register(new EntityTypeData<>(EntityType.POTION, ThrownPotion.class, CraftThrownPotion::new, spawnData -> { - EntityPotion entity = new EntityPotion(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z()); - entity.setItem(CraftItemStack.asNMSCopy(new ItemStack(Material.SPLASH_POTION, 1))); + EntityPotion entity = new EntityPotion(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), new net.minecraft.world.item.ItemStack(Items.SPLASH_POTION)); return entity; })); register(new EntityTypeData<>(EntityType.TNT, TNTPrimed.class, CraftTNTPrimed::new, spawnData -> new EntityTNTPrimed(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), null))); @@ -400,13 +453,13 @@ public final class CraftEntityTypes { })); register(new EntityTypeData<>(EntityType.FIREWORK_ROCKET, Firework.class, CraftFirework::new, spawnData -> new EntityFireworks(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), net.minecraft.world.item.ItemStack.EMPTY))); register(new EntityTypeData<>(EntityType.EVOKER_FANGS, EvokerFangs.class, CraftEvokerFangs::new, spawnData -> new EntityEvokerFangs(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), (float) Math.toRadians(spawnData.yaw()), 0, null))); - register(new EntityTypeData<>(EntityType.COMMAND_BLOCK_MINECART, CommandMinecart.class, CraftMinecartCommand::new, spawnData -> new EntityMinecartCommandBlock(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z()))); - register(new EntityTypeData<>(EntityType.MINECART, RideableMinecart.class, CraftMinecartRideable::new, spawnData -> new EntityMinecartRideable(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z()))); - register(new EntityTypeData<>(EntityType.CHEST_MINECART, StorageMinecart.class, CraftMinecartChest::new, spawnData -> new EntityMinecartChest(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z()))); - register(new EntityTypeData<>(EntityType.FURNACE_MINECART, PoweredMinecart.class, CraftMinecartFurnace::new, spawnData -> new EntityMinecartFurnace(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z()))); - register(new EntityTypeData<>(EntityType.TNT_MINECART, ExplosiveMinecart.class, CraftMinecartTNT::new, spawnData -> new EntityMinecartTNT(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z()))); - register(new EntityTypeData<>(EntityType.HOPPER_MINECART, HopperMinecart.class, CraftMinecartHopper::new, spawnData -> new EntityMinecartHopper(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z()))); - register(new EntityTypeData<>(EntityType.SPAWNER_MINECART, SpawnerMinecart.class, CraftMinecartMobSpawner::new, spawnData -> new EntityMinecartMobSpawner(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z()))); + register(new EntityTypeData<>(EntityType.COMMAND_BLOCK_MINECART, CommandMinecart.class, CraftMinecartCommand::new, createMinecart(EntityTypes.COMMAND_BLOCK_MINECART))); + register(new EntityTypeData<>(EntityType.MINECART, RideableMinecart.class, CraftMinecartRideable::new, createMinecart(EntityTypes.MINECART))); + register(new EntityTypeData<>(EntityType.CHEST_MINECART, StorageMinecart.class, CraftMinecartChest::new, createMinecart(EntityTypes.CHEST_MINECART))); + register(new EntityTypeData<>(EntityType.FURNACE_MINECART, PoweredMinecart.class, CraftMinecartFurnace::new, createMinecart(EntityTypes.FURNACE_MINECART))); + register(new EntityTypeData<>(EntityType.TNT_MINECART, ExplosiveMinecart.class, CraftMinecartTNT::new, createMinecart(EntityTypes.TNT_MINECART))); + register(new EntityTypeData<>(EntityType.HOPPER_MINECART, HopperMinecart.class, CraftMinecartHopper::new, createMinecart(EntityTypes.HOPPER_MINECART))); + register(new EntityTypeData<>(EntityType.SPAWNER_MINECART, SpawnerMinecart.class, CraftMinecartMobSpawner::new, createMinecart(EntityTypes.SPAWNER_MINECART))); // None spawn able register(new EntityTypeData<>(EntityType.FISHING_BOBBER, FishHook.class, CraftFishHook::new, null)); // Cannot spawn a fish hook @@ -426,7 +479,7 @@ public final class CraftEntityTypes { } private static Function fromEntityType(EntityTypes entityTypes) { - return spawnData -> entityTypes.create(spawnData.minecraftWorld()); + return spawnData -> entityTypes.create(spawnData.minecraftWorld(), EntitySpawnReason.COMMAND); } private static Function createLiving(EntityTypes entityTypes) { @@ -437,6 +490,10 @@ public final class CraftEntityTypes { return combine(createAndMove(entityTypes), DIRECTION); } + private static Function createMinecart(EntityTypes entityTypes) { + return spawnData -> EntityMinecartAbstract.createMinecart(spawnData.minecraftWorld(), spawnData.x(), spawnData.y(), spawnData.z(), entityTypes, EntitySpawnReason.TRIGGERED, ItemStack.EMPTY, null); + } + private static Function createAndMove(EntityTypes entityTypes) { return combine(fromEntityType(entityTypes), MOVE); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java index 24fb29778a..ae7cc82d6d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java @@ -12,9 +12,11 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.network.protocol.game.PacketPlayInCloseWindow; import net.minecraft.network.protocol.game.PacketPlayOutOpenWindow; +import net.minecraft.resources.MinecraftKey; import net.minecraft.server.level.EntityPlayer; import net.minecraft.world.ITileInventory; import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.entity.EnumMainHand; import net.minecraft.world.entity.player.EntityHuman; @@ -45,11 +47,10 @@ import org.bukkit.craftbukkit.inventory.CraftInventoryLectern; import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer; import org.bukkit.craftbukkit.inventory.CraftInventoryView; import org.bukkit.craftbukkit.inventory.CraftItemStack; -import org.bukkit.craftbukkit.inventory.CraftItemType; import org.bukkit.craftbukkit.inventory.CraftMerchantCustom; +import org.bukkit.craftbukkit.inventory.CraftRecipe; import org.bukkit.craftbukkit.util.CraftChatMessage; import org.bukkit.craftbukkit.util.CraftLocation; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.Firework; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Villager; @@ -493,7 +494,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { Preconditions.checkArgument(material != null, "Material cannot be null"); Preconditions.checkArgument(material.isItem(), "Material %s is not an item", material); - return getHandle().getCooldowns().isOnCooldown(CraftItemType.bukkitToMinecraft(material)); + return hasCooldown(new ItemStack(material)); } @Override @@ -501,17 +502,40 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { Preconditions.checkArgument(material != null, "Material cannot be null"); Preconditions.checkArgument(material.isItem(), "Material %s is not an item", material); - ItemCooldown.Info cooldown = getHandle().getCooldowns().cooldowns.get(CraftItemType.bukkitToMinecraft(material)); - return (cooldown == null) ? 0 : Math.max(0, cooldown.endTime - getHandle().getCooldowns().tickCount); + return getCooldown(new ItemStack(material)); } @Override public void setCooldown(Material material, int ticks) { - Preconditions.checkArgument(material != null, "Material cannot be null"); - Preconditions.checkArgument(material.isItem(), "Material %s is not an item", material); + setCooldown(new ItemStack(material), ticks); + } + + @Override + public boolean hasCooldown(ItemStack item) { + Preconditions.checkArgument(item != null, "Material cannot be null"); + + return getHandle().getCooldowns().isOnCooldown(CraftItemStack.asNMSCopy(item)); + } + + @Override + public int getCooldown(ItemStack item) { + Preconditions.checkArgument(item != null, "Material cannot be null"); + + MinecraftKey group = getHandle().getCooldowns().getCooldownGroup(CraftItemStack.asNMSCopy(item)); + if (group == null) { + return 0; + } + + ItemCooldown.Info cooldown = getHandle().getCooldowns().cooldowns.get(group); + return (cooldown == null) ? 0 : Math.max(0, cooldown.endTime - getHandle().getCooldowns().tickCount); + } + + @Override + public void setCooldown(ItemStack item, int ticks) { + Preconditions.checkArgument(item != null, "Material cannot be null"); Preconditions.checkArgument(ticks >= 0, "Cannot have negative cooldown"); - getHandle().getCooldowns().addCooldown(CraftItemType.bukkitToMinecraft(material), ticks); + getHandle().getCooldowns().addCooldown(CraftItemStack.asNMSCopy(item), ticks); } @Override @@ -549,7 +573,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { CraftingManager manager = getHandle().level().getServer().getRecipeManager(); for (NamespacedKey recipeKey : recipeKeys) { - Optional> recipe = manager.byKey(CraftNamespacedKey.toMinecraft(recipeKey)); + Optional> recipe = manager.byKey(CraftRecipe.toMinecraft(recipeKey)); if (!recipe.isPresent()) { continue; } @@ -563,7 +587,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { @Override public org.bukkit.entity.Entity getShoulderEntityLeft() { if (!getHandle().getShoulderEntityLeft().isEmpty()) { - Optional shoulder = EntityTypes.create(getHandle().getShoulderEntityLeft(), getHandle().level()); + Optional shoulder = EntityTypes.create(getHandle().getShoulderEntityLeft(), getHandle().level(), EntitySpawnReason.LOAD); return (!shoulder.isPresent()) ? null : shoulder.get().getBukkitEntity(); } @@ -582,7 +606,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { @Override public org.bukkit.entity.Entity getShoulderEntityRight() { if (!getHandle().getShoulderEntityRight().isEmpty()) { - Optional shoulder = EntityTypes.create(getHandle().getShoulderEntityRight(), getHandle().level()); + Optional shoulder = EntityTypes.create(getHandle().getShoulderEntityRight(), getHandle().level(), EntitySpawnReason.LOAD); return (!shoulder.isPresent()) ? null : shoulder.get().getBukkitEntity(); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java index 5f48235b40..6bde0489d1 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -8,14 +8,17 @@ import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.UUID; +import net.minecraft.core.component.DataComponents; import net.minecraft.network.protocol.game.ClientboundHurtAnimationPacket; import net.minecraft.server.level.WorldServer; import net.minecraft.sounds.SoundEffect; +import net.minecraft.sounds.SoundEffects; import net.minecraft.world.EnumHand; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.entity.EntityInsentient; import net.minecraft.world.entity.EntityLiving; +import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.entity.ai.attributes.GenericAttributes; import net.minecraft.world.entity.boss.wither.EntityWither; @@ -40,6 +43,8 @@ import net.minecraft.world.entity.projectile.EntityThrownExpBottle; import net.minecraft.world.entity.projectile.EntityThrownTrident; import net.minecraft.world.entity.projectile.EntityTippedArrow; import net.minecraft.world.entity.projectile.EntityWitherSkull; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.component.Consumable; import net.minecraft.world.phys.Vec3D; import org.bukkit.FluidCollisionMode; import org.bukkit.Location; @@ -296,6 +301,11 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { getHandle().getEntityData().set(EntityLiving.DATA_ARROW_COUNT_ID, count); } + @Override + public boolean isInvulnerable() { + return getHandle().isInvulnerableTo((WorldServer) getHandle().level(), getHandle().damageSources().generic()); + } + @Override public void damage(double amount) { damage(amount, getHandle().damageSources().generic()); @@ -454,13 +464,13 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { net.minecraft.world.entity.Entity launch = null; if (Snowball.class.isAssignableFrom(projectile)) { - launch = new EntitySnowball(world, getHandle()); + launch = new EntitySnowball(world, getHandle(), new net.minecraft.world.item.ItemStack(Items.SNOWBALL)); ((EntityProjectile) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), 0.0F, 1.5F, 1.0F); // ItemSnowball } else if (Egg.class.isAssignableFrom(projectile)) { - launch = new EntityEgg(world, getHandle()); + launch = new EntityEgg(world, getHandle(), new net.minecraft.world.item.ItemStack(Items.EGG)); ((EntityProjectile) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), 0.0F, 1.5F, 1.0F); // ItemEgg } else if (EnderPearl.class.isAssignableFrom(projectile)) { - launch = new EntityEnderPearl(world, getHandle()); + launch = new EntityEnderPearl(world, getHandle(), new net.minecraft.world.item.ItemStack(Items.ENDER_PEARL)); ((EntityProjectile) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), 0.0F, 1.5F, 1.0F); // ItemEnderPearl } else if (AbstractArrow.class.isAssignableFrom(projectile)) { if (TippedArrow.class.isAssignableFrom(projectile)) { @@ -476,18 +486,16 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { ((EntityArrow) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), 0.0F, 3.0F, 1.0F); // ItemBow } else if (ThrownPotion.class.isAssignableFrom(projectile)) { if (LingeringPotion.class.isAssignableFrom(projectile)) { - launch = new EntityPotion(world, getHandle()); - ((EntityPotion) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1))); + launch = new EntityPotion(world, getHandle(), new net.minecraft.world.item.ItemStack(Items.LINGERING_POTION)); } else { - launch = new EntityPotion(world, getHandle()); - ((EntityPotion) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1))); + launch = new EntityPotion(world, getHandle(), new net.minecraft.world.item.ItemStack(Items.SPLASH_POTION)); } ((EntityProjectile) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), -20.0F, 0.5F, 1.0F); // ItemSplashPotion } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) { - launch = new EntityThrownExpBottle(world, getHandle()); + launch = new EntityThrownExpBottle(world, getHandle(), new net.minecraft.world.item.ItemStack(Items.EXPERIENCE_BOTTLE)); ((EntityProjectile) launch).shootFromRotation(getHandle(), getHandle().getXRot(), getHandle().getYRot(), -20.0F, 0.7F, 1.0F); // ItemExpBottle } else if (FishHook.class.isAssignableFrom(projectile) && getHandle() instanceof EntityHuman) { - launch = new EntityFishingHook((EntityHuman) getHandle(), world, 0, 0); + launch = new EntityFishingHook((EntityHuman) getHandle(), world, 0, 0, new net.minecraft.world.item.ItemStack(Items.FISHING_ROD)); } else if (Fireball.class.isAssignableFrom(projectile)) { Location location = getEyeLocation(); Vector direction = location.getDirection().multiply(10); @@ -501,9 +509,9 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { launch = new EntityDragonFireball(world, getHandle(), vec); } else if (AbstractWindCharge.class.isAssignableFrom(projectile)) { if (BreezeWindCharge.class.isAssignableFrom(projectile)) { - launch = EntityTypes.BREEZE_WIND_CHARGE.create(world); + launch = EntityTypes.BREEZE_WIND_CHARGE.create(world, EntitySpawnReason.TRIGGERED); } else { - launch = EntityTypes.WIND_CHARGE.create(world); + launch = EntityTypes.WIND_CHARGE.create(world, EntitySpawnReason.TRIGGERED); } ((net.minecraft.world.entity.projectile.windcharge.AbstractWindCharge) launch).setOwner(getHandle()); @@ -518,7 +526,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { Location location = getEyeLocation(); Vector direction = location.getDirection(); - launch = EntityTypes.LLAMA_SPIT.create(world); + launch = EntityTypes.LLAMA_SPIT.create(world, EntitySpawnReason.TRIGGERED); ((EntityLlamaSpit) launch).setOwner(getHandle()); ((EntityLlamaSpit) launch).shoot(direction.getX(), direction.getY(), direction.getZ(), 1.5F, 10.0F); // EntityLlama @@ -704,7 +712,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { if (getHandle() instanceof EntityHuman) { ((EntityHuman) getHandle()).attack(((CraftEntity) target).getHandle()); } else { - getHandle().doHurtTarget(((CraftEntity) target).getHandle()); + getHandle().doHurtTarget((WorldServer) ((CraftEntity) target).getHandle().level(), ((CraftEntity) target).getHandle()); } } @@ -790,14 +798,26 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { @Override public Sound getDrinkingSound(ItemStack itemStack) { - Preconditions.checkArgument(itemStack != null, "itemStack must not be null"); - return CraftSound.minecraftToBukkit(getHandle().getDrinkingSound0(CraftItemStack.asNMSCopy(itemStack))); + return getEatingSound(itemStack); } @Override public Sound getEatingSound(ItemStack itemStack) { Preconditions.checkArgument(itemStack != null, "itemStack must not be null"); - return CraftSound.minecraftToBukkit(getHandle().getEatingSound0(CraftItemStack.asNMSCopy(itemStack))); + + net.minecraft.world.item.ItemStack nms = CraftItemStack.asNMSCopy(itemStack); + Consumable consumable = nms.get(DataComponents.CONSUMABLE); + SoundEffect soundeffect = SoundEffects.GENERIC_DRINK.value(); + + if (consumable != null) { + if (getHandle() instanceof Consumable.b consumable_b) { + soundeffect = consumable_b.getConsumeSound(nms); + } else { + soundeffect = (SoundEffect) consumable.sound().value(); + } + } + + return CraftSound.minecraftToBukkit(soundeffect); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartTNT.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartTNT.java index db91c9b48c..c7f3da5e4c 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartTNT.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartTNT.java @@ -10,6 +10,26 @@ public final class CraftMinecartTNT extends CraftMinecart implements ExplosiveMi super(server, entity); } + @Override + public float getYield() { + return getHandle().explosionPowerBase; + } + + @Override + public boolean isIncendiary() { + return getHandle().isIncendiary; + } + + @Override + public void setIsIncendiary(boolean isIncendiary) { + getHandle().isIncendiary = isIncendiary; + } + + @Override + public void setYield(float yield) { + getHandle().explosionPowerBase = yield; + } + @Override public void setFuseTicks(int ticks) { getHandle().fuse = ticks; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java index fd3e321258..4a52c56f07 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMob.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; +import java.util.Optional; import net.minecraft.sounds.SoundEffect; import net.minecraft.world.entity.EntityInsentient; import org.bukkit.Sound; @@ -63,12 +64,12 @@ public abstract class CraftMob extends CraftLivingEntity implements Mob { @Override public void setLootTable(LootTable table) { - getHandle().lootTable = CraftLootTable.bukkitToMinecraft(table); + getHandle().lootTable = Optional.ofNullable(CraftLootTable.bukkitToMinecraft(table)); } @Override public LootTable getLootTable() { - return CraftLootTable.minecraftToBukkit(getHandle().getLootTable()); + return CraftLootTable.minecraftToBukkit(getHandle().getLootTable().orElse(null)); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index ad8bc24b5d..1c9ae250b4 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -160,6 +160,7 @@ import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.conversations.ConversationTracker; import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.inventory.CraftRecipe; import org.bukkit.craftbukkit.map.CraftMapCursor; import org.bukkit.craftbukkit.map.CraftMapView; import org.bukkit.craftbukkit.map.RenderData; @@ -418,6 +419,18 @@ public class CraftPlayer extends CraftHumanEntity implements Player { } } + @Override + public int getPlayerListOrder() { + return getHandle().listOrder; + } + + @Override + public void setPlayerListOrder(int order) { + Preconditions.checkArgument(order >= 0, "order cannot be negative"); + + getHandle().listOrder = order; + } + private IChatBaseComponent playerListHeader; private IChatBaseComponent playerListFooter; @@ -961,7 +974,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { } } - PacketPlayOutMap packet = new PacketPlayOutMap(new MapId(map.getId()), map.getScale().getValue(), map.isLocked(), icons, new WorldMap.b(0, 0, 128, 128, data.buffer)); + PacketPlayOutMap packet = new PacketPlayOutMap(new MapId(map.getId()), map.getScale().getValue(), map.isLocked(), icons, new WorldMap.c(0, 0, 128, 128, data.buffer)); getHandle().connection.send(packet); } @@ -1184,13 +1197,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player { @Override public boolean hasDiscoveredRecipe(NamespacedKey recipe) { Preconditions.checkArgument(recipe != null, "recipe cannot be null"); - return getHandle().getRecipeBook().contains(CraftNamespacedKey.toMinecraft(recipe)); + return getHandle().getRecipeBook().contains(CraftRecipe.toMinecraft(recipe)); } @Override public Set getDiscoveredRecipes() { ImmutableSet.Builder bukkitRecipeKeys = ImmutableSet.builder(); - getHandle().getRecipeBook().known.forEach(key -> bukkitRecipeKeys.add(CraftNamespacedKey.fromMinecraft(key))); + getHandle().getRecipeBook().known.forEach(key -> bukkitRecipeKeys.add(CraftNamespacedKey.fromMinecraft(key.location()))); return bukkitRecipeKeys.build(); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSalmon.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSalmon.java index 041ed192d5..171691e15f 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSalmon.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSalmon.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit.entity; +import com.google.common.base.Preconditions; import net.minecraft.world.entity.animal.EntitySalmon; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Salmon; @@ -19,4 +20,16 @@ public class CraftSalmon extends CraftFish implements Salmon { public String toString() { return "CraftSalmon"; } + + @Override + public Variant getVariant() { + return Variant.values()[getHandle().getVariant().ordinal()]; + } + + @Override + public void setVariant(Variant variant) { + Preconditions.checkArgument(variant != null, "variant"); + + getHandle().setVariant(EntitySalmon.a.values()[variant.ordinal()]); + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSquid.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSquid.java index 82e0109a30..25df325da4 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSquid.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSquid.java @@ -4,7 +4,7 @@ import net.minecraft.world.entity.animal.EntitySquid; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Squid; -public class CraftSquid extends CraftWaterMob implements Squid { +public class CraftSquid extends CraftAgeable implements Squid { public CraftSquid(CraftServer server, EntitySquid entity) { super(server, entity); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftTNTPrimed.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftTNTPrimed.java index 7ad063e0ef..872642b24d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftTNTPrimed.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftTNTPrimed.java @@ -15,7 +15,7 @@ public class CraftTNTPrimed extends CraftEntity implements TNTPrimed { @Override public float getYield() { - return getHandle().yield; + return getHandle().explosionPower; } @Override @@ -30,7 +30,7 @@ public class CraftTNTPrimed extends CraftEntity implements TNTPrimed { @Override public void setYield(float yield) { - getHandle().yield = yield; + getHandle().explosionPower = yield; } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java index ccdf3af2d3..2c5e0b8940 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftVillager.java @@ -21,6 +21,7 @@ import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.entity.Villager; import org.bukkit.entity.ZombieVillager; import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityTransformEvent; public class CraftVillager extends CraftAbstractVillager implements Villager { @@ -123,7 +124,7 @@ public class CraftVillager extends CraftAbstractVillager implements Villager { @Override public ZombieVillager zombify() { - EntityZombieVillager entityzombievillager = EntityZombie.zombifyVillager(getHandle().level().getMinecraftWorld(), getHandle(), getHandle().blockPosition(), isSilent(), CreatureSpawnEvent.SpawnReason.CUSTOM); + EntityZombieVillager entityzombievillager = EntityZombie.convertVillagerToZombieVillager(getHandle().level().getMinecraftWorld(), getHandle(), getHandle().blockPosition(), isSilent(), EntityTransformEvent.TransformReason.INFECTION, CreatureSpawnEvent.SpawnReason.CUSTOM); return (entityzombievillager != null) ? (ZombieVillager) entityzombievillager.getBukkitEntity() : null; } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWolf.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWolf.java index 14b31d4f9f..90129132b2 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWolf.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWolf.java @@ -51,7 +51,7 @@ public class CraftWolf extends CraftTameableAnimal implements Wolf { @Override public boolean isWet() { - return getHandle().isWet(); + return getHandle().isWet; } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaBoat.java new file mode 100644 index 0000000000..0ffa2e8e05 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftBoat; +import org.bukkit.entity.boat.AcaciaBoat; + +public class CraftAcaciaBoat extends CraftBoat implements AcaciaBoat { + + public CraftAcaciaBoat(CraftServer server, AbstractBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaChestBoat.java new file mode 100644 index 0000000000..29bb5460b3 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftAcaciaChestBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractChestBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftChestBoat; +import org.bukkit.entity.boat.AcaciaChestBoat; + +public class CraftAcaciaChestBoat extends CraftChestBoat implements AcaciaChestBoat { + + public CraftAcaciaChestBoat(CraftServer server, AbstractChestBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooChestRaft.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooChestRaft.java new file mode 100644 index 0000000000..eea5763585 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooChestRaft.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractChestBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftChestBoat; +import org.bukkit.entity.boat.BambooChestRaft; + +public class CraftBambooChestRaft extends CraftChestBoat implements BambooChestRaft { + + public CraftBambooChestRaft(CraftServer server, AbstractChestBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooRaft.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooRaft.java new file mode 100644 index 0000000000..05952dd62c --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBambooRaft.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftBoat; +import org.bukkit.entity.boat.BambooRaft; + +public class CraftBambooRaft extends CraftBoat implements BambooRaft { + + public CraftBambooRaft(CraftServer server, AbstractBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchBoat.java new file mode 100644 index 0000000000..1d629bf9df --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftBoat; +import org.bukkit.entity.boat.BirchBoat; + +public class CraftBirchBoat extends CraftBoat implements BirchBoat { + + public CraftBirchBoat(CraftServer server, AbstractBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchChestBoat.java new file mode 100644 index 0000000000..24734c47a7 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftBirchChestBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractChestBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftChestBoat; +import org.bukkit.entity.boat.BirchChestBoat; + +public class CraftBirchChestBoat extends CraftChestBoat implements BirchChestBoat { + + public CraftBirchChestBoat(CraftServer server, AbstractChestBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryBoat.java new file mode 100644 index 0000000000..3f55982cc5 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftBoat; +import org.bukkit.entity.boat.CherryBoat; + +public class CraftCherryBoat extends CraftBoat implements CherryBoat { + + public CraftCherryBoat(CraftServer server, AbstractBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryChestBoat.java new file mode 100644 index 0000000000..a983236cab --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftCherryChestBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractChestBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftChestBoat; +import org.bukkit.entity.boat.CherryChestBoat; + +public class CraftCherryChestBoat extends CraftChestBoat implements CherryChestBoat { + + public CraftCherryChestBoat(CraftServer server, AbstractChestBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakBoat.java new file mode 100644 index 0000000000..06c64e9220 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftBoat; +import org.bukkit.entity.boat.DarkOakBoat; + +public class CraftDarkOakBoat extends CraftBoat implements DarkOakBoat { + + public CraftDarkOakBoat(CraftServer server, AbstractBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakChestBoat.java new file mode 100644 index 0000000000..f49955cfea --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftDarkOakChestBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractChestBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftChestBoat; +import org.bukkit.entity.boat.DarkOakChestBoat; + +public class CraftDarkOakChestBoat extends CraftChestBoat implements DarkOakChestBoat { + + public CraftDarkOakChestBoat(CraftServer server, AbstractChestBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleBoat.java new file mode 100644 index 0000000000..400bfe4523 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftBoat; +import org.bukkit.entity.boat.JungleBoat; + +public class CraftJungleBoat extends CraftBoat implements JungleBoat { + + public CraftJungleBoat(CraftServer server, AbstractBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleChestBoat.java new file mode 100644 index 0000000000..e8d6cd4c96 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftJungleChestBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractChestBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftChestBoat; +import org.bukkit.entity.boat.JungleChestBoat; + +public class CraftJungleChestBoat extends CraftChestBoat implements JungleChestBoat { + + public CraftJungleChestBoat(CraftServer server, AbstractChestBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveBoat.java new file mode 100644 index 0000000000..c1f0c3e558 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftBoat; +import org.bukkit.entity.boat.MangroveBoat; + +public class CraftMangroveBoat extends CraftBoat implements MangroveBoat { + + public CraftMangroveBoat(CraftServer server, AbstractBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveChestBoat.java new file mode 100644 index 0000000000..97eb913be0 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftMangroveChestBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractChestBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftChestBoat; +import org.bukkit.entity.boat.MangroveChestBoat; + +public class CraftMangroveChestBoat extends CraftChestBoat implements MangroveChestBoat { + + public CraftMangroveChestBoat(CraftServer server, AbstractChestBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakBoat.java new file mode 100644 index 0000000000..7e3e8f5fda --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftBoat; +import org.bukkit.entity.boat.OakBoat; + +public class CraftOakBoat extends CraftBoat implements OakBoat { + + public CraftOakBoat(CraftServer server, AbstractBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakChestBoat.java new file mode 100644 index 0000000000..7beb164491 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftOakChestBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractChestBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftChestBoat; +import org.bukkit.entity.boat.OakChestBoat; + +public class CraftOakChestBoat extends CraftChestBoat implements OakChestBoat { + + public CraftOakChestBoat(CraftServer server, AbstractChestBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakBoat.java new file mode 100644 index 0000000000..e6d65858ed --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftBoat; +import org.bukkit.entity.boat.PaleOakBoat; + +public class CraftPaleOakBoat extends CraftBoat implements PaleOakBoat { + + public CraftPaleOakBoat(CraftServer server, AbstractBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakChestBoat.java new file mode 100644 index 0000000000..bcc91c8319 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftPaleOakChestBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractChestBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftChestBoat; +import org.bukkit.entity.boat.PaleOakChestBoat; + +public class CraftPaleOakChestBoat extends CraftChestBoat implements PaleOakChestBoat { + + public CraftPaleOakChestBoat(CraftServer server, AbstractChestBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceBoat.java new file mode 100644 index 0000000000..92eb7ea211 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftBoat; +import org.bukkit.entity.boat.SpruceBoat; + +public class CraftSpruceBoat extends CraftBoat implements SpruceBoat { + + public CraftSpruceBoat(CraftServer server, AbstractBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceChestBoat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceChestBoat.java new file mode 100644 index 0000000000..64cc4dc33a --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/boat/CraftSpruceChestBoat.java @@ -0,0 +1,13 @@ +package org.bukkit.craftbukkit.entity.boat; + +import net.minecraft.world.entity.vehicle.AbstractChestBoat; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.entity.CraftChestBoat; +import org.bukkit.entity.boat.SpruceChestBoat; + +public class CraftSpruceChestBoat extends CraftChestBoat implements SpruceChestBoat { + + public CraftSpruceChestBoat(CraftServer server, AbstractChestBoat entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 85c949273d..bc49380ba8 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -47,7 +47,6 @@ import net.minecraft.world.entity.monster.EntitySlime; import net.minecraft.world.entity.monster.EntityStrider; import net.minecraft.world.entity.monster.piglin.EntityPiglin; import net.minecraft.world.entity.npc.EntityVillager; -import net.minecraft.world.entity.npc.NPC; import net.minecraft.world.entity.player.EntityHuman; import net.minecraft.world.entity.projectile.EntityFireworks; import net.minecraft.world.entity.projectile.EntityPotion; @@ -668,10 +667,9 @@ public class CraftEventFactory { if (entity instanceof EntityLiving && !(entity instanceof EntityPlayer)) { boolean isAnimal = entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal || entity instanceof EntityGolem; boolean isMonster = entity instanceof EntityMonster || entity instanceof EntityGhast || entity instanceof EntitySlime; - boolean isNpc = entity instanceof NPC; if (spawnReason != SpawnReason.CUSTOM) { - if (isAnimal && !world.getWorld().getAllowAnimals() || isMonster && !world.getWorld().getAllowMonsters() || isNpc && !world.getCraftServer().getServer().areNpcsEnabled()) { + if (isAnimal && !world.getWorld().getAllowAnimals() || isMonster && !world.getWorld().getAllowMonsters()) { entity.discard(null); // Add Bukkit remove cause return false; } @@ -899,8 +897,8 @@ public class CraftEventFactory { public static EntityDeathEvent callEntityDeathEvent(EntityLiving victim, DamageSource damageSource, List drops) { CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity(); CraftDamageSource bukkitDamageSource = new CraftDamageSource(damageSource); - EntityDeathEvent event = new EntityDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(damageSource.getEntity())); CraftWorld world = (CraftWorld) entity.getWorld(); + EntityDeathEvent event = new EntityDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(world.getHandle(), damageSource.getEntity())); Bukkit.getServer().getPluginManager().callEvent(event); victim.expToDrop = event.getDroppedExp(); @@ -917,7 +915,7 @@ public class CraftEventFactory { public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, DamageSource damageSource, List drops, String deathMessage, boolean keepInventory) { CraftPlayer entity = victim.getBukkitEntity(); CraftDamageSource bukkitDamageSource = new CraftDamageSource(damageSource); - PlayerDeathEvent event = new PlayerDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(damageSource.getEntity()), 0, deathMessage); + PlayerDeathEvent event = new PlayerDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(victim.serverLevel(), damageSource.getEntity()), 0, deathMessage); event.setKeepInventory(keepInventory); event.setKeepLevel(victim.keepLevel); // SPIGOT-2222: pre-set keepLevel Bukkit.getServer().getPluginManager().callEvent(event); @@ -935,7 +933,7 @@ public class CraftEventFactory { victim.drop(CraftItemStack.asNMSCopy(stack), true, false, false); // SPIGOT-7800, SPIGOT-7801: Vanilla Behaviour for Player Inventory dropped items } else { victim.forceDrops = true; - victim.spawnAtLocation(CraftItemStack.asNMSCopy(stack)); // SPIGOT-7806: Vanilla Behaviour for items not related to Player Inventory dropped items + victim.spawnAtLocation(victim.serverLevel(), CraftItemStack.asNMSCopy(stack)); // SPIGOT-7806: Vanilla Behaviour for items not related to Player Inventory dropped items victim.forceDrops = false; } } @@ -1427,7 +1425,7 @@ public class CraftEventFactory { } public static BlockIgniteEvent callBlockIgniteEvent(World world, BlockPosition blockposition, Explosion explosion) { - org.bukkit.entity.Entity igniter = explosion.source == null ? null : explosion.source.getBukkitEntity(); + org.bukkit.entity.Entity igniter = explosion.getDirectSourceEntity() == null ? null : explosion.getDirectSourceEntity().getBukkitEntity(); BlockIgniteEvent event = new BlockIgniteEvent(CraftBlock.at(world, blockposition), IgniteCause.EXPLOSION, igniter); world.getCraftServer().getPluginManager().callEvent(event); @@ -1780,7 +1778,7 @@ public class CraftEventFactory { public static LootGenerateEvent callLootGenerateEvent(IInventory inventory, LootTable lootTable, LootTableInfo lootInfo, List loot, boolean plugin) { CraftWorld world = lootInfo.getLevel().getWorld(); - Entity entity = lootInfo.getParamOrNull(LootContextParameters.THIS_ENTITY); + Entity entity = lootInfo.getOptionalParameter(LootContextParameters.THIS_ENTITY); List bukkitLoot = loot.stream().map(CraftItemStack::asCraftMirror).collect(Collectors.toCollection(ArrayList::new)); LootGenerateEvent event = new LootGenerateEvent(world, (entity != null ? entity.getBukkitEntity() : null), inventory.getOwner(), lootTable.craftLootTable, CraftLootTable.convertContext(lootInfo), bukkitLoot, plugin); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java index 6070a54cf4..ec0ad0f654 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java @@ -10,6 +10,7 @@ import java.util.function.Consumer; import net.minecraft.core.BlockPosition; import net.minecraft.core.Holder; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.level.ChunkCoordIntPair; import net.minecraft.world.level.GeneratorAccessSeed; @@ -84,7 +85,7 @@ public class CraftLimitedRegion extends CraftRegionAccessor implements LimitedRe for (int z = -(buffer >> 4); z <= (buffer >> 4); z++) { ProtoChunk chunk = (ProtoChunk) access.getChunk(centerChunkX + x, centerChunkZ + z); for (NBTTagCompound compound : chunk.getEntities()) { - EntityTypes.loadEntityRecursive(compound, access.getMinecraftWorld(), (entity) -> { + EntityTypes.loadEntityRecursive(compound, access.getMinecraftWorld(), EntitySpawnReason.LOAD, (entity) -> { if (region.contains(entity.getX(), entity.getY(), entity.getZ())) { entity.generation = true; entities.add(entity); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java index c750ee5cdb..f2dc4dad38 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomChunkGenerator.java @@ -31,7 +31,6 @@ import net.minecraft.world.level.levelgen.HeightMap; import net.minecraft.world.level.levelgen.LegacyRandomSource; import net.minecraft.world.level.levelgen.RandomState; import net.minecraft.world.level.levelgen.SeededRandom; -import net.minecraft.world.level.levelgen.WorldGenStage; import net.minecraft.world.level.levelgen.blending.Blender; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager; import org.bukkit.block.Biome; @@ -224,14 +223,14 @@ public class CustomChunkGenerator extends InternalChunkGenerator { } @Override - public void applyCarvers(RegionLimitedWorldAccess regionlimitedworldaccess, long seed, RandomState randomstate, BiomeManager biomemanager, StructureManager structuremanager, IChunkAccess ichunkaccess, WorldGenStage.Features worldgenstage_features) { + public void applyCarvers(RegionLimitedWorldAccess regionlimitedworldaccess, long seed, RandomState randomstate, BiomeManager biomemanager, StructureManager structuremanager, IChunkAccess ichunkaccess) { SeededRandom random = getSeededRandom(); int x = ichunkaccess.getPos().x; int z = ichunkaccess.getPos().z; random.setSeed(MathHelper.getSeed(x, "should-caves".hashCode(), z) ^ regionlimitedworldaccess.getSeed()); if (generator.shouldGenerateCaves(this.world.getWorld(), new RandomSourceWrapper.RandomWrapper(random), x, z)) { - delegate.applyCarvers(regionlimitedworldaccess, seed, randomstate, biomemanager, structuremanager, ichunkaccess, worldgenstage_features); + delegate.applyCarvers(regionlimitedworldaccess, seed, randomstate, biomemanager, structuremanager, ichunkaccess); } // Minecraft removed the LIQUID_CARVERS stage from world generation, without removing the LIQUID Carving enum. diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftBlastingRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftBlastingRecipe.java index 0c028b66d1..ce66f373c1 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftBlastingRecipe.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftBlastingRecipe.java @@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory; import net.minecraft.server.MinecraftServer; import net.minecraft.world.item.crafting.RecipeHolder; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.BlastingRecipe; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.RecipeChoice; @@ -27,6 +26,6 @@ public class CraftBlastingRecipe extends BlastingRecipe implements CraftRecipe { public void addToCraftingManager() { ItemStack result = this.getResult(); - MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeBlasting(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()))); + MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeBlasting(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()))); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftCampfireRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftCampfireRecipe.java index 07d48eee33..ebb9f58023 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftCampfireRecipe.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftCampfireRecipe.java @@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory; import net.minecraft.server.MinecraftServer; import net.minecraft.world.item.crafting.RecipeHolder; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.CampfireRecipe; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.RecipeChoice; @@ -27,6 +26,6 @@ public class CraftCampfireRecipe extends CampfireRecipe implements CraftRecipe { public void addToCraftingManager() { ItemStack result = this.getResult(); - MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeCampfire(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()))); + MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeCampfire(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()))); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftComplexRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftComplexRecipe.java index 1427f478fb..453adee9a1 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftComplexRecipe.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftComplexRecipe.java @@ -4,7 +4,6 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.world.item.crafting.IRecipeComplex; import net.minecraft.world.item.crafting.RecipeHolder; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.ComplexRecipe; import org.bukkit.inventory.CraftingRecipe; import org.bukkit.inventory.ItemStack; @@ -20,6 +19,6 @@ public class CraftComplexRecipe extends CraftingRecipe implements CraftRecipe, C @Override public void addToCraftingManager() { - MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), recipe)); + MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), recipe)); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftFurnaceRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftFurnaceRecipe.java index 1d8382659b..4c620c9ab0 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftFurnaceRecipe.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftFurnaceRecipe.java @@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory; import net.minecraft.server.MinecraftServer; import net.minecraft.world.item.crafting.RecipeHolder; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.FurnaceRecipe; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.RecipeChoice; @@ -27,6 +26,6 @@ public class CraftFurnaceRecipe extends FurnaceRecipe implements CraftRecipe { public void addToCraftingManager() { ItemStack result = this.getResult(); - MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.FurnaceRecipe(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()))); + MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.FurnaceRecipe(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()))); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java index 78c5d4d6d2..5de47c7d12 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemFactory.java @@ -25,9 +25,11 @@ import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftEntityType; +import org.bukkit.craftbukkit.inventory.components.CraftEquippableComponent; import org.bukkit.craftbukkit.inventory.components.CraftFoodComponent; import org.bukkit.craftbukkit.inventory.components.CraftJukeboxComponent; import org.bukkit.craftbukkit.inventory.components.CraftToolComponent; +import org.bukkit.craftbukkit.inventory.components.CraftUseCooldownComponent; import org.bukkit.craftbukkit.util.CraftLegacy; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -43,11 +45,12 @@ public final class CraftItemFactory implements ItemFactory { static { instance = new CraftItemFactory(); ConfigurationSerialization.registerClass(SerializableMeta.class); + ConfigurationSerialization.registerClass(CraftEquippableComponent.class); ConfigurationSerialization.registerClass(CraftFoodComponent.class); - ConfigurationSerialization.registerClass(CraftFoodComponent.CraftFoodEffect.class); ConfigurationSerialization.registerClass(CraftToolComponent.class); ConfigurationSerialization.registerClass(CraftToolComponent.CraftToolRule.class); ConfigurationSerialization.registerClass(CraftJukeboxComponent.class); + ConfigurationSerialization.registerClass(CraftUseCooldownComponent.class); } private CraftItemFactory() { @@ -204,7 +207,7 @@ public final class CraftItemFactory implements ItemFactory { itemStack = CraftItemStack.asCraftCopy(itemStack); CraftItemStack craft = (CraftItemStack) itemStack; IRegistryCustom registry = CraftRegistry.getMinecraftRegistry(); - Optional> optional = (allowTreasures) ? Optional.empty() : registry.registryOrThrow(Registries.ENCHANTMENT).getTag(EnchantmentTags.IN_ENCHANTING_TABLE); + Optional> optional = (allowTreasures) ? Optional.empty() : registry.lookupOrThrow(Registries.ENCHANTMENT).get(EnchantmentTags.IN_ENCHANTING_TABLE); return CraftItemStack.asCraftMirror(EnchantmentManager.enchantItem(source, craft.handle, level, registry, optional)); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java index b7243eba80..ca8009cb1d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemMetas.java @@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.inventory; import java.util.function.BiFunction; import java.util.function.Function; +import net.minecraft.world.item.BundleItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemBanner; import net.minecraft.world.item.ItemBlock; @@ -244,7 +245,8 @@ public final class CraftItemMetas { || itemType == ItemType.CALIBRATED_SCULK_SENSOR || itemType == ItemType.CHISELED_BOOKSHELF || itemType == ItemType.DECORATED_POT || itemType == ItemType.SUSPICIOUS_SAND || itemType == ItemType.SUSPICIOUS_GRAVEL || itemType == ItemType.CRAFTER - || itemType == ItemType.TRIAL_SPAWNER || itemType == ItemType.VAULT) { + || itemType == ItemType.TRIAL_SPAWNER || itemType == ItemType.VAULT + || itemType == ItemType.CREAKING_HEART) { return asType(BLOCK_STATE_META_DATA); } if (itemType == ItemType.SHIELD) { @@ -270,7 +272,7 @@ public final class CraftItemMetas { if (itemType == ItemType.COMPASS) { return asType(COMPASS_META_DATA); } - if (itemType == ItemType.BUNDLE) { + if (itemHandle instanceof BundleItem) { return asType(BUNDLE_META_DATA); } if (itemType == ItemType.GOAT_HORN) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index f382379af2..83653c1f38 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -2,10 +2,18 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; +import java.util.Collections; import java.util.Map; +import java.util.Optional; +import net.minecraft.advancements.critereon.CriterionConditionItem; +import net.minecraft.advancements.critereon.CriterionConditionValue; import net.minecraft.core.Holder; +import net.minecraft.core.HolderSet; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponentPredicate; import net.minecraft.core.component.DataComponents; +import net.minecraft.core.component.PatchedDataComponentMap; import net.minecraft.world.item.Item; import net.minecraft.world.item.enchantment.EnchantmentManager; import net.minecraft.world.item.enchantment.ItemEnchantments; @@ -85,6 +93,13 @@ public final class CraftItemStack extends ItemStack { return new CraftItemStack(CraftItemType.minecraftToBukkit(item), amount, (short) 0, null); } + public static CriterionConditionItem asCriterionConditionItem(ItemStack original) { + net.minecraft.world.item.ItemStack nms = CraftItemStack.asNMSCopy(original); + DataComponentPredicate predicate = DataComponentPredicate.allOf(PatchedDataComponentMap.fromPatch(DataComponentMap.EMPTY, nms.getComponentsPatch())); + + return new CriterionConditionItem(Optional.of(HolderSet.direct(nms.getItemHolder())), CriterionConditionValue.IntegerRange.ANY, predicate, Collections.emptyMap()); + } + net.minecraft.world.item.ItemStack handle; private boolean isForInventoryDrop; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java index 139c1f4148..235909405a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java @@ -8,11 +8,11 @@ import java.util.function.Consumer; import java.util.function.Supplier; import net.minecraft.core.component.DataComponents; import net.minecraft.core.registries.Registries; +import net.minecraft.server.MinecraftServer; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemBlock; import net.minecraft.world.item.component.ItemAttributeModifiers; import net.minecraft.world.level.block.BlockComposter; -import net.minecraft.world.level.block.entity.TileEntityFurnace; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.Registry; @@ -172,7 +172,7 @@ public class CraftItemType implements ItemType.Typed, Han @Override public boolean isFuel() { - return TileEntityFurnace.isFuel(new net.minecraft.world.item.ItemStack(item)); + return MinecraftServer.getServer().fuelValues().isFuel(new net.minecraft.world.item.ItemStack(item)); } @Override @@ -188,8 +188,8 @@ public class CraftItemType implements ItemType.Typed, Han @Override public ItemType getCraftingRemainingItem() { - Item expectedItem = item.getCraftingRemainingItem(); - return expectedItem == null ? null : minecraftToBukkitNew(expectedItem); + net.minecraft.world.item.ItemStack expectedItem = item.getCraftingRemainder(); + return expectedItem.isEmpty() ? null : minecraftToBukkitNew(expectedItem.getItem()); } // @Override @@ -202,9 +202,6 @@ public class CraftItemType implements ItemType.Typed, Han ImmutableMultimap.Builder defaultAttributes = ImmutableMultimap.builder(); ItemAttributeModifiers nmsDefaultAttributes = item.components().getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY); - if (nmsDefaultAttributes.modifiers().isEmpty()) { - nmsDefaultAttributes = item.getDefaultAttributeModifiers(); - } nmsDefaultAttributes.forEach(CraftEquipmentSlot.getNMS(slot), (key, value) -> { Attribute attribute = CraftAttribute.minecraftToBukkit(key.value()); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java index 55b4fb78d9..a1c65d946d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmor.java @@ -20,7 +20,7 @@ import org.bukkit.inventory.meta.trim.TrimPattern; @DelegateDeserialization(SerializableMeta.class) public class CraftMetaArmor extends CraftMetaItem implements ArmorMeta { - static final ItemMetaKeyType TRIM = new ItemMetaKeyType<>(DataComponents.TRIM, "trim"); + static final ItemMetaKeyType TRIM = new ItemMetaKeyType<>(DataComponents.TRIM, "trim"); static final ItemMetaKey TRIM_MATERIAL = new ItemMetaKey("material"); static final ItemMetaKey TRIM_PATTERN = new ItemMetaKey("pattern"); @@ -43,7 +43,7 @@ public class CraftMetaArmor extends CraftMetaItem implements ArmorMeta { this.trim = new ArmorTrim(trimMaterial, trimPattern); - if (!trimCompound.showInTooltip) { + if (!trimCompound.showInTooltip()) { addItemFlags(ItemFlag.HIDE_ARMOR_TRIM); } }); @@ -78,7 +78,7 @@ public class CraftMetaArmor extends CraftMetaItem implements ArmorMeta { super.applyToItem(itemTag); if (hasTrim()) { - itemTag.put(TRIM, new net.minecraft.world.item.armortrim.ArmorTrim(CraftTrimMaterial.bukkitToMinecraftHolder(trim.getMaterial()), CraftTrimPattern.bukkitToMinecraftHolder(trim.getPattern()), !hasItemFlag(ItemFlag.HIDE_ARMOR_TRIM))); + itemTag.put(TRIM, new net.minecraft.world.item.equipment.trim.ArmorTrim(CraftTrimMaterial.bukkitToMinecraftHolder(trim.getMaterial()), CraftTrimPattern.bukkitToMinecraftHolder(trim.getPattern()), !hasItemFlag(ItemFlag.HIDE_ARMOR_TRIM))); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java index 22a5bc1a64..a2f2201a34 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java @@ -57,6 +57,7 @@ import net.minecraft.nbt.SnbtPrinterTagVisitor; import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.resources.MinecraftKey; import net.minecraft.server.MinecraftServer; +import net.minecraft.tags.TagKey; import net.minecraft.util.Unit; import net.minecraft.world.entity.EnumItemSlot; import net.minecraft.world.entity.EquipmentSlotGroup; @@ -69,13 +70,21 @@ import net.minecraft.world.item.JukeboxSongs; import net.minecraft.world.item.component.BlockItemStateProperties; import net.minecraft.world.item.component.CustomData; import net.minecraft.world.item.component.CustomModelData; +import net.minecraft.world.item.component.DamageResistant; import net.minecraft.world.item.component.ItemAttributeModifiers; import net.minecraft.world.item.component.ItemLore; import net.minecraft.world.item.component.Tool; import net.minecraft.world.item.component.Unbreakable; +import net.minecraft.world.item.component.UseCooldown; +import net.minecraft.world.item.component.UseRemainder; +import net.minecraft.world.item.enchantment.Enchantable; import net.minecraft.world.item.enchantment.ItemEnchantments; +import net.minecraft.world.item.equipment.Equippable; import net.minecraft.world.level.block.state.IBlockData; +import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.Tag; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; import org.bukkit.block.data.BlockData; @@ -89,28 +98,37 @@ import org.bukkit.craftbukkit.block.CraftBlockType; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.enchantments.CraftEnchantment; import org.bukkit.craftbukkit.inventory.CraftMetaItem.ItemMetaKey.Specific; +import org.bukkit.craftbukkit.inventory.components.CraftEquippableComponent; import org.bukkit.craftbukkit.inventory.components.CraftFoodComponent; import org.bukkit.craftbukkit.inventory.components.CraftJukeboxComponent; import org.bukkit.craftbukkit.inventory.components.CraftToolComponent; +import org.bukkit.craftbukkit.inventory.components.CraftUseCooldownComponent; import org.bukkit.craftbukkit.inventory.tags.DeprecatedCustomTagContainer; import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer; import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry; +import org.bukkit.craftbukkit.tag.CraftDamageTag; import org.bukkit.craftbukkit.util.CraftChatMessage; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftNBTTagConfigSerializer; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.damage.DamageType; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemRarity; +import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BlockDataMeta; import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.Repairable; +import org.bukkit.inventory.meta.components.EquippableComponent; import org.bukkit.inventory.meta.components.FoodComponent; import org.bukkit.inventory.meta.components.JukeboxPlayableComponent; import org.bukkit.inventory.meta.components.ToolComponent; +import org.bukkit.inventory.meta.components.UseCooldownComponent; import org.bukkit.inventory.meta.tags.CustomItemTagContainer; import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.tag.DamageTypeTags; /** * Children must include the following: @@ -207,6 +225,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { static final ItemMetaKeyType ITEM_NAME = new ItemMetaKeyType(DataComponents.ITEM_NAME, "item-name"); static final ItemMetaKeyType LORE = new ItemMetaKeyType<>(DataComponents.LORE, "lore"); static final ItemMetaKeyType CUSTOM_MODEL_DATA = new ItemMetaKeyType<>(DataComponents.CUSTOM_MODEL_DATA, "custom-model-data"); + static final ItemMetaKeyType ENCHANTABLE = new ItemMetaKeyType<>(DataComponents.ENCHANTABLE, "enchantable"); static final ItemMetaKeyType ENCHANTMENTS = new ItemMetaKeyType<>(DataComponents.ENCHANTMENTS, "enchants"); static final ItemMetaKeyType REPAIR = new ItemMetaKeyType<>(DataComponents.REPAIR_COST, "repair-cost"); static final ItemMetaKeyType ATTRIBUTES = new ItemMetaKeyType<>(DataComponents.ATTRIBUTE_MODIFIERS, "attribute-modifiers"); @@ -219,20 +238,32 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { @Specific(Specific.To.NBT) static final ItemMetaKeyType HIDE_TOOLTIP = new ItemMetaKeyType<>(DataComponents.HIDE_TOOLTIP, "hide-tool-tip"); @Specific(Specific.To.NBT) + static final ItemMetaKeyType TOOLTIP_STYLE = new ItemMetaKeyType<>(DataComponents.TOOLTIP_STYLE, "tool-tip-style"); + @Specific(Specific.To.NBT) + static final ItemMetaKeyType ITEM_MODEL = new ItemMetaKeyType<>(DataComponents.ITEM_MODEL, "item-model"); + @Specific(Specific.To.NBT) static final ItemMetaKeyType UNBREAKABLE = new ItemMetaKeyType<>(DataComponents.UNBREAKABLE, "Unbreakable"); @Specific(Specific.To.NBT) static final ItemMetaKeyType ENCHANTMENT_GLINT_OVERRIDE = new ItemMetaKeyType<>(DataComponents.ENCHANTMENT_GLINT_OVERRIDE, "enchantment-glint-override"); @Specific(Specific.To.NBT) - static final ItemMetaKeyType FIRE_RESISTANT = new ItemMetaKeyType<>(DataComponents.FIRE_RESISTANT, "fire-resistant"); + static final ItemMetaKeyType GLIDER = new ItemMetaKeyType<>(DataComponents.GLIDER, "glider"); + @Specific(Specific.To.NBT) + static final ItemMetaKeyType DAMAGE_RESISTANT = new ItemMetaKeyType<>(DataComponents.DAMAGE_RESISTANT, "damage-resistant"); @Specific(Specific.To.NBT) static final ItemMetaKeyType MAX_STACK_SIZE = new ItemMetaKeyType<>(DataComponents.MAX_STACK_SIZE, "max-stack-size"); @Specific(Specific.To.NBT) static final ItemMetaKeyType RARITY = new ItemMetaKeyType<>(DataComponents.RARITY, "rarity"); @Specific(Specific.To.NBT) + static final ItemMetaKeyType USE_REMAINDER = new ItemMetaKeyType<>(DataComponents.USE_REMAINDER, "use-remainder"); + @Specific(Specific.To.NBT) + static final ItemMetaKeyType USE_COOLDOWN = new ItemMetaKeyType<>(DataComponents.USE_COOLDOWN, "use-cooldown"); + @Specific(Specific.To.NBT) static final ItemMetaKeyType FOOD = new ItemMetaKeyType<>(DataComponents.FOOD, "food"); @Specific(Specific.To.NBT) static final ItemMetaKeyType TOOL = new ItemMetaKeyType<>(DataComponents.TOOL, "tool"); @Specific(Specific.To.NBT) + static final ItemMetaKeyType EQUIPPABLE = new ItemMetaKeyType<>(DataComponents.EQUIPPABLE, "equippable"); + @Specific(Specific.To.NBT) static final ItemMetaKeyType JUKEBOX_PLAYABLE = new ItemMetaKeyType<>(DataComponents.JUKEBOX_PLAYABLE, "jukebox-playable"); @Specific(Specific.To.NBT) static final ItemMetaKeyType DAMAGE = new ItemMetaKeyType<>(DataComponents.DAMAGE, "Damage"); @@ -251,19 +282,26 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { private IChatBaseComponent itemName; private List lore; // null and empty are two different states internally private Integer customModelData; + private Integer enchantableValue; private Map blockData; private Map enchantments; private Multimap attributeModifiers; private int repairCost; private int hideFlag; private boolean hideTooltip; + private NamespacedKey tooltipStyle; + private NamespacedKey itemModel; private boolean unbreakable; private Boolean enchantmentGlintOverride; - private boolean fireResistant; + private boolean glider; + private TagKey damageResistant; private Integer maxStackSize; private ItemRarity rarity; + private ItemStack useRemainder; + private CraftUseCooldownComponent useCooldown; private CraftFoodComponent food; private CraftToolComponent tool; + private CraftEquippableComponent equippable; private CraftJukeboxComponent jukebox; private int damage; private Integer maxDamage; @@ -291,6 +329,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { } this.customModelData = meta.customModelData; + this.enchantableValue = meta.enchantableValue; this.blockData = meta.blockData; if (meta.enchantments != null) { @@ -304,17 +343,29 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { this.repairCost = meta.repairCost; this.hideFlag = meta.hideFlag; this.hideTooltip = meta.hideTooltip; + this.tooltipStyle = meta.tooltipStyle; + this.itemModel = meta.itemModel; this.unbreakable = meta.unbreakable; this.enchantmentGlintOverride = meta.enchantmentGlintOverride; - this.fireResistant = meta.fireResistant; + this.glider = meta.glider; + this.damageResistant = meta.damageResistant; this.maxStackSize = meta.maxStackSize; this.rarity = meta.rarity; + if (meta.hasUseRemainder()) { + this.useRemainder = meta.useRemainder.clone(); + } + if (meta.hasUseCooldown()) { + this.useCooldown = new CraftUseCooldownComponent(meta.useCooldown); + } if (meta.hasFood()) { this.food = new CraftFoodComponent(meta.food); } if (meta.hasTool()) { this.tool = new CraftToolComponent(meta.tool); } + if (meta.hasEquippable()) { + this.equippable = new CraftEquippableComponent(meta.equippable); + } if (meta.hasJukeboxPlayable()) { this.jukebox = new CraftJukeboxComponent(meta.jukebox); } @@ -349,6 +400,9 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { getOrEmpty(tag, CUSTOM_MODEL_DATA).ifPresent((i) -> { customModelData = i.value(); }); + getOrEmpty(tag, ENCHANTABLE).ifPresent((i) -> { + enchantableValue = i.value(); + }); getOrEmpty(tag, BLOCK_DATA).ifPresent((t) -> { blockData = t.properties(); }); @@ -376,6 +430,12 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { getOrEmpty(tag, HIDE_TOOLTIP).ifPresent((u) -> { hideTooltip = true; }); + getOrEmpty(tag, TOOLTIP_STYLE).ifPresent((key) -> { + tooltipStyle = CraftNamespacedKey.fromMinecraft(key); + }); + getOrEmpty(tag, ITEM_MODEL).ifPresent((key) -> { + itemModel = CraftNamespacedKey.fromMinecraft(key); + }); getOrEmpty(tag, UNBREAKABLE).ifPresent((u) -> { unbreakable = true; if (!u.showInTooltip()) { @@ -385,8 +445,11 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { getOrEmpty(tag, ENCHANTMENT_GLINT_OVERRIDE).ifPresent((override) -> { enchantmentGlintOverride = override; }); - getOrEmpty(tag, FIRE_RESISTANT).ifPresent((u) -> { - fireResistant = true; + getOrEmpty(tag, GLIDER).ifPresent((u) -> { + glider = true; + }); + getOrEmpty(tag, DAMAGE_RESISTANT).ifPresent((tags) -> { + damageResistant = tags.types(); }); getOrEmpty(tag, MAX_STACK_SIZE).ifPresent((i) -> { maxStackSize = i; @@ -394,12 +457,21 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { getOrEmpty(tag, RARITY).ifPresent((enumItemRarity) -> { rarity = ItemRarity.valueOf(enumItemRarity.name()); }); + getOrEmpty(tag, USE_REMAINDER).ifPresent((remainder) -> { + useRemainder = CraftItemStack.asCraftMirror(remainder.convertInto()); + }); + getOrEmpty(tag, USE_COOLDOWN).ifPresent((cooldown) -> { + useCooldown = new CraftUseCooldownComponent(cooldown); + }); getOrEmpty(tag, FOOD).ifPresent((foodInfo) -> { food = new CraftFoodComponent(foodInfo); }); getOrEmpty(tag, TOOL).ifPresent((toolInfo) -> { tool = new CraftToolComponent(toolInfo); }); + getOrEmpty(tag, EQUIPPABLE).ifPresent((equippableInfo) -> { + equippable = new CraftEquippableComponent(equippableInfo); + }); getOrEmpty(tag, JUKEBOX_PLAYABLE).ifPresent((jukeboxPlayable) -> { jukebox = new CraftJukeboxComponent(jukeboxPlayable); }); @@ -514,6 +586,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { if (customModelData != null) { setCustomModelData(customModelData); } + Integer enchantmentValue = SerializableMeta.getObject(Integer.class, map, ENCHANTABLE.BUKKIT, true); + if (enchantmentValue != null) { + setEnchantable(enchantmentValue); + } Object blockData = SerializableMeta.getObject(Object.class, map, BLOCK_DATA.BUKKIT, true); if (blockData != null) { @@ -560,6 +636,16 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { setHideTooltip(hideTooltip); } + String tooltipStyle = SerializableMeta.getString(map, TOOLTIP_STYLE.BUKKIT, true); + if (tooltipStyle != null) { + setTooltipStyle(NamespacedKey.fromString(tooltipStyle)); + } + + String itemModel = SerializableMeta.getString(map, ITEM_MODEL.BUKKIT, true); + if (itemModel != null) { + setItemModel(NamespacedKey.fromString(itemModel)); + } + Boolean unbreakable = SerializableMeta.getObject(Boolean.class, map, UNBREAKABLE.BUKKIT, true); if (unbreakable != null) { setUnbreakable(unbreakable); @@ -570,9 +656,17 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { setEnchantmentGlintOverride(enchantmentGlintOverride); } - Boolean fireResistant = SerializableMeta.getObject(Boolean.class, map, FIRE_RESISTANT.BUKKIT, true); - if (fireResistant != null) { - setFireResistant(fireResistant); + Boolean glider = SerializableMeta.getObject(Boolean.class, map, GLIDER.BUKKIT, true); + if (glider != null) { + setGlider(glider); + } + + String damageResistant = SerializableMeta.getString(map, DAMAGE_RESISTANT.BUKKIT, true); + if (damageResistant != null) { + Tag tag = Bukkit.getTag(DamageTypeTags.REGISTRY_DAMAGE_TYPES, NamespacedKey.fromString(damageResistant), DamageType.class); + if (tag != null) { + setDamageResistant(tag); + } } Integer maxStackSize = SerializableMeta.getObject(Integer.class, map, MAX_STACK_SIZE.BUKKIT, true); @@ -585,6 +679,16 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { setRarity(ItemRarity.valueOf(rarity)); } + ItemStack remainder = SerializableMeta.getObject(ItemStack.class, map, USE_REMAINDER.BUKKIT, true); + if (remainder != null) { + setUseRemainder(remainder); + } + + CraftUseCooldownComponent cooldown = SerializableMeta.getObject(CraftUseCooldownComponent.class, map, USE_COOLDOWN.BUKKIT, true); + if (cooldown != null) { + setUseCooldown(cooldown); + } + CraftFoodComponent food = SerializableMeta.getObject(CraftFoodComponent.class, map, FOOD.BUKKIT, true); if (food != null) { setFood(food); @@ -595,6 +699,11 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { setTool(tool); } + CraftEquippableComponent equippable = SerializableMeta.getObject(CraftEquippableComponent.class, map, EQUIPPABLE.BUKKIT, true); + if (equippable != null) { + setEquippable(equippable); + } + CraftJukeboxComponent jukeboxPlayable = SerializableMeta.getObject(CraftJukeboxComponent.class, map, JUKEBOX_PLAYABLE.BUKKIT, true); if (jukeboxPlayable != null) { setJukeboxPlayable(jukeboxPlayable); @@ -646,12 +755,12 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { Iterable removed = SerializableMeta.getObject(Iterable.class, map, "removed", true); if (removed != null) { IRegistryCustom registryAccess = CraftRegistry.getMinecraftRegistry(); - IRegistry> componentTypeRegistry = registryAccess.registryOrThrow(Registries.DATA_COMPONENT_TYPE); + IRegistry> componentTypeRegistry = registryAccess.lookupOrThrow(Registries.DATA_COMPONENT_TYPE); for (Object removedObject : removed) { String removedString = (String) removedObject; - DataComponentType component = componentTypeRegistry.get(MinecraftKey.parse(removedString)); + DataComponentType component = componentTypeRegistry.getValue(MinecraftKey.parse(removedString)); if (component != null) { this.removedTags.add(component); } @@ -809,6 +918,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { itemTag.put(CUSTOM_MODEL_DATA, new CustomModelData(customModelData)); } + if (hasEnchantable()) { + itemTag.put(ENCHANTABLE, new Enchantable(enchantableValue)); + } + if (hasBlockData()) { itemTag.put(BLOCK_DATA, new BlockItemStateProperties(blockData)); } @@ -830,6 +943,14 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { itemTag.put(HIDE_TOOLTIP, Unit.INSTANCE); } + if (hasTooltipStyle()) { + itemTag.put(TOOLTIP_STYLE, CraftNamespacedKey.toMinecraft(getTooltipStyle())); + } + + if (hasItemModel()) { + itemTag.put(ITEM_MODEL, CraftNamespacedKey.toMinecraft(getItemModel())); + } + if (isUnbreakable()) { itemTag.put(UNBREAKABLE, new Unbreakable(!hasItemFlag(ItemFlag.HIDE_UNBREAKABLE))); } @@ -838,8 +959,12 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { itemTag.put(ENCHANTMENT_GLINT_OVERRIDE, getEnchantmentGlintOverride()); } - if (isFireResistant()) { - itemTag.put(FIRE_RESISTANT, Unit.INSTANCE); + if (isGlider()) { + itemTag.put(GLIDER, Unit.INSTANCE); + } + + if (hasDamageResistant()) { + itemTag.put(DAMAGE_RESISTANT, new DamageResistant(damageResistant)); } if (hasMaxStackSize()) { @@ -850,6 +975,14 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { itemTag.put(RARITY, EnumItemRarity.valueOf(rarity.name())); } + if (hasUseRemainder()) { + itemTag.put(USE_REMAINDER, new UseRemainder(CraftItemStack.asNMSCopy(useRemainder))); + } + + if (hasUseCooldown()) { + itemTag.put(USE_COOLDOWN, useCooldown.getHandle()); + } + if (hasFood()) { itemTag.put(FOOD, food.getHandle()); } @@ -858,6 +991,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { itemTag.put(TOOL, tool.getHandle()); } + if (hasEquippable()) { + itemTag.put(EQUIPPABLE, equippable.getHandle()); + } + if (hasJukeboxPlayable()) { itemTag.put(JUKEBOX_PLAYABLE, jukebox.getHandle()); } @@ -960,7 +1097,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { @Overridden boolean isEmpty() { - return !(hasDisplayName() || hasItemName() || hasLocalizedName() || hasEnchants() || (lore != null) || hasCustomModelData() || hasBlockData() || hasRepairCost() || !unhandledTags.build().isEmpty() || !removedTags.isEmpty() || !persistentDataContainer.isEmpty() || hideFlag != 0 || isHideTooltip() || isUnbreakable() || hasEnchantmentGlintOverride() || isFireResistant() || hasMaxStackSize() || hasRarity() || hasFood() || hasTool() || hasJukeboxPlayable() || hasDamage() || hasMaxDamage() || hasAttributeModifiers() || customTag != null); + return !(hasDisplayName() || hasItemName() || hasLocalizedName() || hasEnchants() || (lore != null) || hasCustomModelData() || hasEnchantable() || hasBlockData() || hasRepairCost() || !unhandledTags.build().isEmpty() || !removedTags.isEmpty() || !persistentDataContainer.isEmpty() || hideFlag != 0 || isHideTooltip() || hasTooltipStyle() || hasItemModel() || isUnbreakable() || hasEnchantmentGlintOverride() || isGlider() || hasDamageResistant() || hasMaxStackSize() || hasRarity() || hasUseRemainder() || hasUseCooldown() || hasFood() || hasTool() || hasJukeboxPlayable() || hasEquippable() || hasDamage() || hasMaxDamage() || hasAttributeModifiers() || customTag != null); } @Override @@ -1152,6 +1289,22 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { this.customModelData = data; } + @Override + public boolean hasEnchantable() { + return enchantableValue != null; + } + + @Override + public int getEnchantable() { + Preconditions.checkState(hasEnchantable(), "We don't have Enchantable! Check hasEnchantable first!"); + return enchantableValue; + } + + @Override + public void setEnchantable(Integer data) { + this.enchantableValue = data; + } + @Override public boolean hasBlockData() { return this.blockData != null; @@ -1188,6 +1341,36 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { this.hideTooltip = hideTooltip; } + @Override + public boolean hasTooltipStyle() { + return this.tooltipStyle != null; + } + + @Override + public NamespacedKey getTooltipStyle() { + return this.tooltipStyle; + } + + @Override + public void setTooltipStyle(NamespacedKey tooltipStyle) { + this.tooltipStyle = tooltipStyle; + } + + @Override + public boolean hasItemModel() { + return this.itemModel != null; + } + + @Override + public NamespacedKey getItemModel() { + return this.itemModel; + } + + @Override + public void setItemModel(NamespacedKey itemModel) { + this.itemModel = itemModel; + } + @Override public boolean isUnbreakable() { return unbreakable; @@ -1214,14 +1397,39 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { this.enchantmentGlintOverride = override; } + @Override + public boolean isGlider() { + return this.glider; + } + + @Override + public void setGlider(boolean glider) { + this.glider = glider; + } + @Override public boolean isFireResistant() { - return this.fireResistant; + return hasDamageResistant() && DamageTypeTags.IS_FIRE.equals(getDamageResistant()); } @Override public void setFireResistant(boolean fireResistant) { - this.fireResistant = fireResistant; + setDamageResistant(DamageTypeTags.IS_FIRE); + } + + @Override + public boolean hasDamageResistant() { + return this.damageResistant != null; + } + + @Override + public Tag getDamageResistant() { + return (hasDamageResistant()) ? Bukkit.getTag(DamageTypeTags.REGISTRY_DAMAGE_TYPES, CraftNamespacedKey.fromMinecraft(this.damageResistant.location()), DamageType.class) : null; + } + + @Override + public void setDamageResistant(Tag tag) { + this.damageResistant = (tag != null) ? ((CraftDamageTag) tag).getHandle().key() : null; } @Override @@ -1258,6 +1466,36 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { this.rarity = rarity; } + @Override + public boolean hasUseRemainder() { + return this.useRemainder != null; + } + + @Override + public ItemStack getUseRemainder() { + return this.useRemainder; + } + + @Override + public void setUseRemainder(ItemStack useRemainder) { + this.useRemainder = useRemainder; + } + + @Override + public boolean hasUseCooldown() { + return this.useCooldown != null; + } + + @Override + public UseCooldownComponent getUseCooldown() { + return (this.hasUseCooldown()) ? new CraftUseCooldownComponent(this.useCooldown) : new CraftUseCooldownComponent(new UseCooldown(0)); + } + + @Override + public void setUseCooldown(UseCooldownComponent cooldown) { + this.useCooldown = (cooldown == null) ? null : new CraftUseCooldownComponent((CraftUseCooldownComponent) cooldown); + } + @Override public boolean hasFood() { return this.food != null; @@ -1265,7 +1503,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { @Override public FoodComponent getFood() { - return (this.hasFood()) ? new CraftFoodComponent(this.food) : new CraftFoodComponent(new FoodInfo(0, 0, false, 0, Optional.empty(), Collections.emptyList())); + return (this.hasFood()) ? new CraftFoodComponent(this.food) : new CraftFoodComponent(new FoodInfo(0, 0, false)); } @Override @@ -1288,6 +1526,21 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { this.tool = (tool == null) ? null : new CraftToolComponent((CraftToolComponent) tool); } + @Override + public boolean hasEquippable() { + return this.equippable != null; + } + + @Override + public EquippableComponent getEquippable() { + return (this.hasEquippable()) ? new CraftEquippableComponent(this.equippable) : new CraftEquippableComponent(Equippable.builder(EnumItemSlot.HEAD).build()); + } + + @Override + public void setEquippable(EquippableComponent equippable) { + this.equippable = (equippable == null) ? null : new CraftEquippableComponent((CraftEquippableComponent) this.equippable); + } + @Override public boolean hasJukeboxPlayable() { return this.jukebox != null; @@ -1436,7 +1689,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { IRegistryCustom registryAccess = CraftRegistry.getMinecraftRegistry(); DynamicOps ops = registryAccess.createSerializationContext(DynamicOpsNBT.INSTANCE); - IRegistry> componentTypeRegistry = registryAccess.registryOrThrow(Registries.DATA_COMPONENT_TYPE); + IRegistry> componentTypeRegistry = registryAccess.lookupOrThrow(Registries.DATA_COMPONENT_TYPE); StringJoiner componentString = new StringJoiner(",", "[", "]"); for (Entry, Optional> entry : patch.entrySet()) { @@ -1540,6 +1793,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { && (this.hasEnchants() ? that.hasEnchants() && this.enchantments.equals(that.enchantments) : !that.hasEnchants()) && (Objects.equals(this.lore, that.lore)) && (this.hasCustomModelData() ? that.hasCustomModelData() && this.customModelData.equals(that.customModelData) : !that.hasCustomModelData()) + && (this.hasEnchantable() ? that.hasEnchantable() && this.enchantableValue.equals(that.enchantableValue) : !that.hasEnchantable()) && (this.hasBlockData() ? that.hasBlockData() && this.blockData.equals(that.blockData) : !that.hasBlockData()) && (this.hasRepairCost() ? that.hasRepairCost() && this.repairCost == that.repairCost : !that.hasRepairCost()) && (this.hasAttributeModifiers() ? that.hasAttributeModifiers() && compareModifiers(this.attributeModifiers, that.attributeModifiers) : !that.hasAttributeModifiers()) @@ -1549,13 +1803,19 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { && (this.persistentDataContainer.equals(that.persistentDataContainer)) && (this.hideFlag == that.hideFlag) && (this.isHideTooltip() == that.isHideTooltip()) + && (this.hasTooltipStyle() ? that.hasTooltipStyle() && this.tooltipStyle.equals(that.tooltipStyle) : !that.hasTooltipStyle()) + && (this.hasItemModel() ? that.hasItemModel() && this.itemModel.equals(that.itemModel) : !that.hasItemModel()) && (this.isUnbreakable() == that.isUnbreakable()) && (this.hasEnchantmentGlintOverride() ? that.hasEnchantmentGlintOverride() && this.enchantmentGlintOverride.equals(that.enchantmentGlintOverride) : !that.hasEnchantmentGlintOverride()) - && (this.fireResistant == that.fireResistant) + && (this.glider == that.glider) + && (this.hasDamageResistant() ? that.hasDamageResistant() && this.damageResistant.equals(that.damageResistant) : !that.hasDamageResistant()) && (this.hasMaxStackSize() ? that.hasMaxStackSize() && this.maxStackSize.equals(that.maxStackSize) : !that.hasMaxStackSize()) && (this.rarity == that.rarity) + && (this.hasUseRemainder() ? that.hasUseRemainder() && this.useRemainder.equals(that.useRemainder) : !that.hasUseRemainder()) + && (this.hasUseCooldown() ? that.hasUseCooldown() && this.useCooldown.equals(that.useCooldown) : !that.hasUseCooldown()) && (this.hasFood() ? that.hasFood() && this.food.equals(that.food) : !that.hasFood()) && (this.hasTool() ? that.hasTool() && this.tool.equals(that.tool) : !that.hasTool()) + && (this.hasEquippable() ? that.hasEquippable() && this.equippable.equals(that.equippable) : !that.hasEquippable()) && (this.hasJukeboxPlayable() ? that.hasJukeboxPlayable() && this.jukebox.equals(that.jukebox) : !that.hasJukeboxPlayable()) && (this.hasDamage() ? that.hasDamage() && this.damage == that.damage : !that.hasDamage()) && (this.hasMaxDamage() ? that.hasMaxDamage() && this.maxDamage.equals(that.maxDamage) : !that.hasMaxDamage()) @@ -1584,6 +1844,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { hash = 61 * hash + (hasItemName() ? this.itemName.hashCode() : 0); hash = 61 * hash + ((lore != null) ? this.lore.hashCode() : 0); hash = 61 * hash + (hasCustomModelData() ? this.customModelData.hashCode() : 0); + hash = 61 * hash + (hasEnchantable() ? this.enchantableValue.hashCode() : 0); hash = 61 * hash + (hasBlockData() ? this.blockData.hashCode() : 0); hash = 61 * hash + (hasEnchants() ? this.enchantments.hashCode() : 0); hash = 61 * hash + (hasRepairCost() ? this.repairCost : 0); @@ -1593,14 +1854,20 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { hash = 61 * hash + (!persistentDataContainer.isEmpty() ? persistentDataContainer.hashCode() : 0); hash = 61 * hash + hideFlag; hash = 61 * hash + (isHideTooltip() ? 1231 : 1237); + hash = 61 * hash + (hasTooltipStyle() ? this.tooltipStyle.hashCode() : 0); + hash = 61 * hash + (hasItemModel() ? this.itemModel.hashCode() : 0); hash = 61 * hash + (isUnbreakable() ? 1231 : 1237); hash = 61 * hash + (hasEnchantmentGlintOverride() ? this.enchantmentGlintOverride.hashCode() : 0); - hash = 61 * hash + (isFireResistant() ? 1231 : 1237); + hash = 61 * hash + (isGlider() ? 1231 : 1237); + hash = 61 * hash + (hasDamageResistant() ? this.damageResistant.hashCode() : 0); hash = 61 * hash + (hasMaxStackSize() ? this.maxStackSize.hashCode() : 0); hash = 61 * hash + (hasRarity() ? this.rarity.hashCode() : 0); + hash = 61 * hash + (hasUseRemainder() ? this.useRemainder.hashCode() : 0); + hash = 61 * hash + (hasUseCooldown() ? this.useCooldown.hashCode() : 0); hash = 61 * hash + (hasFood() ? this.food.hashCode() : 0); hash = 61 * hash + (hasTool() ? this.tool.hashCode() : 0); hash = 61 * hash + (hasJukeboxPlayable() ? this.jukebox.hashCode() : 0); + hash = 61 * hash + (hasEquippable() ? this.equippable.hashCode() : 0); hash = 61 * hash + (hasDamage() ? this.damage : 0); hash = 61 * hash + (hasMaxDamage() ? 1231 : 1237); hash = 61 * hash + (hasAttributeModifiers() ? this.attributeModifiers.hashCode() : 0); @@ -1617,6 +1884,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { clone.lore = new ArrayList(this.lore); } clone.customModelData = this.customModelData; + clone.enchantableValue = this.enchantableValue; clone.blockData = this.blockData; if (this.enchantments != null) { clone.enchantments = new LinkedHashMap(this.enchantments); @@ -1631,17 +1899,29 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { clone.persistentDataContainer = new CraftPersistentDataContainer(this.persistentDataContainer.getRaw(), DATA_TYPE_REGISTRY); clone.hideFlag = this.hideFlag; clone.hideTooltip = this.hideTooltip; + clone.tooltipStyle = this.tooltipStyle; + clone.itemModel = this.itemModel; clone.unbreakable = this.unbreakable; clone.enchantmentGlintOverride = this.enchantmentGlintOverride; - clone.fireResistant = fireResistant; + clone.glider = glider; + clone.damageResistant = damageResistant; clone.maxStackSize = maxStackSize; clone.rarity = rarity; + if (this.hasUseRemainder()) { + clone.useRemainder = useRemainder.clone(); + } + if (this.hasUseCooldown()) { + clone.useCooldown = new CraftUseCooldownComponent(useCooldown); + } if (this.hasFood()) { clone.food = new CraftFoodComponent(food); } if (this.hasTool()) { clone.tool = new CraftToolComponent(tool); } + if (this.hasEquippable()) { + clone.equippable = new CraftEquippableComponent(equippable); + } if (this.hasJukeboxPlayable()) { clone.jukebox = new CraftJukeboxComponent(jukebox); } @@ -1686,6 +1966,9 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { if (hasCustomModelData()) { builder.put(CUSTOM_MODEL_DATA.BUKKIT, customModelData); } + if (hasEnchantable()) { + builder.put(ENCHANTABLE.BUKKIT, enchantableValue); + } if (hasBlockData()) { builder.put(BLOCK_DATA.BUKKIT, blockData); } @@ -1709,6 +1992,14 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { builder.put(HIDE_TOOLTIP.BUKKIT, hideTooltip); } + if (hasTooltipStyle()) { + builder.put(TOOLTIP_STYLE.BUKKIT, tooltipStyle.toString()); + } + + if (hasItemModel()) { + builder.put(ITEM_MODEL.BUKKIT, itemModel.toString()); + } + if (isUnbreakable()) { builder.put(UNBREAKABLE.BUKKIT, unbreakable); } @@ -1717,8 +2008,12 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { builder.put(ENCHANTMENT_GLINT_OVERRIDE.BUKKIT, enchantmentGlintOverride); } - if (isFireResistant()) { - builder.put(FIRE_RESISTANT.BUKKIT, fireResistant); + if (isGlider()) { + builder.put(GLIDER.BUKKIT, glider); + } + + if (hasDamageResistant()) { + builder.put(DAMAGE_RESISTANT.BUKKIT, damageResistant.location().toString()); } if (hasMaxStackSize()) { @@ -1729,6 +2024,14 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { builder.put(RARITY.BUKKIT, rarity.name()); } + if (hasUseRemainder()) { + builder.put(USE_REMAINDER.BUKKIT, useRemainder); + } + + if (hasUseCooldown()) { + builder.put(USE_COOLDOWN.BUKKIT, useCooldown); + } + if (hasFood()) { builder.put(FOOD.BUKKIT, food); } @@ -1737,6 +2040,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { builder.put(TOOL.BUKKIT, tool); } + if (hasEquippable()) { + builder.put(EQUIPPABLE.BUKKIT, equippable); + } + if (hasJukeboxPlayable()) { builder.put(JUKEBOX_PLAYABLE.BUKKIT, jukebox); } @@ -1778,7 +2085,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { if (!this.removedTags.isEmpty()) { IRegistryCustom registryAccess = CraftRegistry.getMinecraftRegistry(); - IRegistry> componentTypeRegistry = registryAccess.registryOrThrow(Registries.DATA_COMPONENT_TYPE); + IRegistry> componentTypeRegistry = registryAccess.lookupOrThrow(Registries.DATA_COMPONENT_TYPE); List removedTags = new ArrayList<>(); for (DataComponentType removed : this.removedTags) { @@ -1906,18 +2213,25 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { ITEM_NAME.TYPE, LORE.TYPE, CUSTOM_MODEL_DATA.TYPE, + ENCHANTABLE.TYPE, BLOCK_DATA.TYPE, REPAIR.TYPE, ENCHANTMENTS.TYPE, HIDE_ADDITIONAL_TOOLTIP.TYPE, HIDE_TOOLTIP.TYPE, + TOOLTIP_STYLE.TYPE, + ITEM_MODEL.TYPE, UNBREAKABLE.TYPE, ENCHANTMENT_GLINT_OVERRIDE.TYPE, - FIRE_RESISTANT.TYPE, + GLIDER.TYPE, + DAMAGE_RESISTANT.TYPE, MAX_STACK_SIZE.TYPE, RARITY.TYPE, + USE_REMAINDER.TYPE, + USE_COOLDOWN.TYPE, FOOD.TYPE, TOOL.TYPE, + EQUIPPABLE.TYPE, JUKEBOX_PLAYABLE.TYPE, DAMAGE.TYPE, MAX_DAMAGE.TYPE, diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaKnowledgeBook.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaKnowledgeBook.java index c73445f04e..334f809c92 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaKnowledgeBook.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaKnowledgeBook.java @@ -8,6 +8,8 @@ import java.util.Map; import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.component.DataComponents; import net.minecraft.resources.MinecraftKey; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.crafting.IRecipe; import org.bukkit.NamespacedKey; import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.craftbukkit.util.CraftNamespacedKey; @@ -16,7 +18,7 @@ import org.bukkit.inventory.meta.KnowledgeBookMeta; @DelegateDeserialization(SerializableMeta.class) public class CraftMetaKnowledgeBook extends CraftMetaItem implements KnowledgeBookMeta { - static final ItemMetaKeyType> BOOK_RECIPES = new ItemMetaKeyType<>(DataComponents.RECIPES, "Recipes"); + static final ItemMetaKeyType>>> BOOK_RECIPES = new ItemMetaKeyType<>(DataComponents.RECIPES, "Recipes"); static final int MAX_RECIPES = Short.MAX_VALUE; protected List recipes = new ArrayList(); @@ -35,7 +37,7 @@ public class CraftMetaKnowledgeBook extends CraftMetaItem implements KnowledgeBo getOrEmpty(tag, BOOK_RECIPES).ifPresent((pages) -> { for (int i = 0; i < pages.size(); i++) { - MinecraftKey recipe = pages.get(i); + MinecraftKey recipe = pages.get(i).location(); addRecipe(CraftNamespacedKey.fromMinecraft(recipe)); } @@ -60,9 +62,9 @@ public class CraftMetaKnowledgeBook extends CraftMetaItem implements KnowledgeBo super.applyToItem(itemData); if (hasRecipes()) { - List list = new ArrayList<>(); + List>> list = new ArrayList<>(); for (NamespacedKey recipe : this.recipes) { - list.add(CraftNamespacedKey.toMinecraft(recipe)); + list.add(CraftRecipe.toMinecraft(recipe)); } itemData.put(BOOK_RECIPES, list); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaOminousBottle.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaOminousBottle.java index 18f510d3f6..182aa30034 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaOminousBottle.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaOminousBottle.java @@ -5,13 +5,14 @@ import com.google.common.collect.ImmutableMap.Builder; import java.util.Map; import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.component.OminousBottleAmplifier; import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.inventory.meta.OminousBottleMeta; @DelegateDeserialization(SerializableMeta.class) public class CraftMetaOminousBottle extends CraftMetaItem implements OminousBottleMeta { - static final ItemMetaKeyType OMINOUS_BOTTLE_AMPLIFIER = new ItemMetaKeyType<>(DataComponents.OMINOUS_BOTTLE_AMPLIFIER, "ominous-bottle-amplifier"); + static final ItemMetaKeyType OMINOUS_BOTTLE_AMPLIFIER = new ItemMetaKeyType<>(DataComponents.OMINOUS_BOTTLE_AMPLIFIER, "ominous-bottle-amplifier"); private Integer ominousBottleAmplifier; CraftMetaOminousBottle(CraftMetaItem meta) { @@ -26,7 +27,7 @@ public class CraftMetaOminousBottle extends CraftMetaItem implements OminousBott CraftMetaOminousBottle(DataComponentPatch tag) { super(tag); getOrEmpty(tag, OMINOUS_BOTTLE_AMPLIFIER).ifPresent((amplifier) -> { - ominousBottleAmplifier = amplifier; + ominousBottleAmplifier = amplifier.value(); }); } @@ -43,7 +44,7 @@ public class CraftMetaOminousBottle extends CraftMetaItem implements OminousBott super.applyToItem(tag); if (hasAmplifier()) { - tag.put(OMINOUS_BOTTLE_AMPLIFIER, ominousBottleAmplifier); + tag.put(OMINOUS_BOTTLE_AMPLIFIER, new OminousBottleAmplifier(ominousBottleAmplifier)); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java index c40905f4b9..1aec60cbe8 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java @@ -33,11 +33,13 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { static final ItemMetaKeyType POTION_CONTENTS = new ItemMetaKeyType<>(DataComponents.POTION_CONTENTS); static final ItemMetaKey POTION_EFFECTS = new ItemMetaKey("custom-effects"); static final ItemMetaKey POTION_COLOR = new ItemMetaKey("custom-color"); + static final ItemMetaKey CUSTOM_NAME = new ItemMetaKey("custom-name"); static final ItemMetaKey DEFAULT_POTION = new ItemMetaKey("potion-type"); private PotionType type; private List customEffects; private Color color; + private String customName; CraftMetaPotion(CraftMetaItem meta) { super(meta); @@ -46,6 +48,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { } this.type = potionMeta.type; this.color = potionMeta.color; + this.customName = potionMeta.customName; if (potionMeta.hasCustomEffects()) { this.customEffects = new ArrayList<>(potionMeta.customEffects); } @@ -66,6 +69,10 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { } }); + potionContents.customName().ifPresent((name) -> { + customName = name; + }); + List list = potionContents.customEffects(); int length = list.size(); customEffects = new ArrayList<>(length); @@ -100,6 +107,11 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { setColor(color); } + String name = SerializableMeta.getString(map, CUSTOM_NAME.BUKKIT, true); + if (name != null) { + setCustomName(name); + } + Iterable rawEffectList = SerializableMeta.getObject(Iterable.class, map, POTION_EFFECTS.BUKKIT, true); if (rawEffectList == null) { return; @@ -121,6 +133,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { Optional> defaultPotion = (hasBasePotionType()) ? Optional.of(CraftPotionType.bukkitToMinecraftHolder(type)) : Optional.empty(); Optional potionColor = (hasColor()) ? Optional.of(this.color.asRGB()) : Optional.empty(); + Optional customName = Optional.ofNullable(this.customName); List effectList = new ArrayList<>(); if (customEffects != null) { @@ -129,7 +142,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { } } - tag.put(POTION_CONTENTS, new PotionContents(defaultPotion, potionColor, effectList)); + tag.put(POTION_CONTENTS, new PotionContents(defaultPotion, potionColor, effectList, customName)); } @Override @@ -138,7 +151,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { } boolean isPotionEmpty() { - return (type == null) && !(hasCustomEffects() || hasColor()); + return (type == null) && !(hasCustomEffects() || hasColor() || hasCustomName()); } @Override @@ -292,6 +305,21 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { this.color = color; } + @Override + public boolean hasCustomName() { + return this.customName != null; + } + + @Override + public String getCustomName() { + return this.customName; + } + + @Override + public void setCustomName(String customName) { + this.customName = customName; + } + @Override int applyHash() { final int original; @@ -302,6 +330,9 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { if (hasColor()) { hash = 73 * hash + color.hashCode(); } + if (hasCustomName()) { + hash = 73 * hash + customName.hashCode(); + } if (hasCustomEffects()) { hash = 73 * hash + customEffects.hashCode(); } @@ -318,7 +349,8 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { return Objects.equals(type, that.type) && (this.hasCustomEffects() ? that.hasCustomEffects() && this.customEffects.equals(that.customEffects) : !that.hasCustomEffects()) - && (this.hasColor() ? that.hasColor() && this.color.equals(that.color) : !that.hasColor()); + && (this.hasColor() ? that.hasColor() && this.color.equals(that.color) : !that.hasColor()) + && (this.hasCustomName() ? that.hasCustomName() && this.customName.equals(that.customName) : !that.hasCustomName()); } return true; } @@ -339,6 +371,10 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { builder.put(POTION_COLOR.BUKKIT, getColor()); } + if (hasCustomName()) { + builder.put(CUSTOM_NAME.BUKKIT, getCustomName()); + } + if (hasCustomEffects()) { builder.put(POTION_EFFECTS.BUKKIT, ImmutableList.copyOf(this.customEffects)); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java index 857a64f631..ed0cf5b493 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java @@ -3,8 +3,15 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.List; +import java.util.Optional; +import net.minecraft.core.Holder; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.crafting.IRecipe; import net.minecraft.world.item.crafting.RecipeItemStack; -import org.bukkit.inventory.ItemStack; +import org.bukkit.NamespacedKey; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.RecipeChoice; import org.bukkit.inventory.recipe.CookingBookCategory; @@ -14,47 +21,53 @@ public interface CraftRecipe extends Recipe { void addToCraftingManager(); + default Optional toNMSOptional(RecipeChoice bukkit, boolean requireNotEmpty) { + return (bukkit == null) ? Optional.empty() : Optional.of(toNMS(bukkit, requireNotEmpty)); + } + default RecipeItemStack toNMS(RecipeChoice bukkit, boolean requireNotEmpty) { RecipeItemStack stack; if (bukkit == null) { - stack = RecipeItemStack.EMPTY; + stack = RecipeItemStack.of(); } else if (bukkit instanceof RecipeChoice.MaterialChoice) { - stack = new RecipeItemStack(((RecipeChoice.MaterialChoice) bukkit).getChoices().stream().map((mat) -> new net.minecraft.world.item.crafting.RecipeItemStack.StackProvider(CraftItemStack.asNMSCopy(new ItemStack(mat))))); + stack = RecipeItemStack.of(((RecipeChoice.MaterialChoice) bukkit).getChoices().stream().map((mat) -> CraftItemType.bukkitToMinecraft(mat))); } else if (bukkit instanceof RecipeChoice.ExactChoice) { - stack = new RecipeItemStack(((RecipeChoice.ExactChoice) bukkit).getChoices().stream().map((mat) -> new net.minecraft.world.item.crafting.RecipeItemStack.StackProvider(CraftItemStack.asNMSCopy(mat)))); - stack.exact = true; + stack = RecipeItemStack.ofStacks(((RecipeChoice.ExactChoice) bukkit).getChoices().stream().map((mat) -> CraftItemStack.asNMSCopy(mat))); } else { throw new IllegalArgumentException("Unknown recipe stack instance " + bukkit); } - stack.getItems(); + List> items = stack.items(); if (requireNotEmpty) { - Preconditions.checkArgument(stack.itemStacks.length != 0, "Recipe requires at least one non-air choice"); + Preconditions.checkArgument(!items.isEmpty(), "Recipe requires at least one non-air choice"); } return stack; } - public static RecipeChoice toBukkit(RecipeItemStack list) { - list.getItems(); + public static RecipeChoice toBukkit(Optional list) { + return list.map(CraftRecipe::toBukkit).orElse(null); + } - if (list.itemStacks.length == 0) { + public static RecipeChoice toBukkit(RecipeItemStack list) { + List> items = list.items(); + + if (items.isEmpty()) { return null; } - if (list.exact) { - List choices = new ArrayList<>(list.itemStacks.length); - for (net.minecraft.world.item.ItemStack i : list.itemStacks) { + if (list.isExact()) { + List choices = new ArrayList<>(list.itemStacks().size()); + for (net.minecraft.world.item.ItemStack i : list.itemStacks()) { choices.add(CraftItemStack.asBukkitCopy(i)); } return new RecipeChoice.ExactChoice(choices); } else { - - List choices = new ArrayList<>(list.itemStacks.length); - for (net.minecraft.world.item.ItemStack i : list.itemStacks) { - choices.add(CraftItemType.minecraftToBukkit(i.getItem())); + List choices = new ArrayList<>(items.size()); + for (Holder i : items) { + choices.add(CraftItemType.minecraftToBukkit(i.value())); } return new RecipeChoice.MaterialChoice(choices); @@ -76,4 +89,8 @@ public interface CraftRecipe extends Recipe { public static CookingBookCategory getCategory(net.minecraft.world.item.crafting.CookingBookCategory nms) { return CookingBookCategory.valueOf(nms.name()); } + + public static ResourceKey> toMinecraft(NamespacedKey key) { + return ResourceKey.create(Registries.RECIPE, CraftNamespacedKey.toMinecraft(key)); + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapedRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapedRecipe.java index e6d413ce91..243118cdad 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapedRecipe.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapedRecipe.java @@ -9,7 +9,6 @@ import net.minecraft.world.item.crafting.RecipeItemStack; import net.minecraft.world.item.crafting.ShapedRecipePattern; import net.minecraft.world.item.crafting.ShapedRecipes; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.RecipeChoice; import org.bukkit.inventory.ShapedRecipe; @@ -54,7 +53,7 @@ public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe { Map data = Maps.transformValues(ingred, (bukkit) -> toNMS(bukkit, false)); ShapedRecipePattern pattern = ShapedRecipePattern.of(data, shape); - MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new ShapedRecipes(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), pattern, CraftItemStack.asNMSCopy(this.getResult())))); + MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new ShapedRecipes(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), pattern, CraftItemStack.asNMSCopy(this.getResult())))); } private static String[] replaceUndefinedIngredientsWithEmpty(String[] shape, Map ingredients) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java index c69c90cd49..3cc08a6418 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapelessRecipe.java @@ -1,13 +1,12 @@ package org.bukkit.craftbukkit.inventory; +import java.util.ArrayList; import java.util.List; -import net.minecraft.core.NonNullList; import net.minecraft.server.MinecraftServer; import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.RecipeItemStack; import net.minecraft.world.item.crafting.ShapelessRecipes; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.RecipeChoice; import org.bukkit.inventory.ShapelessRecipe; @@ -41,11 +40,11 @@ public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe @Override public void addToCraftingManager() { List ingred = this.getChoiceList(); - NonNullList data = NonNullList.withSize(ingred.size(), RecipeItemStack.EMPTY); + List data = new ArrayList<>(ingred.size()); for (int i = 0; i < ingred.size(); i++) { data.set(i, toNMS(ingred.get(i), true)); } - MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new ShapelessRecipes(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), CraftItemStack.asNMSCopy(this.getResult()), data))); + MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new ShapelessRecipes(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), CraftItemStack.asNMSCopy(this.getResult()), data))); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTransformRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTransformRecipe.java index d0649e3b0d..2a518ac135 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTransformRecipe.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTransformRecipe.java @@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory; import net.minecraft.server.MinecraftServer; import net.minecraft.world.item.crafting.RecipeHolder; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.RecipeChoice; import org.bukkit.inventory.SmithingTransformRecipe; @@ -25,6 +24,6 @@ public class CraftSmithingTransformRecipe extends SmithingTransformRecipe implem public void addToCraftingManager() { ItemStack result = this.getResult(); - MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTransformRecipe(toNMS(this.getTemplate(), false), toNMS(this.getBase(), false), toNMS(this.getAddition(), false), CraftItemStack.asNMSCopy(result)))); + MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTransformRecipe(toNMSOptional(this.getTemplate(), false), toNMSOptional(this.getBase(), false), toNMSOptional(this.getAddition(), false), CraftItemStack.asNMSCopy(result)))); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java index 3c48b4093f..339dcbfc7e 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java @@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory; import net.minecraft.server.MinecraftServer; import net.minecraft.world.item.crafting.RecipeHolder; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.RecipeChoice; import org.bukkit.inventory.SmithingTrimRecipe; @@ -23,6 +22,6 @@ public class CraftSmithingTrimRecipe extends SmithingTrimRecipe implements Craft @Override public void addToCraftingManager() { - MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTrimRecipe(toNMS(this.getTemplate(), false), toNMS(this.getBase(), false), toNMS(this.getAddition(), false)))); + MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTrimRecipe(toNMSOptional(this.getTemplate(), false), toNMSOptional(this.getBase(), false), toNMSOptional(this.getAddition(), false)))); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmokingRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmokingRecipe.java index 0b30003b8e..69e3b32565 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmokingRecipe.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmokingRecipe.java @@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory; import net.minecraft.server.MinecraftServer; import net.minecraft.world.item.crafting.RecipeHolder; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.RecipeChoice; import org.bukkit.inventory.SmokingRecipe; @@ -27,6 +26,6 @@ public class CraftSmokingRecipe extends SmokingRecipe implements CraftRecipe { public void addToCraftingManager() { ItemStack result = this.getResult(); - MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeSmoking(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()))); + MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeSmoking(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()))); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftStonecuttingRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftStonecuttingRecipe.java index ec27634cc6..1515c7b1f5 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftStonecuttingRecipe.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftStonecuttingRecipe.java @@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory; import net.minecraft.server.MinecraftServer; import net.minecraft.world.item.crafting.RecipeHolder; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.RecipeChoice; import org.bukkit.inventory.StonecuttingRecipe; @@ -26,6 +25,6 @@ public class CraftStonecuttingRecipe extends StonecuttingRecipe implements Craft public void addToCraftingManager() { ItemStack result = this.getResult(); - MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeStonecutting(this.getGroup(), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result)))); + MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.RecipeStonecutting(this.getGroup(), toNMS(this.getInputChoice(), true), CraftItemStack.asNMSCopy(result)))); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftTransmuteRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftTransmuteRecipe.java new file mode 100644 index 0000000000..6af50aaa6b --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftTransmuteRecipe.java @@ -0,0 +1,40 @@ +package org.bukkit.craftbukkit.inventory; + +import net.minecraft.core.Holder; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.item.crafting.RecipeHolder; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.RecipeChoice; +import org.bukkit.inventory.TransmuteRecipe; + +public class CraftTransmuteRecipe extends TransmuteRecipe implements CraftRecipe { + + public CraftTransmuteRecipe(NamespacedKey key, Material result, RecipeChoice input, RecipeChoice material) { + super(key, result, input, material); + } + + public static CraftTransmuteRecipe fromBukkitRecipe(TransmuteRecipe recipe) { + if (recipe instanceof CraftTransmuteRecipe) { + return (CraftTransmuteRecipe) recipe; + } + CraftTransmuteRecipe ret = new CraftTransmuteRecipe(recipe.getKey(), recipe.getResult().getType(), recipe.getInput(), recipe.getMaterial()); + ret.setGroup(recipe.getGroup()); + ret.setCategory(recipe.getCategory()); + return ret; + } + + @Override + public void addToCraftingManager() { + MinecraftServer.getServer().getRecipeManager().addRecipe( + new RecipeHolder<>(CraftRecipe.toMinecraft(this.getKey()), + new net.minecraft.world.item.crafting.TransmuteRecipe(this.getGroup(), + CraftRecipe.getCategory(this.getCategory()), + toNMS(this.getInput(), true), + toNMS(this.getMaterial(), true), + Holder.direct(CraftItemType.bukkitToMinecraft(this.getResult().getType())) + ) + ) + ); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java index 4b846bb3f8..460b29e540 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java @@ -11,7 +11,7 @@ public class RecipeIterator implements Iterator { private final Iterator, RecipeHolder>> recipes; public RecipeIterator() { - this.recipes = MinecraftServer.getServer().getRecipeManager().byType.entries().iterator(); + this.recipes = MinecraftServer.getServer().getRecipeManager().recipes.byType.entries().iterator(); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftEquippableComponent.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftEquippableComponent.java new file mode 100644 index 0000000000..f72ae5155f --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftEquippableComponent.java @@ -0,0 +1,239 @@ +package org.bukkit.craftbukkit.inventory.components; + +import com.google.common.base.Preconditions; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; +import net.minecraft.core.Holder; +import net.minecraft.core.HolderSet; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.MinecraftKey; +import net.minecraft.sounds.SoundEffects; +import net.minecraft.world.entity.EntityTypes; +import net.minecraft.world.entity.EnumItemSlot; +import net.minecraft.world.item.equipment.Equippable; +import org.bukkit.NamespacedKey; +import org.bukkit.Registry; +import org.bukkit.Sound; +import org.bukkit.Tag; +import org.bukkit.configuration.serialization.SerializableAs; +import org.bukkit.craftbukkit.CraftEquipmentSlot; +import org.bukkit.craftbukkit.CraftSound; +import org.bukkit.craftbukkit.entity.CraftEntityType; +import org.bukkit.craftbukkit.inventory.SerializableMeta; +import org.bukkit.craftbukkit.tag.CraftEntityTag; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.entity.EntityType; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.meta.components.EquippableComponent; + +@SerializableAs("Equippable") +public final class CraftEquippableComponent implements EquippableComponent { + + private Equippable handle; + + public CraftEquippableComponent(Equippable handle) { + this.handle = handle; + } + + public CraftEquippableComponent(CraftEquippableComponent craft) { + this.handle = craft.handle; + } + + public CraftEquippableComponent(Map map) { + EnumItemSlot slot = CraftEquipmentSlot.getNMS(EquipmentSlot.valueOf(SerializableMeta.getString(map, "slot", false))); + + Sound equipSound = null; + String snd = SerializableMeta.getString(map, "equip-sound", true); + if (snd != null) { + equipSound = Registry.SOUNDS.get(NamespacedKey.fromString(snd)); + } + + String model = SerializableMeta.getString(map, "model", true); + String cameraOverlay = SerializableMeta.getString(map, "camera-overlay", true); + + HolderSet> allowedEntities = null; + Object allowed = SerializableMeta.getObject(Object.class, map, "allowed-entities", true); + if (allowed != null) { + allowedEntities = CraftHolderUtil.parse(allowed, Registries.ENTITY_TYPE, BuiltInRegistries.ENTITY_TYPE); + } + + Boolean dispensable = SerializableMeta.getObject(Boolean.class, map, "dispensable", true); + Boolean swappable = SerializableMeta.getObject(Boolean.class, map, "swappable", true); + Boolean damageOnHurt = SerializableMeta.getObject(Boolean.class, map, "damage-on-hurt", true); + + this.handle = new Equippable(slot, + (equipSound != null) ? CraftSound.bukkitToMinecraftHolder(equipSound) : SoundEffects.ARMOR_EQUIP_GENERIC, + Optional.ofNullable(model).map(MinecraftKey::parse), + Optional.ofNullable(cameraOverlay).map(MinecraftKey::parse), + Optional.ofNullable(allowedEntities), + (dispensable != null) ? dispensable : true, + (swappable != null) ? swappable : true, + (damageOnHurt != null) ? damageOnHurt : true + ); + } + + @Override + public Map serialize() { + Map result = new LinkedHashMap<>(); + result.put("slot", getSlot().name()); + result.put("equip-sound", getEquipSound().getKey().toString()); + + NamespacedKey model = getModel(); + if (model != null) { + result.put("model", model.toString()); + } + + NamespacedKey cameraOverlay = getCameraOverlay(); + if (cameraOverlay != null) { + result.put("camera-overlay", cameraOverlay.toString()); + } + + Optional>> allowed = handle.allowedEntities(); + if (allowed.isPresent()) { + CraftHolderUtil.serialize(result, "allowed-entities", allowed.get()); + } + + result.put("dispensable", isDispensable()); + result.put("swappable", isSwappable()); + result.put("damage-on-hurt", isDamageOnHurt()); + + return result; + } + + public Equippable getHandle() { + return handle; + } + + @Override + public EquipmentSlot getSlot() { + return CraftEquipmentSlot.getSlot(handle.slot()); + } + + @Override + public void setSlot(EquipmentSlot slot) { + handle = new Equippable(CraftEquipmentSlot.getNMS(slot), handle.equipSound(), handle.model(), handle.cameraOverlay(), handle.allowedEntities(), handle.dispensable(), handle.swappable(), handle.damageOnHurt()); + } + + @Override + public Sound getEquipSound() { + return CraftSound.minecraftToBukkit(handle.equipSound().value()); + } + + @Override + public void setEquipSound(Sound sound) { + handle = new Equippable(handle.slot(), (sound != null) ? CraftSound.bukkitToMinecraftHolder(sound) : SoundEffects.ARMOR_EQUIP_GENERIC, handle.model(), handle.cameraOverlay(), handle.allowedEntities(), handle.dispensable(), handle.swappable(), handle.damageOnHurt()); + } + + @Override + public NamespacedKey getModel() { + return handle.model().map(CraftNamespacedKey::fromMinecraft).orElse(null); + } + + @Override + public void setModel(NamespacedKey key) { + handle = new Equippable(handle.slot(), handle.equipSound(), Optional.ofNullable(key).map(CraftNamespacedKey::toMinecraft), handle.cameraOverlay(), handle.allowedEntities(), handle.dispensable(), handle.swappable(), handle.damageOnHurt()); + } + + @Override + public NamespacedKey getCameraOverlay() { + return handle.cameraOverlay().map(CraftNamespacedKey::fromMinecraft).orElse(null); + } + + @Override + public void setCameraOverlay(NamespacedKey key) { + handle = new Equippable(handle.slot(), handle.equipSound(), handle.model(), Optional.ofNullable(key).map(CraftNamespacedKey::toMinecraft), handle.allowedEntities(), handle.dispensable(), handle.swappable(), handle.damageOnHurt()); + } + + @Override + public Collection getAllowedEntities() { + return handle.allowedEntities().map(HolderSet::stream).map((stream) -> stream.map(Holder::value).map(CraftEntityType::minecraftToBukkit).collect(Collectors.toList())).orElse(null); + } + + @Override + public void setAllowedEntities(EntityType entities) { + handle = new Equippable(handle.slot(), handle.equipSound(), handle.model(), handle.cameraOverlay(), + (entities != null) ? Optional.of(HolderSet.direct(CraftEntityType.bukkitToMinecraftHolder(entities))) : Optional.empty(), + handle.dispensable(), handle.swappable(), handle.damageOnHurt() + ); + } + + @Override + public void setAllowedEntities(Collection entities) { + handle = new Equippable(handle.slot(), handle.equipSound(), handle.model(), handle.cameraOverlay(), + (entities != null) ? Optional.of(HolderSet.direct(entities.stream().map(CraftEntityType::bukkitToMinecraftHolder).collect(Collectors.toList()))) : Optional.empty(), + handle.dispensable(), handle.swappable(), handle.damageOnHurt() + ); + } + + @Override + public void setAllowedEntities(Tag tag) { + Preconditions.checkArgument(tag instanceof CraftEntityTag, "tag must be an entity tag"); + + handle = new Equippable(handle.slot(), handle.equipSound(), handle.model(), handle.cameraOverlay(), + (tag != null) ? Optional.of(((CraftEntityTag) tag).getHandle()) : Optional.empty(), + handle.dispensable(), handle.swappable(), handle.damageOnHurt() + ); + } + + @Override + public boolean isDispensable() { + return handle.dispensable(); + } + + @Override + public void setDispensable(boolean dispensable) { + handle = new Equippable(handle.slot(), handle.equipSound(), handle.model(), handle.cameraOverlay(), handle.allowedEntities(), dispensable, handle.swappable(), handle.damageOnHurt()); + } + + @Override + public boolean isSwappable() { + return handle.swappable(); + } + + @Override + public void setSwappable(boolean swappable) { + handle = new Equippable(handle.slot(), handle.equipSound(), handle.model(), handle.cameraOverlay(), handle.allowedEntities(), handle.dispensable(), swappable, handle.damageOnHurt()); + } + + @Override + public boolean isDamageOnHurt() { + return handle.damageOnHurt(); + } + + @Override + public void setDamageOnHurt(boolean damage) { + handle = new Equippable(handle.slot(), handle.equipSound(), handle.model(), handle.cameraOverlay(), handle.allowedEntities(), handle.dispensable(), handle.swappable(), damage); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final CraftEquippableComponent other = (CraftEquippableComponent) obj; + return Objects.equals(this.handle, other.handle); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 19 * hash + Objects.hashCode(this.handle); + return hash; + } + + @Override + public String toString() { + return "CraftEquippableComponent{" + "handle=" + handle + '}'; + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftFoodComponent.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftFoodComponent.java index 21fee6cd21..f121f46b47 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftFoodComponent.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftFoodComponent.java @@ -1,22 +1,13 @@ package org.bukkit.craftbukkit.inventory.components; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import java.util.ArrayList; import java.util.LinkedHashMap; -import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; import net.minecraft.world.food.FoodInfo; import org.bukkit.configuration.serialization.SerializableAs; -import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.inventory.SerializableMeta; -import org.bukkit.craftbukkit.potion.CraftPotionUtil; -import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.components.FoodComponent; -import org.bukkit.potion.PotionEffect; @SerializableAs("Food") public final class CraftFoodComponent implements FoodComponent { @@ -36,23 +27,7 @@ public final class CraftFoodComponent implements FoodComponent { Float saturationModifier = SerializableMeta.getObject(Float.class, map, "saturation", false); Boolean canAlwaysEat = SerializableMeta.getBoolean(map, "can-always-eat"); - Float eatSeconds = SerializableMeta.getObject(Float.class, map, "eat-seconds", true); - if (eatSeconds == null) { - eatSeconds = 1.6f; - } - - ItemStack usingConvertsTo = SerializableMeta.getObject(ItemStack.class, map, "using-converts-to", true); - - ImmutableList.Builder effects = ImmutableList.builder(); - Iterable rawEffectList = SerializableMeta.getObject(Iterable.class, map, "effects", true); - if (rawEffectList != null) { - for (Object obj : rawEffectList) { - Preconditions.checkArgument(obj instanceof FoodEffect, "Object (%s) in effect list is not valid", obj.getClass()); - effects.add(new CraftFoodEffect((FoodEffect) obj)); - } - } - - this.handle = new FoodInfo(nutrition, saturationModifier, canAlwaysEat, eatSeconds, Optional.ofNullable(usingConvertsTo).map(CraftItemStack::asNMSCopy), effects.build().stream().map(CraftFoodEffect::new).map(CraftFoodEffect::getHandle).toList()); + this.handle = new FoodInfo(nutrition, saturationModifier, canAlwaysEat); } @Override @@ -61,14 +36,7 @@ public final class CraftFoodComponent implements FoodComponent { result.put("nutrition", getNutrition()); result.put("saturation", getSaturation()); result.put("can-always-eat", canAlwaysEat()); - result.put("eat-seconds", getEatSeconds()); - ItemStack usingConvertsTo = getUsingConvertsTo(); - if (usingConvertsTo != null) { - result.put("using-converts-to", usingConvertsTo); - } - - result.put("effects", getEffects()); return result; } @@ -84,7 +52,7 @@ public final class CraftFoodComponent implements FoodComponent { @Override public void setNutrition(int nutrition) { Preconditions.checkArgument(nutrition >= 0, "Nutrition cannot be negative"); - handle = new FoodInfo(nutrition, handle.saturation(), handle.canAlwaysEat(), handle.eatSeconds(), handle.usingConvertsTo(), handle.effects()); + handle = new FoodInfo(nutrition, handle.saturation(), handle.canAlwaysEat()); } @Override @@ -94,7 +62,7 @@ public final class CraftFoodComponent implements FoodComponent { @Override public void setSaturation(float saturation) { - handle = new FoodInfo(handle.nutrition(), saturation, handle.canAlwaysEat(), handle.eatSeconds(), handle.usingConvertsTo(), handle.effects()); + handle = new FoodInfo(handle.nutrition(), saturation, handle.canAlwaysEat()); } @Override @@ -104,49 +72,7 @@ public final class CraftFoodComponent implements FoodComponent { @Override public void setCanAlwaysEat(boolean canAlwaysEat) { - handle = new FoodInfo(handle.nutrition(), handle.saturation(), canAlwaysEat, handle.eatSeconds(), handle.usingConvertsTo(), handle.effects()); - } - - @Override - public float getEatSeconds() { - return handle.eatSeconds(); - } - - @Override - public void setEatSeconds(float eatSeconds) { - handle = new FoodInfo(handle.nutrition(), handle.saturation(), handle.canAlwaysEat(), eatSeconds, handle.usingConvertsTo(), handle.effects()); - } - - @Override - public ItemStack getUsingConvertsTo() { - return handle.usingConvertsTo().map(CraftItemStack::asBukkitCopy).orElse(null); - } - - @Override - public void setUsingConvertsTo(ItemStack item) { - handle = new FoodInfo(handle.nutrition(), handle.saturation(), handle.canAlwaysEat(), handle.eatSeconds(), Optional.ofNullable(item).map(CraftItemStack::asNMSCopy), handle.effects()); - } - - @Override - public List getEffects() { - return handle.effects().stream().map(CraftFoodEffect::new).collect(Collectors.toList()); - } - - @Override - public void setEffects(List effects) { - handle = new FoodInfo(handle.nutrition(), handle.saturation(), handle.canAlwaysEat(), handle.eatSeconds(), handle.usingConvertsTo(), effects.stream().map(CraftFoodEffect::new).map(CraftFoodEffect::getHandle).toList()); - } - - @Override - public FoodEffect addEffect(PotionEffect effect, float probability) { - List effects = new ArrayList<>(handle.effects()); - - FoodInfo.b newEffect = new net.minecraft.world.food.FoodInfo.b(CraftPotionUtil.fromBukkit(effect), probability); - effects.add(newEffect); - - handle = new FoodInfo(handle.nutrition(), handle.saturation(), handle.canAlwaysEat(), handle.eatSeconds(), handle.usingConvertsTo(), effects); - - return new CraftFoodEffect(newEffect); + handle = new FoodInfo(handle.nutrition(), handle.saturation(), canAlwaysEat); } @Override @@ -175,89 +101,4 @@ public final class CraftFoodComponent implements FoodComponent { public String toString() { return "CraftFoodComponent{" + "handle=" + handle + '}'; } - - @SerializableAs("FoodEffect") - public static class CraftFoodEffect implements FoodEffect { - - private FoodInfo.b handle; - - public CraftFoodEffect(FoodInfo.b handle) { - this.handle = handle; - } - - public CraftFoodEffect(FoodEffect bukkit) { - this.handle = new net.minecraft.world.food.FoodInfo.b(CraftPotionUtil.fromBukkit(bukkit.getEffect()), bukkit.getProbability()); - } - - public CraftFoodEffect(Map map) { - PotionEffect effect = SerializableMeta.getObject(PotionEffect.class, map, "effect", false); - - Float probability = SerializableMeta.getObject(Float.class, map, "probability", true); - if (probability == null) { - probability = 1.0f; - } - - this.handle = new net.minecraft.world.food.FoodInfo.b(CraftPotionUtil.fromBukkit(effect), probability); - } - - @Override - public Map serialize() { - Map result = new LinkedHashMap<>(); - result.put("effect", getEffect()); - result.put("probability", getProbability()); - return result; - } - - public FoodInfo.b getHandle() { - return handle; - } - - @Override - public PotionEffect getEffect() { - return CraftPotionUtil.toBukkit(handle.effect()); - } - - @Override - public void setEffect(PotionEffect effect) { - handle = new net.minecraft.world.food.FoodInfo.b(CraftPotionUtil.fromBukkit(effect), handle.probability()); - } - - @Override - public float getProbability() { - return handle.probability(); - } - - @Override - public void setProbability(float probability) { - Preconditions.checkArgument(0 <= probability && probability <= 1, "Probability cannot be outside range [0,1]"); - handle = new net.minecraft.world.food.FoodInfo.b(handle.effect(), probability); - } - - @Override - public int hashCode() { - int hash = 5; - hash = 97 * hash + Objects.hashCode(this.handle); - return hash; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final CraftFoodEffect other = (CraftFoodEffect) obj; - return Objects.equals(this.handle, other.handle); - } - - @Override - public String toString() { - return "CraftFoodEffect{" + "handle=" + handle + '}'; - } - } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftHolderUtil.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftHolderUtil.java new file mode 100644 index 0000000000..0f1e5e74ef --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftHolderUtil.java @@ -0,0 +1,56 @@ +package org.bukkit.craftbukkit.inventory.components; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import net.minecraft.core.Holder; +import net.minecraft.core.HolderSet; +import net.minecraft.core.IRegistry; +import net.minecraft.resources.MinecraftKey; +import net.minecraft.resources.ResourceKey; +import net.minecraft.tags.TagKey; + +final class CraftHolderUtil { + + private CraftHolderUtil() { + } + + public static void serialize(Map result, String key, HolderSet handle) { + handle.unwrap() + .ifLeft(tag -> result.put(key, "#" + tag.location().toString())) // Tag + .ifRight(list -> result.put(key, list.stream().map((entry) -> entry.unwrapKey().orElseThrow().location().toString()).toList())); // List + } + + public static HolderSet parse(Object parseObject, ResourceKey> registryKey, IRegistry registry) { + HolderSet holderSet = null; + + if (parseObject instanceof String parseString && parseString.startsWith("#")) { // Tag + parseString = parseString.substring(1); + MinecraftKey key = MinecraftKey.tryParse(parseString); + if (key != null) { + holderSet = registry.get(TagKey.create(registryKey, key)).orElse(null); + } + } else if (parseObject instanceof List parseList) { // List + List> holderList = new ArrayList<>(parseList.size()); + + for (Object entry : parseList) { + MinecraftKey key = MinecraftKey.tryParse(entry.toString()); + if (key == null) { + continue; + } + + registry.get(key).ifPresent(holderList::add); + } + + holderSet = HolderSet.direct(holderList); + } else { + throw new IllegalArgumentException("(" + parseObject + ") is not a valid String or List"); + } + + if (holderSet == null) { + holderSet = HolderSet.empty(); + } + + return holderSet; + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftToolComponent.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftToolComponent.java index 7b909a3fab..1484ac8ea4 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftToolComponent.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftToolComponent.java @@ -14,8 +14,6 @@ import net.minecraft.core.Holder; import net.minecraft.core.HolderSet; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; -import net.minecraft.resources.MinecraftKey; -import net.minecraft.tags.TagKey; import net.minecraft.world.item.component.Tool; import net.minecraft.world.level.block.Block; import org.bukkit.Material; @@ -197,35 +195,7 @@ public final class CraftToolComponent implements ToolComponent { public CraftToolRule(Map map) { Float speed = SerializableMeta.getObject(Float.class, map, "speed", true); Boolean correct = SerializableMeta.getObject(Boolean.class, map, "correct-for-drops", true); - - HolderSet blocks = null; - Object blocksObject = SerializableMeta.getObject(Object.class, map, "blocks", false); - if (blocksObject instanceof String blocksString && blocksString.startsWith("#")) { // Tag - blocksString = blocksString.substring(1); - MinecraftKey key = MinecraftKey.tryParse(blocksString); - if (key != null) { - blocks = BuiltInRegistries.BLOCK.getTag(TagKey.create(Registries.BLOCK, key)).orElse(null); - } - } else if (blocksObject instanceof List blocksList) { // List of blocks - List> blockHolders = new ArrayList<>(blocksList.size()); - - for (Object entry : blocksList) { - MinecraftKey key = MinecraftKey.tryParse(entry.toString()); - if (key == null) { - continue; - } - - BuiltInRegistries.BLOCK.getHolder(key).ifPresent(blockHolders::add); - } - - blocks = HolderSet.direct(blockHolders); - } else { - throw new IllegalArgumentException("blocks" + "(" + blocksObject + ") is not a valid String or List"); - } - - if (blocks == null) { - blocks = HolderSet.empty(); - } + HolderSet blocks = CraftHolderUtil.parse(SerializableMeta.getObject(Object.class, map, "blocks", false), Registries.BLOCK, BuiltInRegistries.BLOCK); this.handle = new Tool.a(blocks, Optional.ofNullable(speed), Optional.ofNullable(correct)); } @@ -234,9 +204,7 @@ public final class CraftToolComponent implements ToolComponent { public Map serialize() { Map result = new LinkedHashMap<>(); - handle.blocks().unwrap() - .ifLeft(key -> result.put("blocks", "#" + key.location().toString())) // Tag - .ifRight(blocks -> result.put("blocks", blocks.stream().map((block) -> block.unwrapKey().orElseThrow().location().toString()).toList())); // List of blocks + CraftHolderUtil.serialize(result, "blocks", handle.blocks()); Float speed = getSpeed(); if (speed != null) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftUseCooldownComponent.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftUseCooldownComponent.java new file mode 100644 index 0000000000..a316eb6242 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftUseCooldownComponent.java @@ -0,0 +1,99 @@ +package org.bukkit.craftbukkit.inventory.components; + +import com.google.common.base.Preconditions; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import net.minecraft.resources.MinecraftKey; +import net.minecraft.world.item.component.UseCooldown; +import org.bukkit.NamespacedKey; +import org.bukkit.configuration.serialization.SerializableAs; +import org.bukkit.craftbukkit.inventory.SerializableMeta; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.inventory.meta.components.UseCooldownComponent; + +@SerializableAs("UseCooldown") +public final class CraftUseCooldownComponent implements UseCooldownComponent { + + private UseCooldown handle; + + public CraftUseCooldownComponent(UseCooldown cooldown) { + this.handle = cooldown; + } + + public CraftUseCooldownComponent(CraftUseCooldownComponent food) { + this.handle = food.handle; + } + + public CraftUseCooldownComponent(Map map) { + Float seconds = SerializableMeta.getObject(Float.class, map, "seconds", false); + String cooldownGroup = SerializableMeta.getString(map, "cooldown-group", true); + + this.handle = new UseCooldown(seconds, Optional.ofNullable(cooldownGroup).map(MinecraftKey::parse)); + } + + @Override + public Map serialize() { + Map result = new LinkedHashMap<>(); + result.put("seconds", getCooldownSeconds()); + if (getCooldownGroup() != null) { + result.put("cooldown-group", getCooldownGroup()); + } + + return result; + } + + public UseCooldown getHandle() { + return handle; + } + + @Override + public float getCooldownSeconds() { + return handle.seconds(); + } + + @Override + public void setCooldownSeconds(float eatSeconds) { + Preconditions.checkArgument(eatSeconds >= 0, "eatSeconds cannot be less than 0"); + + handle = new UseCooldown(eatSeconds, handle.cooldownGroup()); + } + + @Override + public NamespacedKey getCooldownGroup() { + return handle.cooldownGroup().map(CraftNamespacedKey::fromMinecraft).orElse(null); + } + + @Override + public void setCooldownGroup(NamespacedKey song) { + handle = new UseCooldown(handle.seconds(), Optional.ofNullable(song).map(CraftNamespacedKey::toMinecraft)); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 73 * hash + Objects.hashCode(this.handle); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final CraftUseCooldownComponent other = (CraftUseCooldownComponent) obj; + return Objects.equals(this.handle, other.handle); + } + + @Override + public String toString() { + return "CraftUseCooldownComponent{" + "handle=" + handle + '}'; + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimMaterial.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimMaterial.java index 0094020436..b7944a5c18 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimMaterial.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimMaterial.java @@ -12,26 +12,26 @@ import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.inventory.meta.trim.TrimMaterial; import org.jetbrains.annotations.NotNull; -public class CraftTrimMaterial implements TrimMaterial, Handleable { +public class CraftTrimMaterial implements TrimMaterial, Handleable { - public static TrimMaterial minecraftToBukkit(net.minecraft.world.item.armortrim.TrimMaterial minecraft) { + public static TrimMaterial minecraftToBukkit(net.minecraft.world.item.equipment.trim.TrimMaterial minecraft) { return CraftRegistry.minecraftToBukkit(minecraft, Registries.TRIM_MATERIAL, Registry.TRIM_MATERIAL); } - public static TrimMaterial minecraftHolderToBukkit(Holder minecraft) { + public static TrimMaterial minecraftHolderToBukkit(Holder minecraft) { return minecraftToBukkit(minecraft.value()); } - public static net.minecraft.world.item.armortrim.TrimMaterial bukkitToMinecraft(TrimMaterial bukkit) { + public static net.minecraft.world.item.equipment.trim.TrimMaterial bukkitToMinecraft(TrimMaterial bukkit) { return CraftRegistry.bukkitToMinecraft(bukkit); } - public static Holder bukkitToMinecraftHolder(TrimMaterial bukkit) { + public static Holder bukkitToMinecraftHolder(TrimMaterial bukkit) { Preconditions.checkArgument(bukkit != null); - IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.TRIM_MATERIAL); + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.TRIM_MATERIAL); - if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c holder) { + if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c holder) { return holder; } @@ -40,15 +40,15 @@ public class CraftTrimMaterial implements TrimMaterial, Handleable { +public class CraftTrimPattern implements TrimPattern, Handleable { - public static TrimPattern minecraftToBukkit(net.minecraft.world.item.armortrim.TrimPattern minecraft) { + public static TrimPattern minecraftToBukkit(net.minecraft.world.item.equipment.trim.TrimPattern minecraft) { return CraftRegistry.minecraftToBukkit(minecraft, Registries.TRIM_PATTERN, Registry.TRIM_PATTERN); } - public static TrimPattern minecraftHolderToBukkit(Holder minecraft) { + public static TrimPattern minecraftHolderToBukkit(Holder minecraft) { return minecraftToBukkit(minecraft.value()); } - public static net.minecraft.world.item.armortrim.TrimPattern bukkitToMinecraft(TrimPattern bukkit) { + public static net.minecraft.world.item.equipment.trim.TrimPattern bukkitToMinecraft(TrimPattern bukkit) { return CraftRegistry.bukkitToMinecraft(bukkit); } - public static Holder bukkitToMinecraftHolder(TrimPattern bukkit) { + public static Holder bukkitToMinecraftHolder(TrimPattern bukkit) { Preconditions.checkArgument(bukkit != null); - IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.TRIM_PATTERN); + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.TRIM_PATTERN); - if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c holder) { + if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c holder) { return holder; } @@ -40,15 +40,15 @@ public class CraftTrimPattern implements TrimPattern, Handleable> registry = CraftRegistry.getMinecraftRegistry().registryOrThrow(Registries.ENCHANTMENT).asHolderIdMap(); + Registry> registry = CraftRegistry.getMinecraftRegistry().lookupOrThrow(Registries.ENCHANTMENT).asHolderIdMap(); EnchantmentOffer[] offers = new EnchantmentOffer[3]; for (int i = 0; i < 3; i++) { org.bukkit.enchantments.Enchantment enchantment = (container.enchantClue[i] >= 0) ? CraftEnchantment.minecraftHolderToBukkit(registry.byId(container.enchantClue[i])) : null; @@ -41,7 +41,7 @@ public class CraftEnchantmentView extends CraftInventoryView> registry = CraftRegistry.getMinecraftRegistry().registryOrThrow(Registries.ENCHANTMENT).asHolderIdMap(); + Registry> registry = CraftRegistry.getMinecraftRegistry().lookupOrThrow(Registries.ENCHANTMENT).asHolderIdMap(); for (int i = 0; i < offers.length; i++) { final EnchantmentOffer offer = offers[i]; if (offer == null) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftStonecutterView.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftStonecutterView.java index 579d83438c..19cb5bc162 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftStonecutterView.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/view/CraftStonecutterView.java @@ -5,6 +5,7 @@ import java.util.List; import net.minecraft.world.inventory.ContainerStonecutter; import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.RecipeStonecutting; +import net.minecraft.world.item.crafting.SelectableRecipe; import org.bukkit.craftbukkit.inventory.CraftInventoryView; import org.bukkit.entity.HumanEntity; import org.bukkit.inventory.StonecutterInventory; @@ -27,14 +28,14 @@ public class CraftStonecutterView extends CraftInventoryView getRecipes() { final List recipes = new ArrayList<>(); - for (final RecipeHolder recipe : container.getRecipes()) { - recipes.add((StonecuttingRecipe) recipe.toBukkitRecipe()); + for (final SelectableRecipe.a recipe : container.getVisibleRecipes().entries()) { + recipe.recipe().recipe().map(RecipeHolder::toBukkitRecipe).ifPresent((bukkit) -> recipes.add((StonecuttingRecipe) bukkit)); } return recipes; } @Override public int getRecipeAmount() { - return container.getNumRecipes(); + return container.getNumberOfVisibleRecipes(); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/CraftLegacy.java b/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/CraftLegacy.java index 6ba12831af..536db5de31 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/CraftLegacy.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/CraftLegacy.java @@ -342,7 +342,7 @@ public final class CraftLegacy { } String name = blockTag.get("Name").asString(""); - Block block = BuiltInRegistries.BLOCK.get(MinecraftKey.parse(name)); + Block block = BuiltInRegistries.BLOCK.getValue(MinecraftKey.parse(name)); if (block == null) { continue; } @@ -416,7 +416,7 @@ public final class CraftLegacy { } // Preconditions.checkState(newId.contains("minecraft:"), "Unknown new material for " + matData); - Item newMaterial = BuiltInRegistries.ITEM.get(MinecraftKey.parse(newId)); + Item newMaterial = BuiltInRegistries.ITEM.getValue(MinecraftKey.parse(newId)); if (newMaterial == Items.AIR) { continue; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java b/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java index 117f72db73..f52f1f3368 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/FieldRename.java @@ -175,6 +175,8 @@ public class FieldRename { .change("SNOWMAN", "SNOW_GOLEM") .change("FISHING_HOOK", "FISHING_BOBBER") .change("LIGHTNING", "LIGHTNING_BOLT") + .change("BOAT", "OAK_BOAT") + .change("CHEST_BOAT", "OAK_CHEST_BOAT") .withKeyRename() .change("XP_ORB", "EXPERIENCE_ORB") .change("EYE_OF_ENDER_SIGNAL", "EYE_OF_ENDER") diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java b/paper-server/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java index 3c35b3f8fb..aedca773c1 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/projectiles/CraftBlockProjectileSource.java @@ -6,6 +6,7 @@ import net.minecraft.core.IPosition; import net.minecraft.core.dispenser.SourceBlock; import net.minecraft.server.level.WorldServer; import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.entity.projectile.EntityArrow; import net.minecraft.world.entity.projectile.EntityFireball; @@ -109,13 +110,13 @@ public class CraftBlockProjectileSource implements BlockProjectileSource { if (Fireball.class.isAssignableFrom(projectile)) { EntityFireball customFireball = null; if (WitherSkull.class.isAssignableFrom(projectile)) { - launch = customFireball = EntityTypes.WITHER_SKULL.create(world); + launch = customFireball = EntityTypes.WITHER_SKULL.create(world, EntitySpawnReason.TRIGGERED); } else if (DragonFireball.class.isAssignableFrom(projectile)) { - launch = EntityTypes.DRAGON_FIREBALL.create(world); + launch = EntityTypes.DRAGON_FIREBALL.create(world, EntitySpawnReason.TRIGGERED); } else if (BreezeWindCharge.class.isAssignableFrom(projectile)) { - launch = customFireball = EntityTypes.BREEZE_WIND_CHARGE.create(world); + launch = customFireball = EntityTypes.BREEZE_WIND_CHARGE.create(world, EntitySpawnReason.TRIGGERED); } else if (LargeFireball.class.isAssignableFrom(projectile)) { - launch = customFireball = EntityTypes.FIREBALL.create(world); + launch = customFireball = EntityTypes.FIREBALL.create(world, EntitySpawnReason.TRIGGERED); } if (customFireball != null) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java index d7da2a0b59..e504fbb051 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java @@ -395,8 +395,8 @@ public class CraftScheduler implements BukkitScheduler { /** * This method is designed to never block or wait for locks; an immediate execution of all current tasks. */ - public void mainThreadHeartbeat(final int currentTick) { - this.currentTick = currentTick; + public void mainThreadHeartbeat() { + this.currentTick++; final List temp = this.temp; parsePending(); while (isReady(currentTick)) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/structure/CraftPalette.java b/paper-server/src/main/java/org/bukkit/craftbukkit/structure/CraftPalette.java index 2a31247ba5..0bb840fda0 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/structure/CraftPalette.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/structure/CraftPalette.java @@ -10,10 +10,10 @@ import org.bukkit.structure.Palette; public class CraftPalette implements Palette { - private final DefinedStructure.a palette; + private final DefinedStructure.b palette; private final IRegistryCustom registry; - public CraftPalette(DefinedStructure.a palette, IRegistryCustom registry) { + public CraftPalette(DefinedStructure.b palette, IRegistryCustom registry) { this.palette = palette; this.registry = registry; } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/structure/CraftStructure.java b/paper-server/src/main/java/org/bukkit/craftbukkit/structure/CraftStructure.java index 3722459bd8..1ff90536fd 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/structure/CraftStructure.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/structure/CraftStructure.java @@ -10,6 +10,7 @@ import java.util.stream.Collectors; import net.minecraft.core.BlockPosition; import net.minecraft.core.IRegistryCustom; import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.level.ChunkCoordIntPair; import net.minecraft.world.level.GeneratorAccessSeed; @@ -133,7 +134,7 @@ public class CraftStructure implements Structure { public List getEntities() { List entities = new ArrayList<>(); for (DefinedStructure.EntityInfo entity : structure.entityInfoList) { - EntityTypes.create(entity.nbt, ((CraftWorld) Bukkit.getServer().getWorlds().get(0)).getHandle()).ifPresent(dummyEntity -> { + EntityTypes.create(entity.nbt, ((CraftWorld) Bukkit.getServer().getWorlds().get(0)).getHandle(), EntitySpawnReason.STRUCTURE).ifPresent(dummyEntity -> { dummyEntity.setPos(entity.pos.x, entity.pos.y, entity.pos.z); entities.add(dummyEntity.getBukkitEntity()); }); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftDamageTag.java b/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftDamageTag.java new file mode 100644 index 0000000000..12a2660895 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftDamageTag.java @@ -0,0 +1,26 @@ +package org.bukkit.craftbukkit.tag; + +import java.util.Set; +import java.util.stream.Collectors; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; +import net.minecraft.tags.TagKey; +import org.bukkit.craftbukkit.damage.CraftDamageType; +import org.bukkit.damage.DamageType; + +public class CraftDamageTag extends CraftTag { + + public CraftDamageTag(IRegistry registry, TagKey tag) { + super(registry, tag); + } + + @Override + public boolean isTagged(DamageType type) { + return CraftDamageType.bukkitToMinecraftHolder(type).is(tag); + } + + @Override + public Set getValues() { + return getHandle().stream().map(Holder::value).map(CraftDamageType::minecraftToBukkit).collect(Collectors.toUnmodifiableSet()); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftTag.java b/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftTag.java index e950501092..0f26ded9c1 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftTag.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/tag/CraftTag.java @@ -19,7 +19,7 @@ public abstract class CraftTag implements Tag { public CraftTag(IRegistry registry, TagKey tag) { this.registry = registry; this.tag = tag; - this.handle = registry.getTag(this.tag).orElseThrow(); + this.handle = registry.get(this.tag).orElseThrow(); } public HolderSet.Named getHandle() { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/ApiVersion.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/ApiVersion.java index e9599da68d..7f2c0bfd90 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/ApiVersion.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/ApiVersion.java @@ -16,7 +16,7 @@ public final class ApiVersion implements Comparable, Serializable { static { versions = new HashMap<>(); - CURRENT = getOrCreateVersion("1.21.1"); + CURRENT = getOrCreateVersion("1.21.2"); FLATTENING = getOrCreateVersion("1.13"); FIELD_NAME_PARITY = getOrCreateVersion("1.20.5"); NONE = getOrCreateVersion("none"); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/BlockStateListPopulator.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/BlockStateListPopulator.java index 9db620bd76..81c11159fd 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/BlockStateListPopulator.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/BlockStateListPopulator.java @@ -114,8 +114,8 @@ public class BlockStateListPopulator extends DummyGeneratorAccess { // For tree generation @Override - public int getMinBuildHeight() { - return getWorld().getMinBuildHeight(); + public int getMinY() { + return getWorld().getMinY(); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java index 0ab6b0a5fb..20cd67e13f 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -6,6 +6,7 @@ import com.google.common.collect.Multimap; import com.google.common.io.Files; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; +import com.google.gson.JsonParser; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.serialization.Dynamic; @@ -27,7 +28,6 @@ import net.minecraft.nbt.DynamicOpsNBT; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagString; import net.minecraft.resources.MinecraftKey; -import net.minecraft.server.AdvancementDataWorld; import net.minecraft.server.MinecraftServer; import net.minecraft.util.datafix.DataConverterRegistry; import net.minecraft.util.datafix.fixes.DataConverterTypes; @@ -232,7 +232,7 @@ public final class CraftMagicNumbers implements UnsafeValues { * @return string */ public String getMappingsVersion() { - return "7092ff1ff9352ad7e2260dc150e6a3ec"; + return "ec8b033a89c54252f1dfcb809eab710a"; } @Override @@ -264,7 +264,7 @@ public final class CraftMagicNumbers implements UnsafeValues { Preconditions.checkArgument(Bukkit.getAdvancement(key) == null, "Advancement %s already exists", key); MinecraftKey minecraftkey = CraftNamespacedKey.toMinecraft(key); - JsonElement jsonelement = AdvancementDataWorld.GSON.fromJson(advancement, JsonElement.class); + JsonElement jsonelement = JsonParser.parseString(advancement); net.minecraft.advancements.Advancement nms = net.minecraft.advancements.Advancement.CODEC.parse(JsonOps.INSTANCE, jsonelement).getOrThrow(JsonParseException::new); if (nms != null) { MinecraftServer.getServer().getAdvancements().advancements.put(minecraftkey, new AdvancementHolder(minecraftkey, nms)); @@ -363,7 +363,7 @@ public final class CraftMagicNumbers implements UnsafeValues { @Override public String getTranslationKey(ItemStack itemStack) { net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack); - return nmsItemStack.getItem().getDescriptionId(nmsItemStack); + return nmsItemStack.getItem().getDescriptionId(); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java index babb2abf89..cb42d26f01 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/DelegatedGeneratorAccess.java @@ -22,8 +22,6 @@ import net.minecraft.util.RandomSource; import net.minecraft.world.DifficultyDamageScaler; import net.minecraft.world.EnumDifficulty; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityLiving; -import net.minecraft.world.entity.ai.targeting.PathfinderTargetCondition; import net.minecraft.world.entity.player.EntityHuman; import net.minecraft.world.flag.FeatureFlagSet; import net.minecraft.world.level.ClipBlockStateContext; @@ -77,13 +75,13 @@ public abstract class DelegatedGeneratorAccess implements GeneratorAccessSeed { } @Override - public void setCurrentlyGenerating(Supplier arg0) { - handle.setCurrentlyGenerating(arg0); + public boolean ensureCanWrite(BlockPosition var0) { + return handle.ensureCanWrite(var0); } @Override - public boolean ensureCanWrite(BlockPosition arg0) { - return handle.ensureCanWrite(arg0); + public void setCurrentlyGenerating(Supplier var0) { + handle.setCurrentlyGenerating(var0); } @Override @@ -92,13 +90,13 @@ public abstract class DelegatedGeneratorAccess implements GeneratorAccessSeed { } @Override - public void addFreshEntityWithPassengers(Entity arg0, CreatureSpawnEvent.SpawnReason arg1) { - handle.addFreshEntityWithPassengers(arg0, arg1); + public void addFreshEntityWithPassengers(Entity entity) { + handle.addFreshEntityWithPassengers(entity); } @Override - public void addFreshEntityWithPassengers(Entity arg0) { - handle.addFreshEntityWithPassengers(arg0); + public void addFreshEntityWithPassengers(Entity entity, CreatureSpawnEvent.SpawnReason reason) { + handle.addFreshEntityWithPassengers(entity, reason); } @Override @@ -106,411 +104,184 @@ public abstract class DelegatedGeneratorAccess implements GeneratorAccessSeed { return handle.getMinecraftWorld(); } - @Override - public DifficultyDamageScaler getCurrentDifficultyAt(BlockPosition arg0) { - return handle.getCurrentDifficultyAt(arg0); - } - - @Override - public void neighborShapeChanged(EnumDirection arg0, IBlockData arg1, BlockPosition arg2, BlockPosition arg3, int arg4, int arg5) { - handle.neighborShapeChanged(arg0, arg1, arg2, arg3, arg4, arg5); - } - @Override public long dayTime() { return handle.dayTime(); } - @Override - public WorldData getLevelData() { - return handle.getLevelData(); - } - - @Override - public boolean hasChunk(int arg0, int arg1) { - return handle.hasChunk(arg0, arg1); - } - - @Override - public IChunkProvider getChunkSource() { - return handle.getChunkSource(); - } - - @Override - public void scheduleTick(BlockPosition arg0, Block arg1, int arg2, TickListPriority arg3) { - handle.scheduleTick(arg0, arg1, arg2, arg3); - } - - @Override - public void scheduleTick(BlockPosition arg0, Block arg1, int arg2) { - handle.scheduleTick(arg0, arg1, arg2); - } - - @Override - public void scheduleTick(BlockPosition arg0, FluidType arg1, int arg2, TickListPriority arg3) { - handle.scheduleTick(arg0, arg1, arg2, arg3); - } - - @Override - public void scheduleTick(BlockPosition arg0, FluidType arg1, int arg2) { - handle.scheduleTick(arg0, arg1, arg2); - } - - @Override - public EnumDifficulty getDifficulty() { - return handle.getDifficulty(); - } - - @Override - public void blockUpdated(BlockPosition arg0, Block arg1) { - handle.blockUpdated(arg0, arg1); - } - - @Override - public MinecraftServer getServer() { - return handle.getServer(); - } - - @Override - public RandomSource getRandom() { - return handle.getRandom(); - } - - @Override - public LevelTickAccess getBlockTicks() { - return handle.getBlockTicks(); - } - @Override public long nextSubTickCount() { return handle.nextSubTickCount(); } + @Override + public LevelTickAccess getBlockTicks() { + return handle.getBlockTicks(); + } + + @Override + public void scheduleTick(BlockPosition blockposition, Block block, int i, TickListPriority ticklistpriority) { + handle.scheduleTick(blockposition, block, i, ticklistpriority); + } + + @Override + public void scheduleTick(BlockPosition blockposition, Block block, int i) { + handle.scheduleTick(blockposition, block, i); + } + @Override public LevelTickAccess getFluidTicks() { return handle.getFluidTicks(); } @Override - public void playSound(EntityHuman arg0, BlockPosition arg1, SoundEffect arg2, SoundCategory arg3) { - handle.playSound(arg0, arg1, arg2, arg3); + public void scheduleTick(BlockPosition blockposition, FluidType fluidtype, int i, TickListPriority ticklistpriority) { + handle.scheduleTick(blockposition, fluidtype, i, ticklistpriority); } @Override - public void playSound(EntityHuman arg0, BlockPosition arg1, SoundEffect arg2, SoundCategory arg3, float arg4, float arg5) { - handle.playSound(arg0, arg1, arg2, arg3, arg4, arg5); + public void scheduleTick(BlockPosition blockposition, FluidType fluidtype, int i) { + handle.scheduleTick(blockposition, fluidtype, i); } @Override - public void levelEvent(int arg0, BlockPosition arg1, int arg2) { - handle.levelEvent(arg0, arg1, arg2); + public WorldData getLevelData() { + return handle.getLevelData(); } @Override - public void levelEvent(EntityHuman arg0, int arg1, BlockPosition arg2, int arg3) { - handle.levelEvent(arg0, arg1, arg2, arg3); + public DifficultyDamageScaler getCurrentDifficultyAt(BlockPosition blockposition) { + return handle.getCurrentDifficultyAt(blockposition); } @Override - public void addParticle(ParticleParam arg0, double arg1, double arg2, double arg3, double arg4, double arg5, double arg6) { - handle.addParticle(arg0, arg1, arg2, arg3, arg4, arg5, arg6); + public MinecraftServer getServer() { + return handle.getServer(); } @Override - public void gameEvent(Holder arg0, Vec3D arg1, GameEvent.a arg2) { - handle.gameEvent(arg0, arg1, arg2); + public EnumDifficulty getDifficulty() { + return handle.getDifficulty(); } @Override - public void gameEvent(Holder arg0, BlockPosition arg1, GameEvent.a arg2) { - handle.gameEvent(arg0, arg1, arg2); + public IChunkProvider getChunkSource() { + return handle.getChunkSource(); } @Override - public void gameEvent(Entity arg0, Holder arg1, BlockPosition arg2) { - handle.gameEvent(arg0, arg1, arg2); + public boolean hasChunk(int i, int j) { + return handle.hasChunk(i, j); } @Override - public void gameEvent(Entity arg0, Holder arg1, Vec3D arg2) { - handle.gameEvent(arg0, arg1, arg2); + public RandomSource getRandom() { + return handle.getRandom(); } @Override - public List getEntityCollisions(Entity arg0, AxisAlignedBB arg1) { - return handle.getEntityCollisions(arg0, arg1); + public void blockUpdated(BlockPosition blockposition, Block block) { + handle.blockUpdated(blockposition, block); } @Override - public Optional getBlockEntity(BlockPosition arg0, TileEntityTypes arg1) { - return handle.getBlockEntity(arg0, arg1); + public void neighborShapeChanged(EnumDirection enumdirection, BlockPosition blockposition, BlockPosition blockposition1, IBlockData iblockdata, int i, int j) { + handle.neighborShapeChanged(enumdirection, blockposition, blockposition1, iblockdata, i, j); } @Override - public BlockPosition getHeightmapPos(HeightMap.Type arg0, BlockPosition arg1) { - return handle.getHeightmapPos(arg0, arg1); + public void playSound(EntityHuman entityhuman, BlockPosition blockposition, SoundEffect soundeffect, SoundCategory soundcategory) { + handle.playSound(entityhuman, blockposition, soundeffect, soundcategory); } @Override - public boolean isUnobstructed(Entity arg0, VoxelShape arg1) { - return handle.isUnobstructed(arg0, arg1); + public void playSound(EntityHuman entityhuman, BlockPosition blockposition, SoundEffect soundeffect, SoundCategory soundcategory, float f, float f1) { + handle.playSound(entityhuman, blockposition, soundeffect, soundcategory, f, f1); } @Override - public boolean hasNearbyAlivePlayer(double arg0, double arg1, double arg2, double arg3) { - return handle.hasNearbyAlivePlayer(arg0, arg1, arg2, arg3); + public void addParticle(ParticleParam particleparam, double d0, double d1, double d2, double d3, double d4, double d5) { + handle.addParticle(particleparam, d0, d1, d2, d3, d4, d5); } @Override - public List players() { - return handle.players(); + public void levelEvent(EntityHuman entityhuman, int i, BlockPosition blockposition, int j) { + handle.levelEvent(entityhuman, i, blockposition, j); } @Override - public List getEntities(Entity arg0, AxisAlignedBB arg1, Predicate arg2) { - return handle.getEntities(arg0, arg1, arg2); + public void levelEvent(int i, BlockPosition blockposition, int j) { + handle.levelEvent(i, blockposition, j); } @Override - public List getEntities(EntityTypeTest arg0, AxisAlignedBB arg1, Predicate arg2) { - return handle.getEntities(arg0, arg1, arg2); + public void gameEvent(Holder holder, Vec3D vec3d, GameEvent.a gameevent_a) { + handle.gameEvent(holder, vec3d, gameevent_a); } @Override - public List getEntities(Entity arg0, AxisAlignedBB arg1) { - return handle.getEntities(arg0, arg1); + public void gameEvent(Entity entity, Holder holder, Vec3D vec3d) { + handle.gameEvent(entity, holder, vec3d); } @Override - public List getEntitiesOfClass(Class arg0, AxisAlignedBB arg1) { - return handle.getEntitiesOfClass(arg0, arg1); + public void gameEvent(Entity entity, Holder holder, BlockPosition blockposition) { + handle.gameEvent(entity, holder, blockposition); } @Override - public List getEntitiesOfClass(Class arg0, AxisAlignedBB arg1, Predicate arg2) { - return handle.getEntitiesOfClass(arg0, arg1, arg2); + public void gameEvent(Holder holder, BlockPosition blockposition, GameEvent.a gameevent_a) { + handle.gameEvent(holder, blockposition, gameevent_a); } @Override - public EntityHuman getNearestPlayer(PathfinderTargetCondition arg0, EntityLiving arg1, double arg2, double arg3, double arg4) { - return handle.getNearestPlayer(arg0, arg1, arg2, arg3, arg4); + public void gameEvent(ResourceKey resourcekey, BlockPosition blockposition, GameEvent.a gameevent_a) { + handle.gameEvent(resourcekey, blockposition, gameevent_a); } @Override - public EntityHuman getNearestPlayer(PathfinderTargetCondition arg0, double arg1, double arg2, double arg3) { - return handle.getNearestPlayer(arg0, arg1, arg2, arg3); + public Optional getBlockEntity(BlockPosition var0, TileEntityTypes var1) { + return handle.getBlockEntity(var0, var1); } @Override - public EntityHuman getNearestPlayer(Entity arg0, double arg1) { - return handle.getNearestPlayer(arg0, arg1); + public List getEntityCollisions(Entity var0, AxisAlignedBB var1) { + return handle.getEntityCollisions(var0, var1); } @Override - public EntityHuman getNearestPlayer(double arg0, double arg1, double arg2, double arg3, Predicate arg4) { - return handle.getNearestPlayer(arg0, arg1, arg2, arg3, arg4); + public boolean isUnobstructed(Entity var0, VoxelShape var1) { + return handle.isUnobstructed(var0, var1); } @Override - public EntityHuman getNearestPlayer(double arg0, double arg1, double arg2, double arg3, boolean arg4) { - return handle.getNearestPlayer(arg0, arg1, arg2, arg3, arg4); + public BlockPosition getHeightmapPos(HeightMap.Type var0, BlockPosition var1) { + return handle.getHeightmapPos(var0, var1); } @Override - public EntityHuman getNearestPlayer(PathfinderTargetCondition arg0, EntityLiving arg1) { - return handle.getNearestPlayer(arg0, arg1); + public float getMoonBrightness() { + return handle.getMoonBrightness(); } @Override - public T getNearestEntity(Class arg0, PathfinderTargetCondition arg1, EntityLiving arg2, double arg3, double arg4, double arg5, AxisAlignedBB arg6) { - return handle.getNearestEntity(arg0, arg1, arg2, arg3, arg4, arg5, arg6); + public float getTimeOfDay(float var0) { + return handle.getTimeOfDay(var0); } @Override - public T getNearestEntity(List arg0, PathfinderTargetCondition arg1, EntityLiving arg2, double arg3, double arg4, double arg5) { - return handle.getNearestEntity(arg0, arg1, arg2, arg3, arg4, arg5); + public int getMoonPhase() { + return handle.getMoonPhase(); } @Override - public EntityHuman getPlayerByUUID(UUID arg0) { - return handle.getPlayerByUUID(arg0); + public IChunkAccess getChunk(int i, int i1, ChunkStatus cs, boolean bln) { + return handle.getChunk(i, i1, cs, bln); } @Override - public List getNearbyPlayers(PathfinderTargetCondition arg0, EntityLiving arg1, AxisAlignedBB arg2) { - return handle.getNearbyPlayers(arg0, arg1, arg2); - } - - @Override - public List getNearbyEntities(Class arg0, PathfinderTargetCondition arg1, EntityLiving arg2, AxisAlignedBB arg3) { - return handle.getNearbyEntities(arg0, arg1, arg2, arg3); - } - - @Override - @Deprecated - public float getLightLevelDependentMagicValue(BlockPosition arg0) { - return handle.getLightLevelDependentMagicValue(arg0); - } - - @Override - public IBlockAccess getChunkForCollisions(int arg0, int arg1) { - return handle.getChunkForCollisions(arg0, arg1); - } - - @Override - public int getMaxLocalRawBrightness(BlockPosition arg0) { - return handle.getMaxLocalRawBrightness(arg0); - } - - @Override - public int getMaxLocalRawBrightness(BlockPosition arg0, int arg1) { - return handle.getMaxLocalRawBrightness(arg0, arg1); - } - - @Override - public boolean canSeeSkyFromBelowWater(BlockPosition arg0) { - return handle.canSeeSkyFromBelowWater(arg0); - } - - @Override - public float getPathfindingCostFromLightLevels(BlockPosition arg0) { - return handle.getPathfindingCostFromLightLevels(arg0); - } - - @Override - public Stream getBlockStatesIfLoaded(AxisAlignedBB arg0) { - return handle.getBlockStatesIfLoaded(arg0); - } - - @Override - public Holder getUncachedNoiseBiome(int arg0, int arg1, int arg2) { - return handle.getUncachedNoiseBiome(arg0, arg1, arg2); - } - - @Override - @Deprecated - public int getSeaLevel() { - return handle.getSeaLevel(); - } - - @Override - public boolean containsAnyLiquid(AxisAlignedBB arg0) { - return handle.containsAnyLiquid(arg0); - } - - @Override - public int getMinBuildHeight() { - return handle.getMinBuildHeight(); - } - - @Override - public boolean isWaterAt(BlockPosition arg0) { - return handle.isWaterAt(arg0); - } - - @Override - public boolean isEmptyBlock(BlockPosition arg0) { - return handle.isEmptyBlock(arg0); - } - - @Override - public boolean isClientSide() { - return handle.isClientSide(); - } - - @Override - public DimensionManager dimensionType() { - return handle.dimensionType(); - } - - @Override - public FeatureFlagSet enabledFeatures() { - return handle.enabledFeatures(); - } - - @Override - @Deprecated - public boolean hasChunkAt(int arg0, int arg1) { - return handle.hasChunkAt(arg0, arg1); - } - - @Override - @Deprecated - public boolean hasChunkAt(BlockPosition arg0) { - return handle.hasChunkAt(arg0); - } - - @Override - public HolderLookup holderLookup(ResourceKey> arg0) { - return handle.holderLookup(arg0); - } - - @Override - public IRegistryCustom registryAccess() { - return handle.registryAccess(); - } - - @Override - public Holder getNoiseBiome(int arg0, int arg1, int arg2) { - return handle.getNoiseBiome(arg0, arg1, arg2); - } - - @Override - public int getBlockTint(BlockPosition arg0, ColorResolver arg1) { - return handle.getBlockTint(arg0, arg1); - } - - @Override - @Deprecated - public boolean hasChunksAt(BlockPosition arg0, BlockPosition arg1) { - return handle.hasChunksAt(arg0, arg1); - } - - @Override - @Deprecated - public boolean hasChunksAt(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5) { - return handle.hasChunksAt(arg0, arg1, arg2, arg3, arg4, arg5); - } - - @Override - @Deprecated - public boolean hasChunksAt(int arg0, int arg1, int arg2, int arg3) { - return handle.hasChunksAt(arg0, arg1, arg2, arg3); - } - - @Override - public IChunkAccess getChunk(int arg0, int arg1, ChunkStatus arg2, boolean arg3) { - return handle.getChunk(arg0, arg1, arg2, arg3); - } - - @Override - public IChunkAccess getChunk(int arg0, int arg1, ChunkStatus arg2) { - return handle.getChunk(arg0, arg1, arg2); - } - - @Override - public IChunkAccess getChunk(BlockPosition arg0) { - return handle.getChunk(arg0); - } - - @Override - public IChunkAccess getChunk(int arg0, int arg1) { - return handle.getChunk(arg0, arg1); - } - - @Override - public int getHeight(HeightMap.Type arg0, int arg1, int arg2) { - return handle.getHeight(arg0, arg1, arg2); - } - - @Override - public int getHeight() { - return handle.getHeight(); - } - - @Override - public Holder getBiome(BlockPosition arg0) { - return handle.getBiome(arg0); + public int getHeight(HeightMap.Type type, int i, int i1) { + return handle.getHeight(type, i, i1); } @Override @@ -524,13 +295,158 @@ public abstract class DelegatedGeneratorAccess implements GeneratorAccessSeed { } @Override - public boolean canSeeSky(BlockPosition arg0) { - return handle.canSeeSky(arg0); + public Holder getBiome(BlockPosition var0) { + return handle.getBiome(var0); } @Override - public int getRawBrightness(BlockPosition arg0, int arg1) { - return handle.getRawBrightness(arg0, arg1); + public Stream getBlockStatesIfLoaded(AxisAlignedBB var0) { + return handle.getBlockStatesIfLoaded(var0); + } + + @Override + public int getBlockTint(BlockPosition var0, ColorResolver var1) { + return handle.getBlockTint(var0, var1); + } + + @Override + public Holder getNoiseBiome(int var0, int var1, int var2) { + return handle.getNoiseBiome(var0, var1, var2); + } + + @Override + public Holder getUncachedNoiseBiome(int i, int i1, int i2) { + return handle.getUncachedNoiseBiome(i, i1, i2); + } + + @Override + public boolean isClientSide() { + return handle.isClientSide(); + } + + @Override + public int getSeaLevel() { + return handle.getSeaLevel(); + } + + @Override + public DimensionManager dimensionType() { + return handle.dimensionType(); + } + + @Override + public int getMinY() { + return handle.getMinY(); + } + + @Override + public int getHeight() { + return handle.getHeight(); + } + + @Override + public boolean isEmptyBlock(BlockPosition var0) { + return handle.isEmptyBlock(var0); + } + + @Override + public boolean canSeeSkyFromBelowWater(BlockPosition var0) { + return handle.canSeeSkyFromBelowWater(var0); + } + + @Override + public float getPathfindingCostFromLightLevels(BlockPosition var0) { + return handle.getPathfindingCostFromLightLevels(var0); + } + + @Override + public float getLightLevelDependentMagicValue(BlockPosition var0) { + return handle.getLightLevelDependentMagicValue(var0); + } + + @Override + public IChunkAccess getChunk(BlockPosition var0) { + return handle.getChunk(var0); + } + + @Override + public IChunkAccess getChunk(int var0, int var1) { + return handle.getChunk(var0, var1); + } + + @Override + public IChunkAccess getChunk(int var0, int var1, ChunkStatus var2) { + return handle.getChunk(var0, var1, var2); + } + + @Override + public IBlockAccess getChunkForCollisions(int var0, int var1) { + return handle.getChunkForCollisions(var0, var1); + } + + @Override + public boolean isWaterAt(BlockPosition var0) { + return handle.isWaterAt(var0); + } + + @Override + public boolean containsAnyLiquid(AxisAlignedBB var0) { + return handle.containsAnyLiquid(var0); + } + + @Override + public int getMaxLocalRawBrightness(BlockPosition var0) { + return handle.getMaxLocalRawBrightness(var0); + } + + @Override + public int getMaxLocalRawBrightness(BlockPosition var0, int var1) { + return handle.getMaxLocalRawBrightness(var0, var1); + } + + @Override + public boolean hasChunkAt(int var0, int var1) { + return handle.hasChunkAt(var0, var1); + } + + @Override + public boolean hasChunkAt(BlockPosition var0) { + return handle.hasChunkAt(var0); + } + + @Override + public boolean hasChunksAt(BlockPosition var0, BlockPosition var1) { + return handle.hasChunksAt(var0, var1); + } + + @Override + public boolean hasChunksAt(int var0, int var1, int var2, int var3, int var4, int var5) { + return handle.hasChunksAt(var0, var1, var2, var3, var4, var5); + } + + @Override + public boolean hasChunksAt(int var0, int var1, int var2, int var3) { + return handle.hasChunksAt(var0, var1, var2, var3); + } + + @Override + public IRegistryCustom registryAccess() { + return handle.registryAccess(); + } + + @Override + public FeatureFlagSet enabledFeatures() { + return handle.enabledFeatures(); + } + + @Override + public HolderLookup holderLookup(ResourceKey> var0) { + return handle.holderLookup(var0); + } + + @Override + public float getShade(EnumDirection ed, boolean bln) { + return handle.getShade(ed, bln); } @Override @@ -539,128 +455,18 @@ public abstract class DelegatedGeneratorAccess implements GeneratorAccessSeed { } @Override - public int getBrightness(EnumSkyBlock arg0, BlockPosition arg1) { - return handle.getBrightness(arg0, arg1); + public int getBrightness(EnumSkyBlock var0, BlockPosition var1) { + return handle.getBrightness(var0, var1); } @Override - public float getShade(EnumDirection arg0, boolean arg1) { - return handle.getShade(arg0, arg1); + public int getRawBrightness(BlockPosition var0, int var1) { + return handle.getRawBrightness(var0, var1); } @Override - public TileEntity getBlockEntity(BlockPosition arg0) { - return handle.getBlockEntity(arg0); - } - - @Override - public double getBlockFloorHeight(VoxelShape arg0, Supplier arg1) { - return handle.getBlockFloorHeight(arg0, arg1); - } - - @Override - public double getBlockFloorHeight(BlockPosition arg0) { - return handle.getBlockFloorHeight(arg0); - } - - @Override - public MovingObjectPositionBlock clipWithInteractionOverride(Vec3D arg0, Vec3D arg1, BlockPosition arg2, VoxelShape arg3, IBlockData arg4) { - return handle.clipWithInteractionOverride(arg0, arg1, arg2, arg3, arg4); - } - - @Override - public IBlockData getBlockState(BlockPosition arg0) { - return handle.getBlockState(arg0); - } - - @Override - public Fluid getFluidState(BlockPosition arg0) { - return handle.getFluidState(arg0); - } - - @Override - public int getLightEmission(BlockPosition arg0) { - return handle.getLightEmission(arg0); - } - - @Override - public MovingObjectPositionBlock clip(RayTrace arg0) { - return handle.clip(arg0); - } - - @Override - public MovingObjectPositionBlock clip(RayTrace arg0, BlockPosition arg1) { - return handle.clip(arg0, arg1); - } - - @Override - public int getMaxLightLevel() { - return handle.getMaxLightLevel(); - } - - @Override - public MovingObjectPositionBlock isBlockInLine(ClipBlockStateContext arg0) { - return handle.isBlockInLine(arg0); - } - - @Override - public Stream getBlockStates(AxisAlignedBB arg0) { - return handle.getBlockStates(arg0); - } - - @Override - public boolean isOutsideBuildHeight(int arg0) { - return handle.isOutsideBuildHeight(arg0); - } - - @Override - public boolean isOutsideBuildHeight(BlockPosition arg0) { - return handle.isOutsideBuildHeight(arg0); - } - - @Override - public int getSectionIndexFromSectionY(int arg0) { - return handle.getSectionIndexFromSectionY(arg0); - } - - @Override - public int getSectionYFromSectionIndex(int arg0) { - return handle.getSectionYFromSectionIndex(arg0); - } - - @Override - public int getMaxSection() { - return handle.getMaxSection(); - } - - @Override - public int getMinSection() { - return handle.getMinSection(); - } - - @Override - public int getSectionIndex(int arg0) { - return handle.getSectionIndex(arg0); - } - - @Override - public int getSectionsCount() { - return handle.getSectionsCount(); - } - - @Override - public int getMaxBuildHeight() { - return handle.getMaxBuildHeight(); - } - - @Override - public boolean isUnobstructed(IBlockData arg0, BlockPosition arg1, VoxelShapeCollision arg2) { - return handle.isUnobstructed(arg0, arg1, arg2); - } - - @Override - public boolean isUnobstructed(Entity arg0) { - return handle.isUnobstructed(arg0); + public boolean canSeeSky(BlockPosition var0) { + return handle.canSeeSky(var0); } @Override @@ -669,142 +475,317 @@ public abstract class DelegatedGeneratorAccess implements GeneratorAccessSeed { } @Override - public Optional findFreePosition(Entity arg0, VoxelShape arg1, Vec3D arg2, double arg3, double arg4, double arg5) { - return handle.findFreePosition(arg0, arg1, arg2, arg3, arg4, arg5); + public boolean isUnobstructed(IBlockData var0, BlockPosition var1, VoxelShapeCollision var2) { + return handle.isUnobstructed(var0, var1, var2); } @Override - public Iterable getCollisions(Entity arg0, AxisAlignedBB arg1) { - return handle.getCollisions(arg0, arg1); + public boolean isUnobstructed(Entity var0) { + return handle.isUnobstructed(var0); } @Override - public Iterable getBlockCollisions(Entity arg0, AxisAlignedBB arg1) { - return handle.getBlockCollisions(arg0, arg1); + public boolean noCollision(AxisAlignedBB var0) { + return handle.noCollision(var0); } @Override - public boolean noCollision(AxisAlignedBB arg0) { - return handle.noCollision(arg0); + public boolean noCollision(Entity var0) { + return handle.noCollision(var0); } @Override - public boolean noCollision(Entity arg0) { - return handle.noCollision(arg0); + public boolean noCollision(Entity var0, AxisAlignedBB var1) { + return handle.noCollision(var0, var1); } @Override - public boolean noCollision(Entity arg0, AxisAlignedBB arg1) { - return handle.noCollision(arg0, arg1); + public boolean noCollision(Entity var0, AxisAlignedBB var1, boolean var2) { + return handle.noCollision(var0, var1, var2); } @Override - public boolean collidesWithSuffocatingBlock(Entity arg0, AxisAlignedBB arg1) { - return handle.collidesWithSuffocatingBlock(arg0, arg1); + public boolean noBlockCollision(Entity var0, AxisAlignedBB var1) { + return handle.noBlockCollision(var0, var1); } @Override - public Optional findSupportingBlock(Entity arg0, AxisAlignedBB arg1) { - return handle.findSupportingBlock(arg0, arg1); + public Iterable getCollisions(Entity var0, AxisAlignedBB var1) { + return handle.getCollisions(var0, var1); } @Override - public int getBestNeighborSignal(BlockPosition arg0) { - return handle.getBestNeighborSignal(arg0); + public Iterable getBlockCollisions(Entity var0, AxisAlignedBB var1) { + return handle.getBlockCollisions(var0, var1); } @Override - public int getControlInputSignal(BlockPosition arg0, EnumDirection arg1, boolean arg2) { - return handle.getControlInputSignal(arg0, arg1, arg2); + public Iterable getBlockAndLiquidCollisions(Entity var0, AxisAlignedBB var1) { + return handle.getBlockAndLiquidCollisions(var0, var1); } @Override - public int getDirectSignal(BlockPosition arg0, EnumDirection arg1) { - return handle.getDirectSignal(arg0, arg1); + public MovingObjectPositionBlock clipIncludingBorder(RayTrace var0) { + return handle.clipIncludingBorder(var0); } @Override - public int getDirectSignalTo(BlockPosition arg0) { - return handle.getDirectSignalTo(arg0); + public boolean collidesWithSuffocatingBlock(Entity var0, AxisAlignedBB var1) { + return handle.collidesWithSuffocatingBlock(var0, var1); } @Override - public boolean hasNeighborSignal(BlockPosition arg0) { - return handle.hasNeighborSignal(arg0); + public Optional findSupportingBlock(Entity var0, AxisAlignedBB var1) { + return handle.findSupportingBlock(var0, var1); } @Override - public boolean hasSignal(BlockPosition arg0, EnumDirection arg1) { - return handle.hasSignal(arg0, arg1); + public Optional findFreePosition(Entity var0, VoxelShape var1, Vec3D var2, double var3, double var5, double var7) { + return handle.findFreePosition(var0, var1, var2, var3, var5, var7); } @Override - public int getSignal(BlockPosition arg0, EnumDirection arg1) { - return handle.getSignal(arg0, arg1); + public int getDirectSignal(BlockPosition var0, EnumDirection var1) { + return handle.getDirectSignal(var0, var1); } @Override - public boolean isStateAtPosition(BlockPosition arg0, Predicate arg1) { - return handle.isStateAtPosition(arg0, arg1); + public int getDirectSignalTo(BlockPosition var0) { + return handle.getDirectSignalTo(var0); } @Override - public boolean isFluidAtPosition(BlockPosition arg0, Predicate arg1) { - return handle.isFluidAtPosition(arg0, arg1); + public int getControlInputSignal(BlockPosition var0, EnumDirection var1, boolean var2) { + return handle.getControlInputSignal(var0, var1, var2); } @Override - public boolean addFreshEntity(Entity arg0, CreatureSpawnEvent.SpawnReason arg1) { - return handle.addFreshEntity(arg0, arg1); + public boolean hasSignal(BlockPosition var0, EnumDirection var1) { + return handle.hasSignal(var0, var1); } @Override - public boolean addFreshEntity(Entity arg0) { - return handle.addFreshEntity(arg0); + public int getSignal(BlockPosition var0, EnumDirection var1) { + return handle.getSignal(var0, var1); } @Override - public boolean removeBlock(BlockPosition arg0, boolean arg1) { - return handle.removeBlock(arg0, arg1); + public boolean hasNeighborSignal(BlockPosition var0) { + return handle.hasNeighborSignal(var0); } @Override - public boolean destroyBlock(BlockPosition arg0, boolean arg1, Entity arg2, int arg3) { - return handle.destroyBlock(arg0, arg1, arg2, arg3); + public int getBestNeighborSignal(BlockPosition var0) { + return handle.getBestNeighborSignal(var0); } @Override - public boolean destroyBlock(BlockPosition arg0, boolean arg1, Entity arg2) { - return handle.destroyBlock(arg0, arg1, arg2); + public TileEntity getBlockEntity(BlockPosition blockposition) { + return handle.getBlockEntity(blockposition); } @Override - public boolean destroyBlock(BlockPosition arg0, boolean arg1) { - return handle.destroyBlock(arg0, arg1); + public IBlockData getBlockState(BlockPosition blockposition) { + return handle.getBlockState(blockposition); } @Override - public boolean setBlock(BlockPosition arg0, IBlockData arg1, int arg2) { - return handle.setBlock(arg0, arg1, arg2); + public Fluid getFluidState(BlockPosition blockposition) { + return handle.getFluidState(blockposition); } @Override - public boolean setBlock(BlockPosition arg0, IBlockData arg1, int arg2, int arg3) { - return handle.setBlock(arg0, arg1, arg2, arg3); + public int getLightEmission(BlockPosition blockposition) { + return handle.getLightEmission(blockposition); } @Override - public float getTimeOfDay(float arg0) { - return handle.getTimeOfDay(arg0); + public Stream getBlockStates(AxisAlignedBB axisalignedbb) { + return handle.getBlockStates(axisalignedbb); } @Override - public float getMoonBrightness() { - return handle.getMoonBrightness(); + public MovingObjectPositionBlock isBlockInLine(ClipBlockStateContext clipblockstatecontext) { + return handle.isBlockInLine(clipblockstatecontext); } @Override - public int getMoonPhase() { - return handle.getMoonPhase(); + public MovingObjectPositionBlock clip(RayTrace raytrace1, BlockPosition blockposition) { + return handle.clip(raytrace1, blockposition); + } + + @Override + public MovingObjectPositionBlock clip(RayTrace raytrace) { + return handle.clip(raytrace); + } + + @Override + public MovingObjectPositionBlock clipWithInteractionOverride(Vec3D vec3d, Vec3D vec3d1, BlockPosition blockposition, VoxelShape voxelshape, IBlockData iblockdata) { + return handle.clipWithInteractionOverride(vec3d, vec3d1, blockposition, voxelshape, iblockdata); + } + + @Override + public double getBlockFloorHeight(VoxelShape voxelshape, Supplier supplier) { + return handle.getBlockFloorHeight(voxelshape, supplier); + } + + @Override + public double getBlockFloorHeight(BlockPosition blockposition) { + return handle.getBlockFloorHeight(blockposition); + } + + @Override + public List getEntities(Entity entity, AxisAlignedBB aabb, Predicate prdct) { + return handle.getEntities(entity, aabb, prdct); + } + + @Override + public List getEntities(EntityTypeTest ett, AxisAlignedBB aabb, Predicate prdct) { + return handle.getEntities(ett, aabb, prdct); + } + + @Override + public List getEntitiesOfClass(Class var0, AxisAlignedBB var1, Predicate var2) { + return handle.getEntitiesOfClass(var0, var1, var2); + } + + @Override + public List players() { + return handle.players(); + } + + @Override + public List getEntities(Entity var0, AxisAlignedBB var1) { + return handle.getEntities(var0, var1); + } + + @Override + public List getEntitiesOfClass(Class var0, AxisAlignedBB var1) { + return handle.getEntitiesOfClass(var0, var1); + } + + @Override + public EntityHuman getNearestPlayer(double var0, double var2, double var4, double var6, Predicate var8) { + return handle.getNearestPlayer(var0, var2, var4, var6, var8); + } + + @Override + public EntityHuman getNearestPlayer(Entity var0, double var1) { + return handle.getNearestPlayer(var0, var1); + } + + @Override + public EntityHuman getNearestPlayer(double var0, double var2, double var4, double var6, boolean var8) { + return handle.getNearestPlayer(var0, var2, var4, var6, var8); + } + + @Override + public boolean hasNearbyAlivePlayer(double var0, double var2, double var4, double var6) { + return handle.hasNearbyAlivePlayer(var0, var2, var4, var6); + } + + @Override + public EntityHuman getPlayerByUUID(UUID var0) { + return handle.getPlayerByUUID(var0); + } + + @Override + public boolean setBlock(BlockPosition blockposition, IBlockData iblockdata, int i, int j) { + return handle.setBlock(blockposition, iblockdata, i, j); + } + + @Override + public boolean setBlock(BlockPosition blockposition, IBlockData iblockdata, int i) { + return handle.setBlock(blockposition, iblockdata, i); + } + + @Override + public boolean removeBlock(BlockPosition blockposition, boolean flag) { + return handle.removeBlock(blockposition, flag); + } + + @Override + public boolean destroyBlock(BlockPosition blockposition, boolean flag) { + return handle.destroyBlock(blockposition, flag); + } + + @Override + public boolean destroyBlock(BlockPosition blockposition, boolean flag, Entity entity) { + return handle.destroyBlock(blockposition, flag, entity); + } + + @Override + public boolean destroyBlock(BlockPosition blockposition, boolean flag, Entity entity, int i) { + return handle.destroyBlock(blockposition, flag, entity, i); + } + + @Override + public boolean addFreshEntity(Entity entity) { + return handle.addFreshEntity(entity); + } + + @Override + public boolean addFreshEntity(Entity entity, CreatureSpawnEvent.SpawnReason reason) { + return handle.addFreshEntity(entity, reason); + } + + @Override + public int getMaxY() { + return handle.getMaxY(); + } + + @Override + public int getSectionsCount() { + return handle.getSectionsCount(); + } + + @Override + public int getMinSectionY() { + return handle.getMinSectionY(); + } + + @Override + public int getMaxSectionY() { + return handle.getMaxSectionY(); + } + + @Override + public boolean isInsideBuildHeight(int var0) { + return handle.isInsideBuildHeight(var0); + } + + @Override + public boolean isOutsideBuildHeight(BlockPosition var0) { + return handle.isOutsideBuildHeight(var0); + } + + @Override + public boolean isOutsideBuildHeight(int var0) { + return handle.isOutsideBuildHeight(var0); + } + + @Override + public int getSectionIndex(int var0) { + return handle.getSectionIndex(var0); + } + + @Override + public int getSectionIndexFromSectionY(int var0) { + return handle.getSectionIndexFromSectionY(var0); + } + + @Override + public int getSectionYFromSectionIndex(int var0) { + return handle.getSectionYFromSectionIndex(var0); + } + + @Override + public boolean isStateAtPosition(BlockPosition bp, Predicate prdct) { + return handle.isStateAtPosition(bp, prdct); + } + + @Override + public boolean isFluidAtPosition(BlockPosition bp, Predicate prdct) { + return handle.isFluidAtPosition(bp, prdct); } } diff --git a/paper-server/src/test/java/org/bukkit/ArtTest.java b/paper-server/src/test/java/org/bukkit/ArtTest.java index def9e87877..1c4469f2d1 100644 --- a/paper-server/src/test/java/org/bukkit/ArtTest.java +++ b/paper-server/src/test/java/org/bukkit/ArtTest.java @@ -26,7 +26,7 @@ public class ArtTest { List arts = Lists.newArrayList(Art.values()); for (ResourceKey key : CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT).registryKeySet()) { - Holder enumArt = CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT).getHolderOrThrow(key); + Holder enumArt = CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT).getOrThrow(key); String name = key.location().getPath(); int width = enumArt.value().width(); int height = enumArt.value().height(); diff --git a/paper-server/src/test/java/org/bukkit/EnchantmentTest.java b/paper-server/src/test/java/org/bukkit/EnchantmentTest.java index 9a194613f8..255ebdcb56 100644 --- a/paper-server/src/test/java/org/bukkit/EnchantmentTest.java +++ b/paper-server/src/test/java/org/bukkit/EnchantmentTest.java @@ -15,7 +15,7 @@ public class EnchantmentTest { @Test public void verifyMapping() { for (MinecraftKey key : CraftRegistry.getMinecraftRegistry(Registries.ENCHANTMENT).keySet()) { - net.minecraft.world.item.enchantment.Enchantment nms = CraftRegistry.getMinecraftRegistry(Registries.ENCHANTMENT).get(key); + net.minecraft.world.item.enchantment.Enchantment nms = CraftRegistry.getMinecraftRegistry(Registries.ENCHANTMENT).getValue(key); Enchantment bukkitById = Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(key)); diff --git a/paper-server/src/test/java/org/bukkit/GameRuleTest.java b/paper-server/src/test/java/org/bukkit/GameRuleTest.java index e446b82ad1..d0aac851c4 100644 --- a/paper-server/src/test/java/org/bukkit/GameRuleTest.java +++ b/paper-server/src/test/java/org/bukkit/GameRuleTest.java @@ -2,6 +2,7 @@ package org.bukkit; import static org.junit.jupiter.api.Assertions.*; import java.util.Map; +import net.minecraft.world.flag.FeatureFlags; import net.minecraft.world.level.GameRules; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.support.environment.Normal; @@ -23,7 +24,7 @@ public class GameRuleTest { @Test public void testMinecraftRules() { - Map> minecraftRules = CraftWorld.getGameRulesNMS(); + Map> minecraftRules = CraftWorld.getGameRulesNMS(new GameRules(FeatureFlags.REGISTRY.allFlags())); for (Map.Entry> entry : minecraftRules.entrySet()) { GameRule bukkitRule = GameRule.getByName(entry.getKey()); diff --git a/paper-server/src/test/java/org/bukkit/ParticleTest.java b/paper-server/src/test/java/org/bukkit/ParticleTest.java index fcf2a64724..598fd3ffe8 100644 --- a/paper-server/src/test/java/org/bukkit/ParticleTest.java +++ b/paper-server/src/test/java/org/bukkit/ParticleTest.java @@ -13,6 +13,7 @@ import net.minecraft.core.particles.ParticleParamRedstone; import net.minecraft.core.particles.ParticleType; import net.minecraft.core.particles.SculkChargeParticleOptions; import net.minecraft.core.particles.ShriekParticleOption; +import net.minecraft.core.particles.TargetColorParticleOption; import net.minecraft.core.particles.VibrationParticleOption; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.DynamicOpsNBT; @@ -112,6 +113,11 @@ public class ParticleTest { return; } + if (bukkit.getDataType().equals(Particle.TargetColor.class)) { + testTargetColor(bukkit, minecraft); + return; + } + fail(String.format(""" No test found for particle %s. Please add a test case for it here. @@ -242,6 +248,28 @@ public class ParticleTest { """, bukkit.getKey(), expected, actual)); // Print expected and got since we use assert true } + private void testTargetColor(Particle bukkit, net.minecraft.core.particles.Particle minecraft) { + Color color = Color.fromRGB(236, 28, 36); + Particle.TargetColor targetColor = new Particle.TargetColor(new Location(null, 1, 5, 9), color); + + TargetColorParticleOption param = createAndTest(bukkit, minecraft, targetColor, TargetColorParticleOption.class); + + Vec3D pos = param.target(); + assertEquals(new Vec3D(1.0, 5.0, 9.0), pos, String.format(""" + Vibration position for particle %s do not match. + Did something change in the implementation or minecraft? + """, bukkit.getKey())); + + int actual = param.color(); + int expected = color.asRGB(); + assertEquals(expected, actual, String.format(""" + Color for particle %s do not match. + Did something change in the implementation or minecraft? + Expected: %s. + Got: %s. + """, bukkit.getKey(), expected, actual)); // Print expected and got since we use assert true + } + private D createAndTest(Particle bukkit, net.minecraft.core.particles.Particle minecraft, Object data, Class paramClass) { @SuppressWarnings("unchecked") T particleParam = (T) assertDoesNotThrow(() -> CraftParticle.createParticleParam(bukkit, data), String.format(""" diff --git a/paper-server/src/test/java/org/bukkit/PerMaterialTest.java b/paper-server/src/test/java/org/bukkit/PerMaterialTest.java index 61d910eff4..aedd828bab 100644 --- a/paper-server/src/test/java/org/bukkit/PerMaterialTest.java +++ b/paper-server/src/test/java/org/bukkit/PerMaterialTest.java @@ -9,14 +9,13 @@ import net.minecraft.core.component.DataComponents; import net.minecraft.world.EnumHand; import net.minecraft.world.entity.EnumItemSlot; import net.minecraft.world.entity.player.EntityHuman; -import net.minecraft.world.item.Equipable; import net.minecraft.world.item.Item; +import net.minecraft.world.item.equipment.Equippable; import net.minecraft.world.level.BlockAccessAir; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.BlockFire; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Fallable; -import net.minecraft.world.level.block.entity.TileEntityFurnace; import net.minecraft.world.level.block.state.BlockBase; import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.phys.MovingObjectPositionBlock; @@ -149,16 +148,6 @@ public class PerMaterialTest { } } - @ParameterizedTest - @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) - public void isFuel(Material material) { - if (material.isItem()) { - assertThat(material.isFuel(), is(TileEntityFurnace.isFuel(new net.minecraft.world.item.ItemStack(CraftMagicNumbers.getItem(material))))); - } else { - assertFalse(material.isFuel()); - } - } - @ParameterizedTest @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) public void isOccluding(Material material) { @@ -299,8 +288,8 @@ public class PerMaterialTest { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) public void testCraftingRemainingItem(Material material) { if (material.isItem()) { - Item expectedItem = CraftMagicNumbers.getItem(material).getCraftingRemainingItem(); - Material expected = expectedItem == null ? null : CraftMagicNumbers.getMaterial(expectedItem); + net.minecraft.world.item.ItemStack expectedItem = CraftMagicNumbers.getItem(material).getCraftingRemainder(); + Material expected = expectedItem.isEmpty() ? null : CraftMagicNumbers.getMaterial(expectedItem.getItem()); assertThat(material.getCraftingRemainingItem(), is(expected)); } @@ -310,8 +299,8 @@ public class PerMaterialTest { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) public void testEquipmentSlot(Material material) { if (material.isItem()) { - Equipable equipable = Equipable.get(CraftItemStack.asNMSCopy(new ItemStack(material))); - EquipmentSlot expected = CraftEquipmentSlot.getSlot(equipable != null ? equipable.getEquipmentSlot() : EnumItemSlot.MAINHAND); + Equippable equipable = CraftItemStack.asNMSCopy(new ItemStack(material)).get(DataComponents.EQUIPPABLE); + EquipmentSlot expected = CraftEquipmentSlot.getSlot(equipable != null ? equipable.slot() : EnumItemSlot.MAINHAND); assertThat(material.getEquipmentSlot(), is(expected)); } } diff --git a/paper-server/src/test/java/org/bukkit/block/banner/PatternTypeTest.java b/paper-server/src/test/java/org/bukkit/block/banner/PatternTypeTest.java index a3db73fad1..a11708a899 100644 --- a/paper-server/src/test/java/org/bukkit/block/banner/PatternTypeTest.java +++ b/paper-server/src/test/java/org/bukkit/block/banner/PatternTypeTest.java @@ -16,7 +16,7 @@ public class PatternTypeTest { @Test public void testToBukkit() { - for (EnumBannerPatternType nms : MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.BANNER_PATTERN)) { + for (EnumBannerPatternType nms : MinecraftServer.getDefaultRegistryAccess().lookupOrThrow(Registries.BANNER_PATTERN)) { PatternType bukkit = Registry.BANNER_PATTERN.get(CraftNamespacedKey.fromMinecraft(nms.assetId())); assertNotNull(bukkit, "No Bukkit banner pattern for " + nms + " " + nms); @@ -25,7 +25,7 @@ public class PatternTypeTest { @Test public void testToNMS() { - IRegistry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.BANNER_PATTERN); + IRegistry registry = MinecraftServer.getDefaultRegistryAccess().lookupOrThrow(Registries.BANNER_PATTERN); for (PatternType bukkit : PatternType.values()) { EnumBannerPatternType found = null; for (EnumBannerPatternType nms : registry) { diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/entity/EntityTypesTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/entity/EntityTypesTest.java index 0c3fae8354..adc50ef382 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/entity/EntityTypesTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/entity/EntityTypesTest.java @@ -18,8 +18,10 @@ import org.bukkit.entity.AbstractWindCharge; import org.bukkit.entity.Ageable; import org.bukkit.entity.Ambient; import org.bukkit.entity.Animals; +import org.bukkit.entity.Boat; import org.bukkit.entity.Boss; import org.bukkit.entity.Breedable; +import org.bukkit.entity.ChestBoat; import org.bukkit.entity.ChestedHorse; import org.bukkit.entity.ComplexEntityPart; import org.bukkit.entity.ComplexLivingEntity; @@ -78,8 +80,10 @@ public class EntityTypesTest { Ageable.class, Ambient.class, Animals.class, - Breedable.class, + Boat.class, Boss.class, + Breedable.class, + ChestBoat.class, ChestedHorse.class, ComplexEntityPart.class, ComplexLivingEntity.class, diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/legacy/LegacyTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/legacy/LegacyTest.java index 15d30e4104..fc1db8b369 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/legacy/LegacyTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/legacy/LegacyTest.java @@ -126,6 +126,12 @@ public class LegacyTest { Material.FLOW_ARMOR_TRIM_SMITHING_TEMPLATE, Material.BOLT_ARMOR_TRIM_SMITHING_TEMPLATE, Material.FLOW_POTTERY_SHERD, Material.GUSTER_POTTERY_SHERD, Material.SCRAPE_POTTERY_SHERD, Material.BREEZE_ROD, Material.OMINOUS_TRIAL_KEY, Material.OMINOUS_BOTTLE, // 1.21 Material.MUSIC_DISC_CREATOR, Material.MUSIC_DISC_CREATOR_MUSIC_BOX, Material.MUSIC_DISC_PRECIPICE, + // 1.21.2 + Material.FIELD_MASONED_BANNER_PATTERN, Material.BORDURE_INDENTED_BANNER_PATTERN, Material.WHITE_BUNDLE, Material.ORANGE_BUNDLE, Material.MAGENTA_BUNDLE, Material.LIGHT_BLUE_BUNDLE, Material.YELLOW_BUNDLE, Material.LIME_BUNDLE, Material.PINK_BUNDLE, + Material.GRAY_BUNDLE, Material.LIGHT_GRAY_BUNDLE, Material.CYAN_BUNDLE, Material.PURPLE_BUNDLE, Material.BLUE_BUNDLE, Material.BROWN_BUNDLE, Material.GREEN_BUNDLE, Material.RED_BUNDLE, Material.BLACK_BUNDLE, Material.CREAKING_HEART, + Material.CREAKING_SPAWN_EGG, Material.PALE_HANGING_MOSS, Material.PALE_MOSS_BLOCK, Material.PALE_MOSS_CARPET, Material.PALE_OAK_BOAT, Material.PALE_OAK_BUTTON, Material.PALE_OAK_CHEST_BOAT, Material.PALE_OAK_DOOR, Material.PALE_OAK_FENCE, + Material.PALE_OAK_FENCE_GATE, Material.PALE_OAK_HANGING_SIGN, Material.PALE_OAK_LEAVES, Material.PALE_OAK_LOG, Material.PALE_OAK_PLANKS, Material.PALE_OAK_PRESSURE_PLATE, Material.PALE_OAK_SAPLING, Material.PALE_OAK_SIGN, Material.PALE_OAK_SLAB, + Material.PALE_OAK_STAIRS, Material.PALE_OAK_TRAPDOOR, Material.PALE_OAK_WALL_SIGN, Material.PALE_OAK_WALL_HANGING_SIGN, Material.PALE_OAK_WOOD, Material.POTTED_PALE_OAK_SAPLING, Material.STRIPPED_PALE_OAK_LOG, Material.STRIPPED_PALE_OAK_WOOD, // Material.LEGACY_AIR, Material.LEGACY_DEAD_BUSH, Material.LEGACY_BURNING_FURNACE, Material.LEGACY_WALL_SIGN, Material.LEGACY_REDSTONE_TORCH_OFF, Material.LEGACY_SKULL, Material.LEGACY_REDSTONE_COMPARATOR_ON, Material.LEGACY_WALL_BANNER, Material.LEGACY_MONSTER_EGG)); diff --git a/paper-server/src/test/java/org/bukkit/entity/BoatTest.java b/paper-server/src/test/java/org/bukkit/entity/BoatTest.java deleted file mode 100644 index c027c7a7f8..0000000000 --- a/paper-server/src/test/java/org/bukkit/entity/BoatTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.bukkit.entity; - -import net.minecraft.world.entity.vehicle.EntityBoat; -import org.bukkit.craftbukkit.entity.CraftBoat; -import org.bukkit.support.environment.Normal; -import org.junit.jupiter.api.Test; - -@Normal -public class BoatTest { - - @Test - public void testTypes() { - for (EntityBoat.EnumBoatType enumBoatType : EntityBoat.EnumBoatType.values()) { - CraftBoat.boatTypeFromNms(enumBoatType); - } - - for (Boat.Type enumBoatType : Boat.Type.values()) { - CraftBoat.boatTypeToNms(enumBoatType); - } - } - - @Test - public void testStatus() { - for (EntityBoat.EnumStatus enumStatus : EntityBoat.EnumStatus.values()) { - CraftBoat.boatStatusFromNms(enumStatus); - } - } -} diff --git a/paper-server/src/test/java/org/bukkit/registry/RegistryClassTest.java b/paper-server/src/test/java/org/bukkit/registry/RegistryClassTest.java index 31bc2bba44..efb6bed5ee 100644 --- a/paper-server/src/test/java/org/bukkit/registry/RegistryClassTest.java +++ b/paper-server/src/test/java/org/bukkit/registry/RegistryClassTest.java @@ -339,7 +339,7 @@ public class RegistryClassTest { continue; } - IRegistry registry = vanilla_registry.registryOrThrow(registryKey); + IRegistry registry = vanilla_registry.lookupOrThrow(registryKey); Optional optionalValue = registry.getOptional(CraftNamespacedKey.toMinecraft(((Keyed) fieldData.field().get(null)).getKey())); @@ -368,7 +368,7 @@ public class RegistryClassTest { @ParameterizedTest @MethodSource("fieldData") public void testMissingExperimentalAnnotation(Class type, ResourceKey> registryKey, List fieldDataList) throws IllegalAccessException { - IRegistry registry = vanilla_registry.registryOrThrow(registryKey); + IRegistry registry = vanilla_registry.lookupOrThrow(registryKey); List missing = new ArrayList<>(); for (FieldData fieldData : fieldDataList) { @@ -403,7 +403,7 @@ public class RegistryClassTest { @ParameterizedTest @MethodSource("fieldData") public void testExcessNullCheck(Class type, ResourceKey> registryKey, List fieldDataList) throws IllegalAccessException { - IRegistry registry = vanilla_registry.registryOrThrow(registryKey); + IRegistry registry = vanilla_registry.lookupOrThrow(registryKey); List excess = new ArrayList<>(); Data data = INIT_DATA.get(type); @@ -434,7 +434,7 @@ public class RegistryClassTest { @ParameterizedTest @MethodSource("fieldData") public void testMissingNullCheck(Class type, ResourceKey> registryKey, List fieldDataList) throws IllegalAccessException { - IRegistry registry = vanilla_registry.registryOrThrow(registryKey); + IRegistry registry = vanilla_registry.lookupOrThrow(registryKey); List missing = new ArrayList<>(); Data data = INIT_DATA.get(type); @@ -491,7 +491,7 @@ public class RegistryClassTest { @ParameterizedTest @MethodSource("fieldData") public void testMissingConstants(Class type, ResourceKey> registryKey) throws IllegalAccessException { - IRegistry registry = RegistryHelper.getRegistry().registryOrThrow(registryKey); + IRegistry registry = RegistryHelper.getRegistry().lookupOrThrow(registryKey); List missingKeys = new ArrayList<>(); for (Object nmsObject : registry) { diff --git a/paper-server/src/test/java/org/bukkit/registry/RegistryConstantsTest.java b/paper-server/src/test/java/org/bukkit/registry/RegistryConstantsTest.java index dd388617fc..cff9bd134c 100644 --- a/paper-server/src/test/java/org/bukkit/registry/RegistryConstantsTest.java +++ b/paper-server/src/test/java/org/bukkit/registry/RegistryConstantsTest.java @@ -64,7 +64,7 @@ public class RegistryConstantsTest { private void testMissingConstants(Class clazz, ResourceKey> nmsRegistryKey) { List missingKeys = new ArrayList<>(); - IRegistry nmsRegistry = RegistryHelper.getRegistry().registryOrThrow(nmsRegistryKey); + IRegistry nmsRegistry = RegistryHelper.getRegistry().lookupOrThrow(nmsRegistryKey); for (M nmsObject : nmsRegistry) { MinecraftKey minecraftKey = nmsRegistry.getKey(nmsObject); diff --git a/paper-server/src/test/java/org/bukkit/support/DummyServerHelper.java b/paper-server/src/test/java/org/bukkit/support/DummyServerHelper.java index eb81eee25a..fa6a70ecd2 100644 --- a/paper-server/src/test/java/org/bukkit/support/DummyServerHelper.java +++ b/paper-server/src/test/java/org/bukkit/support/DummyServerHelper.java @@ -56,28 +56,28 @@ public final class DummyServerHelper { case org.bukkit.Tag.REGISTRY_BLOCKS -> { Preconditions.checkArgument(clazz == Material.class, "Block namespace must have block type"); TagKey blockTagKey = TagKey.create(Registries.BLOCK, key); - if (BuiltInRegistries.BLOCK.getTag(blockTagKey).isPresent()) { + if (BuiltInRegistries.BLOCK.get(blockTagKey).isPresent()) { return new CraftBlockTag(BuiltInRegistries.BLOCK, blockTagKey); } } case org.bukkit.Tag.REGISTRY_ITEMS -> { Preconditions.checkArgument(clazz == Material.class, "Item namespace must have item type"); TagKey itemTagKey = TagKey.create(Registries.ITEM, key); - if (BuiltInRegistries.ITEM.getTag(itemTagKey).isPresent()) { + if (BuiltInRegistries.ITEM.get(itemTagKey).isPresent()) { return new CraftItemTag(BuiltInRegistries.ITEM, itemTagKey); } } case org.bukkit.Tag.REGISTRY_FLUIDS -> { Preconditions.checkArgument(clazz == org.bukkit.Fluid.class, "Fluid namespace must have fluid type"); TagKey fluidTagKey = TagKey.create(Registries.FLUID, key); - if (BuiltInRegistries.FLUID.getTag(fluidTagKey).isPresent()) { + if (BuiltInRegistries.FLUID.get(fluidTagKey).isPresent()) { return new CraftFluidTag(BuiltInRegistries.FLUID, fluidTagKey); } } case org.bukkit.Tag.REGISTRY_ENTITY_TYPES -> { Preconditions.checkArgument(clazz == org.bukkit.entity.EntityType.class, "Entity type namespace must have entity type"); TagKey> entityTagKey = TagKey.create(Registries.ENTITY_TYPE, key); - if (BuiltInRegistries.ENTITY_TYPE.getTag(entityTagKey).isPresent()) { + if (BuiltInRegistries.ENTITY_TYPE.get(entityTagKey).isPresent()) { return new CraftEntityTag(BuiltInRegistries.ENTITY_TYPE, entityTagKey); } } diff --git a/paper-server/src/test/java/org/bukkit/support/RegistryHelper.java b/paper-server/src/test/java/org/bukkit/support/RegistryHelper.java index 297e9357e8..d729b17254 100644 --- a/paper-server/src/test/java/org/bukkit/support/RegistryHelper.java +++ b/paper-server/src/test/java/org/bukkit/support/RegistryHelper.java @@ -1,9 +1,11 @@ package org.bukkit.support; import com.google.common.util.concurrent.MoreExecutors; +import java.util.List; import java.util.Locale; import net.minecraft.SharedConstants; import net.minecraft.commands.CommandDispatcher; +import net.minecraft.core.HolderLookup; import net.minecraft.core.IRegistry; import net.minecraft.core.IRegistryCustom; import net.minecraft.core.LayeredRegistryAccess; @@ -12,12 +14,13 @@ import net.minecraft.resources.RegistryDataLoader; import net.minecraft.server.DataPackResources; import net.minecraft.server.DispenserRegistry; import net.minecraft.server.RegistryLayer; -import net.minecraft.server.WorldLoader; import net.minecraft.server.packs.EnumResourcePackType; import net.minecraft.server.packs.repository.ResourcePackLoader; import net.minecraft.server.packs.repository.ResourcePackRepository; import net.minecraft.server.packs.repository.ResourcePackSourceVanilla; +import net.minecraft.server.packs.resources.IResourceManager; import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.tags.TagDataPack; import net.minecraft.world.flag.FeatureFlagSet; import net.minecraft.world.level.biome.BiomeBase; import org.bukkit.Keyed; @@ -54,22 +57,37 @@ public final class RegistryHelper { } public static IRegistryCustom.Dimension createRegistry(FeatureFlagSet featureFlagSet) { - return createLayers(createResourceManager(featureFlagSet)).compositeAccess().freeze(); + ResourceManager ireloadableresourcemanager = createResourceManager(featureFlagSet); + // add tags and loot tables for unit tests + LayeredRegistryAccess layeredregistryaccess = RegistryLayer.createRegistryAccess(); + List> list = TagDataPack.loadTagsForExistingRegistries(ireloadableresourcemanager, layeredregistryaccess.getLayer(RegistryLayer.STATIC)); + IRegistryCustom.Dimension iregistrycustom_dimension = layeredregistryaccess.getAccessForLoading(RegistryLayer.WORLDGEN); + List> list1 = TagDataPack.buildUpdatedLookups(iregistrycustom_dimension, list); + IRegistryCustom.Dimension iregistrycustom_dimension1 = RegistryDataLoader.load((IResourceManager) ireloadableresourcemanager, list1, RegistryDataLoader.WORLDGEN_REGISTRIES); + LayeredRegistryAccess layers = layeredregistryaccess.replaceFrom(RegistryLayer.WORLDGEN, iregistrycustom_dimension1); + + return layers.compositeAccess().freeze(); } public static void setup(FeatureFlagSet featureFlagSet) { SharedConstants.tryDetectVersion(); DispenserRegistry.bootStrap(); - ResourceManager resourceManager = createResourceManager(featureFlagSet); - LayeredRegistryAccess layers = createLayers(resourceManager); + ResourceManager ireloadableresourcemanager = createResourceManager(featureFlagSet); + // add tags and loot tables for unit tests + LayeredRegistryAccess layeredregistryaccess = RegistryLayer.createRegistryAccess(); + List> list = TagDataPack.loadTagsForExistingRegistries(ireloadableresourcemanager, layeredregistryaccess.getLayer(RegistryLayer.STATIC)); + IRegistryCustom.Dimension iregistrycustom_dimension = layeredregistryaccess.getAccessForLoading(RegistryLayer.WORLDGEN); + List> list1 = TagDataPack.buildUpdatedLookups(iregistrycustom_dimension, list); + IRegistryCustom.Dimension iregistrycustom_dimension1 = RegistryDataLoader.load((IResourceManager) ireloadableresourcemanager, list1, RegistryDataLoader.WORLDGEN_REGISTRIES); + LayeredRegistryAccess layers = layeredregistryaccess.replaceFrom(RegistryLayer.WORLDGEN, iregistrycustom_dimension1); registry = layers.compositeAccess().freeze(); // Register vanilla pack - dataPack = DataPackResources.loadResources(resourceManager, layers, featureFlagSet, CommandDispatcher.ServerType.DEDICATED, 0, MoreExecutors.directExecutor(), MoreExecutors.directExecutor()).join(); + dataPack = DataPackResources.loadResources(ireloadableresourcemanager, layers, list, featureFlagSet, CommandDispatcher.ServerType.DEDICATED, 0, MoreExecutors.directExecutor(), MoreExecutors.directExecutor()).join(); // Bind tags - dataPack.updateRegistryTags(); + dataPack.updateStaticRegistryTags(); // Biome shortcut - biomes = registry.registryOrThrow(Registries.BIOME); + biomes = registry.lookupOrThrow(Registries.BIOME); } public static Class updateClass(Class aClass, NamespacedKey key) { @@ -94,14 +112,6 @@ public final class RegistryHelper { return new ResourceManager(EnumResourcePackType.SERVER_DATA, resourceRepository.getAvailablePacks().stream().filter(pack -> pack.getRequestedFeatures().isSubsetOf(featureFlagSet)).map(ResourcePackLoader::open).toList()); } - private static LayeredRegistryAccess createLayers(ResourceManager resourceManager) { - // add tags and loot tables for unit tests - LayeredRegistryAccess layers = RegistryLayer.createRegistryAccess(); - layers = WorldLoader.loadAndReplaceLayer(resourceManager, layers, RegistryLayer.WORLDGEN, RegistryDataLoader.WORLDGEN_REGISTRIES); - - return layers; - } - private static void throwError(String field) { throw new IllegalStateException(String.format(""" Trying to access %s will it is not setup. diff --git a/paper-server/src/test/java/org/bukkit/support/provider/RegistriesArgumentProvider.java b/paper-server/src/test/java/org/bukkit/support/provider/RegistriesArgumentProvider.java index 8579c6de27..c237986a10 100644 --- a/paper-server/src/test/java/org/bukkit/support/provider/RegistriesArgumentProvider.java +++ b/paper-server/src/test/java/org/bukkit/support/provider/RegistriesArgumentProvider.java @@ -72,8 +72,8 @@ public class RegistriesArgumentProvider implements ArgumentsProvider { register(StructureType.class, Registries.STRUCTURE_TYPE, CraftStructureType.class, net.minecraft.world.level.levelgen.structure.StructureType.class); register(Villager.Type.class, Registries.VILLAGER_TYPE, CraftVillager.CraftType.class, VillagerType.class); register(Villager.Profession.class, Registries.VILLAGER_PROFESSION, CraftVillager.CraftProfession.class, VillagerProfession.class); - register(TrimMaterial.class, Registries.TRIM_MATERIAL, CraftTrimMaterial.class, net.minecraft.world.item.armortrim.TrimMaterial.class); - register(TrimPattern.class, Registries.TRIM_PATTERN, CraftTrimPattern.class, net.minecraft.world.item.armortrim.TrimPattern.class); + register(TrimMaterial.class, Registries.TRIM_MATERIAL, CraftTrimMaterial.class, net.minecraft.world.item.equipment.trim.TrimMaterial.class); + register(TrimPattern.class, Registries.TRIM_PATTERN, CraftTrimPattern.class, net.minecraft.world.item.equipment.trim.TrimPattern.class); register(DamageType.class, Registries.DAMAGE_TYPE, CraftDamageType.class, net.minecraft.world.damagesource.DamageType.class); register(JukeboxSong.class, Registries.JUKEBOX_SONG, CraftJukeboxSong.class, net.minecraft.world.item.JukeboxSong.class); register(Wolf.Variant.class, Registries.WOLF_VARIANT, CraftWolf.CraftVariant.class, WolfVariant.class);