From 65bc2541a34511db936b2d0d01a2269487e952e9 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Wed, 24 Apr 2024 01:15:00 +1000 Subject: [PATCH] Update to Minecraft 1.20.5 By: md_5 --- .../advancements/AdvancementHolder.patch | 8 +- .../advancements/AdvancementTree.patch | 9 - .../commands/CommandDispatcher.patch | 33 +- .../commands/CommandListenerWrapper.patch | 4 +- .../arguments/blocks/ArgumentBlock.patch | 12 +- .../core/cauldron/CauldronInteraction.patch | 143 +- .../core/component/DataComponentPatch.patch | 59 + .../DispenseBehaviorProjectile.patch | 22 +- .../dispenser/DispenseBehaviorShears.patch | 18 +- .../core/dispenser/IDispenseBehavior.patch | 187 +-- .../net/minecraft/nbt/NBTTagList.patch | 11 - .../minecraft/network/NetworkManager.patch | 17 +- .../network/PacketDataSerializer.patch | 58 +- .../protocol/PlayerConnectionUtils.patch | 4 +- .../ServerboundCustomPayloadPacket.patch | 43 - .../common/custom/DiscardedPayload.patch | 24 + .../ClientboundInitializeBorderPacket.patch | 2 +- .../ClientboundSetBorderCenterPacket.patch | 4 +- .../game/ClientboundSystemChatPacket.patch | 2 +- .../game/PacketPlayOutMultiBlockChange.patch | 4 +- .../PacketHandshakingInSetProtocol.patch | 2 +- .../network/syncher/DataWatcher.patch | 51 +- .../minecraft/server/DispenserRegistry.patch | 6 +- .../net/minecraft/server/Main.patch | 53 +- .../minecraft/server/MinecraftServer.patch | 123 +- .../minecraft/server/ScoreboardServer.patch | 30 +- .../server/bossevents/BossBattleCustom.patch | 2 +- .../server/commands/CommandEffect.patch | 6 +- .../server/commands/CommandGive.patch | 8 +- .../server/commands/CommandLoot.patch | 4 +- .../server/commands/CommandSummon.patch | 2 +- .../server/commands/PlaceCommand.patch | 2 +- .../server/dedicated/DedicatedServer.patch | 34 +- .../dedicated/DedicatedServerProperties.patch | 14 +- .../server/dedicated/PropertyManager.patch | 4 +- .../net/minecraft/server/gui/ServerGUI.patch | 9 + .../server/level/ChunkMapDistance.patch | 23 +- .../server/level/ChunkProviderServer.patch | 48 +- .../minecraft/server/level/EntityPlayer.patch | 149 ++- .../server/level/EntityTrackerEntry.patch | 36 +- .../minecraft/server/level/PlayerChunk.patch | 77 +- .../server/level/PlayerChunkMap.patch | 89 +- .../server/level/PlayerInteractManager.patch | 57 +- .../level/RegionLimitedWorldAccess.patch | 4 +- .../minecraft/server/level/WorldServer.patch | 99 +- .../server/network/HandshakeListener.patch | 72 +- .../server/network/LoginListener.patch | 106 +- .../server/network/PlayerConnection.patch | 396 +++--- .../ServerCommonPacketListenerImpl.patch | 63 +- ...erverConfigurationPacketListenerImpl.patch | 32 +- .../server/network/ServerConnection.patch | 4 +- .../minecraft/server/players/PlayerList.patch | 147 ++- .../minecraft/server/players/UserCache.patch | 18 + .../rcon/thread/RemoteControlSession.patch | 4 +- .../net/minecraft/util/SpawnUtil.patch | 8 +- .../util/datafix/DataConverterRegistry.patch | 26 +- .../util/worldupdate/WorldUpgrader.patch | 39 +- .../net/minecraft/world/ChestLock.patch | 42 +- .../net/minecraft/world/IInventory.patch | 16 +- .../world/damagesource/DamageSource.patch | 11 +- .../world/effect/HealOrHarmMobEffect.patch | 6 +- .../world/effect/HungerMobEffect.patch | 10 +- .../world/effect/MobEffectUtil.patch | 6 +- .../world/effect/PoisonMobEffect.patch | 8 +- .../world/effect/RegenerationMobEffect.patch | 8 +- .../world/effect/SaturationMobEffect.patch | 10 +- .../net/minecraft/world/entity/Entity.patch | 146 ++- .../world/entity/EntityAreaEffectCloud.patch | 23 +- .../world/entity/EntityCreature.patch | 6 +- .../world/entity/EntityExperienceOrb.patch | 18 +- .../world/entity/EntityInsentient.patch | 112 +- .../world/entity/EntityLightning.patch | 12 +- .../minecraft/world/entity/EntityLiving.patch | 218 ++-- .../minecraft/world/entity/EntityTypes.patch | 67 +- .../world/entity/IEntityAngerable.patch | 4 +- .../minecraft/world/entity/Interaction.patch | 11 +- .../ai/attributes/GenericAttributes.patch | 2 +- .../entity/ai/behavior/BehaviorFarm.patch | 12 +- .../entity/ai/behavior/BehaviorMakeLove.patch | 6 +- .../entity/ai/behavior/BehaviorUtil.patch | 8 +- .../ai/behavior/PrepareRamNearestTarget.patch | 12 +- .../behavior/TryLaySpawnOnWaterNearLand.patch | 4 +- .../ai/goal/PathfinderGoalFollowOwner.patch | 4 +- .../ai/goal/PathfinderGoalRemoveBlock.patch | 2 +- .../entity/ai/goal/PathfinderGoalTempt.patch | 10 +- .../entity/ai/sensing/TemptingSensor.patch | 2 +- .../entity/ai/village/VillageSiege.patch | 2 +- .../world/entity/ambient/EntityBat.patch | 8 +- .../world/entity/animal/Bucketable.patch | 10 +- .../world/entity/animal/EntityAnimal.patch | 37 +- .../world/entity/animal/EntityBee.patch | 35 +- .../world/entity/animal/EntityCat.patch | 39 +- .../world/entity/animal/EntityChicken.patch | 2 +- .../world/entity/animal/EntityCow.patch | 8 +- .../world/entity/animal/EntityDolphin.patch | 10 +- .../world/entity/animal/EntityFox.patch | 20 +- .../world/entity/animal/EntityIronGolem.patch | 2 +- .../entity/animal/EntityMushroomCow.patch | 14 +- .../world/entity/animal/EntityOcelot.patch | 4 +- .../world/entity/animal/EntityPanda.patch | 10 +- .../world/entity/animal/EntityParrot.patch | 12 +- .../world/entity/animal/EntityPig.patch | 6 +- .../entity/animal/EntityPufferFish.patch | 4 +- .../world/entity/animal/EntityRabbit.patch | 8 +- .../world/entity/animal/EntitySheep.patch | 18 +- .../world/entity/animal/EntitySnowman.patch | 14 +- .../world/entity/animal/EntityTurtle.patch | 10 +- .../world/entity/animal/EntityWolf.patch | 108 +- .../world/entity/animal/allay/Allay.patch | 24 +- .../entity/animal/armadillo/Armadillo.patch | 54 + .../world/entity/animal/axolotl/Axolotl.patch | 8 +- .../world/entity/animal/camel/Camel.patch | 6 +- .../world/entity/animal/frog/Tadpole.patch | 8 +- .../world/entity/animal/goat/Goat.patch | 4 +- .../animal/horse/EntityHorseAbstract.patch | 82 +- .../animal/horse/EntityHorseSkeleton.patch | 4 +- .../horse/PathfinderGoalHorseTrap.patch | 4 +- .../world/entity/animal/sniffer/Sniffer.patch | 32 +- .../boss/enderdragon/EntityEnderCrystal.patch | 2 +- .../boss/enderdragon/EntityEnderDragon.patch | 32 +- .../entity/boss/wither/EntityWither.patch | 30 +- .../entity/decoration/EntityArmorStand.patch | 30 +- .../entity/decoration/EntityHanging.patch | 14 +- .../entity/decoration/EntityItemFrame.patch | 8 +- .../world/entity/decoration/EntityLeash.patch | 6 +- .../entity/item/EntityFallingBlock.patch | 8 +- .../world/entity/item/EntityItem.patch | 20 +- .../world/entity/item/EntityTNTPrimed.patch | 4 +- .../entity/monster/EntityCaveSpider.patch | 2 +- .../world/entity/monster/EntityCreeper.patch | 14 +- .../world/entity/monster/EntityDrowned.patch | 2 +- .../world/entity/monster/EntityEnderman.patch | 16 +- .../entity/monster/EntityEndermite.patch | 6 +- .../world/entity/monster/EntityEvoker.patch | 4 +- .../world/entity/monster/EntityGhast.patch | 2 +- .../world/entity/monster/EntityGuardian.patch | 4 +- .../entity/monster/EntityGuardianElder.patch | 2 +- .../monster/EntityIllagerIllusioner.patch | 4 +- .../entity/monster/EntityIllagerWizard.patch | 4 +- .../world/entity/monster/EntityPhantom.patch | 2 +- .../entity/monster/EntityPigZombie.patch | 6 +- .../world/entity/monster/EntityPillager.patch | 4 +- .../world/entity/monster/EntityRavager.patch | 6 +- .../world/entity/monster/EntityShulker.patch | 6 +- .../entity/monster/EntitySilverfish.patch | 8 +- .../entity/monster/EntitySkeletonWither.patch | 2 +- .../world/entity/monster/EntitySlime.patch | 16 +- .../world/entity/monster/EntitySpider.patch | 10 +- .../world/entity/monster/EntityVex.patch | 2 +- .../world/entity/monster/EntityWitch.patch | 14 +- .../world/entity/monster/EntityZombie.patch | 42 +- .../entity/monster/EntityZombieHusk.patch | 2 +- .../entity/monster/EntityZombieVillager.patch | 31 +- .../entity/monster/piglin/EntityPiglin.patch | 20 +- .../monster/piglin/EntityPiglinAbstract.patch | 11 +- .../entity/monster/piglin/PiglinAI.patch | 8 +- .../world/entity/monster/warden/Warden.patch | 43 +- .../world/entity/npc/EntityVillager.patch | 17 +- .../entity/npc/EntityVillagerAbstract.patch | 19 +- .../entity/npc/EntityVillagerTrader.patch | 2 +- .../world/entity/npc/InventoryCarrier.patch | 4 +- .../world/entity/player/EntityHuman.patch | 262 ++-- .../world/entity/player/PlayerInventory.patch | 8 +- .../world/entity/projectile/EntityArrow.patch | 36 +- .../entity/projectile/EntityEnderSignal.patch | 32 +- .../entity/projectile/EntityEvokerFangs.patch | 6 +- .../entity/projectile/EntityFireball.patch | 37 +- .../projectile/EntityFireballFireball.patch | 20 +- .../entity/projectile/EntityFireworks.patch | 14 +- .../entity/projectile/EntityFishingHook.patch | 14 +- .../entity/projectile/EntityLlamaSpit.patch | 14 +- .../entity/projectile/EntityPotion.patch | 71 +- .../entity/projectile/EntityProjectile.patch | 4 +- .../EntityProjectileThrowable.patch | 6 +- .../projectile/EntityShulkerBullet.patch | 20 +- .../projectile/EntitySmallFireball.patch | 4 +- .../projectile/EntitySpectralArrow.patch | 2 +- .../projectile/EntityThrownExpBottle.patch | 6 +- .../projectile/EntityThrownTrident.patch | 6 +- .../entity/projectile/EntityTippedArrow.patch | 28 +- .../world/entity/projectile/IProjectile.patch | 21 +- .../world/entity/projectile/WindCharge.patch | 39 - .../windcharge/AbstractWindCharge.patch | 40 + .../world/entity/raid/EntityRaider.patch | 27 +- .../world/entity/raid/PersistentRaid.patch | 36 +- .../minecraft/world/entity/raid/Raid.patch | 28 +- .../world/entity/vehicle/ChestBoat.patch | 10 +- .../world/entity/vehicle/EntityBoat.patch | 16 +- .../vehicle/EntityMinecartAbstract.patch | 30 +- .../vehicle/EntityMinecartContainer.patch | 10 +- .../entity/vehicle/EntityMinecartTNT.patch | 2 +- .../world/entity/vehicle/VehicleEntity.patch | 6 +- .../minecraft/world/food/FoodMetaData.patch | 22 +- .../minecraft/world/inventory/Container.patch | 2 +- .../world/inventory/ContainerAnvil.patch | 43 +- .../inventory/ContainerAnvilAbstract.patch | 11 +- .../world/inventory/ContainerBeacon.patch | 26 +- .../inventory/ContainerBrewingStand.patch | 12 +- .../inventory/ContainerCartography.patch | 21 +- .../inventory/ContainerEnchantTable.patch | 70 +- .../world/inventory/ContainerGrindstone.patch | 60 +- .../world/inventory/ContainerHorse.patch | 26 +- .../world/inventory/ContainerLoom.patch | 46 +- .../world/inventory/ContainerMerchant.patch | 8 +- .../world/inventory/ContainerPlayer.patch | 22 +- .../world/inventory/CrafterMenu.patch | 4 +- .../world/inventory/InventoryEnderChest.patch | 2 +- .../world/inventory/SlotFurnaceResult.patch | 6 +- .../net/minecraft/world/item/ItemArmor.patch | 4 +- .../net/minecraft/world/item/ItemBlock.patch | 66 +- .../net/minecraft/world/item/ItemBoat.patch | 16 +- .../minecraft/world/item/ItemBoneMeal.patch | 8 +- .../net/minecraft/world/item/ItemBow.patch | 35 - .../net/minecraft/world/item/ItemBucket.patch | 16 +- .../world/item/ItemChorusFruit.patch | 4 +- .../minecraft/world/item/ItemCrossbow.patch | 31 - .../minecraft/world/item/ItemDebugStick.patch | 2 +- .../net/minecraft/world/item/ItemDye.patch | 2 +- .../net/minecraft/world/item/ItemEgg.patch | 4 +- .../minecraft/world/item/ItemEndCrystal.patch | 4 +- .../minecraft/world/item/ItemEnderEye.patch | 4 +- .../minecraft/world/item/ItemEnderPearl.patch | 4 +- .../minecraft/world/item/ItemFireball.patch | 6 +- .../minecraft/world/item/ItemFishingRod.patch | 6 +- .../world/item/ItemFlintAndSteel.patch | 14 +- .../minecraft/world/item/ItemHanging.patch | 6 +- .../net/minecraft/world/item/ItemLeash.patch | 62 +- .../minecraft/world/item/ItemMilkBucket.patch | 4 +- .../minecraft/world/item/ItemMinecart.patch | 8 +- .../minecraft/world/item/ItemMonsterEgg.patch | 11 +- .../net/minecraft/world/item/ItemPotion.patch | 14 +- .../world/item/ItemProjectileWeapon.patch | 33 + .../net/minecraft/world/item/ItemRecord.patch | 2 +- .../minecraft/world/item/ItemSnowball.patch | 16 +- .../net/minecraft/world/item/ItemStack.patch | 182 +-- .../minecraft/world/item/ItemTrident.patch | 24 +- .../minecraft/world/item/ItemWorldMap.patch | 11 - .../world/item/crafting/CraftingManager.patch | 148 +-- .../world/item/crafting/IRecipe.patch | 2 +- .../world/item/crafting/IRecipeComplex.patch | 2 +- .../world/item/crafting/RecipeHolder.patch | 14 +- .../world/item/crafting/RecipeItemStack.patch | 6 +- .../world/item/crafting/ShapedRecipes.patch | 4 +- .../item/crafting/ShapelessRecipes.patch | 4 +- .../crafting/SmithingTransformRecipe.patch | 4 +- .../item/crafting/SmithingTrimRecipe.patch | 6 +- .../enchantment/EnchantmentFrostWalker.patch | 2 +- .../enchantment/EnchantmentWeaponDamage.patch | 4 +- .../world/item/trading/MerchantRecipe.patch | 28 +- .../level/CommandBlockListenerAbstract.patch | 12 +- .../net/minecraft/world/level/Explosion.patch | 26 +- .../net/minecraft/world/level/GameRules.patch | 71 +- .../world/level/GeneratorAccess.patch | 20 +- .../world/level/MobSpawnerAbstract.patch | 11 +- .../net/minecraft/world/level/RayTrace.patch | 4 +- .../world/level/SpawnerCreature.patch | 14 +- .../net/minecraft/world/level/World.patch | 50 +- .../level/block/AbstractCandleBlock.patch | 4 +- .../world/level/block/BigDripleafBlock.patch | 20 +- .../minecraft/world/level/block/Block.patch | 6 +- .../world/level/block/BlockBed.patch | 8 +- .../world/level/block/BlockBeehive.patch | 9 + .../level/block/BlockButtonAbstract.patch | 2 +- .../world/level/block/BlockCactus.patch | 2 +- .../world/level/block/BlockCake.patch | 4 +- .../world/level/block/BlockCampfire.patch | 2 +- .../world/level/block/BlockCauldron.patch | 8 +- .../world/level/block/BlockChest.patch | 14 +- .../world/level/block/BlockCommand.patch | 4 +- .../world/level/block/BlockComposter.patch | 18 +- .../level/block/BlockConcretePowder.patch | 2 +- .../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 | 2 +- .../level/block/BlockDirtSnowSpreadable.patch | 2 +- .../world/level/block/BlockDispenser.patch | 10 +- .../world/level/block/BlockDoor.patch | 4 +- .../world/level/block/BlockDragonEgg.patch | 4 +- .../world/level/block/BlockDropper.patch | 6 +- .../world/level/block/BlockEnderPortal.patch | 2 +- .../world/level/block/BlockFenceGate.patch | 2 +- .../world/level/block/BlockFire.patch | 2 +- .../world/level/block/BlockFireAbstract.patch | 4 +- .../world/level/block/BlockFluids.patch | 6 +- .../world/level/block/BlockGrassPath.patch | 2 +- .../world/level/block/BlockLeaves.patch | 2 +- .../world/level/block/BlockLectern.patch | 5 +- .../world/level/block/BlockMobSpawner.patch | 2 +- .../world/level/block/BlockNote.patch | 6 +- .../world/level/block/BlockNylium.patch | 2 +- .../world/level/block/BlockObserver.patch | 2 +- .../world/level/block/BlockPlant.patch | 2 +- .../world/level/block/BlockPortal.patch | 2 +- .../block/BlockPressurePlateAbstract.patch | 6 +- .../level/block/BlockRedstoneComparator.patch | 6 +- .../world/level/block/BlockRedstoneLamp.patch | 2 +- .../world/level/block/BlockRedstoneOre.patch | 16 +- .../world/level/block/BlockRedstoneWire.patch | 4 +- .../level/block/BlockRespawnAnchor.patch | 12 +- .../world/level/block/BlockSign.patch | 22 +- .../world/level/block/BlockSnow.patch | 2 +- .../world/level/block/BlockSoil.patch | 4 +- .../level/block/BlockSweetBerryBush.patch | 16 +- .../world/level/block/BlockTNT.patch | 20 +- .../world/level/block/BlockTripwire.patch | 4 +- .../world/level/block/BlockTripwireHook.patch | 4 +- .../world/level/block/BlockTurtleEgg.patch | 12 +- .../world/level/block/BlockWaterLily.patch | 2 +- .../world/level/block/BlockWitherRose.patch | 2 +- .../world/level/block/BlockWitherSkull.patch | 6 +- .../world/level/block/CaveVines.patch | 4 +- .../level/block/CeilingHangingSignBlock.patch | 2 +- .../world/level/block/DecoratedPotBlock.patch | 2 +- .../level/block/DropExperienceBlock.patch | 2 +- .../level/block/LayeredCauldronBlock.patch | 18 +- .../level/block/PointedDripstoneBlock.patch | 14 +- .../world/level/block/RootedDirtBlock.patch | 5 +- .../level/block/SculkCatalystBlock.patch | 2 +- .../world/level/block/SculkSensorBlock.patch | 12 +- .../level/block/SculkShriekerBlock.patch | 6 +- .../level/block/WallHangingSignBlock.patch | 2 +- .../block/entity/BrushableBlockEntity.patch | 12 +- .../entity/ChiseledBookShelfBlockEntity.patch | 16 +- .../entity/ContainerOpenersCounter.patch | 18 +- .../block/entity/CrafterBlockEntity.patch | 11 +- .../entity/DecoratedPotBlockEntity.patch | 6 +- .../entity/SculkCatalystBlockEntity.patch | 9 +- .../world/level/block/entity/TileEntity.patch | 41 +- .../level/block/entity/TileEntityBanner.patch | 47 +- .../level/block/entity/TileEntityBarrel.patch | 2 +- .../level/block/entity/TileEntityBeacon.patch | 52 +- .../block/entity/TileEntityBeehive.patch | 140 +- .../block/entity/TileEntityBrewingStand.patch | 23 +- .../block/entity/TileEntityCampfire.patch | 8 +- .../level/block/entity/TileEntityChest.patch | 6 +- .../block/entity/TileEntityCommand.patch | 2 +- .../block/entity/TileEntityConduit.patch | 32 +- .../block/entity/TileEntityContainer.patch | 6 +- .../block/entity/TileEntityDispenser.patch | 2 +- .../block/entity/TileEntityEndGateway.patch | 8 +- .../block/entity/TileEntityFurnace.patch | 30 +- .../level/block/entity/TileEntityHopper.patch | 91 +- .../block/entity/TileEntityJukeBox.patch | 10 +- .../block/entity/TileEntityLectern.patch | 12 +- .../block/entity/TileEntityShulkerBox.patch | 12 +- .../level/block/entity/TileEntitySign.patch | 32 +- .../level/block/entity/TileEntitySkull.patch | 19 - .../trialspawner/TrialSpawnerData.patch | 18 + .../block/grower/WorldGenTreeProvider.patch | 10 +- .../level/block/piston/BlockPiston.patch | 6 +- .../world/level/block/state/BlockBase.patch | 2 +- .../minecraft/world/level/chunk/Chunk.patch | 14 +- .../world/level/chunk/ChunkGenerator.patch | 17 +- .../world/level/chunk/ChunkStatus.patch | 11 - .../world/level/chunk/IChunkAccess.patch | 8 +- .../level/chunk/status/ChunkStatusTasks.patch | 11 + .../chunk/storage/ChunkRegionLoader.patch | 62 +- .../level/chunk/storage/IChunkLoader.patch | 45 +- .../level/chunk/storage/RegionFile.patch | 16 +- .../level/chunk/storage/RegionFileCache.patch | 14 +- .../dimension/end/EnderDragonBattle.patch | 9 - .../PersistentEntitySectionManager.patch | 2 +- .../level/gameevent/GameEventDispatcher.patch | 10 +- .../vibrations/VibrationSystem.patch | 18 +- .../level/levelgen/MobSpawnerPatrol.patch | 4 +- .../level/levelgen/MobSpawnerPhantom.patch | 4 +- .../levelgen/structure/StructurePiece.patch | 36 +- .../structures/DesertPyramidStructure.patch | 6 +- .../structures/MineshaftPieces.patch | 10 +- .../structures/OceanRuinPieces.patch | 6 +- .../structure/structures/SwampHutPiece.patch | 4 +- .../templatesystem/DefinedStructure.patch | 10 +- .../level/material/FluidTypeFlowing.patch | 2 +- .../level/redstone/NeighborUpdater.patch | 2 +- .../world/level/saveddata/maps/WorldMap.patch | 52 +- .../world/level/storage/Convertable.patch | 27 +- .../world/level/storage/WorldDataServer.patch | 38 +- .../world/level/storage/WorldNBTStorage.patch | 119 +- .../level/storage/loot/LootDataManager.patch | 48 - .../level/storage/loot/LootDataType.patch | 22 + .../world/level/storage/loot/LootTable.patch | 6 +- ...ItemConditionRandomChanceWithLooting.patch | 2 +- paper-server/pom.xml | 45 +- .../org/bukkit/craftbukkit/CraftChunk.java | 12 +- .../org/bukkit/craftbukkit/CraftEffect.java | 3 - .../craftbukkit/CraftEquipmentSlot.java | 11 + .../bukkit/craftbukkit/CraftLootTable.java | 25 + .../craftbukkit/CraftMusicInstrument.java | 20 + .../craftbukkit/CraftOfflinePlayer.java | 2 +- .../org/bukkit/craftbukkit/CraftParticle.java | 10 + .../org/bukkit/craftbukkit/CraftRaid.java | 8 +- .../craftbukkit/CraftRegionAccessor.java | 2 +- .../org/bukkit/craftbukkit/CraftRegistry.java | 14 + .../org/bukkit/craftbukkit/CraftServer.java | 50 +- .../org/bukkit/craftbukkit/CraftWorld.java | 14 +- .../java/org/bukkit/craftbukkit/Main.java | 5 +- .../craftbukkit/attribute/CraftAttribute.java | 18 + .../attribute/CraftAttributeInstance.java | 6 +- .../attribute/CraftAttributeMap.java | 2 +- .../craftbukkit/block/CapturedBlockState.java | 6 +- .../bukkit/craftbukkit/block/CraftBanner.java | 22 +- .../bukkit/craftbukkit/block/CraftBeacon.java | 8 +- .../craftbukkit/block/CraftBeehive.java | 2 +- .../block/CraftBlockEntityState.java | 38 +- .../craftbukkit/block/CraftBlockStates.java | 27 +- .../block/CraftBrushableBlock.java | 16 +- .../block/CraftChiseledBookshelf.java | 9 +- .../craftbukkit/block/CraftCommandBlock.java | 2 +- .../craftbukkit/block/CraftContainer.java | 8 +- .../block/CraftCreatureSpawner.java | 44 +- .../craftbukkit/block/CraftDecoratedPot.java | 32 +- .../craftbukkit/block/CraftLootable.java | 16 +- .../bukkit/craftbukkit/block/CraftSkull.java | 24 +- .../bukkit/craftbukkit/block/CraftVault.java | 27 + .../block/banner/CraftPatternType.java | 49 + .../block/data/CraftBlockData.java | 9 +- .../block/data/type/CraftTrialSpawner.java | 11 + .../block/data/type/CraftVault.java | 30 + .../block/impl/CraftHeavyCore.java | 29 + .../block/impl/CraftTrialSpawner.java | 11 + .../craftbukkit/block/impl/CraftVault.java | 59 + .../enchantments/CraftEnchantment.java | 29 +- .../entity/CraftAbstractHorse.java | 2 +- .../entity/CraftAbstractWindCharge.java | 27 + .../entity/CraftAreaEffectCloud.java | 72 +- .../craftbukkit/entity/CraftArmadillo.java | 21 + .../craftbukkit/entity/CraftBogged.java | 27 + .../entity/CraftBreezeWindCharge.java | 20 + .../bukkit/craftbukkit/entity/CraftCat.java | 22 +- .../craftbukkit/entity/CraftChestBoat.java | 16 +- .../craftbukkit/entity/CraftEntityTypes.java | 10 +- .../craftbukkit/entity/CraftFireball.java | 2 +- .../bukkit/craftbukkit/entity/CraftFrog.java | 22 +- .../craftbukkit/entity/CraftHumanEntity.java | 6 +- .../craftbukkit/entity/CraftLivingEntity.java | 35 +- .../entity/CraftMinecartCommand.java | 2 +- .../entity/CraftMinecartContainer.java | 16 +- .../bukkit/craftbukkit/entity/CraftMob.java | 9 +- .../craftbukkit/entity/CraftMushroomCow.java | 42 +- .../entity/CraftOminousItemSpawner.java | 43 + .../craftbukkit/entity/CraftPlayer.java | 109 +- .../entity/CraftSizedFireball.java | 4 +- .../entity/CraftTameableAnimal.java | 2 +- .../entity/CraftThrowableProjectile.java | 4 +- .../craftbukkit/entity/CraftThrownPotion.java | 7 +- .../craftbukkit/entity/CraftTippedArrow.java | 70 +- .../craftbukkit/entity/CraftWindCharge.java | 15 +- .../bukkit/craftbukkit/entity/CraftWolf.java | 58 + .../craftbukkit/event/CraftEventFactory.java | 3 +- .../generator/CraftLimitedRegion.java | 2 +- .../generator/CustomChunkGenerator.java | 6 +- .../generator/CustomWorldChunkManager.java | 4 +- .../inventory/CraftItemFactory.java | 23 +- .../craftbukkit/inventory/CraftItemStack.java | 165 +-- .../inventory/CraftMerchantRecipe.java | 18 +- .../craftbukkit/inventory/CraftMetaArmor.java | 33 +- .../inventory/CraftMetaArmorStand.java | 19 +- .../inventory/CraftMetaAxolotlBucket.java | 32 +- .../inventory/CraftMetaBanner.java | 85 +- .../inventory/CraftMetaBlockState.java | 143 +- .../craftbukkit/inventory/CraftMetaBook.java | 230 +--- .../inventory/CraftMetaBookSigned.java | 326 ++++- .../inventory/CraftMetaBundle.java | 43 +- .../inventory/CraftMetaCharge.java | 19 +- .../inventory/CraftMetaColorableArmor.java | 8 +- .../inventory/CraftMetaCompass.java | 83 +- .../inventory/CraftMetaCrossbow.java | 52 +- .../inventory/CraftMetaEnchantedBook.java | 25 +- .../inventory/CraftMetaEntityTag.java | 19 +- .../inventory/CraftMetaFirework.java | 146 +-- .../craftbukkit/inventory/CraftMetaItem.java | 1145 +++++++++++------ .../inventory/CraftMetaKnowledgeBook.java | 29 +- .../inventory/CraftMetaLeatherArmor.java | 41 +- .../craftbukkit/inventory/CraftMetaMap.java | 62 +- .../inventory/CraftMetaMusicInstrument.java | 23 +- .../inventory/CraftMetaOminousBottle.java | 126 ++ .../inventory/CraftMetaPotion.java | 139 +- .../craftbukkit/inventory/CraftMetaSkull.java | 61 +- .../inventory/CraftMetaSpawnEgg.java | 23 +- .../inventory/CraftMetaSuspiciousStew.java | 39 +- .../CraftMetaTropicalFishBucket.java | 29 +- .../craftbukkit/inventory/RecipeIterator.java | 29 +- .../inventory/SerializableMeta.java | 113 ++ .../components/CraftFoodComponent.java | 242 ++++ .../inventory/trim/CraftTrimMaterial.java | 20 + .../inventory/trim/CraftTrimPattern.java | 20 + .../util/CraftTileInventoryConverter.java | 6 +- .../craftbukkit/map/CraftMapCursor.java | 52 + .../craftbukkit/map/CraftMapRenderer.java | 3 +- .../bukkit/craftbukkit/map/CraftMapView.java | 9 +- .../craftbukkit/packs/CraftDataPack.java | 2 +- .../craftbukkit/potion/CraftPotionBrewer.java | 31 - .../potion/CraftPotionEffectType.java | 9 + .../craftbukkit/potion/CraftPotionType.java | 18 + .../craftbukkit/potion/CraftPotionUtil.java | 73 +- .../craftbukkit/structure/CraftPalette.java | 7 +- .../craftbukkit/structure/CraftStructure.java | 7 +- .../structure/CraftStructureManager.java | 21 +- .../bukkit/craftbukkit/util/Commodore.java | 14 + .../craftbukkit/util/CraftChatMessage.java | 13 +- .../craftbukkit/util/CraftMagicNumbers.java | 25 +- .../util/DelegatedGeneratorAccess.java | 21 +- .../util/DummyGeneratorAccess.java | 4 +- .../util/TransformerGeneratorAccess.java | 4 +- paper-server/src/main/resources/log4j2.xml | 10 +- .../test/java/org/bukkit/EnchantmentTest.java | 2 - .../test/java/org/bukkit/LootTablesTest.java | 8 +- .../test/java/org/bukkit/ParticleTest.java | 33 +- .../test/java/org/bukkit/PerMaterialTest.java | 43 +- .../bukkit/block/banner/PatternTypeTest.java | 20 +- .../craftbukkit/attribute/AttributeTest.java | 3 +- .../craftbukkit/entity/EntityTypesTest.java | 2 + .../DeprecatedItemMetaCustomValueTest.java | 7 +- .../craftbukkit/inventory/ItemMetaTest.java | 14 +- .../PersistentDataContainerTest.java | 21 +- .../bukkit/craftbukkit/legacy/LegacyTest.java | 5 +- .../enchantments/EnchantmentTargetTest.java | 42 - .../java/org/bukkit/potion/PotionTest.java | 4 +- .../registry/RegistryConstantsTest.java | 2 +- .../registry/RegistryLoadOrderTest.java | 6 +- .../bukkit/support/AbstractTestingBase.java | 4 +- .../java/org/bukkit/support/DummyServer.java | 4 +- 524 files changed, 7788 insertions(+), 6181 deletions(-) create mode 100644 paper-server/nms-patches/net/minecraft/core/component/DataComponentPatch.patch delete mode 100644 paper-server/nms-patches/net/minecraft/nbt/NBTTagList.patch delete mode 100644 paper-server/nms-patches/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.patch create mode 100644 paper-server/nms-patches/net/minecraft/network/protocol/common/custom/DiscardedPayload.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/entity/animal/armadillo/Armadillo.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/entity/projectile/WindCharge.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/entity/projectile/windcharge/AbstractWindCharge.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/item/ItemBow.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/item/ItemCrossbow.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/item/ItemProjectileWeapon.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/item/ItemWorldMap.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntitySkull.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerData.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkStatus.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/level/chunk/status/ChunkStatusTasks.patch delete mode 100644 paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootDataManager.patch create mode 100644 paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootDataType.patch create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftVault.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/block/banner/CraftPatternType.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftVault.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftHeavyCore.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftVault.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractWindCharge.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArmadillo.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBogged.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBreezeWindCharge.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftOminousItemSpawner.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaOminousBottle.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/inventory/SerializableMeta.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftFoodComponent.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapCursor.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionBrewer.java delete mode 100644 paper-server/src/test/java/org/bukkit/enchantments/EnchantmentTargetTest.java diff --git a/paper-server/nms-patches/net/minecraft/advancements/AdvancementHolder.patch b/paper-server/nms-patches/net/minecraft/advancements/AdvancementHolder.patch index 211bb9e586..1b57fcdb4a 100644 --- a/paper-server/nms-patches/net/minecraft/advancements/AdvancementHolder.patch +++ b/paper-server/nms-patches/net/minecraft/advancements/AdvancementHolder.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/advancements/AdvancementHolder.java +++ b/net/minecraft/advancements/AdvancementHolder.java -@@ -3,6 +3,11 @@ - import net.minecraft.network.PacketDataSerializer; +@@ -6,6 +6,11 @@ + import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.MinecraftKey; +// CraftBukkit start @@ -11,8 +11,8 @@ + public record AdvancementHolder(MinecraftKey id, Advancement value) { - public void write(PacketDataSerializer packetdataserializer) { -@@ -41,4 +46,10 @@ + public static final StreamCodec STREAM_CODEC = StreamCodec.composite(MinecraftKey.STREAM_CODEC, AdvancementHolder::id, Advancement.STREAM_CODEC, AdvancementHolder::value, AdvancementHolder::new); +@@ -38,4 +43,10 @@ public String toString() { return this.id.toString(); } diff --git a/paper-server/nms-patches/net/minecraft/advancements/AdvancementTree.patch b/paper-server/nms-patches/net/minecraft/advancements/AdvancementTree.patch index f736fbf6e4..a09551dbaa 100644 --- a/paper-server/nms-patches/net/minecraft/advancements/AdvancementTree.patch +++ b/paper-server/nms-patches/net/minecraft/advancements/AdvancementTree.patch @@ -1,14 +1,5 @@ --- a/net/minecraft/advancements/AdvancementTree.java +++ b/net/minecraft/advancements/AdvancementTree.java -@@ -68,7 +68,7 @@ - } - - public void addAll(Collection collection) { -- ArrayList arraylist = new ArrayList(collection); -+ ArrayList arraylist = new ArrayList(collection); // CraftBukkit - decompile error - - while (!arraylist.isEmpty()) { - if (!arraylist.removeIf(this::tryInsert)) { @@ -77,7 +77,7 @@ } } diff --git a/paper-server/nms-patches/net/minecraft/commands/CommandDispatcher.patch b/paper-server/nms-patches/net/minecraft/commands/CommandDispatcher.patch index 970e29b176..c1a239711a 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 -@@ -134,6 +134,14 @@ +@@ -136,6 +136,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(); -@@ -146,6 +154,7 @@ +@@ -148,6 +156,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); -@@ -246,6 +255,11 @@ +@@ -249,6 +258,11 @@ CommandPublish.register(this.dispatcher); } @@ -35,7 +35,7 @@ this.dispatcher.setConsumer(ExecutionCommandSource.resultConsumer()); } -@@ -256,18 +270,65 @@ +@@ -259,18 +273,65 @@ return new ParseResults(commandcontextbuilder1, parseresults.getReader(), parseresults.getExceptions()); } @@ -98,12 +98,12 @@ commandlistenerwrapper.getServer().getProfiler().push(() -> { return "/" + s; }); -- ContextChain contextchain = finishParsing(parseresults, s, commandlistenerwrapper); -+ ContextChain contextchain = finishParsing(parseresults, s, commandlistenerwrapper, label); // CraftBukkit +- ContextChain contextchain = finishParsing(parseresults, s, commandlistenerwrapper); ++ ContextChain contextchain = finishParsing(parseresults, s, commandlistenerwrapper, label); // CraftBukkit try { if (contextchain != null) { -@@ -301,7 +362,7 @@ +@@ -304,7 +365,7 @@ } @Nullable @@ -112,7 +112,7 @@ try { validateParseResults(parseresults); return (ContextChain) ContextChain.tryFlatten(parseresults.getContext().build(s)).orElseThrow(() -> { -@@ -312,7 +373,7 @@ +@@ -315,7 +376,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) { -@@ -362,7 +423,7 @@ +@@ -365,7 +426,7 @@ executioncontext1.close(); } finally { @@ -130,7 +130,7 @@ } } else { consumer.accept(executioncontext); -@@ -371,11 +432,36 @@ +@@ -374,11 +435,36 @@ } public void sendCommands(EntityPlayer entityplayer) { @@ -168,7 +168,7 @@ entityplayer.connection.send(new PacketPlayOutCommands(rootcommandnode)); } -@@ -386,7 +472,7 @@ +@@ -389,7 +475,7 @@ CommandNode commandnode2 = (CommandNode) iterator.next(); if (commandnode2.canUse(commandlistenerwrapper)) { @@ -177,7 +177,7 @@ argumentbuilder.requires((icompletionprovider) -> { return true; -@@ -409,7 +495,7 @@ +@@ -412,7 +498,7 @@ argumentbuilder.redirect((CommandNode) map.get(argumentbuilder.getRedirect())); } @@ -186,3 +186,12 @@ map.put(commandnode2, commandnode3); commandnode1.addChild(commandnode3); +@@ -473,7 +559,7 @@ + } + + private HolderLookup.b.a createLookup(final HolderLookup.b holderlookup_b) { +- return new HolderLookup.b.a(this) { ++ return new HolderLookup.b.a() { // CraftBukkit - decompile error + @Override + public HolderLookup.b parent() { + return 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 6b05786842..092f48ad10 100644 --- a/paper-server/nms-patches/net/minecraft/commands/CommandListenerWrapper.patch +++ b/paper-server/nms-patches/net/minecraft/commands/CommandListenerWrapper.patch @@ -41,7 +41,7 @@ public Vec3D getPosition() { return this.worldPosition; } -@@ -304,7 +321,7 @@ +@@ -300,7 +317,7 @@ while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer) iterator.next(); @@ -50,7 +50,7 @@ entityplayer.sendSystemMessage(ichatmutablecomponent); } } -@@ -397,4 +414,10 @@ +@@ -393,4 +410,10 @@ public boolean isSilent() { return this.silent; } diff --git a/paper-server/nms-patches/net/minecraft/commands/arguments/blocks/ArgumentBlock.patch b/paper-server/nms-patches/net/minecraft/commands/arguments/blocks/ArgumentBlock.patch index 6d86c0ea37..e979bd5e4d 100644 --- a/paper-server/nms-patches/net/minecraft/commands/arguments/blocks/ArgumentBlock.patch +++ b/paper-server/nms-patches/net/minecraft/commands/arguments/blocks/ArgumentBlock.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/commands/arguments/blocks/ArgumentBlock.java +++ b/net/minecraft/commands/arguments/blocks/ArgumentBlock.java -@@ -68,7 +68,7 @@ +@@ -67,7 +67,7 @@ private final StringReader reader; private final boolean forTesting; private final boolean allowNbt; @@ -9,16 +9,16 @@ private final Map vagueProperties = Maps.newHashMap(); private MinecraftKey id = new MinecraftKey(""); @Nullable -@@ -276,7 +276,7 @@ +@@ -275,7 +275,7 @@ Iterator iterator = iblockstate.getPossibleValues().iterator(); while (iterator.hasNext()) { - T t0 = (Comparable) iterator.next(); + T t0 = (T) iterator.next(); // CraftBukkit - decompile error - if (t0 instanceof Integer) { - Integer integer = (Integer) t0; -@@ -548,7 +548,7 @@ + if (t0 instanceof Integer integer) { + suggestionsbuilder.suggest(integer); +@@ -545,7 +545,7 @@ Optional optional = iblockstate.getValue(s); if (optional.isPresent()) { @@ -27,7 +27,7 @@ this.properties.put(iblockstate, (Comparable) optional.get()); } else { this.reader.setCursor(i); -@@ -584,7 +584,7 @@ +@@ -581,7 +581,7 @@ private static > void appendProperty(StringBuilder stringbuilder, IBlockState iblockstate, Comparable comparable) { stringbuilder.append(iblockstate.getName()); stringbuilder.append('='); 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 bf21acdd23..f6b6beeeaf 100644 --- a/paper-server/nms-patches/net/minecraft/core/cauldron/CauldronInteraction.patch +++ b/paper-server/nms-patches/net/minecraft/core/cauldron/CauldronInteraction.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/core/cauldron/CauldronInteraction.java +++ b/net/minecraft/core/cauldron/CauldronInteraction.java -@@ -33,9 +33,15 @@ +@@ -34,9 +34,15 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.gameevent.GameEvent; @@ -16,7 +16,7 @@ Codec CODEC; CauldronInteraction.a EMPTY; CauldronInteraction.a WATER; -@@ -47,6 +53,8 @@ +@@ -48,6 +54,8 @@ CauldronInteraction SHULKER_BOX; CauldronInteraction BANNER; CauldronInteraction DYED_ITEM; @@ -25,13 +25,13 @@ static CauldronInteraction.a newInteractionMap(String s) { Object2ObjectOpenHashMap object2objectopenhashmap = new Object2ObjectOpenHashMap(); -@@ -71,12 +79,17 @@ - return EnumInteractionResult.PASS; - } else { +@@ -72,12 +80,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 EnumInteractionResult.SUCCESS; ++ return ItemInteractionResult.SUCCESS; + } + // CraftBukkit end Item item = itemstack.getItem(); @@ -42,51 +42,51 @@ - world.setBlockAndUpdate(blockposition, Blocks.WATER_CAULDRON.defaultBlockState()); + // world.setBlockAndUpdate(blockposition, Blocks.WATER_CAULDRON.defaultBlockState()); // CraftBukkit world.playSound((EntityHuman) null, blockposition, SoundEffects.BOTTLE_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F); - world.gameEvent((Entity) null, GameEvent.FLUID_PLACE, blockposition); + world.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PLACE, blockposition); } -@@ -94,12 +107,17 @@ +@@ -97,12 +110,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 EnumInteractionResult.SUCCESS; ++ return ItemInteractionResult.SUCCESS; + } + // CraftBukkit end Item item = itemstack.getItem(); - entityhuman.setItemInHand(enumhand, ItemLiquidUtil.createFilledResult(itemstack, entityhuman, PotionUtil.setPotion(new ItemStack(Items.POTION), Potions.WATER))); + entityhuman.setItemInHand(enumhand, ItemLiquidUtil.createFilledResult(itemstack, entityhuman, PotionContents.createItemStack(Items.POTION, Potions.WATER))); entityhuman.awardStat(StatisticList.USE_CAULDRON); entityhuman.awardStat(StatisticList.ITEM_USED.get(item)); - LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); + // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit world.playSound((EntityHuman) null, blockposition, SoundEffects.BOTTLE_FILL, SoundCategory.BLOCKS, 1.0F, 1.0F); - world.gameEvent((Entity) null, GameEvent.FLUID_PICKUP, blockposition); + world.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PICKUP, blockposition); } -@@ -109,10 +127,15 @@ - map1.put(Items.POTION, (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { - if ((Integer) iblockdata.getValue(LayeredCauldronBlock.LEVEL) != 3 && PotionUtil.getPotion(itemstack) == Potions.WATER) { - if (!world.isClientSide) { -+ // CraftBukkit start -+ if (!LayeredCauldronBlock.changeLevel(iblockdata, world, blockposition, iblockdata.cycle(LayeredCauldronBlock.LEVEL), entityhuman, CauldronLevelChangeEvent.ChangeReason.BOTTLE_EMPTY)) { -+ return EnumInteractionResult.SUCCESS; -+ } -+ // CraftBukkit end - entityhuman.setItemInHand(enumhand, ItemLiquidUtil.createFilledResult(itemstack, entityhuman, new ItemStack(Items.GLASS_BOTTLE))); - entityhuman.awardStat(StatisticList.USE_CAULDRON); - entityhuman.awardStat(StatisticList.ITEM_USED.get(itemstack.getItem())); -- world.setBlockAndUpdate(blockposition, (IBlockData) iblockdata.cycle(LayeredCauldronBlock.LEVEL)); -+ // world.setBlockAndUpdate(blockposition, (IBlockData) iblockdata.cycle(LayeredCauldronBlock.LEVEL)); // CraftBukkit - world.playSound((EntityHuman) null, blockposition, SoundEffects.BOTTLE_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F); - world.gameEvent((Entity) null, GameEvent.FLUID_PLACE, blockposition); - } -@@ -188,12 +211,17 @@ - return EnumInteractionResult.PASS; +@@ -117,10 +135,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; ++ } ++ // CraftBukkit end + entityhuman.setItemInHand(enumhand, ItemLiquidUtil.createFilledResult(itemstack, entityhuman, new ItemStack(Items.GLASS_BOTTLE))); + entityhuman.awardStat(StatisticList.USE_CAULDRON); + entityhuman.awardStat(StatisticList.ITEM_USED.get(itemstack.getItem())); +- world.setBlockAndUpdate(blockposition, (IBlockData) iblockdata.cycle(LayeredCauldronBlock.LEVEL)); ++ // world.setBlockAndUpdate(blockposition, (IBlockData) iblockdata.cycle(LayeredCauldronBlock.LEVEL)); // CraftBukkit + 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; } else { if (!world.isClientSide) { + // CraftBukkit start + if (!LayeredCauldronBlock.changeLevel(iblockdata, world, blockposition, Blocks.CAULDRON.defaultBlockState(), entityhuman, CauldronLevelChangeEvent.ChangeReason.BUCKET_FILL)) { -+ return EnumInteractionResult.SUCCESS; ++ return ItemInteractionResult.SUCCESS; + } + // CraftBukkit end Item item = itemstack.getItem(); @@ -97,15 +97,15 @@ - world.setBlockAndUpdate(blockposition, Blocks.CAULDRON.defaultBlockState()); + // world.setBlockAndUpdate(blockposition, Blocks.CAULDRON.defaultBlockState()); // CraftBukkit world.playSound((EntityHuman) null, blockposition, soundeffect, SoundCategory.BLOCKS, 1.0F, 1.0F); - world.gameEvent((Entity) null, GameEvent.FLUID_PICKUP, blockposition); + world.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PICKUP, blockposition); } -@@ -204,12 +232,17 @@ +@@ -214,12 +242,17 @@ - static EnumInteractionResult emptyBucket(World world, BlockPosition blockposition, EntityHuman entityhuman, EnumHand enumhand, ItemStack itemstack, IBlockData iblockdata, SoundEffect soundeffect) { + static ItemInteractionResult 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 EnumInteractionResult.SUCCESS; ++ return ItemInteractionResult.SUCCESS; + } + // CraftBukkit end Item item = itemstack.getItem(); @@ -116,10 +116,10 @@ - world.setBlockAndUpdate(blockposition, iblockdata); + // world.setBlockAndUpdate(blockposition, iblockdata); // CraftBukkit world.playSound((EntityHuman) null, blockposition, soundeffect, SoundCategory.BLOCKS, 1.0F, 1.0F); - world.gameEvent((Entity) null, GameEvent.FLUID_PLACE, blockposition); + world.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PLACE, blockposition); } -@@ -217,32 +250,35 @@ - return EnumInteractionResult.sidedSuccess(world.isClientSide); +@@ -227,47 +260,55 @@ + return ItemInteractionResult.sidedSuccess(world.isClientSide); } - static { @@ -127,7 +127,7 @@ - Map map = CauldronInteraction.INTERACTIONS; - - Objects.requireNonNull(map); -- CODEC = ExtraCodecs.stringResolverCodec(function, map::get); +- CODEC = Codec.stringResolver(function, map::get); - EMPTY = newInteractionMap("empty"); - WATER = newInteractionMap("water"); - LAVA = newInteractionMap("lava"); @@ -135,7 +135,7 @@ - FILL_WATER = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { + // CraftBukkit start - decompile errors + // static { -+ Codec CODEC = ExtraCodecs.stringResolverCodec(CauldronInteraction.a::name, CauldronInteraction.INTERACTIONS::get); ++ 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"); @@ -157,43 +157,40 @@ Block block = Block.byItem(itemstack.getItem()); if (!(block instanceof BlockShulkerBox)) { - return EnumInteractionResult.PASS; + 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 EnumInteractionResult.SUCCESS; ++ return ItemInteractionResult.SUCCESS; + } + // CraftBukkit end - ItemStack itemstack1 = new ItemStack(Blocks.SHULKER_BOX); - - if (itemstack.hasTag()) { -@@ -251,17 +287,22 @@ - - entityhuman.setItemInHand(enumhand, itemstack1); + entityhuman.setItemInHand(enumhand, itemstack.transmuteCopy(Blocks.SHULKER_BOX, 1)); entityhuman.awardStat(StatisticList.CLEAN_SHULKER_BOX); - LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); + // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit } - return EnumInteractionResult.sidedSuccess(world.isClientSide); + return ItemInteractionResult.sidedSuccess(world.isClientSide); } }; - BANNER = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { + CauldronInteraction BANNER = (iblockdata, world, blockposition, entityhuman, enumhand, itemstack) -> { // CraftBukkit - decompile error - if (TileEntityBanner.getPatternCount(itemstack) <= 0) { - return EnumInteractionResult.PASS; + 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 EnumInteractionResult.SUCCESS; ++ return ItemInteractionResult.SUCCESS; + } + // CraftBukkit end ItemStack itemstack1 = itemstack.copyWithCount(1); - TileEntityBanner.removeLastPattern(itemstack1); -@@ -278,13 +319,13 @@ + itemstack1.set(DataComponents.BANNER_PATTERNS, bannerpatternlayers.removeLast()); +@@ -281,28 +322,33 @@ } entityhuman.awardStat(StatisticList.CLEAN_BANNER); @@ -201,31 +198,29 @@ + // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit } - return EnumInteractionResult.sidedSuccess(world.isClientSide); + 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 - Item item = itemstack.getItem(); - - if (!(item instanceof IDyeable)) { -@@ -296,16 +337,21 @@ - return EnumInteractionResult.PASS; - } else { - if (!world.isClientSide) { -+ // CraftBukkit start -+ if (!LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition, entityhuman, CauldronLevelChangeEvent.ChangeReason.ARMOR_WASH)) { -+ return EnumInteractionResult.SUCCESS; -+ } -+ // CraftBukkit end - idyeable.clearColor(itemstack); - entityhuman.awardStat(StatisticList.CLEAN_ARMOR); -- LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); -+ // LayeredCauldronBlock.lowerFillLevel(iblockdata, world, blockposition); // CraftBukkit - } - - return EnumInteractionResult.sidedSuccess(world.isClientSide); + 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); } }; - } diff --git a/paper-server/nms-patches/net/minecraft/core/component/DataComponentPatch.patch b/paper-server/nms-patches/net/minecraft/core/component/DataComponentPatch.patch new file mode 100644 index 0000000000..339e9743ff --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/core/component/DataComponentPatch.patch @@ -0,0 +1,59 @@ +--- a/net/minecraft/core/component/DataComponentPatch.java ++++ b/net/minecraft/core/component/DataComponentPatch.java +@@ -61,7 +61,7 @@ + } + } + +- return reference2objectmap; ++ return (Reference2ObjectMap) reference2objectmap; // CraftBukkit - decompile error + }); + public static final StreamCodec STREAM_CODEC = new StreamCodec() { + public DataComponentPatch decode(RegistryFriendlyByteBuf registryfriendlybytebuf) { +@@ -143,7 +143,7 @@ + } + + private static void encodeComponent(RegistryFriendlyByteBuf registryfriendlybytebuf, DataComponentType datacomponenttype, Object object) { +- datacomponenttype.streamCodec().encode(registryfriendlybytebuf, object); ++ datacomponenttype.streamCodec().encode(registryfriendlybytebuf, (T) object); // CraftBukkit - decompile error + } + }; + private static final String REMOVED_PREFIX = "!"; +@@ -270,6 +270,38 @@ + + a() {} + ++ // CraftBukkit start ++ public void copy(DataComponentPatch orig) { ++ this.map.putAll(orig.map); ++ } ++ ++ public void clear(DataComponentType type) { ++ this.map.remove(type); ++ } ++ ++ public boolean isEmpty() { ++ return this.map.isEmpty(); ++ } ++ ++ @Override ++ public boolean equals(Object object) { ++ if (this == object) { ++ return true; ++ } ++ ++ if (object instanceof DataComponentPatch.a patch) { ++ return this.map.equals(patch.map); ++ } ++ ++ return false; ++ } ++ ++ @Override ++ public int hashCode() { ++ return this.map.hashCode(); ++ } ++ // CraftBukkit end ++ + public DataComponentPatch.a set(DataComponentType datacomponenttype, T t0) { + this.map.put(datacomponenttype, Optional.of(t0)); + return this; 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 df420f085a..cad1f78630 100644 --- a/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorProjectile.patch +++ b/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorProjectile.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/core/dispenser/DispenseBehaviorProjectile.java +++ b/net/minecraft/core/dispenser/DispenseBehaviorProjectile.java -@@ -8,6 +8,13 @@ - import net.minecraft.world.level.World; +@@ -9,6 +9,13 @@ + import net.minecraft.world.item.ProjectileItem; import net.minecraft.world.level.block.BlockDispenser; +// CraftBukkit start @@ -11,21 +11,21 @@ +import org.bukkit.event.block.BlockDispenseEvent; +// CraftBukkit end + - public abstract class DispenseBehaviorProjectile extends DispenseBehaviorItem { + public class DispenseBehaviorProjectile extends DispenseBehaviorItem { - public DispenseBehaviorProjectile() {} -@@ -19,9 +26,38 @@ - EnumDirection enumdirection = (EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING); - IProjectile iprojectile = this.getProjectile(worldserver, iposition, itemstack); + private final ProjectileItem projectileItem; +@@ -32,9 +39,38 @@ + IPosition iposition = this.dispenseConfig.positionFunction().getDispensePosition(sourceblock, enumdirection); + IProjectile iprojectile = this.projectileItem.asProjectile(worldserver, iposition, itemstack, enumdirection); -- iprojectile.shoot((double) enumdirection.getStepX(), (double) ((float) enumdirection.getStepY() + 0.1F), (double) enumdirection.getStepZ(), this.getPower(), this.getUncertainty()); +- this.projectileItem.shoot(iprojectile, (double) enumdirection.getStepX(), (double) enumdirection.getStepY(), (double) enumdirection.getStepZ(), this.dispenseConfig.power(), this.dispenseConfig.uncertainty()); + // CraftBukkit start -+ // iprojectile.shoot((double) enumdirection.getStepX(), (double) ((float) enumdirection.getStepY() + 0.1F), (double) enumdirection.getStepZ(), this.getPower(), this.getUncertainty()); ++ // this.projectileItem.shoot(iprojectile, (double) enumdirection.getStepX(), (double) enumdirection.getStepY(), (double) enumdirection.getStepZ(), this.dispenseConfig.power(), this.dispenseConfig.uncertainty()); + ItemStack itemstack1 = itemstack.split(1); + org.bukkit.block.Block block = CraftBlock.at(worldserver, sourceblock.pos()); + CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1); + -+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector((double) enumdirection.getStepX(), (double) ((float) enumdirection.getStepY() + 0.1F), (double) enumdirection.getStepZ())); ++ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector((double) enumdirection.getStepX(), (double) enumdirection.getStepY(), (double) enumdirection.getStepZ())); + if (!BlockDispenser.eventFired) { + worldserver.getCraftServer().getPluginManager().callEvent(event); + } @@ -46,7 +46,7 @@ + } + } + -+ iprojectile.shoot(event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), this.getPower(), this.getUncertainty()); ++ this.projectileItem.shoot(iprojectile, 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); 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 7db9555285..74cefdd763 100644 --- a/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorShears.patch +++ b/paper-server/nms-patches/net/minecraft/core/dispenser/DispenseBehaviorShears.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/core/dispenser/DispenseBehaviorShears.java +++ b/net/minecraft/core/dispenser/DispenseBehaviorShears.java -@@ -22,6 +22,13 @@ +@@ -23,6 +23,13 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.AxisAlignedBB; @@ -14,7 +14,7 @@ public class DispenseBehaviorShears extends DispenseBehaviorMaybe { public DispenseBehaviorShears() {} -@@ -29,11 +36,34 @@ +@@ -30,11 +37,34 @@ @Override protected ItemStack execute(SourceBlock sourceblock, ItemStack itemstack) { WorldServer worldserver = sourceblock.level(); @@ -47,10 +47,10 @@ - this.setSuccess(tryShearBeehive(worldserver, blockposition) || tryShearLivingEntity(worldserver, blockposition)); + this.setSuccess(tryShearBeehive(worldserver, blockposition) || tryShearLivingEntity(worldserver, blockposition, bukkitBlock, craftItem)); // CraftBukkit - if (this.isSuccess() && itemstack.hurt(1, worldserver.getRandom(), (EntityPlayer) null)) { - itemstack.setCount(0); - } -@@ -62,7 +92,7 @@ + if (this.isSuccess()) { + itemstack.hurtAndBreak(1, worldserver.getRandom(), (EntityPlayer) null, () -> { + itemstack.setCount(0); +@@ -65,7 +95,7 @@ return false; } @@ -59,9 +59,9 @@ List list = worldserver.getEntitiesOfClass(EntityLiving.class, new AxisAlignedBB(blockposition), IEntitySelector.NO_SPECTATORS); Iterator iterator = list.iterator(); -@@ -73,6 +103,11 @@ - IShearable ishearable = (IShearable) entityliving; +@@ -74,6 +104,11 @@ + if (entityliving instanceof IShearable ishearable) { if (ishearable.readyForShearing()) { + // CraftBukkit start + if (CraftEventFactory.callBlockShearEntityEvent(entityliving, bukkitBlock, craftItem).isCancelled()) { @@ -69,5 +69,5 @@ + } + // CraftBukkit end ishearable.shear(SoundCategory.BLOCKS); - worldserver.gameEvent((Entity) null, GameEvent.SHEAR, blockposition); + worldserver.gameEvent((Entity) null, (Holder) GameEvent.SHEAR, blockposition); return true; 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 4a9d4f7e2e..20c555d68a 100644 --- a/paper-server/nms-patches/net/minecraft/core/dispenser/IDispenseBehavior.patch +++ b/paper-server/nms-patches/net/minecraft/core/dispenser/IDispenseBehavior.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/core/dispenser/IDispenseBehavior.java +++ b/net/minecraft/core/dispenser/IDispenseBehavior.java -@@ -77,6 +77,22 @@ - import net.minecraft.world.phys.Vec3D; +@@ -66,6 +66,22 @@ + import net.minecraft.world.phys.MovingObjectPositionBlock; import org.slf4j.Logger; +// CraftBukkit start @@ -23,9 +23,9 @@ public interface IDispenseBehavior { Logger LOGGER = LogUtils.getLogger(); -@@ -201,14 +217,42 @@ +@@ -93,14 +109,42 @@ EnumDirection enumdirection = (EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING); - EntityTypes entitytypes = ((ItemMonsterEgg) itemstack.getItem()).getType(itemstack.getTag()); + EntityTypes entitytypes = ((ItemMonsterEgg) itemstack.getItem()).getType(itemstack); + // CraftBukkit start + WorldServer worldserver = sourceblock.level(); @@ -65,10 +65,10 @@ - itemstack.shrink(1); + // itemstack.shrink(1); // Handled during event processing + // CraftBukkit end - sourceblock.level().gameEvent((Entity) null, GameEvent.ENTITY_PLACE, sourceblock.pos()); + sourceblock.level().gameEvent((Entity) null, (Holder) GameEvent.ENTITY_PLACE, sourceblock.pos()); return itemstack; } -@@ -227,13 +271,41 @@ +@@ -119,13 +163,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, itemstack.getTag(), consumer, blockposition, EnumMobSpawn.DISPENSER, false, false); + EntityArmorStand entityarmorstand = (EntityArmorStand) EntityTypes.ARMOR_STAND.spawn(worldserver, consumer, blockposition, EnumMobSpawn.DISPENSER, false, false); if (entityarmorstand != null) { - itemstack.shrink(1); @@ -111,13 +111,13 @@ } return itemstack; -@@ -254,8 +326,35 @@ +@@ -144,8 +216,35 @@ }); if (!list.isEmpty()) { + // CraftBukkit start + ItemStack itemstack1 = itemstack.split(1); -+ World world = sourceblock.level(); ++ WorldServer world = sourceblock.level(); + org.bukkit.block.Block block = CraftBlock.at(world, sourceblock.pos()); + CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1); + @@ -148,14 +148,14 @@ this.setSuccess(true); return itemstack; } else { -@@ -282,7 +381,35 @@ +@@ -172,7 +271,35 @@ entityhorseabstract = (EntityHorseAbstract) iterator1.next(); - } while (!entityhorseabstract.isArmor(itemstack) || entityhorseabstract.isWearingArmor() || !entityhorseabstract.isTamed()); + } while (!entityhorseabstract.isBodyArmorItem(itemstack) || entityhorseabstract.isWearingBodyArmor() || !entityhorseabstract.isTamed()); -- entityhorseabstract.getSlot(401).set(itemstack.split(1)); +- entityhorseabstract.setBodyArmorItem(itemstack.split(1)); + // CraftBukkit start + ItemStack itemstack1 = itemstack.split(1); -+ World world = sourceblock.level(); ++ WorldServer world = sourceblock.level(); + org.bukkit.block.Block block = CraftBlock.at(world, sourceblock.pos()); + CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1); + @@ -180,12 +180,12 @@ + } + } + -+ entityhorseabstract.getSlot(401).set(CraftItemStack.asNMSCopy(event.getItem())); ++ entityhorseabstract.setBodyArmorItem(CraftItemStack.asNMSCopy(event.getItem())); + // CraftBukkit end this.setSuccess(true); return itemstack; } -@@ -325,9 +452,35 @@ +@@ -215,9 +342,35 @@ } entityhorsechestedabstract = (EntityHorseChestedAbstract) iterator1.next(); @@ -193,7 +193,7 @@ + // CraftBukkit start + } while (!entityhorsechestedabstract.isTamed()); + ItemStack itemstack1 = itemstack.split(1); -+ World world = sourceblock.level(); ++ WorldServer world = sourceblock.level(); + org.bukkit.block.Block block = CraftBlock.at(world, sourceblock.pos()); + CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1); @@ -223,96 +223,7 @@ this.setSuccess(true); return itemstack; } -@@ -336,12 +489,41 @@ - @Override - public ItemStack execute(SourceBlock sourceblock, ItemStack itemstack) { - EnumDirection enumdirection = (EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING); -+ // CraftBukkit start -+ WorldServer worldserver = sourceblock.level(); -+ ItemStack itemstack1 = itemstack.split(1); -+ org.bukkit.block.Block block = CraftBlock.at(worldserver, sourceblock.pos()); -+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1); -+ -+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(enumdirection.getStepX(), enumdirection.getStepY(), enumdirection.getStepZ())); -+ 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()); - Vec3D vec3d = IDispenseBehavior.getEntityPokingOutOfBlockPos(sourceblock, EntityTypes.FIREWORK_ROCKET, enumdirection); - EntityFireworks entityfireworks = new EntityFireworks(sourceblock.level(), itemstack, vec3d.x(), vec3d.y(), vec3d.z(), true); - - entityfireworks.shoot((double) enumdirection.getStepX(), (double) enumdirection.getStepY(), (double) enumdirection.getStepZ(), 0.5F, 1.0F); - sourceblock.level().addFreshEntity(entityfireworks); -- itemstack.shrink(1); -+ // itemstack.shrink(1); // Handled during event processing -+ // CraftBukkit end - return itemstack; - } - -@@ -363,12 +545,40 @@ - double d3 = randomsource.triangle((double) enumdirection.getStepX(), 0.11485000000000001D); - double d4 = randomsource.triangle((double) enumdirection.getStepY(), 0.11485000000000001D); - double d5 = randomsource.triangle((double) enumdirection.getStepZ(), 0.11485000000000001D); -- EntitySmallFireball entitysmallfireball = new EntitySmallFireball(worldserver, d0, d1, d2, d3, d4, d5); - -- worldserver.addFreshEntity((Entity) SystemUtils.make(entitysmallfireball, (entitysmallfireball1) -> { -- entitysmallfireball1.setItem(itemstack); -- })); -- itemstack.shrink(1); -+ // CraftBukkit start -+ ItemStack itemstack1 = itemstack.split(1); -+ org.bukkit.block.Block block = CraftBlock.at(worldserver, sourceblock.pos()); -+ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1); -+ -+ BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(d3, d4, d5)); -+ 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; -+ } -+ } -+ -+ EntitySmallFireball entitysmallfireball = new EntitySmallFireball(worldserver, d0, d1, d2, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ()); -+ entitysmallfireball.setItem(itemstack1); -+ entitysmallfireball.projectileSource = new org.bukkit.craftbukkit.projectiles.CraftBlockProjectileSource(sourceblock.blockEntity()); -+ -+ worldserver.addFreshEntity(entitysmallfireball); -+ // itemstack.shrink(1); // Handled during event processing -+ // CraftBukkit end - return itemstack; - } - -@@ -404,9 +614,51 @@ +@@ -249,9 +402,51 @@ BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING)); WorldServer worldserver = sourceblock.level(); @@ -365,17 +276,17 @@ } else { return this.defaultDispenseItemBehavior.dispense(sourceblock, itemstack); } -@@ -434,7 +686,7 @@ +@@ -278,7 +473,7 @@ + Block block = iblockdata.getBlock(); - if (block instanceof IFluidSource) { - IFluidSource ifluidsource = (IFluidSource) block; + if (block instanceof IFluidSource ifluidsource) { - ItemStack itemstack1 = ifluidsource.pickupBlock((EntityHuman) null, worldserver, blockposition, iblockdata); + ItemStack itemstack1 = ifluidsource.pickupBlock((EntityHuman) null, DummyGeneratorAccess.INSTANCE, blockposition, iblockdata); // CraftBukkit if (itemstack1.isEmpty()) { return super.execute(sourceblock, itemstack); -@@ -442,6 +694,32 @@ - worldserver.gameEvent((Entity) null, GameEvent.FLUID_PICKUP, blockposition); +@@ -286,6 +481,32 @@ + worldserver.gameEvent((Entity) null, (Holder) GameEvent.FLUID_PICKUP, blockposition); Item item = itemstack1.getItem(); + // CraftBukkit start @@ -407,7 +318,7 @@ itemstack.shrink(1); if (itemstack.isEmpty()) { return new ItemStack(item); -@@ -463,16 +741,44 @@ +@@ -307,16 +528,44 @@ protected ItemStack execute(SourceBlock sourceblock, ItemStack itemstack) { WorldServer worldserver = sourceblock.level(); @@ -442,11 +353,11 @@ if (BlockFireAbstract.canBePlacedAt(worldserver, blockposition, enumdirection)) { - worldserver.setBlockAndUpdate(blockposition, BlockFireAbstract.getState(worldserver, blockposition)); -- worldserver.gameEvent((Entity) null, GameEvent.BLOCK_PLACE, blockposition); +- worldserver.gameEvent((Entity) null, (Holder) GameEvent.BLOCK_PLACE, blockposition); + // CraftBukkit start - Ignition by dispensing flint and steel + if (!org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(worldserver, blockposition, sourceblock.pos()).isCancelled()) { + worldserver.setBlockAndUpdate(blockposition, BlockFireAbstract.getState(worldserver, blockposition)); -+ worldserver.gameEvent((Entity) null, GameEvent.BLOCK_PLACE, blockposition); ++ worldserver.gameEvent((Entity) null, (Holder) GameEvent.BLOCK_PLACE, blockposition); + } + // CraftBukkit end } else if (!BlockCampfire.canLight(iblockdata) && !CandleBlock.canLight(iblockdata) && !CandleCakeBlock.canLight(iblockdata)) { @@ -455,7 +366,7 @@ BlockTNT.explode(worldserver, blockposition); worldserver.removeBlock(blockposition, false); } else { -@@ -496,12 +802,62 @@ +@@ -342,12 +591,62 @@ this.setSuccess(true); WorldServer worldserver = sourceblock.level(); BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING)); @@ -488,7 +399,7 @@ if (!ItemBoneMeal.growCrop(itemstack, worldserver, blockposition) && !ItemBoneMeal.growWaterPlant(itemstack, worldserver, blockposition, (EnumDirection) null)) { this.setSuccess(false); } else if (!worldserver.isClientSide) { - worldserver.levelEvent(1505, blockposition, 0); + worldserver.levelEvent(1505, blockposition, 15); } + // CraftBukkit start + worldserver.captureTreeGeneration = false; @@ -518,7 +429,7 @@ return itemstack; } -@@ -511,12 +867,41 @@ +@@ -357,12 +656,41 @@ protected ItemStack execute(SourceBlock sourceblock, ItemStack itemstack) { WorldServer worldserver = sourceblock.level(); BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING)); @@ -556,13 +467,13 @@ worldserver.addFreshEntity(entitytntprimed); worldserver.playSound((EntityHuman) null, entitytntprimed.getX(), entitytntprimed.getY(), entitytntprimed.getZ(), SoundEffects.TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F); - worldserver.gameEvent((Entity) null, GameEvent.ENTITY_PLACE, blockposition); + worldserver.gameEvent((Entity) null, (Holder) GameEvent.ENTITY_PLACE, blockposition); - itemstack.shrink(1); + // itemstack.shrink(1); // CraftBukkit - handled above return itemstack; } }); -@@ -541,6 +926,30 @@ +@@ -387,6 +715,30 @@ EnumDirection enumdirection = (EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING); BlockPosition blockposition = sourceblock.pos().relative(enumdirection); @@ -592,8 +503,8 @@ + 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, GameEvent.BLOCK_PLACE, blockposition); -@@ -566,6 +975,30 @@ + worldserver.gameEvent((Entity) null, (Holder) GameEvent.BLOCK_PLACE, blockposition); +@@ -412,6 +764,30 @@ BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING)); BlockPumpkinCarved blockpumpkincarved = (BlockPumpkinCarved) Blocks.CARVED_PUMPKIN; @@ -624,7 +535,7 @@ if (worldserver.isEmptyBlock(blockposition) && blockpumpkincarved.canSpawnGolem(worldserver, blockposition)) { if (!worldserver.isClientSide) { worldserver.setBlock(blockposition, blockpumpkincarved.defaultBlockState(), 3); -@@ -615,6 +1048,30 @@ +@@ -461,6 +837,30 @@ BlockPosition blockposition = sourceblock.pos().relative((EnumDirection) sourceblock.state().getValue(BlockDispenser.FACING)); IBlockData iblockdata = worldserver.getBlockState(blockposition); @@ -655,3 +566,35 @@ 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) { +@@ -510,6 +910,31 @@ + this.setSuccess(false); + return itemstack; + } else { ++ // CraftBukkit start ++ ItemStack itemstack1 = itemstack; ++ WorldServer world = sourceblock.level(); ++ org.bukkit.block.Block block = CraftBlock.at(world, sourceblock.pos()); ++ CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1); ++ ++ BlockDispenseEvent event = new BlockDispenseArmorEvent(block, craftItem.clone(), (org.bukkit.craftbukkit.entity.CraftLivingEntity) list.get(0).getBukkitEntity()); ++ if (!BlockDispenser.eventFired) { ++ world.getCraftServer().getPluginManager().callEvent(event); ++ } ++ ++ if (event.isCancelled()) { ++ return itemstack; ++ } ++ ++ if (!event.getItem().equals(craftItem)) { ++ // 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; ++ } ++ } ++ // CraftBukkit end + Iterator iterator1 = list.iterator(); + + Armadillo armadillo; diff --git a/paper-server/nms-patches/net/minecraft/nbt/NBTTagList.patch b/paper-server/nms-patches/net/minecraft/nbt/NBTTagList.patch deleted file mode 100644 index 0281b565c8..0000000000 --- a/paper-server/nms-patches/net/minecraft/nbt/NBTTagList.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/net/minecraft/nbt/NBTTagList.java -+++ b/net/minecraft/nbt/NBTTagList.java -@@ -145,7 +145,7 @@ - private final List list; - private byte type; - -- NBTTagList(List list, byte b0) { -+ public NBTTagList(List list, byte b0) { // PAIL: package-private -> public - this.list = list; - this.type = b0; - } diff --git a/paper-server/nms-patches/net/minecraft/network/NetworkManager.patch b/paper-server/nms-patches/net/minecraft/network/NetworkManager.patch index fb4e0c61d1..ce47080818 100644 --- a/paper-server/nms-patches/net/minecraft/network/NetworkManager.patch +++ b/paper-server/nms-patches/net/minecraft/network/NetworkManager.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/network/NetworkManager.java +++ b/net/minecraft/network/NetworkManager.java -@@ -105,6 +105,7 @@ +@@ -114,6 +114,7 @@ private volatile IChatBaseComponent delayedDisconnect; @Nullable BandwidthDebugMonitor bandwidthDebugMonitor; @@ -8,7 +8,7 @@ public NetworkManager(EnumProtocolDirection enumprotocoldirection) { this.receiving = enumprotocoldirection; -@@ -194,7 +195,7 @@ +@@ -197,7 +198,7 @@ } private static void genericsFtw(Packet packet, PacketListener packetlistener) { @@ -16,8 +16,8 @@ + packet.handle((T) packetlistener); // CraftBukkit - decompile error } - public void suspendInboundAfterProtocolChange() { -@@ -421,7 +422,7 @@ + private void validateListener(ProtocolInfo protocolinfo, PacketListener packetlistener) { +@@ -457,7 +458,7 @@ } if (this.isConnected()) { @@ -26,3 +26,12 @@ this.disconnectedReason = ichatbasecomponent; } +@@ -525,7 +526,7 @@ + } + + public void configurePacketHandler(ChannelPipeline channelpipeline) { +- channelpipeline.addLast("hackfix", new ChannelOutboundHandlerAdapter(this) { ++ channelpipeline.addLast("hackfix", new ChannelOutboundHandlerAdapter() { // CraftBukkit - decompile error + public void write(ChannelHandlerContext channelhandlercontext, Object object, ChannelPromise channelpromise) throws Exception { + super.write(channelhandlercontext, object, channelpromise); + } diff --git a/paper-server/nms-patches/net/minecraft/network/PacketDataSerializer.patch b/paper-server/nms-patches/net/minecraft/network/PacketDataSerializer.patch index 560385097a..37573090e5 100644 --- a/paper-server/nms-patches/net/minecraft/network/PacketDataSerializer.patch +++ b/paper-server/nms-patches/net/minecraft/network/PacketDataSerializer.patch @@ -1,33 +1,24 @@ --- a/net/minecraft/network/PacketDataSerializer.java +++ b/net/minecraft/network/PacketDataSerializer.java -@@ -81,6 +81,8 @@ - import org.joml.Quaternionf; - import org.joml.Vector3f; +@@ -139,7 +139,7 @@ -+import org.bukkit.craftbukkit.inventory.CraftItemStack; // CraftBukkit -+ - public class PacketDataSerializer extends ByteBuf { - - public static final int DEFAULT_NBT_QUOTA = 2097152; -@@ -205,7 +207,7 @@ - - public > C readCollection(IntFunction intfunction, PacketDataSerializer.a packetdataserializer_a) { + public > C readCollection(IntFunction intfunction, StreamDecoder streamdecoder) { int i = this.readVarInt(); - C c0 = (Collection) intfunction.apply(i); + C c0 = intfunction.apply(i); // CraftBukkit - decompile error for (int j = 0; j < i; ++j) { - c0.add(packetdataserializer_a.apply(this)); -@@ -216,7 +218,7 @@ + c0.add(streamdecoder.decode(this)); +@@ -150,7 +150,7 @@ - public void writeCollection(Collection collection, PacketDataSerializer.b packetdataserializer_b) { + public void writeCollection(Collection collection, StreamEncoder streamencoder) { this.writeVarInt(collection.size()); - Iterator iterator = collection.iterator(); + Iterator iterator = collection.iterator(); // CraftBukkit - decompile error while (iterator.hasNext()) { T t0 = iterator.next(); -@@ -243,12 +245,12 @@ +@@ -177,12 +177,12 @@ public void writeIntIdList(IntList intlist) { this.writeVarInt(intlist.size()); @@ -35,14 +26,14 @@ + intlist.forEach((java.util.function.IntConsumer) this::writeVarInt); // CraftBukkit - decompile error } - public > M readMap(IntFunction intfunction, PacketDataSerializer.a packetdataserializer_a, PacketDataSerializer.a packetdataserializer_a1) { + public > M readMap(IntFunction intfunction, StreamDecoder streamdecoder, StreamDecoder streamdecoder1) { int i = this.readVarInt(); - M m0 = (Map) intfunction.apply(i); + M m0 = intfunction.apply(i); // CraftBukkit - decompile error for (int j = 0; j < i; ++j) { - K k0 = packetdataserializer_a.apply(this); -@@ -282,7 +284,7 @@ + K k0 = streamdecoder.decode(this); +@@ -216,7 +216,7 @@ } public > void writeEnumSet(EnumSet enumset, Class oclass) { @@ -51,7 +42,7 @@ BitSet bitset = new BitSet(ae.length); for (int i = 0; i < ae.length; ++i) { -@@ -293,7 +295,7 @@ +@@ -227,7 +227,7 @@ } public > EnumSet readEnumSet(Class oclass) { @@ -60,7 +51,7 @@ BitSet bitset = this.readFixedBitSet(ae.length); EnumSet enumset = EnumSet.noneOf(oclass); -@@ -529,7 +531,7 @@ +@@ -482,7 +482,7 @@ } public > T readEnum(Class oclass) { @@ -69,33 +60,12 @@ } public PacketDataSerializer writeEnum(Enum oenum) { -@@ -584,7 +586,7 @@ +@@ -549,7 +549,7 @@ + try { - NBTCompressedStreamTools.writeAnyTag((NBTBase) nbtbase, new ByteBufOutputStream(this)); - return this; + NBTCompressedStreamTools.writeAnyTag((NBTBase) nbtbase, new ByteBufOutputStream(bytebuf)); - } catch (IOException ioexception) { + } catch (Exception ioexception) { // CraftBukkit - IOException -> Exception throw new EncoderException(ioexception); } } -@@ -612,7 +614,7 @@ - } - - public PacketDataSerializer writeItem(ItemStack itemstack) { -- if (itemstack.isEmpty()) { -+ if (itemstack.isEmpty() || itemstack.getItem() == null) { // CraftBukkit - NPE fix itemstack.getItem() - this.writeBoolean(false); - } else { - this.writeBoolean(true); -@@ -641,6 +643,11 @@ - ItemStack itemstack = new ItemStack(item, b0); - - itemstack.setTag(this.readNbt()); -+ // CraftBukkit start -+ if (itemstack.getTag() != null) { -+ CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack)); -+ } -+ // CraftBukkit end - return itemstack; - } - } diff --git a/paper-server/nms-patches/net/minecraft/network/protocol/PlayerConnectionUtils.patch b/paper-server/nms-patches/net/minecraft/network/protocol/PlayerConnectionUtils.patch index 467aceeafb..56cd482b40 100644 --- a/paper-server/nms-patches/net/minecraft/network/protocol/PlayerConnectionUtils.patch +++ b/paper-server/nms-patches/net/minecraft/network/protocol/PlayerConnectionUtils.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/network/protocol/PlayerConnectionUtils.java +++ b/net/minecraft/network/protocol/PlayerConnectionUtils.java -@@ -9,6 +9,11 @@ +@@ -10,6 +10,11 @@ import net.minecraft.util.thread.IAsyncTaskHandler; import org.slf4j.Logger; @@ -12,7 +12,7 @@ public class PlayerConnectionUtils { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -22,6 +27,7 @@ +@@ -23,6 +28,7 @@ public static void ensureRunningOnSameThread(Packet packet, T t0, IAsyncTaskHandler iasynctaskhandler) throws CancelledPacketHandleException { if (!iasynctaskhandler.isSameThread()) { iasynctaskhandler.executeIfPossible(() -> { diff --git a/paper-server/nms-patches/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.patch b/paper-server/nms-patches/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.patch deleted file mode 100644 index f4712b4d08..0000000000 --- a/paper-server/nms-patches/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.patch +++ /dev/null @@ -1,43 +0,0 @@ ---- a/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java -+++ b/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java -@@ -12,7 +12,7 @@ - public record ServerboundCustomPayloadPacket(CustomPacketPayload payload) implements Packet { - - private static final int MAX_PAYLOAD_SIZE = 32767; -- private static final Map> KNOWN_TYPES = ImmutableMap.builder().put(BrandPayload.ID, BrandPayload::new).build(); -+ private static final Map> KNOWN_TYPES = ImmutableMap.>builder().build(); // CraftBukkit - no special handling - - public ServerboundCustomPayloadPacket(PacketDataSerializer packetdataserializer) { - this(readPayload(packetdataserializer.readResourceLocation(), packetdataserializer)); -@@ -24,12 +24,13 @@ - return (CustomPacketPayload) (packetdataserializer_a != null ? (CustomPacketPayload) packetdataserializer_a.apply(packetdataserializer) : readUnknownPayload(minecraftkey, packetdataserializer)); - } - -- private static DiscardedPayload readUnknownPayload(MinecraftKey minecraftkey, PacketDataSerializer packetdataserializer) { -+ private static UnknownPayload readUnknownPayload(MinecraftKey minecraftkey, PacketDataSerializer packetdataserializer) { // CraftBukkit - int i = packetdataserializer.readableBytes(); - - if (i >= 0 && i <= 32767) { -- packetdataserializer.skipBytes(i); -- return new DiscardedPayload(minecraftkey); -+ // CraftBukkit start -+ return new UnknownPayload(minecraftkey, packetdataserializer.readBytes(i)); -+ // CraftBukkit end - } else { - throw new IllegalArgumentException("Payload may not be larger than 32767 bytes"); - } -@@ -44,4 +45,14 @@ - public void handle(ServerCommonPacketListener servercommonpacketlistener) { - servercommonpacketlistener.handleCustomPayload(this); - } -+ -+ // CraftBukkit start -+ public record UnknownPayload(MinecraftKey id, io.netty.buffer.ByteBuf data) implements CustomPacketPayload { -+ -+ @Override -+ public void write(PacketDataSerializer packetdataserializer) { -+ packetdataserializer.writeBytes(data); -+ } -+ } -+ // CraftBukkit end - } diff --git a/paper-server/nms-patches/net/minecraft/network/protocol/common/custom/DiscardedPayload.patch b/paper-server/nms-patches/net/minecraft/network/protocol/common/custom/DiscardedPayload.patch new file mode 100644 index 0000000000..c6b3d3ebe4 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/network/protocol/common/custom/DiscardedPayload.patch @@ -0,0 +1,24 @@ +--- a/net/minecraft/network/protocol/common/custom/DiscardedPayload.java ++++ b/net/minecraft/network/protocol/common/custom/DiscardedPayload.java +@@ -4,16 +4,18 @@ + import net.minecraft.network.codec.StreamCodec; + import net.minecraft.resources.MinecraftKey; + +-public record DiscardedPayload(MinecraftKey id) implements CustomPacketPayload { ++public record DiscardedPayload(MinecraftKey id, io.netty.buffer.ByteBuf data) implements CustomPacketPayload { // CraftBukkit - store data + + public static StreamCodec codec(MinecraftKey minecraftkey, int i) { + return CustomPacketPayload.codec((discardedpayload, packetdataserializer) -> { ++ packetdataserializer.writeBytes(discardedpayload.data); // CraftBukkit - serialize + }, (packetdataserializer) -> { + int j = packetdataserializer.readableBytes(); + + if (j >= 0 && j <= i) { +- packetdataserializer.skipBytes(j); +- return new DiscardedPayload(minecraftkey); ++ // CraftBukkit start ++ return new DiscardedPayload(minecraftkey, packetdataserializer.readBytes(j)); ++ // CraftBukkit end + } else { + throw new IllegalArgumentException("Payload may not be larger than " + i + " bytes"); + } diff --git a/paper-server/nms-patches/net/minecraft/network/protocol/game/ClientboundInitializeBorderPacket.patch b/paper-server/nms-patches/net/minecraft/network/protocol/game/ClientboundInitializeBorderPacket.patch index fa0dc08cc7..61b3f3b221 100644 --- a/paper-server/nms-patches/net/minecraft/network/protocol/game/ClientboundInitializeBorderPacket.patch +++ b/paper-server/nms-patches/net/minecraft/network/protocol/game/ClientboundInitializeBorderPacket.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/network/protocol/game/ClientboundInitializeBorderPacket.java +++ b/net/minecraft/network/protocol/game/ClientboundInitializeBorderPacket.java -@@ -27,8 +27,10 @@ +@@ -30,8 +30,10 @@ } public ClientboundInitializeBorderPacket(WorldBorder worldborder) { diff --git a/paper-server/nms-patches/net/minecraft/network/protocol/game/ClientboundSetBorderCenterPacket.patch b/paper-server/nms-patches/net/minecraft/network/protocol/game/ClientboundSetBorderCenterPacket.patch index abf12e82da..ecc14ffea2 100644 --- a/paper-server/nms-patches/net/minecraft/network/protocol/game/ClientboundSetBorderCenterPacket.patch +++ b/paper-server/nms-patches/net/minecraft/network/protocol/game/ClientboundSetBorderCenterPacket.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/network/protocol/game/ClientboundSetBorderCenterPacket.java +++ b/net/minecraft/network/protocol/game/ClientboundSetBorderCenterPacket.java -@@ -10,8 +10,10 @@ +@@ -13,8 +13,10 @@ private final double newCenterZ; public ClientboundSetBorderCenterPacket(WorldBorder worldborder) { @@ -12,4 +12,4 @@ + // CraftBukkit end } - public ClientboundSetBorderCenterPacket(PacketDataSerializer packetdataserializer) { + private ClientboundSetBorderCenterPacket(PacketDataSerializer packetdataserializer) { diff --git a/paper-server/nms-patches/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.patch b/paper-server/nms-patches/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.patch index 380b8686c6..362eebf617 100644 --- a/paper-server/nms-patches/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.patch +++ b/paper-server/nms-patches/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.patch @@ -4,4 +4,4 @@ +// mc-dev import package net.minecraft.network.protocol.game; - import net.minecraft.network.PacketDataSerializer; + import net.minecraft.network.RegistryFriendlyByteBuf; diff --git a/paper-server/nms-patches/net/minecraft/network/protocol/game/PacketPlayOutMultiBlockChange.patch b/paper-server/nms-patches/net/minecraft/network/protocol/game/PacketPlayOutMultiBlockChange.patch index 06f07964d1..15a1ae262f 100644 --- a/paper-server/nms-patches/net/minecraft/network/protocol/game/PacketPlayOutMultiBlockChange.patch +++ b/paper-server/nms-patches/net/minecraft/network/protocol/game/PacketPlayOutMultiBlockChange.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/network/protocol/game/PacketPlayOutMultiBlockChange.java +++ b/net/minecraft/network/protocol/game/PacketPlayOutMultiBlockChange.java -@@ -30,11 +30,19 @@ +@@ -33,11 +33,19 @@ short short0 = (Short) shortiterator.next(); this.positions[j] = short0; @@ -18,6 +18,6 @@ + } + // CraftBukkit end + - public PacketPlayOutMultiBlockChange(PacketDataSerializer packetdataserializer) { + private PacketPlayOutMultiBlockChange(PacketDataSerializer packetdataserializer) { this.sectionPos = SectionPosition.of(packetdataserializer.readLong()); int i = packetdataserializer.readVarInt(); diff --git a/paper-server/nms-patches/net/minecraft/network/protocol/handshake/PacketHandshakingInSetProtocol.patch b/paper-server/nms-patches/net/minecraft/network/protocol/handshake/PacketHandshakingInSetProtocol.patch index 3ab554b774..01082820bd 100644 --- a/paper-server/nms-patches/net/minecraft/network/protocol/handshake/PacketHandshakingInSetProtocol.patch +++ b/paper-server/nms-patches/net/minecraft/network/protocol/handshake/PacketHandshakingInSetProtocol.patch @@ -4,4 +4,4 @@ +// mc-dev import package net.minecraft.network.protocol.handshake; - import net.minecraft.network.EnumProtocol; + import net.minecraft.network.PacketDataSerializer; diff --git a/paper-server/nms-patches/net/minecraft/network/syncher/DataWatcher.patch b/paper-server/nms-patches/net/minecraft/network/syncher/DataWatcher.patch index a818feaeda..309bde763f 100644 --- a/paper-server/nms-patches/net/minecraft/network/syncher/DataWatcher.patch +++ b/paper-server/nms-patches/net/minecraft/network/syncher/DataWatcher.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/network/syncher/DataWatcher.java +++ b/net/minecraft/network/syncher/DataWatcher.java -@@ -24,6 +24,11 @@ +@@ -14,6 +14,11 @@ import org.apache.commons.lang3.ObjectUtils; import org.slf4j.Logger; @@ -12,7 +12,16 @@ public class DataWatcher { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -146,6 +151,13 @@ +@@ -51,7 +56,7 @@ + } + + private DataWatcher.Item getItem(DataWatcherObject datawatcherobject) { +- return this.itemsById[datawatcherobject.id()]; ++ return (DataWatcher.Item) this.itemsById[datawatcherobject.id()]; // CraftBukkit - decompile error + } + + public T get(DataWatcherObject datawatcherobject) { +@@ -74,6 +79,13 @@ } @@ -26,40 +35,12 @@ public boolean isDirty() { return this.isDirty; } -@@ -227,7 +239,7 @@ - if (!Objects.equals(datawatcher_b.serializer(), datawatcher_item.accessor.getSerializer())) { - throw new IllegalStateException(String.format(Locale.ROOT, "Invalid entity data item type for field %d on entity %s: old=%s(%s), new=%s(%s)", datawatcher_item.accessor.getId(), this.entity, datawatcher_item.value, datawatcher_item.value.getClass(), datawatcher_b.value, datawatcher_b.value.getClass())); +@@ -140,7 +152,7 @@ + if (!Objects.equals(datawatcher_c.serializer(), datawatcher_item.accessor.serializer())) { + throw new IllegalStateException(String.format(Locale.ROOT, "Invalid entity data item type for field %d on entity %s: old=%s(%s), new=%s(%s)", datawatcher_item.accessor.id(), this.entity, datawatcher_item.value, datawatcher_item.value.getClass(), datawatcher_c.value, datawatcher_c.value.getClass())); } else { -- datawatcher_item.setValue(datawatcher_b.value); -+ datawatcher_item.setValue((T) datawatcher_b.value); // CraftBukkit - decompile error +- datawatcher_item.setValue(datawatcher_c.value); ++ datawatcher_item.setValue((T) datawatcher_c.value); // CraftBukkit - decompile error } } -@@ -235,6 +247,18 @@ - return this.itemsById.isEmpty(); - } - -+ // CraftBukkit start -+ public void refresh(EntityPlayer to) { -+ if (!this.isEmpty()) { -+ List> list = this.getNonDefaultValues(); -+ -+ if (list != null) { -+ to.connection.send(new PacketPlayOutEntityMetadata(this.entity.getId(), list)); -+ } -+ } -+ } -+ // CraftBukkit end -+ - public static class Item { - - final DataWatcherObject accessor; -@@ -277,7 +301,7 @@ - } - } - -- public static record b (int id, DataWatcherSerializer serializer, T value) { -+ public static record b(int id, DataWatcherSerializer serializer, T value) { // CraftBukkit - decompile error - - public static DataWatcher.b create(DataWatcherObject datawatcherobject, T t0) { - DataWatcherSerializer datawatcherserializer = datawatcherobject.getSerializer(); diff --git a/paper-server/nms-patches/net/minecraft/server/DispenserRegistry.patch b/paper-server/nms-patches/net/minecraft/server/DispenserRegistry.patch index e592b70ef9..495bec3dbd 100644 --- a/paper-server/nms-patches/net/minecraft/server/DispenserRegistry.patch +++ b/paper-server/nms-patches/net/minecraft/server/DispenserRegistry.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/DispenserRegistry.java +++ b/net/minecraft/server/DispenserRegistry.java -@@ -30,6 +30,12 @@ +@@ -29,6 +29,12 @@ import net.minecraft.world.level.block.BlockFire; import org.slf4j.Logger; @@ -13,7 +13,7 @@ public class DispenserRegistry { public static final PrintStream STDOUT = System.out; -@@ -41,6 +47,23 @@ +@@ -40,6 +46,23 @@ public static void bootStrap() { if (!DispenserRegistry.isBootstrapped) { @@ -37,7 +37,7 @@ DispenserRegistry.isBootstrapped = true; Instant instant = Instant.now(); -@@ -61,6 +84,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 d89f6deee2..01bf23cac7 100644 --- a/paper-server/nms-patches/net/minecraft/server/Main.patch +++ b/paper-server/nms-patches/net/minecraft/server/Main.patch @@ -29,13 +29,13 @@ OptionParser optionparser = new OptionParser(); OptionSpec optionspec = optionparser.accepts("nogui"); OptionSpec optionspec1 = optionparser.accepts("initSettings", "Initializes 'server.properties' and 'eula.txt', then quits"); -@@ -93,15 +105,18 @@ +@@ -94,15 +106,18 @@ optionparser.printHelpOn(System.err); return; } + */ // CraftBukkit end -- Path path = (Path) optionset.valueOf(optionspec13); +- Path path = (Path) optionset.valueOf(optionspec14); + try { + + Path path = (Path) optionset.valueOf("pidFile"); // CraftBukkit @@ -45,12 +45,12 @@ } CrashReport.preload(); -- if (optionset.has(optionspec12)) { +- if (optionset.has(optionspec13)) { + if (optionset.has("jfrProfile")) { // CraftBukkit JvmProfiler.INSTANCE.start(Environment.SERVER); } -@@ -109,13 +124,26 @@ +@@ -110,14 +125,27 @@ DispenserRegistry.validate(); SystemUtils.startTimerHackThread(); Path path1 = Paths.get("server.properties"); @@ -58,6 +58,7 @@ + DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(optionset); // CraftBukkit - CLI argument support dedicatedserversettings.forceSave(); + RegionFileCompression.configure(dedicatedserversettings.getProperties().regionFileComression); Path path2 = Paths.get("eula.txt"); EULA eula = new EULA(path2); @@ -79,14 +80,14 @@ Main.LOGGER.info("Initialized '{}' and '{}'", path1.toAbsolutePath(), path2.toAbsolutePath()); return; } -@@ -125,11 +153,13 @@ +@@ -127,11 +155,13 @@ return; } -- File file = new File((String) optionset.valueOf(optionspec8)); +- File file = new File((String) optionset.valueOf(optionspec9)); + File file = (File) optionset.valueOf("universe"); // CraftBukkit Services services = Services.create(new YggdrasilAuthenticationService(Proxy.NO_PROXY), file); -- String s = (String) Optional.ofNullable((String) optionset.valueOf(optionspec9)).orElse(dedicatedserversettings.getProperties().levelName); +- String s = (String) Optional.ofNullable((String) optionset.valueOf(optionspec10)).orElse(dedicatedserversettings.getProperties().levelName); + // CraftBukkit start + String s = (String) Optional.ofNullable((String) optionset.valueOf("world")).orElse(dedicatedserversettings.getProperties().levelName); Convertable convertable = Convertable.createDefault(file.toPath()); @@ -96,11 +97,11 @@ Dynamic dynamic; if (convertable_conversionsession.hasWorldData()) { -@@ -170,13 +200,31 @@ +@@ -172,13 +202,31 @@ } Dynamic dynamic1 = dynamic; -- boolean flag = optionset.has(optionspec6); +- boolean flag = optionset.has(optionspec7); + boolean flag = optionset.has("safeMode"); // CraftBukkit if (flag) { @@ -129,7 +130,7 @@ WorldStem worldstem; -@@ -185,6 +233,7 @@ +@@ -187,6 +235,7 @@ worldstem = (WorldStem) SystemUtils.blockUntilDone((executor) -> { return WorldLoader.load(worldloader_c, (worldloader_a) -> { @@ -137,7 +138,7 @@ IRegistry iregistry = worldloader_a.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM); if (dynamic1 != null) { -@@ -197,7 +246,7 @@ +@@ -199,7 +248,7 @@ WorldOptions worldoptions; WorldDimensions worlddimensions; @@ -146,7 +147,7 @@ worldsettings = MinecraftServer.DEMO_SETTINGS; worldoptions = WorldOptions.DEMO_OPTIONS; worlddimensions = WorldPresets.createNormalWorldDimensions(worldloader_a.datapackWorldgen()); -@@ -205,7 +254,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()); @@ -155,32 +156,32 @@ worlddimensions = dedicatedserverproperties.createDimensions(worldloader_a.datapackWorldgen()); } -@@ -221,6 +270,7 @@ +@@ -223,6 +272,7 @@ return; } + /* IRegistryCustom.Dimension iregistrycustom_dimension = worldstem.registries().compositeAccess(); + boolean flag1 = optionset.has(optionspec6); - if (optionset.has(optionspec4)) { -@@ -232,20 +282,31 @@ +@@ -235,20 +285,31 @@ SaveData savedata = worldstem.worldData(); convertable_conversionsession.saveDataTag(iregistrycustom_dimension, savedata); + */ final DedicatedServer dedicatedserver = (DedicatedServer) MinecraftServer.spin((thread) -> { -- DedicatedServer dedicatedserver1 = new DedicatedServer(thread, convertable_conversionsession, resourcepackrepository, worldstem, dedicatedserversettings, DataConverterRegistry.getDataFixer(), services, WorldLoadListenerLogger::new); -+ DedicatedServer dedicatedserver1 = new DedicatedServer(optionset, worldLoader.get(), thread, convertable_conversionsession, resourcepackrepository, worldstem, dedicatedserversettings, DataConverterRegistry.getDataFixer(), services, WorldLoadListenerLogger::new); +- DedicatedServer dedicatedserver1 = new DedicatedServer(thread, convertable_conversionsession, resourcepackrepository, worldstem, dedicatedserversettings, DataConverterRegistry.getDataFixer(), services, WorldLoadListenerLogger::createFromGameruleRadius); ++ DedicatedServer dedicatedserver1 = new DedicatedServer(optionset, worldLoader.get(), thread, convertable_conversionsession, resourcepackrepository, worldstem, dedicatedserversettings, DataConverterRegistry.getDataFixer(), services, WorldLoadListenerLogger::createFromGameruleRadius); + /* - dedicatedserver1.setPort((Integer) optionset.valueOf(optionspec10)); + dedicatedserver1.setPort((Integer) optionset.valueOf(optionspec11)); dedicatedserver1.setDemo(optionset.has(optionspec2)); - dedicatedserver1.setId((String) optionset.valueOf(optionspec11)); -- boolean flag1 = !optionset.has(optionspec) && !optionset.valuesOf(nonoptionargumentspec).contains("nogui"); + dedicatedserver1.setId((String) optionset.valueOf(optionspec12)); +- boolean flag2 = !optionset.has(optionspec) && !optionset.valuesOf(optionspec15).contains("nogui"); + */ -+ boolean flag1 = !optionset.has("nogui") && !optionset.nonOptionArguments().contains("nogui"); ++ boolean flag2 = !optionset.has("nogui") && !optionset.nonOptionArguments().contains("nogui"); - if (flag1 && !GraphicsEnvironment.isHeadless()) { + if (flag2 && !GraphicsEnvironment.isHeadless()) { dedicatedserver1.showGui(); } @@ -197,7 +198,7 @@ Thread thread = new Thread("Server Shutdown Thread") { public void run() { dedicatedserver.halt(true); -@@ -254,6 +315,7 @@ +@@ -257,6 +318,7 @@ thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(Main.LOGGER)); Runtime.getRuntime().addShutdownHook(thread); @@ -205,12 +206,12 @@ } catch (Exception exception1) { Main.LOGGER.error(LogUtils.FATAL_MARKER, "Failed to start the minecraft server", exception1); } -@@ -290,7 +352,7 @@ +@@ -293,7 +355,7 @@ } - public static void forceUpgrade(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, boolean flag, BooleanSupplier booleansupplier, IRegistry iregistry) { + public static void forceUpgrade(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, boolean flag, BooleanSupplier booleansupplier, IRegistryCustom iregistrycustom, boolean flag1) { - Main.LOGGER.info("Forcing world upgrade!"); + Main.LOGGER.info("Forcing world upgrade! {}", convertable_conversionsession.getLevelId()); // CraftBukkit - WorldUpgrader worldupgrader = new WorldUpgrader(convertable_conversionsession, datafixer, iregistry, flag); + WorldUpgrader worldupgrader = new WorldUpgrader(convertable_conversionsession, datafixer, iregistrycustom, flag, flag1); IChatBaseComponent ichatbasecomponent = null; diff --git a/paper-server/nms-patches/net/minecraft/server/MinecraftServer.patch b/paper-server/nms-patches/net/minecraft/server/MinecraftServer.patch index 204547502c..77acf286fc 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 -@@ -165,13 +165,36 @@ +@@ -168,13 +168,37 @@ import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; @@ -22,6 +22,7 @@ +import net.minecraft.world.level.storage.WorldInfo; +import net.minecraft.world.level.validation.ContentValidationException; +import org.bukkit.Bukkit; ++import org.bukkit.craftbukkit.CraftRegistry; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.Main; +import org.bukkit.event.server.ServerLoadEvent; @@ -38,8 +39,8 @@ 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; -@@ -254,6 +277,19 @@ - protected SaveData worldData; +@@ -260,6 +284,19 @@ + private final PotionBrewer potionBrewing; private volatile boolean isSaving; + // CraftBukkit start @@ -58,7 +59,7 @@ public static S spin(Function function) { AtomicReference atomicreference = new AtomicReference(); Thread thread = new Thread(() -> { -@@ -267,14 +303,14 @@ +@@ -273,14 +310,14 @@ thread.setPriority(8); } @@ -75,7 +76,7 @@ super("Server"); this.metricsRecorder = InactiveMetricsRecorder.INSTANCE; this.profiler = this.metricsRecorder.getProfiler(); -@@ -295,7 +331,7 @@ +@@ -303,7 +340,7 @@ this.customBossEvents = new BossBattleCustomData(); this.registries = worldstem.registries(); this.worldData = worldstem.worldData(); @@ -84,9 +85,9 @@ throw new IllegalStateException("Missing Overworld dimension data"); } else { this.proxy = proxy; -@@ -319,6 +355,33 @@ - this.serverThread = thread; +@@ -328,6 +365,33 @@ this.executor = SystemUtils.backgroundExecutor(); + this.potionBrewing = PotionBrewer.bootstrap(this.worldData.enabledFeatures()); } + // CraftBukkit start + this.options = options; @@ -118,7 +119,7 @@ } private void readScoreboard(WorldPersistentData worldpersistentdata) { -@@ -327,7 +390,7 @@ +@@ -336,7 +400,7 @@ protected abstract boolean initServer() throws IOException; @@ -127,12 +128,12 @@ if (!JvmProfiler.INSTANCE.isRunning()) { ; } -@@ -335,12 +398,8 @@ +@@ -344,12 +408,8 @@ boolean flag = false; ProfiledDuration profiledduration = JvmProfiler.INSTANCE.onWorldLoadedStarted(); - this.worldData.setModdedInfo(this.getServerModName(), this.getModdedStatus().shouldReportAsModified()); -- WorldLoadListener worldloadlistener = this.progressListenerFactory.create(11); +- WorldLoadListener worldloadlistener = this.progressListenerFactory.create(this.worldData.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS)); + loadWorld0(s); // CraftBukkit - this.createLevels(worldloadlistener); @@ -141,7 +142,7 @@ if (profiledduration != null) { profiledduration.finish(); } -@@ -357,23 +416,216 @@ +@@ -366,23 +426,217 @@ protected void forceDifficulty() {} @@ -161,7 +162,8 @@ - this.levels.put(World.OVERWORLD, worldserver); - WorldPersistentData worldpersistentdata = worldserver.getDataStorage(); -+ IRegistry dimensions = this.registries.compositeAccess().registryOrThrow(Registries.LEVEL_STEM); ++ IRegistryCustom.Dimension iregistrycustom_dimension = this.registries.compositeAccess(); ++ IRegistry dimensions = iregistrycustom_dimension.registryOrThrow(Registries.LEVEL_STEM); + for (WorldDimension worldDimension : dimensions) { + ResourceKey dimensionKey = dimensions.getResourceKey(worldDimension).get(); @@ -304,7 +306,7 @@ + if (options.has("forceUpgrade")) { + net.minecraft.server.Main.forceUpgrade(worldSession, DataConverterRegistry.getDataFixer(), options.has("eraseCache"), () -> { + return true; -+ }, dimensions); ++ }, iregistrycustom_dimension, options.has("recreateRegionFiles")); + } + + WorldDataServer iworlddataserver = worlddata; @@ -326,7 +328,7 @@ + this.worldData = worlddata; + this.worldData.setGameType(((DedicatedServer) this).getProperties().gamemode); // From DedicatedServer.init + -+ WorldLoadListener worldloadlistener = this.progressListenerFactory.create(11); ++ WorldLoadListener worldloadlistener = this.progressListenerFactory.create(this.worldData.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS)); + + world = new WorldServer(this, this.executor, worldSession, iworlddataserver, worldKey, worlddimension, worldloadlistener, flag, j, list, true, (RandomSequences) null, org.bukkit.World.Environment.getEnvironment(dimension), gen, biomeProvider); + WorldPersistentData worldpersistentdata = world.getDataStorage(); @@ -334,7 +336,7 @@ + this.server.scoreboardManager = new org.bukkit.craftbukkit.scoreboard.CraftScoreboardManager(this, world.getScoreboard()); + this.commandStorage = new PersistentCommandStorage(worldpersistentdata); + } else { -+ WorldLoadListener worldloadlistener = this.progressListenerFactory.create(11); ++ WorldLoadListener worldloadlistener = this.progressListenerFactory.create(worldData.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS)); + world = new WorldServer(this, this.executor, worldSession, iworlddataserver, worldKey, worlddimension, worldloadlistener, flag, j, ImmutableList.of(), true, this.overworld().getRandomSequences(), org.bukkit.World.Environment.getEnvironment(dimension), gen, biomeProvider); + } + @@ -345,7 +347,7 @@ + this.getPlayerList().addWorldborderListener(world); + + if (worlddata.getCustomBossEvents() != null) { -+ this.getCustomBossEvents().load(worlddata.getCustomBossEvents()); ++ this.getCustomBossEvents().load(worlddata.getCustomBossEvents(), this.registryAccess()); + } + } + this.forceDifficulty(); @@ -372,13 +374,13 @@ if (!iworlddataserver.isInitialized()) { try { -@@ -397,30 +649,8 @@ +@@ -406,30 +660,8 @@ iworlddataserver.setInitialized(true); } - this.getPlayerList().addWorldborderListener(worldserver); - if (this.worldData.getCustomBossEvents() != null) { -- this.getCustomBossEvents().load(this.worldData.getCustomBossEvents()); +- this.getCustomBossEvents().load(this.worldData.getCustomBossEvents(), this.registryAccess()); - } - - RandomSequences randomsequences = worldserver.getRandomSequences(); @@ -404,7 +406,7 @@ private static void setInitialSpawn(WorldServer worldserver, IWorldDataServer iworlddataserver, boolean flag, boolean flag1) { if (flag1) { -@@ -428,6 +658,21 @@ +@@ -437,6 +669,21 @@ } else { ChunkProviderServer chunkproviderserver = worldserver.getChunkSource(); ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(chunkproviderserver.randomState().sampler().findSpawnPosition()); @@ -426,7 +428,7 @@ int i = chunkproviderserver.getGenerator().getSpawnHeight(worldserver); if (i < worldserver.getMinBuildHeight()) { -@@ -487,8 +732,11 @@ +@@ -495,8 +742,11 @@ iworlddataserver.setGameType(EnumGamemode.SPECTATOR); } @@ -440,22 +442,20 @@ MinecraftServer.LOGGER.info("Preparing start region for dimension {}", worldserver.dimension().location()); BlockPosition blockposition = worldserver.getSharedSpawnPos(); -@@ -497,19 +745,23 @@ - ChunkProviderServer chunkproviderserver = worldserver.getChunkSource(); +@@ -506,20 +756,22 @@ this.nextTickTimeNanos = SystemUtils.getNanos(); -- chunkproviderserver.addRegionTicket(TicketType.START, new ChunkCoordIntPair(blockposition), 11, Unit.INSTANCE); -+ // CraftBukkit start -+ if (worldserver.getWorld().getKeepSpawnInMemory()) { -+ chunkproviderserver.addRegionTicket(TicketType.START, new ChunkCoordIntPair(blockposition), 11, Unit.INSTANCE); + worldserver.setDefaultSpawnPos(blockposition, worldserver.getSharedSpawnAngle()); +- int i = this.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS); ++ int i = worldserver.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS); // CraftBukkit - per-world + int j = i > 0 ? MathHelper.square(WorldLoadListener.calculateDiameter(i)) : 0; -- while (chunkproviderserver.getTickingGenerated() != 441) { + while (chunkproviderserver.getTickingGenerated() < j) { - this.nextTickTimeNanos = SystemUtils.getNanos() + MinecraftServer.PREPARE_LEVELS_DEFAULT_DELAY_NANOS; - this.waitUntilNextTick(); -+ while (chunkproviderserver.getTickingGenerated() != 441) { -+ // this.nextTickTimeNanos = SystemUtils.getNanos() + MinecraftServer.PREPARE_LEVELS_DEFAULT_DELAY_NANOS; -+ this.executeModerately(); -+ } ++ // CraftBukkit start ++ // this.nextTickTimeNanos = SystemUtils.getNanos() + MinecraftServer.PREPARE_LEVELS_DEFAULT_DELAY_NANOS; ++ this.executeModerately(); } - this.nextTickTimeNanos = SystemUtils.getNanos() + MinecraftServer.PREPARE_LEVELS_DEFAULT_DELAY_NANOS; @@ -473,7 +473,7 @@ ForcedChunk forcedchunk = (ForcedChunk) worldserver1.getDataStorage().get(ForcedChunk.factory(), "chunks"); if (forcedchunk != null) { -@@ -524,10 +776,17 @@ +@@ -534,10 +786,17 @@ } } @@ -494,7 +494,7 @@ } public EnumGamemode getDefaultGameType() { -@@ -557,12 +816,16 @@ +@@ -567,12 +826,16 @@ worldserver.save((IProgressUpdate) null, flag1, worldserver.noSave && !flag2); } @@ -504,14 +504,14 @@ IWorldDataServer iworlddataserver = this.worldData.overworldData(); iworlddataserver.setWorldBorder(worldserver1.getWorldBorder().createSettings()); - this.worldData.setCustomBossEvents(this.getCustomBossEvents().save()); + this.worldData.setCustomBossEvents(this.getCustomBossEvents().save(this.registryAccess())); this.storageSource.saveDataTag(this.registryAccess(), this.worldData, this.getPlayerList().getSingleplayerData()); + */ + // CraftBukkit end if (flag1) { Iterator iterator1 = this.getAllLevels().iterator(); -@@ -597,18 +860,40 @@ +@@ -607,18 +870,40 @@ this.stopServer(); } @@ -552,7 +552,7 @@ } MinecraftServer.LOGGER.info("Saving worlds"); -@@ -696,7 +981,7 @@ +@@ -706,7 +991,7 @@ } this.nextTickTimeNanos = SystemUtils.getNanos(); @@ -561,7 +561,7 @@ this.status = this.buildServerStatus(); while (this.running) { -@@ -713,6 +998,7 @@ +@@ -723,6 +1008,7 @@ if (j > MinecraftServer.OVERLOADED_THRESHOLD_NANOS + 20L * i && this.nextTickTimeNanos - this.lastOverloadWarningNanos >= MinecraftServer.OVERLOADED_WARNING_INTERVAL_NANOS + 100L * i) { long k = j / i; @@ -569,7 +569,7 @@ 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; -@@ -726,6 +1012,7 @@ +@@ -736,6 +1022,7 @@ this.debugCommandProfiler = new MinecraftServer.TimeProfiler(SystemUtils.getNanos(), this.tickCount); } @@ -577,7 +577,7 @@ this.nextTickTimeNanos += i; this.startMetricsRecordingTick(); this.profiler.push("tick"); -@@ -770,6 +1057,12 @@ +@@ -783,6 +1070,12 @@ this.services.profileCache().clearExecutor(); } @@ -590,7 +590,7 @@ this.onServerExit(); } -@@ -803,7 +1096,14 @@ +@@ -842,7 +1135,14 @@ } private boolean haveTime() { @@ -606,7 +606,7 @@ } protected void waitUntilNextTick() { -@@ -850,7 +1150,7 @@ +@@ -901,7 +1201,7 @@ } } @@ -615,7 +615,7 @@ this.getProfiler().incrementCounter("runTask"); super.doRunTask(ticktask); } -@@ -909,8 +1209,10 @@ +@@ -960,8 +1260,10 @@ } --this.ticksUntilAutosave; @@ -628,7 +628,7 @@ MinecraftServer.LOGGER.debug("Autosave started"); this.profiler.push("save"); this.saveEverything(true, false, false); -@@ -991,22 +1293,39 @@ +@@ -1049,11 +1351,26 @@ this.getPlayerList().getPlayers().forEach((entityplayer) -> { entityplayer.connection.suspendFlushing(); }); @@ -655,8 +655,9 @@ while (iterator.hasNext()) { WorldServer worldserver = (WorldServer) iterator.next(); - this.profiler.push(() -> { - return worldserver + " " + worldserver.dimension().location(); +@@ -1062,11 +1379,13 @@ + + return s + " " + String.valueOf(worldserver.dimension().location()); }); + /* Drop global time updates if (this.tickCount % 20 == 0) { @@ -668,7 +669,7 @@ this.profiler.push("tick"); -@@ -1096,6 +1415,22 @@ +@@ -1156,6 +1475,22 @@ return (WorldServer) this.levels.get(resourcekey); } @@ -691,7 +692,7 @@ public Set> levelKeys() { return this.levels.keySet(); } -@@ -1125,7 +1460,7 @@ +@@ -1185,7 +1520,7 @@ @DontObfuscate public String getServerModName() { @@ -700,9 +701,9 @@ } public SystemReport fillSystemReport(SystemReport systemreport) { -@@ -1466,11 +1801,11 @@ +@@ -1527,11 +1862,11 @@ + public CompletableFuture reloadResources(Collection collection) { - IRegistryCustom.Dimension iregistrycustom_dimension = this.registries.getAccessForLoading(RegistryLayer.RELOADABLE); CompletableFuture completablefuture = CompletableFuture.supplyAsync(() -> { - Stream stream = collection.stream(); + Stream stream = collection.stream(); // CraftBukkit - decompile error @@ -714,15 +715,24 @@ }, this).thenCompose((immutablelist) -> { ResourceManager resourcemanager = new ResourceManager(EnumResourcePackType.SERVER_DATA, immutablelist); -@@ -1485,6 +1820,7 @@ +@@ -1546,6 +1881,7 @@ }).thenAcceptAsync((minecraftserver_reloadableresources) -> { this.resources.close(); this.resources = minecraftserver_reloadableresources; + this.server.syncCommands(); // SPIGOT-5884: Lost on reload this.packRepository.setSelected(collection); - WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(getSelectedPacks(this.packRepository), this.worldData.enabledFeatures()); + WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures()); -@@ -1853,7 +2189,7 @@ +@@ -1846,7 +2182,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 + @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))); +@@ -1952,7 +2288,7 @@ try { label51: { @@ -731,7 +741,7 @@ try { arraylist = Lists.newArrayList(NativeModuleLister.listModules()); -@@ -1903,6 +2239,17 @@ +@@ -2002,6 +2338,22 @@ } @@ -744,12 +754,17 @@ + public static MinecraftServer getServer() { + return (Bukkit.getServer() instanceof CraftServer) ? ((CraftServer) Bukkit.getServer()).getServer() : null; + } ++ ++ @Deprecated ++ public static IRegistryCustom getDefaultRegistryAccess() { ++ return CraftRegistry.getMinecraftRegistry(); ++ } + // CraftBukkit end + private void startMetricsRecordingTick() { if (this.willStartRecordingMetrics) { this.metricsRecorder = ActiveMetricsRecorder.createStarted(new ServerMetricsSamplersProvider(SystemUtils.timeSource, this.isDedicatedServer()), SystemUtils.timeSource, SystemUtils.ioPool(), new MetricsPersister("server"), this.onMetricsRecordingStopped, (path) -> { -@@ -2029,6 +2376,11 @@ +@@ -2132,6 +2484,11 @@ } diff --git a/paper-server/nms-patches/net/minecraft/server/ScoreboardServer.patch b/paper-server/nms-patches/net/minecraft/server/ScoreboardServer.patch index 5522befd5b..a99db94a5b 100644 --- a/paper-server/nms-patches/net/minecraft/server/ScoreboardServer.patch +++ b/paper-server/nms-patches/net/minecraft/server/ScoreboardServer.patch @@ -1,15 +1,15 @@ --- a/net/minecraft/server/ScoreboardServer.java +++ b/net/minecraft/server/ScoreboardServer.java -@@ -40,7 +40,7 @@ +@@ -42,7 +42,7 @@ protected void onScoreChanged(ScoreHolder scoreholder, ScoreboardObjective scoreboardobjective, ScoreboardScore scoreboardscore) { super.onScoreChanged(scoreholder, scoreboardobjective, scoreboardscore); if (this.trackedObjectives.contains(scoreboardobjective)) { -- this.server.getPlayerList().broadcastAll(new PacketPlayOutScoreboardScore(scoreholder.getScoreboardName(), scoreboardobjective.getName(), scoreboardscore.value(), scoreboardscore.display(), scoreboardscore.numberFormat())); -+ this.broadcastAll(new PacketPlayOutScoreboardScore(scoreholder.getScoreboardName(), scoreboardobjective.getName(), scoreboardscore.value(), scoreboardscore.display(), scoreboardscore.numberFormat())); // CraftBukkit +- this.server.getPlayerList().broadcastAll(new PacketPlayOutScoreboardScore(scoreholder.getScoreboardName(), scoreboardobjective.getName(), scoreboardscore.value(), Optional.ofNullable(scoreboardscore.display()), Optional.ofNullable(scoreboardscore.numberFormat()))); ++ this.broadcastAll(new PacketPlayOutScoreboardScore(scoreholder.getScoreboardName(), scoreboardobjective.getName(), scoreboardscore.value(), Optional.ofNullable(scoreboardscore.display()), Optional.ofNullable(scoreboardscore.numberFormat()))); // CraftBukkit } this.setDirty(); -@@ -55,7 +55,7 @@ +@@ -57,7 +57,7 @@ @Override public void onPlayerRemoved(ScoreHolder scoreholder) { super.onPlayerRemoved(scoreholder); @@ -18,7 +18,7 @@ this.setDirty(); } -@@ -63,7 +63,7 @@ +@@ -65,7 +65,7 @@ public void onPlayerScoreRemoved(ScoreHolder scoreholder, ScoreboardObjective scoreboardobjective) { super.onPlayerScoreRemoved(scoreholder, scoreboardobjective); if (this.trackedObjectives.contains(scoreboardobjective)) { @@ -27,7 +27,7 @@ } this.setDirty(); -@@ -76,7 +76,7 @@ +@@ -78,7 +78,7 @@ super.setDisplayObjective(displayslot, scoreboardobjective); if (scoreboardobjective1 != scoreboardobjective && scoreboardobjective1 != null) { if (this.getObjectiveDisplaySlotCount(scoreboardobjective1) > 0) { @@ -36,7 +36,7 @@ } else { this.stopTrackingObjective(scoreboardobjective1); } -@@ -84,7 +84,7 @@ +@@ -86,7 +86,7 @@ if (scoreboardobjective != null) { if (this.trackedObjectives.contains(scoreboardobjective)) { @@ -45,7 +45,7 @@ } else { this.startTrackingObjective(scoreboardobjective); } -@@ -96,7 +96,7 @@ +@@ -98,7 +98,7 @@ @Override public boolean addPlayerToTeam(String s, ScoreboardTeam scoreboardteam) { if (super.addPlayerToTeam(s, scoreboardteam)) { @@ -54,7 +54,7 @@ this.setDirty(); return true; } else { -@@ -107,7 +107,7 @@ +@@ -109,7 +109,7 @@ @Override public void removePlayerFromTeam(String s, ScoreboardTeam scoreboardteam) { super.removePlayerFromTeam(s, scoreboardteam); @@ -63,7 +63,7 @@ this.setDirty(); } -@@ -121,7 +121,7 @@ +@@ -123,7 +123,7 @@ public void onObjectiveChanged(ScoreboardObjective scoreboardobjective) { super.onObjectiveChanged(scoreboardobjective); if (this.trackedObjectives.contains(scoreboardobjective)) { @@ -72,7 +72,7 @@ } this.setDirty(); -@@ -140,21 +140,21 @@ +@@ -142,21 +142,21 @@ @Override public void onTeamAdded(ScoreboardTeam scoreboardteam) { super.onTeamAdded(scoreboardteam); @@ -97,7 +97,7 @@ this.setDirty(); } -@@ -205,6 +205,7 @@ +@@ -207,6 +207,7 @@ while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer) iterator.next(); @@ -105,7 +105,7 @@ Iterator iterator1 = list.iterator(); while (iterator1.hasNext()) { -@@ -241,6 +242,7 @@ +@@ -243,6 +244,7 @@ while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer) iterator.next(); @@ -113,8 +113,8 @@ Iterator iterator1 = list.iterator(); while (iterator1.hasNext()) { -@@ -285,6 +287,16 @@ - return this.createData().load(nbttagcompound); +@@ -287,6 +289,16 @@ + return this.createData().load(nbttagcompound, holderlookup_a); } + // CraftBukkit start - Send to players diff --git a/paper-server/nms-patches/net/minecraft/server/bossevents/BossBattleCustom.patch b/paper-server/nms-patches/net/minecraft/server/bossevents/BossBattleCustom.patch index 896ccb39ea..3dacf95669 100644 --- a/paper-server/nms-patches/net/minecraft/server/bossevents/BossBattleCustom.patch +++ b/paper-server/nms-patches/net/minecraft/server/bossevents/BossBattleCustom.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/bossevents/BossBattleCustom.java +++ b/net/minecraft/server/bossevents/BossBattleCustom.java -@@ -18,12 +18,27 @@ +@@ -19,12 +19,27 @@ import net.minecraft.util.MathHelper; import net.minecraft.world.BossBattle; diff --git a/paper-server/nms-patches/net/minecraft/server/commands/CommandEffect.patch b/paper-server/nms-patches/net/minecraft/server/commands/CommandEffect.patch index bc43b68302..f1896566c8 100644 --- a/paper-server/nms-patches/net/minecraft/server/commands/CommandEffect.patch +++ b/paper-server/nms-patches/net/minecraft/server/commands/CommandEffect.patch @@ -2,7 +2,7 @@ +++ b/net/minecraft/server/commands/CommandEffect.java @@ -84,7 +84,7 @@ if (entity instanceof EntityLiving) { - MobEffect mobeffect = new MobEffect(mobeffectlist, k, i, false, flag); + MobEffect mobeffect = new MobEffect(holder, k, i, false, flag); - if (((EntityLiving) entity).addEffect(mobeffect, commandlistenerwrapper.getEntity())) { + if (((EntityLiving) entity).addEffect(mobeffect, commandlistenerwrapper.getEntity(), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.COMMAND)) { // CraftBukkit @@ -22,8 +22,8 @@ while (iterator.hasNext()) { Entity entity = (Entity) iterator.next(); -- if (entity instanceof EntityLiving && ((EntityLiving) entity).removeEffect(mobeffectlist)) { -+ if (entity instanceof EntityLiving && ((EntityLiving) entity).removeEffect(mobeffectlist, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.COMMAND)) { // CraftBukkit +- if (entity instanceof EntityLiving && ((EntityLiving) entity).removeEffect(holder)) { ++ if (entity instanceof EntityLiving && ((EntityLiving) entity).removeEffect(holder, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.COMMAND)) { // CraftBukkit ++i; } } diff --git a/paper-server/nms-patches/net/minecraft/server/commands/CommandGive.patch b/paper-server/nms-patches/net/minecraft/server/commands/CommandGive.patch index e221613485..bf774c373b 100644 --- a/paper-server/nms-patches/net/minecraft/server/commands/CommandGive.patch +++ b/paper-server/nms-patches/net/minecraft/server/commands/CommandGive.patch @@ -1,11 +1,11 @@ --- a/net/minecraft/server/commands/CommandGive.java +++ b/net/minecraft/server/commands/CommandGive.java -@@ -61,7 +61,7 @@ +@@ -60,7 +60,7 @@ + EntityItem entityitem; if (flag && itemstack1.isEmpty()) { - itemstack1.setCount(1); -- entityitem = entityplayer.drop(itemstack1, false); -+ entityitem = entityplayer.drop(itemstack1, false, false, false); // CraftBukkit - SPIGOT-2942: Add boolean to call event +- entityitem = entityplayer.drop(itemstack, false); ++ entityitem = entityplayer.drop(itemstack, false, false, false); // CraftBukkit - SPIGOT-2942: Add boolean to call event if (entityitem != null) { entityitem.makeFakeItem(); } 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 5004695bcc..8c24291735 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 -@@ -90,7 +90,7 @@ +@@ -91,7 +91,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); -@@ -247,6 +247,7 @@ +@@ -246,6 +246,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/CommandSummon.patch b/paper-server/nms-patches/net/minecraft/server/commands/CommandSummon.patch index 7ab0f2a793..7cff016f53 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, (NBTTagCompound) null); + ((EntityInsentient) entity).finalizeSpawn(commandlistenerwrapper.getLevel(), commandlistenerwrapper.getLevel().getCurrentDifficultyAt(entity.blockPosition()), EnumMobSpawn.COMMAND, (GroupDataEntity) null); } - if (!worldserver.tryAddFreshEntityWithPassengers(entity)) { diff --git a/paper-server/nms-patches/net/minecraft/server/commands/PlaceCommand.patch b/paper-server/nms-patches/net/minecraft/server/commands/PlaceCommand.patch index 2b96dcd0c8..61c08f6c46 100644 --- a/paper-server/nms-patches/net/minecraft/server/commands/PlaceCommand.patch +++ b/paper-server/nms-patches/net/minecraft/server/commands/PlaceCommand.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/commands/PlaceCommand.java +++ b/net/minecraft/server/commands/PlaceCommand.java -@@ -130,6 +130,7 @@ +@@ -132,6 +132,7 @@ if (!structurestart.isValid()) { throw PlaceCommand.ERROR_STRUCTURE_FAILED.create(); } else { 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 c54c205b8e..ad2881ffa1 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 -@@ -53,6 +53,18 @@ +@@ -58,6 +58,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(); -@@ -61,7 +73,7 @@ +@@ -66,7 +78,7 @@ private final List consoleInput = Collections.synchronizedList(Lists.newArrayList()); @Nullable private RemoteStatusListener queryThreadGs4; @@ -28,9 +28,9 @@ @Nullable private RemoteControlListener rconThread; public DedicatedServerSettings settings; -@@ -70,10 +82,12 @@ +@@ -79,10 +91,12 @@ @Nullable - private final TextFilter textFilterClient; + private DebugSampleSubscriptionTracker debugSampleSubscriptionTracker; - public DedicatedServer(Thread thread, Convertable.ConversionSession convertable_conversionsession, ResourcePackRepository resourcepackrepository, WorldStem worldstem, DedicatedServerSettings dedicatedserversettings, DataFixer datafixer, Services services, WorldLoadListenerFactory worldloadlistenerfactory) { - super(thread, convertable_conversionsession, resourcepackrepository, worldstem, Proxy.NO_PROXY, datafixer, services, worldloadlistenerfactory); @@ -44,7 +44,7 @@ this.textFilterClient = TextFilter.createFromConfig(dedicatedserversettings.getProperties().textFilteringConfig); } -@@ -81,13 +95,44 @@ +@@ -90,13 +104,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); -@@ -96,6 +141,29 @@ +@@ -105,6 +150,29 @@ } }; @@ -122,7 +122,7 @@ thread.setDaemon(true); thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(DedicatedServer.LOGGER)); thread.start(); -@@ -120,7 +188,7 @@ +@@ -129,7 +197,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; -@@ -144,6 +212,12 @@ +@@ -153,6 +221,12 @@ return false; } @@ -144,14 +144,16 @@ 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."); -@@ -158,19 +232,19 @@ +@@ -167,7 +241,7 @@ if (!NameReferencingFileConverter.serverReadyAfterUserconversion(this)) { return false; } else { - this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage)); + // this.setPlayerList(new DedicatedPlayerList(this, this.registries(), this.playerDataStorage)); // CraftBukkit - moved up + this.debugSampleSubscriptionTracker = new DebugSampleSubscriptionTracker(this.getPlayerList()); + this.tickTimeLogger = new RemoteSampleLogger(TpsDebugDimensions.values().length, this.debugSampleSubscriptionTracker, RemoteDebugSampleType.TICK_TIME); long i = SystemUtils.getNanos(); - +@@ -175,13 +249,13 @@ TileEntitySkull.setup(this.services, this); UserCache.setUsesAuthentication(this.usesAuthentication()); DedicatedServer.LOGGER.info("Preparing level \"{}\"", this.getLevelIdName()); @@ -167,7 +169,7 @@ } if (dedicatedserverproperties.enableQuery) { -@@ -296,6 +370,7 @@ +@@ -307,6 +381,7 @@ this.queryThreadGs4.stop(); } @@ -175,7 +177,7 @@ } @Override -@@ -317,7 +392,15 @@ +@@ -328,7 +403,15 @@ while (!this.consoleInput.isEmpty()) { ServerCommand servercommand = (ServerCommand) this.consoleInput.remove(0); @@ -192,7 +194,7 @@ } } -@@ -544,16 +627,52 @@ +@@ -555,16 +638,52 @@ @Override public String getPluginNames() { @@ -249,9 +251,9 @@ } public void storeUsingWhiteList(boolean flag) { -@@ -604,4 +723,15 @@ - public Optional getServerResourcePack() { - return this.settings.getProperties().serverResourcePackInfo; +@@ -641,4 +760,15 @@ + public boolean acceptsTransfers() { + return this.settings.getProperties().acceptsTransfers; } + + // CraftBukkit start 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 47870fe56d..49746df6f7 100644 --- a/paper-server/nms-patches/net/minecraft/server/dedicated/DedicatedServerProperties.patch +++ b/paper-server/nms-patches/net/minecraft/server/dedicated/DedicatedServerProperties.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/dedicated/DedicatedServerProperties.java +++ b/net/minecraft/server/dedicated/DedicatedServerProperties.java -@@ -44,11 +44,16 @@ +@@ -43,11 +43,16 @@ import net.minecraft.world.level.levelgen.presets.WorldPresets; import org.slf4j.Logger; @@ -17,9 +17,9 @@ public final boolean onlineMode = this.get("online-mode", true); public final boolean preventProxyConnections = this.get("prevent-proxy-connections", false); public final String serverIp = this.get("server-ip", ""); -@@ -103,8 +108,10 @@ - private final DedicatedServerProperties.WorldDimensionData worldDimensionData; +@@ -104,8 +109,10 @@ public final WorldOptions worldOptions; + public boolean acceptsTransfers; - public DedicatedServerProperties(Properties properties) { - super(properties); @@ -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"); -@@ -161,13 +168,15 @@ +@@ -164,13 +171,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 -@@ -248,10 +257,10 @@ +@@ -251,10 +260,10 @@ }).orElseThrow(() -> { return new IllegalStateException("Invalid datapack contents: can't find default preset"); }); @@ -63,10 +63,10 @@ }); Objects.requireNonNull(iregistry); -@@ -263,7 +272,7 @@ +@@ -266,7 +275,7 @@ if (holder.is(WorldPresets.FLAT)) { - RegistryOps registryops = RegistryOps.create(JsonOps.INSTANCE, (HolderLookup.b) iregistrycustom); + RegistryOps registryops = iregistrycustom.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/dedicated/PropertyManager.patch b/paper-server/nms-patches/net/minecraft/server/dedicated/PropertyManager.patch index 3baccfc5e3..7ad50cc4b0 100644 --- a/paper-server/nms-patches/net/minecraft/server/dedicated/PropertyManager.patch +++ b/paper-server/nms-patches/net/minecraft/server/dedicated/PropertyManager.patch @@ -108,8 +108,8 @@ private final V value; private final Function serializer; -- EditableProperty(String s, Object object, Function function) { -+ EditableProperty(String s, V object, Function function) { // CraftBukkit - decompile error +- EditableProperty(final String s, final Object object, final Function function) { ++ EditableProperty(final String s, final V object, final Function function) { // CraftBukkit - decompile error this.key = s; this.value = object; this.serializer = function; diff --git a/paper-server/nms-patches/net/minecraft/server/gui/ServerGUI.patch b/paper-server/nms-patches/net/minecraft/server/gui/ServerGUI.patch index 5c6b09ab35..e99114a8d8 100644 --- a/paper-server/nms-patches/net/minecraft/server/gui/ServerGUI.patch +++ b/paper-server/nms-patches/net/minecraft/server/gui/ServerGUI.patch @@ -9,6 +9,15 @@ Objects.requireNonNull(guistatscomponent); collection.add(guistatscomponent::close); +@@ -132,7 +132,7 @@ + + jtextfield.setText(""); + }); +- jtextarea.addFocusListener(new FocusAdapter(this) { ++ jtextarea.addFocusListener(new FocusAdapter() { // CraftBukkit - decompile error + public void focusGained(FocusEvent focusevent) {} + }); + jpanel.add(jscrollpane, "Center"); @@ -166,6 +166,7 @@ this.finalizers.forEach(Runnable::run); } 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 a0087ed66c..3ffbd07a4a 100644 --- a/paper-server/nms-patches/net/minecraft/server/level/ChunkMapDistance.patch +++ b/paper-server/nms-patches/net/minecraft/server/level/ChunkMapDistance.patch @@ -1,15 +1,6 @@ --- a/net/minecraft/server/level/ChunkMapDistance.java +++ b/net/minecraft/server/level/ChunkMapDistance.java -@@ -55,7 +55,7 @@ - final LongSet ticketsToRelease = new LongOpenHashSet(); - final Executor mainThreadExecutor; - private long ticketTickCounter; -- private int simulationDistance = 10; -+ public int simulationDistance = 10; - - protected ChunkMapDistance(Executor executor, Executor executor1) { - Objects.requireNonNull(executor1); -@@ -122,10 +122,25 @@ +@@ -121,10 +121,25 @@ } if (!this.chunksToUpdateFutures.isEmpty()) { @@ -38,7 +29,7 @@ return true; } else { if (!this.ticketsToRelease.isEmpty()) { -@@ -161,7 +176,7 @@ +@@ -160,7 +175,7 @@ } } @@ -47,7 +38,7 @@ ArraySetSorted> arraysetsorted = this.getTickets(i); int j = getTicketLevelAt(arraysetsorted); Ticket ticket1 = (Ticket) arraysetsorted.addOrGet(ticket); -@@ -171,13 +186,15 @@ +@@ -170,13 +185,15 @@ this.ticketTracker.update(i, ticket.getTicketLevel(), true); } @@ -65,7 +56,7 @@ } if (arraysetsorted.isEmpty()) { -@@ -185,6 +202,7 @@ +@@ -184,6 +201,7 @@ } this.ticketTracker.update(i, getTicketLevelAt(arraysetsorted), false); @@ -73,7 +64,7 @@ } public void addTicket(TicketType tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) { -@@ -198,19 +216,33 @@ +@@ -197,19 +215,33 @@ } public void addRegionTicket(TicketType tickettype, ChunkCoordIntPair chunkcoordintpair, int i, T t0) { @@ -109,7 +100,7 @@ } private ArraySetSorted> getTickets(long i) { -@@ -249,6 +281,7 @@ +@@ -248,6 +280,7 @@ ChunkCoordIntPair chunkcoordintpair = sectionposition.chunk(); long i = chunkcoordintpair.toLong(); ObjectSet objectset = (ObjectSet) this.playersPerChunk.get(i); @@ -117,7 +108,7 @@ objectset.remove(entityplayer); if (objectset.isEmpty()) { -@@ -378,6 +411,26 @@ +@@ -377,6 +410,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 e12e4c657c..99e6077793 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 -@@ -83,6 +83,16 @@ +@@ -81,6 +81,16 @@ this.clearCache(); } @@ -17,31 +17,40 @@ @Override public LightEngineThreaded getLightEngine() { return this.lightEngine; -@@ -127,7 +137,7 @@ - for (int l = 0; l < 4; ++l) { +@@ -124,7 +134,7 @@ if (k == this.lastChunkPos[l] && chunkstatus == this.lastChunkStatus[l]) { - ichunkaccess = this.lastChunk[l]; + IChunkAccess ichunkaccess = this.lastChunk[l]; + - if (ichunkaccess != null || !flag) { + if (ichunkaccess != null) { // CraftBukkit - the chunk can become accessible in the meantime TODO for non-null chunks it might also make sense to check that the chunk's state hasn't changed in the meantime return ichunkaccess; } } -@@ -175,12 +185,12 @@ +@@ -137,7 +147,7 @@ + Objects.requireNonNull(completablefuture); + chunkproviderserver_b.managedBlock(completablefuture::isDone); + ChunkResult chunkresult = (ChunkResult) completablefuture.join(); +- IChunkAccess ichunkaccess1 = (IChunkAccess) chunkresult.orElse((Object) null); ++ IChunkAccess ichunkaccess1 = (IChunkAccess) chunkresult.orElse(null); // CraftBukkit - decompile error + + if (ichunkaccess1 == null && flag) { + throw (IllegalStateException) SystemUtils.pauseInIde(new IllegalStateException("Chunk not there when requested: " + chunkresult.getError())); +@@ -170,12 +180,12 @@ if (playerchunk == null) { return null; } else { -- Either either = (Either) playerchunk.getFutureIfPresent(ChunkStatus.FULL).getNow((Object) null); -+ Either either = (Either) playerchunk.getFutureIfPresent(ChunkStatus.FULL).getNow(null); // CraftBukkit - decompile error +- ChunkResult chunkresult = (ChunkResult) playerchunk.getFutureIfPresent(ChunkStatus.FULL).getNow((Object) null); ++ ChunkResult chunkresult = (ChunkResult) playerchunk.getFutureIfPresent(ChunkStatus.FULL).getNow(null); // CraftBukkit - decompile error - if (either == null) { + if (chunkresult == null) { return null; } else { -- IChunkAccess ichunkaccess1 = (IChunkAccess) either.left().orElse((Object) null); -+ IChunkAccess ichunkaccess1 = (IChunkAccess) either.left().orElse(null); // CraftBukkit - decompile error +- IChunkAccess ichunkaccess1 = (IChunkAccess) chunkresult.orElse((Object) null); ++ IChunkAccess ichunkaccess1 = (IChunkAccess) chunkresult.orElse(null); // CraftBukkit - decompile error if (ichunkaccess1 != null) { this.storeInCache(k, ichunkaccess1, ChunkStatus.FULL); -@@ -228,7 +238,15 @@ +@@ -223,7 +233,15 @@ int l = ChunkLevel.byStatus(chunkstatus); PlayerChunk playerchunk = this.getVisibleChunkIfPresent(k); @@ -58,7 +67,7 @@ this.distanceManager.addTicket(TicketType.UNKNOWN, chunkcoordintpair, l, chunkcoordintpair); if (this.chunkAbsent(playerchunk, l)) { GameProfilerFiller gameprofilerfiller = this.level.getProfiler(); -@@ -247,7 +265,7 @@ +@@ -242,7 +260,7 @@ } private boolean chunkAbsent(@Nullable PlayerChunk playerchunk, int i) { @@ -67,16 +76,7 @@ } @Override -@@ -315,7 +333,7 @@ - } else if (!this.level.shouldTickBlocksAt(i)) { - return false; - } else { -- Either either = (Either) playerchunk.getTickingChunkFuture().getNow((Object) null); -+ Either either = (Either) playerchunk.getTickingChunkFuture().getNow(null); // CraftBukkit - decompile error - - return either != null && either.left().isPresent(); - } -@@ -328,11 +346,31 @@ +@@ -315,11 +333,31 @@ @Override public void close() throws IOException { @@ -109,7 +109,7 @@ @Override public void tick(BooleanSupplier booleansupplier, boolean flag) { this.level.getProfiler().push("purge"); -@@ -379,11 +417,11 @@ +@@ -369,11 +407,11 @@ this.lastSpawnState = spawnercreature_d; gameprofilerfiller.popPush("spawnAndTick"); @@ -123,7 +123,7 @@ Iterator iterator1 = list.iterator(); while (iterator1.hasNext()) { -@@ -586,13 +624,19 @@ +@@ -576,13 +614,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 c6c6c892d2..835305dd2d 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 -@@ -157,6 +157,38 @@ +@@ -165,6 +165,38 @@ import net.minecraft.world.scores.criteria.IScoreboardCriteria; import org.slf4j.Logger; @@ -39,7 +39,7 @@ public class EntityPlayer extends EntityHuman { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -192,7 +224,7 @@ +@@ -203,7 +235,7 @@ private int levitationStartTime; private boolean disconnected; private int requestedViewDistance; @@ -48,11 +48,12 @@ @Nullable private Vec3D startingToFallPosition; @Nullable -@@ -217,6 +249,20 @@ +@@ -233,6 +265,21 @@ private int containerCounter; public boolean wonGame; + // CraftBukkit start ++ public CraftPlayer.TransferCookieConnection transferCookieConnection; + public String displayName; + public IChatBaseComponent listName; + public org.bukkit.Location compassTarget; @@ -69,17 +70,17 @@ public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, ClientInformation clientinformation) { super(worldserver, worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle(), gameprofile); this.chatVisibility = EnumChatVisibility.FULL; -@@ -283,12 +329,56 @@ - this.setMaxUpStep(1.0F); +@@ -299,12 +346,56 @@ this.fudgeSpawnLocation(worldserver); this.updateOptions(clientinformation); + this.object = null; + + // CraftBukkit start + this.displayName = this.getScoreboardName(); + this.bukkitPickUpLoot = true; + this.maxHealthCache = this.getMaxHealth(); -+ } -+ + } + + // Yes, this doesn't match Vanilla, but it's the best we can do for now. + // If this is an issue, PRs are welcome + public final BlockPosition getSpawnPoint(WorldServer worldserver) { @@ -116,9 +117,9 @@ + } + + return blockposition; - } ++ } + // CraftBukkit end - ++ private void fudgeSpawnLocation(WorldServer worldserver) { BlockPosition blockposition = worldserver.getSharedSpawnPos(); @@ -127,16 +128,16 @@ int i = Math.max(0, this.server.getSpawnRadius(worldserver)); int j = MathHelper.floor(worldserver.getWorldBorder().getDistanceToBorder((double) blockposition.getX(), (double) blockposition.getZ())); -@@ -337,7 +427,7 @@ - public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { - super.readAdditionalSaveData(nbttagcompound); - if (nbttagcompound.contains("warden_spawn_tracker", 10)) { -- DataResult dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("warden_spawn_tracker"))); -+ DataResult dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("warden_spawn_tracker"))); // CraftBukkit - decompile error - Logger logger = EntityPlayer.LOGGER; - +@@ -359,7 +450,7 @@ + dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("warden_spawn_tracker"))); + logger = EntityPlayer.LOGGER; Objects.requireNonNull(logger); -@@ -356,17 +446,26 @@ +- dataresult.resultOrPartial(logger::error).ifPresent((wardenspawntracker) -> { ++ ((DataResult) dataresult).resultOrPartial(logger::error).ifPresent((wardenspawntracker) -> { + this.wardenSpawnTracker = wardenspawntracker; + }); + } +@@ -374,17 +465,26 @@ if (nbttagcompound.contains("recipeBook", 10)) { this.recipeBook.fromNbt(nbttagcompound.getCompound("recipeBook"), this.server.getRecipeManager()); } @@ -164,7 +165,16 @@ Logger logger1 = EntityPlayer.LOGGER; Objects.requireNonNull(logger1); -@@ -379,7 +478,7 @@ +@@ -399,7 +499,7 @@ + dataresult = BlockPosition.CODEC.parse(DynamicOpsNBT.INSTANCE, nbtbase); + logger = EntityPlayer.LOGGER; + Objects.requireNonNull(logger); +- dataresult.resultOrPartial(logger::error).ifPresent((blockposition) -> { ++ ((DataResult) dataresult).resultOrPartial(logger::error).ifPresent((blockposition) -> { // CraftBukkit - decompile error + this.raidOmenPosition = blockposition; + }); + } +@@ -409,7 +509,7 @@ @Override public void addAdditionalSaveData(NBTTagCompound nbttagcompound) { super.addAdditionalSaveData(nbttagcompound); @@ -173,7 +183,7 @@ Logger logger = EntityPlayer.LOGGER; Objects.requireNonNull(logger); -@@ -400,7 +499,20 @@ +@@ -430,7 +530,20 @@ Entity entity = this.getRootVehicle(); Entity entity1 = this.getVehicle(); @@ -195,13 +205,17 @@ NBTTagCompound nbttagcompound2 = new NBTTagCompound(); NBTTagCompound nbttagcompound3 = new NBTTagCompound(); -@@ -425,8 +537,32 @@ +@@ -455,6 +568,7 @@ nbttagcompound.put("SpawnDimension", nbtbase); }); } + this.getBukkitEntity().setExtraData(nbttagcompound); // CraftBukkit -+ -+ } + + nbttagcompound.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall); + if (this.raidOmenPosition != null) { +@@ -468,6 +582,29 @@ + + } + // CraftBukkit start - World fallback code, either respawn location or global spawn + public void spawnIn(World world) { @@ -223,12 +237,13 @@ + this.setPos(position); + } + this.gameMode.setLevel((WorldServer) world); - } ++ } + // CraftBukkit end - ++ public void setExperiencePoints(int i) { float f = (float) this.getXpNeededForNextLevel(); -@@ -486,6 +622,11 @@ + float f1 = (f - 1.0F) / f; +@@ -526,6 +663,11 @@ @Override public void tick() { @@ -240,7 +255,7 @@ this.gameMode.tick(); this.wardenSpawnTracker.tick(); --this.spawnInvulnerableTime; -@@ -542,7 +683,7 @@ +@@ -606,7 +748,7 @@ } if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) { @@ -249,7 +264,7 @@ this.lastSentHealth = this.getHealth(); this.lastSentFood = this.foodData.getFoodLevel(); this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F; -@@ -573,6 +714,12 @@ +@@ -637,6 +779,12 @@ this.updateScoreForCriteria(IScoreboardCriteria.EXPERIENCE, MathHelper.ceil((float) this.lastRecordedExperience)); } @@ -262,7 +277,7 @@ if (this.experienceLevel != this.lastRecordedLevel) { this.lastRecordedLevel = this.experienceLevel; this.updateScoreForCriteria(IScoreboardCriteria.LEVEL, MathHelper.ceil((float) this.lastRecordedLevel)); -@@ -587,6 +734,20 @@ +@@ -651,6 +799,20 @@ CriterionTriggers.LOCATION.trigger(this); } @@ -283,7 +298,7 @@ } catch (Throwable throwable) { CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player"); CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Player being ticked"); -@@ -629,7 +790,8 @@ +@@ -696,7 +858,8 @@ } private void updateScoreForCriteria(IScoreboardCriteria iscoreboardcriteria, int i) { @@ -293,7 +308,7 @@ scoreaccess.set(i); }); } -@@ -638,9 +800,47 @@ +@@ -705,9 +868,47 @@ public void die(DamageSource damagesource) { this.gameEvent(GameEvent.ENTITY_DIE); boolean flag = this.level().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES); @@ -343,7 +358,7 @@ this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> { boolean flag1 = true; -@@ -671,12 +871,18 @@ +@@ -738,12 +939,18 @@ if (this.level().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) { this.tellNeutralMobsThatIDied(); } @@ -366,7 +381,7 @@ EntityLiving entityliving = this.getKillCredit(); if (entityliving != null) { -@@ -711,10 +917,12 @@ +@@ -778,10 +985,12 @@ if (entity != this) { super.awardKillScore(entity, i, damagesource); this.increaseScore(i); @@ -381,7 +396,7 @@ } else { this.awardStat(StatisticList.MOB_KILLS); } -@@ -732,7 +940,8 @@ +@@ -799,7 +1008,8 @@ int i = scoreboardteam.getColor().getId(); if (i >= 0 && i < aiscoreboardcriteria.length) { @@ -391,7 +406,7 @@ } } -@@ -782,18 +991,20 @@ +@@ -849,18 +1059,20 @@ } private boolean isPvpAllowed() { @@ -415,7 +430,7 @@ } else { return shapedetectorshape; } -@@ -802,11 +1013,20 @@ +@@ -869,11 +1081,20 @@ @Nullable @Override public Entity changeDimension(WorldServer worldserver) { @@ -439,7 +454,7 @@ this.unRide(); this.serverLevel().removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION); if (!this.wonGame) { -@@ -817,6 +1037,8 @@ +@@ -884,6 +1105,8 @@ return this; } else { @@ -448,7 +463,7 @@ WorldData worlddata = worldserver.getLevelData(); this.connection.send(new PacketPlayOutRespawn(this.createCommonSpawnInfo(worldserver), (byte) 3)); -@@ -826,20 +1048,50 @@ +@@ -893,20 +1116,50 @@ playerlist.sendPlayerPermissionLevel(this); worldserver1.removePlayerImmediately(this, Entity.RemovalReason.CHANGED_DIMENSION); this.unsetRemoved(); @@ -504,7 +519,7 @@ this.connection.resetPosition(); worldserver.addDuringPortalTeleport(this); worldserver1.getProfiler().pop(); -@@ -859,39 +1111,66 @@ +@@ -926,39 +1179,66 @@ this.lastSentExp = -1; this.lastSentHealth = -1.0F; this.lastSentFood = -1; @@ -577,7 +592,7 @@ } return optional1; -@@ -901,13 +1180,21 @@ +@@ -968,13 +1248,21 @@ public void triggerDimensionChangeTriggers(WorldServer worldserver) { ResourceKey resourcekey = worldserver.dimension(); ResourceKey resourcekey1 = this.level().dimension(); @@ -602,7 +617,7 @@ this.enteredNetherPosition = null; } -@@ -924,19 +1211,17 @@ +@@ -991,19 +1279,17 @@ this.containerMenu.broadcastChanges(); } @@ -626,7 +641,7 @@ if (this.level().isDay()) { return Either.left(EntityHuman.EnumBedResult.NOT_POSSIBLE_NOW); } else { -@@ -953,7 +1238,36 @@ +@@ -1020,7 +1306,36 @@ } } @@ -664,7 +679,7 @@ this.awardStat(StatisticList.SLEEP_IN_BED); CriterionTriggers.SLEPT_IN_BED.trigger(this); }); -@@ -966,9 +1280,8 @@ +@@ -1033,9 +1348,8 @@ return either; } } @@ -675,7 +690,7 @@ } @Override -@@ -995,13 +1308,31 @@ +@@ -1062,13 +1376,31 @@ @Override public void stopSleepInBed(boolean flag, boolean flag1) { @@ -708,7 +723,7 @@ } } -@@ -1051,8 +1382,9 @@ +@@ -1135,8 +1467,9 @@ this.connection.send(new PacketPlayOutOpenSignEditor(tileentitysign.getBlockPos(), flag)); } @@ -719,7 +734,7 @@ } @Override -@@ -1060,13 +1392,35 @@ +@@ -1144,13 +1477,35 @@ if (itileinventory == null) { return OptionalInt.empty(); } else { @@ -755,7 +770,7 @@ if (container == null) { if (this.isSpectator()) { this.displayClientMessage(IChatBaseComponent.translatable("container.spectatorCantOpen").withStyle(EnumChatFormat.RED), true); -@@ -1074,9 +1428,11 @@ +@@ -1158,9 +1513,11 @@ return OptionalInt.empty(); } else { @@ -769,7 +784,7 @@ return OptionalInt.of(this.containerCounter); } } -@@ -1089,13 +1445,24 @@ +@@ -1173,13 +1530,24 @@ @Override public void openHorseInventory(EntityHorseAbstract entityhorseabstract, IInventory iinventory) { @@ -796,7 +811,7 @@ this.initMenu(this.containerMenu); } -@@ -1118,6 +1485,7 @@ +@@ -1202,6 +1570,7 @@ @Override public void closeContainer() { @@ -804,7 +819,7 @@ this.connection.send(new PacketPlayOutCloseWindow(this.containerMenu.containerId)); this.doCloseContainer(); } -@@ -1140,6 +1508,16 @@ +@@ -1224,6 +1593,16 @@ } this.jumping = flag; @@ -821,7 +836,7 @@ this.setShiftKeyDown(flag1); } -@@ -1173,19 +1551,19 @@ +@@ -1257,19 +1636,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); @@ -844,7 +859,7 @@ } } else if (this.onClimbable()) { if (d1 > 0.0D) { -@@ -1196,13 +1574,13 @@ +@@ -1280,13 +1659,13 @@ if (i > 0) { if (this.isSprinting()) { this.awardStat(StatisticList.SPRINT_ONE_CM, i); @@ -861,7 +876,7 @@ } } } else if (this.isFallFlying()) { -@@ -1245,7 +1623,7 @@ +@@ -1329,7 +1708,7 @@ @Override public void awardStat(Statistic statistic, int i) { this.stats.increment(this, statistic, i); @@ -870,7 +885,7 @@ scoreaccess.add(i); }); } -@@ -1253,7 +1631,7 @@ +@@ -1337,7 +1716,7 @@ @Override public void resetStat(Statistic statistic) { this.stats.setValue(this, statistic, 0); @@ -879,7 +894,7 @@ } @Override -@@ -1301,6 +1679,7 @@ +@@ -1385,6 +1764,7 @@ public void resetSentInfo() { this.lastSentHealth = -1.0E8F; @@ -887,7 +902,7 @@ } @Override -@@ -1358,7 +1737,7 @@ +@@ -1442,7 +1822,7 @@ this.lastSentExp = -1; this.lastSentHealth = -1.0F; this.lastSentFood = -1; @@ -896,7 +911,7 @@ this.seenCredits = entityplayer.seenCredits; this.enteredNetherPosition = entityplayer.enteredNetherPosition; this.chunkTrackingView = entityplayer.chunkTrackingView; -@@ -1409,6 +1788,12 @@ +@@ -1493,6 +1873,12 @@ @Override public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1) { @@ -909,7 +924,7 @@ ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(BlockPosition.containing(d0, d1, d2)); worldserver.getChunkSource().addRegionTicket(TicketType.POST_TELEPORT, chunkcoordintpair, 1, this.getId()); -@@ -1418,9 +1803,9 @@ +@@ -1502,9 +1888,9 @@ } if (worldserver == this.level()) { @@ -921,7 +936,7 @@ } this.setYHeadRot(f); -@@ -1524,6 +1909,16 @@ +@@ -1606,6 +1992,16 @@ } public void updateOptions(ClientInformation clientinformation) { @@ -938,7 +953,7 @@ this.language = clientinformation.language(); this.requestedViewDistance = clientinformation.viewDistance(); this.chatVisibility = clientinformation.chatVisibility(); -@@ -1607,7 +2002,7 @@ +@@ -1689,7 +2085,7 @@ if (world instanceof WorldServer) { WorldServer worldserver = (WorldServer) world; @@ -947,7 +962,7 @@ } if (entity != null) { -@@ -1644,7 +2039,7 @@ +@@ -1726,7 +2122,7 @@ @Nullable public IChatBaseComponent getTabListDisplayName() { @@ -956,7 +971,7 @@ } @Override -@@ -1665,9 +2060,16 @@ +@@ -1747,9 +2143,16 @@ return this.advancements; } @@ -973,7 +988,7 @@ if (worldserver == this.level()) { this.connection.teleport(d0, d1, d2, f, f1); } else { -@@ -1687,6 +2089,9 @@ +@@ -1769,6 +2172,9 @@ this.server.getPlayerList().sendLevelInfo(this, worldserver); this.server.getPlayerList().sendAllPlayerInfo(this); } @@ -983,7 +998,7 @@ } -@@ -1708,6 +2113,32 @@ +@@ -1790,6 +2196,32 @@ } public void setRespawnPosition(ResourceKey resourcekey, @Nullable BlockPosition blockposition, float f, boolean flag, boolean flag1) { @@ -1016,9 +1031,9 @@ if (blockposition != null) { boolean flag2 = blockposition.equals(this.respawnPosition) && resourcekey.equals(this.respawnDimension); -@@ -1913,4 +2344,147 @@ - public CommonPlayerSpawnInfo createCommonSpawnInfo(WorldServer worldserver) { - return new CommonPlayerSpawnInfo(worldserver.dimensionTypeId(), worldserver.dimension(), BiomeManager.obfuscateSeed(worldserver.getSeed()), this.gameMode.getGameModeForPlayer(), this.gameMode.getPreviousGameModeForPlayer(), worldserver.isDebug(), worldserver.isFlat(), this.getLastDeathLocation(), this.getPortalCooldown()); +@@ -2011,4 +2443,147 @@ + public BlockPosition getRaidOmenPosition() { + return this.raidOmenPosition; } + + // CraftBukkit start - Add per-player time and weather. 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 cfbd28d8b3..4a967146ff 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 -@@ -42,6 +42,12 @@ +@@ -46,6 +46,12 @@ import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; @@ -13,10 +13,10 @@ public class EntityTrackerEntry { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -66,8 +72,12 @@ +@@ -70,8 +76,12 @@ private boolean wasOnGround; @Nullable - private List> trackedDataValues; + private List> trackedDataValues; + // CraftBukkit start + private final Set trackedPlayers; @@ -27,27 +27,27 @@ this.ap = Vec3D.ZERO; this.lastPassengers = Collections.emptyList(); this.level = worldserver; -@@ -87,7 +97,7 @@ +@@ -91,7 +101,7 @@ List list = this.entity.getPassengers(); if (!list.equals(this.lastPassengers)) { - this.broadcast.accept(new PacketPlayOutMount(this.entity)); + this.broadcastAndSend(new PacketPlayOutMount(this.entity)); // CraftBukkit removedPassengers(list, this.lastPassengers).forEach((entity) -> { - if (entity instanceof EntityPlayer) { - EntityPlayer entityplayer = (EntityPlayer) entity; + if (entity instanceof EntityPlayer entityplayer) { + entityplayer.connection.teleport(entityplayer.getX(), entityplayer.getY(), entityplayer.getZ(), entityplayer.getYRot(), entityplayer.getXRot()); @@ -104,18 +114,18 @@ - if (entity instanceof EntityItemFrame) { - EntityItemFrame entityitemframe = (EntityItemFrame) entity; + Entity entity = this.entity; + if (entity instanceof EntityItemFrame entityitemframe) { - if (this.tickCount % 10 == 0) { + if (true || this.tickCount % 10 == 0) { // CraftBukkit - Moved below, should always enter this block ItemStack itemstack = entityitemframe.getItem(); - if (itemstack.getItem() instanceof ItemWorldMap) { + if (this.tickCount % 10 == 0 && itemstack.getItem() instanceof ItemWorldMap) { // CraftBukkit - Moved this.tickCounter % 10 logic here so item frames do not enter the other blocks - Integer integer = ItemWorldMap.getMapId(itemstack); - WorldMap worldmap = ItemWorldMap.getSavedData(integer, this.level); + MapId mapid = (MapId) itemstack.get(DataComponents.MAP_ID); + WorldMap worldmap = ItemWorldMap.getSavedData(mapid, this.level); if (worldmap != null) { - Iterator iterator = this.level.players().iterator(); @@ -58,7 +58,7 @@ + EntityPlayer entityplayer = iterator.next().getPlayer(); // CraftBukkit worldmap.tickCarriedBy(entityplayer, itemstack); - Packet packet = worldmap.getUpdatePacket(integer, entityplayer); + Packet packet = worldmap.getUpdatePacket(mapid, entityplayer); @@ -228,7 +238,27 @@ ++this.tickCount; @@ -85,10 +85,10 @@ + this.broadcastAndSend(new PacketPlayOutEntityVelocity(this.entity)); + } + // CraftBukkit end - this.entity.hurtMarked = false; - } - -@@ -256,7 +286,10 @@ + entity = this.entity; + if (entity instanceof EntityFireball) { + EntityFireball entityfireball = (EntityFireball) entity; +@@ -263,7 +293,10 @@ public void sendPairingData(EntityPlayer entityplayer, Consumer> consumer) { if (this.entity.isRemoved()) { @@ -100,7 +100,7 @@ } Packet packet = this.entity.getAddEntityPacket(); -@@ -272,6 +305,12 @@ +@@ -279,6 +312,12 @@ if (this.entity instanceof EntityLiving) { Collection collection = ((EntityLiving) this.entity).getAttributes().getSyncableAttributes(); @@ -113,7 +113,7 @@ if (!collection.isEmpty()) { consumer.accept(new PacketPlayOutUpdateAttributes(this.entity.getId(), collection)); } -@@ -303,6 +342,7 @@ +@@ -310,6 +349,7 @@ if (!list.isEmpty()) { consumer.accept(new PacketPlayOutEntityEquipment(this.entity.getId(), list)); } @@ -121,7 +121,7 @@ } if (!this.entity.getPassengers().isEmpty()) { -@@ -338,6 +378,11 @@ +@@ -343,6 +383,11 @@ Set set = ((EntityLiving) this.entity).getAttributes().getDirtyAttributes(); 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 67d9bd0f2d..ef4371bdc5 100644 --- a/paper-server/nms-patches/net/minecraft/server/level/PlayerChunk.patch +++ b/paper-server/nms-patches/net/minecraft/server/level/PlayerChunk.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/server/level/PlayerChunk.java +++ b/net/minecraft/server/level/PlayerChunk.java -@@ -36,6 +36,10 @@ - import net.minecraft.world.level.chunk.ProtoChunkExtension; +@@ -34,6 +34,10 @@ + import net.minecraft.world.level.chunk.status.ChunkStatus; import net.minecraft.world.level.lighting.LevelLightEngine; +// CraftBukkit start @@ -10,8 +10,8 @@ + public class PlayerChunk { - public static final Either UNLOADED_CHUNK = Either.right(PlayerChunk.Failure.UNLOADED); -@@ -72,12 +76,12 @@ + public static final ChunkResult UNLOADED_CHUNK = ChunkResult.error("Unloaded chunk"); +@@ -70,12 +74,12 @@ this.fullChunkFuture = PlayerChunk.UNLOADED_LEVEL_CHUNK_FUTURE; this.tickingChunkFuture = PlayerChunk.UNLOADED_LEVEL_CHUNK_FUTURE; this.entityTickingChunkFuture = PlayerChunk.UNLOADED_LEVEL_CHUNK_FUTURE; @@ -27,7 +27,7 @@ this.pos = chunkcoordintpair; this.levelHeightAccessor = levelheightaccessor; this.lightEngine = levellightengine; -@@ -90,6 +94,20 @@ +@@ -88,6 +92,20 @@ this.changedBlocksPerSection = new ShortSet[levelheightaccessor.getSectionsCount()]; } @@ -39,40 +39,25 @@ + } + + public Chunk getFullChunkNowUnchecked() { -+ CompletableFuture> statusFuture = this.getFutureIfPresentUnchecked(ChunkStatus.FULL); -+ Either either = (Either) statusFuture.getNow(null); -+ return (either == null) ? null : (Chunk) either.left().orElse(null); ++ CompletableFuture> statusFuture = this.getFutureIfPresentUnchecked(ChunkStatus.FULL); ++ ChunkResult either = statusFuture.getNow(null); ++ return (either == null) ? null : (Chunk) either.orElse(null); + } + // CraftBukkit end + - public CompletableFuture> getFutureIfPresentUnchecked(ChunkStatus chunkstatus) { - CompletableFuture> completablefuture = (CompletableFuture) this.futures.get(chunkstatus.getIndex()); + public CompletableFuture> getFutureIfPresentUnchecked(ChunkStatus chunkstatus) { + CompletableFuture> completablefuture = (CompletableFuture) this.futures.get(chunkstatus.getIndex()); + +@@ -112,7 +130,7 @@ -@@ -115,9 +133,9 @@ @Nullable public Chunk getTickingChunk() { - CompletableFuture> completablefuture = this.getTickingChunkFuture(); -- Either either = (Either) completablefuture.getNow((Object) null); -+ Either either = (Either) completablefuture.getNow(null); // CraftBukkit - decompile error - -- return either == null ? null : (Chunk) either.left().orElse((Object) null); -+ return either == null ? null : (Chunk) either.left().orElse(null); // CraftBukkit - decompile error +- return (Chunk) ((ChunkResult) this.getTickingChunkFuture().getNow(PlayerChunk.UNLOADED_LEVEL_CHUNK)).orElse((Object) null); ++ return (Chunk) ((ChunkResult) this.getTickingChunkFuture().getNow(PlayerChunk.UNLOADED_LEVEL_CHUNK)).orElse(null); // CraftBukkit - decompile error } public CompletableFuture getChunkSendSyncFuture() { -@@ -132,9 +150,9 @@ - @Nullable - public Chunk getFullChunk() { - CompletableFuture> completablefuture = this.getFullChunkFuture(); -- Either either = (Either) completablefuture.getNow((Object) null); -+ Either either = (Either) completablefuture.getNow(null); // CraftBukkit - decompile error - -- return either == null ? null : (Chunk) either.left().orElse((Object) null); -+ return either == null ? null : (Chunk) either.left().orElse(null); // CraftBukkit - decompile error - } - - @Nullable -@@ -179,6 +197,7 @@ +@@ -166,6 +184,7 @@ if (chunk != null) { int i = this.levelHeightAccessor.getSectionIndex(blockposition.getY()); @@ -80,20 +65,16 @@ if (this.changedBlocksPerSection[i] == null) { this.hasChangedSections = true; this.changedBlocksPerSection[i] = new ShortOpenHashSet(); -@@ -189,10 +208,10 @@ +@@ -176,7 +195,7 @@ } public void sectionLightChanged(EnumSkyBlock enumskyblock, int i) { -- Either either = (Either) this.getFutureIfPresent(ChunkStatus.INITIALIZE_LIGHT).getNow((Object) null); -+ Either either = (Either) this.getFutureIfPresent(ChunkStatus.INITIALIZE_LIGHT).getNow(null); // CraftBukkit - decompile error +- IChunkAccess ichunkaccess = (IChunkAccess) ((ChunkResult) this.getFutureIfPresent(ChunkStatus.INITIALIZE_LIGHT).getNow(PlayerChunk.UNLOADED_CHUNK)).orElse((Object) null); ++ IChunkAccess ichunkaccess = (IChunkAccess) ((ChunkResult) this.getFutureIfPresent(ChunkStatus.INITIALIZE_LIGHT).getNow(PlayerChunk.UNLOADED_CHUNK)).orElse(null); // CraftBukkit - decompile error - if (either != null) { -- IChunkAccess ichunkaccess = (IChunkAccess) either.left().orElse((Object) null); -+ IChunkAccess ichunkaccess = (IChunkAccess) either.left().orElse(null); // CraftBukkit - decompile error - - if (ichunkaccess != null) { - ichunkaccess.setUnsaved(true); -@@ -257,8 +276,11 @@ + if (ichunkaccess != null) { + ichunkaccess.setUnsaved(true); +@@ -240,8 +259,11 @@ PacketPlayOutMultiBlockChange packetplayoutmultiblockchange = new PacketPlayOutMultiBlockChange(sectionposition, shortset, chunksection); this.broadcast(list, packetplayoutmultiblockchange); @@ -106,16 +87,16 @@ }); } } -@@ -394,7 +416,7 @@ +@@ -374,7 +396,7 @@ this.pendingFullStateConfirmation = completablefuture1; - completablefuture.thenAccept((either) -> { - either.ifLeft((chunk) -> { + completablefuture.thenAccept((chunkresult) -> { + chunkresult.ifSuccess((chunk) -> { - completablefuture1.complete((Object) null); + completablefuture1.complete(null); // CraftBukkit - decompile error }); }); } -@@ -411,6 +433,30 @@ +@@ -391,6 +413,30 @@ boolean flag1 = ChunkLevel.isLoaded(this.ticketLevel); FullChunkStatus fullchunkstatus = ChunkLevel.fullStatus(this.oldTicketLevel); FullChunkStatus fullchunkstatus1 = ChunkLevel.fullStatus(this.ticketLevel); @@ -123,7 +104,7 @@ + // ChunkUnloadEvent: Called before the chunk is unloaded: isChunkLoaded is still true and chunk can still be modified by plugins. + if (fullchunkstatus.isOrAfter(FullChunkStatus.FULL) && !fullchunkstatus1.isOrAfter(FullChunkStatus.FULL)) { + this.getFutureIfPresentUnchecked(ChunkStatus.FULL).thenAccept((either) -> { -+ Chunk chunk = (Chunk)either.left().orElse(null); ++ Chunk chunk = (Chunk) either.orElse(null); + if (chunk != null) { + playerchunkmap.callbackExecutor.execute(() -> { + // Minecraft will apply the chunks tick lists to the world once the chunk got loaded, and then store the tick @@ -145,8 +126,8 @@ + // CraftBukkit end if (flag) { - Either either = Either.right(new PlayerChunk.Failure() { -@@ -481,6 +527,26 @@ + ChunkResult chunkresult = ChunkResult.error(() -> { +@@ -459,6 +505,26 @@ this.onLevelChange.onLevelChange(this.pos, this::getQueueLevel, this.ticketLevel, this::setQueueLevel); this.oldTicketLevel = this.ticketLevel; @@ -154,7 +135,7 @@ + // ChunkLoadEvent: Called after the chunk is loaded: isChunkLoaded returns true and chunk is ready to be modified by plugins. + if (!fullchunkstatus.isOrAfter(FullChunkStatus.FULL) && fullchunkstatus1.isOrAfter(FullChunkStatus.FULL)) { + this.getFutureIfPresentUnchecked(ChunkStatus.FULL).thenAccept((either) -> { -+ Chunk chunk = (Chunk)either.left().orElse(null); ++ Chunk chunk = (Chunk) either.orElse(null); + if (chunk != null) { + playerchunkmap.callbackExecutor.execute(() -> { + chunk.loadCallback(); 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 7f21fd8f03..dd9b7027ec 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 -@@ -101,6 +101,10 @@ +@@ -104,6 +104,10 @@ import org.apache.commons.lang3.mutable.MutableBoolean; import org.slf4j.Logger; @@ -8,16 +8,13 @@ +import org.bukkit.craftbukkit.generator.CustomChunkGenerator; +// CraftBukkit end + - public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { + public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.c { private static final byte CHUNK_TYPE_REPLACEABLE = -1; -@@ -141,7 +145,28 @@ - private final Long2ByteMap chunkTypeCache; - private final Long2LongMap chunkSaveCooldowns; - private final Queue unloadQueue; -- private int serverViewDistance; -+ public int serverViewDistance; -+ +@@ -146,6 +150,27 @@ + public int serverViewDistance; + private WorldGenContext worldGenContext; + + // CraftBukkit start - recursion-safe executor for Chunk loadCallback() and unloadCallback() + public final CallbackExecutor callbackExecutor = new CallbackExecutor(); + public static final class CallbackExecutor implements java.util.concurrent.Executor, Runnable { @@ -38,10 +35,11 @@ + } + }; + // CraftBukkit end - ++ 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(convertable_conversionsession.getDimensionPath(worldserver.dimension()).resolve("region"), datafixer, flag); -@@ -161,6 +186,11 @@ + super(new RegionStorageInfo(convertable_conversionsession.getLevelId(), worldserver.dimension(), "chunk"), convertable_conversionsession.getDimensionPath(worldserver.dimension()).resolve("region"), datafixer, flag); + this.visibleChunkMap = this.updatingChunkMap.clone(); +@@ -163,6 +188,11 @@ this.storageName = path.getFileName().toString(); this.level = worldserver; this.generator = chunkgenerator; @@ -53,11 +51,11 @@ IRegistryCustom iregistrycustom = worldserver.registryAccess(); long j = worldserver.getSeed(); -@@ -332,9 +362,12 @@ - CompletableFuture>> completablefuture1 = SystemUtils.sequence(list); - CompletableFuture, PlayerChunk.Failure>> completablefuture2 = completablefuture1.thenApply((list2) -> { +@@ -332,16 +362,19 @@ + CompletableFuture>> completablefuture1 = SystemUtils.sequence(list); + CompletableFuture>> completablefuture2 = completablefuture1.thenApply((list2) -> { List list3 = Lists.newArrayList(); -- final int l1 = 0; +- int l1 = 0; + // CraftBukkit start - decompile error + int cnt = 0; @@ -65,10 +63,18 @@ + for (Iterator iterator = list2.iterator(); iterator.hasNext(); ++cnt) { + final int l1 = cnt; + // CraftBukkit end - final Either either = (Either) iterator.next(); + ChunkResult chunkresult = (ChunkResult) iterator.next(); - if (either == null) { -@@ -540,7 +573,7 @@ + if (chunkresult == null) { + throw this.debugFuturesAndCreateReportedException(new IllegalStateException("At least one of the chunk futures were null"), "n/a"); + } + +- IChunkAccess ichunkaccess = (IChunkAccess) chunkresult.orElse((Object) null); ++ IChunkAccess ichunkaccess = (IChunkAccess) chunkresult.orElse(null); // CraftBukkit - decompile error + + if (ichunkaccess == null) { + return ChunkResult.error(() -> { +@@ -538,7 +571,7 @@ private void scheduleUnload(long i, PlayerChunk playerchunk) { CompletableFuture completablefuture = playerchunk.getChunkToSave(); @@ -77,19 +83,16 @@ CompletableFuture completablefuture1 = playerchunk.getChunkToSave(); if (completablefuture1 != completablefuture) { -@@ -631,9 +664,9 @@ - ProtoChunk protochunk = ChunkRegionLoader.read(this.level, this.poiManager, chunkcoordintpair, (NBTTagCompound) optional.get()); +@@ -708,7 +741,7 @@ + }; - this.markPosition(chunkcoordintpair, protochunk.getStatus().getChunkType()); -- return Either.left(protochunk); -+ return Either.left(protochunk); // CraftBukkit - decompile error - } else { -- return Either.left(this.createEmptyChunk(chunkcoordintpair)); -+ return Either.left(this.createEmptyChunk(chunkcoordintpair)); // CraftBukkit - decompile error - } - }, this.mainThreadExecutor).exceptionallyAsync((throwable) -> { - return this.handleChunkLoadFailure(throwable, chunkcoordintpair); -@@ -748,7 +781,21 @@ + return completablefuture.thenComposeAsync((chunkresult) -> { +- List list = (List) chunkresult.orElse((Object) null); ++ List list = (List) chunkresult.orElse(null); // CraftBukkit - decompile error + + if (list == null) { + this.releaseLightTicket(chunkcoordintpair); +@@ -773,7 +806,21 @@ private static void postLoadProtoChunk(WorldServer worldserver, List list) { if (!list.isEmpty()) { @@ -112,7 +115,7 @@ } } -@@ -860,7 +907,7 @@ +@@ -879,7 +926,7 @@ if (!playerchunk.wasAccessibleSinceLastSave()) { return false; } else { @@ -121,7 +124,7 @@ if (!(ichunkaccess instanceof ProtoChunkExtension) && !(ichunkaccess instanceof Chunk)) { return false; -@@ -1017,7 +1064,8 @@ +@@ -1040,7 +1087,8 @@ return ichunkaccess instanceof Chunk ? Optional.of((Chunk) ichunkaccess) : Optional.empty(); }); @@ -131,16 +134,16 @@ return chunk.getBlockEntities().size(); }).orElse(0), tickingtracker.getTicketDebugString(i), tickingtracker.getLevel(i), optional1.map((chunk) -> { return chunk.getBlockTicks().count(); -@@ -1030,7 +1078,7 @@ +@@ -1053,7 +1101,7 @@ - private static String printFuture(CompletableFuture> completablefuture) { + private static String printFuture(CompletableFuture> completablefuture) { try { -- Either either = (Either) completablefuture.getNow((Object) null); -+ Either either = (Either) completablefuture.getNow(null); // CraftBukkit - decompile error +- ChunkResult chunkresult = (ChunkResult) completablefuture.getNow((Object) null); ++ ChunkResult chunkresult = (ChunkResult) completablefuture.getNow(null); // CraftBukkit - decompile error - return either != null ? (String) either.map((chunk) -> { - return "done"; -@@ -1046,12 +1094,14 @@ + return chunkresult != null ? (chunkresult.isSuccess() ? "done" : "unloaded") : "not completed"; + } catch (CompletionException completionexception) { +@@ -1065,12 +1113,14 @@ private CompletableFuture> readChunk(ChunkCoordIntPair chunkcoordintpair) { return this.read(chunkcoordintpair).thenApplyAsync((optional) -> { @@ -158,16 +161,16 @@ } boolean anyPlayerCloseEnoughForSpawning(ChunkCoordIntPair chunkcoordintpair) { -@@ -1460,7 +1510,7 @@ +@@ -1473,7 +1523,7 @@ public final Set seenBy = Sets.newIdentityHashSet(); - public EntityTracker(Entity entity, int i, int j, boolean flag) { + public EntityTracker(final Entity entity, final int i, final int j, final boolean flag) { - this.serverEntity = new EntityTrackerEntry(PlayerChunkMap.this.level, entity, j, flag, this::broadcast); + this.serverEntity = new EntityTrackerEntry(PlayerChunkMap.this.level, entity, j, flag, this::broadcast, seenBy); // CraftBukkit this.entity = entity; this.range = i; this.lastSectionPos = SectionPosition.of((EntityAccess) entity); -@@ -1520,6 +1570,11 @@ +@@ -1533,6 +1583,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 370a8ae24b..c01a3a913c 100644 --- a/paper-server/nms-patches/net/minecraft/server/level/PlayerInteractManager.patch +++ b/paper-server/nms-patches/net/minecraft/server/level/PlayerInteractManager.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/server/level/PlayerInteractManager.java +++ b/net/minecraft/server/level/PlayerInteractManager.java -@@ -26,6 +26,27 @@ - import net.minecraft.world.phys.Vec3D; +@@ -25,6 +25,27 @@ + import net.minecraft.world.phys.MovingObjectPositionBlock; import org.slf4j.Logger; +// CraftBukkit start @@ -28,7 +28,7 @@ public class PlayerInteractManager { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -56,9 +77,16 @@ +@@ -55,9 +76,16 @@ if (enumgamemode == this.gameModeForPlayer) { return false; } else { @@ -44,9 +44,9 @@ - this.player.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.a.UPDATE_GAME_MODE, this.player)); + this.player.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.a.UPDATE_GAME_MODE, this.player), this.player); // CraftBukkit this.level.updateSleepingPlayerList(); - return true; - } -@@ -88,7 +116,7 @@ + if (enumgamemode == EnumGamemode.CREATIVE) { + this.player.resetCurrentImpulseContext(); +@@ -91,7 +119,7 @@ } public void tick() { @@ -55,7 +55,7 @@ IBlockData iblockdata; if (this.hasDelayedDestroy) { -@@ -142,11 +170,33 @@ +@@ -145,11 +173,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; -@@ -162,11 +212,43 @@ +@@ -165,11 +215,43 @@ float f = 1.0F; iblockdata = this.level.getBlockState(blockposition); @@ -134,7 +134,7 @@ if (!iblockdata.isAir() && f >= 1.0F) { this.destroyAndAck(blockposition, j, "insta mine"); } else { -@@ -211,13 +293,15 @@ +@@ -214,13 +296,15 @@ } else if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.ABORT_DESTROY_BLOCK) { this.isDestroyingBlock = false; if (!Objects.equals(this.destroyPos, blockposition)) { @@ -151,7 +151,7 @@ } } -@@ -235,10 +319,65 @@ +@@ -238,10 +322,65 @@ public boolean destroyBlock(BlockPosition blockposition) { IBlockData iblockdata = this.level.getBlockState(blockposition); @@ -218,7 +218,7 @@ TileEntity tileentity = this.level.getBlockEntity(blockposition); Block block = iblockdata.getBlock(); -@@ -248,6 +387,10 @@ +@@ -251,6 +390,10 @@ } else if (this.player.blockActionRestricted(this.level, blockposition, this.gameModeForPlayer)) { return false; } else { @@ -229,7 +229,7 @@ IBlockData iblockdata1 = block.playerWillDestroy(this.level, blockposition, iblockdata, this.player); boolean flag = this.level.removeBlock(blockposition, false); -@@ -256,19 +399,32 @@ +@@ -259,19 +402,32 @@ } if (this.isCreative()) { @@ -265,7 +265,7 @@ } } } -@@ -313,14 +469,54 @@ +@@ -309,14 +465,53 @@ } } @@ -278,7 +278,6 @@ public EnumInteractionResult useItemOn(EntityPlayer entityplayer, World world, ItemStack itemstack, EnumHand enumhand, MovingObjectPositionBlock movingobjectpositionblock) { BlockPosition blockposition = movingobjectpositionblock.getBlockPos(); IBlockData iblockdata = world.getBlockState(blockposition); -+ EnumInteractionResult enuminteractionresult = EnumInteractionResult.PASS; + boolean cancelledBlock = false; if (!iblockdata.getBlock().isEnabled(world.enabledFeatures())) { @@ -314,40 +313,18 @@ + entityplayer.connection.send(new PacketPlayOutBlockChange(world, blockposition.above())); + } + entityplayer.getBukkitEntity().updateInventory(); // SPIGOT-2867 -+ enuminteractionresult = (event.useItemInHand() != Event.Result.ALLOW) ? EnumInteractionResult.SUCCESS : EnumInteractionResult.PASS; ++ return (event.useItemInHand() != Event.Result.ALLOW) ? EnumInteractionResult.SUCCESS : EnumInteractionResult.PASS; + } else if (this.gameModeForPlayer == EnumGamemode.SPECTATOR) { + ITileInventory itileinventory = iblockdata.getMenuProvider(world, blockposition); if (itileinventory != null) { entityplayer.openMenu(itileinventory); -@@ -334,7 +530,7 @@ - ItemStack itemstack1 = itemstack.copy(); - - if (!flag1) { -- EnumInteractionResult enuminteractionresult = iblockdata.use(world, entityplayer, enumhand, movingobjectpositionblock); -+ enuminteractionresult = iblockdata.use(world, entityplayer, enumhand, movingobjectpositionblock); - - if (enuminteractionresult.consumesAction()) { - CriterionTriggers.ITEM_USED_ON_BLOCK.trigger(entityplayer, blockposition, itemstack1); -@@ -342,7 +538,7 @@ +@@ -347,7 +542,7 @@ } } - if (!itemstack.isEmpty() && !entityplayer.getCooldowns().isOnCooldown(itemstack.getItem())) { -+ if (!itemstack.isEmpty() && enuminteractionresult != EnumInteractionResult.SUCCESS && !interactResult) { // add !interactResult SPIGOT-764 ++ if (!itemstack.isEmpty() && !interactResult) { // add !interactResult SPIGOT-764 ItemActionContext itemactioncontext = new ItemActionContext(entityplayer, enumhand, movingobjectpositionblock); - EnumInteractionResult enuminteractionresult1; -@@ -360,10 +556,10 @@ - } - - return enuminteractionresult1; -- } else { -- return EnumInteractionResult.PASS; - } - } -+ return enuminteractionresult; -+ // CraftBukkit end - } - - public void setLevel(WorldServer worldserver) { + if (this.isCreative()) { diff --git a/paper-server/nms-patches/net/minecraft/server/level/RegionLimitedWorldAccess.patch b/paper-server/nms-patches/net/minecraft/server/level/RegionLimitedWorldAccess.patch index b638902b8d..b77319ec9d 100644 --- a/paper-server/nms-patches/net/minecraft/server/level/RegionLimitedWorldAccess.patch +++ b/paper-server/nms-patches/net/minecraft/server/level/RegionLimitedWorldAccess.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/level/RegionLimitedWorldAccess.java +++ b/net/minecraft/server/level/RegionLimitedWorldAccess.java -@@ -208,7 +208,7 @@ +@@ -216,7 +216,7 @@ if (iblockdata.isAir()) { return false; } else { @@ -9,7 +9,7 @@ TileEntity tileentity = iblockdata.hasBlockEntity() ? this.getBlockEntity(blockposition) : null; Block.dropResources(iblockdata, this.level, blockposition, tileentity, entity, ItemStack.EMPTY); -@@ -327,6 +327,13 @@ +@@ -335,6 +335,13 @@ @Override public boolean addFreshEntity(Entity entity) { 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 5d14ea6723..3c7c308512 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 -@@ -164,6 +164,26 @@ +@@ -170,6 +170,23 @@ import net.minecraft.world.ticks.TickListServer; import org.slf4j.Logger; @@ -11,32 +11,29 @@ +import net.minecraft.world.level.levelgen.ChunkProviderFlat; +import net.minecraft.world.level.storage.WorldDataServer; +import org.bukkit.Bukkit; -+import org.bukkit.Location; +import org.bukkit.WeatherType; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.craftbukkit.generator.CustomWorldChunkManager; -+import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.craftbukkit.util.WorldUUID; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.server.MapInitializeEvent; +import org.bukkit.event.weather.LightningStrikeEvent; -+import org.bukkit.event.world.GenericGameEvent; +import org.bukkit.event.world.TimeSkipEvent; +// CraftBukkit end + public class WorldServer extends World implements GeneratorAccessSeed { public static final BlockPosition END_SPAWN_POINT = new BlockPosition(100, 50, 0); -@@ -177,7 +197,7 @@ +@@ -183,7 +200,7 @@ final List players; private final ChunkProviderServer chunkSource; private final MinecraftServer server; - public final IWorldDataServer serverLevelData; + public final WorldDataServer serverLevelData; // CraftBukkit - type + private int lastSpawnChunkRadius; final EntityTickList entityTickList; public final PersistentEntitySectionManager entityManager; - private final GameEventDispatcher gameEventDispatcher; -@@ -202,12 +222,30 @@ +@@ -210,12 +227,30 @@ private final boolean tickTime; private final RandomSequences randomSequences; @@ -72,7 +69,7 @@ this.players = Lists.newArrayList(); this.entityTickList = new EntityTickList(); this.blockTicks = new TickListServer<>(this::isPositionTickingWithEntitiesLoaded, this.getProfilerSupplier()); -@@ -221,6 +259,22 @@ +@@ -230,6 +265,22 @@ this.customSpawners = list; this.serverLevelData = iworlddataserver; ChunkGenerator chunkgenerator = worlddimension.generator(); @@ -94,8 +91,8 @@ + // CraftBukkit end boolean flag2 = minecraftserver.forceSynchronousWrites(); DataFixer datafixer = minecraftserver.getFixerUpper(); - EntityPersistentStorage entitypersistentstorage = new EntityStorage(this, convertable_conversionsession.getDimensionPath(resourcekey).resolve("entities"), datafixer, flag2, minecraftserver); -@@ -248,9 +302,9 @@ + 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); +@@ -257,9 +308,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); @@ -108,7 +105,7 @@ } else { this.dragonFight = null; } -@@ -260,6 +314,7 @@ +@@ -269,6 +320,7 @@ this.randomSequences = (RandomSequences) Objects.requireNonNullElseGet(randomsequences, () -> { return (RandomSequences) this.getDataStorage().computeIfAbsent(RandomSequences.factory(l), "random_sequences"); }); @@ -116,7 +113,7 @@ } /** @deprecated */ -@@ -304,12 +359,20 @@ +@@ -313,12 +365,20 @@ long j; if (this.sleepStatus.areEnoughSleeping(i) && this.sleepStatus.areEnoughDeepSleeping(i, this.players)) { @@ -140,7 +137,7 @@ if (this.getGameRules().getBoolean(GameRules.RULE_WEATHER_CYCLE) && this.isRaining()) { this.resetWeatherCycle(); } -@@ -344,7 +407,7 @@ +@@ -353,7 +413,7 @@ this.handlingTick = false; gameprofilerfiller.pop(); @@ -149,7 +146,7 @@ if (flag1) { this.resetEmptyTime(); -@@ -360,7 +423,7 @@ +@@ -369,7 +429,7 @@ this.entityTickList.forEach((entity) -> { if (!entity.isRemoved()) { @@ -158,7 +155,7 @@ entity.discard(); } else if (!tickratemanager.isEntityFrozen(entity)) { gameprofilerfiller.push("checkDespawn"); -@@ -432,7 +495,7 @@ +@@ -441,7 +501,7 @@ private void wakeUpAllPlayers() { this.sleepStatus.removeAllSleepers(); @@ -167,7 +164,7 @@ entityplayer.stopSleepInBed(false, false); }); } -@@ -459,7 +522,7 @@ +@@ -468,7 +528,7 @@ entityhorseskeleton.setTrap(true); entityhorseskeleton.setAge(0); entityhorseskeleton.setPos((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ()); @@ -176,7 +173,7 @@ } } -@@ -468,7 +531,7 @@ +@@ -477,7 +537,7 @@ if (entitylightning != null) { entitylightning.moveTo(Vec3D.atBottomCenterOf(blockposition)); entitylightning.setVisualOnly(flag1); @@ -185,7 +182,7 @@ } } } -@@ -524,7 +587,7 @@ +@@ -533,7 +593,7 @@ BiomeBase biomebase = (BiomeBase) this.getBiome(blockposition1).value(); if (biomebase.shouldFreeze(this, blockposition2)) { @@ -194,7 +191,7 @@ } if (this.isRaining()) { -@@ -540,10 +603,10 @@ +@@ -549,10 +609,10 @@ IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockSnow.LAYERS, j + 1); Block.pushEntitiesUp(iblockdata, iblockdata1, this, blockposition1); @@ -207,7 +204,7 @@ } } -@@ -704,6 +767,7 @@ +@@ -713,6 +773,7 @@ this.rainLevel = MathHelper.clamp(this.rainLevel, 0.0F, 1.0F); } @@ -215,7 +212,7 @@ if (this.oRainLevel != this.rainLevel) { this.server.getPlayerList().broadcastAll(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, this.rainLevel), this.dimension()); } -@@ -722,15 +786,48 @@ +@@ -731,15 +792,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)); } @@ -266,7 +263,7 @@ } public void resetEmptyTime() { -@@ -765,6 +862,7 @@ +@@ -774,6 +868,7 @@ }); gameprofilerfiller.incrementCounter("tickNonPassenger"); entity.tick(); @@ -274,7 +271,7 @@ this.getProfiler().pop(); Iterator iterator = entity.getPassengers().iterator(); -@@ -788,6 +886,7 @@ +@@ -797,6 +892,7 @@ }); gameprofilerfiller.incrementCounter("tickPassenger"); entity1.rideTick(); @@ -282,7 +279,7 @@ gameprofilerfiller.pop(); Iterator iterator = entity1.getPassengers().iterator(); -@@ -812,6 +911,7 @@ +@@ -821,6 +917,7 @@ ChunkProviderServer chunkproviderserver = this.getChunkSource(); if (!flag1) { @@ -290,7 +287,7 @@ if (iprogressupdate != null) { iprogressupdate.progressStartNoAbort(IChatBaseComponent.translatable("menu.savingLevel")); } -@@ -829,11 +929,19 @@ +@@ -838,11 +935,19 @@ } } @@ -299,7 +296,7 @@ + WorldServer worldserver1 = this; + + serverLevelData.setWorldBorder(worldserver1.getWorldBorder().createSettings()); -+ serverLevelData.setCustomBossEvents(this.server.getCustomBossEvents().save()); ++ serverLevelData.setCustomBossEvents(this.server.getCustomBossEvents().save(this.registryAccess())); + convertable.saveDataTag(this.server.registryAccess(), this.serverLevelData, this.server.getPlayerList().getSingleplayerData()); + // CraftBukkit end } @@ -311,7 +308,7 @@ } this.getChunkSource().getDataStorage().save(); -@@ -898,15 +1006,37 @@ +@@ -907,15 +1012,37 @@ @Override public boolean addFreshEntity(Entity entity) { @@ -352,7 +349,7 @@ } public void addDuringCommandTeleport(EntityPlayer entityplayer) { -@@ -937,24 +1067,37 @@ +@@ -946,24 +1073,37 @@ this.entityManager.addNewEntity(entityplayer); } @@ -394,7 +391,7 @@ return true; } } -@@ -965,13 +1108,35 @@ +@@ -974,13 +1114,35 @@ } public void removePlayerImmediately(EntityPlayer entityplayer, Entity.RemovalReason entity_removalreason) { @@ -431,7 +428,7 @@ while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer) iterator.next(); -@@ -980,6 +1145,12 @@ +@@ -989,6 +1151,12 @@ double d1 = (double) blockposition.getY() - entityplayer.getY(); double d2 = (double) blockposition.getZ() - entityplayer.getZ(); @@ -444,7 +441,7 @@ if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) { entityplayer.connection.send(new PacketPlayOutBlockBreakAnimation(i, blockposition, j)); } -@@ -1039,7 +1210,18 @@ +@@ -1049,7 +1217,18 @@ Iterator iterator = this.navigatingMobs.iterator(); while (iterator.hasNext()) { @@ -464,10 +461,10 @@ NavigationAbstract navigationabstract = entityinsentient.getNavigation(); if (navigationabstract.shouldRecomputePath(blockposition)) { -@@ -1101,6 +1283,11 @@ +@@ -1111,6 +1290,11 @@ @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, SoundEffect soundeffect) { - Explosion explosion = this.explode(entity, damagesource, explosiondamagecalculator, d0, d1, d2, f, flag, world_a, false, particleparam, particleparam1, soundeffect); + 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); + // CraftBukkit start + if (explosion.wasCanceled) { + return explosion; @@ -476,7 +473,7 @@ if (!explosion.interactsWithBlocks()) { explosion.clearToBlow(); -@@ -1173,13 +1360,20 @@ +@@ -1183,13 +1367,20 @@ } public int sendParticles(T t0, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) { @@ -499,7 +496,7 @@ ++j; } } -@@ -1230,7 +1424,7 @@ +@@ -1240,7 +1431,7 @@ @Nullable public BlockPosition findNearestMapStructure(TagKey tagkey, BlockPosition blockposition, int i, boolean flag) { @@ -508,31 +505,31 @@ return null; } else { Optional> optional = this.registryAccess().registryOrThrow(Registries.STRUCTURE).getTag(tagkey); -@@ -1272,11 +1466,22 @@ +@@ -1282,11 +1473,22 @@ @Nullable @Override - public WorldMap getMapData(String s) { -- return (WorldMap) this.getServer().overworld().getDataStorage().get(WorldMap.factory(), s); + public WorldMap getMapData(MapId mapid) { +- return (WorldMap) this.getServer().overworld().getDataStorage().get(WorldMap.factory(), mapid.key()); + // CraftBukkit start -+ WorldMap worldmap = (WorldMap) this.getServer().overworld().getDataStorage().get(WorldMap.factory(), s); ++ WorldMap worldmap = (WorldMap) this.getServer().overworld().getDataStorage().get(WorldMap.factory(), mapid.key()); + if (worldmap != null) { -+ worldmap.id = s; ++ worldmap.id = mapid; + } + return worldmap; + // CraftBukkit end } @Override - public void setMapData(String s, WorldMap worldmap) { + public void setMapData(MapId mapid, WorldMap worldmap) { + // CraftBukkit start -+ worldmap.id = s; ++ worldmap.id = mapid; + MapInitializeEvent event = new MapInitializeEvent(worldmap.mapView); + Bukkit.getServer().getPluginManager().callEvent(event); + // CraftBukkit end - this.getServer().overworld().getDataStorage().set(s, worldmap); + this.getServer().overworld().getDataStorage().set(mapid.key(), worldmap); } -@@ -1574,6 +1779,11 @@ +@@ -1597,6 +1799,11 @@ @Override public void blockUpdated(BlockPosition blockposition, Block block) { if (!this.isDebug()) { @@ -544,7 +541,7 @@ this.updateNeighborsAt(blockposition, block); } -@@ -1593,12 +1803,12 @@ +@@ -1616,12 +1823,12 @@ } public boolean isFlat() { @@ -559,7 +556,7 @@ } @Nullable -@@ -1621,7 +1831,7 @@ +@@ -1644,7 +1851,7 @@ private static String getTypeCount(Iterable iterable, Function function) { try { Object2IntOpenHashMap object2intopenhashmap = new Object2IntOpenHashMap(); @@ -568,7 +565,7 @@ while (iterator.hasNext()) { T t0 = iterator.next(); -@@ -1630,7 +1840,7 @@ +@@ -1653,7 +1860,7 @@ object2intopenhashmap.addTo(s, 1); } @@ -577,7 +574,7 @@ String s1 = (String) entry.getKey(); return s1 + ":" + entry.getIntValue(); -@@ -1641,17 +1851,33 @@ +@@ -1664,17 +1871,33 @@ } public static void makeObsidianPlatform(WorldServer worldserver) { @@ -613,7 +610,7 @@ } @Override -@@ -1785,6 +2011,8 @@ +@@ -1812,6 +2035,8 @@ } entity.updateDynamicGameEventListener(DynamicGameEventListener::add); @@ -622,7 +619,7 @@ } public void onTrackingEnd(Entity entity) { -@@ -1821,6 +2049,14 @@ +@@ -1843,6 +2068,14 @@ } entity.updateDynamicGameEventListener(DynamicGameEventListener::remove); diff --git a/paper-server/nms-patches/net/minecraft/server/network/HandshakeListener.patch b/paper-server/nms-patches/net/minecraft/server/network/HandshakeListener.patch index 5abb5c22e7..8f128db0c0 100644 --- a/paper-server/nms-patches/net/minecraft/server/network/HandshakeListener.patch +++ b/paper-server/nms-patches/net/minecraft/server/network/HandshakeListener.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/server/network/HandshakeListener.java +++ b/net/minecraft/server/network/HandshakeListener.java -@@ -11,8 +11,17 @@ - import net.minecraft.network.protocol.status.ServerPing; +@@ -12,8 +12,17 @@ + import net.minecraft.network.protocol.status.StatusProtocols; import net.minecraft.server.MinecraftServer; +// CraftBukkit start @@ -18,48 +18,52 @@ private static final IChatBaseComponent IGNORE_STATUS_REASON = IChatBaseComponent.translatable("disconnect.ignoring_status_request"); private final MinecraftServer server; private final NetworkManager connection; -@@ -24,9 +33,44 @@ +@@ -25,6 +34,7 @@ @Override public void handleIntention(PacketHandshakingInSetProtocol packethandshakinginsetprotocol) { + this.connection.hostname = packethandshakinginsetprotocol.hostName() + ":" + packethandshakinginsetprotocol.port(); // CraftBukkit - set hostname switch (packethandshakinginsetprotocol.intention()) { case LOGIN: - this.connection.setClientboundProtocolAfterHandshake(ClientIntent.LOGIN); -+ // CraftBukkit start - Connection throttle -+ try { -+ long currentTime = System.currentTimeMillis(); -+ long connectionThrottle = this.server.server.getConnectionThrottle(); -+ InetAddress address = ((java.net.InetSocketAddress) this.connection.getRemoteAddress()).getAddress(); + this.beginLogin(packethandshakinginsetprotocol, false); +@@ -58,6 +68,40 @@ + + private void beginLogin(PacketHandshakingInSetProtocol packethandshakinginsetprotocol, boolean flag) { + this.connection.setupOutboundProtocol(LoginProtocols.CLIENTBOUND); ++ // CraftBukkit start - Connection throttle ++ try { ++ long currentTime = System.currentTimeMillis(); ++ long connectionThrottle = this.server.server.getConnectionThrottle(); ++ InetAddress address = ((java.net.InetSocketAddress) this.connection.getRemoteAddress()).getAddress(); + -+ synchronized (throttleTracker) { -+ if (throttleTracker.containsKey(address) && !"127.0.0.1".equals(address.getHostAddress()) && currentTime - throttleTracker.get(address) < connectionThrottle) { -+ throttleTracker.put(address, currentTime); -+ IChatMutableComponent chatmessage = IChatBaseComponent.literal("Connection throttled! Please wait before reconnecting."); -+ this.connection.send(new PacketLoginOutDisconnect(chatmessage)); -+ this.connection.disconnect(chatmessage); -+ return; -+ } ++ synchronized (throttleTracker) { ++ if (throttleTracker.containsKey(address) && !"127.0.0.1".equals(address.getHostAddress()) && currentTime - throttleTracker.get(address) < connectionThrottle) { ++ throttleTracker.put(address, currentTime); ++ IChatMutableComponent chatmessage = IChatBaseComponent.literal("Connection throttled! Please wait before reconnecting."); ++ this.connection.send(new PacketLoginOutDisconnect(chatmessage)); ++ this.connection.disconnect(chatmessage); ++ return; ++ } + -+ throttleTracker.put(address, currentTime); -+ throttleCounter++; -+ if (throttleCounter > 200) { -+ throttleCounter = 0; ++ throttleTracker.put(address, currentTime); ++ throttleCounter++; ++ if (throttleCounter > 200) { ++ throttleCounter = 0; + -+ // Cleanup stale entries -+ java.util.Iterator iter = throttleTracker.entrySet().iterator(); -+ while (iter.hasNext()) { -+ java.util.Map.Entry entry = (java.util.Map.Entry) iter.next(); -+ if (entry.getValue() > connectionThrottle) { -+ iter.remove(); -+ } -+ } ++ // Cleanup stale entries ++ java.util.Iterator iter = throttleTracker.entrySet().iterator(); ++ while (iter.hasNext()) { ++ java.util.Map.Entry entry = (java.util.Map.Entry) iter.next(); ++ if (entry.getValue() > connectionThrottle) { ++ iter.remove(); + } + } -+ } catch (Throwable t) { -+ org.apache.logging.log4j.LogManager.getLogger().debug("Failed to check connection throttle", t); + } -+ // CraftBukkit end - if (packethandshakinginsetprotocol.protocolVersion() != SharedConstants.getCurrentVersion().getProtocolVersion()) { - IChatMutableComponent ichatmutablecomponent; ++ } ++ } catch (Throwable t) { ++ org.apache.logging.log4j.LogManager.getLogger().debug("Failed to check connection throttle", t); ++ } ++ // CraftBukkit end + if (packethandshakinginsetprotocol.protocolVersion() != SharedConstants.getCurrentVersion().getProtocolVersion()) { + IChatMutableComponent ichatmutablecomponent; diff --git a/paper-server/nms-patches/net/minecraft/server/network/LoginListener.patch b/paper-server/nms-patches/net/minecraft/server/network/LoginListener.patch index 3334a8db25..012e5b59f0 100644 --- a/paper-server/nms-patches/net/minecraft/server/network/LoginListener.patch +++ b/paper-server/nms-patches/net/minecraft/server/network/LoginListener.patch @@ -1,28 +1,62 @@ --- a/net/minecraft/server/network/LoginListener.java +++ b/net/minecraft/server/network/LoginListener.java -@@ -40,6 +40,13 @@ +@@ -42,8 +42,33 @@ import org.apache.commons.lang3.Validate; import org.slf4j.Logger; +-public class LoginListener implements PacketLoginInListener, TickablePacketListener { +// CraftBukkit start ++import net.minecraft.network.EnumProtocol; ++import net.minecraft.network.protocol.Packet; ++import net.minecraft.network.protocol.PlayerConnectionUtils; +import net.minecraft.server.level.EntityPlayer; ++import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.util.Waitable; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.event.player.PlayerPreLoginEvent; -+// CraftBukkit end + - public class LoginListener implements PacketLoginInListener, TickablePacketListener { ++public class LoginListener implements PacketLoginInListener, TickablePacketListener, CraftPlayer.TransferCookieConnection { ++ ++ @Override ++ public boolean isTransferred() { ++ return this.transferred; ++ } ++ ++ @Override ++ public EnumProtocol protocol() { ++ return EnumProtocol.LOGIN; ++ } ++ @Override ++ public void send(Packet packet) { ++ this.connection.send(packet); ++ } ++ // CraftBukkit end private static final AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0); -@@ -56,6 +63,7 @@ - @Nullable + static final Logger LOGGER = LogUtils.getLogger(); + private static final int MAX_TICKS_BEFORE_LOGIN = 600; +@@ -58,6 +83,7 @@ private GameProfile authenticatedProfile; private final String serverId; + private final boolean transferred; + private EntityPlayer player; // CraftBukkit - public LoginListener(MinecraftServer minecraftserver, NetworkManager networkmanager) { + public LoginListener(MinecraftServer minecraftserver, NetworkManager networkmanager, boolean flag) { this.state = LoginListener.EnumProtocolState.HELLO; -@@ -81,6 +89,13 @@ +@@ -74,6 +100,12 @@ + this.verifyLoginAndFinishConnectionSetup((GameProfile) Objects.requireNonNull(this.authenticatedProfile)); + } + ++ // CraftBukkit start ++ if (this.state == LoginListener.EnumProtocolState.WAITING_FOR_COOKIES && !this.player.getBukkitEntity().isAwaitingCookies()) { ++ this.postCookies(this.authenticatedProfile); ++ } ++ // CraftBukkit end ++ + if (this.state == LoginListener.EnumProtocolState.WAITING_FOR_DUPE_DISCONNECT && !this.isPlayerAlreadyInWorld((GameProfile) Objects.requireNonNull(this.authenticatedProfile))) { + this.finishLoginAndWaitForClient(this.authenticatedProfile); + } +@@ -84,6 +116,13 @@ } @@ -36,9 +70,9 @@ @Override public boolean isAcceptingMessages() { return this.connection.isConnected(); -@@ -126,7 +141,27 @@ +@@ -129,7 +168,27 @@ this.state = LoginListener.EnumProtocolState.KEY; - this.connection.send(new PacketLoginOutEncryptionBegin("", this.server.getKeyPair().getPublic().getEncoded(), this.challenge)); + this.connection.send(new PacketLoginOutEncryptionBegin("", this.server.getKeyPair().getPublic().getEncoded(), this.challenge, true)); } else { - this.startClientVerification(UUIDUtil.createOfflineProfile(this.requestedUsername)); + // CraftBukkit start @@ -65,7 +99,7 @@ } } -@@ -139,10 +174,12 @@ +@@ -142,10 +201,24 @@ private void verifyLoginAndFinishConnectionSetup(GameProfile gameprofile) { PlayerList playerlist = this.server.getPlayerList(); @@ -75,13 +109,25 @@ - if (ichatbasecomponent != null) { - this.disconnect(ichatbasecomponent); ++ if (this.player != null) { ++ if (this.player.getBukkitEntity().isAwaitingCookies()) { ++ this.state = LoginListener.EnumProtocolState.WAITING_FOR_COOKIES; ++ } else { ++ this.postCookies(gameprofile); ++ } ++ } ++ } ++ ++ private void postCookies(GameProfile gameprofile) { ++ PlayerList playerlist = this.server.getPlayerList(); ++ + if (this.player == null) { + // this.disconnect(ichatbasecomponent); + // CraftBukkit end } else { if (this.server.getCompressionThreshold() >= 0 && !this.connection.isMemoryConnection()) { this.connection.send(new PacketLoginOutSetCompression(this.server.getCompressionThreshold()), PacketSendListener.thenRun(() -> { -@@ -150,7 +187,7 @@ +@@ -153,7 +226,7 @@ })); } @@ -90,7 +136,7 @@ if (flag) { this.state = LoginListener.EnumProtocolState.WAITING_FOR_DUPE_DISCONNECT; -@@ -200,6 +237,12 @@ +@@ -203,6 +276,12 @@ if (profileresult != null) { GameProfile gameprofile = profileresult.profile(); @@ -103,7 +149,7 @@ LoginListener.LOGGER.info("UUID of player {} is {}", gameprofile.getName(), gameprofile.getId()); LoginListener.this.startClientVerification(gameprofile); } else if (LoginListener.this.server.isSingleplayer()) { -@@ -217,6 +260,11 @@ +@@ -220,6 +299,11 @@ LoginListener.this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.authservers_down")); LoginListener.LOGGER.error("Couldn't verify username because servers are unavailable"); } @@ -115,7 +161,7 @@ } } -@@ -233,6 +281,43 @@ +@@ -236,6 +320,43 @@ thread.start(); } @@ -126,7 +172,7 @@ + java.util.UUID uniqueId = gameprofile.getId(); + final org.bukkit.craftbukkit.CraftServer server = LoginListener.this.server.server; + -+ AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId); ++ AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId, this.transferred); + server.getPluginManager().callEvent(asyncEvent); + + if (PlayerPreLoginEvent.getHandlerList().getRegisteredListeners().length != 0) { @@ -158,13 +204,33 @@ + @Override public void handleCustomQueryPacket(ServerboundCustomQueryAnswerPacket serverboundcustomqueryanswerpacket) { - this.disconnect(LoginListener.DISCONNECT_UNEXPECTED_QUERY); -@@ -242,7 +327,7 @@ - public void handleLoginAcknowledgement(ServerboundLoginAcknowledgedPacket serverboundloginacknowledgedpacket) { + this.disconnect(ServerCommonPacketListenerImpl.DISCONNECT_UNEXPECTED_QUERY); +@@ -246,7 +367,7 @@ Validate.validState(this.state == LoginListener.EnumProtocolState.PROTOCOL_SWITCHING, "Unexpected login acknowledgement packet", new Object[0]); - CommonListenerCookie commonlistenercookie = CommonListenerCookie.createInitial((GameProfile) Objects.requireNonNull(this.authenticatedProfile)); + this.connection.setupOutboundProtocol(ConfigurationProtocols.CLIENTBOUND); + CommonListenerCookie commonlistenercookie = CommonListenerCookie.createInitial((GameProfile) Objects.requireNonNull(this.authenticatedProfile), this.transferred); - ServerConfigurationPacketListenerImpl serverconfigurationpacketlistenerimpl = new ServerConfigurationPacketListenerImpl(this.server, this.connection, commonlistenercookie); + ServerConfigurationPacketListenerImpl serverconfigurationpacketlistenerimpl = new ServerConfigurationPacketListenerImpl(this.server, this.connection, commonlistenercookie, this.player); // CraftBukkit - this.connection.setListener(serverconfigurationpacketlistenerimpl); + this.connection.setupInboundProtocol(ConfigurationProtocols.SERVERBOUND, serverconfigurationpacketlistenerimpl); serverconfigurationpacketlistenerimpl.startConfiguration(); +@@ -262,12 +383,18 @@ + + @Override + public void handleCookieResponse(ServerboundCookieResponsePacket serverboundcookieresponsepacket) { ++ // CraftBukkit start ++ PlayerConnectionUtils.ensureRunningOnSameThread(serverboundcookieresponsepacket, this, this.server); ++ if (this.player != null && this.player.getBukkitEntity().handleCookieResponse(serverboundcookieresponsepacket)) { ++ return; ++ } ++ // CraftBukkit end + this.disconnect(ServerCommonPacketListenerImpl.DISCONNECT_UNEXPECTED_QUERY); + } + + private static enum EnumProtocolState { + +- HELLO, KEY, AUTHENTICATING, NEGOTIATING, VERIFYING, WAITING_FOR_DUPE_DISCONNECT, PROTOCOL_SWITCHING, ACCEPTED; ++ HELLO, KEY, AUTHENTICATING, NEGOTIATING, VERIFYING, WAITING_FOR_COOKIES, WAITING_FOR_DUPE_DISCONNECT, PROTOCOL_SWITCHING, ACCEPTED; // CraftBukkit + + private EnumProtocolState() {} + } 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 c55952434f..eab5d66be4 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 -@@ -183,6 +183,67 @@ +@@ -190,6 +190,68 @@ import net.minecraft.world.phys.shapes.VoxelShapes; import org.slf4j.Logger; @@ -10,6 +10,7 @@ +import java.util.concurrent.ExecutionException; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; ++import net.minecraft.network.EnumProtocol; +import net.minecraft.network.chat.OutgoingChatMessage; +import net.minecraft.network.protocol.game.PacketPlayOutAttachEntity; +import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; @@ -68,7 +69,7 @@ public class PlayerConnection extends ServerCommonPacketListenerImpl implements PacketListenerPlayIn, ServerPlayerConnection, TickablePacketListener { static final Logger LOGGER = LogUtils.getLogger(); -@@ -194,7 +255,9 @@ +@@ -203,7 +265,9 @@ public final PlayerChunkSender chunkSender; private int tickCount; private int ackBlockChangesUpTo = -1; @@ -79,16 +80,16 @@ private int dropSpamTickCount; private double firstGoodX; private double firstGoodY; -@@ -229,7 +292,7 @@ +@@ -238,7 +302,7 @@ private boolean waitingForSwitchToConfig; public PlayerConnection(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayer entityplayer, CommonListenerCookie commonlistenercookie) { - super(minecraftserver, networkmanager, commonlistenercookie); + super(minecraftserver, networkmanager, commonlistenercookie, entityplayer); // CraftBukkit this.chunkSender = new PlayerChunkSender(networkmanager.isMemoryConnection()); - networkmanager.setListener(this); this.player = entityplayer; -@@ -239,9 +302,25 @@ + entityplayer.connection = this; +@@ -247,9 +311,30 @@ Objects.requireNonNull(minecraftserver); this.signedMessageDecoder = SignedMessageChain.b.unsigned(uuid, minecraftserver::enforceSecureProfile); @@ -96,7 +97,7 @@ + this.chatMessageChain = new FutureChain(minecraftserver.chatExecutor); // CraftBukkit - async chat } -+ // CraftBukkit start - add fields ++ // CraftBukkit start - add fields and methods + private int lastTick = MinecraftServer.currentTick; + private int allowedPlayerTicks = 1; + private int lastDropTick = MinecraftServer.currentTick; @@ -110,12 +111,17 @@ + private float lastPitch = Float.MAX_VALUE; + private float lastYaw = Float.MAX_VALUE; + private boolean justTeleported = false; ++ ++ @Override ++ public EnumProtocol protocol() { ++ return PacketListenerPlayIn.super.protocol(); ++ } + // CraftBukkit end + @Override public void tick() { if (this.ackBlockChangesUpTo > -1) { -@@ -293,15 +372,21 @@ +@@ -301,15 +386,21 @@ } this.keepConnectionAlive(); @@ -137,7 +143,7 @@ this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.idling")); } -@@ -378,6 +463,13 @@ +@@ -398,6 +489,13 @@ if (entity != this.player && entity.getControllingPassenger() == this.player && entity == this.lastVehicle) { WorldServer worldserver = this.player.serverLevel(); @@ -151,7 +157,7 @@ double d0 = entity.getX(); double d1 = entity.getY(); double d2 = entity.getZ(); -@@ -392,7 +484,33 @@ +@@ -412,7 +510,33 @@ double d9 = entity.getDeltaMovement().lengthSqr(); double d10 = d6 * d6 + d7 * d7 + d8 * d8; @@ -186,7 +192,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; -@@ -432,14 +550,76 @@ +@@ -452,14 +576,76 @@ } entity.absMoveTo(d3, d4, d5, f, f1); @@ -263,7 +269,7 @@ this.player.serverLevel().getChunkSource().move(this.player); this.player.checkMovementStatistics(this.player.getX() - d0, this.player.getY() - d1, this.player.getZ() - d2); this.clientVehicleIsFloating = d11 >= -0.03125D && !flag1 && !this.server.isFlightAllowed() && !entity.isNoGravity() && this.noBlocksAround(entity); -@@ -473,6 +653,7 @@ +@@ -493,6 +679,7 @@ } this.awaitingPositionFromClient = null; @@ -271,7 +277,7 @@ } } -@@ -480,7 +661,7 @@ +@@ -500,7 +687,7 @@ @Override public void handleRecipeBookSeenRecipePacket(PacketPlayInRecipeDisplayed packetplayinrecipedisplayed) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipedisplayed, this, this.player.serverLevel()); @@ -280,7 +286,7 @@ RecipeBookServer recipebookserver = this.player.getRecipeBook(); Objects.requireNonNull(recipebookserver); -@@ -490,6 +671,7 @@ +@@ -510,6 +697,7 @@ @Override public void handleRecipeBookChangeSettingsPacket(PacketPlayInRecipeSettings packetplayinrecipesettings) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinrecipesettings, this, this.player.serverLevel()); @@ -288,7 +294,7 @@ this.player.getRecipeBook().setBookSetting(packetplayinrecipesettings.getBookType(), packetplayinrecipesettings.isOpen(), packetplayinrecipesettings.isFiltering()); } -@@ -510,6 +692,12 @@ +@@ -530,6 +718,12 @@ @Override public void handleCustomCommandSuggestions(PacketPlayInTabComplete packetplayintabcomplete) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayintabcomplete, this, this.player.serverLevel()); @@ -301,18 +307,18 @@ StringReader stringreader = new StringReader(packetplayintabcomplete.getCommand()); if (stringreader.canRead() && stringreader.peek() == '/') { -@@ -519,6 +707,7 @@ +@@ -539,6 +733,7 @@ ParseResults parseresults = this.server.getCommands().getDispatcher().parse(stringreader, this.player.createCommandSourceStack()); this.server.getCommands().getDispatcher().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> { + if (suggestions.isEmpty()) return; // CraftBukkit - don't send through empty suggestions - prevents [] from showing for plugins with nothing more to offer - this.send(new PacketPlayOutTabComplete(packetplayintabcomplete.getId(), suggestions)); - }); - } -@@ -766,6 +955,13 @@ + Suggestions suggestions1 = suggestions.getList().size() <= 1000 ? suggestions : new Suggestions(suggestions.getRange(), suggestions.getList().subList(0, 1000)); - if (container instanceof ContainerMerchant) { - ContainerMerchant containermerchant = (ContainerMerchant) container; + this.send(new PacketPlayOutTabComplete(packetplayintabcomplete.getId(), suggestions1)); +@@ -783,6 +978,13 @@ + Container container = this.player.containerMenu; + + if (container instanceof ContainerMerchant containermerchant) { + // CraftBukkit start + final org.bukkit.event.inventory.TradeSelectEvent tradeSelectEvent = CraftEventFactory.callTradeSelectEvent(this.player, i, containermerchant); + if (tradeSelectEvent.isCancelled()) { @@ -320,10 +326,10 @@ + return; + } + // CraftBukkit end - if (!containermerchant.stillValid(this.player)) { PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, containermerchant); -@@ -780,6 +976,13 @@ + return; +@@ -796,6 +998,13 @@ @Override public void handleEditBook(PacketPlayInBEdit packetplayinbedit) { @@ -334,57 +340,53 @@ + } + this.lastBookTick = MinecraftServer.currentTick; + // CraftBukkit end - int i = packetplayinbedit.getSlot(); + int i = packetplayinbedit.slot(); if (PlayerInventory.isHotbarSlot(i) || i == 40) { -@@ -788,7 +991,7 @@ +@@ -804,7 +1013,7 @@ Objects.requireNonNull(list); optional.ifPresent(list::add); -- Stream stream = packetplayinbedit.getPages().stream().limit(100L); -+ Stream stream = packetplayinbedit.getPages().stream().limit(100L); // CraftBukkit - decompile error +- Stream stream = packetplayinbedit.pages().stream().limit(100L); ++ Stream stream = packetplayinbedit.pages().stream().limit(100L); // CraftBukkit - decompile error Objects.requireNonNull(list); stream.forEach(list::add); -@@ -806,7 +1009,7 @@ - ItemStack itemstack = this.player.getInventory().getItem(i); +@@ -819,12 +1028,16 @@ + } + + private void updateBookContents(List list, int i) { +- ItemStack itemstack = this.player.getInventory().getItem(i); ++ // CraftBukkit start ++ ItemStack handItem = this.player.getInventory().getItem(i); ++ ItemStack itemstack = handItem.copy(); ++ // CraftBukkit end if (itemstack.is(Items.WRITABLE_BOOK)) { -- this.updateBookPages(list, UnaryOperator.identity(), itemstack); -+ this.updateBookPages(list, UnaryOperator.identity(), itemstack.copy(), i, itemstack); // CraftBukkit + List> list1 = list.stream().map(this::filterableFromOutgoing).toList(); + + itemstack.set(DataComponents.WRITABLE_BOOK_CONTENT, new WritableBookContent(list1)); ++ CraftEventFactory.handleEditBookEvent(player, i, handItem, itemstack); // CraftBukkit } } -@@ -831,16 +1034,16 @@ +@@ -835,12 +1048,13 @@ + ItemStack itemstack1 = itemstack.transmuteCopy(Items.WRITTEN_BOOK, 1); - this.updateBookPages(list, (s) -> { - return IChatBaseComponent.ChatSerializer.toJson(IChatBaseComponent.literal(s)); -- }, itemstack1); + itemstack1.remove(DataComponents.WRITABLE_BOOK_CONTENT); +- List> list1 = list.stream().map((filteredtext1) -> { ++ List> list1 = (List>) (List) list.stream().map((filteredtext1) -> { // CraftBukkit - decompile error + return this.filterableFromOutgoing(filteredtext1).map(IChatBaseComponent::literal); + }).toList(); + + itemstack1.set(DataComponents.WRITTEN_BOOK_CONTENT, new WrittenBookContent(this.filterableFromOutgoing(filteredtext), this.player.getName().getString(), 0, list1, true)); - this.player.getInventory().setItem(i, itemstack1); -+ }, itemstack1, i, itemstack); // CraftBukkit ++ CraftEventFactory.handleEditBookEvent(player, i, itemstack, itemstack1); // CraftBukkit + this.player.getInventory().setItem(i, itemstack); // CraftBukkit - event factory updates the hand book } } -- private void updateBookPages(List list, UnaryOperator unaryoperator, ItemStack itemstack) { -+ private void updateBookPages(List list, UnaryOperator unaryoperator, ItemStack itemstack, int slot, ItemStack handItem) { // CraftBukkit - NBTTagList nbttaglist = new NBTTagList(); - - if (this.player.isTextFilteringEnabled()) { -- Stream stream = list.stream().map((filteredtext) -> { -+ Stream stream = list.stream().map((filteredtext) -> { // CraftBukkit - decompile error - return NBTTagString.valueOf((String) unaryoperator.apply(filteredtext.filteredOrEmpty())); - }); - -@@ -866,6 +1069,7 @@ - } - - itemstack.addTagElement("pages", nbttaglist); -+ CraftEventFactory.handleEditBookEvent(player, slot, handItem, itemstack); // CraftBukkit - } - - @Override -@@ -922,7 +1126,7 @@ +@@ -902,7 +1116,7 @@ } else { WorldServer worldserver = this.player.serverLevel(); @@ -393,7 +395,7 @@ if (this.tickCount == 0) { this.resetPosition(); } -@@ -932,6 +1136,7 @@ +@@ -912,6 +1126,7 @@ this.awaitingTeleportTime = this.tickCount; this.teleport(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot()); } @@ -401,7 +403,7 @@ } else { this.awaitingTeleportTime = this.tickCount; -@@ -944,7 +1149,15 @@ +@@ -924,7 +1139,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); @@ -417,7 +419,7 @@ double d3 = this.player.getX(); double d4 = this.player.getY(); double d5 = this.player.getZ(); -@@ -964,15 +1177,33 @@ +@@ -946,15 +1169,33 @@ ++this.receivedMovePacketCount; int i = this.receivedMovePacketCount - this.knownMovePacketCount; @@ -444,8 +446,8 @@ + speed = player.getAbilities().walkingSpeed * 10f; + } + - if (!this.player.isChangingDimension() && (!this.player.level().getGameRules().getBoolean(GameRules.RULE_DISABLE_ELYTRA_MOVEMENT_CHECK) || !this.player.isFallFlying())) { - float f2 = this.player.isFallFlying() ? 300.0F : 100.0F; + if (!this.player.isChangingDimension() && (!this.player.level().getGameRules().getBoolean(GameRules.RULE_DISABLE_ELYTRA_MOVEMENT_CHECK) || !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()) { @@ -453,18 +455,18 @@ 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; -@@ -994,6 +1225,7 @@ - boolean flag1 = this.player.verticalCollisionBelow; +@@ -976,6 +1217,7 @@ + boolean flag2 = this.player.verticalCollisionBelow; this.player.move(EnumMoveType.PLAYER, new Vec3D(d6, d7, d8)); + this.player.onGround = packetplayinflying.isOnGround(); // CraftBukkit - SPIGOT-5810, SPIGOT-5835, SPIGOT-6828: reset by this.player.move double d11 = d7; d6 = d0 - this.player.getX(); -@@ -1012,9 +1244,75 @@ +@@ -994,9 +1236,75 @@ } - if (!this.player.noPhysics && !this.player.isSleeping() && (flag2 && worldserver.noCollision(this.player, axisalignedbb) || this.isPlayerCollidingWithAnythingNew(worldserver, axisalignedbb, d0, d1, d2))) { + 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.player.doCheckFallDamage(this.player.getX() - d3, this.player.getY() - d4, this.player.getZ() - d5, packetplayinflying.isOnGround()); @@ -536,9 +538,9 @@ + } + // CraftBukkit end this.player.absMoveTo(d0, d1, d2, f, f1); - this.clientIsFloating = d11 >= -0.03125D && !flag1 && this.player.gameMode.getGameModeForPlayer() != EnumGamemode.SPECTATOR && !this.server.isFlightAllowed() && !this.player.getAbilities().mayfly && !this.player.hasEffect(MobEffects.LEVITATION) && !this.player.isFallFlying() && !this.player.isAutoSpinAttack() && this.noBlocksAround(this.player); - this.player.serverLevel().getChunkSource().move(this.player); -@@ -1055,11 +1353,68 @@ + boolean flag4 = this.player.isAutoSpinAttack(); + +@@ -1043,11 +1351,68 @@ return true; } @@ -608,7 +610,7 @@ 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; -@@ -1071,6 +1426,14 @@ +@@ -1059,6 +1424,14 @@ this.awaitingTeleport = 0; } @@ -621,9 +623,9 @@ + // CraftBukkit end + this.awaitingTeleportTime = this.tickCount; + this.player.resetCurrentImpulseContext(); 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)); -@@ -1079,6 +1442,7 @@ +@@ -1068,6 +1441,7 @@ @Override public void handlePlayerAction(PacketPlayInBlockDig packetplayinblockdig) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockdig, this, this.player.serverLevel()); @@ -631,7 +633,7 @@ BlockPosition blockposition = packetplayinblockdig.getPos(); this.player.resetLastActionTime(); -@@ -1089,14 +1453,46 @@ +@@ -1078,14 +1452,46 @@ if (!this.player.isSpectator()) { ItemStack itemstack = this.player.getItemInHand(EnumHand.OFF_HAND); @@ -680,7 +682,7 @@ this.player.drop(false); } -@@ -1134,6 +1530,7 @@ +@@ -1123,6 +1529,7 @@ @Override public void handleUseItemOn(PacketPlayInUseItem packetplayinuseitem) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseitem, this, this.player.serverLevel()); @@ -688,15 +690,15 @@ this.player.connection.ackBlockChangesUpTo(packetplayinuseitem.getSequence()); WorldServer worldserver = this.player.serverLevel(); EnumHand enumhand = packetplayinuseitem.getHand(); -@@ -1157,6 +1554,7 @@ +@@ -1145,6 +1552,7 @@ if (blockposition.getY() < i) { - if (this.awaitingPositionFromClient == null && this.player.distanceToSqr((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && worldserver.mayInteract(this.player, blockposition)) { + 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 (enumdirection == EnumDirection.UP && !enuminteractionresult.consumesAction() && blockposition.getY() >= i - 1 && wasBlockPlacementAttempt(this.player, itemstack)) { -@@ -1185,6 +1583,7 @@ + if (enuminteractionresult.consumesAction()) { +@@ -1177,6 +1585,7 @@ @Override public void handleUseItem(PacketPlayInBlockPlace packetplayinblockplace) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinblockplace, this, this.player.serverLevel()); @@ -704,7 +706,7 @@ this.ackBlockChangesUpTo(packetplayinblockplace.getSequence()); WorldServer worldserver = this.player.serverLevel(); EnumHand enumhand = packetplayinblockplace.getHand(); -@@ -1192,6 +1591,49 @@ +@@ -1184,6 +1593,49 @@ this.player.resetLastActionTime(); if (!itemstack.isEmpty() && itemstack.isItemEnabled(worldserver.enabledFeatures())) { @@ -733,7 +735,7 @@ + cancelled = event.useItemInHand() == Event.Result.DENY; + } else { + MovingObjectPositionBlock movingobjectpositionblock = (MovingObjectPositionBlock) movingobjectposition; -+ if (player.gameMode.firedInteract && player.gameMode.interactPosition.equals(movingobjectpositionblock.getBlockPos()) && player.gameMode.interactHand == enumhand && ItemStack.isSameItemSameTags(player.gameMode.interactItemStack, itemstack)) { ++ if (player.gameMode.firedInteract && player.gameMode.interactPosition.equals(movingobjectpositionblock.getBlockPos()) && player.gameMode.interactHand == enumhand && ItemStack.isSameItemSameComponents(player.gameMode.interactItemStack, itemstack)) { + cancelled = player.gameMode.interactResult; + } else { + org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, movingobjectpositionblock.getBlockPos(), movingobjectpositionblock.getDirection(), itemstack, true, enumhand, movingobjectpositionblock.getLocation()); @@ -754,7 +756,7 @@ EnumInteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand); if (enuminteractionresult.shouldSwing()) { -@@ -1212,7 +1654,7 @@ +@@ -1204,7 +1656,7 @@ Entity entity = packetplayinspectate.getEntity(worldserver); if (entity != null) { @@ -763,7 +765,7 @@ return; } } -@@ -1235,6 +1677,13 @@ +@@ -1225,6 +1677,13 @@ @Override public void onDisconnect(IChatBaseComponent ichatbasecomponent) { @@ -777,7 +779,7 @@ PlayerConnection.LOGGER.info("{} lost connection: {}", this.player.getName().getString(), ichatbasecomponent.getString()); this.removePlayerFromWorld(); super.onDisconnect(ichatbasecomponent); -@@ -1242,10 +1691,18 @@ +@@ -1232,10 +1691,18 @@ private void removePlayerFromWorld() { this.chatMessageChain.close(); @@ -797,7 +799,7 @@ this.player.getTextFilter().leave(); } -@@ -1260,7 +1717,16 @@ +@@ -1250,7 +1717,16 @@ @Override public void handleSetCarriedItem(PacketPlayInHeldItemSlot packetplayinhelditemslot) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinhelditemslot, this, this.player.serverLevel()); @@ -814,7 +816,7 @@ if (this.player.getInventory().selected != packetplayinhelditemslot.getSlot() && this.player.getUsedItemHand() == EnumHand.MAIN_HAND) { this.player.stopUsingItem(); } -@@ -1269,18 +1735,25 @@ +@@ -1259,11 +1735,18 @@ this.player.resetLastActionTime(); } else { PlayerConnection.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString()); @@ -830,55 +832,77 @@ + return; + } + // CraftBukkit end - if (isChatMessageIllegal(packetplayinchat.message())) { - this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.illegal_characters")); - } else { - Optional optional = this.tryHandleChat(packetplayinchat.lastSeenMessages()); + Optional optional = this.unpackAndApplyLastSeen(packetplayinchat.lastSeenMessages()); - if (optional.isPresent()) { -- this.server.submit(() -> { -+ // this.server.submit(() -> { // CraftBukkit - async chat - PlayerChatMessage playerchatmessage; + if (!optional.isEmpty()) { +@@ -1277,7 +1760,7 @@ + return; + } - try { -@@ -1290,7 +1763,7 @@ - return; - } +- CompletableFuture completablefuture = this.filterTextPacket(playerchatmessage.signedContent()); ++ CompletableFuture completablefuture = this.filterTextPacket(playerchatmessage.signedContent()).thenApplyAsync(Function.identity(), this.server.chatExecutor); // CraftBukkit - async chat + IChatBaseComponent ichatbasecomponent = this.server.getChatDecorator().decorate(this.player, playerchatmessage.decoratedContent()); -- CompletableFuture completablefuture = this.filterTextPacket(playerchatmessage.signedContent()); -+ CompletableFuture completablefuture = this.filterTextPacket(playerchatmessage.signedContent()).thenApplyAsync(Function.identity(), this.server.chatExecutor); // CraftBukkit - async chat - IChatBaseComponent ichatbasecomponent = this.server.getChatDecorator().decorate(this.player, playerchatmessage.decoratedContent()); + this.chatMessageChain.append(completablefuture, (filteredtext) -> { +@@ -1285,19 +1768,36 @@ - this.chatMessageChain.append(completablefuture, (filteredtext) -> { -@@ -1298,7 +1771,7 @@ - - this.broadcastChatMessage(playerchatmessage1); - }); -- }); -+ // }); // CraftBukkit - async chat - } - - } -@@ -1313,6 +1786,12 @@ - - if (optional.isPresent()) { - this.server.submit(() -> { -+ // CraftBukkit start - SPIGOT-7346: Prevent disconnected players from executing commands -+ if (player.hasDisconnected()) { -+ return; -+ } -+ // CraftBukkit end -+ - this.performChatCommand(serverboundchatcommandpacket, (LastSeenMessages) optional.get()); - this.detectRateSpam(); + this.broadcastChatMessage(playerchatmessage1); }); -@@ -1322,12 +1801,25 @@ +- }); ++ }, false); // CraftBukkit - async chat + } } - private void performChatCommand(ServerboundChatCommandPacket serverboundchatcommandpacket, LastSeenMessages lastseenmessages) { -- ParseResults parseresults = this.parseCommand(serverboundchatcommandpacket.command()); + @Override + public void handleChatCommand(ServerboundChatCommandPacket serverboundchatcommandpacket) { + this.tryHandleChat(serverboundchatcommandpacket.command(), () -> { ++ // CraftBukkit start - SPIGOT-7346: Prevent disconnected players from executing commands ++ if (player.hasDisconnected()) { ++ return; ++ } ++ // CraftBukkit end + this.performUnsignedChatCommand(serverboundchatcommandpacket.command()); + this.detectRateSpam(); +- }); ++ }, true); // CraftBukkit - sync commands + } + + private void performUnsignedChatCommand(String s) { + // CraftBukkit start -+ String command = "/" + serverboundchatcommandpacket.command(); ++ String command = "/" + s; ++ PlayerConnection.LOGGER.info(this.player.getScoreboardName() + " issued server command: " + command); ++ ++ PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(getCraftPlayer(), command, new LazyPlayerSet(server)); ++ this.cserver.getPluginManager().callEvent(event); ++ ++ if (event.isCancelled()) { ++ return; ++ } ++ s = event.getMessage().substring(1); ++ // CraftBukkit end + ParseResults parseresults = this.parseCommand(s); + + if (this.server.enforceSecureProfile() && SignableCommand.hasSignableArguments(parseresults)) { +@@ -1314,19 +1814,37 @@ + + if (!optional.isEmpty()) { + this.tryHandleChat(serverboundchatcommandsignedpacket.command(), () -> { ++ // CraftBukkit start - SPIGOT-7346: Prevent disconnected players from executing commands ++ if (player.hasDisconnected()) { ++ return; ++ } ++ // CraftBukkit end + this.performSignedChatCommand(serverboundchatcommandsignedpacket, (LastSeenMessages) optional.get()); + this.detectRateSpam(); +- }); ++ }, true); // CraftBukkit - sync commands + } + } + + private void performSignedChatCommand(ServerboundChatCommandSignedPacket serverboundchatcommandsignedpacket, LastSeenMessages lastseenmessages) { +- ParseResults parseresults = this.parseCommand(serverboundchatcommandsignedpacket.command()); ++ // CraftBukkit start ++ String command = "/" + serverboundchatcommandsignedpacket.command(); + PlayerConnection.LOGGER.info(this.player.getScoreboardName() + " issued server command: " + command); + + PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(getCraftPlayer(), command, new LazyPlayerSet(server)); @@ -889,18 +913,18 @@ + } + command = event.getMessage().substring(1); + -+ ParseResults parseresults = this.parseCommand(command); ++ ParseResults parseresults = this.parseCommand(command); + // CraftBukkit end Map map; try { -- map = this.collectSignedArguments(serverboundchatcommandpacket, SignableCommand.of(parseresults), lastseenmessages); -+ map = (serverboundchatcommandpacket.command().equals(command)) ? this.collectSignedArguments(serverboundchatcommandpacket, SignableCommand.of(parseresults), lastseenmessages) : Collections.emptyMap(); // CraftBukkit +- map = this.collectSignedArguments(serverboundchatcommandsignedpacket, SignableCommand.of(parseresults), lastseenmessages); ++ map = (serverboundchatcommandsignedpacket.command().equals(command)) ? this.collectSignedArguments(serverboundchatcommandsignedpacket, SignableCommand.of(parseresults), lastseenmessages) : Collections.emptyMap(); // CraftBukkit } catch (SignedMessageChain.a signedmessagechain_a) { this.handleMessageDecodeFailure(signedmessagechain_a); return; -@@ -1335,10 +1827,10 @@ +@@ -1334,10 +1852,10 @@ CommandSigningContext.a commandsigningcontext_a = new CommandSigningContext.a(map); @@ -908,21 +932,36 @@ + parseresults = CommandDispatcher.mapSource(parseresults, (commandlistenerwrapper) -> { // CraftBukkit - decompile error return commandlistenerwrapper.withSigningContext(commandsigningcontext_a, this.chatMessageChain); }); -- this.server.getCommands().performCommand(parseresults, serverboundchatcommandpacket.command()); +- this.server.getCommands().performCommand(parseresults, serverboundchatcommandsignedpacket.command()); + this.server.getCommands().performCommand(parseresults, command); // CraftBukkit } private void handleMessageDecodeFailure(SignedMessageChain.a signedmessagechain_a) { -@@ -1375,7 +1867,7 @@ - private Optional tryHandleChat(LastSeenMessages.b lastseenmessages_b) { - Optional optional = this.unpackAndApplyLastSeen(lastseenmessages_b); +@@ -1413,14 +1931,20 @@ + return com_mojang_brigadier_commanddispatcher.parse(s, this.player.createCommandSourceStack()); + } -- if (this.player.getChatVisibility() == EnumChatVisibility.HIDDEN) { -+ if (this.player.isRemoved() || this.player.getChatVisibility() == EnumChatVisibility.HIDDEN) { // CraftBukkit - dead men tell no tales +- private void tryHandleChat(String s, Runnable runnable) { ++ private void tryHandleChat(String s, Runnable runnable, boolean sync) { // CraftBukkit + if (isChatMessageIllegal(s)) { + this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.illegal_characters")); +- } else if (this.player.getChatVisibility() == EnumChatVisibility.HIDDEN) { ++ } else if (this.player.isRemoved() || this.player.getChatVisibility() == EnumChatVisibility.HIDDEN) { // CraftBukkit - dead men tell no tales this.send(new ClientboundSystemChatPacket(IChatBaseComponent.translatable("chat.disabled.options").withStyle(EnumChatFormat.RED), false)); - return Optional.empty(); } else { -@@ -1409,6 +1901,116 @@ + this.player.resetLastActionTime(); +- this.server.execute(runnable); ++ // CraftBukkit start ++ if (sync) { ++ this.server.execute(runnable); ++ } else { ++ runnable.run(); ++ } ++ // CraftBukkit end + } + } + +@@ -1449,6 +1973,116 @@ return false; } @@ -1039,7 +1078,7 @@ private PlayerChatMessage getSignedMessage(PacketPlayInChat packetplayinchat, LastSeenMessages lastseenmessages) throws SignedMessageChain.a { SignedMessageBody signedmessagebody = new SignedMessageBody(packetplayinchat.message(), packetplayinchat.timeStamp(), packetplayinchat.salt(), lastseenmessages); -@@ -1416,13 +2018,33 @@ +@@ -1456,13 +2090,33 @@ } private void broadcastChatMessage(PlayerChatMessage playerchatmessage) { @@ -1076,7 +1115,7 @@ this.disconnect(IChatBaseComponent.translatable("disconnect.spam")); } -@@ -1444,13 +2066,62 @@ +@@ -1484,13 +2138,62 @@ @Override public void handleAnimate(PacketPlayInArmAnimation packetplayinarmanimation) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinarmanimation, this, this.player.serverLevel()); @@ -1138,8 +1177,8 @@ + // CraftBukkit end this.player.resetLastActionTime(); Entity entity; - IJumpable ijumpable; -@@ -1532,6 +2203,12 @@ + +@@ -1567,6 +2270,12 @@ } public void sendPlayerChatMessage(PlayerChatMessage playerchatmessage, ChatMessageType.a chatmessagetype_a) { @@ -1149,10 +1188,10 @@ + return; + } + // CraftBukkit end - this.send(new ClientboundPlayerChatPacket(playerchatmessage.link().sender(), playerchatmessage.link().index(), playerchatmessage.signature(), playerchatmessage.signedBody().pack(this.messageSignatureCache), playerchatmessage.unsignedContent(), playerchatmessage.filterMask(), chatmessagetype_a.toNetwork(this.player.level().registryAccess()))); + 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); } -@@ -1558,6 +2235,7 @@ +@@ -1594,6 +2303,7 @@ @Override public void handleInteract(PacketPlayInUseEntity packetplayinuseentity) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinuseentity, this, this.player.serverLevel()); @@ -1160,9 +1199,9 @@ final WorldServer worldserver = this.player.serverLevel(); final Entity entity = packetplayinuseentity.getTarget(worldserver); -@@ -1572,13 +2250,51 @@ +@@ -1608,13 +2318,51 @@ - if (axisalignedbb.distanceToSqr(this.player.getEyePosition()) < PlayerConnection.MAX_INTERACTION_DISTANCE) { + if (this.player.canInteractWithEntity(axisalignedbb, 1.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 @@ -1190,7 +1229,7 @@ + + if (event.isCancelled() || player.getInventory().getSelected() == null || player.getInventory().getSelected().getItem() != origItem) { + // Refresh the current entity metadata -+ entity.getEntityData().refresh(player); ++ entity.refreshEntityData(player); + // SPIGOT-7136 - Allays + if (entity instanceof Allay) { + send(new PacketPlayOutEntityEquipment(entity.getId(), Arrays.stream(EnumItemSlot.values()).map((slot) -> Pair.of(slot, ((EntityLiving) entity).getItemBySlot(slot).copy())).collect(Collectors.toList()))); @@ -1211,9 +1250,9 @@ + // CraftBukkit end + if (enuminteractionresult.consumesAction()) { - CriterionTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(PlayerConnection.this.player, itemstack1, entity); + CriterionTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(PlayerConnection.this.player, enuminteractionresult.indicateItemUse() ? itemstack1 : ItemStack.EMPTY, entity); if (enuminteractionresult.shouldSwing()) { -@@ -1591,23 +2307,29 @@ +@@ -1627,19 +2375,20 @@ @Override public void onInteraction(EnumHand enumhand) { @@ -1231,22 +1270,25 @@ @Override public void onAttack() { -- if (!(entity instanceof EntityItem) && !(entity instanceof EntityExperienceOrb) && !(entity instanceof EntityArrow) && entity != PlayerConnection.this.player) { +- if (!(entity instanceof EntityItem) && !(entity instanceof EntityExperienceOrb) && entity != PlayerConnection.this.player) { + // CraftBukkit -+ if (!(entity instanceof EntityItem) && !(entity instanceof EntityExperienceOrb) && !(entity instanceof EntityArrow) && (entity != PlayerConnection.this.player || player.isSpectator())) { - ItemStack itemstack = PlayerConnection.this.player.getItemInHand(EnumHand.MAIN_HAND); ++ if (!(entity instanceof EntityItem) && !(entity instanceof EntityExperienceOrb) && (entity != PlayerConnection.this.player || player.isSpectator())) { + label23: + { + if (entity instanceof EntityArrow) { +@@ -1657,6 +2406,11 @@ + } - if (itemstack.isItemEnabled(worldserver.enabledFeatures())) { PlayerConnection.this.player.attack(entity); + // CraftBukkit start + if (!itemstack.isEmpty() && itemstack.getCount() <= -1) { + player.containerMenu.sendAllDataToRemote(); + } + // CraftBukkit end + return; } - } else { - PlayerConnection.this.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.invalid_entity_attacked")); -@@ -1630,17 +2352,17 @@ + } +@@ -1680,17 +2434,17 @@ case PERFORM_RESPAWN: if (this.player.wonGame) { this.player.wonGame = false; @@ -1267,7 +1309,7 @@ } } break; -@@ -1653,15 +2375,21 @@ +@@ -1703,15 +2457,21 @@ @Override public void handleContainerClose(PacketPlayInCloseWindow packetplayinclosewindow) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinclosewindow, this, this.player.serverLevel()); @@ -1291,7 +1333,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); -@@ -1674,7 +2402,284 @@ +@@ -1724,7 +2484,284 @@ boolean flag = packetplayinwindowclick.getStateId() != this.player.containerMenu.getStateId(); this.player.containerMenu.suppressRemoteUpdates(); @@ -1338,7 +1380,7 @@ + if (cursor.isEmpty()) { + action = packetplayinwindowclick.getButtonNum() == 0 ? InventoryAction.PICKUP_ALL : InventoryAction.PICKUP_HALF; + } else if (slot.mayPlace(cursor)) { -+ if (ItemStack.isSameItemSameTags(clickedItem, cursor)) { ++ if (ItemStack.isSameItemSameComponents(clickedItem, cursor)) { + int toPlace = packetplayinwindowclick.getButtonNum() == 0 ? cursor.getCount() : 1; + toPlace = Math.min(toPlace, clickedItem.getMaxStackSize() - clickedItem.getCount()); + toPlace = Math.min(toPlace, slot.container.getMaxStackSize() - clickedItem.getCount()); @@ -1354,7 +1396,7 @@ + } else if (cursor.getCount() <= slot.getMaxStackSize()) { + action = InventoryAction.SWAP_WITH_CURSOR; + } -+ } else if (ItemStack.isSameItemSameTags(cursor, clickedItem)) { ++ } else if (ItemStack.isSameItemSameComponents(cursor, clickedItem)) { + if (clickedItem.getCount() >= 0) { + if (clickedItem.getCount() + cursor.getCount() <= cursor.getMaxStackSize()) { + // As of 1.5, this is result slots only @@ -1577,7 +1619,7 @@ ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packetplayinwindowclick.getChangedSlots()).iterator(); while (objectiterator.hasNext()) { -@@ -1704,9 +2709,18 @@ +@@ -1754,9 +2791,18 @@ if (!this.player.containerMenu.stillValid(this.player)) { PlayerConnection.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu); } else { @@ -1598,34 +1640,34 @@ } } } -@@ -1714,6 +2728,7 @@ +@@ -1764,6 +2810,7 @@ @Override public void handleContainerButtonClick(PacketPlayInEnchantItem packetplayinenchantitem) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinenchantitem, this, this.player.serverLevel()); + if (this.player.isImmobile()) return; // CraftBukkit this.player.resetLastActionTime(); - if (this.player.containerMenu.containerId == packetplayinenchantitem.getContainerId() && !this.player.isSpectator()) { + if (this.player.containerMenu.containerId == packetplayinenchantitem.containerId() && !this.player.isSpectator()) { if (!this.player.containerMenu.stillValid(this.player)) { -@@ -1756,6 +2771,43 @@ +@@ -1806,6 +2853,43 @@ - boolean flag1 = packetplayinsetcreativeslot.getSlotNum() >= 1 && packetplayinsetcreativeslot.getSlotNum() <= 45; - boolean flag2 = itemstack.isEmpty() || itemstack.getDamageValue() >= 0 && itemstack.getCount() <= 64 && !itemstack.isEmpty(); -+ if (flag || (flag1 && !ItemStack.matches(this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.getSlotNum()).getItem(), packetplayinsetcreativeslot.getItem()))) { // Insist on valid slot + boolean flag1 = packetplayinsetcreativeslot.slotNum() >= 1 && packetplayinsetcreativeslot.slotNum() <= 45; + boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize(); ++ if (flag || (flag1 && !ItemStack.matches(this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.slotNum()).getItem(), packetplayinsetcreativeslot.itemStack()))) { // Insist on valid slot + // CraftBukkit start - Call click event + InventoryView inventory = this.player.inventoryMenu.getBukkitView(); -+ org.bukkit.inventory.ItemStack item = CraftItemStack.asBukkitCopy(packetplayinsetcreativeslot.getItem()); ++ org.bukkit.inventory.ItemStack item = CraftItemStack.asBukkitCopy(packetplayinsetcreativeslot.itemStack()); + + SlotType type = SlotType.QUICKBAR; + if (flag) { + type = SlotType.OUTSIDE; -+ } else if (packetplayinsetcreativeslot.getSlotNum() < 36) { -+ if (packetplayinsetcreativeslot.getSlotNum() >= 5 && packetplayinsetcreativeslot.getSlotNum() < 9) { ++ } else if (packetplayinsetcreativeslot.slotNum() < 36) { ++ if (packetplayinsetcreativeslot.slotNum() >= 5 && packetplayinsetcreativeslot.slotNum() < 9) { + type = SlotType.ARMOR; + } else { + type = SlotType.CONTAINER; + } + } -+ InventoryCreativeEvent event = new InventoryCreativeEvent(inventory, type, flag ? -999 : packetplayinsetcreativeslot.getSlotNum(), item); ++ InventoryCreativeEvent event = new InventoryCreativeEvent(inventory, type, flag ? -999 : packetplayinsetcreativeslot.slotNum(), item); + cserver.getPluginManager().callEvent(event); + + itemstack = CraftItemStack.asNMSCopy(event.getCursor()); @@ -1639,8 +1681,8 @@ + break; + case DENY: + // Reset the slot -+ if (packetplayinsetcreativeslot.getSlotNum() >= 0) { -+ this.player.connection.send(new PacketPlayOutSetSlot(this.player.inventoryMenu.containerId, this.player.inventoryMenu.incrementStateId(), packetplayinsetcreativeslot.getSlotNum(), this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.getSlotNum()).getItem())); ++ if (packetplayinsetcreativeslot.slotNum() >= 0) { ++ this.player.connection.send(new PacketPlayOutSetSlot(this.player.inventoryMenu.containerId, this.player.inventoryMenu.incrementStateId(), packetplayinsetcreativeslot.slotNum(), this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.slotNum()).getItem())); + this.player.connection.send(new PacketPlayOutSetSlot(-1, this.player.inventoryMenu.incrementStateId(), -1, ItemStack.EMPTY)); + } + return; @@ -1649,8 +1691,8 @@ + // CraftBukkit end if (flag1 && flag2) { - this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.getSlotNum()).setByPlayer(itemstack); -@@ -1778,6 +2830,7 @@ + this.player.inventoryMenu.getSlot(packetplayinsetcreativeslot.slotNum()).setByPlayer(itemstack); +@@ -1828,6 +2912,7 @@ } private void updateSignText(PacketPlayInUpdateSign packetplayinupdatesign, List list) { @@ -1658,7 +1700,7 @@ this.player.resetLastActionTime(); WorldServer worldserver = this.player.serverLevel(); BlockPosition blockposition = packetplayinupdatesign.getPos(); -@@ -1799,7 +2852,17 @@ +@@ -1849,7 +2934,17 @@ @Override public void handlePlayerAbilities(PacketPlayInAbilities packetplayinabilities) { PlayerConnectionUtils.ensureRunningOnSameThread(packetplayinabilities, this, this.player.serverLevel()); @@ -1677,12 +1719,12 @@ } @Override -@@ -1858,7 +2921,7 @@ +@@ -1908,7 +3003,7 @@ if (!this.waitingForSwitchToConfig) { throw new IllegalStateException("Client acknowledged config, but none was requested"); } else { -- this.connection.setListener(new ServerConfigurationPacketListenerImpl(this.server, this.connection, this.createCookie(this.player.clientInformation()))); -+ this.connection.setListener(new ServerConfigurationPacketListenerImpl(this.server, this.connection, this.createCookie(this.player.clientInformation()), this.player)); // CraftBukkit +- this.connection.setupInboundProtocol(ConfigurationProtocols.SERVERBOUND, new ServerConfigurationPacketListenerImpl(this.server, this.connection, this.createCookie(this.player.clientInformation()))); ++ this.connection.setupInboundProtocol(ConfigurationProtocols.SERVERBOUND, new ServerConfigurationPacketListenerImpl(this.server, this.connection, this.createCookie(this.player.clientInformation()), this.player)); // CraftBukkit } } 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 bf4ec91fe2..a1f0385a8b 100644 --- a/paper-server/nms-patches/net/minecraft/server/network/ServerCommonPacketListenerImpl.patch +++ b/paper-server/nms-patches/net/minecraft/server/network/ServerCommonPacketListenerImpl.patch @@ -1,13 +1,15 @@ --- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java +++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java -@@ -26,6 +26,21 @@ +@@ -27,8 +27,28 @@ import net.minecraft.util.thread.IAsyncTaskHandler; import org.slf4j.Logger; +-public abstract class ServerCommonPacketListenerImpl implements ServerCommonPacketListener { +// CraftBukkit start +import io.netty.buffer.ByteBuf; +import java.util.concurrent.ExecutionException; +import net.minecraft.EnumChatFormat; ++import net.minecraft.network.protocol.common.custom.DiscardedPayload; +import net.minecraft.network.protocol.game.PacketPlayOutSpawnPosition; +import net.minecraft.resources.MinecraftKey; +import net.minecraft.server.level.EntityPlayer; @@ -17,12 +19,18 @@ +import org.bukkit.craftbukkit.util.Waitable; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerResourcePackStatusEvent; -+// CraftBukkit end -+ - public abstract class ServerCommonPacketListenerImpl implements ServerCommonPacketListener { ++public abstract class ServerCommonPacketListenerImpl implements ServerCommonPacketListener, CraftPlayer.TransferCookieConnection { ++ ++ @Override ++ public boolean isTransferred() { ++ return this.transferred; ++ } ++ // CraftBukkit end private static final Logger LOGGER = LogUtils.getLogger(); -@@ -39,11 +54,22 @@ + public static final int LATENCY_CHECK_INTERVAL = 15000; + private static final int CLOSED_LISTENER_TIMEOUT = 15000; +@@ -45,12 +65,24 @@ private int latency; private volatile boolean suspendFlushingOnServerThread = false; @@ -32,8 +40,10 @@ this.connection = networkmanager; this.keepAliveTime = SystemUtils.getMillis(); this.latency = commonlistenercookie.latency(); + this.transferred = commonlistenercookie.transferred(); + // CraftBukkit start - add fields and methods + this.player = player; ++ this.player.transferCookieConnection = this; + this.cserver = minecraftserver.server; + } + protected final EntityPlayer player; @@ -45,8 +55,8 @@ + // CraftBukkit end } - @Override -@@ -57,6 +83,7 @@ + private void close() { +@@ -72,6 +104,7 @@ @Override public void handleKeepAlive(ServerboundKeepAlivePacket serverboundkeepalivepacket) { @@ -54,7 +64,7 @@ if (this.keepAlivePending && serverboundkeepalivepacket.getId() == this.keepAliveChallenge) { int i = (int) (SystemUtils.getMillis() - this.keepAliveTime); -@@ -71,8 +98,56 @@ +@@ -86,8 +119,56 @@ @Override public void handlePong(ServerboundPongPacket serverboundpongpacket) {} @@ -65,12 +75,12 @@ @Override - public void handleCustomPayload(ServerboundCustomPayloadPacket serverboundcustompayloadpacket) {} + public void handleCustomPayload(ServerboundCustomPayloadPacket serverboundcustompayloadpacket) { -+ if (!(serverboundcustompayloadpacket.payload() instanceof ServerboundCustomPayloadPacket.UnknownPayload)) { ++ if (!(serverboundcustompayloadpacket.payload() instanceof DiscardedPayload)) { + return; + } + PlayerConnectionUtils.ensureRunningOnSameThread(serverboundcustompayloadpacket, this, this.player.serverLevel()); -+ MinecraftKey identifier = serverboundcustompayloadpacket.payload().id(); -+ ByteBuf payload = ((ServerboundCustomPayloadPacket.UnknownPayload)serverboundcustompayloadpacket.payload()).data(); ++ MinecraftKey identifier = serverboundcustompayloadpacket.payload().type().id(); ++ ByteBuf payload = ((DiscardedPayload)serverboundcustompayloadpacket.payload()).data(); + + if (identifier.equals(CUSTOM_REGISTER)) { + try { @@ -112,7 +122,7 @@ @Override public void handleResourcePackResponse(ServerboundResourcePackPacket serverboundresourcepackpacket) { -@@ -81,6 +156,7 @@ +@@ -96,11 +177,18 @@ ServerCommonPacketListenerImpl.LOGGER.info("Disconnecting {} due to resource pack {} rejection", this.playerProfile().getName(), serverboundresourcepackpacket.id()); this.disconnect(IChatBaseComponent.translatable("multiplayer.requiredTexturePrompt.disconnect")); } @@ -120,16 +130,27 @@ } -@@ -88,7 +164,7 @@ + @Override + public void handleCookieResponse(ServerboundCookieResponsePacket serverboundcookieresponsepacket) { ++ // CraftBukkit start ++ PlayerConnectionUtils.ensureRunningOnSameThread(serverboundcookieresponsepacket, this, (IAsyncTaskHandler) this.server); ++ if (this.player.getBukkitEntity().handleCookieResponse(serverboundcookieresponsepacket)) { ++ return; ++ } ++ // CraftBukkit end + this.disconnect(ServerCommonPacketListenerImpl.DISCONNECT_UNEXPECTED_QUERY); + } + +@@ -108,7 +196,7 @@ this.server.getProfiler().push("keepAlive"); long i = SystemUtils.getMillis(); -- if (i - this.keepAliveTime >= 15000L) { -+ if (i - this.keepAliveTime >= 25000L) { // CraftBukkit +- if (!this.isSingleplayerOwner() && i - this.keepAliveTime >= 15000L) { ++ if (!this.isSingleplayerOwner() && i - this.keepAliveTime >= 25000L) { // CraftBukkit if (this.keepAlivePending) { this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE); - } else { -@@ -116,6 +192,14 @@ + } else if (this.checkIfClosed(i)) { +@@ -148,6 +236,14 @@ } public void send(Packet packet, @Nullable PacketSendListener packetsendlistener) { @@ -141,10 +162,10 @@ + this.player.compassTarget = CraftLocation.toBukkit(packet6.pos, this.getCraftPlayer().getWorld()); + } + // CraftBukkit end - boolean flag = !this.suspendFlushingOnServerThread || !this.server.isSameThread(); - - try { -@@ -131,16 +215,67 @@ + if (packet.isTerminal()) { + this.close(); + } +@@ -167,16 +263,67 @@ } } diff --git a/paper-server/nms-patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.patch b/paper-server/nms-patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.patch index f35ab94328..034b43a097 100644 --- a/paper-server/nms-patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.patch +++ b/paper-server/nms-patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.patch @@ -1,17 +1,35 @@ --- a/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java +++ b/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java -@@ -44,8 +44,8 @@ - private ConfigurationTask currentTask; - private ClientInformation clientInformation; +@@ -35,6 +35,10 @@ + import net.minecraft.world.flag.FeatureFlags; + import org.slf4j.Logger; + ++// CraftBukkit start ++import net.minecraft.network.EnumProtocol; ++// CraftBukkit end ++ + public class ServerConfigurationPacketListenerImpl extends ServerCommonPacketListenerImpl implements ServerConfigurationPacketListener, TickablePacketListener { + + private static final Logger LOGGER = LogUtils.getLogger(); +@@ -47,8 +51,15 @@ + @Nullable + private SynchronizeRegistriesTask synchronizeRegistriesTask; - public ServerConfigurationPacketListenerImpl(MinecraftServer minecraftserver, NetworkManager networkmanager, CommonListenerCookie commonlistenercookie) { - super(minecraftserver, networkmanager, commonlistenercookie); -+ public ServerConfigurationPacketListenerImpl(MinecraftServer minecraftserver, NetworkManager networkmanager, CommonListenerCookie commonlistenercookie, EntityPlayer player) { // CraftBukkit -+ super(minecraftserver, networkmanager, commonlistenercookie, player); // CraftBukkit ++ // CraftBukkit start ++ @Override ++ public EnumProtocol protocol() { ++ return ServerConfigurationPacketListener.super.protocol(); ++ } ++ ++ public ServerConfigurationPacketListenerImpl(MinecraftServer minecraftserver, NetworkManager networkmanager, CommonListenerCookie commonlistenercookie, EntityPlayer player) { ++ super(minecraftserver, networkmanager, commonlistenercookie, player); ++ // CraftBukkit end this.gameProfile = commonlistenercookie.gameProfile(); this.clientInformation = commonlistenercookie.clientInformation(); } -@@ -117,14 +117,14 @@ +@@ -134,14 +145,14 @@ return; } @@ -27,4 +45,4 @@ + EntityPlayer entityplayer = playerlist.getPlayerForLogin(this.gameProfile, this.clientInformation, this.player); // CraftBukkit playerlist.placeNewPlayer(this.connection, entityplayer, this.createCookie(this.clientInformation)); - this.connection.resumeInboundAfterProtocolChange(); + } catch (Exception exception) { diff --git a/paper-server/nms-patches/net/minecraft/server/network/ServerConnection.patch b/paper-server/nms-patches/net/minecraft/server/network/ServerConnection.patch index 1108bf2026..3c67718d6b 100644 --- a/paper-server/nms-patches/net/minecraft/server/network/ServerConnection.patch +++ b/paper-server/nms-patches/net/minecraft/server/network/ServerConnection.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/server/network/ServerConnection.java +++ b/net/minecraft/server/network/ServerConnection.java -@@ -98,15 +98,25 @@ +@@ -100,15 +100,25 @@ - NetworkManager.configureSerialization(channelpipeline, EnumProtocolDirection.SERVERBOUND, (BandwidthDebugMonitor) null); + NetworkManager.configureSerialization(channelpipeline, EnumProtocolDirection.SERVERBOUND, false, (BandwidthDebugMonitor) null); int j = ServerConnection.this.server.getRateLimitPacketsPerSecond(); - Object object = j > 0 ? new NetworkManagerServer(j) : new NetworkManager(EnumProtocolDirection.SERVERBOUND); + NetworkManager object = j > 0 ? new NetworkManagerServer(j) : new NetworkManager(EnumProtocolDirection.SERVERBOUND); // CraftBukkit - decompile error 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 d9facec37d..fa5b7652ed 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 -@@ -101,6 +101,27 @@ +@@ -103,6 +103,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"); -@@ -113,14 +134,16 @@ +@@ -115,14 +136,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; -@@ -131,13 +154,23 @@ +@@ -133,13 +156,23 @@ private static final boolean ALLOW_LOGOUTIVATOR = false; private int sendAllPlayerInfoIn; @@ -74,32 +74,47 @@ this.server = minecraftserver; this.registries = layeredregistryaccess; this.maxPlayers = i; -@@ -160,15 +193,21 @@ +@@ -149,25 +182,34 @@ + public void placeNewPlayer(NetworkManager networkmanager, EntityPlayer entityplayer, CommonListenerCookie commonlistenercookie) { + GameProfile gameprofile = entityplayer.getGameProfile(); + UserCache usercache = this.server.getProfileCache(); +- Optional optional; ++ // Optional optional; // CraftBukkit - decompile error + String s; - NBTTagCompound nbttagcompound = this.load(entityplayer); - ResourceKey resourcekey; + if (usercache != null) { +- optional = usercache.get(gameprofile.getId()); ++ Optional optional = usercache.get(gameprofile.getId()); // CraftBukkit - decompile error + s = (String) optional.map(GameProfile::getName).orElse(gameprofile.getName()); + usercache.add(gameprofile); + } else { + s = gameprofile.getName(); + } + +- optional = this.load(entityplayer); ++ Optional optional = this.load(entityplayer); // CraftBukkit - decompile error + // CraftBukkit start - Better rename detection -+ if (nbttagcompound != null && nbttagcompound.contains("bukkit")) { -+ NBTTagCompound bukkit = nbttagcompound.getCompound("bukkit"); -+ s = bukkit.contains("lastKnownName", 8) ? bukkit.getString("lastKnownName") : s; ++ if (optional.isPresent()) { ++ NBTTagCompound nbttagcompound = optional.get(); ++ if (nbttagcompound.contains("bukkit")) { ++ NBTTagCompound bukkit = nbttagcompound.getCompound("bukkit"); ++ s = bukkit.contains("lastKnownName", 8) ? bukkit.getString("lastKnownName") : s; ++ } + } + // CraftBukkit end - - if (nbttagcompound != null) { + ResourceKey resourcekey = (ResourceKey) optional.flatMap((nbttagcompound) -> { - DataResult dataresult = DimensionManager.parseLegacy(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("Dimension"))); + DataResult> dataresult = DimensionManager.parseLegacy(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("Dimension"))); // CraftBukkit - decompile error Logger logger = PlayerList.LOGGER; Objects.requireNonNull(logger); -- resourcekey = (ResourceKey) dataresult.resultOrPartial(logger::error).orElse(World.OVERWORLD); -+ resourcekey = (ResourceKey) dataresult.resultOrPartial(logger::error).orElse(entityplayer.serverLevel().dimension()); // CraftBukkit - SPIGOT-7507: If no dimension, fall back to existing dimension loaded from "WorldUUID", which in turn defaults to World.OVERWORLD - } else { -- resourcekey = World.OVERWORLD; -+ resourcekey = entityplayer.serverLevel().dimension(); // CraftBukkit - SPIGOT-7507: If no dimension, fall back to existing dimension loaded from "WorldUUID", which in turn defaults to World.OVERWORLD - } + return dataresult.resultOrPartial(logger::error); +- }).orElse(World.OVERWORLD); ++ }).orElse(entityplayer.serverLevel().dimension()); // CraftBukkit - SPIGOT-7507: If no dimension, fall back to existing dimension loaded from "WorldUUID", which in turn defaults to World.OVERWORLD + WorldServer worldserver = this.server.getLevel(resourcekey); + WorldServer worldserver1; - ResourceKey resourcekey1 = resourcekey; -@@ -185,7 +224,8 @@ +@@ -181,10 +223,11 @@ entityplayer.setServerLevel(worldserver1); String s1 = networkmanager.getLoggableAddress(this.server.logIPs()); @@ -108,16 +123,20 @@ + // PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ({}, {}, {})", new Object[]{entityplayer.getName().getString(), s1, entityplayer.getId(), entityplayer.getX(), entityplayer.getY(), entityplayer.getZ()}); WorldData worlddata = worldserver1.getLevelData(); - entityplayer.loadGameTypes(nbttagcompound); -@@ -196,6 +236,7 @@ +- entityplayer.loadGameTypes((NBTTagCompound) optional.orElse((Object) null)); ++ entityplayer.loadGameTypes((NBTTagCompound) optional.orElse(null)); // CraftBukkit - decompile error + PlayerConnection playerconnection = new PlayerConnection(this.server, networkmanager, entityplayer, commonlistenercookie); + + networkmanager.setupInboundProtocol(GameProtocols.SERVERBOUND.bind(RegistryFriendlyByteBuf.decorator(this.server.registryAccess())), playerconnection); +@@ -194,6 +237,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))); + 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())); + entityplayer.getBukkitEntity().sendSupportedChannels(); // CraftBukkit playerconnection.send(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked())); playerconnection.send(new PacketPlayOutAbilities(entityplayer.getAbilities())); playerconnection.send(new PacketPlayOutHeldItemSlot(entityplayer.getInventory().selected)); -@@ -212,8 +253,10 @@ +@@ -210,8 +254,10 @@ } else { ichatmutablecomponent = IChatBaseComponent.translatable("multiplayer.player.joined.renamed", entityplayer.getDisplayName(), s); } @@ -129,7 +148,7 @@ playerconnection.teleport(entityplayer.getX(), entityplayer.getY(), entityplayer.getZ(), entityplayer.getYRot(), entityplayer.getXRot()); ServerPing serverping = this.server.getStatus(); -@@ -221,13 +264,64 @@ +@@ -219,13 +265,64 @@ entityplayer.sendServerStatus(serverping); } @@ -181,7 +200,7 @@ + entityplayer.sentListPacket = true; + // CraftBukkit end + -+ entityplayer.getEntityData().refresh(entityplayer); // CraftBukkit - BungeeCord#2321, send complete data to self on spawn ++ entityplayer.refreshEntityData(entityplayer); // CraftBukkit - BungeeCord#2321, send complete data to self on spawn + this.sendLevelInfo(entityplayer, worldserver1); - worldserver1.addNewPlayer(entityplayer); @@ -198,21 +217,18 @@ Iterator iterator = entityplayer.getActiveEffects().iterator(); while (iterator.hasNext()) { -@@ -238,8 +332,11 @@ +@@ -236,8 +333,9 @@ - if (nbttagcompound != null && nbttagcompound.contains("RootVehicle", 10)) { - NBTTagCompound nbttagcompound1 = nbttagcompound.getCompound("RootVehicle"); -- Entity entity = EntityTypes.loadEntityRecursive(nbttagcompound1.getCompound("Entity"), worldserver1, (entity1) -> { + 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; -+ // CraftBukkit start -+ WorldServer finalWorldServer = worldserver1; -+ Entity entity = EntityTypes.loadEntityRecursive(nbttagcompound1.getCompound("Entity"), finalWorldServer, (entity1) -> { -+ return !finalWorldServer.addWithUUID(entity1) ? null : entity1; -+ // CraftBukkit end ++ return !finalWorldServer.addWithUUID(entity1) ? null : entity1; // CraftBukkit - decompile error }); if (entity != null) { -@@ -270,18 +367,20 @@ +@@ -268,18 +366,20 @@ if (!entityplayer.isPassenger()) { PlayerList.LOGGER.warn("Couldn't reattach entity to player"); @@ -235,7 +251,7 @@ } public void updateEntireScoreboard(ScoreboardServer scoreboardserver, EntityPlayer entityplayer) { -@@ -318,30 +417,31 @@ +@@ -316,30 +416,31 @@ } public void addWorldborderListener(WorldServer worldserver) { @@ -272,7 +288,7 @@ } @Override -@@ -369,14 +469,15 @@ +@@ -366,14 +467,15 @@ } protected void save(EntityPlayer entityplayer) { @@ -290,7 +306,7 @@ if (advancementdataplayer != null) { advancementdataplayer.save(); -@@ -384,10 +485,24 @@ +@@ -381,10 +483,24 @@ } @@ -316,7 +332,7 @@ this.save(entityplayer); if (entityplayer.isPassenger()) { Entity entity = entityplayer.getRootVehicle(); -@@ -396,7 +511,7 @@ +@@ -393,7 +509,7 @@ PlayerList.LOGGER.debug("Removing player mount"); entityplayer.stopRiding(); entity.getPassengersAndSelf().forEach((entity1) -> { @@ -325,7 +341,7 @@ }); } } -@@ -411,17 +526,65 @@ +@@ -408,17 +524,66 @@ if (entityplayer1 == entityplayer) { this.playersByUUID.remove(uuid); @@ -390,13 +406,14 @@ + SocketAddress socketaddress = loginlistener.connection.getRemoteAddress(); + + EntityPlayer entity = new EntityPlayer(this.server, this.server.getLevel(World.OVERWORLD), gameprofile, ClientInformation.createDefault()); ++ entity.transferCookieConnection = loginlistener; + Player player = entity.getBukkitEntity(); + PlayerLoginEvent event = new PlayerLoginEvent(player, loginlistener.connection.hostname, ((java.net.InetSocketAddress) socketaddress).getAddress()); + if (this.bans.isBanned(gameprofile)) { GameProfileBanEntry gameprofilebanentry = (GameProfileBanEntry) this.bans.get(gameprofile); -@@ -430,9 +593,11 @@ +@@ -427,9 +592,11 @@ ichatmutablecomponent.append((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.banned.expiration", PlayerList.BAN_DATE_FORMAT.format(gameprofilebanentry.getExpires()))); } @@ -410,7 +427,7 @@ } else if (this.ipBans.isBanned(socketaddress)) { IpBanEntry ipbanentry = this.ipBans.get(socketaddress); -@@ -441,17 +606,32 @@ +@@ -438,17 +605,32 @@ ichatmutablecomponent.append((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.banned_ip.expiration", PlayerList.BAN_DATE_FORMAT.format(ipbanentry.getExpires()))); } @@ -448,7 +465,7 @@ UUID uuid = gameprofile.getId(); Set set = Sets.newIdentityHashSet(); Iterator iterator = this.players.iterator(); -@@ -479,14 +659,24 @@ +@@ -476,14 +658,24 @@ } return !set.isEmpty(); @@ -474,7 +491,7 @@ WorldServer worldserver = this.server.getLevel(entityplayer.getRespawnDimension()); Optional optional; -@@ -498,6 +688,11 @@ +@@ -495,6 +687,11 @@ WorldServer worldserver1 = worldserver != null && optional.isPresent() ? worldserver : this.server.overworld(); EntityPlayer entityplayer1 = new EntityPlayer(this.server, worldserver1, entityplayer.getGameProfile(), entityplayer.clientInformation()); @@ -486,7 +503,7 @@ entityplayer1.connection = entityplayer.connection; entityplayer1.restoreFrom(entityplayer, flag); -@@ -513,28 +708,66 @@ +@@ -510,28 +707,66 @@ boolean flag2 = false; @@ -569,7 +586,7 @@ entityplayer1.setPos(entityplayer1.getX(), entityplayer1.getY() + 1.0D, entityplayer1.getZ()); } -@@ -543,21 +776,43 @@ +@@ -540,21 +775,43 @@ WorldData worlddata = worldserver2.getLevelData(); entityplayer1.connection.send(new PacketPlayOutRespawn(entityplayer1.createCommonSpawnInfo(worldserver2), (byte) i)); @@ -598,9 +615,9 @@ + sendAllPlayerInfo(entityplayer); // Update health, etc... + entityplayer.onUpdateAbilities(); + for (MobEffect mobEffect : entityplayer.getActiveEffects()) { -+ entityplayer.connection.send(new PacketPlayOutEntityEffect(entityplayer.getId(), mobEffect)); ++ entityplayer.connection.send(new PacketPlayOutEntityEffect(entityplayer.getId(), mobEffect, false)); // blend = false + } - ++ + // Fire advancement trigger + entityplayer.triggerDimensionChangeTriggers(((CraftWorld) fromWorld).getHandle()); + @@ -609,7 +626,7 @@ + PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(entityplayer.getBukkitEntity(), fromWorld); + server.server.getPluginManager().callEvent(event); + } -+ + + // Save player file again if they were disconnected + if (entityplayer.connection.isDisconnected()) { + this.save(entityplayer); @@ -618,7 +635,7 @@ return entityplayer1; } -@@ -570,7 +825,18 @@ +@@ -567,7 +824,18 @@ public void tick() { if (++this.sendAllPlayerInfoIn > 600) { @@ -638,7 +655,7 @@ this.sendAllPlayerInfoIn = 0; } -@@ -587,6 +853,25 @@ +@@ -584,6 +852,25 @@ } @@ -664,7 +681,7 @@ public void broadcastAll(Packet packet, ResourceKey resourcekey) { Iterator iterator = this.players.iterator(); -@@ -665,7 +950,7 @@ +@@ -662,7 +949,7 @@ } public void deop(GameProfile gameprofile) { @@ -673,7 +690,7 @@ EntityPlayer entityplayer = this.getPlayer(gameprofile.getId()); if (entityplayer != null) { -@@ -689,6 +974,7 @@ +@@ -686,6 +973,7 @@ entityplayer.connection.send(new PacketPlayOutEntityStatus(entityplayer, b0)); } @@ -681,7 +698,7 @@ this.server.getCommands().sendCommands(entityplayer); } -@@ -719,6 +1005,12 @@ +@@ -716,6 +1004,12 @@ for (int i = 0; i < this.players.size(); ++i) { EntityPlayer entityplayer = (EntityPlayer) this.players.get(i); @@ -694,7 +711,7 @@ if (entityplayer != entityhuman && entityplayer.level().dimension() == resourcekey) { double d4 = d0 - entityplayer.getX(); double d5 = d1 - entityplayer.getY(); -@@ -758,15 +1050,19 @@ +@@ -755,15 +1049,19 @@ public void reloadWhiteList() {} public void sendLevelInfo(EntityPlayer entityplayer, WorldServer worldserver) { @@ -718,14 +735,14 @@ } entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.LEVEL_CHUNKS_LOAD_START, 0.0F)); -@@ -775,8 +1071,16 @@ +@@ -772,8 +1070,16 @@ public void sendAllPlayerInfo(EntityPlayer entityplayer) { entityplayer.inventoryMenu.sendAllDataToRemote(); - entityplayer.resetSentInfo(); + // entityplayer.resetSentInfo(); + entityplayer.getBukkitEntity().updateScaledHealth(); // CraftBukkit - Update scaled health on respawn and worldchange -+ entityplayer.getEntityData().refresh(entityplayer); // CraftBukkkit - SPIGOT-7218: sync metadata ++ 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; @@ -736,7 +753,7 @@ } public int getPlayerCount() { -@@ -832,12 +1136,22 @@ +@@ -829,12 +1135,22 @@ } public void removeAll() { @@ -761,7 +778,7 @@ public void broadcastSystemMessage(IChatBaseComponent ichatbasecomponent, boolean flag) { this.broadcastSystemMessage(ichatbasecomponent, (entityplayer) -> { return ichatbasecomponent; -@@ -895,16 +1209,23 @@ +@@ -892,16 +1208,23 @@ return playerchatmessage.hasSignature() && !playerchatmessage.hasExpiredServer(Instant.now()); } @@ -781,7 +798,7 @@ if (serverstatisticmanager == null) { File file = this.server.getWorldPath(SavedFile.PLAYER_STATS_DIR).toFile(); - File file1 = new File(file, uuid + ".json"); + File file1 = new File(file, String.valueOf(uuid) + ".json"); if (!file1.exists()) { - File file2 = new File(file, entityhuman.getName().getString() + ".json"); @@ -789,7 +806,7 @@ Path path = file2.toPath(); if (FileUtils.isPathNormalized(path) && FileUtils.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) { -@@ -913,7 +1234,7 @@ +@@ -910,7 +1233,7 @@ } serverstatisticmanager = new ServerStatisticManager(this.server, file1); @@ -798,7 +815,7 @@ } return serverstatisticmanager; -@@ -921,13 +1242,13 @@ +@@ -918,13 +1241,13 @@ public AdvancementDataPlayer getPlayerAdvancements(EntityPlayer entityplayer) { UUID uuid = entityplayer.getUUID(); @@ -806,7 +823,7 @@ + AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) entityplayer.getAdvancements(); // CraftBukkit if (advancementdataplayer == null) { - Path path = this.server.getWorldPath(SavedFile.PLAYER_ADVANCEMENTS_DIR).resolve(uuid + ".json"); + Path path = this.server.getWorldPath(SavedFile.PLAYER_ADVANCEMENTS_DIR).resolve(String.valueOf(uuid) + ".json"); advancementdataplayer = new AdvancementDataPlayer(this.server.getFixerUpper(), this, this.server.getAdvancements(), path, entityplayer); - this.advancements.put(uuid, advancementdataplayer); @@ -814,7 +831,7 @@ } advancementdataplayer.setPlayer(entityplayer); -@@ -978,13 +1299,20 @@ +@@ -975,13 +1298,20 @@ } public void reloadResources() { @@ -835,4 +852,4 @@ + // CraftBukkit end this.broadcastAll(new ClientboundUpdateTagsPacket(TagNetworkSerialization.serializeTagsToNetwork(this.registries))); - PacketPlayOutRecipeUpdate packetplayoutrecipeupdate = new PacketPlayOutRecipeUpdate(this.server.getRecipeManager().getRecipes()); + PacketPlayOutRecipeUpdate packetplayoutrecipeupdate = new PacketPlayOutRecipeUpdate(this.server.getRecipeManager().getOrderedRecipes()); diff --git a/paper-server/nms-patches/net/minecraft/server/players/UserCache.patch b/paper-server/nms-patches/net/minecraft/server/players/UserCache.patch index 58913080d3..3199cd6eab 100644 --- a/paper-server/nms-patches/net/minecraft/server/players/UserCache.patch +++ b/paper-server/nms-patches/net/minecraft/server/players/UserCache.patch @@ -18,3 +18,21 @@ if (optional.isPresent()) { this.add((GameProfile) optional.get()); flag = false; +@@ -208,7 +208,7 @@ + + label54: + { +- ArrayList arraylist; ++ List arraylist; // CraftBukkit - decompile error + + try { + JsonArray jsonarray = (JsonArray) this.gson.fromJson(bufferedreader, JsonArray.class); +@@ -217,7 +217,7 @@ + DateFormat dateformat = createDateFormat(); + + jsonarray.forEach((jsonelement) -> { +- Optional optional = readGameProfile(jsonelement, dateformat); ++ Optional optional = readGameProfile(jsonelement, dateformat); // CraftBukkit - decompile error + + Objects.requireNonNull(list); + optional.ifPresent(list::add); diff --git a/paper-server/nms-patches/net/minecraft/server/rcon/thread/RemoteControlSession.patch b/paper-server/nms-patches/net/minecraft/server/rcon/thread/RemoteControlSession.patch index f3e0a80992..3feb32243d 100644 --- a/paper-server/nms-patches/net/minecraft/server/rcon/thread/RemoteControlSession.patch +++ b/paper-server/nms-patches/net/minecraft/server/rcon/thread/RemoteControlSession.patch @@ -22,7 +22,7 @@ + // CraftBukkit end RemoteControlSession(IMinecraftServer iminecraftserver, String s, Socket socket) { - super("RCON Client " + socket.getInetAddress()); + super("RCON Client " + String.valueOf(socket.getInetAddress())); - this.serverInterface = iminecraftserver; + this.serverInterface = (DedicatedServer) iminecraftserver; // CraftBukkit this.client = socket; @@ -46,7 +46,7 @@ return; } @@ -71,7 +81,7 @@ - String s = StatusChallengeUtils.stringFromByteArray(this.buf, k, i); + String s = StatusChallengeUtils.stringFromByteArray(this.buf, j, i); try { - this.sendCmdResponse(l, this.serverInterface.runCommand(s)); diff --git a/paper-server/nms-patches/net/minecraft/util/SpawnUtil.patch b/paper-server/nms-patches/net/minecraft/util/SpawnUtil.patch index e76f3ef697..7ac5d4fa30 100644 --- a/paper-server/nms-patches/net/minecraft/util/SpawnUtil.patch +++ b/paper-server/nms-patches/net/minecraft/util/SpawnUtil.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/util/SpawnUtil.java +++ b/net/minecraft/util/SpawnUtil.java -@@ -21,6 +21,12 @@ +@@ -20,6 +20,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) { @@ -13,12 +13,12 @@ BlockPosition.MutableBlockPosition blockposition_mutableblockposition = blockposition.mutable(); for (int l = 0; l < i; ++l) { -@@ -29,15 +35,15 @@ +@@ -28,15 +34,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, (NBTTagCompound) null, (Consumer) null, blockposition_mutableblockposition, enummobspawn, false, false); -+ T t0 = entitytypes.create(worldserver, (NBTTagCompound) null, null, blockposition_mutableblockposition, enummobspawn, false, false); // CraftBukkit - decompile error +- 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 if (t0 != null) { if (t0.checkSpawnRules(worldserver, enummobspawn) && t0.checkSpawnObstruction(worldserver)) { 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 3990ce056e..320eecc616 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 -@@ -455,6 +455,18 @@ +@@ -483,6 +483,18 @@ datafixerbuilder.addFixer(new DataConverterItemFrame(schema44, false)); Schema schema45 = datafixerbuilder.addSchema(1458, DataConverterRegistry.SAME_NAMESPACED); @@ -19,7 +19,17 @@ datafixerbuilder.addFixer(new DataConverterCustomNameEntity(schema45, false)); datafixerbuilder.addFixer(new DataConverterCustomNameItem(schema45, false)); datafixerbuilder.addFixer(new DataConverterCustomNameTile(schema45, false)); -@@ -776,12 +788,14 @@ +@@ -741,7 +753,8 @@ + datafixerbuilder.addFixer(new DataConverterAddChoices(schema110, "Added Zoglin", DataConverterTypes.ENTITY)); + Schema schema111 = datafixerbuilder.addSchema(2523, DataConverterRegistry.SAME_NAMESPACED); + +- datafixerbuilder.addFixer(new DataConverterAttributes(schema111, "Attribute renames", createRenamerNoNamespace(ImmutableMap.builder().put("generic.maxHealth", "minecraft:generic.max_health").put("Max Health", "minecraft:generic.max_health").put("zombie.spawnReinforcements", "minecraft:zombie.spawn_reinforcements").put("Spawn Reinforcements Chance", "minecraft:zombie.spawn_reinforcements").put("horse.jumpStrength", "minecraft:horse.jump_strength").put("Jump Strength", "minecraft:horse.jump_strength").put("generic.followRange", "minecraft:generic.follow_range").put("Follow Range", "minecraft:generic.follow_range").put("generic.knockbackResistance", "minecraft:generic.knockback_resistance").put("Knockback Resistance", "minecraft:generic.knockback_resistance").put("generic.movementSpeed", "minecraft:generic.movement_speed").put("Movement Speed", "minecraft:generic.movement_speed").put("generic.flyingSpeed", "minecraft:generic.flying_speed").put("Flying Speed", "minecraft:generic.flying_speed").put("generic.attackDamage", "minecraft:generic.attack_damage").put("generic.attackKnockback", "minecraft:generic.attack_knockback").put("generic.attackSpeed", "minecraft:generic.attack_speed").put("generic.armorToughness", "minecraft:generic.armor_toughness").build()))); ++ // CraftBukkit - decompile error ++ datafixerbuilder.addFixer(new DataConverterAttributes(schema111, "Attribute renames", createRenamerNoNamespace(ImmutableMap.builder().put("generic.maxHealth", "minecraft:generic.max_health").put("Max Health", "minecraft:generic.max_health").put("zombie.spawnReinforcements", "minecraft:zombie.spawn_reinforcements").put("Spawn Reinforcements Chance", "minecraft:zombie.spawn_reinforcements").put("horse.jumpStrength", "minecraft:horse.jump_strength").put("Jump Strength", "minecraft:horse.jump_strength").put("generic.followRange", "minecraft:generic.follow_range").put("Follow Range", "minecraft:generic.follow_range").put("generic.knockbackResistance", "minecraft:generic.knockback_resistance").put("Knockback Resistance", "minecraft:generic.knockback_resistance").put("generic.movementSpeed", "minecraft:generic.movement_speed").put("Movement Speed", "minecraft:generic.movement_speed").put("generic.flyingSpeed", "minecraft:generic.flying_speed").put("Flying Speed", "minecraft:generic.flying_speed").put("generic.attackDamage", "minecraft:generic.attack_damage").put("generic.attackKnockback", "minecraft:generic.attack_knockback").put("generic.attackSpeed", "minecraft:generic.attack_speed").put("generic.armorToughness", "minecraft:generic.armor_toughness").build()))); + Schema schema112 = datafixerbuilder.addSchema(2527, DataConverterRegistry.SAME_NAMESPACED); + + datafixerbuilder.addFixer(new DataConverterBitStorageAlign(schema112)); +@@ -804,12 +817,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); @@ -28,15 +38,15 @@ + ImmutableMap immutablemap = ImmutableMap.builder().put("minecraft:weathered_copper_block", "minecraft:oxidized_copper_block").put("minecraft:semi_weathered_copper_block", "minecraft:weathered_copper_block").put("minecraft:lightly_weathered_copper_block", "minecraft:exposed_copper_block").put("minecraft:weathered_cut_copper", "minecraft:oxidized_cut_copper").put("minecraft:semi_weathered_cut_copper", "minecraft:weathered_cut_copper").put("minecraft:lightly_weathered_cut_copper", "minecraft:exposed_cut_copper").put("minecraft:weathered_cut_copper_stairs", "minecraft:oxidized_cut_copper_stairs").put("minecraft:semi_weathered_cut_copper_stairs", "minecraft:weathered_cut_copper_stairs").put("minecraft:lightly_weathered_cut_copper_stairs", "minecraft:exposed_cut_copper_stairs").put("minecraft:weathered_cut_copper_slab", "minecraft:oxidized_cut_copper_slab").put("minecraft:semi_weathered_cut_copper_slab", "minecraft:weathered_cut_copper_slab").put("minecraft:lightly_weathered_cut_copper_slab", "minecraft:exposed_cut_copper_slab").put("minecraft:waxed_semi_weathered_copper", "minecraft:waxed_weathered_copper").put("minecraft:waxed_lightly_weathered_copper", "minecraft:waxed_exposed_copper").put("minecraft:waxed_semi_weathered_cut_copper", "minecraft:waxed_weathered_cut_copper").put("minecraft:waxed_lightly_weathered_cut_copper", "minecraft:waxed_exposed_cut_copper").put("minecraft:waxed_semi_weathered_cut_copper_stairs", "minecraft:waxed_weathered_cut_copper_stairs").put("minecraft:waxed_lightly_weathered_cut_copper_stairs", "minecraft:waxed_exposed_cut_copper_stairs").put("minecraft:waxed_semi_weathered_cut_copper_slab", "minecraft:waxed_weathered_cut_copper_slab").put("minecraft:waxed_lightly_weathered_cut_copper_slab", "minecraft:waxed_exposed_cut_copper_slab").build(); datafixerbuilder.addFixer(DataConverterItemName.create(schema131, "Renamed copper block items to new oxidized terms", createRenamer(immutablemap))); - datafixerbuilder.addFixer(BlockRenameFixWithJigsaw.create(schema131, "Renamed copper blocks to new oxidized terms", createRenamer(immutablemap))); + datafixerbuilder.addFixer(DataConverterBlockRename.create(schema131, "Renamed copper blocks to new oxidized terms", createRenamer(immutablemap))); Schema schema132 = datafixerbuilder.addSchema(2691, DataConverterRegistry.SAME_NAMESPACED); - ImmutableMap immutablemap1 = ImmutableMap.builder().put("minecraft:waxed_copper", "minecraft:waxed_copper_block").put("minecraft:oxidized_copper_block", "minecraft:oxidized_copper").put("minecraft:weathered_copper_block", "minecraft:weathered_copper").put("minecraft:exposed_copper_block", "minecraft:exposed_copper").build(); + // CraftBukkit - decompile error + ImmutableMap immutablemap1 = ImmutableMap.builder().put("minecraft:waxed_copper", "minecraft:waxed_copper_block").put("minecraft:oxidized_copper_block", "minecraft:oxidized_copper").put("minecraft:weathered_copper_block", "minecraft:weathered_copper").put("minecraft:exposed_copper_block", "minecraft:exposed_copper").build(); datafixerbuilder.addFixer(DataConverterItemName.create(schema132, "Rename copper item suffixes", createRenamer(immutablemap1))); - datafixerbuilder.addFixer(BlockRenameFixWithJigsaw.create(schema132, "Rename copper blocks suffixes", createRenamer(immutablemap1))); -@@ -789,7 +803,8 @@ + datafixerbuilder.addFixer(DataConverterBlockRename.create(schema132, "Rename copper blocks suffixes", createRenamer(immutablemap1))); +@@ -817,7 +832,8 @@ datafixerbuilder.addFixer(new AddFlagIfNotPresentFix(schema133, DataConverterTypes.WORLD_GEN_SETTINGS, "has_increased_height_already", false)); Schema schema134 = datafixerbuilder.addSchema(2696, DataConverterRegistry.SAME_NAMESPACED); @@ -45,8 +55,8 @@ + ImmutableMap immutablemap2 = ImmutableMap.builder().put("minecraft:grimstone", "minecraft:deepslate").put("minecraft:grimstone_slab", "minecraft:cobbled_deepslate_slab").put("minecraft:grimstone_stairs", "minecraft:cobbled_deepslate_stairs").put("minecraft:grimstone_wall", "minecraft:cobbled_deepslate_wall").put("minecraft:polished_grimstone", "minecraft:polished_deepslate").put("minecraft:polished_grimstone_slab", "minecraft:polished_deepslate_slab").put("minecraft:polished_grimstone_stairs", "minecraft:polished_deepslate_stairs").put("minecraft:polished_grimstone_wall", "minecraft:polished_deepslate_wall").put("minecraft:grimstone_tiles", "minecraft:deepslate_tiles").put("minecraft:grimstone_tile_slab", "minecraft:deepslate_tile_slab").put("minecraft:grimstone_tile_stairs", "minecraft:deepslate_tile_stairs").put("minecraft:grimstone_tile_wall", "minecraft:deepslate_tile_wall").put("minecraft:grimstone_bricks", "minecraft:deepslate_bricks").put("minecraft:grimstone_brick_slab", "minecraft:deepslate_brick_slab").put("minecraft:grimstone_brick_stairs", "minecraft:deepslate_brick_stairs").put("minecraft:grimstone_brick_wall", "minecraft:deepslate_brick_wall").put("minecraft:chiseled_grimstone", "minecraft:chiseled_deepslate").build(); datafixerbuilder.addFixer(DataConverterItemName.create(schema134, "Renamed grimstone block items to deepslate", createRenamer(immutablemap2))); - datafixerbuilder.addFixer(BlockRenameFixWithJigsaw.create(schema134, "Renamed grimstone blocks to deepslate", createRenamer(immutablemap2))); -@@ -876,10 +891,11 @@ + datafixerbuilder.addFixer(DataConverterBlockRename.create(schema134, "Renamed grimstone blocks to deepslate", createRenamer(immutablemap2))); +@@ -904,10 +920,11 @@ datafixerbuilder.addFixer(new DataConverterAddChoices(schema159, "Added Allay", DataConverterTypes.ENTITY)); Schema schema160 = datafixerbuilder.addSchema(3084, DataConverterRegistry.SAME_NAMESPACED); @@ -60,7 +70,7 @@ int2objectopenhashmap1.defaultReturnValue("minecraft:tabby"); int2objectopenhashmap1.put(0, "minecraft:tabby"); int2objectopenhashmap1.put(1, "minecraft:black"); -@@ -896,7 +912,8 @@ +@@ -924,7 +941,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 3a08d57bb0..05b7105fd5 100644 --- a/paper-server/nms-patches/net/minecraft/util/worldupdate/WorldUpgrader.patch +++ b/paper-server/nms-patches/net/minecraft/util/worldupdate/WorldUpgrader.patch @@ -1,23 +1,32 @@ --- a/net/minecraft/util/worldupdate/WorldUpgrader.java +++ b/net/minecraft/util/worldupdate/WorldUpgrader.java -@@ -66,7 +66,7 @@ +@@ -81,7 +81,7 @@ - public WorldUpgrader(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, IRegistry iregistry, boolean flag) { - this.dimensions = iregistry; -- this.levels = (Set) iregistry.registryKeySet().stream().map(Registries::levelStemToLevel).collect(Collectors.toUnmodifiableSet()); + public WorldUpgrader(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, IRegistryCustom iregistrycustom, boolean flag, boolean flag1) { + this.dimensions = iregistrycustom.registryOrThrow(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; -@@ -145,9 +145,9 @@ - if (nbttagcompound != null) { - int j = IChunkLoader.getVersion(nbttagcompound); - ChunkGenerator chunkgenerator = ((WorldDimension) this.dimensions.getOrThrow(Registries.levelToLevelStem(resourcekey2))).generator(); -- NBTTagCompound nbttagcompound1 = ichunkloader.upgradeChunkTag(resourcekey2, () -> { -+ NBTTagCompound nbttagcompound1 = ichunkloader.upgradeChunkTag(Registries.levelToLevelStem(resourcekey2), () -> { // CraftBukkit - return this.overworldDataStorage; -- }, nbttagcompound, chunkgenerator.getTypeNameForDataFixer()); -+ }, nbttagcompound, chunkgenerator.getTypeNameForDataFixer(), chunkcoordintpair, null); // CraftBukkit - ChunkCoordIntPair chunkcoordintpair1 = new ChunkCoordIntPair(nbttagcompound1.getInt("xPos"), nbttagcompound1.getInt("zPos")); +@@ -194,9 +194,9 @@ + if (nbttagcompound != null) { + int i = IChunkLoader.getVersion(nbttagcompound); + ChunkGenerator chunkgenerator = ((WorldDimension) WorldUpgrader.this.dimensions.getOrThrow(Registries.levelToLevelStem(resourcekey))).generator(); +- NBTTagCompound nbttagcompound1 = ichunkloader.upgradeChunkTag(resourcekey, () -> { ++ NBTTagCompound nbttagcompound1 = ichunkloader.upgradeChunkTag(Registries.levelToLevelStem(resourcekey), () -> { // CraftBukkit + return WorldUpgrader.this.overworldDataStorage; +- }, nbttagcompound, chunkgenerator.getTypeNameForDataFixer()); ++ }, nbttagcompound, chunkgenerator.getTypeNameForDataFixer(), chunkcoordintpair, null); // CraftBukkit + ChunkCoordIntPair chunkcoordintpair1 = new ChunkCoordIntPair(nbttagcompound1.getInt("xPos"), nbttagcompound1.getInt("zPos")); - if (!chunkcoordintpair1.equals(chunkcoordintpair)) { + if (!chunkcoordintpair1.equals(chunkcoordintpair)) { +@@ -316,7 +316,7 @@ + WorldUpgrader.c worldupgrader_c = (WorldUpgrader.c) iterator.next(); + ResourceKey resourcekey = worldupgrader_c.dimensionKey; + ListIterator listiterator = worldupgrader_c.files; +- T t0 = (AutoCloseable) worldupgrader_c.storage; ++ T t0 = (T) worldupgrader_c.storage; // CraftBukkit - decompile error + + if (listiterator.hasNext()) { + WorldUpgrader.e worldupgrader_e = (WorldUpgrader.e) listiterator.next(); diff --git a/paper-server/nms-patches/net/minecraft/world/ChestLock.patch b/paper-server/nms-patches/net/minecraft/world/ChestLock.patch index 424ef2ca00..a6fe4a98bb 100644 --- a/paper-server/nms-patches/net/minecraft/world/ChestLock.patch +++ b/paper-server/nms-patches/net/minecraft/world/ChestLock.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/ChestLock.java +++ b/net/minecraft/world/ChestLock.java -@@ -4,6 +4,11 @@ - import net.minecraft.nbt.NBTTagCompound; +@@ -6,6 +6,11 @@ + import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.world.item.ItemStack; +// CraftBukkit start @@ -9,27 +9,27 @@ +import org.bukkit.craftbukkit.util.CraftChatMessage; +// CraftBukkit end + - @Immutable - public class ChestLock { + public record ChestLock(String key) { -@@ -16,7 +21,19 @@ - } + public static final ChestLock NO_LOCK = new ChestLock(""); +@@ -18,7 +23,19 @@ + } else { + IChatBaseComponent ichatbasecomponent = (IChatBaseComponent) itemstack.get(DataComponents.CUSTOM_NAME); - public boolean unlocksWith(ItemStack itemstack) { -- return this.key.isEmpty() || !itemstack.isEmpty() && itemstack.hasCustomHoverName() && this.key.equals(itemstack.getHoverName().getString()); -+ // CraftBukkit start - SPIGOT-6307: Check for color codes if the lock contains color codes -+ if (this.key.isEmpty()) return true; -+ if (!itemstack.isEmpty() && itemstack.hasCustomHoverName()) { -+ 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(itemstack.getHoverName().getString()); -+ } else { -+ // The lock key contains color codes, so let's take them into account: -+ return this.key.equals(CraftChatMessage.fromComponent(itemstack.getHoverName())); +- 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 ++ return false; ++ // CraftBukkit end + } } - public void addToTag(NBTTagCompound nbttagcompound) { diff --git a/paper-server/nms-patches/net/minecraft/world/IInventory.patch b/paper-server/nms-patches/net/minecraft/world/IInventory.patch index 8fecf72098..f405332f8b 100644 --- a/paper-server/nms-patches/net/minecraft/world/IInventory.patch +++ b/paper-server/nms-patches/net/minecraft/world/IInventory.patch @@ -11,21 +11,21 @@ + public interface IInventory extends Clearable { - int LARGE_MAX_STACK_SIZE = 64; -@@ -26,9 +31,7 @@ + float DEFAULT_DISTANCE_BUFFER = 4.0F; +@@ -25,9 +30,7 @@ void setItem(int i, ItemStack itemstack); - default int getMaxStackSize() { -- return 64; +- return 99; - } + int getMaxStackSize(); // CraftBukkit - void setChanged(); + default int getMaxStackSize(ItemStack itemstack) { + return Math.min(this.getMaxStackSize(), itemstack.getMaxStackSize()); +@@ -91,4 +94,29 @@ -@@ -88,4 +91,29 @@ - - return world == null ? false : (world.getBlockEntity(blockposition) != tileentity ? false : entityhuman.distanceToSqr((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) <= (double) (i * i)); + return world == null ? false : (world.getBlockEntity(blockposition) != tileentity ? false : entityhuman.canInteractWithBlock(blockposition, (double) f)); } + + // CraftBukkit start @@ -50,6 +50,6 @@ + default void setCurrentRecipe(RecipeHolder recipe) { + } + -+ int MAX_STACK = 64; ++ int MAX_STACK = 99; + // CraftBukkit end } diff --git a/paper-server/nms-patches/net/minecraft/world/damagesource/DamageSource.patch b/paper-server/nms-patches/net/minecraft/world/damagesource/DamageSource.patch index fde31eb45c..a42500d312 100644 --- a/paper-server/nms-patches/net/minecraft/world/damagesource/DamageSource.patch +++ b/paper-server/nms-patches/net/minecraft/world/damagesource/DamageSource.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/damagesource/DamageSource.java +++ b/net/minecraft/world/damagesource/DamageSource.java -@@ -20,6 +20,86 @@ +@@ -21,6 +21,86 @@ private final Entity directEntity; @Nullable private final Vec3D damageSourcePosition; @@ -87,12 +87,3 @@ public String toString() { return "DamageSource (" + this.type().msgId() + ")"; -@@ -33,7 +113,7 @@ - return this.causingEntity != this.directEntity; - } - -- private DamageSource(Holder holder, @Nullable Entity entity, @Nullable Entity entity1, @Nullable Vec3D vec3d) { -+ public DamageSource(Holder holder, @Nullable Entity entity, @Nullable Entity entity1, @Nullable Vec3D vec3d) { - this.type = holder; - this.causingEntity = entity1; - this.directEntity = entity; 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 f4b437045a..539a08569e 100644 --- a/paper-server/nms-patches/net/minecraft/world/effect/HealOrHarmMobEffect.patch +++ b/paper-server/nms-patches/net/minecraft/world/effect/HealOrHarmMobEffect.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/effect/HealOrHarmMobEffect.java +++ b/net/minecraft/world/effect/HealOrHarmMobEffect.java -@@ -17,7 +17,7 @@ - public void applyEffectTick(EntityLiving entityliving, int i) { - super.applyEffectTick(entityliving, i); +@@ -16,7 +16,7 @@ + @Override + public boolean applyEffectTick(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 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 65962d9d09..3bfa8f796f 100644 --- a/paper-server/nms-patches/net/minecraft/world/effect/HungerMobEffect.patch +++ b/paper-server/nms-patches/net/minecraft/world/effect/HungerMobEffect.patch @@ -1,11 +1,11 @@ --- a/net/minecraft/world/effect/HungerMobEffect.java +++ b/net/minecraft/world/effect/HungerMobEffect.java -@@ -15,7 +15,7 @@ - if (entityliving instanceof EntityHuman) { - EntityHuman entityhuman = (EntityHuman) entityliving; - +@@ -12,7 +12,7 @@ + @Override + public boolean applyEffectTick(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 } - } + return true; diff --git a/paper-server/nms-patches/net/minecraft/world/effect/MobEffectUtil.patch b/paper-server/nms-patches/net/minecraft/world/effect/MobEffectUtil.patch index f243643eea..ae1001ff82 100644 --- a/paper-server/nms-patches/net/minecraft/world/effect/MobEffectUtil.patch +++ b/paper-server/nms-patches/net/minecraft/world/effect/MobEffectUtil.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/effect/MobEffectUtil.java +++ b/net/minecraft/world/effect/MobEffectUtil.java -@@ -49,13 +49,19 @@ +@@ -50,13 +50,19 @@ } public static List addEffectToPlayersAround(WorldServer worldserver, @Nullable Entity entity, Vec3D vec3d, double d0, MobEffect mobeffect, int i) { @@ -10,9 +10,9 @@ + + public static List addEffectToPlayersAround(WorldServer worldserver, @Nullable Entity entity, Vec3D vec3d, double d0, MobEffect mobeffect, int i, org.bukkit.event.entity.EntityPotionEffectEvent.Cause cause) { + // CraftBukkit end - MobEffectList mobeffectlist = mobeffect.getEffect(); + Holder holder = mobeffect.getEffect(); List list = worldserver.getPlayers((entityplayer) -> { - return entityplayer.gameMode.isSurvival() && (entity == null || !entity.isAlliedTo((Entity) entityplayer)) && vec3d.closerThan(entityplayer.position(), d0) && (!entityplayer.hasEffect(mobeffectlist) || entityplayer.getEffect(mobeffectlist).getAmplifier() < mobeffect.getAmplifier() || entityplayer.getEffect(mobeffectlist).endsWithin(i - 1)); + return entityplayer.gameMode.isSurvival() && (entity == null || !entity.isAlliedTo((Entity) entityplayer)) && vec3d.closerThan(entityplayer.position(), d0) && (!entityplayer.hasEffect(holder) || entityplayer.getEffect(holder).getAmplifier() < mobeffect.getAmplifier() || entityplayer.getEffect(holder).endsWithin(i - 1)); }); list.forEach((entityplayer) -> { 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 57ba5d621d..e493de93e1 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 -@@ -12,7 +12,7 @@ - public void applyEffectTick(EntityLiving entityliving, int i) { - super.applyEffectTick(entityliving, i); +@@ -11,7 +11,7 @@ + @Override + public boolean applyEffectTick(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 } - } + 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 3c8b576194..7ec7c8c01a 100644 --- a/paper-server/nms-patches/net/minecraft/world/effect/RegenerationMobEffect.patch +++ b/paper-server/nms-patches/net/minecraft/world/effect/RegenerationMobEffect.patch @@ -1,11 +1,11 @@ --- a/net/minecraft/world/effect/RegenerationMobEffect.java +++ b/net/minecraft/world/effect/RegenerationMobEffect.java -@@ -12,7 +12,7 @@ - public void applyEffectTick(EntityLiving entityliving, int i) { - super.applyEffectTick(entityliving, i); +@@ -11,7 +11,7 @@ + @Override + public boolean applyEffectTick(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 } - } + return true; 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 cd7fcfc9ce..390177b4bb 100644 --- a/paper-server/nms-patches/net/minecraft/world/effect/SaturationMobEffect.patch +++ b/paper-server/nms-patches/net/minecraft/world/effect/SaturationMobEffect.patch @@ -12,10 +12,10 @@ class SaturationMobEffect extends InstantMobEffect { protected SaturationMobEffect(MobEffectInfo mobeffectinfo, int i) { -@@ -15,7 +20,15 @@ - if (!entityliving.level().isClientSide && entityliving instanceof EntityHuman) { - EntityHuman entityhuman = (EntityHuman) entityliving; - +@@ -12,7 +17,15 @@ + @Override + public boolean applyEffectTick(EntityLiving entityliving, int i) { + if (!entityliving.level().isClientSide && entityliving instanceof EntityHuman entityhuman) { - entityhuman.getFoodData().eat(i + 1, 1.0F); + // CraftBukkit start + int oldFoodLevel = entityhuman.getFoodData().foodLevel; @@ -28,4 +28,4 @@ + // CraftBukkit end } - } + return true; 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 52f6534e9e..54d9040f99 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/Entity.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/Entity.patch @@ -1,10 +1,11 @@ --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java -@@ -126,8 +126,68 @@ - import org.joml.Vector3f; +@@ -128,8 +128,69 @@ + import net.minecraft.world.scores.ScoreboardTeamBase; import org.slf4j.Logger; +// CraftBukkit start ++import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata; +import net.minecraft.world.level.dimension.WorldDimension; +import org.bukkit.Bukkit; +import org.bukkit.Location; @@ -38,7 +39,7 @@ +import org.bukkit.plugin.PluginManager; +// CraftBukkit end + - public abstract class Entity implements INamableTileEntity, EntityAccess, ICommandListener, ScoreHolder { + public abstract class Entity implements SyncedDataHolder, INamableTileEntity, EntityAccess, ICommandListener, ScoreHolder { + // CraftBukkit start + private static final int CURRENT_LEVEL = 2; @@ -69,10 +70,10 @@ private static final Logger LOGGER = LogUtils.getLogger(); public static final String ID_TAG = "id"; public static final String PASSENGERS_TAG = "Passengers"; -@@ -242,6 +302,29 @@ +@@ -243,6 +304,29 @@ public boolean hasVisualFire; @Nullable - private IBlockData feetBlockState; + private IBlockData inBlockState; + // CraftBukkit start + public boolean persist = true; + public boolean visibleByDefault = true; @@ -99,7 +100,7 @@ public Entity(EntityTypes entitytypes, World world) { this.id = Entity.ENTITY_COUNTER.incrementAndGet(); -@@ -346,12 +429,18 @@ +@@ -349,12 +433,18 @@ } public void kill() { @@ -119,8 +120,25 @@ + // CraftBukkit end } - protected abstract void defineSynchedData(); -@@ -369,12 +458,24 @@ + protected abstract void defineSynchedData(DataWatcher.a datawatcher_a); +@@ -363,6 +453,16 @@ + return this.entityData; + } + ++ // CraftBukkit start ++ public void refreshEntityData(EntityPlayer to) { ++ List> list = this.getEntityData().getNonDefaultValues(); ++ ++ if (list != null) { ++ to.connection.send(new PacketPlayOutEntityMetadata(this.getId(), list)); ++ } ++ } ++ // CraftBukkit end ++ + public boolean equals(Object object) { + return object instanceof Entity ? ((Entity) object).id == this.id : false; + } +@@ -372,12 +472,24 @@ } public void remove(Entity.RemovalReason entity_removalreason) { @@ -146,7 +164,7 @@ this.entityData.set(Entity.DATA_POSE, entitypose); } -@@ -399,6 +500,33 @@ +@@ -402,6 +514,33 @@ } protected void setRot(float f, float f1) { @@ -180,7 +198,7 @@ this.setYRot(f % 360.0F); this.setXRot(f1 % 360.0F); } -@@ -440,6 +568,15 @@ +@@ -443,6 +582,15 @@ this.baseTick(); } @@ -195,8 +213,8 @@ + public void baseTick() { this.level().getProfiler().push("entityBaseTick"); - this.feetBlockState = null; -@@ -454,7 +591,7 @@ + this.inBlockState = null; +@@ -457,7 +605,7 @@ this.walkDistO = this.walkDist; this.xRotO = this.getXRot(); this.yRotO = this.getYRot(); @@ -205,7 +223,7 @@ if (this.canSpawnSprintParticle()) { this.spawnSprintParticle(); } -@@ -489,6 +626,10 @@ +@@ -492,6 +640,10 @@ if (this.isInLava()) { this.lavaHurt(); this.fallDistance *= 0.5F; @@ -216,11 +234,11 @@ } this.checkBelowWorld(); -@@ -540,15 +681,47 @@ +@@ -543,15 +695,47 @@ public void lavaHurt() { if (!this.fireImmune()) { -- this.setSecondsOnFire(15); +- this.igniteForSeconds(15); - if (this.hurt(this.damageSources().lava(), 4.0F)) { + // CraftBukkit start - Fallen in lava TODO: this event spams! + if (this instanceof EntityLiving && remainingFireTicks <= 0) { @@ -231,11 +249,11 @@ + this.level.getCraftServer().getPluginManager().callEvent(combustEvent); + + if (!combustEvent.isCancelled()) { -+ this.setSecondsOnFire(combustEvent.getDuration(), false); ++ this.igniteForSeconds(combustEvent.getDuration(), false); + } + } else { + // This will be called every single tick the entity is in lava, so don't throw an event -+ this.setSecondsOnFire(15, false); ++ this.igniteForSeconds(15, false); + } + + if (this.hurt(this.damageSources().lava().directBlock(level, lastLavaContact), 4.0F)) { @@ -246,12 +264,12 @@ } } - public void setSecondsOnFire(int i) { + public final void igniteForSeconds(int i) { + // CraftBukkit start -+ this.setSecondsOnFire(i, true); ++ this.igniteForSeconds(i, true); + } + -+ public void setSecondsOnFire(int i, boolean callEvent) { ++ public final void igniteForSeconds(int i, boolean callEvent) { + if (callEvent) { + EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity(), i); + this.level.getCraftServer().getPluginManager().callEvent(event); @@ -263,10 +281,10 @@ + i = event.getDuration(); + } + // CraftBukkit end - int j = i * 20; + this.igniteForTicks(i * 20); + } - if (this instanceof EntityLiving) { -@@ -574,7 +747,7 @@ +@@ -575,7 +759,7 @@ } protected void onBelowWorld() { @@ -275,7 +293,7 @@ } public boolean isFree(double d0, double d1, double d2) { -@@ -699,6 +872,28 @@ +@@ -700,6 +884,28 @@ block.updateEntityAfterFallOn(this.level(), this); } @@ -304,7 +322,7 @@ if (this.onGround()) { block.stepOn(this.level(), blockposition, iblockdata, this); } -@@ -1026,6 +1221,20 @@ +@@ -1027,6 +1233,20 @@ return SoundEffects.GENERIC_SPLASH; } @@ -325,7 +343,7 @@ 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); -@@ -1440,6 +1649,7 @@ +@@ -1454,6 +1674,7 @@ this.yo = d1; this.zo = d4; this.setPos(d3, d1, d4); @@ -333,7 +351,7 @@ } public void moveTo(Vec3D vec3d) { -@@ -1634,6 +1844,12 @@ +@@ -1652,6 +1873,12 @@ return false; } @@ -346,7 +364,7 @@ public void awardKillScore(Entity entity, int i, DamageSource damagesource) { if (entity instanceof EntityPlayer) { CriterionTriggers.ENTITY_KILLED_PLAYER.trigger((EntityPlayer) entity, this, damagesource); -@@ -1662,16 +1878,22 @@ +@@ -1680,16 +1907,22 @@ } public boolean saveAsPassenger(NBTTagCompound nbttagcompound) { @@ -371,7 +389,7 @@ return true; } } -@@ -1682,16 +1904,38 @@ +@@ -1700,16 +1933,38 @@ } public NBTTagCompound saveWithoutId(NBTTagCompound nbttagcompound) { @@ -414,7 +432,7 @@ nbttagcompound.put("Rotation", this.newFloatList(this.getYRot(), this.getXRot())); nbttagcompound.putFloat("FallDistance", this.fallDistance); nbttagcompound.putShort("Fire", (short) this.remainingFireTicks); -@@ -1699,7 +1943,28 @@ +@@ -1717,7 +1972,28 @@ nbttagcompound.putBoolean("OnGround", this.onGround()); nbttagcompound.putBoolean("Invulnerable", this.invulnerable); nbttagcompound.putInt("PortalCooldown", this.portalCooldown); @@ -444,7 +462,7 @@ IChatBaseComponent ichatbasecomponent = this.getCustomName(); if (ichatbasecomponent != null) { -@@ -1748,7 +2013,7 @@ +@@ -1766,7 +2042,7 @@ nbttagcompound.put("Tags", nbttaglist); } @@ -453,7 +471,7 @@ if (this.isVehicle()) { nbttaglist = new NBTTagList(); iterator = this.getPassengers().iterator(); -@@ -1757,7 +2022,7 @@ +@@ -1775,7 +2051,7 @@ Entity entity = (Entity) iterator.next(); NBTTagCompound nbttagcompound1 = new NBTTagCompound(); @@ -462,7 +480,7 @@ nbttaglist.add(nbttagcompound1); } } -@@ -1767,6 +2032,11 @@ +@@ -1785,6 +2061,11 @@ } } @@ -474,7 +492,7 @@ return nbttagcompound; } catch (Throwable throwable) { CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT"); -@@ -1850,6 +2120,45 @@ +@@ -1868,6 +2149,45 @@ } else { throw new IllegalStateException("Entity has invalid position"); } @@ -520,7 +538,7 @@ } catch (Throwable throwable) { CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT"); CrashReportSystemDetails crashreportsystemdetails = crashreport.addCategory("Entity being loaded"); -@@ -1871,6 +2180,12 @@ +@@ -1889,6 +2209,12 @@ return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null; } @@ -533,7 +551,7 @@ protected abstract void readAdditionalSaveData(NBTTagCompound nbttagcompound); protected abstract void addAdditionalSaveData(NBTTagCompound nbttagcompound); -@@ -1925,9 +2240,22 @@ +@@ -1943,9 +2269,22 @@ } else if (this.level().isClientSide) { return null; } else { @@ -556,7 +574,7 @@ this.level().addFreshEntity(entityitem); return entityitem; } -@@ -2025,6 +2353,27 @@ +@@ -2046,6 +2385,27 @@ if (!flag && (!this.canRide(entity) || !entity.canAddPassenger(this))) { return false; } else { @@ -584,7 +602,7 @@ if (this.isPassenger()) { this.stopRiding(); } -@@ -2058,7 +2407,7 @@ +@@ -2079,7 +2439,7 @@ Entity entity = this.vehicle; this.vehicle = null; @@ -593,7 +611,7 @@ } } -@@ -2089,10 +2438,38 @@ +@@ -2110,10 +2470,38 @@ } } @@ -633,7 +651,7 @@ if (this.passengers.size() == 1 && this.passengers.get(0) == entity) { this.passengers = ImmutableList.of(); } else { -@@ -2104,6 +2481,7 @@ +@@ -2125,6 +2513,7 @@ entity.boardingCooldown = 60; this.gameEvent(GameEvent.ENTITY_DISMOUNT, entity); } @@ -641,7 +659,7 @@ } protected boolean canAddPassenger(Entity entity) { -@@ -2190,14 +2568,20 @@ +@@ -2210,14 +2599,20 @@ if (this.isInsidePortal) { MinecraftServer minecraftserver = worldserver.getServer(); @@ -665,7 +683,7 @@ this.level().getProfiler().pop(); } -@@ -2321,6 +2705,13 @@ +@@ -2327,6 +2722,13 @@ } public void setSwimming(boolean flag) { @@ -679,7 +697,7 @@ this.setSharedFlag(4, flag); } -@@ -2370,8 +2761,12 @@ +@@ -2376,8 +2778,12 @@ return this.getTeam() != null ? this.getTeam().isAlliedTo(scoreboardteambase) : false; } @@ -693,7 +711,7 @@ } public boolean getSharedFlag(int i) { -@@ -2390,7 +2785,7 @@ +@@ -2396,7 +2802,7 @@ } public int getMaxAirSupply() { @@ -702,7 +720,7 @@ } public int getAirSupply() { -@@ -2398,7 +2793,18 @@ +@@ -2404,7 +2810,18 @@ } public void setAirSupply(int i) { @@ -722,7 +740,7 @@ } public int getTicksFrozen() { -@@ -2425,11 +2831,40 @@ +@@ -2431,11 +2848,40 @@ public void thunderHit(WorldServer worldserver, EntityLightning entitylightning) { this.setRemainingFireTicks(this.remainingFireTicks + 1); @@ -733,12 +751,12 @@ + // CraftBukkit end + if (this.remainingFireTicks == 0) { -- this.setSecondsOnFire(8); +- this.igniteForSeconds(8); + // CraftBukkit start - Call a combust event when lightning strikes + EntityCombustByEntityEvent entityCombustEvent = new EntityCombustByEntityEvent(stormBukkitEntity, thisBukkitEntity, 8); + pluginManager.callEvent(entityCombustEvent); + if (!entityCombustEvent.isCancelled()) { -+ this.setSecondsOnFire(entityCombustEvent.getDuration(), false); ++ this.igniteForSeconds(entityCombustEvent.getDuration(), false); + } + // CraftBukkit end } @@ -765,7 +783,7 @@ } public void onAboveBubbleCol(boolean flag) { -@@ -2594,15 +3029,38 @@ +@@ -2600,15 +3046,38 @@ @Nullable public Entity changeDimension(WorldServer worldserver) { @@ -806,7 +824,7 @@ this.level().getProfiler().popPush("reloading"); Entity entity = this.getType().create(worldserver); -@@ -2610,10 +3068,22 @@ +@@ -2616,10 +3085,22 @@ entity.restoreFrom(this); entity.moveTo(shapedetectorshape.pos.x, shapedetectorshape.pos.y, shapedetectorshape.pos.z, shapedetectorshape.yRot, entity.getXRot()); entity.setDeltaMovement(shapedetectorshape.speed); @@ -832,7 +850,7 @@ } this.removeAfterChangingDimensions(); -@@ -2629,25 +3099,39 @@ +@@ -2635,25 +3116,39 @@ } protected void removeAfterChangingDimensions() { @@ -878,7 +896,7 @@ IBlockData iblockdata = this.level().getBlockState(this.portalEntrancePos); EnumDirection.EnumAxis enumdirection_enumaxis; Vec3D vec3d; -@@ -2664,8 +3148,8 @@ +@@ -2670,8 +3165,8 @@ vec3d = new Vec3D(0.5D, 0.0D, 0.0D); } @@ -888,24 +906,24 @@ + }).orElse(null); // CraftBukkit - decompile error } } else { - BlockPosition blockposition1; -@@ -2675,8 +3159,14 @@ + BlockPosition blockposition1 = flag1 ? WorldServer.END_SPAWN_POINT : worldserver.getSharedSpawnPos(); +@@ -2684,8 +3179,14 @@ } else { - blockposition1 = worldserver.getHeightmapPos(HeightMap.Type.MOTION_BLOCKING_NO_LEAVES, worldserver.getSharedSpawnPos()); + i = worldserver.getChunkAt(blockposition1).getHeight(HeightMap.Type.MOTION_BLOCKING_NO_LEAVES, blockposition1.getX(), blockposition1.getZ()) + 1; } + // CraftBukkit start -+ CraftPortalEvent event = callPortalEvent(this, worldserver, new Vec3D(blockposition1.getX() + 0.5D, blockposition1.getY(), blockposition1.getZ() + 0.5D), PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0); ++ CraftPortalEvent event = callPortalEvent(this, worldserver, new Vec3D(blockposition1.getX() + 0.5D, i, blockposition1.getZ() + 0.5D), PlayerTeleportEvent.TeleportCause.END_PORTAL, 0, 0); + if (event == null) { + return null; + } -- return new ShapeDetectorShape(new Vec3D((double) blockposition1.getX() + 0.5D, (double) blockposition1.getY(), (double) blockposition1.getZ() + 0.5D), this.getDeltaMovement(), this.getYRot(), this.getXRot()); +- return new ShapeDetectorShape(new Vec3D((double) blockposition1.getX() + 0.5D, (double) i, (double) blockposition1.getZ() + 0.5D), this.getDeltaMovement(), this.getYRot(), this.getXRot()); + return new ShapeDetectorShape(new Vec3D(event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()), this.getDeltaMovement(), this.getYRot(), this.getXRot(), ((CraftWorld) event.getTo().getWorld()).getHandle(), event); + // CraftBukkit end } } -@@ -2684,8 +3174,23 @@ +@@ -2693,8 +3194,23 @@ return BlockPortalShape.getRelativePosition(blockutil_rectangle, enumdirection_enumaxis, this.position(), this.getDimensions(this.getPose())); } @@ -931,7 +949,7 @@ } public boolean canChangeDimensions() { -@@ -2806,6 +3311,12 @@ +@@ -2815,6 +3331,12 @@ } } @@ -944,7 +962,7 @@ public boolean teleportTo(WorldServer worldserver, double d0, double d1, double d2, Set set, float f, float f1) { float f2 = MathHelper.clamp(f1, -90.0F, 90.0F); -@@ -2824,8 +3335,12 @@ +@@ -2833,8 +3355,12 @@ entity.restoreFrom(this); entity.moveTo(d0, d1, d2, f, f2); entity.setYHeadRot(f); @@ -959,7 +977,7 @@ } return true; -@@ -2931,7 +3446,26 @@ +@@ -2942,7 +3468,26 @@ } public final void setBoundingBox(AxisAlignedBB axisalignedbb) { @@ -986,8 +1004,8 @@ + // CraftBukkit end } - protected float getEyeHeight(EntityPose entitypose, EntitySize entitysize) { -@@ -3246,6 +3780,11 @@ + public final float getEyeHeight(EntityPose entitypose) { +@@ -3263,6 +3808,11 @@ vec3d = vec3d.add(vec3d1); ++k1; } @@ -999,7 +1017,7 @@ } } } -@@ -3517,6 +4056,14 @@ +@@ -3532,6 +4082,14 @@ @Override public final void setRemoved(Entity.RemovalReason entity_removalreason) { 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 f10363dae0..58a58725a9 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/EntityAreaEffectCloud.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/EntityAreaEffectCloud.patch @@ -1,11 +1,10 @@ --- a/net/minecraft/world/entity/EntityAreaEffectCloud.java +++ b/net/minecraft/world/entity/EntityAreaEffectCloud.java -@@ -31,6 +31,13 @@ +@@ -30,6 +30,12 @@ import net.minecraft.world.level.material.EnumPistonReaction; import org.slf4j.Logger; +// CraftBukkit start -+import net.minecraft.resources.MinecraftKey; +import org.bukkit.craftbukkit.entity.CraftLivingEntity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.entity.EntityRemoveEvent; @@ -14,7 +13,7 @@ public class EntityAreaEffectCloud extends Entity implements TraceableEntity { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -216,7 +223,7 @@ +@@ -186,7 +192,7 @@ } } else { if (this.tickCount >= this.waitTime + this.duration) { @@ -23,7 +22,7 @@ return; } -@@ -233,7 +240,7 @@ +@@ -203,7 +209,7 @@ if (this.radiusPerTick != 0.0F) { f += this.radiusPerTick; if (f < 0.5F) { @@ -32,7 +31,7 @@ return; } -@@ -264,6 +271,7 @@ +@@ -237,6 +243,7 @@ if (!list1.isEmpty()) { Iterator iterator1 = list1.iterator(); @@ -40,10 +39,10 @@ while (iterator1.hasNext()) { EntityLiving entityliving = (EntityLiving) iterator1.next(); -@@ -273,6 +281,17 @@ - double d8 = d6 * d6 + d7 * d7; +@@ -246,6 +253,17 @@ + double d5 = d3 * d3 + d4 * d4; - if (d8 <= (double) (f * f)) { + if (d5 <= (double) (f * f)) { + // CraftBukkit start + entities.add((LivingEntity) entityliving.getBukkitEntity()); + } @@ -58,9 +57,9 @@ this.victims.put(entityliving, this.tickCount + this.reapplicationDelay); Iterator iterator2 = list.iterator(); -@@ -282,14 +301,14 @@ - if (mobeffect1.getEffect().isInstantenous()) { - mobeffect1.getEffect().applyInstantenousEffect(this, this.getOwner(), entityliving, mobeffect1.getAmplifier(), 0.5D); +@@ -255,14 +273,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 @@ -75,7 +74,7 @@ return; } -@@ -299,7 +318,7 @@ +@@ -272,7 +290,7 @@ if (this.durationOnUse != 0) { this.duration += this.durationOnUse; if (this.duration <= 0) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/EntityCreature.patch b/paper-server/nms-patches/net/minecraft/world/entity/EntityCreature.patch index 0af2eb0e05..2d506ce6f9 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/EntityCreature.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/EntityCreature.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/EntityCreature.java +++ b/net/minecraft/world/entity/EntityCreature.java -@@ -9,6 +9,10 @@ +@@ -11,6 +11,10 @@ import net.minecraft.world.level.World; import net.minecraft.world.phys.Vec3D; @@ -11,7 +11,7 @@ public abstract class EntityCreature extends EntityInsentient { protected static final float DEFAULT_WALK_TARGET_VALUE = 0.0F; -@@ -51,6 +55,7 @@ +@@ -67,6 +71,7 @@ if (this instanceof EntityTameableAnimal && ((EntityTameableAnimal) this).isInSittingPose()) { if (f > 10.0F) { @@ -19,7 +19,7 @@ this.dropLeash(true, true); } -@@ -59,6 +64,7 @@ +@@ -75,6 +80,7 @@ this.onLeashDistance(f); if (f > 10.0F) { 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 8d0823f904..904aa64996 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/EntityExperienceOrb.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/EntityExperienceOrb.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/EntityExperienceOrb.java +++ b/net/minecraft/world/entity/EntityExperienceOrb.java -@@ -21,6 +21,14 @@ +@@ -22,6 +22,14 @@ import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; @@ -15,7 +15,7 @@ public class EntityExperienceOrb extends Entity { private static final int LIFETIME = 6000; -@@ -59,6 +67,7 @@ +@@ -65,6 +73,7 @@ @Override public void tick() { super.tick(); @@ -23,7 +23,7 @@ this.xo = this.getX(); this.yo = this.getY(); this.zo = this.getZ(); -@@ -84,7 +93,22 @@ +@@ -90,7 +99,22 @@ this.followingPlayer = null; } @@ -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(); -@@ -109,7 +133,7 @@ +@@ -115,7 +139,7 @@ ++this.age; if (this.age >= 6000) { @@ -56,7 +56,7 @@ } } -@@ -178,7 +202,7 @@ +@@ -184,7 +208,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() { -@@ -200,7 +224,7 @@ +@@ -206,7 +230,7 @@ this.markHurt(); this.health = (int) ((float) this.health - f); if (this.health <= 0) { @@ -74,7 +74,7 @@ } return true; -@@ -227,17 +251,17 @@ +@@ -233,17 +257,17 @@ public void playerTouch(EntityHuman entityhuman) { if (!this.level().isClientSide) { if (entityhuman.takeXpDelay == 0) { @@ -95,7 +95,7 @@ } } -@@ -250,9 +274,17 @@ +@@ -256,9 +280,17 @@ if (entry != null) { ItemStack itemstack = (ItemStack) entry.getValue(); int j = Math.min(this.xpToDurability(i), itemstack.getDamageValue()); @@ -113,7 +113,7 @@ return k > 0 ? this.repairPlayerItems(entityhuman, k) : 0; } else { -@@ -277,6 +309,24 @@ +@@ -283,6 +315,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 6c044ca683..db4d0a83cc 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/EntityInsentient.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/EntityInsentient.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/entity/EntityInsentient.java +++ b/net/minecraft/world/entity/EntityInsentient.java -@@ -76,6 +76,20 @@ - import net.minecraft.world.level.pathfinder.PathType; +@@ -89,6 +89,20 @@ + import net.minecraft.world.level.storage.loot.parameters.LootContextParameters; import net.minecraft.world.phys.AxisAlignedBB; +// CraftBukkit start @@ -18,10 +18,10 @@ +import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason; +// CraftBukkit end + - public abstract class EntityInsentient extends EntityLiving implements Targeting { + public abstract class EntityInsentient extends EntityLiving implements EquipmentUser, Targeting { private static final DataWatcherObject DATA_MOB_FLAGS_ID = DataWatcher.defineId(EntityInsentient.class, DataWatcherRegistry.BYTE); -@@ -123,6 +137,8 @@ +@@ -138,6 +152,8 @@ private BlockPosition restrictCenter; private float restrictRadius; @@ -30,7 +30,7 @@ protected EntityInsentient(EntityTypes entitytypes, World world) { super(entitytypes, world); this.handItems = NonNullList.withSize(2, ItemStack.EMPTY); -@@ -148,6 +164,12 @@ +@@ -165,6 +181,12 @@ } @@ -43,7 +43,12 @@ protected void registerGoals() {} public static AttributeProvider.Builder createMobAttributes() { -@@ -259,7 +281,38 @@ +@@ -269,11 +291,42 @@ + + @Nullable + protected final EntityLiving getTargetFromBrain() { +- return (EntityLiving) this.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).orElse((Object) null); ++ return (EntityLiving) this.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).orElse(null); // CraftBukkit - decompile error } public void setTarget(@Nullable EntityLiving entityliving) { @@ -82,7 +87,7 @@ } @Override -@@ -399,6 +452,12 @@ +@@ -412,6 +465,12 @@ return null; } @@ -95,16 +100,16 @@ @Override public void addAdditionalSaveData(NBTTagCompound nbttagcompound) { super.addAdditionalSaveData(nbttagcompound); -@@ -457,7 +516,7 @@ +@@ -486,7 +545,7 @@ + } } - nbttagcompound.put("HandDropChances", nbttaglist3); -- if (this.leashHolder != null) { -+ if (this.leashHolder != null && !this.leashHolder.pluginRemoved) { // CraftBukkit - SPIGOT-7487: Don't save (and possible drop) leash, when the holder was removed by a plugin - nbttagcompound2 = new NBTTagCompound(); - if (this.leashHolder instanceof EntityLiving) { - UUID uuid = this.leashHolder.getUUID(); -@@ -488,16 +547,26 @@ +- if (either != null) { ++ if (either != null && !this.leashHolder.pluginRemoved) { // CraftBukkit - SPIGOT-7487: Don't save (and possible drop) leash, when the holder was removed by a plugin + nbttagcompound.put("leash", (NBTBase) either.map((uuid) -> { + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + +@@ -507,16 +566,26 @@ nbttagcompound.putBoolean("NoAI", this.isNoAi()); } @@ -131,9 +136,18 @@ + } + // CraftBukkit end NBTTagList nbttaglist; + NBTTagCompound nbttagcompound1; int i; - -@@ -544,6 +613,11 @@ +@@ -565,7 +634,7 @@ + if (nbttagcompound.contains("leash", 10)) { + this.delayedLeashInfo = Either.left(nbttagcompound.getCompound("leash").getUUID("UUID")); + } else if (nbttagcompound.contains("leash", 11)) { +- this.delayedLeashInfo = (Either) GameProfileSerializer.readBlockPos(nbttagcompound, "leash").map(Either::right).orElse((Object) null); ++ this.delayedLeashInfo = (Either) GameProfileSerializer.readBlockPos(nbttagcompound, "leash").map(Either::right).orElse(null); // CraftBukkit - decompile error + } else { + this.delayedLeashInfo = null; + } +@@ -577,6 +646,11 @@ } this.setNoAi(nbttagcompound.getBoolean("NoAI")); @@ -145,7 +159,7 @@ } @Override -@@ -611,20 +685,26 @@ +@@ -651,20 +725,26 @@ protected void pickUpItem(EntityItem entityitem) { ItemStack itemstack = entityitem.getItem(); @@ -174,7 +188,7 @@ EnumItemSlot enumitemslot = getEquipmentSlotForItem(itemstack); ItemStack itemstack1 = this.getItemBySlot(enumitemslot); boolean flag = this.canReplaceCurrentItem(itemstack, itemstack1); -@@ -635,11 +715,19 @@ +@@ -675,11 +755,19 @@ flag = itemstack1.isEmpty(); } @@ -195,7 +209,7 @@ } if (enumitemslot.isArmor() && itemstack.getCount() > 1) { -@@ -760,7 +848,7 @@ +@@ -813,7 +901,7 @@ @Override public void checkDespawn() { if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL && this.shouldDespawnInPeaceful()) { @@ -204,7 +218,7 @@ } else if (!this.isPersistenceRequired() && !this.requiresCustomPersistence()) { EntityHuman entityhuman = this.level().getNearestPlayer(this, -1.0D); -@@ -770,14 +858,14 @@ +@@ -823,14 +911,14 @@ int j = i * i; if (d0 > (double) j && this.removeWhenFarAway(d0)) { @@ -221,15 +235,15 @@ } else if (d0 < (double) l) { this.noActionTime = 0; } -@@ -791,6 +879,7 @@ +@@ -844,6 +932,7 @@ @Override protected final void serverAiStep() { ++this.noActionTime; + if (!this.aware) return; // CraftBukkit - this.level().getProfiler().push("sensing"); - this.sensing.tick(); - this.level().getProfiler().pop(); -@@ -1184,6 +1273,12 @@ + GameProfilerFiller gameprofilerfiller = this.level().getProfiler(); + + gameprofilerfiller.push("sensing"); +@@ -1311,6 +1400,12 @@ if (!this.isAlive()) { return EnumInteractionResult.PASS; } else if (this.getLeashHolder() == entityhuman) { @@ -239,10 +253,10 @@ + return EnumInteractionResult.PASS; + } + // CraftBukkit end - this.dropLeash(true, !entityhuman.getAbilities().instabuild); + this.dropLeash(true, !entityhuman.hasInfiniteMaterials()); this.gameEvent(GameEvent.ENTITY_INTERACT, entityhuman); return EnumInteractionResult.sidedSuccess(this.level().isClientSide); -@@ -1209,6 +1304,12 @@ +@@ -1336,6 +1431,12 @@ ItemStack itemstack = entityhuman.getItemInHand(enumhand); if (itemstack.is(Items.LEAD) && this.canBeLeashed(entityhuman)) { @@ -255,7 +269,7 @@ this.setLeashedTo(entityhuman, true); itemstack.shrink(1); return EnumInteractionResult.sidedSuccess(this.level().isClientSide); -@@ -1224,7 +1325,7 @@ +@@ -1351,7 +1452,7 @@ if (itemstack.getItem() instanceof ItemMonsterEgg) { if (this.level() instanceof WorldServer) { ItemMonsterEgg itemmonsteregg = (ItemMonsterEgg) itemstack.getItem(); @@ -264,7 +278,7 @@ optional.ifPresent((entityinsentient) -> { this.onOffspringSpawnedFromEgg(entityhuman, entityinsentient); -@@ -1274,12 +1375,19 @@ +@@ -1401,12 +1502,19 @@ return this.restrictRadius != -1.0F; } @@ -285,7 +299,7 @@ if (t0 == null) { return null; -@@ -1313,7 +1421,12 @@ +@@ -1440,7 +1548,12 @@ } } @@ -299,7 +313,7 @@ if (this.isPassenger()) { Entity entity = this.getVehicle(); -@@ -1321,7 +1434,7 @@ +@@ -1448,7 +1561,7 @@ t0.startRiding(entity, true); } @@ -308,7 +322,7 @@ return t0; } } -@@ -1334,7 +1447,8 @@ +@@ -1461,7 +1574,8 @@ if (this.leashHolder != null) { if (!this.isAlive() || !this.leashHolder.isAlive()) { @@ -318,9 +332,9 @@ } } -@@ -1345,7 +1459,9 @@ - this.leashHolder = null; - this.leashInfoTag = null; +@@ -1473,7 +1587,9 @@ + this.delayedLeashInfo = null; + this.clearRestriction(); if (!this.level().isClientSide && flag1) { + this.forceDrops = true; // CraftBukkit this.spawnAtLocation((IMaterial) Items.LEAD); @@ -328,7 +342,7 @@ } if (!this.level().isClientSide && flag && this.level() instanceof WorldServer) { -@@ -1395,6 +1511,7 @@ +@@ -1527,6 +1643,7 @@ boolean flag1 = super.startRiding(entity, flag); if (flag1 && this.isLeashed()) { @@ -336,27 +350,27 @@ this.dropLeash(true, true); } -@@ -1419,7 +1536,9 @@ - } +@@ -1555,7 +1672,9 @@ + } - if (this.tickCount > 100) { -+ this.forceDrops = true; // CraftBukkit - this.spawnAtLocation((IMaterial) Items.LEAD); -+ this.forceDrops = false; // CraftBukkit - this.leashInfoTag = null; + if (this.tickCount > 100) { ++ this.forceDrops = true; // CraftBukkit + this.spawnAtLocation((IMaterial) Items.LEAD); ++ this.forceDrops = false; // CraftBukkit + this.delayedLeashInfo = null; + } } - } -@@ -1501,14 +1620,21 @@ +@@ -1638,14 +1757,21 @@ int i = EnchantmentManager.getFireAspect(this); if (i > 0) { -- entity.setSecondsOnFire(i * 4); +- entity.igniteForSeconds(i * 4); + // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item + EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), i * 4); + org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent); + + if (!combustEvent.isCancelled()) { -+ entity.setSecondsOnFire(combustEvent.getDuration(), false); ++ entity.igniteForSeconds(combustEvent.getDuration(), false); + } + // CraftBukkit end } @@ -370,7 +384,7 @@ this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D)); } -@@ -1576,6 +1702,7 @@ +@@ -1695,6 +1821,7 @@ @Override protected void removeAfterChangingDimensions() { super.removeAfterChangingDimensions(); 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 5ad8ee3d48..84f36215b0 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 -@@ -29,6 +29,11 @@ +@@ -30,6 +30,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; -@@ -120,7 +125,7 @@ +@@ -121,7 +126,7 @@ } } @@ -21,7 +21,7 @@ } else if (this.life < -this.random.nextInt(10)) { --this.flashes; this.life = 1; -@@ -129,7 +134,7 @@ +@@ -130,7 +135,7 @@ } } @@ -30,7 +30,7 @@ if (!(this.level() instanceof WorldServer)) { this.level().setSkyFlashTime(2); } else if (!this.visualOnly) { -@@ -163,8 +168,12 @@ +@@ -164,8 +169,12 @@ IBlockData iblockdata = BlockFireAbstract.getState(this.level(), blockposition); if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) { @@ -45,7 +45,7 @@ } for (int j = 0; j < i; ++j) { -@@ -172,8 +181,12 @@ +@@ -173,8 +182,12 @@ iblockdata = BlockFireAbstract.getState(this.level(), blockposition1); if (this.level().getBlockState(blockposition1).isAir() && iblockdata.canSurvive(this.level(), blockposition1)) { @@ -60,7 +60,7 @@ } } -@@ -237,8 +250,9 @@ +@@ -238,8 +251,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 91705f5769..3d38cbbfd3 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 -@@ -119,6 +119,32 @@ +@@ -126,6 +126,32 @@ import net.minecraft.world.scores.ScoreboardTeam; import org.slf4j.Logger; @@ -33,21 +33,10 @@ public abstract class EntityLiving extends Entity implements Attackable { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -214,7 +240,7 @@ - private int noJumpDelay; - private float absorptionAmount; - protected ItemStack useItem; -- protected int useItemRemaining; -+ public int useItemRemaining; - protected int fallFlyTicks; - private BlockPosition lastPos; - private Optional lastClimbablePos; -@@ -225,7 +251,21 @@ - private float swimAmount; - private float swimAmountO; +@@ -237,6 +263,20 @@ protected BehaviorController brain; -- private boolean skipDropExperience; -+ protected boolean skipDropExperience; + protected boolean skipDropExperience; + protected float appliedScale; + // CraftBukkit start + public int expToDrop; + public boolean forceDrops; @@ -65,9 +54,9 @@ protected EntityLiving(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -238,7 +278,9 @@ - this.useItem = ItemStack.EMPTY; +@@ -251,7 +291,9 @@ this.lastClimbablePos = Optional.empty(); + this.appliedScale = 1.0F; this.attributes = new AttributeMapBase(AttributeDefaults.getSupplier(entitytypes)); - this.setHealth(this.getMaxHealth()); + this.craftAttributes = new CraftAttributeMap(attributes); // CraftBukkit @@ -76,22 +65,22 @@ this.blocksBuilding = true; this.rotA = (float) ((Math.random() + 1.0D) * 0.009999999776482582D); this.reapplyPosition(); -@@ -317,7 +359,13 @@ - double d7 = Math.min((double) (0.2F + f / 15.0F), 2.5D); - int i = (int) (150.0D * d7); +@@ -329,7 +371,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), d1, d2, d3, 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), this.getX(), this.getY(), this.getZ(), i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, false); -+ } else { -+ ((WorldServer) this.level()).sendParticles(new ParticleParamBlock(Particles.BLOCK, iblockdata), d1, d2, d3, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D); -+ } -+ // CraftBukkit end +- ((WorldServer) this.level()).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); ++ } else { ++ ((WorldServer) this.level()).sendParticles(new ParticleParamBlock(Particles.BLOCK, iblockdata), d2, d3, d4, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D); ++ } ++ // CraftBukkit end + } } - super.checkFallDamage(d0, flag, iblockdata, blockposition); -@@ -573,7 +621,7 @@ +@@ -594,7 +642,7 @@ ++this.deathTime; if (this.deathTime >= 20 && !this.level().isClientSide() && !this.isRemoved()) { this.level().broadcastEntityEvent(this, (byte) 60); @@ -100,7 +89,7 @@ } } -@@ -672,13 +720,19 @@ +@@ -693,13 +741,19 @@ } public void onEquipItem(EnumItemSlot enumitemslot, ItemStack itemstack, ItemStack itemstack1) { @@ -112,32 +101,39 @@ + // CraftBukkit end boolean flag = itemstack1.isEmpty() && itemstack.isEmpty(); - if (!flag && !ItemStack.isSameItemSameTags(itemstack, itemstack1) && !this.firstTick) { + if (!flag && !ItemStack.isSameItemSameComponents(itemstack, itemstack1) && !this.firstTick) { Equipable equipable = Equipable.get(itemstack1); 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().playSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), equipable.getEquipSound(), this.getSoundSource(), 1.0F, 1.0F); + this.level().playSeededSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), equipable.getEquipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong()); } -@@ -692,7 +746,14 @@ +@@ -713,6 +767,13 @@ @Override public void remove(Entity.RemovalReason entity_removalreason) { -- super.remove(entity_removalreason); + // CraftBukkit start - add Bukkit remove cause + this.remove(entity_removalreason, null); + } + + @Override + public void remove(Entity.RemovalReason entity_removalreason, EntityRemoveEvent.Cause cause) { -+ super.remove(entity_removalreason, cause); + // CraftBukkit end + if (entity_removalreason == Entity.RemovalReason.KILLED || entity_removalreason == Entity.RemovalReason.DISCARDED) { + Iterator iterator = this.getActiveEffects().iterator(); + +@@ -723,7 +784,7 @@ + } + } + +- super.remove(entity_removalreason); ++ super.remove(entity_removalreason, cause); // CraftBukkit this.brain.clearMemories(); } -@@ -752,6 +813,17 @@ +@@ -783,6 +844,17 @@ } } @@ -155,7 +151,7 @@ if (nbttagcompound.contains("Health", 99)) { this.setHealth(nbttagcompound.getFloat("Health")); } -@@ -789,9 +861,32 @@ +@@ -821,9 +893,32 @@ } @@ -165,7 +161,7 @@ + + private static class ProcessableEffect { + -+ private MobEffectList type; ++ private Holder type; + private MobEffect effect; + private final EntityPotionEffectEvent.Cause cause; + @@ -174,7 +170,7 @@ + this.cause = cause; + } + -+ private ProcessableEffect(MobEffectList type, EntityPotionEffectEvent.Cause cause) { ++ private ProcessableEffect(Holder type, EntityPotionEffectEvent.Cause cause) { + this.type = type; + this.cause = cause; + } @@ -182,13 +178,13 @@ + // CraftBukkit end + protected void tickEffects() { - Iterator iterator = this.activeEffects.keySet().iterator(); + Iterator> iterator = this.activeEffects.keySet().iterator(); + isTickingEffects = true; // CraftBukkit try { while (iterator.hasNext()) { - MobEffectList mobeffectlist = (MobEffectList) iterator.next(); -@@ -801,6 +896,12 @@ + Holder holder = (Holder) iterator.next(); +@@ -833,6 +928,12 @@ this.onEffectUpdated(mobeffect, true, (Entity) null); })) { if (!this.level().isClientSide) { @@ -201,7 +197,7 @@ iterator.remove(); this.onEffectRemoved(mobeffect); } -@@ -811,6 +912,17 @@ +@@ -843,6 +944,17 @@ } catch (ConcurrentModificationException concurrentmodificationexception) { ; } @@ -219,8 +215,8 @@ if (this.effectsDirty) { if (!this.level().isClientSide) { -@@ -937,7 +1049,13 @@ - this.entityData.set(EntityLiving.DATA_EFFECT_COLOR_ID, 0); +@@ -958,7 +1070,13 @@ + this.entityData.set(EntityLiving.DATA_EFFECT_PARTICLES, List.of()); } + // CraftBukkit start @@ -233,7 +229,7 @@ if (this.level().isClientSide) { return false; } else { -@@ -946,7 +1064,14 @@ +@@ -967,7 +1085,14 @@ boolean flag; for (flag = false; iterator.hasNext(); flag = true) { @@ -249,7 +245,7 @@ iterator.remove(); } -@@ -975,19 +1100,49 @@ +@@ -996,20 +1121,50 @@ return this.addEffect(mobeffect, (Entity) null); } @@ -291,6 +287,7 @@ this.activeEffects.put(mobeffect.getEffect(), mobeffect); this.onEffectAdded(mobeffect, entity); flag = true; + mobeffect.onEffectAdded(this); - } else if (mobeffect1.update(mobeffect)) { + // CraftBukkit start + } else if (event.isOverride()) { @@ -300,24 +297,24 @@ flag = true; } -@@ -1025,13 +1180,39 @@ - return this.getMobType() == EnumMonsterType.UNDEAD; +@@ -1040,13 +1195,39 @@ + return this.getType().is(TagsEntity.INVERTED_HEALING_AND_HARM); } + // CraftBukkit start @Nullable - public MobEffect removeEffectNoUpdate(@Nullable MobEffectList mobeffectlist) { -+ return c(mobeffectlist, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN); + public MobEffect removeEffectNoUpdate(Holder holder) { ++ return removeEffectNoUpdate(holder, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN); + } + + @Nullable -+ public MobEffect c(@Nullable MobEffectList mobeffectlist, EntityPotionEffectEvent.Cause cause) { ++ public MobEffect removeEffectNoUpdate(Holder holder, EntityPotionEffectEvent.Cause cause) { + if (isTickingEffects) { -+ effectsToProcess.add(new ProcessableEffect(mobeffectlist, cause)); ++ effectsToProcess.add(new ProcessableEffect(holder, cause)); + return null; + } + -+ MobEffect effect = this.activeEffects.get(mobeffectlist); ++ MobEffect effect = this.activeEffects.get(holder); + if (effect == null) { + return null; + } @@ -327,21 +324,21 @@ + return null; + } + - return (MobEffect) this.activeEffects.remove(mobeffectlist); + return (MobEffect) this.activeEffects.remove(holder); } - public boolean removeEffect(MobEffectList mobeffectlist) { -- MobEffect mobeffect = this.removeEffectNoUpdate(mobeffectlist); -+ return removeEffect(mobeffectlist, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN); + public boolean removeEffect(Holder holder) { +- MobEffect mobeffect = this.removeEffectNoUpdate(holder); ++ return removeEffect(holder, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.UNKNOWN); + } + -+ public boolean removeEffect(MobEffectList mobeffectlist, EntityPotionEffectEvent.Cause cause) { -+ MobEffect mobeffect = this.c(mobeffectlist, cause); ++ public boolean removeEffect(Holder holder, EntityPotionEffectEvent.Cause cause) { ++ MobEffect mobeffect = this.removeEffectNoUpdate(holder, cause); + // CraftBukkit end if (mobeffect != null) { this.onEffectRemoved(mobeffect); -@@ -1129,20 +1310,55 @@ +@@ -1142,20 +1323,55 @@ } @@ -398,7 +395,7 @@ this.entityData.set(EntityLiving.DATA_HEALTH_ID, MathHelper.clamp(f, 0.0F, this.getMaxHealth())); } -@@ -1156,7 +1372,7 @@ +@@ -1169,7 +1385,7 @@ return false; } else if (this.level().isClientSide) { return false; @@ -407,7 +404,7 @@ return false; } else if (damagesource.is(DamageTypeTags.IS_FIRE) && this.hasEffect(MobEffects.FIRE_RESISTANCE)) { return false; -@@ -1167,10 +1383,11 @@ +@@ -1180,10 +1396,11 @@ this.noActionTime = 0; float f1 = f; @@ -421,7 +418,17 @@ this.hurtCurrentlyUsedShield(f); f2 = f; f = 0.0F; -@@ -1194,23 +1411,33 @@ +@@ -1204,7 +1421,8 @@ + f *= 5.0F; + } + +- if (damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) { ++ // CraftBukkit - Moved into actuallyHurt(DamageSource, float) ++ if (false && damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) { + this.hurtHelmet(damagesource, f); + f *= 0.75F; + } +@@ -1212,18 +1430,27 @@ this.walkAnimation.setSpeed(1.5F); boolean flag1 = true; @@ -453,14 +460,7 @@ this.hurtDuration = 10; this.hurtTime = this.hurtDuration; } - -- if (damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) { -+ // CraftBukkit - Moved into actuallyHurt(DamageSource, float) -+ if (false && damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) { - this.hurtHelmet(damagesource, f); - f *= 0.75F; - } -@@ -1269,7 +1496,7 @@ +@@ -1282,7 +1509,7 @@ d0 = (Math.random() - Math.random()) * 0.01D; } @@ -469,7 +469,7 @@ if (!flag) { this.indicateDamage(d0, d1); } -@@ -1317,7 +1544,7 @@ +@@ -1335,7 +1562,7 @@ } protected void blockedByShield(EntityLiving entityliving) { @@ -478,7 +478,7 @@ } private boolean checkTotemDeathProtection(DamageSource damagesource) { -@@ -1328,19 +1555,32 @@ +@@ -1346,19 +1573,32 @@ EnumHand[] aenumhand = EnumHand.values(); int i = aenumhand.length; @@ -515,7 +515,7 @@ EntityPlayer entityplayer = (EntityPlayer) this; entityplayer.awardStat(StatisticList.ITEM_USED.get(Items.TOTEM_OF_UNDYING)); -@@ -1349,14 +1589,16 @@ +@@ -1367,14 +1607,16 @@ } this.setHealth(1.0F); @@ -537,7 +537,7 @@ } } -@@ -1463,14 +1705,22 @@ +@@ -1481,14 +1723,22 @@ IBlockData iblockdata = Blocks.WITHER_ROSE.defaultBlockState(); if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) { @@ -562,7 +562,7 @@ this.level().addFreshEntity(entityitem); } } -@@ -1490,21 +1740,40 @@ +@@ -1508,21 +1758,40 @@ boolean flag = this.lastHurtByPlayerTime > 0; @@ -606,7 +606,7 @@ } -@@ -1533,13 +1802,25 @@ +@@ -1551,13 +1820,25 @@ } public void knockback(double d0, double d1, double d2) { @@ -635,7 +635,7 @@ } } -@@ -1596,6 +1877,28 @@ +@@ -1614,6 +1895,28 @@ return itemstack.getEatingSound(); } @@ -664,7 +664,7 @@ public Optional getLastClimbablePos() { return this.lastClimbablePos; } -@@ -1642,9 +1945,14 @@ +@@ -1669,9 +1972,14 @@ int i = this.calculateFallDamage(f, f1); if (i > 0) { @@ -680,16 +680,16 @@ return true; } else { return flag; -@@ -1696,7 +2004,7 @@ +@@ -1741,7 +2049,7 @@ protected float getDamageAfterArmorAbsorb(DamageSource damagesource, float f) { if (!damagesource.is(DamageTypeTags.BYPASSES_ARMOR)) { - this.hurtArmor(damagesource, f); + // this.hurtArmor(damagesource, f); // CraftBukkit - Moved into actuallyHurt(DamageSource, float) - f = CombatMath.getDamageAfterAbsorb(f, (float) this.getArmorValue(), (float) this.getAttributeValue(GenericAttributes.ARMOR_TOUGHNESS)); + f = CombatMath.getDamageAfterAbsorb(f, damagesource, (float) this.getArmorValue(), (float) this.getAttributeValue(GenericAttributes.ARMOR_TOUGHNESS)); } -@@ -1709,7 +2017,8 @@ +@@ -1754,7 +2062,8 @@ } else { int i; @@ -699,7 +699,7 @@ i = (this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5; int j = 25 - i; float f1 = f * (float) j; -@@ -1742,16 +2051,125 @@ +@@ -1787,16 +2096,125 @@ } } @@ -746,7 +746,7 @@ + }; + float armorModifier = armor.apply((double) f).floatValue(); + f += armorModifier; -+ + + Function resistance = new Function() { + @Override + public Double apply(Double f) { @@ -805,7 +805,7 @@ + if (damagesource.is(DamageTypeTags.DAMAGES_HELMET) && !this.getItemBySlot(EnumItemSlot.HEAD).isEmpty()) { + this.hurtHelmet(damagesource, f); + } - ++ + // Apply damage to armor + if (!damagesource.is(DamageTypeTags.BYPASSES_ARMOR)) { + float armorDamage = (float) (event.getDamage() + event.getDamage(DamageModifier.BLOCKING) + event.getDamage(DamageModifier.HARD_HAT)); @@ -833,7 +833,7 @@ if (f2 > 0.0F && f2 < 3.4028235E37F) { Entity entity = damagesource.getEntity(); -@@ -1762,13 +2180,47 @@ +@@ -1807,13 +2225,47 @@ } } @@ -883,7 +883,7 @@ } public CombatTracker getCombatTracker() { -@@ -1793,8 +2245,18 @@ +@@ -1838,8 +2290,18 @@ } public final void setArrowCount(int i) { @@ -903,7 +903,7 @@ public final int getStingerCount() { return (Integer) this.entityData.get(EntityLiving.DATA_STINGER_COUNT_ID); -@@ -2036,6 +2498,12 @@ +@@ -2075,6 +2537,12 @@ public abstract ItemStack getItemBySlot(EnumItemSlot enumitemslot); @@ -913,10 +913,10 @@ + } + // CraftBukkit end + - @Override public abstract void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack); -@@ -2270,6 +2738,7 @@ + public Iterable getHandSlots() { +@@ -2328,6 +2796,7 @@ } if (this.onGround() && !this.level().isClientSide) { @@ -924,7 +924,7 @@ this.setSharedFlag(7, false); } } else { -@@ -2440,7 +2909,7 @@ +@@ -2498,7 +2967,7 @@ } } @@ -933,8 +933,8 @@ if (this.tickCount % 20 == 0) { this.getCombatTracker().recheckStatus(); } -@@ -2537,7 +3006,7 @@ - this.refreshDirtyAttributes(); +@@ -2602,7 +3071,7 @@ + } - public void detectEquipmentUpdates() { @@ -942,7 +942,7 @@ Map map = this.collectEquipmentChanges(); if (map != null) { -@@ -2839,6 +3308,7 @@ +@@ -2924,6 +3393,7 @@ } if (!this.level().isClientSide) { @@ -950,7 +950,7 @@ this.setSharedFlag(7, flag); } -@@ -3029,14 +3499,21 @@ +@@ -3114,14 +3584,21 @@ @Override public boolean isPickable() { @@ -974,7 +974,7 @@ @Override public float getYHeadRot() { return this.yHeadRot; -@@ -3231,7 +3708,26 @@ +@@ -3314,7 +3791,26 @@ } else { if (!this.useItem.isEmpty() && this.isUsingItem()) { this.triggerItemUseEffects(this.useItem, 16); @@ -1002,7 +1002,7 @@ if (itemstack != this.useItem) { this.setItemInHand(enumhand, itemstack); -@@ -3309,6 +3805,12 @@ +@@ -3392,6 +3888,12 @@ } public boolean randomTeleport(double d0, double d1, double d2, boolean flag) { @@ -1015,7 +1015,7 @@ double d3 = this.getX(); double d4 = this.getY(); double d5 = this.getZ(); -@@ -3333,16 +3835,41 @@ +@@ -3416,16 +3918,41 @@ } if (flag2) { @@ -1060,7 +1060,7 @@ } else { if (flag) { world.broadcastEntityEvent(this, (byte) 46); -@@ -3354,7 +3881,7 @@ +@@ -3437,7 +3964,7 @@ entitycreature.getNavigation().stop(); } @@ -1069,7 +1069,7 @@ } } -@@ -3443,7 +3970,7 @@ +@@ -3530,7 +4057,7 @@ } public void stopSleeping() { @@ -1078,7 +1078,7 @@ World world = this.level(); java.util.Objects.requireNonNull(world); -@@ -3477,7 +4004,7 @@ +@@ -3564,7 +4091,7 @@ @Nullable public EnumDirection getBedOrientation() { @@ -1087,12 +1087,12 @@ return blockposition != null ? BlockBed.getBedOrientation(this.level(), blockposition) : null; } -@@ -3525,7 +4052,7 @@ - Pair pair = (Pair) iterator.next(); +@@ -3600,7 +4127,7 @@ + FoodInfo.b foodinfo_b = (FoodInfo.b) iterator.next(); - if (!world.isClientSide && pair.getFirst() != null && world.random.nextFloat() < (Float) pair.getSecond()) { -- entityliving.addEffect(new MobEffect((MobEffect) pair.getFirst())); -+ entityliving.addEffect(new MobEffect((MobEffect) pair.getFirst()), EntityPotionEffectEvent.Cause.FOOD); // CraftBukkit + 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/EntityTypes.patch b/paper-server/nms-patches/net/minecraft/world/entity/EntityTypes.patch index 7ec6526629..f07ee72677 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/EntityTypes.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/EntityTypes.patch @@ -1,24 +1,24 @@ --- a/net/minecraft/world/entity/EntityTypes.java +++ b/net/minecraft/world/entity/EntityTypes.java -@@ -160,6 +160,7 @@ - import net.minecraft.world.phys.AxisAlignedBB; +@@ -168,6 +168,7 @@ + import net.minecraft.world.phys.Vec3D; import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapes; +import org.bukkit.event.entity.CreatureSpawnEvent; import org.slf4j.Logger; public class EntityTypes implements FeatureElement, EntityTypeTest { -@@ -170,7 +171,7 @@ - private static final float MAGIC_HORSE_WIDTH = 1.3964844F; +@@ -178,7 +179,7 @@ private static final int DISPLAY_TRACKING_RANGE = 10; - public static final EntityTypes ALLAY = register("allay", EntityTypes.Builder.of(Allay::new, EnumCreatureType.CREATURE).sized(0.35F, 0.6F).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 ARMOR_STAND = register("armor_stand", EntityTypes.Builder.of(EntityArmorStand::new, EnumCreatureType.MISC).sized(0.5F, 1.975F).clientTrackingRange(10)); - public static final EntityTypes ARROW = register("arrow", EntityTypes.Builder.of(EntityTippedArrow::new, EnumCreatureType.MISC).sized(0.5F, 0.5F).clientTrackingRange(4).updateInterval(20)); - public static final EntityTypes AXOLOTL = register("axolotl", EntityTypes.Builder.of(Axolotl::new, EnumCreatureType.AXOLOTLS).sized(0.75F, 0.42F).clientTrackingRange(10)); -@@ -313,8 +314,8 @@ - private final EntitySize dimensions; + 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 ARMADILLO = register("armadillo", EntityTypes.Builder.of(Armadillo::new, EnumCreatureType.CREATURE).sized(0.7F, 0.65F).eyeHeight(0.26F).clientTrackingRange(10)); ++ public static final EntityTypes ARMADILLO = register("armadillo", EntityTypes.Builder.of(Armadillo::new, EnumCreatureType.CREATURE).sized(0.7F, 0.65F).eyeHeight(0.26F).clientTrackingRange(10).updateInterval(10)); // CraftBukkit - SPIGOT-3729: track area effect clouds + 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)); + public static final EntityTypes AXOLOTL = register("axolotl", EntityTypes.Builder.of(Axolotl::new, EnumCreatureType.AXOLOTLS).sized(0.75F, 0.42F).eyeHeight(0.2751F).clientTrackingRange(10)); +@@ -325,8 +326,8 @@ + private final float spawnDimensionsScale; private final FeatureFlagSet requiredFeatures; - private static EntityTypes register(String s, EntityTypes.Builder entitytypes_builder) { @@ -28,10 +28,11 @@ } public static MinecraftKey getKey(EntityTypes entitytypes) { -@@ -342,8 +343,15 @@ +@@ -355,7 +356,14 @@ @Nullable public T spawn(WorldServer worldserver, @Nullable ItemStack itemstack, @Nullable EntityHuman entityhuman, BlockPosition blockposition, EnumMobSpawn enummobspawn, 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); + } @@ -39,53 +40,51 @@ + @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) { + // CraftBukkit end - NBTTagCompound nbttagcompound; -- Consumer consumer; + Consumer consumer; // CraftBukkit - decompile error if (itemstack != null) { - nbttagcompound = itemstack.getTag(); -@@ -354,7 +362,7 @@ - nbttagcompound = null; + consumer = createDefaultStackConfig(worldserver, itemstack, entityhuman); +@@ -364,7 +372,7 @@ + }; } -- return this.spawn(worldserver, nbttagcompound, consumer, blockposition, enummobspawn, flag, flag1); -+ return this.spawn(worldserver, nbttagcompound, consumer, blockposition, enummobspawn, flag, flag1, spawnReason); // CraftBukkit +- return this.spawn(worldserver, consumer, blockposition, enummobspawn, flag, flag1); ++ return this.spawn(worldserver, consumer, blockposition, enummobspawn, flag, flag1, spawnReason); // CraftBukkit } public static Consumer createDefaultStackConfig(WorldServer worldserver, ItemStack itemstack, @Nullable EntityHuman entityhuman) { -@@ -376,21 +384,37 @@ - NBTTagCompound nbttagcompound = itemstack.getTag(); +@@ -388,21 +396,37 @@ + CustomData customdata = (CustomData) itemstack.getOrDefault(DataComponents.ENTITY_DATA, CustomData.EMPTY); - return nbttagcompound != null ? consumer.andThen((entity) -> { -- updateCustomEntityTag(worldserver, entityhuman, entity, nbttagcompound); -+ try { updateCustomEntityTag(worldserver, entityhuman, entity, nbttagcompound); } catch (Throwable t) { LOGGER.warn("Error loading spawn egg NBT", t); } // CraftBukkit - SPIGOT-5665 + 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 }) : consumer; } @Nullable public T spawn(WorldServer worldserver, BlockPosition blockposition, EnumMobSpawn enummobspawn) { -- return this.spawn(worldserver, (NBTTagCompound) null, (Consumer) null, blockposition, enummobspawn, false, false); +- return this.spawn(worldserver, (Consumer) null, blockposition, enummobspawn, false, false); + // CraftBukkit start + return this.spawn(worldserver, blockposition, enummobspawn, 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, (NBTTagCompound) null, null, blockposition, enummobspawn, false, false, spawnReason); // CraftBukkit - decompile error ++ return this.spawn(worldserver, (Consumer) null, blockposition, enummobspawn, false, false, spawnReason); // CraftBukkit - decompile error + // CraftBukkit end } @Nullable - public T spawn(WorldServer worldserver, @Nullable NBTTagCompound nbttagcompound, @Nullable Consumer consumer, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1) { + public T spawn(WorldServer worldserver, @Nullable Consumer consumer, BlockPosition blockposition, EnumMobSpawn enummobspawn, boolean flag, boolean flag1) { + // CraftBukkit start -+ return this.spawn(worldserver, nbttagcompound, consumer, blockposition, enummobspawn, flag, flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT); ++ return this.spawn(worldserver, consumer, blockposition, enummobspawn, flag, flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT); + } + + @Nullable -+ public T spawn(WorldServer worldserver, @Nullable NBTTagCompound nbttagcompound, @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, EnumMobSpawn enummobspawn, boolean flag, boolean flag1, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) { + // CraftBukkit end - T t0 = this.create(worldserver, nbttagcompound, consumer, blockposition, enummobspawn, flag, flag1); + T t0 = this.create(worldserver, consumer, blockposition, enummobspawn, flag, flag1); if (t0 != null) { - worldserver.addFreshEntityWithPassengers(t0); @@ -95,7 +94,7 @@ } return t0; -@@ -577,7 +601,7 @@ +@@ -583,7 +607,7 @@ } return entity; @@ -104,7 +103,7 @@ } public static Stream loadEntitiesRecursive(final List list, final World world) { -@@ -638,7 +662,7 @@ +@@ -644,7 +668,7 @@ @Nullable public T tryCast(Entity entity) { @@ -113,7 +112,7 @@ } @Override -@@ -673,7 +697,7 @@ +@@ -681,7 +705,7 @@ this.canSpawnFarFromPlayer = enumcreaturetype == EnumCreatureType.CREATURE || enumcreaturetype == EnumCreatureType.MISC; } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/IEntityAngerable.patch b/paper-server/nms-patches/net/minecraft/world/entity/IEntityAngerable.patch index 902b88e16e..1570a962cb 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/IEntityAngerable.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/IEntityAngerable.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/IEntityAngerable.java +++ b/net/minecraft/world/entity/IEntityAngerable.java -@@ -108,7 +108,7 @@ +@@ -114,7 +114,7 @@ default void stopBeingAngry() { this.setLastHurtByMob((EntityLiving) null); this.setPersistentAngerTarget((UUID) null); @@ -9,7 +9,7 @@ this.setRemainingPersistentAngerTime(0); } -@@ -121,6 +121,8 @@ +@@ -127,6 +127,8 @@ void setTarget(@Nullable EntityLiving entityliving); 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 717ba74985..230f95fb0d 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/Interaction.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/Interaction.patch @@ -22,10 +22,10 @@ Logger logger; if (nbttagcompound.contains("attack")) { -@@ -143,12 +149,19 @@ +@@ -142,9 +148,16 @@ + @Override public boolean skipAttackInteraction(Entity entity) { - if (entity instanceof EntityHuman) { - EntityHuman entityhuman = (EntityHuman) entity; + if (entity instanceof EntityHuman entityhuman) { + // CraftBukkit start + DamageSource source = entityhuman.damageSources().playerAttack(entityhuman); + EntityDamageEvent event = CraftEventFactory.callNonLivingEntityDamageEvent(this, source, 1.0F, false); @@ -33,11 +33,8 @@ + return true; + } + // CraftBukkit end - this.attack = new Interaction.PlayerAction(entityhuman.getUUID(), this.level().getGameTime()); - if (entityhuman instanceof EntityPlayer) { - EntityPlayer entityplayer = (EntityPlayer) entityhuman; - + if (entityhuman instanceof EntityPlayer entityplayer) { - CriterionTriggers.PLAYER_HURT_ENTITY.trigger(entityplayer, this, entityhuman.damageSources().generic(), 1.0F, 1.0F, false); + CriterionTriggers.PLAYER_HURT_ENTITY.trigger(entityplayer, this, source, (float) event.getFinalDamage(), 1.0F, false); // CraftBukkit } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/attributes/GenericAttributes.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/attributes/GenericAttributes.patch index c44303ee46..034aac95ab 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/attributes/GenericAttributes.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/attributes/GenericAttributes.patch @@ -4,4 +4,4 @@ +// mc-dev import package net.minecraft.world.entity.ai.attributes; - import net.minecraft.core.IRegistry; + import net.minecraft.core.Holder; diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorFarm.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorFarm.patch index 98ac31afba..b02f71bc72 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorFarm.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorFarm.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/ai/behavior/BehaviorFarm.java +++ b/net/minecraft/world/entity/ai/behavior/BehaviorFarm.java -@@ -26,6 +26,11 @@ +@@ -27,6 +27,11 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.gameevent.GameEvent; @@ -12,7 +12,7 @@ public class BehaviorFarm extends Behavior { private static final int HARVEST_DURATION = 200; -@@ -81,8 +86,8 @@ +@@ -82,8 +87,8 @@ protected void start(WorldServer worldserver, EntityVillager entityvillager, long i) { if (i > this.nextOkStartTime && this.aboveFarmlandPos != null) { @@ -23,7 +23,7 @@ } } -@@ -102,7 +107,9 @@ +@@ -103,7 +108,9 @@ Block block1 = worldserver.getBlockState(this.aboveFarmlandPos.below()).getBlock(); if (block instanceof BlockCrops && ((BlockCrops) block).isMaxAge(iblockdata)) { @@ -33,19 +33,19 @@ } if (iblockdata.isAir() && block1 instanceof BlockSoil && entityvillager.hasFarmSeeds()) { -@@ -119,9 +126,11 @@ +@@ -120,9 +127,11 @@ ItemBlock itemblock = (ItemBlock) item; IBlockData iblockdata1 = itemblock.getBlock().defaultBlockState(); + if (CraftEventFactory.callEntityChangeBlockEvent(entityvillager, this.aboveFarmlandPos, iblockdata1)) { // CraftBukkit worldserver.setBlockAndUpdate(this.aboveFarmlandPos, iblockdata1); - worldserver.gameEvent(GameEvent.BLOCK_PLACE, this.aboveFarmlandPos, GameEvent.a.of(entityvillager, iblockdata1)); + worldserver.gameEvent((Holder) GameEvent.BLOCK_PLACE, this.aboveFarmlandPos, GameEvent.a.of(entityvillager, iblockdata1)); flag = true; + } // CraftBukkit } } -@@ -141,8 +150,8 @@ +@@ -142,8 +151,8 @@ this.aboveFarmlandPos = this.getValidFarmland(worldserver); if (this.aboveFarmlandPos != null) { this.nextOkStartTime = i + 20L; diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorMakeLove.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorMakeLove.patch index 7599010630..b8033a44c4 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorMakeLove.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorMakeLove.patch @@ -11,8 +11,8 @@ + public class BehaviorMakeLove extends Behavior { - private static final int INTERACT_DIST_SQR = 5; -@@ -116,11 +121,17 @@ + private long birthTimestamp; +@@ -114,11 +119,17 @@ if (entityvillager2 == null) { return Optional.empty(); } else { @@ -33,7 +33,7 @@ worldserver.broadcastEntityEvent(entityvillager2, (byte) 12); return Optional.of(entityvillager2); } -@@ -129,6 +140,6 @@ +@@ -127,6 +138,6 @@ private void giveBedToChild(WorldServer worldserver, EntityVillager entityvillager, BlockPosition blockposition) { GlobalPos globalpos = GlobalPos.of(worldserver.dimension(), blockposition); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorUtil.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorUtil.patch index 246146ed44..ffcb48472a 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorUtil.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorUtil.patch @@ -8,8 +8,8 @@ + entityliving.getBrain().setMemory(MemoryModuleType.LOOK_TARGET, (new BehaviorPositionEntity(entityliving1, true))); // CraftBukkit - decompile error } - private static void setWalkAndLookTargetMemoriesToEachOther(EntityLiving entityliving, EntityLiving entityliving1, float f) { -@@ -81,8 +81,8 @@ + private static void setWalkAndLookTargetMemoriesToEachOther(EntityLiving entityliving, EntityLiving entityliving1, float f, int i) { +@@ -79,8 +79,8 @@ public static void setWalkAndLookTargetMemories(EntityLiving entityliving, BehaviorPosition behaviorposition, float f, int i) { MemoryTarget memorytarget = new MemoryTarget(behaviorposition, f, i); @@ -20,7 +20,7 @@ } public static void throwItem(EntityLiving entityliving, ItemStack itemstack, Vec3D vec3d) { -@@ -92,6 +92,7 @@ +@@ -90,6 +90,7 @@ } public static void throwItem(EntityLiving entityliving, ItemStack itemstack, Vec3D vec3d, Vec3D vec3d1, float f) { @@ -28,7 +28,7 @@ double d0 = entityliving.getEyeY() - (double) f; EntityItem entityitem = new EntityItem(entityliving.level(), entityliving.getX(), d0, entityliving.getZ(), itemstack); -@@ -101,12 +102,19 @@ +@@ -99,12 +100,19 @@ vec3d2 = vec3d2.normalize().multiply(vec3d1.x, vec3d1.y, vec3d1.z); entityitem.setDeltaMovement(vec3d2); entityitem.setDefaultPickUpDelay(); 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 904dd8f58a..822fafa21f 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/ai/behavior/PrepareRamNearestTarget.java +++ b/net/minecraft/world/entity/ai/behavior/PrepareRamNearestTarget.java -@@ -30,6 +30,13 @@ +@@ -31,6 +31,13 @@ import net.minecraft.world.level.pathfinder.PathfinderNormal; import net.minecraft.world.phys.Vec3D; @@ -14,7 +14,7 @@ public class PrepareRamNearestTarget extends Behavior { public static final int TIME_OUT_DURATION = 160; -@@ -62,6 +69,13 @@ +@@ -63,6 +70,13 @@ return this.ramTargeting.test(entitycreature, entityliving); }); }).ifPresent((entityliving) -> { @@ -28,7 +28,7 @@ this.chooseRamPosition(entitycreature, entityliving); }); } -@@ -71,7 +85,7 @@ +@@ -72,7 +86,7 @@ if (!behaviorcontroller.hasMemoryValue(MemoryModuleType.RAM_TARGET)) { worldserver.broadcastEntityEvent(e0, (byte) 59); @@ -37,7 +37,7 @@ } } -@@ -82,8 +96,8 @@ +@@ -83,8 +97,8 @@ protected void tick(WorldServer worldserver, E e0, long i) { if (!this.ramCandidate.isEmpty()) { @@ -48,7 +48,7 @@ boolean flag = !((PrepareRamNearestTarget.a) this.ramCandidate.get()).getTarget().blockPosition().equals(((PrepareRamNearestTarget.a) this.ramCandidate.get()).getTargetPosition()); if (flag) { -@@ -100,7 +114,7 @@ +@@ -101,7 +115,7 @@ } if (i - (Long) this.reachedRamPositionTimestamp.get() >= (long) this.ramPrepareTime) { @@ -57,7 +57,7 @@ worldserver.playSound((EntityHuman) null, (Entity) e0, (SoundEffect) this.getPrepareRamSound.apply(e0), SoundCategory.NEUTRAL, 1.0F, e0.getVoicePitch()); this.ramCandidate = Optional.empty(); } -@@ -152,7 +166,7 @@ +@@ -153,7 +167,7 @@ } NavigationAbstract navigationabstract = entitycreature.getNavigation(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/TryLaySpawnOnWaterNearLand.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/TryLaySpawnOnWaterNearLand.patch index 6dda67cf74..e8c12b0853 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/TryLaySpawnOnWaterNearLand.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/TryLaySpawnOnWaterNearLand.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/ai/behavior/TryLaySpawnOnWaterNearLand.java +++ b/net/minecraft/world/entity/ai/behavior/TryLaySpawnOnWaterNearLand.java -@@ -38,6 +38,12 @@ +@@ -39,6 +39,12 @@ if (worldserver.getBlockState(blockposition2).isAir()) { IBlockData iblockdata = block.defaultBlockState(); @@ -11,5 +11,5 @@ + } + // CraftBukkit end worldserver.setBlock(blockposition2, iblockdata, 3); - worldserver.gameEvent(GameEvent.BLOCK_PLACE, blockposition2, GameEvent.a.of(entityliving, iblockdata)); + worldserver.gameEvent((Holder) GameEvent.BLOCK_PLACE, blockposition2, GameEvent.a.of(entityliving, iblockdata)); worldserver.playSound((EntityHuman) null, (Entity) entityliving, SoundEffects.FROG_LAY_SPAWN, SoundCategory.BLOCKS, 1.0F, 1.0F); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalFollowOwner.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalFollowOwner.patch index 096124f0b9..b27e8ae157 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalFollowOwner.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/goal/PathfinderGoalFollowOwner.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/ai/goal/PathfinderGoalFollowOwner.java +++ b/net/minecraft/world/entity/ai/goal/PathfinderGoalFollowOwner.java -@@ -14,6 +14,12 @@ +@@ -15,6 +15,12 @@ import net.minecraft.world.level.pathfinder.PathType; import net.minecraft.world.level.pathfinder.PathfinderNormal; @@ -13,7 +13,7 @@ public class PathfinderGoalFollowOwner extends PathfinderGoal { public static final int TELEPORT_WHEN_DISTANCE_IS = 12; -@@ -122,7 +128,14 @@ +@@ -123,7 +129,14 @@ } else if (!this.canTeleportTo(new BlockPosition(i, j, k))) { return false; } else { 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 c8ddbaec1c..060e890547 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,7 +1,7 @@ --- a/net/minecraft/world/entity/ai/goal/PathfinderGoalRemoveBlock.java +++ b/net/minecraft/world/entity/ai/goal/PathfinderGoalRemoveBlock.java @@ -21,6 +21,11 @@ - import net.minecraft.world.level.chunk.IChunkAccess; + import net.minecraft.world.level.chunk.status.ChunkStatus; import net.minecraft.world.phys.Vec3D; +// CraftBukkit start 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 2d265cb8c5..f47a666e9a 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,8 +1,8 @@ --- a/net/minecraft/world/entity/ai/goal/PathfinderGoalTempt.java +++ b/net/minecraft/world/entity/ai/goal/PathfinderGoalTempt.java -@@ -9,6 +9,13 @@ +@@ -10,6 +10,13 @@ import net.minecraft.world.entity.player.EntityHuman; - import net.minecraft.world.item.crafting.RecipeItemStack; + import net.minecraft.world.item.ItemStack; +// CraftBukkit start +import org.bukkit.craftbukkit.entity.CraftLivingEntity; @@ -14,7 +14,7 @@ public class PathfinderGoalTempt extends PathfinderGoal { private static final PathfinderTargetCondition TEMP_TARGETING = PathfinderTargetCondition.forNonCombat().range(10.0D).ignoreLineOfSight(); -@@ -21,7 +28,7 @@ +@@ -22,7 +29,7 @@ private double pRotX; private double pRotY; @Nullable @@ -22,8 +22,8 @@ + protected EntityLiving player; // CraftBukkit private int calmDown; private boolean isRunning; - private final RecipeItemStack items; -@@ -43,6 +50,15 @@ + private final Predicate items; +@@ -44,6 +51,15 @@ return false; } else { this.player = this.mob.level().getNearestPlayer(this.targetingConditions, this.mob); 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 414d830b7c..2301d3e948 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,8 +1,8 @@ --- a/net/minecraft/world/entity/ai/sensing/TemptingSensor.java +++ b/net/minecraft/world/entity/ai/sensing/TemptingSensor.java @@ -18,6 +18,14 @@ + import net.minecraft.world.entity.player.EntityHuman; import net.minecraft.world.item.ItemStack; - import net.minecraft.world.item.crafting.RecipeItemStack; +// CraftBukkit start +import org.bukkit.craftbukkit.entity.CraftHumanEntity; diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/village/VillageSiege.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/village/VillageSiege.patch index 59d73fb17b..e048e9d58c 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/village/VillageSiege.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/village/VillageSiege.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/ai/village/VillageSiege.java +++ b/net/minecraft/world/entity/ai/village/VillageSiege.java -@@ -122,7 +122,7 @@ +@@ -121,7 +121,7 @@ } entityzombie.moveTo(vec3d.x, vec3d.y, vec3d.z, worldserver.random.nextFloat() * 360.0F, 0.0F); 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 dfb7ac2bcc..3f575b8b51 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,6 +1,6 @@ --- a/net/minecraft/world/entity/ambient/EntityBat.java +++ b/net/minecraft/world/entity/ambient/EntityBat.java -@@ -29,6 +29,10 @@ +@@ -27,6 +27,10 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.phys.Vec3D; @@ -11,7 +11,7 @@ public class EntityBat extends EntityAmbient { public static final float FLAP_LENGTH_SECONDS = 0.5F; -@@ -143,13 +147,13 @@ +@@ -141,13 +145,13 @@ this.yHeadRot = (float) this.random.nextInt(360); } @@ -27,7 +27,7 @@ this.setResting(false); if (!flag) { this.level().levelEvent((EntityHuman) null, 1025, blockposition, 0); -@@ -176,7 +180,7 @@ +@@ -174,7 +178,7 @@ this.zza = 0.5F; this.setYRot(this.getYRot() + f1); @@ -36,7 +36,7 @@ this.setResting(true); } } -@@ -201,7 +205,7 @@ +@@ -199,7 +203,7 @@ if (this.isInvulnerableTo(damagesource)) { return false; } else { 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 2c9dc3c83a..8857dec070 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 @@ -1,7 +1,7 @@ --- a/net/minecraft/world/entity/animal/Bucketable.java +++ b/net/minecraft/world/entity/animal/Bucketable.java -@@ -15,6 +15,15 @@ - import net.minecraft.world.item.Items; +@@ -17,6 +17,15 @@ + import net.minecraft.world.item.component.CustomData; import net.minecraft.world.level.World; +// CraftBukkit start @@ -16,7 +16,7 @@ public interface Bucketable { boolean fromBucket(); -@@ -94,10 +103,22 @@ +@@ -93,10 +102,22 @@ ItemStack itemstack = entityhuman.getItemInHand(enumhand); if (itemstack.getItem() == Items.WATER_BUCKET && t0.isAlive()) { @@ -32,7 +32,7 @@ + if (playerBucketFishEvent.isCancelled()) { + ((EntityPlayer) entityhuman).containerMenu.sendAllDataToRemote(); // We need to update inventory to resync client's bucket + ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutSpawnEntity(t0)); // We need to play out these packets as the client assumes the fish is gone -+ t0.getEntityData().refresh((EntityPlayer) entityhuman); // Need to send data such as the display name to client ++ t0.refreshEntityData((EntityPlayer) entityhuman); // Need to send data such as the display name to client + return Optional.of(EnumInteractionResult.FAIL); + } + t0.playSound(((Bucketable) t0).getPickupSound(), 1.0F, 1.0F); @@ -40,7 +40,7 @@ ItemStack itemstack2 = ItemLiquidUtil.createFilledResult(itemstack, entityhuman, itemstack1, false); entityhuman.setItemInHand(enumhand, itemstack2); -@@ -107,7 +128,7 @@ +@@ -106,7 +127,7 @@ CriterionTriggers.FILLED_BUCKET.trigger((EntityPlayer) entityhuman, itemstack1); } 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 f9b7960cb5..556440d430 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 -@@ -30,12 +30,19 @@ +@@ -29,12 +29,19 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.pathfinder.PathType; @@ -20,22 +20,25 @@ protected EntityAnimal(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -77,8 +84,13 @@ - if (this.isInvulnerableTo(damagesource)) { - return false; - } else { -+ // CraftBukkit start -+ boolean result = super.hurt(damagesource, f); -+ if (result) { - this.inLove = 0; -- return super.hurt(damagesource, f); -+ } -+ return result; -+ // CraftBukkit end - } +@@ -72,9 +79,15 @@ } -@@ -172,10 +184,17 @@ + @Override +- protected void actuallyHurt(DamageSource damagesource, float f) { ++ // CraftBukkit start - void -> boolean ++ public boolean actuallyHurt(DamageSource damagesource, float f) { ++ boolean result = super.actuallyHurt(damagesource, f); ++ if (!result) { ++ return result; ++ } + this.resetLove(); +- super.actuallyHurt(damagesource, f); ++ return result; ++ // CraftBukkit end + } + + @Override +@@ -162,10 +175,17 @@ } public void setInLove(@Nullable EntityHuman entityhuman) { @@ -54,7 +57,7 @@ this.level().broadcastEntityEvent(this, (byte) 18); } -@@ -217,12 +236,29 @@ +@@ -207,12 +227,29 @@ if (entityageable != null) { entityageable.setBaby(true); entityageable.moveTo(this.getX(), this.getY(), this.getZ(), 0.0F, 0.0F); @@ -86,7 +89,7 @@ Optional.ofNullable(this.getLoveCause()).or(() -> { return Optional.ofNullable(entityanimal.getLoveCause()); }).ifPresent((entityplayer) -> { -@@ -235,7 +271,11 @@ +@@ -225,7 +262,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 88399604e3..0aff7f7538 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 -@@ -90,6 +90,12 @@ +@@ -86,6 +86,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; -@@ -187,12 +193,19 @@ +@@ -185,12 +191,19 @@ @Override public void addAdditionalSaveData(NBTTagCompound nbttagcompound) { @@ -27,15 +27,26 @@ super.addAdditionalSaveData(nbttagcompound); - if (this.hasHive()) { + if (includeAll && this.hasHive()) { // CraftBukkit - selectively save hive - nbttagcompound.put("HivePos", GameProfileSerializer.writeBlockPos(this.getHivePos())); + nbttagcompound.put("hive_pos", GameProfileSerializer.writeBlockPos(this.getHivePos())); } - if (this.hasSavedFlowerPos()) { + if (includeAll && this.hasSavedFlowerPos()) { // CraftBukkit - selectively save flower - nbttagcompound.put("FlowerPos", GameProfileSerializer.writeBlockPos(this.getSavedFlowerPos())); + nbttagcompound.put("flower_pos", GameProfileSerializer.writeBlockPos(this.getSavedFlowerPos())); } -@@ -242,7 +255,7 @@ +@@ -204,8 +217,8 @@ + + @Override + public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { +- 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")); +@@ -232,7 +245,7 @@ } if (b0 > 0) { @@ -44,7 +55,7 @@ } } -@@ -640,11 +653,14 @@ +@@ -625,11 +638,14 @@ if (this.isInvulnerableTo(damagesource)) { return false; } else { @@ -61,7 +72,7 @@ } } -@@ -999,7 +1015,7 @@ +@@ -981,7 +997,7 @@ e() { super(); @@ -70,7 +81,7 @@ this.blacklistedTargets = Lists.newArrayList(); this.setFlags(EnumSet.of(PathfinderGoal.Type.MOVE)); } -@@ -1116,7 +1132,7 @@ +@@ -1098,7 +1114,7 @@ f() { super(); @@ -79,16 +90,16 @@ this.setFlags(EnumSet.of(PathfinderGoal.Type.MOVE)); } -@@ -1216,7 +1232,7 @@ +@@ -1198,7 +1214,7 @@ } } - if (iblockdata1 != null) { + if (iblockdata1 != null && CraftEventFactory.callEntityChangeBlockEvent(EntityBee.this, blockposition, iblockdata1)) { // CraftBukkit - EntityBee.this.level().levelEvent(2005, blockposition, 0); + EntityBee.this.level().levelEvent(2011, blockposition, 15); EntityBee.this.level().setBlockAndUpdate(blockposition, iblockdata1); EntityBee.this.incrementNumCropsGrownSincePollination(); -@@ -1289,7 +1305,7 @@ +@@ -1271,7 +1287,7 @@ @Override protected void alertOther(EntityInsentient entityinsentient, EntityLiving entityliving) { if (entityinsentient instanceof EntityBee && this.mob.hasLineOfSight(entityliving)) { @@ -97,7 +108,7 @@ } } -@@ -1298,7 +1314,7 @@ +@@ -1280,7 +1296,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 5f15487654..0c0c7414ac 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,15 +1,28 @@ --- a/net/minecraft/world/entity/animal/EntityCat.java +++ b/net/minecraft/world/entity/animal/EntityCat.java -@@ -413,7 +413,7 @@ - } - } else if (this.isFood(itemstack)) { - this.usePlayerItem(entityhuman, enumhand, itemstack); -- if (this.random.nextInt(3) == 0) { -+ if (this.random.nextInt(3) == 0 && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) { // CraftBukkit - this.tame(entityhuman); - this.setOrderedToSit(true); - this.level().broadcastEntityEvent(this, (byte) 7); -@@ -475,7 +475,7 @@ +@@ -182,10 +182,10 @@ + @Override + public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { + super.readAdditionalSaveData(nbttagcompound); +- Optional optional = Optional.ofNullable(MinecraftKey.tryParse(nbttagcompound.getString("variant"))).map((minecraftkey) -> { ++ Optional> optional = Optional.ofNullable(MinecraftKey.tryParse(nbttagcompound.getString("variant"))).map((minecraftkey) -> { // CraftBukkit - decompile error + return ResourceKey.create(Registries.CAT_VARIANT, minecraftkey); + }); +- IRegistry iregistry = BuiltInRegistries.CAT_VARIANT; ++ IRegistry iregistry = BuiltInRegistries.CAT_VARIANT; // CraftBukkit - decompile error + + Objects.requireNonNull(iregistry); + optional.flatMap(iregistry::getHolder).ifPresent(this::setVariant); +@@ -462,7 +462,7 @@ + } + + private void tryToTame(EntityHuman entityhuman) { +- if (this.random.nextInt(3) == 0) { ++ if (this.random.nextInt(3) == 0 && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) { // CraftBukkit + this.tame(entityhuman); + this.setOrderedToSit(true); + this.level().broadcastEntityEvent(this, (byte) 7); +@@ -480,7 +480,7 @@ private static class PathfinderGoalTemptChance extends PathfinderGoalTempt { @Nullable @@ -17,8 +30,8 @@ + private EntityLiving selectedPlayer; // CraftBukkit private final EntityCat cat; - public PathfinderGoalTemptChance(EntityCat entitycat, double d0, RecipeItemStack recipeitemstack, boolean flag) { -@@ -616,7 +616,15 @@ + public PathfinderGoalTemptChance(EntityCat entitycat, double d0, Predicate predicate, boolean flag) { +@@ -621,7 +621,15 @@ while (iterator.hasNext()) { ItemStack itemstack = (ItemStack) iterator.next(); @@ -35,7 +48,7 @@ } } -@@ -648,10 +656,10 @@ +@@ -653,10 +661,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 30e374f7f8..3319415105 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,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntityChicken.java +++ b/net/minecraft/world/entity/animal/EntityChicken.java -@@ -97,7 +97,9 @@ +@@ -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); 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 c09b33ea87..40f3a47c00 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 @@ -1,8 +1,8 @@ --- a/net/minecraft/world/entity/animal/EntityCow.java +++ b/net/minecraft/world/entity/animal/EntityCow.java -@@ -33,6 +33,12 @@ +@@ -31,6 +31,12 @@ + import net.minecraft.world.level.World; import net.minecraft.world.level.block.state.IBlockData; - import org.joml.Vector3f; +// CraftBukkit start +import org.bukkit.craftbukkit.event.CraftEventFactory; @@ -12,8 +12,8 @@ + public class EntityCow extends EntityAnimal { - public EntityCow(EntityTypes entitytypes, World world) { -@@ -85,8 +91,16 @@ + private static final EntitySize BABY_DIMENSIONS = EntityTypes.COW.getDimensions().scale(0.5F).withEyeHeight(0.665F); +@@ -92,8 +98,16 @@ ItemStack itemstack = entityhuman.getItemInHand(enumhand); if (itemstack.is(Items.BUCKET) && !this.isBaby()) { 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 83f59f4eca..2ecffe142a 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 -@@ -61,8 +61,20 @@ +@@ -59,8 +59,20 @@ import net.minecraft.world.level.pathfinder.PathMode; import net.minecraft.world.phys.Vec3D; @@ -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); -@@ -185,7 +197,7 @@ +@@ -183,7 +195,7 @@ @Override public int getMaxAirSupply() { @@ -30,7 +30,7 @@ } @Override -@@ -226,11 +238,17 @@ +@@ -219,11 +231,17 @@ ItemStack itemstack = entityitem.getItem(); if (this.canHoldItem(itemstack)) { @@ -49,7 +49,7 @@ } } -@@ -484,7 +502,7 @@ +@@ -474,7 +492,7 @@ @Override public void start() { @@ -58,7 +58,7 @@ } @Override -@@ -503,7 +521,7 @@ +@@ -493,7 +511,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 837665f9a3..ef52d3da83 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,8 +1,8 @@ --- a/net/minecraft/world/entity/animal/EntityFox.java +++ b/net/minecraft/world/entity/animal/EntityFox.java -@@ -94,6 +94,10 @@ +@@ -93,6 +93,10 @@ + import net.minecraft.world.level.pathfinder.PathType; import net.minecraft.world.phys.Vec3D; - import org.joml.Vector3f; +// CraftBukkit start +import org.bukkit.event.entity.EntityRemoveEvent; @@ -11,7 +11,7 @@ public class EntityFox extends EntityAnimal implements VariantHolder { private static final DataWatcherObject DATA_TYPE_ID = DataWatcher.defineId(EntityFox.class, DataWatcherRegistry.INT); -@@ -523,7 +527,8 @@ +@@ -518,7 +522,8 @@ protected void pickUpItem(EntityItem entityitem) { ItemStack itemstack = entityitem.getItem(); @@ -21,7 +21,7 @@ int i = itemstack.getCount(); if (i > 1) { -@@ -535,7 +540,7 @@ +@@ -530,7 +535,7 @@ this.setItemSlot(EnumItemSlot.MAINHAND, itemstack.split(1)); this.setGuaranteedDrop(EnumItemSlot.MAINHAND); this.take(entityitem, itemstack.getCount()); @@ -30,7 +30,7 @@ this.ticksSinceEaten = 0; } -@@ -883,6 +888,16 @@ +@@ -868,6 +873,16 @@ if (entityplayer1 != null && entityplayer != entityplayer1) { entityfox.addTrustedUUID(entityplayer1.getUUID()); } @@ -47,7 +47,7 @@ if (entityplayer2 != null) { entityplayer2.awardStat(StatisticList.ANIMALS_BRED); -@@ -893,12 +908,14 @@ +@@ -878,12 +893,14 @@ this.partner.setAge(6000); this.animal.resetLove(); this.partner.resetLove(); @@ -66,7 +66,7 @@ } } -@@ -1294,6 +1311,11 @@ +@@ -1279,6 +1296,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); -@@ -1451,7 +1473,7 @@ +@@ -1436,7 +1458,7 @@ private EntityLiving trustedLastHurt; private int timestamp; -- public a(Class oclass, boolean flag, boolean flag1, @Nullable Predicate predicate) { -+ public a(Class oclass, boolean flag, boolean flag1, @Nullable Predicate predicate) { // CraftBukkit - decompile error +- 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); } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityIronGolem.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityIronGolem.patch index 9142266872..da5d876378 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityIronGolem.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityIronGolem.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntityIronGolem.java +++ b/net/minecraft/world/entity/animal/EntityIronGolem.java -@@ -102,7 +102,7 @@ +@@ -97,7 +97,7 @@ @Override protected void doPush(Entity entity) { if (entity instanceof IMonster && !(entity instanceof EntityCreeper) && this.getRandom().nextInt(20) == 0) { 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 8e9990640a..5eb23724f6 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,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntityMushroomCow.java +++ b/net/minecraft/world/entity/animal/EntityMushroomCow.java -@@ -42,13 +42,21 @@ +@@ -42,6 +42,14 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.gameevent.GameEvent; @@ -15,14 +15,6 @@ public class EntityMushroomCow extends EntityCow implements IShearable, VariantHolder { private static final DataWatcherObject DATA_TYPE = DataWatcher.defineId(EntityMushroomCow.class, DataWatcherRegistry.STRING); - private static final int MUTATE_CHANCE = 1024; - private static final String TAG_STEW_EFFECTS = "stew_effects"; - @Nullable -- private List stewEffects; -+ public List stewEffects; - @Nullable - private UUID lastLightningBoltUUID; - @@ -114,6 +122,11 @@ this.playSound(soundeffect, 1.0F, 1.0F); return EnumInteractionResult.sidedSuccess(this.level().isClientSide); @@ -35,7 +27,7 @@ this.shear(SoundCategory.PLAYERS); this.gameEvent(GameEvent.SHEAR, entityhuman); if (!this.level().isClientSide) { -@@ -161,7 +174,7 @@ +@@ -157,7 +170,7 @@ 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); @@ -44,7 +36,7 @@ entitycow.moveTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), this.getXRot()); entitycow.setHealth(this.getHealth()); entitycow.yBodyRot = this.yBodyRot; -@@ -175,10 +188,25 @@ +@@ -171,10 +184,25 @@ } entitycow.setInvulnerable(this.isInvulnerable()); 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 e57d802e95..fd9f79c2e2 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 -@@ -179,7 +179,7 @@ +@@ -177,7 +177,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); -@@ -315,10 +315,10 @@ +@@ -308,10 +308,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 31b836da5b..12a479cc3b 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,8 +1,8 @@ --- a/net/minecraft/world/entity/animal/EntityPanda.java +++ b/net/minecraft/world/entity/animal/EntityPanda.java -@@ -67,6 +67,12 @@ +@@ -72,6 +72,12 @@ + import net.minecraft.world.level.storage.loot.parameters.LootContextParameters; import net.minecraft.world.phys.Vec3D; - import org.joml.Vector3f; +// CraftBukkit start; +import org.bukkit.craftbukkit.event.CraftEventFactory; @@ -13,7 +13,7 @@ public class EntityPanda extends EntityAnimal { private static final DataWatcherObject UNHAPPY_COUNTER = DataWatcher.defineId(EntityPanda.class, DataWatcherRegistry.INT); -@@ -534,14 +540,14 @@ +@@ -553,14 +559,14 @@ @Override protected void pickUpItem(EntityItem entityitem) { @@ -30,7 +30,7 @@ } } -@@ -870,10 +876,10 @@ +@@ -889,10 +895,10 @@ private final EntityPanda panda; public c(EntityPanda entitypanda, Class oclass, float f, double d0, double d1) { @@ -44,7 +44,7 @@ this.panda = entitypanda; } -@@ -1112,7 +1118,7 @@ +@@ -1131,7 +1137,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 3aa036a9b0..3f9c65d1c2 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 -@@ -263,7 +263,7 @@ +@@ -248,7 +248,7 @@ } if (!this.level().isClientSide) { @@ -9,16 +9,16 @@ this.tame(entityhuman); this.level().broadcastEntityEvent(this, (byte) 7); } else { -@@ -277,7 +277,7 @@ - itemstack.shrink(1); +@@ -269,7 +269,7 @@ } - + } else { + itemstack.consume(1, entityhuman); - 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); } -@@ -384,7 +384,7 @@ +@@ -368,7 +368,7 @@ @Override public boolean isPushable() { @@ -27,7 +27,7 @@ } @Override -@@ -399,11 +399,14 @@ +@@ -383,11 +383,14 @@ if (this.isInvulnerableTo(damagesource)) { return false; } else { 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 c54ff861ae..aefc4f57f8 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,8 +1,8 @@ --- a/net/minecraft/world/entity/animal/EntityPig.java +++ b/net/minecraft/world/entity/animal/EntityPig.java -@@ -51,6 +51,11 @@ +@@ -49,6 +49,11 @@ + import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; - import org.joml.Vector3f; +// CraftBukkit start +import org.bukkit.craftbukkit.event.CraftEventFactory; @@ -12,7 +12,7 @@ public class EntityPig extends EntityAnimal implements ISteerable, ISaddleable { private static final DataWatcherObject DATA_SADDLE_ID = DataWatcher.defineId(EntityPig.class, DataWatcherRegistry.BOOLEAN); -@@ -252,8 +257,14 @@ +@@ -253,8 +258,14 @@ } entitypigzombie.setPersistenceRequired(); 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 e01702784b..e896b2ba79 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,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntityPufferFish.java +++ b/net/minecraft/world/entity/animal/EntityPufferFish.java -@@ -144,7 +144,7 @@ +@@ -150,7 +150,7 @@ int i = this.getPuffState(); if (entityinsentient.hurt(this.damageSources().mobAttack(this), (float) (1 + i))) { @@ -9,7 +9,7 @@ this.playSound(SoundEffects.PUFFER_FISH_STING, 1.0F, 1.0F); } -@@ -159,7 +159,7 @@ +@@ -165,7 +165,7 @@ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.PUFFER_FISH_STING, 0.0F)); } 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 faa5bddea2..076aef7fc3 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; -@@ -89,7 +93,6 @@ +@@ -88,7 +92,6 @@ super(entitytypes, world); this.jumpControl = new EntityRabbit.ControllerJumpRabbit(this); this.moveControl = new EntityRabbit.ControllerMoveRabbit(this); @@ -19,7 +19,7 @@ } @Override -@@ -577,9 +580,19 @@ +@@ -574,9 +577,19 @@ int i = (Integer) iblockdata.getValue(BlockCarrots.AGE); if (i == 0) { @@ -37,5 +37,5 @@ + } + // CraftBukkit end world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockCarrots.AGE, i - 1), 2); - world.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of((Entity) this.rabbit)); + world.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of((Entity) this.rabbit)); world.levelEvent(2001, blockposition, Block.getId(iblockdata)); 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 efda17bf77..b18db46cec 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,8 +1,8 @@ --- a/net/minecraft/world/entity/animal/EntitySheep.java +++ b/net/minecraft/world/entity/animal/EntitySheep.java -@@ -66,6 +66,14 @@ +@@ -64,6 +64,14 @@ + import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.level.storage.loot.LootTables; - import org.joml.Vector3f; +// CraftBukkit start +import net.minecraft.world.inventory.InventoryCraftResult; @@ -15,7 +15,7 @@ public class EntitySheep extends EntityAnimal implements IShearable { private static final int EAT_ANIMATION_TICKS = 40; -@@ -246,6 +254,11 @@ +@@ -251,6 +259,11 @@ if (itemstack.is(Items.SHEARS)) { if (!this.level().isClientSide && this.readyForShearing()) { @@ -26,8 +26,8 @@ + // CraftBukkit end this.shear(SoundCategory.PLAYERS); this.gameEvent(GameEvent.SHEAR, entityhuman); - itemstack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { -@@ -267,7 +280,9 @@ + itemstack.hurtAndBreak(1, entityhuman, getSlotForHand(enumhand)); +@@ -270,7 +283,9 @@ int i = 1 + this.random.nextInt(3); for (int j = 0; j < i; ++j) { @@ -37,7 +37,7 @@ 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))); -@@ -360,6 +375,12 @@ +@@ -363,6 +378,12 @@ @Override public void ate() { @@ -50,7 +50,7 @@ super.ate(); this.setSheared(false); if (this.isBaby()) { -@@ -379,7 +400,7 @@ +@@ -382,7 +403,7 @@ EnumColor enumcolor = ((EntitySheep) entityanimal).getColor(); EnumColor enumcolor1 = ((EntitySheep) entityanimal1).getColor(); InventoryCrafting inventorycrafting = makeContainer(enumcolor, enumcolor1); @@ -59,7 +59,7 @@ return ((RecipeCrafting) recipeholder.value()).assemble(inventorycrafting, this.level().registryAccess()); }).map(ItemStack::getItem); -@@ -402,10 +423,18 @@ +@@ -405,10 +426,18 @@ public boolean stillValid(EntityHuman entityhuman) { return false; } @@ -77,4 +77,4 @@ + transientcraftingcontainer.resultInventory = new InventoryCraftResult(); // CraftBukkit - add result slot for event return transientcraftingcontainer; } - + } 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 c3303d39e3..2c4f535b80 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,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntitySnowman.java +++ b/net/minecraft/world/entity/animal/EntitySnowman.java -@@ -41,6 +41,10 @@ +@@ -40,6 +40,10 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.Vec3D; @@ -11,7 +11,7 @@ public class EntitySnowman extends EntityGolem implements IShearable, IRangedEntity { private static final DataWatcherObject DATA_PUMPKIN_ID = DataWatcher.defineId(EntitySnowman.class, DataWatcherRegistry.BYTE); -@@ -97,7 +101,7 @@ +@@ -95,7 +99,7 @@ super.aiStep(); if (!this.level().isClientSide) { if (this.level().getBiome(this.blockPosition()).is(BiomeTags.SNOW_GOLEM_MELTS)) { @@ -20,7 +20,7 @@ } if (!this.level().getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { -@@ -113,7 +117,11 @@ +@@ -111,7 +115,11 @@ BlockPosition blockposition = new BlockPosition(j, k, l); if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) { @@ -30,10 +30,10 @@ + continue; + } + // CraftBukkit end - this.level().gameEvent(GameEvent.BLOCK_PLACE, blockposition, GameEvent.a.of(this, iblockdata)); + this.level().gameEvent((Holder) GameEvent.BLOCK_PLACE, blockposition, GameEvent.a.of(this, iblockdata)); } } -@@ -145,6 +153,11 @@ +@@ -138,6 +146,11 @@ ItemStack itemstack = entityhuman.getItemInHand(enumhand); if (itemstack.is(Items.SHEARS) && this.readyForShearing()) { @@ -45,12 +45,12 @@ this.shear(SoundCategory.PLAYERS); this.gameEvent(GameEvent.SHEAR, entityhuman); if (!this.level().isClientSide) { -@@ -164,7 +177,9 @@ +@@ -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); + this.forceDrops = true; // CraftBukkit - this.spawnAtLocation(new ItemStack(Items.CARVED_PUMPKIN), 1.7F); + this.spawnAtLocation(new ItemStack(Items.CARVED_PUMPKIN), 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 74d04172cf..fb0d940077 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,16 +1,16 @@ --- a/net/minecraft/world/entity/animal/EntityTurtle.java +++ b/net/minecraft/world/entity/animal/EntityTurtle.java -@@ -307,7 +307,9 @@ +@@ -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.SCUTE, 1); + this.spawnAtLocation(Items.TURTLE_SCUTE, 1); + this.forceDrops = false; // CraftBukkit } } -@@ -334,7 +336,7 @@ +@@ -332,7 +334,7 @@ @Override public void thunderHit(WorldServer worldserver, EntityLightning entitylightning) { @@ -19,7 +19,7 @@ } @Override -@@ -491,12 +493,14 @@ +@@ -489,12 +491,14 @@ } else if (this.turtle.layEggCounter > this.adjustedTickDelay(200)) { World world = this.turtle.level(); @@ -29,7 +29,7 @@ IBlockData iblockdata = (IBlockData) Blocks.TURTLE_EGG.defaultBlockState().setValue(BlockTurtleEgg.EGGS, this.turtle.random.nextInt(4) + 1); world.setBlock(blockposition1, iblockdata, 3); - world.gameEvent(GameEvent.BLOCK_PLACE, blockposition1, GameEvent.a.of(this.turtle, iblockdata)); + world.gameEvent((Holder) GameEvent.BLOCK_PLACE, blockposition1, GameEvent.a.of(this.turtle, iblockdata)); + } // CraftBukkit this.turtle.setHasEgg(false); this.turtle.setLayingEgg(false); 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 8114754db0..27c94ca38b 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,8 +1,8 @@ --- a/net/minecraft/world/entity/animal/EntityWolf.java +++ b/net/minecraft/world/entity/animal/EntityWolf.java -@@ -70,6 +70,12 @@ +@@ -88,6 +88,12 @@ + import net.minecraft.world.level.pathfinder.PathType; import net.minecraft.world.phys.Vec3D; - import org.joml.Vector3f; +// CraftBukkit start +import org.bukkit.event.entity.EntityRegainHealthEvent; @@ -10,67 +10,77 @@ +import org.bukkit.craftbukkit.event.CraftEventFactory; +// CraftBukkit end + - public class EntityWolf extends EntityTameableAnimal implements IEntityAngerable { + public class EntityWolf extends EntityTameableAnimal implements IEntityAngerable, VariantHolder> { private static final DataWatcherObject DATA_INTERESTED_ID = DataWatcher.defineId(EntityWolf.class, DataWatcherRegistry.BOOLEAN); -@@ -298,15 +304,19 @@ +@@ -350,18 +356,21 @@ + if (this.isInvulnerableTo(damagesource)) { + return false; } else { - Entity entity = damagesource.getEntity(); - - if (!this.level().isClientSide) { -- this.setOrderedToSit(false); -- } -+ // CraftBukkit - move diff down - - if (entity != null && !(entity instanceof EntityHuman) && !(entity instanceof EntityArrow)) { - f = (f + 1.0F) / 2.0F; - } - -- return super.hurt(damagesource, f); + // CraftBukkit start + boolean result = super.hurt(damagesource, f); + if (!this.level().isClientSide && result) { -+ this.setOrderedToSit(false); -+ } -+ return result; -+ // CraftBukkit end ++ // CraftBukkit end + this.setOrderedToSit(false); + } + +- return super.hurt(damagesource, f); ++ return result; // CraftBukkit } } -@@ -326,7 +336,7 @@ - super.setTame(flag); - if (flag) { - this.getAttribute(GenericAttributes.MAX_HEALTH).setBaseValue(20.0D); -- this.setHealth(20.0F); -+ this.setHealth(this.getMaxHealth()); // CraftBukkit - 20.0 -> getMaxHealth() + @Override +- protected void actuallyHurt(DamageSource damagesource, float f) { ++ public boolean actuallyHurt(DamageSource damagesource, float f) { // CraftBukkit - void -> boolean + if (!this.canArmorAbsorb(damagesource)) { +- super.actuallyHurt(damagesource, f); ++ return super.actuallyHurt(damagesource, f); // CraftBukkit + } else { + ItemStack itemstack = this.getBodyArmorItem(); + int i = itemstack.getDamageValue(); +@@ -380,6 +389,7 @@ + } + + } ++ return false; // CraftBukkit + } + + private boolean canArmorAbsorb(DamageSource damagesource) { +@@ -401,7 +411,7 @@ + protected void applyTamingSideEffects() { + if (this.isTame()) { + this.getAttribute(GenericAttributes.MAX_HEALTH).setBaseValue(40.0D); +- this.setHealth(40.0F); ++ this.setHealth(this.getMaxHealth()); // CraftBukkit - 40.0 -> getMaxHealth() } else { this.getAttribute(GenericAttributes.MAX_HEALTH).setBaseValue(8.0D); } -@@ -349,7 +359,7 @@ - itemstack.shrink(1); - } +@@ -428,7 +438,7 @@ + FoodInfo foodinfo = (FoodInfo) itemstack.get(DataComponents.FOOD); + float f = foodinfo != null ? (float) foodinfo.nutrition() : 1.0F; -- this.heal((float) item.getFoodProperties().getNutrition()); -+ this.heal((float) item.getFoodProperties().getNutrition(), EntityRegainHealthEvent.RegainReason.EATING); // CraftBukkit - return EnumInteractionResult.SUCCESS; +- this.heal(2.0F * f); ++ this.heal(2.0F * f, EntityRegainHealthEvent.RegainReason.EATING); // CraftBukkit + return EnumInteractionResult.sidedSuccess(this.level().isClientSide()); } else { if (item instanceof ItemDye) { -@@ -377,7 +387,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; - } else { - return enuminteractionresult; -@@ -388,7 +398,8 @@ - itemstack.shrink(1); - } +@@ -476,7 +486,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; + } else { + return enuminteractionresult; +@@ -494,7 +504,8 @@ + } -- if (this.random.nextInt(3) == 0) { -+ // CraftBukkit - added event call and isCancelled check. -+ if (this.random.nextInt(3) == 0 && !CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) { - this.tame(entityhuman); - this.navigation.stop(); - this.setTarget((EntityLiving) null); + private void tryToTame(EntityHuman entityhuman) { +- if (this.random.nextInt(3) == 0) { ++ // CraftBukkit - added event call and isCancelled check. ++ if (this.random.nextInt(3) == 0 && !CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) { + this.tame(entityhuman); + this.navigation.stop(); + this.setTarget((EntityLiving) null); 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 40b4cd0b15..6572fd5ee2 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 @@ -9,7 +9,7 @@ public Allay(EntityTypes entitytypes, World world) { super(entitytypes, world); @@ -110,6 +111,12 @@ - this.dynamicJukeboxListener = new DynamicGameEventListener<>(new Allay.a(this.vibrationUser.getPositionSource(), GameEvent.JUKEBOX_PLAY.getNotificationRadius())); + this.dynamicJukeboxListener = new DynamicGameEventListener<>(new Allay.a(this.vibrationUser.getPositionSource(), ((GameEvent) GameEvent.JUKEBOX_PLAY.value()).notificationRadius())); } + // CraftBukkit start @@ -30,7 +30,7 @@ } public static AttributeProvider.Builder createAttributes() { -@@ -229,7 +236,7 @@ +@@ -223,7 +230,7 @@ public void aiStep() { super.aiStep(); if (!this.level().isClientSide && this.isAlive() && this.tickCount % 10 == 0) { @@ -39,7 +39,7 @@ } if (this.isDancing() && this.shouldStopDancing() && this.tickCount % 20 == 0) { -@@ -299,7 +306,12 @@ +@@ -293,7 +300,12 @@ ItemStack itemstack1 = this.getItemInHand(EnumHand.MAIN_HAND); if (this.isDancing() && this.isDuplicationItem(itemstack) && this.canDuplicate()) { @@ -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); -@@ -310,7 +322,7 @@ +@@ -304,7 +316,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,33 +62,33 @@ return EnumInteractionResult.SUCCESS; } else if (!itemstack1.isEmpty() && enumhand == EnumHand.MAIN_HAND && itemstack.isEmpty()) { this.setItemSlot(EnumItemSlot.MAINHAND, ItemStack.EMPTY); -@@ -427,6 +439,7 @@ +@@ -405,6 +417,7 @@ } private boolean shouldStopDancing() { + if (this.forceDancing) {return false;} // CraftBukkit - return this.jukeboxPos == null || !this.jukeboxPos.closerToCenterThan(this.position(), (double) GameEvent.JUKEBOX_PLAY.getNotificationRadius()) || !this.level().getBlockState(this.jukeboxPos).is(Blocks.JUKEBOX); + return this.jukeboxPos == null || !this.jukeboxPos.closerToCenterThan(this.position(), (double) ((GameEvent) GameEvent.JUKEBOX_PLAY.value()).notificationRadius()) || !this.level().getBlockState(this.jukeboxPos).is(Blocks.JUKEBOX); } -@@ -471,7 +484,7 @@ +@@ -449,7 +462,7 @@ public void addAdditionalSaveData(NBTTagCompound nbttagcompound) { super.addAdditionalSaveData(nbttagcompound); - this.writeInventoryToTag(nbttagcompound); + this.writeInventoryToTag(nbttagcompound, this.registryAccess()); - DataResult dataresult = VibrationSystem.a.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, this.vibrationData); + DataResult dataresult = VibrationSystem.a.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, this.vibrationData); // CraftBukkit - decompile error Logger logger = Allay.LOGGER; Objects.requireNonNull(logger); -@@ -487,7 +500,7 @@ +@@ -465,7 +478,7 @@ super.readAdditionalSaveData(nbttagcompound); - this.readInventoryFromTag(nbttagcompound); + this.readInventoryFromTag(nbttagcompound, this.registryAccess()); if (nbttagcompound.contains("listener", 10)) { - DataResult dataresult = VibrationSystem.a.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.getCompound("listener"))); + DataResult dataresult = VibrationSystem.a.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.getCompound("listener"))); // CraftBukkit - decompile error Logger logger = Allay.LOGGER; Objects.requireNonNull(logger); -@@ -520,7 +533,7 @@ +@@ -498,7 +511,7 @@ return Allay.DUPLICATION_ITEM.test(itemstack); } @@ -97,7 +97,7 @@ Allay allay = (Allay) EntityTypes.ALLAY.create(this.level()); if (allay != null) { -@@ -528,9 +541,9 @@ +@@ -506,9 +519,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 new file mode 100644 index 0000000000..c526525d72 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/armadillo/Armadillo.patch @@ -0,0 +1,54 @@ +--- a/net/minecraft/world/entity/animal/armadillo/Armadillo.java ++++ b/net/minecraft/world/entity/animal/armadillo/Armadillo.java +@@ -131,14 +131,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"); + ArmadilloAi.updateActivity(this); + this.level().getProfiler().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); ++ this.forceDrops = false; // CraftBukkit + this.gameEvent(GameEvent.ENTITY_PLACE); + this.scuteTime = this.pickNextScuteDropTime(); + } +@@ -285,8 +287,13 @@ + } + + @Override +- protected void actuallyHurt(DamageSource damagesource, float f) { +- super.actuallyHurt(damagesource, f); ++ // CraftBukkit start - void -> boolean ++ public boolean actuallyHurt(DamageSource damagesource, float f) { ++ boolean hurt = super.actuallyHurt(damagesource, f); ++ if (!hurt) { ++ return hurt; ++ } ++ // CraftBukkit end + if (!this.isNoAi() && !this.isDeadOrDying()) { + if (damagesource.getEntity() instanceof EntityLiving) { + this.getBrain().setMemoryWithExpiry(MemoryModuleType.DANGER_DETECTED_RECENTLY, true, 80L); +@@ -298,6 +305,7 @@ + } + + } ++ return hurt; // CraftBukkit + } + + public boolean shouldPanic() { +@@ -329,7 +337,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; 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 afe800ab58..90f6fdcf38 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,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/axolotl/Axolotl.java +++ b/net/minecraft/world/entity/animal/axolotl/Axolotl.java -@@ -68,9 +68,16 @@ +@@ -67,9 +67,16 @@ public class Axolotl extends EntityAnimal implements LerpingModel, VariantHolder, Bucketable { @@ -18,7 +18,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); -@@ -188,7 +195,7 @@ +@@ -186,7 +193,7 @@ @Override public int getMaxAirSupply() { @@ -27,7 +27,7 @@ } @Override -@@ -409,7 +416,7 @@ +@@ -397,7 +404,7 @@ int i = mobeffect != null ? mobeffect.getDuration() : 0; int j = Math.min(2400, 100 + i); @@ -36,7 +36,7 @@ } entityhuman.removeEffect(MobEffects.DIG_SLOWDOWN); -@@ -459,7 +466,7 @@ +@@ -447,7 +454,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 9fe4147046..453c03db02 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/camel/Camel.java +++ b/net/minecraft/world/entity/animal/camel/Camel.java -@@ -150,7 +150,7 @@ +@@ -141,7 +141,7 @@ @Override protected void customServerAiStep() { this.level().getProfiler().push("camelBrain"); @@ -9,13 +9,13 @@ behaviorcontroller.tick((WorldServer) this.level(), this); this.level().getProfiler().pop(); -@@ -462,9 +462,15 @@ +@@ -451,9 +451,15 @@ } @Override - protected void actuallyHurt(DamageSource damagesource, float f) { + // CraftBukkit start - void -> boolean -+ protected boolean actuallyHurt(DamageSource damagesource, float f) { ++ public boolean actuallyHurt(DamageSource damagesource, float f) { + boolean hurt = super.actuallyHurt(damagesource, f); + if (!hurt) { + return hurt; 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 c727c9defe..ad9b3e3723 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,7 +1,7 @@ --- a/net/minecraft/world/entity/animal/frog/Tadpole.java +++ b/net/minecraft/world/entity/animal/frog/Tadpole.java -@@ -35,6 +35,10 @@ - import net.minecraft.world.item.Items; +@@ -38,6 +38,10 @@ + import net.minecraft.world.item.component.CustomData; import net.minecraft.world.level.World; +// CraftBukkit start @@ -11,7 +11,7 @@ public class Tadpole extends EntityFish { @VisibleForTesting -@@ -68,7 +72,7 @@ +@@ -71,7 +75,7 @@ @Override public BehaviorController getBrain() { @@ -20,7 +20,7 @@ } @Override -@@ -233,9 +237,15 @@ +@@ -232,9 +236,15 @@ } frog.setPersistenceRequired(); 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 ca94087b21..dc79b95d3e 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,8 +1,8 @@ --- a/net/minecraft/world/entity/animal/goat/Goat.java +++ b/net/minecraft/world/entity/animal/goat/Goat.java @@ -55,6 +55,12 @@ + import net.minecraft.world.level.pathfinder.PathType; import net.minecraft.world.phys.Vec3D; - import org.joml.Vector3f; +// CraftBukkit start +import org.bukkit.craftbukkit.event.CraftEventFactory; @@ -22,7 +22,7 @@ } @Override -@@ -220,8 +226,15 @@ +@@ -225,8 +231,15 @@ ItemStack itemstack = entityhuman.getItemInHand(enumhand); if (itemstack.is(Items.BUCKET) && !this.isBaby()) { 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 5fa071ec87..0109a6838a 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,27 +1,79 @@ --- a/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.java +++ b/net/minecraft/world/entity/animal/horse/EntityHorseAbstract.java -@@ -79,6 +79,12 @@ +@@ -79,6 +79,18 @@ import net.minecraft.world.phys.Vec3D; - import org.joml.Vector3f; + import net.minecraft.world.ticks.ContainerSingleItem; +// CraftBukkit start ++import java.util.Arrays; ++import java.util.List; ++import org.bukkit.Location; ++import org.bukkit.craftbukkit.entity.CraftHumanEntity; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.entity.AbstractHorse; ++import org.bukkit.entity.HumanEntity; +import org.bukkit.event.entity.EntityRegainHealthEvent; ++import org.bukkit.inventory.InventoryHolder; +// CraftBukkit end + public abstract class EntityHorseAbstract extends EntityAnimal implements IInventoryListener, HasCustomInventoryScreen, OwnableEntity, IJumpable, ISaddleable { public static final int EQUIPMENT_SLOT_OFFSET = 400; -@@ -140,6 +146,7 @@ - protected int gallopSoundCounter; - @Nullable - private UUID owner; +@@ -156,7 +168,53 @@ + public boolean stillValid(EntityHuman entityhuman) { + return entityhuman.getVehicle() == EntityHorseAbstract.this || entityhuman.canInteractWithEntity((Entity) EntityHorseAbstract.this, 4.0D); + } ++ ++ // CraftBukkit start - add fields and methods ++ public List transaction = new java.util.ArrayList(); ++ private int maxStack = MAX_STACK; ++ ++ @Override ++ public List getContents() { ++ return Arrays.asList(this.getTheItem()); ++ } ++ ++ @Override ++ public void onOpen(CraftHumanEntity who) { ++ transaction.add(who); ++ } ++ ++ @Override ++ public void onClose(CraftHumanEntity who) { ++ transaction.remove(who); ++ } ++ ++ @Override ++ public List getViewers() { ++ return transaction; ++ } ++ ++ @Override ++ public int getMaxStackSize() { ++ return maxStack; ++ } ++ ++ @Override ++ public void setMaxStackSize(int size) { ++ maxStack = size; ++ } ++ ++ @Override ++ public InventoryHolder getOwner() { ++ return (AbstractHorse) EntityHorseAbstract.this.getBukkitEntity(); ++ } ++ ++ @Override ++ public Location getLocation() { ++ return EntityHorseAbstract.this.getBukkitEntity().getLocation(); ++ } ++ // CraftBukkit end + }; + public int maxDomestication = 100; // CraftBukkit - store max domestication value protected EntityHorseAbstract(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -335,7 +342,7 @@ +@@ -346,7 +404,7 @@ public void createInventory() { InventorySubcontainer inventorysubcontainer = this.inventory; @@ -30,7 +82,7 @@ if (inventorysubcontainer != null) { inventorysubcontainer.removeListener(this); int i = Math.min(inventorysubcontainer.getContainerSize(), this.inventory.getContainerSize()); -@@ -443,7 +450,7 @@ +@@ -450,7 +508,7 @@ } public int getMaxTemper() { @@ -39,7 +91,7 @@ } @Override -@@ -514,7 +521,7 @@ +@@ -521,7 +579,7 @@ } if (this.getHealth() < this.getMaxHealth() && f > 0.0F) { @@ -48,7 +100,7 @@ flag = true; } -@@ -588,7 +595,7 @@ +@@ -595,7 +653,7 @@ super.aiStep(); if (!this.level().isClientSide && this.isAlive()) { if (this.random.nextInt(900) == 0 && this.deathTime == 0) { @@ -57,15 +109,15 @@ } if (this.canEatGrass()) { -@@ -855,6 +862,7 @@ +@@ -857,6 +915,7 @@ if (this.getOwnerUUID() != null) { nbttagcompound.putUUID("Owner", this.getOwnerUUID()); } + nbttagcompound.putInt("Bukkit.MaxDomestication", this.maxDomestication); // CraftBukkit if (!this.inventory.getItem(0).isEmpty()) { - nbttagcompound.put("SaddleItem", this.inventory.getItem(0).save(new NBTTagCompound())); -@@ -882,6 +890,11 @@ + nbttagcompound.put("SaddleItem", this.inventory.getItem(0).save(this.registryAccess())); +@@ -884,6 +943,11 @@ if (uuid != null) { this.setOwnerUUID(uuid); } @@ -76,8 +128,8 @@ + // CraftBukkit end if (nbttagcompound.contains("SaddleItem", 10)) { - ItemStack itemstack = ItemStack.of(nbttagcompound.getCompound("SaddleItem")); -@@ -984,6 +997,17 @@ + ItemStack itemstack = (ItemStack) ItemStack.parse(this.registryAccess(), nbttagcompound.getCompound("SaddleItem")).orElse(ItemStack.EMPTY); +@@ -986,6 +1050,17 @@ @Override public void handleStartJump(int i) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityHorseSkeleton.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityHorseSkeleton.patch index 368a17ea37..b63cd24319 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityHorseSkeleton.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/EntityHorseSkeleton.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/entity/animal/horse/EntityHorseSkeleton.java +++ b/net/minecraft/world/entity/animal/horse/EntityHorseSkeleton.java @@ -27,6 +27,10 @@ + import net.minecraft.world.level.GeneratorAccess; import net.minecraft.world.level.World; - import org.joml.Vector3f; +// CraftBukkit start +import org.bukkit.event.entity.EntityRemoveEvent; @@ -11,7 +11,7 @@ public class EntityHorseSkeleton extends EntityHorseAbstract { private final PathfinderGoalHorseTrap skeletonTrapGoal = new PathfinderGoalHorseTrap(this); -@@ -126,7 +130,7 @@ +@@ -122,7 +126,7 @@ public void aiStep() { super.aiStep(); if (this.isTrap() && this.trapTime++ >= 18000) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/PathfinderGoalHorseTrap.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/PathfinderGoalHorseTrap.patch index 6e536d03d6..d004aa1439 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/PathfinderGoalHorseTrap.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/horse/PathfinderGoalHorseTrap.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/horse/PathfinderGoalHorseTrap.java +++ b/net/minecraft/world/entity/animal/horse/PathfinderGoalHorseTrap.java -@@ -41,12 +41,12 @@ +@@ -43,12 +43,12 @@ if (entitylightning != null) { entitylightning.moveTo(this.horse.getX(), this.horse.getY(), this.horse.getZ()); entitylightning.setVisualOnly(true); @@ -15,7 +15,7 @@ for (int i = 0; i < 3; ++i) { EntityHorseAbstract entityhorseabstract = this.createHorse(difficultydamagescaler); -@@ -57,7 +57,7 @@ +@@ -59,7 +59,7 @@ if (entityskeleton1 != null) { entityskeleton1.startRiding(entityhorseabstract); entityhorseabstract.push(this.horse.getRandom().triangle(0.0D, 1.1485D), 0.0D, this.horse.getRandom().triangle(0.0D, 1.1485D)); 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 94108b6b12..37f01acf82 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,32 +1,6 @@ --- a/net/minecraft/world/entity/animal/sniffer/Sniffer.java +++ b/net/minecraft/world/entity/animal/sniffer/Sniffer.java -@@ -83,14 +83,23 @@ - - public Sniffer(EntityTypes entitytypes, World world) { - super(entitytypes, world); -- this.entityData.define(Sniffer.DATA_STATE, Sniffer.State.IDLING); -- this.entityData.define(Sniffer.DATA_DROP_SEED_AT_TICK, 0); -+ // this.entityData.define(Sniffer.DATA_STATE, Sniffer.State.IDLING); // CraftBukkit - moved down to appropriate location -+ // this.entityData.define(Sniffer.DATA_DROP_SEED_AT_TICK, 0); // CraftBukkit - moved down to appropriate location - this.getNavigation().setCanFloat(true); - this.setPathfindingMalus(PathType.WATER, -1.0F); - this.setPathfindingMalus(PathType.DANGER_POWDER_SNOW, -1.0F); - this.setPathfindingMalus(PathType.DAMAGE_CAUTIOUS, -1.0F); - } - -+ // CraftBukkit start - SPIGOT-7295: moved from constructor to appropriate location -+ @Override -+ protected void defineSynchedData() { -+ super.defineSynchedData(); -+ this.entityData.define(Sniffer.DATA_STATE, Sniffer.State.IDLING); -+ this.entityData.define(Sniffer.DATA_DROP_SEED_AT_TICK, 0); -+ } -+ // CraftBukkit end -+ - @Override - protected float getStandingEyeHeight(EntityPose entitypose, EntitySize entitysize) { - return this.getDimensions(entitypose).height * 0.6F; -@@ -267,6 +276,13 @@ +@@ -274,6 +274,13 @@ ItemStack itemstack = (ItemStack) iterator.next(); EntityItem entityitem = new EntityItem(worldserver, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), itemstack); @@ -40,7 +14,7 @@ entityitem.setDefaultPickUpDelay(); worldserver.addFreshEntity(entityitem); } -@@ -306,7 +322,7 @@ +@@ -313,7 +320,7 @@ List list = (List) this.getExploredPositions().limit(20L).collect(Collectors.toList()); list.add(0, GlobalPos.of(this.level().dimension(), blockposition)); @@ -49,7 +23,7 @@ return this; } -@@ -458,7 +474,7 @@ +@@ -454,7 +461,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 db877da98a..0f6fe4303f 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,7 +26,7 @@ } } -@@ -95,12 +105,26 @@ +@@ -92,12 +102,26 @@ return false; } else { if (!this.isRemoved() && !this.level().isClientSide) { 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 93fdccc4e6..31fab595ef 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,7 +1,7 @@ --- a/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.java +++ b/net/minecraft/world/entity/boss/enderdragon/EntityEnderDragon.java -@@ -53,6 +53,20 @@ - import org.joml.Vector3f; +@@ -51,6 +51,20 @@ + import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; +// CraftBukkit start @@ -21,7 +21,7 @@ public class EntityEnderDragon extends EntityInsentient implements IMonster { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -90,6 +104,7 @@ +@@ -88,6 +102,7 @@ private final PathPoint[] nodes; private final int[] nodeAdjacency; private final Path openSet; @@ -29,7 +29,7 @@ public EntityEnderDragon(EntityTypes entitytypes, World world) { super(EntityTypes.ENDER_DRAGON, world); -@@ -111,6 +126,7 @@ +@@ -109,6 +124,7 @@ this.noPhysics = true; this.noCulling = true; this.phaseManager = new DragonControllerManager(this); @@ -37,7 +37,7 @@ } public void setDragonFight(EnderDragonBattle enderdragonbattle) { -@@ -258,7 +274,7 @@ +@@ -256,7 +272,7 @@ Vec3D vec3d1 = idragoncontroller.getFlyTargetLocation(); @@ -46,7 +46,7 @@ double d0 = vec3d1.x - this.getX(); double d1 = vec3d1.y - this.getY(); double d2 = vec3d1.z - this.getZ(); -@@ -399,7 +415,14 @@ +@@ -397,7 +413,14 @@ if (this.nearestCrystal.isRemoved()) { this.nearestCrystal = null; } else if (this.tickCount % 10 == 0 && this.getHealth() < this.getMaxHealth()) { @@ -62,7 +62,7 @@ } } -@@ -474,6 +497,9 @@ +@@ -472,6 +495,9 @@ int j1 = MathHelper.floor(axisalignedbb.maxZ); boolean flag = false; boolean flag1 = false; @@ -72,7 +72,7 @@ for (int k1 = i; k1 <= l; ++k1) { for (int l1 = j; l1 <= i1; ++l1) { -@@ -483,7 +509,11 @@ +@@ -481,7 +507,11 @@ if (!iblockdata.isAir() && !iblockdata.is(TagsBlock.DRAGON_TRANSPARENT)) { if (this.level().getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) && !iblockdata.is(TagsBlock.DRAGON_IMMUNE)) { @@ -85,7 +85,7 @@ } else { flag = true; } -@@ -492,6 +522,51 @@ +@@ -490,6 +520,51 @@ } } @@ -137,7 +137,7 @@ 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)); -@@ -547,7 +622,7 @@ +@@ -545,7 +620,7 @@ @Override public void kill() { @@ -146,7 +146,7 @@ this.gameEvent(GameEvent.ENTITY_DIE); if (this.dragonFight != null) { this.dragonFight.updateDragon(this); -@@ -556,6 +631,21 @@ +@@ -554,6 +629,21 @@ } @@ -168,7 +168,7 @@ @Override protected void tickDeath() { if (this.dragonFight != null) { -@@ -571,15 +661,20 @@ +@@ -569,15 +659,20 @@ 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); } @@ -190,7 +190,7 @@ EntityExperienceOrb.award((WorldServer) this.level(), this.position(), MathHelper.floor((float) short0 * 0.08F)); } -@@ -590,7 +685,7 @@ +@@ -588,7 +683,7 @@ this.move(EnumMoveType.SELF, new Vec3D(0.0D, 0.10000000149011612D, 0.0D)); if (this.dragonDeathTime == 200 && this.level() instanceof WorldServer) { @@ -199,7 +199,7 @@ EntityExperienceOrb.award((WorldServer) this.level(), this.position(), MathHelper.floor((float) short0 * 0.2F)); } -@@ -598,7 +693,7 @@ +@@ -596,7 +691,7 @@ this.dragonFight.setDragonKilled(this); } @@ -208,7 +208,7 @@ this.gameEvent(GameEvent.ENTITY_DIE); } -@@ -811,6 +906,7 @@ +@@ -809,6 +904,7 @@ super.addAdditionalSaveData(nbttagcompound); nbttagcompound.putInt("DragonPhase", this.phaseManager.getCurrentPhase().getPhase().getId()); nbttagcompound.putInt("DragonDeathTime", this.dragonDeathTime); @@ -216,7 +216,7 @@ } @Override -@@ -824,6 +920,11 @@ +@@ -822,6 +918,11 @@ this.dragonDeathTime = nbttagcompound.getInt("DragonDeathTime"); } 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 2d683a0b57..daff9e28a6 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 -@@ -55,6 +55,18 @@ +@@ -58,6 +58,18 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.phys.Vec3D; @@ -19,7 +19,7 @@ public class EntityWither extends EntityMonster implements PowerableMob, IRangedEntity { private static final DataWatcherObject DATA_TARGET_A = DataWatcher.defineId(EntityWither.class, DataWatcherRegistry.INT); -@@ -248,15 +260,40 @@ +@@ -254,15 +266,40 @@ i = this.getInvulnerableTicks() - 1; this.bossEvent.setProgress(1.0F - (float) i / 220.0F); if (i <= 0) { @@ -63,7 +63,7 @@ } } else { -@@ -301,6 +338,7 @@ +@@ -307,6 +344,7 @@ if (!list.isEmpty()) { EntityLiving entityliving1 = (EntityLiving) list.get(this.random.nextInt(list.size())); @@ -71,18 +71,18 @@ this.setAlternativeTarget(i, entityliving1.getId()); } } -@@ -331,6 +369,11 @@ - IBlockData iblockdata = this.level().getBlockState(blockposition); +@@ -333,6 +371,11 @@ + IBlockData iblockdata = this.level().getBlockState(blockposition); - if (canDestroy(iblockdata)) { -+ // CraftBukkit start -+ if (!CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, Blocks.AIR.defaultBlockState())) { -+ continue; -+ } -+ // CraftBukkit end - flag = this.level().destroyBlock(blockposition, true, this) || flag; - } - } + if (canDestroy(iblockdata)) { ++ // CraftBukkit start ++ if (!CraftEventFactory.callEntityChangeBlockEvent(this, blockposition, Blocks.AIR.defaultBlockState())) { ++ continue; ++ } ++ // CraftBukkit end + flag = this.level().destroyBlock(blockposition, true, this) || flag; + } + } @@ -344,7 +387,7 @@ } @@ -92,7 +92,7 @@ } this.bossEvent.setProgress(this.getHealth() / this.getMaxHealth()); -@@ -498,7 +541,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/EntityArmorStand.patch b/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityArmorStand.patch index 0f6906959b..c710bff8ac 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 -@@ -44,6 +44,16 @@ +@@ -47,6 +47,16 @@ import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; @@ -17,8 +17,8 @@ public class EntityArmorStand extends EntityLiving { public static final int WOBBLE_TIME = 5; -@@ -106,6 +116,13 @@ - this.setPos(d0, d1, d2); +@@ -112,6 +122,13 @@ + return createLivingAttributes().add(GenericAttributes.STEP_HEIGHT, 0.0D); } + // CraftBukkit start - SPIGOT-3607, SPIGOT-3637 @@ -31,7 +31,7 @@ @Override public void refreshDimensions() { double d0 = this.getX(); -@@ -161,13 +178,20 @@ +@@ -172,13 +189,20 @@ @Override public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { @@ -54,11 +54,11 @@ } } -@@ -402,7 +426,25 @@ +@@ -408,7 +432,25 @@ return false; } else if (itemstack1.isEmpty() && (this.disabledSlots & 1 << enumitemslot.getFilterFlag() + 16) != 0) { return false; -- } else if (entityhuman.getAbilities().instabuild && itemstack1.isEmpty() && !itemstack.isEmpty()) { +- } else if (entityhuman.hasInfiniteMaterials() && itemstack1.isEmpty() && !itemstack.isEmpty()) { + // CraftBukkit start + } else { + org.bukkit.inventory.ItemStack armorStandItem = CraftItemStack.asCraftMirror(itemstack1); @@ -76,12 +76,12 @@ + return true; + } + -+ if (entityhuman.getAbilities().instabuild && itemstack1.isEmpty() && !itemstack.isEmpty()) { ++ if (entityhuman.hasInfiniteMaterials() && itemstack1.isEmpty() && !itemstack.isEmpty()) { + // CraftBukkit end this.setItemSlot(enumitemslot, itemstack.copyWithCount(1)); return true; } else if (!itemstack.isEmpty() && itemstack.getCount() > 1) { -@@ -417,15 +459,26 @@ +@@ -423,15 +465,26 @@ entityhuman.setItemInHand(enumhand, itemstack1); return true; } @@ -109,7 +109,7 @@ if (damagesource.is(DamageTypeTags.IS_EXPLOSION)) { this.brokenByAnything(damagesource); this.kill(); -@@ -473,7 +526,7 @@ +@@ -479,7 +532,7 @@ } else { this.brokenByPlayer(damagesource); this.showBreakingParticles(); @@ -118,10 +118,10 @@ } return true; -@@ -541,13 +594,13 @@ - itemstack.setHoverName(this.getCustomName()); - } +@@ -544,13 +597,13 @@ + ItemStack itemstack = new ItemStack(Items.ARMOR_STAND); + itemstack.set(DataComponents.CUSTOM_NAME, this.getCustomName()); - Block.popResource(this.level(), this.blockPosition(), itemstack); + drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack)); // CraftBukkit - add to drops this.brokenByAnything(damagesource); @@ -134,7 +134,7 @@ ItemStack itemstack; int i; -@@ -555,7 +608,7 @@ +@@ -558,7 +611,7 @@ for (i = 0; i < this.handItems.size(); ++i) { itemstack = (ItemStack) this.handItems.get(i); if (!itemstack.isEmpty()) { @@ -143,7 +143,7 @@ this.handItems.set(i, ItemStack.EMPTY); } } -@@ -563,10 +616,11 @@ +@@ -566,10 +619,11 @@ for (i = 0; i < this.armorItems.size(); ++i) { itemstack = (ItemStack) this.armorItems.get(i); if (!itemstack.isEmpty()) { @@ -156,7 +156,7 @@ } -@@ -662,9 +716,17 @@ +@@ -660,9 +714,17 @@ return this.isSmall(); } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityHanging.patch b/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityHanging.patch index 4c27214075..ac14195543 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityHanging.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/decoration/EntityHanging.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/decoration/EntityHanging.java +++ b/net/minecraft/world/entity/decoration/EntityHanging.java -@@ -26,6 +26,14 @@ +@@ -27,6 +27,14 @@ import org.apache.commons.lang3.Validate; import org.slf4j.Logger; @@ -15,7 +15,7 @@ public abstract class EntityHanging extends Entity { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -60,26 +68,37 @@ +@@ -61,26 +69,37 @@ protected void recalculateBoundingBox() { if (this.direction != null) { @@ -66,7 +66,7 @@ d8 = 1.0D; } else { d6 = 1.0D; -@@ -88,11 +107,12 @@ +@@ -89,11 +108,12 @@ d6 /= 32.0D; d7 /= 32.0D; d8 /= 32.0D; @@ -81,7 +81,7 @@ return i % 32 == 0 ? 0.5D : 0.0D; } -@@ -103,7 +123,25 @@ +@@ -104,7 +124,25 @@ if (this.checkInterval++ == 100) { this.checkInterval = 0; if (!this.isRemoved() && !this.survives()) { @@ -108,7 +108,7 @@ this.dropItem((Entity) null); } } -@@ -166,6 +204,22 @@ +@@ -165,6 +203,22 @@ return false; } else { if (!this.isRemoved() && !this.level().isClientSide) { @@ -131,7 +131,7 @@ this.kill(); this.markHurt(); this.dropItem(damagesource.getEntity()); -@@ -178,6 +232,18 @@ +@@ -177,6 +231,18 @@ @Override public void move(EnumMoveType enummovetype, Vec3D vec3d) { if (!this.level().isClientSide && !this.isRemoved() && vec3d.lengthSqr() > 0.0D) { @@ -150,7 +150,7 @@ this.kill(); this.dropItem((Entity) null); } -@@ -186,13 +252,22 @@ +@@ -185,13 +251,22 @@ @Override public void push(double d0, double d1, double d2) { 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 68b8ccd011..54cf44902a 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 -@@ -96,16 +96,27 @@ +@@ -90,16 +90,27 @@ @Override protected void recalculateBoundingBox() { if (this.direction != null) { @@ -36,7 +36,7 @@ switch (enumdirection_enumaxis) { case X: -@@ -121,9 +132,10 @@ +@@ -115,9 +126,10 @@ d4 /= 32.0D; d5 /= 32.0D; d6 /= 32.0D; @@ -48,7 +48,7 @@ @Override public boolean survives() { -@@ -168,6 +180,11 @@ +@@ -162,6 +174,11 @@ return false; } else if (!damagesource.is(DamageTypeTags.IS_EXPLOSION) && !this.getItem().isEmpty()) { if (!this.level().isClientSide) { @@ -60,7 +60,7 @@ this.dropItem(damagesource.getEntity(), false); this.gameEvent(GameEvent.BLOCK_CHANGE, damagesource.getEntity()); this.playSound(this.getRemoveItemSound(), 1.0F, 1.0F); -@@ -297,13 +314,19 @@ +@@ -284,13 +301,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 02a9c4b3d5..c50e027325 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 @@ +@@ -24,6 +24,13 @@ import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; @@ -14,7 +14,7 @@ public class EntityLeash extends EntityHanging { public static final double OFFSET_Y = 0.375D; -@@ -96,6 +103,12 @@ +@@ -89,6 +96,12 @@ EntityInsentient entityinsentient = (EntityInsentient) iterator.next(); if (entityinsentient.getLeashHolder() == entityhuman) { @@ -27,7 +27,7 @@ entityinsentient.setLeashedTo(this, true); flag = true; } -@@ -104,18 +117,32 @@ +@@ -97,18 +110,32 @@ boolean flag1 = false; if (!flag) { 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 bf86a43753..106011ca4e 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; } -@@ -121,7 +133,7 @@ +@@ -126,7 +138,7 @@ @Override public void tick() { if (this.blockState.isAir()) { @@ -40,7 +40,7 @@ } else { Block block = this.blockState.getBlock(); -@@ -152,7 +164,7 @@ +@@ -154,7 +166,7 @@ this.spawnAtLocation((IMaterial) block); } @@ -49,7 +49,7 @@ } } else { IBlockData iblockdata = this.level().getBlockState(blockposition); -@@ -169,9 +181,15 @@ +@@ -171,9 +183,15 @@ this.blockState = (IBlockData) this.blockState.setValue(BlockProperties.WATERLOGGED, true); } @@ -66,7 +66,7 @@ if (block instanceof Fallable) { ((Fallable) block).onLand(this.level(), blockposition, this.blockState, iblockdata, this); } -@@ -199,19 +217,19 @@ +@@ -201,19 +219,19 @@ } } } else if (this.dropItem && this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) { 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 5b99a6716c..013cd88e03 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,6 +1,6 @@ --- a/net/minecraft/world/entity/item/EntityItem.java +++ b/net/minecraft/world/entity/item/EntityItem.java -@@ -31,6 +31,15 @@ +@@ -33,6 +33,15 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.Vec3D; @@ -16,7 +16,7 @@ public class EntityItem extends Entity implements TraceableEntity { private static final DataWatcherObject DATA_ITEM = DataWatcher.defineId(EntityItem.class, DataWatcherRegistry.ITEM_STACK); -@@ -47,6 +56,7 @@ +@@ -51,6 +60,7 @@ @Nullable public UUID target; public final float bobOffs; @@ -24,7 +24,7 @@ public EntityItem(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -125,12 +135,15 @@ +@@ -132,12 +142,15 @@ @Override public void tick() { if (this.getItem().isEmpty()) { @@ -44,7 +44,7 @@ this.xo = this.getX(); this.yo = this.getY(); -@@ -180,9 +193,11 @@ +@@ -186,9 +199,11 @@ this.mergeWithNeighbours(); } @@ -56,7 +56,7 @@ this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing(); if (!this.level().isClientSide) { -@@ -194,7 +209,13 @@ +@@ -200,7 +215,13 @@ } if (!this.level().isClientSide && this.age >= 6000) { @@ -71,7 +71,7 @@ } } -@@ -277,11 +298,16 @@ +@@ -283,11 +304,16 @@ } private static void merge(EntityItem entityitem, ItemStack itemstack, EntityItem entityitem1, ItemStack itemstack1) { @@ -89,7 +89,7 @@ } } -@@ -302,12 +328,17 @@ +@@ -308,12 +334,17 @@ } else if (this.level().isClientSide) { return true; } else { @@ -108,16 +108,16 @@ } return true; -@@ -354,7 +385,7 @@ +@@ -365,7 +396,7 @@ + } - this.setItem(ItemStack.of(nbttagcompound1)); if (this.getItem().isEmpty()) { - this.discard(); + this.discard(null); // CraftBukkit - add Bukkit remove cause } } -@@ -366,10 +397,50 @@ +@@ -377,10 +408,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 50e4ac33e1..9bc59fc25b 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,6 +1,6 @@ --- a/net/minecraft/world/entity/item/EntityTNTPrimed.java +++ b/net/minecraft/world/entity/item/EntityTNTPrimed.java -@@ -19,6 +19,12 @@ +@@ -17,6 +17,12 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.IBlockData; @@ -13,7 +13,7 @@ public class EntityTNTPrimed extends Entity implements TraceableEntity { private static final DataWatcherObject DATA_FUSE_ID = DataWatcher.defineId(EntityTNTPrimed.class, DataWatcherRegistry.INT); -@@ -28,6 +34,8 @@ +@@ -26,6 +32,8 @@ public static final String TAG_FUSE = "fuse"; @Nullable public EntityLiving owner; 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 b73945ea16..9854811931 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 -@@ -42,7 +42,7 @@ +@@ -39,7 +39,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 14bdba958f..98721c85ce 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 @@ -22,7 +22,7 @@ public EntityCreeper(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -218,9 +226,20 @@ +@@ -216,9 +224,20 @@ @Override public void thunderHit(WorldServer worldserver, EntityLightning entitylightning) { super.thunderHit(worldserver, entitylightning); @@ -43,18 +43,18 @@ @Override protected EnumInteractionResult mobInteract(EntityHuman entityhuman, EnumHand enumhand) { ItemStack itemstack = entityhuman.getItemInHand(enumhand); -@@ -230,8 +249,9 @@ +@@ -228,8 +247,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) { + this.entityIgniter = entityhuman; // CraftBukkit this.ignite(); - if (!itemstack.isDamageableItem()) { -+ if (itemstack.getItem().getMaxDamage() == 0) { // CraftBukkit - fix MC-264285: unbreakable flint and steels are completely consumed when igniting a creeper ++ if (itemstack.getMaxDamage() == 0) { // CraftBukkit - fix MC-264285: unbreakable flint and steels are completely consumed when igniting a creeper itemstack.shrink(1); } else { - itemstack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { -@@ -250,10 +270,19 @@ + itemstack.hurtAndBreak(1, entityhuman, getSlotForHand(enumhand)); +@@ -246,10 +266,19 @@ if (!this.level().isClientSide) { float f = this.isPowered() ? 2.0F : 1.0F; @@ -76,7 +76,7 @@ } } -@@ -264,6 +293,7 @@ +@@ -260,6 +289,7 @@ if (!collection.isEmpty()) { EntityAreaEffectCloud entityareaeffectcloud = new EntityAreaEffectCloud(this.level(), this.getX(), this.getY(), this.getZ()); @@ -84,7 +84,7 @@ entityareaeffectcloud.setRadius(2.5F); entityareaeffectcloud.setRadiusOnUse(-0.5F); entityareaeffectcloud.setWaitTime(10); -@@ -277,7 +307,7 @@ +@@ -273,7 +303,7 @@ entityareaeffectcloud.addEffect(new MobEffect(mobeffect)); } 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 index b405773eca..80279ce796 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityDrowned.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityDrowned.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityDrowned.java +++ b/net/minecraft/world/entity/monster/EntityDrowned.java -@@ -244,7 +244,7 @@ +@@ -247,7 +247,7 @@ @Override public void performRangedAttack(EntityLiving entityliving, float f) { 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 0470b2434f..9463915bdb 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 @@ -1,8 +1,8 @@ --- a/net/minecraft/world/entity/monster/EntityEnderman.java +++ b/net/minecraft/world/entity/monster/EntityEnderman.java -@@ -71,6 +71,11 @@ +@@ -68,6 +68,11 @@ + import net.minecraft.world.phys.MovingObjectPositionBlock; import net.minecraft.world.phys.Vec3D; - import org.joml.Vector3f; +// CraftBukkit start; +import org.bukkit.craftbukkit.event.CraftEventFactory; @@ -12,7 +12,7 @@ public class EntityEnderman extends EntityMonster implements IEntityAngerable { private static final UUID SPEED_MODIFIER_ATTACKING_UUID = UUID.fromString("020E0DFB-87AE-4653-9556-831010E291A0"); -@@ -115,7 +120,17 @@ +@@ -111,7 +116,17 @@ @Override public void setTarget(@Nullable EntityLiving entityliving) { @@ -31,7 +31,7 @@ AttributeModifiable attributemodifiable = this.getAttribute(GenericAttributes.MOVEMENT_SPEED); if (entityliving == null) { -@@ -130,6 +145,7 @@ +@@ -126,6 +141,7 @@ attributemodifiable.addTransientModifier(EntityEnderman.SPEED_MODIFIER_ATTACKING); } } @@ -39,25 +39,25 @@ } -@@ -493,9 +509,11 @@ +@@ -477,9 +493,11 @@ if (iblockdata2 != null) { iblockdata2 = Block.updateFromNeighbourShapes(iblockdata2, this.enderman.level(), blockposition); if (this.canPlaceBlock(world, blockposition, iblockdata2, iblockdata, iblockdata1, blockposition1)) { + if (CraftEventFactory.callEntityChangeBlockEvent(this.enderman, blockposition, iblockdata2)) { // CraftBukkit - Place event world.setBlock(blockposition, iblockdata2, 3); - world.gameEvent(GameEvent.BLOCK_PLACE, blockposition, GameEvent.a.of(this.enderman, iblockdata2)); + world.gameEvent((Holder) GameEvent.BLOCK_PLACE, blockposition, GameEvent.a.of(this.enderman, iblockdata2)); this.enderman.setCarriedBlock((IBlockData) null); + } // CraftBukkit } } -@@ -534,9 +552,11 @@ +@@ -518,9 +536,11 @@ boolean flag = movingobjectpositionblock.getBlockPos().equals(blockposition); if (iblockdata.is(TagsBlock.ENDERMAN_HOLDABLE) && flag) { + if (CraftEventFactory.callEntityChangeBlockEvent(this.enderman, blockposition, Blocks.AIR.defaultBlockState())) { // CraftBukkit - Place event world.removeBlock(blockposition, false); - world.gameEvent(GameEvent.BLOCK_DESTROY, blockposition, GameEvent.a.of(this.enderman, iblockdata)); + world.gameEvent((Holder) GameEvent.BLOCK_DESTROY, blockposition, GameEvent.a.of(this.enderman, iblockdata)); this.enderman.setCarriedBlock(iblockdata.getBlock().defaultBlockState()); + } // CraftBukkit } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityEndermite.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityEndermite.patch index e65dbc1ef4..6ba9863189 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityEndermite.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntityEndermite.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/entity/monster/EntityEndermite.java +++ b/net/minecraft/world/entity/monster/EntityEndermite.java -@@ -29,6 +29,10 @@ +@@ -25,6 +25,10 @@ + import net.minecraft.world.level.World; import net.minecraft.world.level.block.state.IBlockData; - import org.joml.Vector3f; +// CraftBukkit start +import org.bukkit.event.entity.EntityRemoveEvent; @@ -11,7 +11,7 @@ public class EntityEndermite extends EntityMonster { private static final int MAX_LIFE = 2400; -@@ -122,7 +126,7 @@ +@@ -113,7 +117,7 @@ } if (this.life >= 2400) { 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 c3fa3d030d..e49d29c823 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,11 +1,11 @@ --- a/net/minecraft/world/entity/monster/EntityEvoker.java +++ b/net/minecraft/world/entity/monster/EntityEvoker.java -@@ -200,7 +200,7 @@ +@@ -213,7 +213,7 @@ worldserver.getScoreboard().addPlayerToTeam(entityvex.getScoreboardName(), scoreboardteam); } - worldserver.addFreshEntityWithPassengers(entityvex); + worldserver.addFreshEntityWithPassengers(entityvex, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPELL); // CraftBukkit - Add SpawnReason - worldserver.gameEvent(GameEvent.ENTITY_PLACE, blockposition, GameEvent.a.of((Entity) EntityEvoker.this)); + worldserver.gameEvent((Holder) GameEvent.ENTITY_PLACE, blockposition, GameEvent.a.of((Entity) EntityEvoker.this)); } } 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 b13f60c7ee..cb043c6e75 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 -@@ -348,6 +348,8 @@ +@@ -331,6 +331,8 @@ EntityLargeFireball entitylargefireball = new EntityLargeFireball(world, this.ghast, d2, d3, d4, 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 ca9e89b61e..b36812b76d 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 -@@ -63,6 +63,7 @@ +@@ -59,6 +59,7 @@ private boolean clientSideTouchedGround; @Nullable public PathfinderGoalRandomStroll randomStrollGoal; @@ -8,7 +8,7 @@ public EntityGuardian(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -78,7 +79,7 @@ +@@ -74,7 +75,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 d1e4065c39..c708cf101b 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,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityGuardianElder.java +++ b/net/minecraft/world/entity/monster/EntityGuardianElder.java -@@ -70,7 +70,7 @@ +@@ -67,7 +67,7 @@ super.customServerAiStep(); if ((this.tickCount + this.getId()) % 1200 == 0) { MobEffect mobeffect = new MobEffect(MobEffects.DIG_SLOWDOWN, 6000, 2); 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 a749b7a0e5..b43c73c23f 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 -@@ -228,7 +228,7 @@ +@@ -215,7 +215,7 @@ @Override protected void performSpellCasting() { @@ -9,7 +9,7 @@ } @Nullable -@@ -279,7 +279,7 @@ +@@ -266,7 +266,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 a25bbe31a5..2ec51fd6fe 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 -@@ -16,6 +16,10 @@ +@@ -17,6 +17,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); -@@ -155,6 +159,11 @@ +@@ -158,6 +162,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 d1fe7ee4b9..2889edc24d 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,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityPhantom.java +++ b/net/minecraft/world/entity/monster/EntityPhantom.java -@@ -543,14 +543,14 @@ +@@ -521,14 +521,14 @@ List list = EntityPhantom.this.level().getNearbyPlayers(this.attackTargeting, EntityPhantom.this, EntityPhantom.this.getBoundingBox().inflate(16.0D, 64.0D, 16.0D)); if (!list.isEmpty()) { 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 0c71b9df7e..108f4665c6 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntityPigZombie.java +++ b/net/minecraft/world/entity/monster/EntityPigZombie.java -@@ -150,7 +150,7 @@ +@@ -148,7 +148,7 @@ }).filter((entitypigzombie) -> { return !entitypigzombie.isAlliedTo((Entity) this.getTarget()); }).forEach((entitypigzombie) -> { @@ -9,7 +9,7 @@ }); } -@@ -159,7 +159,7 @@ +@@ -157,7 +157,7 @@ } @Override @@ -18,7 +18,7 @@ if (this.getTarget() == null && entityliving != null) { this.playFirstAngerSoundIn = EntityPigZombie.FIRST_ANGER_SOUND_DELAY.sample(this.random); this.ticksUntilNextAlert = EntityPigZombie.ALERT_INTERVAL.sample(this.random); -@@ -169,12 +169,21 @@ +@@ -167,12 +167,21 @@ this.setLastHurtByPlayer((EntityHuman) entityliving); } 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 719f3af548..d139655759 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 -@@ -51,6 +51,10 @@ +@@ -44,6 +44,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); -@@ -213,7 +217,7 @@ +@@ -192,7 +196,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 feae2dad01..0716d305c8 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,8 +1,8 @@ --- a/net/minecraft/world/entity/monster/EntityRavager.java +++ b/net/minecraft/world/entity/monster/EntityRavager.java -@@ -43,6 +43,10 @@ +@@ -42,6 +42,10 @@ + import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; - import org.joml.Vector3f; +// CraftBukkit start +import org.bukkit.craftbukkit.event.CraftEventFactory; @@ -11,7 +11,7 @@ public class EntityRavager extends EntityRaider { private static final Predicate NO_RAVAGER_AND_ALIVE = (entity) -> { -@@ -153,6 +157,11 @@ +@@ -146,6 +150,11 @@ Block block = iblockdata.getBlock(); if (block instanceof BlockLeaves) { 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 1a9d64e269..f70888603b 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 -@@ -59,6 +59,12 @@ +@@ -58,6 +58,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 UUID COVERED_ARMOR_MODIFIER_UUID = UUID.fromString("7E0292F2-9434-48D5-A29F-9583AF7DF27F"); -@@ -400,6 +406,14 @@ +@@ -401,6 +407,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); -@@ -470,7 +484,7 @@ +@@ -471,7 +485,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 8467a5fa91..e1f1759175 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,8 +1,8 @@ --- a/net/minecraft/world/entity/monster/EntitySilverfish.java +++ b/net/minecraft/world/entity/monster/EntitySilverfish.java -@@ -34,6 +34,11 @@ +@@ -30,6 +30,11 @@ + import net.minecraft.world.level.block.BlockMonsterEggs; import net.minecraft.world.level.block.state.IBlockData; - import org.joml.Vector3f; +// CraftBukkit start +import org.bukkit.craftbukkit.event.CraftEventFactory; @@ -12,7 +12,7 @@ public class EntitySilverfish extends EntityMonster { @Nullable -@@ -176,6 +181,11 @@ +@@ -157,6 +162,11 @@ Block block = iblockdata.getBlock(); if (block instanceof BlockMonsterEggs) { @@ -24,7 +24,7 @@ if (world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) { world.destroyBlock(blockposition1, true, this.silverfish); } else { -@@ -245,9 +255,14 @@ +@@ -226,9 +236,14 @@ IBlockData iblockdata = world.getBlockState(blockposition); if (BlockMonsterEggs.isCompatibleHostBlock(iblockdata)) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySkeletonWither.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySkeletonWither.patch index b5f342f3e1..b9dc3f1baa 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySkeletonWither.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySkeletonWither.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/EntitySkeletonWither.java +++ b/net/minecraft/world/entity/monster/EntitySkeletonWither.java -@@ -111,7 +111,7 @@ +@@ -96,7 +96,7 @@ return false; } else { if (entity instanceof EntityLiving) { 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 040b5403eb..e5e51ef859 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 -@@ -44,6 +44,15 @@ +@@ -43,6 +43,15 @@ + import net.minecraft.world.level.levelgen.SeededRandom; import net.minecraft.world.phys.Vec3D; - import org.joml.Vector3f; +// 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); -@@ -192,11 +201,18 @@ +@@ -193,11 +202,18 @@ @Override public EntityTypes getType() { @@ -36,7 +36,7 @@ int i = this.getSize(); if (!this.level().isClientSide && i > 1 && this.isDeadOrDying()) { -@@ -206,6 +222,19 @@ +@@ -208,6 +224,19 @@ int j = i / 2; int k = 2 + this.random.nextInt(3); @@ -54,12 +54,12 @@ + // CraftBukkit end + for (int l = 0; l < k; ++l) { - float f1 = ((float) (l % 2) - 0.5F) * f; - float f2 = ((float) (l / 2) - 0.5F) * f; -@@ -221,12 +250,21 @@ + float f2 = ((float) (l % 2) - 0.5F) * f1; + float f3 = ((float) (l / 2) - 0.5F) * f1; +@@ -223,12 +252,21 @@ entityslime.setInvulnerable(this.isInvulnerable()); entityslime.setSize(j, true); - entityslime.moveTo(this.getX() + (double) f1, this.getY() + 0.5D, this.getZ() + (double) f2, this.random.nextFloat() * 360.0F, 0.0F); + 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 } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySpider.patch b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySpider.patch index 530bbaf31d..128d325fae 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySpider.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/monster/EntitySpider.patch @@ -1,11 +1,11 @@ --- a/net/minecraft/world/entity/monster/EntitySpider.java +++ b/net/minecraft/world/entity/monster/EntitySpider.java -@@ -182,7 +182,7 @@ - MobEffectList mobeffectlist = entityspider_groupdataspider.effect; +@@ -172,7 +172,7 @@ + Holder holder = entityspider_groupdataspider.effect; - if (mobeffectlist != null) { -- this.addEffect(new MobEffect(mobeffectlist, -1)); -+ this.addEffect(new MobEffect(mobeffectlist, -1), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.SPIDER_SPAWN); // CraftBukkit + if (holder != null) { +- this.addEffect(new MobEffect(holder, -1)); ++ this.addEffect(new MobEffect(holder, -1), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.SPIDER_SPAWN); // CraftBukkit } } 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 d88bba7677..79cc944e85 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 -@@ -404,7 +404,7 @@ +@@ -383,7 +383,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 27eff7ad40..eef711a29c 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,11 +1,11 @@ --- a/net/minecraft/world/entity/monster/EntityWitch.java +++ b/net/minecraft/world/entity/monster/EntityWitch.java -@@ -134,7 +134,7 @@ - while (iterator.hasNext()) { - MobEffect mobeffect = (MobEffect) iterator.next(); +@@ -124,7 +124,7 @@ + PotionContents potioncontents = (PotionContents) itemstack.get(DataComponents.POTION_CONTENTS); -- this.addEffect(new MobEffect(mobeffect)); -+ this.addEffect(new MobEffect(mobeffect), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.ATTACK); // CraftBukkit - } - } + if (itemstack.is(Items.POTION) && potioncontents != null) { +- potioncontents.forEachEffect(this::addEffect); ++ potioncontents.forEachEffect((effect) -> this.addEffect(effect, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.ATTACK)); // CraftBukkit } + + this.gameEvent(GameEvent.DRINK); 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 1c62de83fa..2e91629171 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,8 +1,8 @@ --- a/net/minecraft/world/entity/monster/EntityZombie.java +++ b/net/minecraft/world/entity/monster/EntityZombie.java -@@ -67,6 +67,15 @@ +@@ -64,6 +64,15 @@ + import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.IBlockData; - import org.joml.Vector3f; +// CraftBukkit start +import net.minecraft.server.MinecraftServer; @@ -16,7 +16,7 @@ public class EntityZombie extends EntityMonster { private static final UUID SPEED_MODIFIER_BABY_UUID = UUID.fromString("B9766B59-9566-4402-BC1F-2EE2A276D836"); -@@ -87,6 +96,7 @@ +@@ -84,6 +93,7 @@ private boolean canBreakDoors; private int inWaterTime; public int conversionTime; @@ -24,7 +24,7 @@ public EntityZombie(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -203,7 +213,10 @@ +@@ -200,7 +210,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(); } -@@ -220,6 +233,7 @@ +@@ -217,6 +230,7 @@ } super.tick(); @@ -44,7 +44,7 @@ } @Override -@@ -252,6 +266,7 @@ +@@ -249,6 +263,7 @@ } public void startUnderWaterConversion(int i) { @@ -52,7 +52,7 @@ this.conversionTime = i; this.getEntityData().set(EntityZombie.DATA_DROWNED_CONVERSION_ID, true); } -@@ -265,11 +280,15 @@ +@@ -262,11 +277,15 @@ } protected void convertToZombieType(EntityTypes entitytypes) { @@ -69,35 +69,35 @@ } } -@@ -309,9 +328,9 @@ - if (SpawnerCreature.isSpawnPositionOk(entitypositiontypes_surface, this.level(), blockposition, entitytypes) && EntityPositionTypes.checkSpawnRules(entitytypes, worldserver, EnumMobSpawn.REINFORCEMENT, blockposition, this.level().random)) { +@@ -305,9 +324,9 @@ + if (EntityPositionTypes.isSpawnPositionOk(entitytypes, this.level(), blockposition) && EntityPositionTypes.checkSpawnRules(entitytypes, worldserver, EnumMobSpawn.REINFORCEMENT, blockposition, this.level().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())) { - entityzombie.setTarget(entityliving); + entityzombie.setTarget(entityliving, EntityTargetEvent.TargetReason.REINFORCEMENT_TARGET, true); // CraftBukkit - entityzombie.finalizeSpawn(worldserver, this.level().getCurrentDifficultyAt(entityzombie.blockPosition()), EnumMobSpawn.REINFORCEMENT, (GroupDataEntity) null, (NBTTagCompound) null); + entityzombie.finalizeSpawn(worldserver, this.level().getCurrentDifficultyAt(entityzombie.blockPosition()), EnumMobSpawn.REINFORCEMENT, (GroupDataEntity) null); - worldserver.addFreshEntityWithPassengers(entityzombie); + worldserver.addFreshEntityWithPassengers(entityzombie, CreatureSpawnEvent.SpawnReason.REINFORCEMENTS); // CraftBukkit - this.getAttribute(GenericAttributes.SPAWN_REINFORCEMENTS_CHANCE).addPermanentModifier(new AttributeModifier("Zombie reinforcement caller charge", -0.05000000074505806D, AttributeModifier.Operation.ADDITION)); - entityzombie.getAttribute(GenericAttributes.SPAWN_REINFORCEMENTS_CHANCE).addPermanentModifier(new AttributeModifier("Zombie reinforcement callee charge", -0.05000000074505806D, AttributeModifier.Operation.ADDITION)); + this.getAttribute(GenericAttributes.SPAWN_REINFORCEMENTS_CHANCE).addPermanentModifier(new AttributeModifier("Zombie reinforcement caller charge", -0.05000000074505806D, AttributeModifier.Operation.ADD_VALUE)); + entityzombie.getAttribute(GenericAttributes.SPAWN_REINFORCEMENTS_CHANCE).addPermanentModifier(new AttributeModifier("Zombie reinforcement callee charge", -0.05000000074505806D, AttributeModifier.Operation.ADD_VALUE)); break; -@@ -332,7 +351,14 @@ +@@ -328,7 +347,14 @@ float f = this.level().getCurrentDifficultyAt(this.blockPosition()).getEffectiveDifficulty(); if (this.getMainHandItem().isEmpty() && this.isOnFire() && this.random.nextFloat() < f * 0.3F) { -- entity.setSecondsOnFire(2 * (int) f); +- entity.igniteForSeconds(2 * (int) f); + // CraftBukkit start + EntityCombustByEntityEvent event = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), 2 * (int) f); // PAIL: fixme + this.level().getCraftServer().getPluginManager().callEvent(event); + + if (!event.isCancelled()) { -+ entity.setSecondsOnFire(event.getDuration(), false); ++ entity.igniteForSeconds(event.getDuration(), false); + } + // CraftBukkit end } } -@@ -414,8 +440,17 @@ +@@ -403,8 +429,17 @@ if (worldserver.getDifficulty() != EnumDifficulty.HARD && this.random.nextBoolean()) { return flag; } @@ -115,10 +115,10 @@ + // CraftBukkit end if (entityzombievillager != null) { - entityzombievillager.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entityzombievillager.blockPosition()), EnumMobSpawn.CONVERSION, new EntityZombie.GroupDataZombie(false, true), (NBTTagCompound) null); -@@ -423,15 +458,17 @@ + entityzombievillager.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entityzombievillager.blockPosition()), EnumMobSpawn.CONVERSION, new EntityZombie.GroupDataZombie(false, true)); +@@ -412,15 +447,17 @@ entityzombievillager.setGossips((NBTBase) entityvillager.getGossips().store(DynamicOpsNBT.INSTANCE)); - entityzombievillager.setTradeOffers(entityvillager.getOffers().createTag()); + entityzombievillager.setTradeOffers(entityvillager.getOffers().copy()); entityzombievillager.setVillagerXp(entityvillager.getVillagerXp()); - if (!this.isSilent()) { - worldserver.levelEvent((EntityHuman) null, 1026, this.blockPosition(), 0); @@ -139,8 +139,8 @@ } @Override -@@ -484,7 +521,7 @@ - entitychicken1.finalizeSpawn(worldaccess, difficultydamagescaler, EnumMobSpawn.JOCKEY, (GroupDataEntity) null, (NBTTagCompound) null); +@@ -471,7 +508,7 @@ + entitychicken1.finalizeSpawn(worldaccess, difficultydamagescaler, EnumMobSpawn.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 f02083ca8a..dab22fcd43 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 -@@ -60,7 +60,7 @@ +@@ -58,7 +58,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 bfa1832ada..4188ddaa1b 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,7 +1,7 @@ --- a/net/minecraft/world/entity/monster/EntityZombieVillager.java +++ b/net/minecraft/world/entity/monster/EntityZombieVillager.java -@@ -50,6 +50,13 @@ - import org.joml.Vector3f; +@@ -48,6 +48,13 @@ + import net.minecraft.world.level.block.state.IBlockData; import org.slf4j.Logger; +// CraftBukkit start @@ -14,15 +14,15 @@ public class EntityZombieVillager extends EntityZombie implements VillagerDataHolder { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -67,6 +74,7 @@ +@@ -65,6 +72,7 @@ @Nullable - private NBTTagCompound tradeOffers; + private MerchantRecipeList tradeOffers; private int villagerXp; + private int lastTick = MinecraftServer.currentTick; // CraftBukkit - add field public EntityZombieVillager(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -85,7 +93,7 @@ +@@ -83,7 +91,7 @@ @Override public void addAdditionalSaveData(NBTTagCompound nbttagcompound) { super.addAdditionalSaveData(nbttagcompound); @@ -31,7 +31,16 @@ Logger logger = EntityZombieVillager.LOGGER; Objects.requireNonNull(logger); -@@ -141,6 +149,10 @@ +@@ -118,7 +126,7 @@ + } + + if (nbttagcompound.contains("Offers")) { +- DataResult dataresult1 = MerchantRecipeList.CODEC.parse(this.registryAccess().createSerializationContext(DynamicOpsNBT.INSTANCE), nbttagcompound.get("Offers")); ++ DataResult dataresult1 = MerchantRecipeList.CODEC.parse(this.registryAccess().createSerializationContext(DynamicOpsNBT.INSTANCE), nbttagcompound.get("Offers")); // CraftBukkit - decompile error + Logger logger1 = EntityZombieVillager.LOGGER; + + Objects.requireNonNull(logger1); +@@ -145,6 +153,10 @@ public void tick() { if (!this.level().isClientSide && this.isAlive() && this.isConverting()) { int i = this.getConversionProgress(); @@ -42,7 +51,7 @@ this.villagerConversionTime -= i; if (this.villagerConversionTime <= 0) { -@@ -149,6 +161,7 @@ +@@ -153,6 +165,7 @@ } super.tick(); @@ -50,7 +59,7 @@ } @Override -@@ -192,8 +205,10 @@ +@@ -193,8 +206,10 @@ this.conversionStarter = uuid; this.villagerConversionTime = i; this.getEntityData().set(EntityZombieVillager.DATA_CONVERTING_ID, true); @@ -63,7 +72,7 @@ this.level().broadcastEntityEvent(this, (byte) 16); } -@@ -210,7 +225,13 @@ +@@ -211,7 +226,13 @@ } private void finishConversion(WorldServer worldserver) { @@ -78,7 +87,7 @@ EnumItemSlot[] aenumitemslot = EnumItemSlot.values(); int i = aenumitemslot.length; -@@ -225,7 +246,9 @@ +@@ -226,7 +247,9 @@ double d0 = (double) this.getEquipmentDropChance(enumitemslot); if (d0 > 1.0D) { @@ -88,7 +97,7 @@ } } } -@@ -252,7 +275,7 @@ +@@ -253,7 +276,7 @@ } } 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 e52f9a28e5..f37c28b69c 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 -@@ -55,6 +55,18 @@ +@@ -54,6 +54,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); -@@ -75,6 +87,10 @@ +@@ -73,6 +85,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,10 +30,10 @@ public EntityPiglin(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -93,6 +109,14 @@ +@@ -91,6 +107,14 @@ } - this.writeInventoryToTag(nbttagcompound); + this.writeInventoryToTag(nbttagcompound, this.registryAccess()); + // CraftBukkit start + NBTTagList barterList = new NBTTagList(); + allowedBarterItems.stream().map(BuiltInRegistries.ITEM::getKey).map(MinecraftKey::toString).map(NBTTagString::valueOf).forEach(barterList::add); @@ -45,10 +45,10 @@ } @Override -@@ -101,6 +125,10 @@ +@@ -99,6 +123,10 @@ this.setBaby(nbttagcompound.getBoolean("IsBaby")); this.setCannotHunt(nbttagcompound.getBoolean("CannotHunt")); - this.readInventoryFromTag(nbttagcompound); + 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)); @@ -56,7 +56,7 @@ } @VisibleForDebug -@@ -220,7 +248,7 @@ +@@ -216,7 +244,7 @@ @Override public BehaviorController getBrain() { @@ -65,7 +65,7 @@ } @Override -@@ -360,7 +388,7 @@ +@@ -349,7 +377,7 @@ } protected void holdInOffHand(ItemStack itemstack) { @@ -74,7 +74,7 @@ this.setItemSlot(EnumItemSlot.OFFHAND, itemstack); this.setGuaranteedDrop(EnumItemSlot.OFFHAND); } else { -@@ -386,8 +414,8 @@ +@@ -375,8 +403,8 @@ if (EnchantmentManager.hasBindingCurse(itemstack1)) { return false; } else { @@ -85,7 +85,7 @@ return flag && !flag1 ? true : (!flag && flag1 ? false : (this.isAdult() && !itemstack.is(Items.CROSSBOW) && itemstack1.is(Items.CROSSBOW) ? false : super.canReplaceCurrentItem(itemstack, itemstack1))); } -@@ -416,7 +444,7 @@ +@@ -405,7 +433,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 6c912b25f0..0df483cf7f 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,6 +1,6 @@ --- a/net/minecraft/world/entity/monster/piglin/EntityPiglinAbstract.java +++ b/net/minecraft/world/entity/monster/piglin/EntityPiglinAbstract.java -@@ -115,7 +115,7 @@ +@@ -94,7 +94,7 @@ } protected void finishConversion(WorldServer worldserver) { @@ -9,12 +9,3 @@ if (entitypigzombie != null) { entitypigzombie.addEffect(new MobEffect(MobEffects.CONFUSION, 200, 0)); -@@ -132,7 +132,7 @@ - @Nullable - @Override - public EntityLiving getTarget() { -- return (EntityLiving) this.brain.getMemory(MemoryModuleType.ATTACK_TARGET).orElse((Object) null); -+ return (EntityLiving) this.brain.getMemory(MemoryModuleType.ATTACK_TARGET).orElse(null); // CraftBukkit - decompile error - } - - protected boolean isHoldingMeleeWeapon() { 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 941d85899d..3150aa5f21 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 @@ -50,7 +50,7 @@ + Optional optional = getSoundForCurrentActivity(entitypiglin); // CraftBukkit - decompile error Objects.requireNonNull(entitypiglin); - optional.ifPresent(entitypiglin::playSoundEvent); + optional.ifPresent(entitypiglin::makeSound); @@ -233,23 +242,27 @@ stopWalking(entitypiglin); ItemStack itemstack; @@ -141,7 +141,7 @@ protected static boolean isLovedItem(ItemStack itemstack) { return itemstack.is(TagsItem.PIGLIN_LOVED); } -@@ -481,7 +505,7 @@ +@@ -479,7 +503,7 @@ } protected static boolean canAdmire(EntityPiglin entitypiglin, ItemStack itemstack) { @@ -150,7 +150,7 @@ } protected static void wasHurtBy(EntityPiglin entitypiglin, EntityLiving entityliving) { -@@ -738,6 +762,12 @@ +@@ -736,6 +760,12 @@ return entitypiglin.getBrain().hasMemoryValue(MemoryModuleType.ADMIRING_ITEM); } @@ -163,7 +163,7 @@ private static boolean isBarterCurrency(ItemStack itemstack) { return itemstack.is(PiglinAI.BARTERING_ITEM); } -@@ -775,7 +805,7 @@ +@@ -773,7 +803,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 ae64567f37..a4f91ac370 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 -@@ -373,7 +373,7 @@ +@@ -371,7 +371,7 @@ @Override public BehaviorController getBrain() { @@ -9,7 +9,7 @@ } @Override -@@ -414,13 +414,13 @@ +@@ -408,13 +408,13 @@ public static void applyDarknessAround(WorldServer worldserver, Vec3D vec3d, @Nullable Entity entity, int i) { MobEffect mobeffect = new MobEffect(MobEffects.DARKNESS, 260, 0, false, false); @@ -25,7 +25,7 @@ Logger logger = Warden.LOGGER; Objects.requireNonNull(logger); -@@ -445,7 +445,7 @@ +@@ -439,7 +439,7 @@ dataresult = AngerManagement.codec(this::canTargetEntity).parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("anger"))); logger = Warden.LOGGER; Objects.requireNonNull(logger); @@ -34,7 +34,7 @@ this.angerManagement = angermanagement; }); this.syncClientAngerLevel(); -@@ -455,7 +455,7 @@ +@@ -449,7 +449,7 @@ dataresult = VibrationSystem.a.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.getCompound("listener"))); logger = Warden.LOGGER; Objects.requireNonNull(logger); @@ -43,25 +43,7 @@ this.vibrationData = vibrationsystem_a; }); } -@@ -489,7 +489,7 @@ - public void increaseAngerAt(@Nullable Entity entity, int i, boolean flag) { - if (!this.isNoAi() && this.canTargetEntity(entity)) { - WardenAi.setDigCooldown(this); -- boolean flag1 = !(this.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).orElse((Object) null) instanceof EntityHuman); -+ boolean flag1 = !(this.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).orElse(null) instanceof EntityHuman); // CraftBukkit - decompile error - int j = this.angerManagement.increaseAnger(entity, i); - - if (entity instanceof EntityHuman && flag1 && AngerLevel.byAnger(j).isAngry()) { -@@ -510,7 +510,7 @@ - @Nullable - @Override - public EntityLiving getTarget() { -- return (EntityLiving) this.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).orElse((Object) null); -+ return (EntityLiving) this.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).orElse(null); // CraftBukkit - decompile error - } - - @Override -@@ -553,7 +553,7 @@ +@@ -547,7 +547,7 @@ public void setAttackTarget(EntityLiving entityliving) { this.getBrain().eraseMemory(MemoryModuleType.ROAR_TARGET); @@ -70,3 +52,18 @@ this.getBrain().eraseMemory(MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE); SonicBoom.setCooldown(this, 200); } +@@ -582,12 +582,12 @@ + + @Override + protected NavigationAbstract createNavigation(World world) { +- return new Navigation(this, this, world) { ++ return new Navigation(this, world) { // CraftBukkit - decompile error + @Override + protected Pathfinder createPathFinder(int i) { + this.nodeEvaluator = new PathfinderNormal(); + this.nodeEvaluator.setCanPassDoors(true); +- return new Pathfinder(this, this.nodeEvaluator, i) { ++ return new Pathfinder(this.nodeEvaluator, i) { // CraftBukkit - decompile error + @Override + protected float distance(PathPoint pathpoint, PathPoint pathpoint1) { + return pathpoint.distanceToXZ(pathpoint1); 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 d5da963e79..e4f070ce7c 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 @@ -73,7 +73,16 @@ Logger logger = EntityVillager.LOGGER; Objects.requireNonNull(logger); -@@ -834,9 +855,14 @@ +@@ -513,7 +534,7 @@ + public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { + super.readAdditionalSaveData(nbttagcompound); + if (nbttagcompound.contains("VillagerData", 10)) { +- DataResult dataresult = VillagerData.CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("VillagerData")); ++ DataResult dataresult = VillagerData.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("VillagerData"))); + Logger logger = EntityVillager.LOGGER; + + Objects.requireNonNull(logger); +@@ -826,9 +847,14 @@ } entitywitch.setPersistenceRequired(); @@ -90,7 +99,7 @@ } else { super.thunderHit(worldserver, entitylightning); } -@@ -933,7 +959,7 @@ +@@ -925,7 +951,7 @@ }).limit(5L).collect(Collectors.toList()); if (list1.size() >= j) { @@ -99,7 +108,7 @@ list.forEach(SensorGolemLastSeen::golemDetected); } } -@@ -990,7 +1016,7 @@ +@@ -982,7 +1008,7 @@ @Override public void startSleeping(BlockPosition blockposition) { super.startSleeping(blockposition); @@ -108,7 +117,7 @@ this.brain.eraseMemory(MemoryModuleType.WALK_TARGET); this.brain.eraseMemory(MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE); } -@@ -998,7 +1024,7 @@ +@@ -990,7 +1016,7 @@ @Override public void stopSleeping() { super.stopSleeping(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/npc/EntityVillagerAbstract.patch b/paper-server/nms-patches/net/minecraft/world/entity/npc/EntityVillagerAbstract.patch index d6c61da367..06804fd12d 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/npc/EntityVillagerAbstract.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/npc/EntityVillagerAbstract.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/entity/npc/EntityVillagerAbstract.java +++ b/net/minecraft/world/entity/npc/EntityVillagerAbstract.java -@@ -35,8 +35,24 @@ - import net.minecraft.world.level.pathfinder.PathType; +@@ -40,8 +40,24 @@ import net.minecraft.world.phys.Vec3D; + import org.slf4j.Logger; +// CraftBukkit start +import org.bukkit.Bukkit; @@ -23,9 +23,9 @@ + } + // CraftBukkit end private static final DataWatcherObject DATA_UNHAPPY_COUNTER = DataWatcher.defineId(EntityVillagerAbstract.class, DataWatcherRegistry.INT); + private static final Logger LOGGER = LogUtils.getLogger(); public static final int VILLAGER_SLOT_OFFSET = 300; - private static final int VILLAGER_INVENTORY_SIZE = 8; -@@ -44,7 +60,7 @@ +@@ -50,7 +66,7 @@ private EntityHuman tradingPlayer; @Nullable protected MerchantRecipeList offers; @@ -34,7 +34,16 @@ public EntityVillagerAbstract(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -233,7 +249,16 @@ +@@ -173,7 +189,7 @@ + public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { + super.readAdditionalSaveData(nbttagcompound); + if (nbttagcompound.contains("Offers")) { +- DataResult dataresult = MerchantRecipeList.CODEC.parse(this.registryAccess().createSerializationContext(DynamicOpsNBT.INSTANCE), nbttagcompound.get("Offers")); ++ DataResult dataresult = MerchantRecipeList.CODEC.parse(this.registryAccess().createSerializationContext(DynamicOpsNBT.INSTANCE), nbttagcompound.get("Offers")); // CraftBukkit - decompile error + Logger logger = EntityVillagerAbstract.LOGGER; + + Objects.requireNonNull(logger); +@@ -240,7 +256,16 @@ MerchantRecipe merchantrecipe = ((VillagerTrades.IMerchantRecipeOption) arraylist.remove(this.random.nextInt(arraylist.size()))).getOffer(this, this.random); if (merchantrecipe != null) { 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 5b5518d48b..0c1a8c8083 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 @@ -41,7 +41,7 @@ } } -@@ -244,7 +262,7 @@ +@@ -243,7 +261,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 72b47a1d91..3f06982ab1 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 -@@ -6,6 +6,10 @@ +@@ -7,6 +7,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"; -@@ -23,13 +27,20 @@ +@@ -24,13 +28,20 @@ return; } 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 4c164497b7..50b7e30ae4 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 -@@ -112,6 +112,22 @@ +@@ -116,6 +116,22 @@ import net.minecraft.world.scores.ScoreboardTeam; import org.slf4j.Logger; @@ -23,20 +23,20 @@ public abstract class EntityHuman extends EntityLiving { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -127,7 +143,8 @@ - public static final float SWIMMING_BB_HEIGHT = 0.6F; +@@ -135,7 +151,8 @@ public static final float DEFAULT_EYE_HEIGHT = 1.62F; - public static final EntitySize STANDING_DIMENSIONS = EntitySize.scalable(0.6F, 1.8F); -- private static final Map POSES = ImmutableMap.builder().put(EntityPose.STANDING, EntityHuman.STANDING_DIMENSIONS).put(EntityPose.SLEEPING, EntityHuman.SLEEPING_DIMENSIONS).put(EntityPose.FALL_FLYING, EntitySize.scalable(0.6F, 0.6F)).put(EntityPose.SWIMMING, EntitySize.scalable(0.6F, 0.6F)).put(EntityPose.SPIN_ATTACK, EntitySize.scalable(0.6F, 0.6F)).put(EntityPose.CROUCHING, EntitySize.scalable(0.6F, 1.5F)).put(EntityPose.DYING, EntitySize.fixed(0.2F, 0.2F)).build(); + 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)); +- private static final Map POSES = ImmutableMap.builder().put(EntityPose.STANDING, EntityHuman.STANDING_DIMENSIONS).put(EntityPose.SLEEPING, EntityHuman.SLEEPING_DIMENSIONS).put(EntityPose.FALL_FLYING, EntitySize.scalable(0.6F, 0.6F).withEyeHeight(0.4F)).put(EntityPose.SWIMMING, EntitySize.scalable(0.6F, 0.6F).withEyeHeight(0.4F)).put(EntityPose.SPIN_ATTACK, EntitySize.scalable(0.6F, 0.6F).withEyeHeight(0.4F)).put(EntityPose.CROUCHING, EntitySize.scalable(0.6F, 1.5F).withEyeHeight(1.27F).withAttachments(EntityAttachments.builder().attach(EntityAttachment.VEHICLE, EntityHuman.DEFAULT_VEHICLE_ATTACHMENT))).put(EntityPose.DYING, EntitySize.fixed(0.2F, 0.2F).withEyeHeight(1.62F)).build(); + // CraftBukkit - decompile error -+ private static final Map POSES = ImmutableMap.builder().put(EntityPose.STANDING, EntityHuman.STANDING_DIMENSIONS).put(EntityPose.SLEEPING, EntityHuman.SLEEPING_DIMENSIONS).put(EntityPose.FALL_FLYING, EntitySize.scalable(0.6F, 0.6F)).put(EntityPose.SWIMMING, EntitySize.scalable(0.6F, 0.6F)).put(EntityPose.SPIN_ATTACK, EntitySize.scalable(0.6F, 0.6F)).put(EntityPose.CROUCHING, EntitySize.scalable(0.6F, 1.5F)).put(EntityPose.DYING, EntitySize.fixed(0.2F, 0.2F)).build(); ++ private static final Map POSES = ImmutableMap.builder().put(EntityPose.STANDING, EntityHuman.STANDING_DIMENSIONS).put(EntityPose.SLEEPING, EntityHuman.SLEEPING_DIMENSIONS).put(EntityPose.FALL_FLYING, EntitySize.scalable(0.6F, 0.6F).withEyeHeight(0.4F)).put(EntityPose.SWIMMING, EntitySize.scalable(0.6F, 0.6F).withEyeHeight(0.4F)).put(EntityPose.SPIN_ATTACK, EntitySize.scalable(0.6F, 0.6F).withEyeHeight(0.4F)).put(EntityPose.CROUCHING, EntitySize.scalable(0.6F, 1.5F).withEyeHeight(1.27F).withAttachments(EntityAttachments.builder().attach(EntityAttachment.VEHICLE, EntityHuman.DEFAULT_VEHICLE_ATTACHMENT))).put(EntityPose.DYING, EntitySize.fixed(0.2F, 0.2F).withEyeHeight(1.62F)).build(); 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); -@@ -136,10 +153,10 @@ +@@ -144,10 +161,10 @@ protected static final DataWatcherObject DATA_SHOULDER_RIGHT = DataWatcher.defineId(EntityHuman.class, DataWatcherRegistry.COMPOUND_TAG); private long timeEntitySatOnShoulder; - private final PlayerInventory inventory = new PlayerInventory(this); + final PlayerInventory inventory = new PlayerInventory(this); - protected InventoryEnderChest enderChestInventory = new InventoryEnderChest(); + protected InventoryEnderChest enderChestInventory = new InventoryEnderChest(this); // CraftBukkit - add "this" to constructor public final ContainerPlayer inventoryMenu; @@ -46,9 +46,9 @@ protected int jumpTriggerTime; public float oBob; public float bob; -@@ -168,6 +185,16 @@ - public EntityFishingHook fishing; - protected float hurtDir; +@@ -181,6 +198,16 @@ + public Entity currentExplosionCause; + public boolean ignoreFallDamageFromCurrentImpulse; + // CraftBukkit start + public boolean fauxSleeping; @@ -63,7 +63,7 @@ public EntityHuman(World world, BlockPosition blockposition, float f, GameProfile gameprofile) { super(EntityTypes.PLAYER, world); this.lastItemInMainHand = ItemStack.EMPTY; -@@ -312,7 +339,7 @@ +@@ -325,7 +352,7 @@ ItemStack itemstack = this.getItemBySlot(EnumItemSlot.HEAD); if (itemstack.is(Items.TURTLE_HELMET) && !this.isEyeInFluid(TagsFluid.WATER)) { @@ -147,7 +147,7 @@ return entityitem; } } -@@ -789,7 +857,7 @@ +@@ -790,7 +858,7 @@ } if (nbttagcompound.contains("LastDeathLocation", 10)) { @@ -156,7 +156,16 @@ Logger logger = EntityHuman.LOGGER; Objects.requireNonNull(logger); -@@ -822,7 +890,7 @@ +@@ -798,7 +866,7 @@ + } + + if (nbttagcompound.contains("current_explosion_impact_pos", 9)) { +- DataResult dataresult1 = Vec3D.CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("current_explosion_impact_pos")); ++ DataResult dataresult1 = Vec3D.CODEC.parse(DynamicOpsNBT.INSTANCE, nbttagcompound.get("current_explosion_impact_pos")); // CraftBukkit - decompile error + Logger logger1 = EntityHuman.LOGGER; + + Objects.requireNonNull(logger1); +@@ -834,7 +902,7 @@ } this.getLastDeathLocation().flatMap((globalpos) -> { @@ -165,7 +174,7 @@ Logger logger = EntityHuman.LOGGER; Objects.requireNonNull(logger); -@@ -849,12 +917,12 @@ +@@ -866,12 +934,12 @@ return false; } else { if (!this.level().isClientSide) { @@ -180,7 +189,7 @@ } if (this.level().getDifficulty() == EnumDifficulty.EASY) { -@@ -866,7 +934,13 @@ +@@ -883,7 +951,13 @@ } } @@ -195,7 +204,7 @@ } } } -@@ -886,10 +960,29 @@ +@@ -903,10 +977,29 @@ } public boolean canHarmPlayer(EntityHuman entityhuman) { @@ -228,7 +237,7 @@ } @Override -@@ -931,8 +1024,13 @@ +@@ -946,8 +1039,13 @@ } } @@ -243,7 +252,7 @@ if (!this.isInvulnerableTo(damagesource)) { f = this.getDamageAfterArmorAbsorb(damagesource, f); f = this.getDamageAfterMagicAbsorb(damagesource, f); -@@ -947,7 +1045,7 @@ +@@ -962,7 +1060,7 @@ } if (f != 0.0F) { @@ -252,7 +261,7 @@ this.getCombatTracker().recordDamage(damagesource, f); this.setHealth(this.getHealth() - f); if (f < 3.4028235E37F) { -@@ -957,6 +1055,7 @@ +@@ -972,6 +1070,7 @@ this.gameEvent(GameEvent.ENTITY_DAMAGE); } } @@ -260,119 +269,128 @@ } @Override -@@ -1121,7 +1220,7 @@ +@@ -1127,10 +1226,16 @@ f *= 0.2F + f2 * f2 * 0.8F; f1 *= f2; - this.resetAttackStrengthTicker(); -+ // this.resetAttackCooldown(); // CraftBukkit - Moved to EntityLiving to reset the cooldown after the damage is dealt - if (f > 0.0F || f1 > 0.0F) { - boolean flag = f2 > 0.9F; - boolean flag1 = false; -@@ -1160,8 +1259,15 @@ - if (entity instanceof EntityLiving) { - f3 = ((EntityLiving) entity).getHealth(); - if (j > 0 && !entity.isOnFire()) { -- flag4 = true; -- entity.setSecondsOnFire(1); -+ // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item -+ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), 1); -+ org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent); -+ -+ if (!combustEvent.isCancelled()) { -+ flag4 = true; -+ entity.setSecondsOnFire(combustEvent.getDuration(), false); -+ } -+ // CraftBukkit end - } - } ++ // this.resetAttackStrengthTicker(); // CraftBukkit - Moved to EntityLiving to reset the cooldown after the damage is dealt + if (entity.getType().is(TagsEntity.REDIRECTABLE_PROJECTILE) && entity instanceof IProjectile) { + IProjectile iprojectile = (IProjectile) entity; -@@ -1171,7 +1277,7 @@ - if (flag5) { - if (i > 0) { - if (entity instanceof EntityLiving) { -- ((EntityLiving) entity).knockback((double) ((float) i * 0.5F), (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F))); -+ ((EntityLiving) entity).knockback((double) ((float) i * 0.5F), (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)), this, EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); // CraftBukkit - } else { - entity.push((double) (-MathHelper.sin(this.getYRot() * 0.017453292F) * (float) i * 0.5F), 0.1D, (double) (MathHelper.cos(this.getYRot() * 0.017453292F) * (float) i * 0.5F)); - } -@@ -1189,8 +1295,11 @@ - EntityLiving entityliving = (EntityLiving) iterator.next(); - - if (entityliving != this && entityliving != entity && !this.isAlliedTo((Entity) entityliving) && (!(entityliving instanceof EntityArmorStand) || !((EntityArmorStand) entityliving).isMarker()) && this.distanceToSqr((Entity) entityliving) < 9.0D) { -- entityliving.knockback(0.4000000059604645D, (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F))); -- entityliving.hurt(this.damageSources().playerAttack(this), f4); -+ // CraftBukkit start - Only apply knockback if the damage hits -+ if (entityliving.hurt(this.damageSources().playerAttack(this).sweep(), f4)) { -+ entityliving.knockback(0.4000000059604645D, (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)), this, EntityKnockbackEvent.KnockbackCause.SWEEP_ATTACK); // CraftBukkit -+ } -+ // CraftBukkit end - } - } - -@@ -1199,9 +1308,26 @@ - } - - if (entity instanceof EntityPlayer && entity.hurtMarked) { -+ // CraftBukkit start - Add Velocity Event -+ boolean cancelled = false; -+ Player player = (Player) entity.getBukkitEntity(); -+ org.bukkit.util.Vector velocity = CraftVector.toBukkit(vec3d); -+ -+ PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone()); -+ this.level().getCraftServer().getPluginManager().callEvent(event); -+ -+ if (event.isCancelled()) { -+ cancelled = true; -+ } else if (!velocity.equals(event.getVelocity())) { -+ player.setVelocity(event.getVelocity()); -+ } -+ -+ if (!cancelled) { - ((EntityPlayer) entity).connection.send(new PacketPlayOutEntityVelocity(entity)); - entity.hurtMarked = false; - entity.setDeltaMovement(vec3d); -+ } -+ // CraftBukkit end - } - - if (flag2) { -@@ -1246,7 +1372,14 @@ - - this.awardStat(StatisticList.DAMAGE_DEALT, Math.round(f5 * 10.0F)); - if (j > 0) { -- entity.setSecondsOnFire(j * 4); ++ // CraftBukkit start ++ DamageSource damagesource = this.damageSources().playerAttack(this); ++ if (CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f1, false)) { ++ return; ++ } ++ // CraftBukkit end + iprojectile.deflect(ProjectileDeflection.AIM_DEFLECT, this, this, true); + } else { + if (f > 0.0F || f1 > 0.0F) { +@@ -1171,8 +1276,15 @@ + if (entity instanceof EntityLiving) { + f3 = ((EntityLiving) entity).getHealth(); + if (j > 0 && !entity.isOnFire()) { +- flag4 = true; +- entity.igniteForSeconds(1); + // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item -+ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), j * 4); ++ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), 1); + org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent); + + if (!combustEvent.isCancelled()) { -+ entity.setSecondsOnFire(combustEvent.getDuration(), false); ++ flag4 = true; ++ entity.igniteForSeconds(combustEvent.getDuration(), false); ++ } ++ // CraftBukkit end + } + } + +@@ -1182,7 +1294,7 @@ + if (flag5) { + if (i > 0) { + if (entity instanceof EntityLiving) { +- ((EntityLiving) entity).knockback((double) ((float) i * 0.5F), (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F))); ++ ((EntityLiving) entity).knockback((double) ((float) i * 0.5F), (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)), this, EntityKnockbackEvent.KnockbackCause.ENTITY_ATTACK); // CraftBukkit + } else { + entity.push((double) (-MathHelper.sin(this.getYRot() * 0.017453292F) * (float) i * 0.5F), 0.1D, (double) (MathHelper.cos(this.getYRot() * 0.017453292F) * (float) i * 0.5F)); + } +@@ -1200,8 +1312,11 @@ + EntityLiving entityliving = (EntityLiving) iterator.next(); + + if (entityliving != this && entityliving != entity && !this.isAlliedTo((Entity) entityliving) && (!(entityliving instanceof EntityArmorStand) || !((EntityArmorStand) entityliving).isMarker()) && this.distanceToSqr((Entity) entityliving) < 9.0D) { +- entityliving.knockback(0.4000000059604645D, (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F))); +- entityliving.hurt(this.damageSources().playerAttack(this), f4); ++ // CraftBukkit start - Only apply knockback if the damage hits ++ if (entityliving.hurt(this.damageSources().playerAttack(this).sweep(), f4)) { ++ entityliving.knockback(0.4000000059604645D, (double) MathHelper.sin(this.getYRot() * 0.017453292F), (double) (-MathHelper.cos(this.getYRot() * 0.017453292F)), this, EntityKnockbackEvent.KnockbackCause.SWEEP_ATTACK); // CraftBukkit ++ } ++ // CraftBukkit end + } + } + +@@ -1210,9 +1325,26 @@ + } + + if (entity instanceof EntityPlayer && entity.hurtMarked) { ++ // CraftBukkit start - Add Velocity Event ++ boolean cancelled = false; ++ Player player = (Player) entity.getBukkitEntity(); ++ org.bukkit.util.Vector velocity = CraftVector.toBukkit(vec3d); ++ ++ PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone()); ++ this.level().getCraftServer().getPluginManager().callEvent(event); ++ ++ if (event.isCancelled()) { ++ cancelled = true; ++ } else if (!velocity.equals(event.getVelocity())) { ++ player.setVelocity(event.getVelocity()); ++ } ++ ++ if (!cancelled) { + ((EntityPlayer) entity).connection.send(new PacketPlayOutEntityVelocity(entity)); + entity.hurtMarked = false; + entity.setDeltaMovement(vec3d); + } + // CraftBukkit end } - if (this.level() instanceof WorldServer && f5 > 2.0F) { -@@ -1256,12 +1389,17 @@ + if (flag2) { +@@ -1257,7 +1389,14 @@ + + this.awardStat(StatisticList.DAMAGE_DEALT, Math.round(f5 * 10.0F)); + if (j > 0) { +- entity.igniteForSeconds(j * 4); ++ // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item ++ EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), j * 4); ++ org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent); ++ ++ if (!combustEvent.isCancelled()) { ++ entity.igniteForSeconds(combustEvent.getDuration(), false); ++ } ++ // CraftBukkit end + } + + if (this.level() instanceof WorldServer && f5 > 2.0F) { +@@ -1267,12 +1406,17 @@ + } } - } -- this.causeFoodExhaustion(0.1F); -+ this.causeFoodExhaustion(0.1F, EntityExhaustionEvent.ExhaustionReason.ATTACK); // CraftBukkit - EntityExhaustionEvent - } else { - this.level().playSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), SoundEffects.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F); - if (flag4) { - entity.clearFire(); +- this.causeFoodExhaustion(0.1F); ++ this.causeFoodExhaustion(0.1F, EntityExhaustionEvent.ExhaustionReason.ATTACK); // CraftBukkit - EntityExhaustionEvent + } else { + this.level().playSound((EntityHuman) null, this.getX(), this.getY(), this.getZ(), SoundEffects.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F); + if (flag4) { + entity.clearFire(); + } ++ // CraftBukkit start - resync on cancelled event ++ if (this instanceof EntityPlayer) { ++ ((EntityPlayer) this).getBukkitEntity().updateInventory(); ++ } ++ // CraftBukkit end } -+ // CraftBukkit start - resync on cancelled event -+ if (this instanceof EntityPlayer) { -+ ((EntityPlayer) this).getBukkitEntity().updateInventory(); -+ } -+ // CraftBukkit end } - } -@@ -1307,7 +1445,14 @@ +@@ -1310,7 +1454,14 @@ @Override public void remove(Entity.RemovalReason entity_removalreason) { @@ -388,7 +406,7 @@ this.inventoryMenu.removed(this); if (this.containerMenu != null && this.hasContainerOpen()) { this.doCloseContainer(); -@@ -1338,6 +1483,12 @@ +@@ -1346,6 +1497,12 @@ } public Either startSleepInBed(BlockPosition blockposition) { @@ -401,7 +419,7 @@ this.startSleeping(blockposition); this.sleepCounter = 0; return Either.right(Unit.INSTANCE); -@@ -1425,9 +1576,9 @@ +@@ -1433,9 +1590,9 @@ super.jumpFromGround(); this.awardStat(StatisticList.JUMP); if (this.isSprinting()) { @@ -413,7 +431,7 @@ } } -@@ -1454,7 +1605,11 @@ +@@ -1462,7 +1619,11 @@ this.setDeltaMovement(vec3d2.x, d0 * 0.6D, vec3d2.z); this.resetFallDistance(); @@ -426,7 +444,7 @@ } else { super.travel(vec3d); } -@@ -1507,12 +1662,24 @@ +@@ -1522,12 +1683,24 @@ } public void startFallFlying() { @@ -452,7 +470,7 @@ } @Override -@@ -1626,10 +1793,21 @@ +@@ -1642,10 +1815,21 @@ return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2); } @@ -475,7 +493,7 @@ } } -@@ -1715,13 +1893,20 @@ +@@ -1731,13 +1915,20 @@ @Override public void setItemSlot(EnumItemSlot enumitemslot, ItemStack itemstack) { @@ -499,7 +517,7 @@ } } -@@ -1760,26 +1945,31 @@ +@@ -1781,26 +1972,31 @@ protected void removeEntitiesOnShoulder() { if (this.timeEntitySatOnShoulder + 20L < this.level().getGameTime()) { 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 b579293e22..b790523bb8 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 -@@ -26,6 +26,13 @@ +@@ -23,6 +23,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; -@@ -43,6 +50,54 @@ +@@ -40,6 +47,54 @@ public final EntityHuman player; private int timesChanged; @@ -69,8 +69,8 @@ public PlayerInventory(EntityHuman entityhuman) { this.items = NonNullList.withSize(36, ItemStack.EMPTY); this.armor = NonNullList.withSize(4, ItemStack.EMPTY); -@@ -63,6 +118,28 @@ - return !itemstack.isEmpty() && ItemStack.isSameItemSameTags(itemstack, itemstack1) && itemstack.isStackable() && itemstack.getCount() < itemstack.getMaxStackSize() && itemstack.getCount() < this.getMaxStackSize(); +@@ -60,6 +115,28 @@ + return !itemstack.isEmpty() && ItemStack.isSameItemSameComponents(itemstack, itemstack1) && itemstack.isStackable() && itemstack.getCount() < this.getMaxStackSize(itemstack); } + // CraftBukkit start - Watch method above! :D 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 af91f84c1d..297edc50a7 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 -@@ -47,6 +47,13 @@ +@@ -49,6 +49,13 @@ import net.minecraft.world.phys.Vec3D; import net.minecraft.world.phys.shapes.VoxelShape; @@ -14,16 +14,16 @@ public abstract class EntityArrow extends IProjectile { private static final double ARROW_BASE_DAMAGE = 2.0D; -@@ -219,7 +226,7 @@ +@@ -225,7 +232,7 @@ } if (object != null && !flag) { -- this.onHit((MovingObjectPosition) object); -+ this.preOnHit((MovingObjectPosition) object); // CraftBukkit - projectile hit event - this.hasImpulse = true; - } +- ProjectileDeflection projectiledeflection = this.hitTargetOrDeflectSelf((MovingObjectPosition) object); ++ ProjectileDeflection projectiledeflection = this.preHitTargetOrDeflectSelf((MovingObjectPosition) object); // CraftBukkit - projectile hit event -@@ -304,7 +311,7 @@ + this.hasImpulse = true; + if (projectiledeflection != ProjectileDeflection.NONE) { +@@ -316,7 +323,7 @@ protected void tickDespawn() { ++this.life; if (this.life >= 1200) { @@ -32,7 +32,7 @@ } } -@@ -337,7 +344,7 @@ +@@ -349,7 +356,7 @@ } if (this.piercingIgnoreEntityIds.size() >= this.getPierceLevel() + 1) { @@ -41,31 +41,31 @@ return; } -@@ -367,7 +374,13 @@ - boolean flag1 = entity.getType().is(TagsEntity.DEFLECTS_ARROWS); +@@ -378,7 +385,13 @@ + int k = entity.getRemainingFireTicks(); - if (this.isOnFire() && !flag && !flag1) { -- entity.setSecondsOnFire(5); + if (this.isOnFire() && !flag) { +- entity.igniteForSeconds(5); + // CraftBukkit start + EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), 5); + org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent); + if (!combustEvent.isCancelled()) { -+ entity.setSecondsOnFire(combustEvent.getDuration(), false); ++ entity.igniteForSeconds(combustEvent.getDuration(), false); + } + // CraftBukkit end } if (entity.hurt(damagesource, (float) i)) { -@@ -418,7 +431,7 @@ +@@ -429,7 +442,7 @@ this.playSound(this.soundEvent, 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F)); if (this.getPierceLevel() <= 0) { - this.discard(); + this.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause } - } else if (flag1) { - this.deflect(); -@@ -432,7 +445,7 @@ + } else { + entity.setRemainingFireTicks(k); +@@ -440,7 +453,7 @@ this.spawnAtLocation(this.getPickupItem(), 0.1F); } @@ -74,7 +74,7 @@ } } -@@ -545,9 +558,24 @@ +@@ -547,9 +560,24 @@ @Override public void playerTouch(EntityHuman entityhuman) { if (!this.level().isClientSide && (this.inGround || this.isNoPhysics()) && this.shakeTime <= 0) { 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 33eec682ad..9cd57aaf80 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 @@ -11,16 +11,7 @@ public class EntityEnderSignal extends Entity implements ItemSupplier { private static final DataWatcherObject DATA_ITEM_STACK = DataWatcher.defineId(EntityEnderSignal.class, DataWatcherRegistry.ITEM_STACK); -@@ -35,7 +39,7 @@ - } - - public void setItem(ItemStack itemstack) { -- if (!itemstack.is(Items.ENDER_EYE) || itemstack.hasTag()) { -+ if (true || !itemstack.is(Items.ENDER_EYE) || itemstack.hasTag()) { // CraftBukkit - always allow item changing - this.getEntityData().set(EntityEnderSignal.DATA_ITEM_STACK, itemstack.copyWithCount(1)); - } - -@@ -150,7 +154,7 @@ +@@ -146,7 +150,7 @@ ++this.life; if (this.life > 80 && !this.level().isClientSide) { this.playSound(SoundEffects.ENDER_EYE_DEATH, 1.0F, 1.0F); @@ -29,12 +20,17 @@ if (this.surviveAfterDeath) { this.level().addFreshEntity(new EntityItem(this.level(), this.getX(), this.getY(), this.getZ(), this.getItem())); } else { -@@ -177,7 +181,7 @@ - public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { - ItemStack itemstack = ItemStack.of(nbttagcompound.getCompound("Item")); - -- this.setItem(itemstack); -+ if (!itemstack.isEmpty()) this.setItem(itemstack); // CraftBukkit - SPIGOT-6103 summon, see also SPIGOT-5474 - } - +@@ -167,7 +171,12 @@ @Override + public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { + if (nbttagcompound.contains("Item", 10)) { +- this.setItem((ItemStack) ItemStack.parse(this.registryAccess(), nbttagcompound.getCompound("Item")).orElse(this.getDefaultItem())); ++ // CraftBukkit start - SPIGOT-6103 summon, see also SPIGOT-5474 ++ ItemStack itemstack = (ItemStack) ItemStack.parse(this.registryAccess(), nbttagcompound.getCompound("Item")).orElse(this.getDefaultItem()); ++ if (!itemstack.isEmpty()) { ++ this.setItem(itemstack); ++ } ++ // CraftBukkit end + } else { + this.setItem(this.getDefaultItem()); + } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEvokerFangs.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEvokerFangs.patch index 78ba4514e7..625a2219dc 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEvokerFangs.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityEvokerFangs.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntityEvokerFangs.java +++ b/net/minecraft/world/entity/projectile/EntityEvokerFangs.java -@@ -14,6 +14,10 @@ +@@ -15,6 +15,10 @@ import net.minecraft.world.entity.TraceableEntity; import net.minecraft.world.level.World; @@ -11,7 +11,7 @@ public class EntityEvokerFangs extends Entity implements TraceableEntity { public static final int ATTACK_DURATION = 20; -@@ -118,7 +122,7 @@ +@@ -119,7 +123,7 @@ } if (--this.lifeTicks < 0) { @@ -20,7 +20,7 @@ } } -@@ -129,7 +133,7 @@ +@@ -130,7 +134,7 @@ if (entityliving.isAlive() && !entityliving.isInvulnerable() && entityliving != entityliving1) { if (entityliving1 == null) { 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 8e5ab2cb4b..97f4340e21 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 -@@ -17,11 +17,18 @@ +@@ -18,6 +18,11 @@ import net.minecraft.world.phys.MovingObjectPosition; import net.minecraft.world.phys.Vec3D; @@ -11,6 +11,8 @@ + public abstract class EntityFireball extends IProjectile { + public static final double ATTACK_DEFLECTION_SCALE = 0.1D; +@@ -25,6 +30,8 @@ public double xPower; public double yPower; public double zPower; @@ -19,20 +21,7 @@ protected EntityFireball(EntityTypes entitytypes, World world) { super(entitytypes, world); -@@ -36,6 +43,12 @@ - this(entitytypes, world); - this.moveTo(d0, d1, d2, this.getYRot(), this.getXRot()); - this.reapplyPosition(); -+ // CraftBukkit start - Added setDirection method -+ this.setDirection(d3, d4, d5); -+ } -+ -+ public void setDirection(double d3, double d4, double d5) { -+ // CraftBukkit end - double d6 = Math.sqrt(d3 * d3 + d4 * d4 + d5 * d5); - - if (d6 != 0.0D) { -@@ -76,7 +89,7 @@ +@@ -72,7 +79,7 @@ Entity entity = this.getOwner(); if (!this.level().isClientSide && (entity != null && entity.isRemoved() || !this.level().hasChunkAt(this.blockPosition()))) { @@ -41,12 +30,12 @@ } else { super.tick(); if (this.shouldBurn()) { -@@ -86,7 +99,13 @@ +@@ -82,7 +89,13 @@ MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResultOnMoveVector(this, this::canHitEntity, this.getClipType()); if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) { -- this.onHit(movingobjectposition); -+ this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event +- this.hitTargetOrDeflectSelf(movingobjectposition); ++ this.preHitTargetOrDeflectSelf(movingobjectposition); // CraftBukkit - projectile hit event + + // CraftBukkit start - Fire ProjectileHitEvent + if (this.isRemoved()) { @@ -56,15 +45,3 @@ } this.checkInsideBlocks(); -@@ -184,6 +203,11 @@ - - if (entity != null) { - if (!this.level().isClientSide) { -+ // CraftBukkit start -+ if (CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f, false)) { -+ return false; -+ } -+ // CraftBukkit end - Vec3D vec3d = entity.getLookAngle(); - - this.setDeltaMovement(vec3d); 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 4c175de142..fbb3c4563d 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,10 +1,16 @@ --- a/net/minecraft/world/entity/projectile/EntityFireballFireball.java +++ b/net/minecraft/world/entity/projectile/EntityFireballFireball.java -@@ -65,6 +65,6 @@ +@@ -56,7 +56,12 @@ + public void readAdditionalSaveData(NBTTagCompound nbttagcompound) { super.readAdditionalSaveData(nbttagcompound); - ItemStack itemstack = ItemStack.of(nbttagcompound.getCompound("Item")); - -- this.setItem(itemstack); -+ if (!itemstack.isEmpty()) this.setItem(itemstack); // CraftBukkit - SPIGOT-5474 probably came from bugged earlier versions - } - } + if (nbttagcompound.contains("Item", 10)) { +- this.setItem((ItemStack) ItemStack.parse(this.registryAccess(), nbttagcompound.getCompound("Item")).orElse(this.getDefaultItem())); ++ // CraftBukkit start - SPIGOT-5474 probably came from bugged earlier versions ++ ItemStack itemstack = (ItemStack) ItemStack.parse(this.registryAccess(), nbttagcompound.getCompound("Item")).orElse(this.getDefaultItem()); ++ if (!itemstack.isEmpty()) { ++ this.setItem(itemstack); ++ } ++ // CraftBukkit end + } else { + this.setItem(this.getDefaultItem()); + } 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 b8ee85381a..74ee3307b6 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 -@@ -28,6 +28,10 @@ +@@ -30,6 +30,10 @@ import net.minecraft.world.phys.MovingObjectPositionEntity; import net.minecraft.world.phys.Vec3D; @@ -11,16 +11,16 @@ public class EntityFireworks extends IProjectile implements ItemSupplier { public static final DataWatcherObject DATA_ID_FIREWORKS_ITEM = DataWatcher.defineId(EntityFireworks.class, DataWatcherRegistry.ITEM_STACK); -@@ -143,7 +147,7 @@ +@@ -146,7 +150,7 @@ MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResultOnMoveVector(this, this::canHitEntity); if (!this.noPhysics) { -- this.onHit(movingobjectposition); -+ this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event +- this.hitTargetOrDeflectSelf(movingobjectposition); ++ this.preHitTargetOrDeflectSelf(movingobjectposition); // CraftBukkit - projectile hit event this.hasImpulse = true; } -@@ -158,7 +162,11 @@ +@@ -161,7 +165,11 @@ } if (!this.level().isClientSide && this.life > this.lifetime) { @@ -33,7 +33,7 @@ } } -@@ -167,14 +175,18 @@ +@@ -170,14 +178,18 @@ this.level().broadcastEntityEvent(this, (byte) 17); this.gameEvent(GameEvent.EXPLODE, this.getOwner()); this.dealExplosionDamage(); @@ -54,7 +54,7 @@ } } -@@ -184,7 +196,11 @@ +@@ -187,7 +199,11 @@ this.level().getBlockState(blockposition).entityInside(this.level(), blockposition, this); if (!this.level().isClientSide() && this.hasExplosion()) { 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 82382ba0a3..e3b9d7b202 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 @@ -61,8 +61,8 @@ private void checkCollision() { MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResultOnMoveVector(this, this::canHitEntity); -- this.onHit(movingobjectposition); -+ this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event +- this.hitTargetOrDeflectSelf(movingobjectposition); ++ this.preHitTargetOrDeflectSelf(movingobjectposition); // CraftBukkit - projectile hit event } @Override @@ -126,7 +126,7 @@ } } -@@ -445,6 +479,14 @@ +@@ -446,6 +480,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); -@@ -460,6 +502,15 @@ +@@ -461,6 +503,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(); -@@ -467,7 +518,11 @@ +@@ -468,7 +519,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); } -@@ -477,10 +532,27 @@ +@@ -478,10 +533,27 @@ } if (this.onGround()) { @@ -199,7 +199,7 @@ return i; } else { return 0; -@@ -513,8 +585,15 @@ +@@ -514,8 +586,15 @@ @Override public void remove(Entity.RemovalReason entity_removalreason) { 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 95397a3d48..3b5e333a89 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntityLlamaSpit.java +++ b/net/minecraft/world/entity/projectile/EntityLlamaSpit.java -@@ -14,6 +14,10 @@ +@@ -15,6 +15,10 @@ import net.minecraft.world.phys.MovingObjectPositionEntity; import net.minecraft.world.phys.Vec3D; @@ -11,17 +11,17 @@ public class EntityLlamaSpit extends IProjectile { public EntityLlamaSpit(EntityTypes entitytypes, World world) { -@@ -32,7 +36,7 @@ +@@ -38,7 +42,7 @@ Vec3D vec3d = this.getDeltaMovement(); MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResultOnMoveVector(this, this::canHitEntity); -- this.onHit(movingobjectposition); -+ this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event +- this.hitTargetOrDeflectSelf(movingobjectposition); ++ this.preHitTargetOrDeflectSelf(movingobjectposition); // CraftBukkit - projectile hit event double d0 = this.getX() + vec3d.x; double d1 = this.getY() + vec3d.y; double d2 = this.getZ() + vec3d.z; -@@ -42,9 +46,9 @@ - float f1 = 0.06F; +@@ -47,9 +51,9 @@ + float f = 0.99F; if (this.level().getBlockStates(this.getBoundingBox()).noneMatch(BlockBase.BlockData::isAir)) { - this.discard(); @@ -31,7 +31,7 @@ + this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause } else { this.setDeltaMovement(vec3d.scale(0.9900000095367432D)); - if (!this.isNoGravity()) { + this.applyGravity(); @@ -72,7 +76,7 @@ protected void onHitBlock(MovingObjectPositionBlock movingobjectpositionblock) { super.onHitBlock(movingobjectpositionblock); 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 d9357b2373..be3ae2fb33 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 -@@ -31,6 +31,18 @@ +@@ -32,6 +32,18 @@ import net.minecraft.world.phys.MovingObjectPositionBlock; import net.minecraft.world.phys.MovingObjectPositionEntity; @@ -19,46 +19,46 @@ public class EntityPotion extends EntityProjectileThrowable implements ItemSupplier { public static final double SPLASH_RANGE = 4.0D; -@@ -99,18 +111,18 @@ +@@ -96,18 +108,18 @@ - if (flag) { + if (potioncontents.is(Potions.WATER)) { this.applyWater(); -- } else if (!list.isEmpty()) { -+ } else if (true || !list.isEmpty()) { // CraftBukkit - Call event even if no effects to apply +- } else if (potioncontents.hasEffects()) { ++ } else if (true || potioncontents.hasEffects()) { // CraftBukkit - Call event even if no effects to apply if (this.isLingering()) { -- this.makeAreaOfEffectCloud(itemstack, potionregistry); -+ this.makeAreaOfEffectCloud(itemstack, potionregistry, movingobjectposition); // CraftBukkit - Pass MovingObjectPosition +- this.makeAreaOfEffectCloud(potioncontents); ++ this.makeAreaOfEffectCloud(potioncontents, movingobjectposition); // CraftBukkit - Pass MovingObjectPosition } else { -- this.applySplash(list, movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.ENTITY ? ((MovingObjectPositionEntity) movingobjectposition).getEntity() : null); -+ this.applySplash(list, movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.ENTITY ? ((MovingObjectPositionEntity) movingobjectposition).getEntity() : null, movingobjectposition); // CraftBukkit - Pass MovingObjectPosition +- 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 } } - int i = potionregistry.hasInstantEffects() ? 2007 : 2002; + int i = potioncontents.potion().isPresent() && ((PotionRegistry) ((Holder) potioncontents.potion().get()).value()).hasInstantEffects() ? 2007 : 2002; - this.level().levelEvent(i, this.blockPosition(), PotionUtil.getColor(itemstack)); + this.level().levelEvent(i, this.blockPosition(), potioncontents.getColor()); - this.discard(); + this.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause } } -@@ -145,9 +157,10 @@ +@@ -142,9 +154,10 @@ } -- private void applySplash(List list, @Nullable Entity entity) { -+ private void applySplash(List list, @Nullable Entity entity, MovingObjectPosition position) { // CraftBukkit - Pass MovingObjectPosition +- private void applySplash(Iterable iterable, @Nullable Entity entity) { ++ private void applySplash(Iterable iterable, @Nullable Entity entity, MovingObjectPosition position) { // CraftBukkit - Pass MovingObjectPosition AxisAlignedBB axisalignedbb = this.getBoundingBox().inflate(4.0D, 2.0D, 4.0D); - List list1 = this.level().getEntitiesOfClass(EntityLiving.class, axisalignedbb); + List list = this.level().getEntitiesOfClass(EntityLiving.class, axisalignedbb); + Map affected = new HashMap(); // CraftBukkit - if (!list1.isEmpty()) { + if (!list.isEmpty()) { Entity entity1 = this.getEffectSource(); -@@ -168,24 +181,49 @@ +@@ -165,24 +178,50 @@ d1 = 1.0D - Math.sqrt(d0) / 4.0D; } -- Iterator iterator1 = list.iterator(); +- Iterator iterator1 = iterable.iterator(); + // CraftBukkit start + affected.put((LivingEntity) entityliving.getBukkitEntity(), d1); + } @@ -68,7 +68,7 @@ - while (iterator1.hasNext()) { - MobEffect mobeffect = (MobEffect) iterator1.next(); -- MobEffectList mobeffectlist = mobeffect.getEffect(); +- Holder holder = mobeffect.getEffect(); + org.bukkit.event.entity.PotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callPotionSplashEvent(this, position, affected); + if (!event.isCancelled() && list != null && !list.isEmpty()) { // do not process effects if there are no effects to process + Entity entity1 = this.getEffectSource(); @@ -77,13 +77,13 @@ + continue; + } -- if (mobeffectlist.isInstantenous()) { -- mobeffectlist.applyInstantenousEffect(this, this.getOwner(), entityliving, mobeffect.getAmplifier(), d1); +- if (((MobEffectList) holder.value()).isInstantenous()) { +- ((MobEffectList) holder.value()).applyInstantenousEffect(this, this.getOwner(), entityliving, mobeffect.getAmplifier(), d1); - } else { - int i = mobeffect.mapDuration((j) -> { - return (int) (d1 * (double) j + 0.5D); - }); -- MobEffect mobeffect1 = new MobEffect(mobeffectlist, i, mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isVisible()); +- MobEffect mobeffect1 = new MobEffect(holder, i, mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isVisible()); + EntityLiving entityliving = ((CraftLivingEntity) victim).getHandle(); + double d1 = event.getIntensity(victim); + // CraftBukkit end @@ -92,13 +92,14 @@ - entityliving.addEffect(mobeffect1, entity1); - } - } -+ Iterator iterator1 = list.iterator(); ++ Iterator iterator1 = iterable.iterator(); + + while (iterator1.hasNext()) { + MobEffect mobeffect = (MobEffect) iterator1.next(); -+ MobEffectList mobeffectlist = mobeffect.getEffect(); ++ Holder holder = mobeffect.getEffect(); + // CraftBukkit start - Abide by PVP settings - for players only! + if (!this.level().pvpMode && this.getOwner() instanceof EntityPlayer && entityliving instanceof EntityPlayer && entityliving != this.getOwner()) { ++ MobEffectList mobeffectlist = (MobEffectList) holder.value(); + if (mobeffectlist == MobEffects.MOVEMENT_SLOWDOWN || mobeffectlist == MobEffects.DIG_SLOWDOWN || mobeffectlist == MobEffects.HARM || mobeffectlist == MobEffects.BLINDNESS + || mobeffectlist == MobEffects.HUNGER || mobeffectlist == MobEffects.WEAKNESS || mobeffectlist == MobEffects.POISON) { + continue; @@ -106,32 +107,32 @@ + } + // CraftBukkit end + -+ if (mobeffectlist.isInstantenous()) { -+ mobeffectlist.applyInstantenousEffect(this, this.getOwner(), entityliving, mobeffect.getAmplifier(), d1); ++ if (((MobEffectList) holder.value()).isInstantenous()) { ++ ((MobEffectList) holder.value()).applyInstantenousEffect(this, this.getOwner(), entityliving, mobeffect.getAmplifier(), d1); + } else { + int i = mobeffect.mapDuration((j) -> { + return (int) (d1 * (double) j + 0.5D); + }); -+ MobEffect mobeffect1 = new MobEffect(mobeffectlist, i, mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isVisible()); ++ MobEffect mobeffect1 = new MobEffect(holder, i, mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isVisible()); + + if (!mobeffect1.endsWithin(20)) { + entityliving.addEffect(mobeffect1, entity1, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.POTION_SPLASH); // CraftBukkit } } } -@@ -194,7 +232,7 @@ +@@ -191,7 +230,7 @@ } -- private void makeAreaOfEffectCloud(ItemStack itemstack, PotionRegistry potionregistry) { -+ private void makeAreaOfEffectCloud(ItemStack itemstack, PotionRegistry potionregistry, MovingObjectPosition position) { // CraftBukkit - Pass MovingObjectPosition +- private void makeAreaOfEffectCloud(PotionContents potioncontents) { ++ private void makeAreaOfEffectCloud(PotionContents potioncontents, MovingObjectPosition position) { // CraftBukkit - Pass MovingObjectPosition EntityAreaEffectCloud entityareaeffectcloud = new EntityAreaEffectCloud(this.level(), this.getX(), this.getY(), this.getZ()); Entity entity = this.getOwner(); -@@ -221,7 +259,14 @@ - entityareaeffectcloud.setFixedColor(nbttagcompound.getInt("CustomPotionColor")); - } - +@@ -204,7 +243,14 @@ + entityareaeffectcloud.setWaitTime(10); + entityareaeffectcloud.setRadiusPerTick(-entityareaeffectcloud.getRadius() / (float) entityareaeffectcloud.getDuration()); + entityareaeffectcloud.setPotionContents(potioncontents); - this.level().addFreshEntity(entityareaeffectcloud); + // CraftBukkit start + org.bukkit.event.entity.LingeringPotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callLingeringPotionSplashEvent(this, position, entityareaeffectcloud); @@ -144,7 +145,7 @@ } public boolean isLingering() { -@@ -232,13 +277,25 @@ +@@ -215,13 +261,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 eacc230d95..f0da500435 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 @@ -4,8 +4,8 @@ } if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS && !flag) { -- this.onHit(movingobjectposition); -+ this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event +- 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 969c95218b..58fe9d5207 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 -@@ -35,6 +35,12 @@ +@@ -32,6 +32,12 @@ protected abstract Item getDefaultItem(); @@ -10,6 +10,6 @@ + } + // CraftBukkit end + - public ItemStack getItemRaw() { + @Override + public ItemStack getItem() { return (ItemStack) this.getEntityData().get(EntityProjectileThrowable.DATA_ITEM_STACK); - } 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 f96d664a88..856120f9dc 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntityShulkerBullet.java +++ b/net/minecraft/world/entity/projectile/EntityShulkerBullet.java -@@ -29,6 +29,10 @@ +@@ -31,6 +31,10 @@ import net.minecraft.world.phys.MovingObjectPositionEntity; import net.minecraft.world.phys.Vec3D; @@ -11,7 +11,7 @@ public class EntityShulkerBullet extends IProjectile { private static final double SPEED = 0.15D; -@@ -60,8 +64,21 @@ +@@ -59,8 +63,21 @@ this.finalTarget = entity; this.currentMoveDirection = EnumDirection.UP; this.selectNextMoveDirection(enumdirection_enumaxis); @@ -33,7 +33,7 @@ @Override public SoundCategory getSoundSource() { return SoundCategory.HOSTILE; -@@ -194,7 +211,7 @@ +@@ -193,7 +210,7 @@ @Override public void checkDespawn() { if (this.level().getDifficulty() == EnumDifficulty.PEACEFUL) { @@ -42,16 +42,16 @@ } } -@@ -225,7 +242,7 @@ +@@ -229,7 +246,7 @@ MovingObjectPosition movingobjectposition = ProjectileHelper.getHitResultOnMoveVector(this, this::canHitEntity); if (movingobjectposition.getType() != MovingObjectPosition.EnumMovingObjectType.MISS) { -- this.onHit(movingobjectposition); -+ this.preOnHit(movingobjectposition); // CraftBukkit - projectile hit event +- this.hitTargetOrDeflectSelf(movingobjectposition); ++ this.preHitTargetOrDeflectSelf(movingobjectposition); // CraftBukkit - projectile hit event } } -@@ -294,7 +311,7 @@ +@@ -298,7 +315,7 @@ if (entity instanceof EntityLiving) { EntityLiving entityliving1 = (EntityLiving) entity; @@ -60,7 +60,7 @@ } } -@@ -308,14 +325,20 @@ +@@ -312,14 +329,20 @@ } private void destroy() { @@ -72,7 +72,7 @@ + private void destroy(EntityRemoveEvent.Cause cause) { + this.discard(cause); + // CraftBukkit end - this.level().gameEvent(GameEvent.ENTITY_DAMAGE, this.position(), GameEvent.a.of((Entity) this)); + this.level().gameEvent((Holder) GameEvent.ENTITY_DAMAGE, this.position(), GameEvent.a.of((Entity) this)); } @Override @@ -83,7 +83,7 @@ } @Override -@@ -325,10 +348,15 @@ +@@ -329,10 +352,15 @@ @Override public boolean hurt(DamageSource damagesource, float f) { 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 b20b84cf77..9a44e062a9 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 @@ -28,13 +28,13 @@ Entity entity1 = this.getOwner(); int i = entity.getRemainingFireTicks(); -- entity.setSecondsOnFire(5); +- entity.igniteForSeconds(5); + // CraftBukkit start - Entity damage by entity event + combust event + EntityCombustByEntityEvent event = new EntityCombustByEntityEvent((org.bukkit.entity.Projectile) this.getBukkitEntity(), entity.getBukkitEntity(), 5); + entity.level().getCraftServer().getPluginManager().callEvent(event); + + if (!event.isCancelled()) { -+ entity.setSecondsOnFire(event.getDuration(), false); ++ entity.igniteForSeconds(event.getDuration(), false); + } + // CraftBukkit end if (!entity.hurt(this.damageSources().fireball(this, entity1), 5.0F)) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntitySpectralArrow.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntitySpectralArrow.patch index 292ce8948a..d1941e9f5d 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntitySpectralArrow.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntitySpectralArrow.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntitySpectralArrow.java +++ b/net/minecraft/world/entity/projectile/EntitySpectralArrow.java -@@ -41,7 +41,7 @@ +@@ -40,7 +40,7 @@ super.doPostHurtEffects(entityliving); MobEffect mobeffect = new MobEffect(MobEffects.GLOWING, this.duration, 0); 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 457d72d219..2323bc5b8a 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 @@ -15,16 +15,16 @@ protected void onHit(MovingObjectPosition movingobjectposition) { super.onHit(movingobjectposition); if (this.level() instanceof WorldServer) { -- this.level().levelEvent(2002, this.blockPosition(), PotionUtil.getColor(Potions.WATER)); +- this.level().levelEvent(2002, this.blockPosition(), PotionContents.getColor(Potions.WATER)); + // CraftBukkit - moved to after event -+ // this.level().levelEvent(2002, this.blockPosition(), PotionUtil.getColor(Potions.WATER)); ++ // this.level().levelEvent(2002, this.blockPosition(), PotionContents.getColor(Potions.WATER)); int i = 3 + this.level().random.nextInt(5) + this.level().random.nextInt(5); + // CraftBukkit start + org.bukkit.event.entity.ExpBottleEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callExpBottleEvent(this, movingobjectposition, i); + i = event.getExperience(); + if (event.getShowEffect()) { -+ this.level().levelEvent(2002, this.blockPosition(), PotionUtil.getColor(Potions.WATER)); ++ this.level().levelEvent(2002, this.blockPosition(), PotionContents.getColor(Potions.WATER)); + } + // CraftBukkit end + 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 3b9dbb04fb..b38276e314 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/projectile/EntityThrownTrident.java +++ b/net/minecraft/world/entity/projectile/EntityThrownTrident.java -@@ -24,6 +24,10 @@ +@@ -23,6 +23,10 @@ import net.minecraft.world.phys.MovingObjectPositionEntity; import net.minecraft.world.phys.Vec3D; @@ -11,7 +11,7 @@ public class EntityThrownTrident extends EntityArrow { private static final DataWatcherObject ID_LOYALTY = DataWatcher.defineId(EntityThrownTrident.class, DataWatcherRegistry.BYTE); -@@ -64,7 +68,7 @@ +@@ -68,7 +72,7 @@ this.spawnAtLocation(this.getPickupItem(), 0.1F); } @@ -20,7 +20,7 @@ } else { this.setNoPhysics(true); Vec3D vec3d = entity.getEyePosition().subtract(this.position()); -@@ -153,7 +157,7 @@ +@@ -152,7 +156,7 @@ if (entitylightning != null) { entitylightning.moveTo(Vec3D.atBottomCenterOf(blockposition)); entitylightning.setCause(entity1 instanceof EntityPlayer ? (EntityPlayer) entity1 : null); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityTippedArrow.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityTippedArrow.patch index c33358120b..c4cedae4b4 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityTippedArrow.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/EntityTippedArrow.patch @@ -1,20 +1,20 @@ --- a/net/minecraft/world/entity/projectile/EntityTippedArrow.java +++ b/net/minecraft/world/entity/projectile/EntityTippedArrow.java -@@ -213,7 +213,7 @@ - mobeffect = (MobEffect) iterator.next(); - entityliving.addEffect(new MobEffect(mobeffect.getEffect(), Math.max(mobeffect.mapDuration((i) -> { - return i / 8; -- }), 1), mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isVisible()), entity); -+ }), 1), mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isVisible()), entity, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.ARROW); // CraftBukkit - } - - if (!this.effects.isEmpty()) { -@@ -221,7 +221,7 @@ - - while (iterator.hasNext()) { +@@ -118,7 +118,7 @@ mobeffect = (MobEffect) iterator.next(); -- entityliving.addEffect(mobeffect, entity); -+ entityliving.addEffect(mobeffect, entity, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.ARROW); // CraftBukkit + entityliving.addEffect(new MobEffect(mobeffect.getEffect(), Math.max(mobeffect.mapDuration((i) -> { + return i / 8; +- }), 1), mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isVisible()), entity); ++ }), 1), mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.isVisible()), entity, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.ARROW); // CraftBukkit } } +@@ -126,7 +126,7 @@ + + while (iterator.hasNext()) { + mobeffect = (MobEffect) iterator.next(); +- entityliving.addEffect(mobeffect, entity); ++ entityliving.addEffect(mobeffect, entity, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.ARROW); // CraftBukkit + } + + } 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 3f2ade60da..6b0fbedd16 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 -@@ -25,6 +25,10 @@ +@@ -26,6 +26,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 -@@ -34,6 +38,10 @@ +@@ -35,6 +39,10 @@ private boolean leftOwner; private boolean hasBeenShot; @@ -22,7 +22,7 @@ IProjectile(EntityTypes entitytypes, World world) { super(entitytypes, world); } -@@ -43,6 +51,7 @@ +@@ -44,6 +52,7 @@ this.ownerUUID = entity.getUUID(); this.cachedOwner = entity; } @@ -30,24 +30,25 @@ } -@@ -167,6 +176,16 @@ +@@ -170,6 +179,17 @@ this.setDeltaMovement(this.getDeltaMovement().add(vec3d.x, entity.onGround() ? 0.0D : vec3d.y, vec3d.z)); } + // CraftBukkit start - call projectile hit event -+ protected void preOnHit(MovingObjectPosition movingobjectposition) { ++ protected ProjectileDeflection preHitTargetOrDeflectSelf(MovingObjectPosition movingobjectposition) { + org.bukkit.event.entity.ProjectileHitEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this, movingobjectposition); + this.hitCancelled = event != null && event.isCancelled(); + if (movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.BLOCK || !this.hitCancelled) { -+ this.onHit(movingobjectposition); ++ return this.hitTargetOrDeflectSelf(movingobjectposition); + } ++ return ProjectileDeflection.NONE; + } + // CraftBukkit end + - protected void onHit(MovingObjectPosition movingobjectposition) { - MovingObjectPosition.EnumMovingObjectType movingobjectposition_enummovingobjecttype = movingobjectposition.getType(); - -@@ -187,6 +206,11 @@ + protected ProjectileDeflection hitTargetOrDeflectSelf(MovingObjectPosition movingobjectposition) { + if (movingobjectposition.getType() == MovingObjectPosition.EnumMovingObjectType.ENTITY) { + MovingObjectPositionEntity movingobjectpositionentity = (MovingObjectPositionEntity) movingobjectposition; +@@ -225,6 +245,11 @@ protected void onHitEntity(MovingObjectPositionEntity movingobjectpositionentity) {} protected void onHitBlock(MovingObjectPositionBlock movingobjectpositionblock) { diff --git a/paper-server/nms-patches/net/minecraft/world/entity/projectile/WindCharge.patch b/paper-server/nms-patches/net/minecraft/world/entity/projectile/WindCharge.patch deleted file mode 100644 index 3c90e4702b..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/entity/projectile/WindCharge.patch +++ /dev/null @@ -1,39 +0,0 @@ ---- a/net/minecraft/world/entity/projectile/WindCharge.java -+++ b/net/minecraft/world/entity/projectile/WindCharge.java -@@ -22,6 +22,10 @@ - import net.minecraft.world.phys.MovingObjectPositionBlock; - import net.minecraft.world.phys.MovingObjectPositionEntity; - -+// CraftBukkit start -+import org.bukkit.event.entity.EntityRemoveEvent; -+// CraftBukkit end -+ - public class WindCharge extends EntityFireball implements ItemSupplier { - - public static final WindCharge.a EXPLOSION_DAMAGE_CALCULATOR = new WindCharge.a(); -@@ -81,7 +85,7 @@ - } - } - -- private void explode() { -+ public void explode() { // PAIL private -> public - this.level().explode(this, (DamageSource) null, WindCharge.EXPLOSION_DAMAGE_CALCULATOR, this.getX(), this.getY(), this.getZ(), (float) (3.0D + this.random.nextDouble()), false, World.a.BLOW, Particles.GUST, Particles.GUST_EMITTER, SoundEffects.WIND_BURST); - } - -@@ -89,14 +93,14 @@ - protected void onHitBlock(MovingObjectPositionBlock movingobjectpositionblock) { - super.onHitBlock(movingobjectpositionblock); - this.explode(); -- this.discard(); -+ this.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause - } - - @Override - protected void onHit(MovingObjectPosition movingobjectposition) { - super.onHit(movingobjectposition); - if (!this.level().isClientSide) { -- this.discard(); -+ this.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause - } - - } 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 new file mode 100644 index 0000000000..745ac82bc8 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/entity/projectile/windcharge/AbstractWindCharge.patch @@ -0,0 +1,40 @@ +--- a/net/minecraft/world/entity/projectile/windcharge/AbstractWindCharge.java ++++ b/net/minecraft/world/entity/projectile/windcharge/AbstractWindCharge.java +@@ -22,6 +22,10 @@ + import net.minecraft.world.phys.MovingObjectPositionBlock; + import net.minecraft.world.phys.MovingObjectPositionEntity; + ++// CraftBukkit start ++import org.bukkit.event.entity.EntityRemoveEvent; ++// CraftBukkit end ++ + public abstract class AbstractWindCharge extends EntityFireball implements ItemSupplier { + + public static final AbstractWindCharge.a EXPLOSION_DAMAGE_CALCULATOR = new AbstractWindCharge.a(); +@@ -95,7 +99,7 @@ + super.onHitBlock(movingobjectpositionblock); + if (!this.level().isClientSide) { + this.explode(); +- this.discard(); ++ this.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause + } + + } +@@ -104,7 +108,7 @@ + protected void onHit(MovingObjectPosition movingobjectposition) { + super.onHit(movingobjectposition); + if (!this.level().isClientSide) { +- this.discard(); ++ this.discard(EntityRemoveEvent.Cause.HIT); // CraftBukkit - add Bukkit remove cause + } + + } +@@ -139,7 +143,7 @@ + public void tick() { + if (!this.level().isClientSide && this.getBlockY() > this.level().getMaxBuildHeight() + 30) { + this.explode(); +- this.discard(); ++ this.discard(EntityRemoveEvent.Cause.OUT_OF_WORLD); // CraftBukkit - add Bukkit remove cause + } else { + super.tick(); + } 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 f297e570a8..c42fe4ca68 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,6 +1,6 @@ --- a/net/minecraft/world/entity/raid/EntityRaider.java +++ b/net/minecraft/world/entity/raid/EntityRaider.java -@@ -43,6 +43,10 @@ +@@ -45,6 +45,10 @@ import net.minecraft.world.level.WorldAccess; import net.minecraft.world.phys.Vec3D; @@ -11,7 +11,7 @@ public abstract class EntityRaider extends EntityMonsterPatrolling { protected static final DataWatcherObject IS_CELEBRATING = DataWatcher.defineId(EntityRaider.class, DataWatcherRegistry.BOOLEAN); -@@ -165,7 +169,7 @@ +@@ -166,7 +170,7 @@ MobEffect mobeffect1 = new MobEffect(MobEffects.BAD_OMEN, 120000, i, false, false, true); if (!this.level().getGameRules().getBoolean(GameRules.RULE_DISABLE_RAIDS)) { @@ -20,7 +20,7 @@ } } } -@@ -256,7 +260,7 @@ +@@ -275,7 +279,7 @@ this.onItemPickup(entityitem); this.setItemSlot(enumitemslot, itemstack); this.take(entityitem, itemstack.getCount()); @@ -29,16 +29,25 @@ this.getCurrentRaid().setLeader(this.getWave(), this); this.setPatrolLeader(true); } else { -@@ -305,7 +309,7 @@ +@@ -324,7 +328,7 @@ private final T mob; -- public b(EntityRaider entityraider) { -+ public b(T entityraider) { // CraftBukkit - decompile error - this.mob = entityraider; +- public b(final EntityRaider entityraider, final EntityRaider entityraider1) { ++ public b(final EntityRaider entityraider, final T entityraider1) { // CraftBukkit - decompile error + this.mob = entityraider1; this.setFlags(EnumSet.of(PathfinderGoal.Type.MOVE)); } -@@ -521,7 +525,7 @@ +@@ -517,7 +521,7 @@ + private final float hostileRadiusSqr; + public final PathfinderTargetCondition shoutTargeting = PathfinderTargetCondition.forNonCombat().range(8.0D).ignoreLineOfSight().ignoreInvisibilityTesting(); + +- public a(final EntityRaider entityraider, final EntityIllagerAbstract entityillagerabstract, final float f) { ++ public a(final EntityIllagerAbstract entityillagerabstract, final float f) { // CraftBukkit - decompile error + this.mob = entityillagerabstract; + this.hostileRadiusSqr = f * f; + this.setFlags(EnumSet.of(PathfinderGoal.Type.MOVE, PathfinderGoal.Type.LOOK)); +@@ -540,7 +544,7 @@ while (iterator.hasNext()) { EntityRaider entityraider = (EntityRaider) iterator.next(); @@ -47,7 +56,7 @@ } } -@@ -538,7 +542,7 @@ +@@ -557,7 +561,7 @@ while (iterator.hasNext()) { EntityRaider entityraider = (EntityRaider) iterator.next(); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/raid/PersistentRaid.patch b/paper-server/nms-patches/net/minecraft/world/entity/raid/PersistentRaid.patch index 72213d9b13..dc16854e76 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/raid/PersistentRaid.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/raid/PersistentRaid.patch @@ -1,37 +1,27 @@ --- a/net/minecraft/world/entity/raid/PersistentRaid.java +++ b/net/minecraft/world/entity/raid/PersistentRaid.java -@@ -121,19 +121,33 @@ - boolean flag = false; +@@ -115,11 +115,23 @@ - if (!raid.isStarted()) { -+ /* CraftBukkit - moved down - if (!this.raidMap.containsKey(raid.getId())) { - this.raidMap.put(raid.getId(), raid); - } -+ */ + Raid raid = this.getOrCreateRaid(entityplayer.serverLevel(), blockposition2); - flag = true; -- } else if (raid.getBadOmenLevel() < raid.getMaxBadOmenLevel()) { -+ // CraftBukkit start - fixed a bug with raid: players could add up Bad Omen level even when the raid had finished -+ } else if (raid.isInProgress() && raid.getBadOmenLevel() < raid.getMaxBadOmenLevel()) { - flag = true; -+ // CraftBukkit end - } else { - entityplayer.removeEffect(MobEffects.BAD_OMEN); - entityplayer.connection.send(new PacketPlayOutEntityStatus(entityplayer, (byte) 43)); ++ /* CraftBukkit - moved down + if (!raid.isStarted() && !this.raidMap.containsKey(raid.getId())) { + this.raidMap.put(raid.getId(), raid); } ++ */ - if (flag) { +- if (!raid.isStarted() || raid.getRaidOmenLevel() < raid.getMaxRaidOmenLevel()) { ++ if (!raid.isStarted() || (raid.isInProgress() && raid.getRaidOmenLevel() < raid.getMaxRaidOmenLevel())) { // CraftBukkit - fixed a bug with raid: players could add up Bad Omen level even when the raid had finished + // CraftBukkit start + if (!org.bukkit.craftbukkit.event.CraftEventFactory.callRaidTriggerEvent(raid, entityplayer)) { -+ entityplayer.removeEffect(MobEffects.BAD_OMEN); ++ entityplayer.removeEffect(net.minecraft.world.effect.MobEffects.RAID_OMEN); + return null; + } + -+ if (!this.raidMap.containsKey(raid.getId())) { ++ if (!raid.isStarted() && !this.raidMap.containsKey(raid.getId())) { + this.raidMap.put(raid.getId(), raid); + } + // CraftBukkit end - raid.absorbBadOmen(entityplayer); - entityplayer.connection.send(new PacketPlayOutEntityStatus(entityplayer, (byte) 43)); - if (!raid.hasFirstWaveSpawned()) { + raid.absorbRaidOmen(entityplayer); + } + 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 c44497a2f3..8d9634db94 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/raid/Raid.java +++ b/net/minecraft/world/entity/raid/Raid.java -@@ -176,6 +176,12 @@ +@@ -180,6 +180,12 @@ return this.status == Raid.Status.LOSS; } @@ -13,7 +13,7 @@ public float getTotalHealth() { return this.totalHealth; } -@@ -272,6 +278,7 @@ +@@ -284,6 +290,7 @@ this.active = this.level.hasChunkAt(this.center); if (this.level.getDifficulty() == EnumDifficulty.PEACEFUL) { @@ -21,7 +21,7 @@ this.stop(); return; } -@@ -291,13 +298,16 @@ +@@ -303,13 +310,16 @@ if (!this.level.isVillage(this.center)) { if (this.groupsSpawned > 0) { this.status = Raid.Status.LOSS; @@ -38,7 +38,7 @@ this.stop(); return; } -@@ -371,6 +381,7 @@ +@@ -383,6 +393,7 @@ } if (j > 3) { @@ -46,7 +46,7 @@ this.stop(); break; } -@@ -383,6 +394,7 @@ +@@ -395,6 +406,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); -@@ -397,10 +409,12 @@ +@@ -409,10 +421,12 @@ entityplayer.awardStat(StatisticList.RAID_WIN); CriterionTriggers.RAID_WIN.trigger(entityplayer); @@ -67,7 +67,7 @@ } } -@@ -408,6 +422,7 @@ +@@ -420,6 +434,7 @@ } else if (this.isOver()) { ++this.celebrationTicks; if (this.celebrationTicks >= 600) { @@ -75,7 +75,7 @@ this.stop(); return; } -@@ -544,6 +559,10 @@ +@@ -556,6 +571,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); -@@ -559,9 +578,11 @@ +@@ -571,9 +590,11 @@ entityraider.setPatrolLeader(true); this.setLeader(i, entityraider); flag = true; @@ -98,7 +98,7 @@ if (raid_wave.entityType == EntityTypes.RAVAGER) { EntityRaider entityraider1 = null; -@@ -580,6 +601,7 @@ +@@ -592,6 +613,7 @@ this.joinRaid(i, entityraider1, blockposition, false); entityraider1.moveTo(blockposition, 0.0F, 0.0F); entityraider1.startRiding(entityraider); @@ -106,7 +106,7 @@ } } -@@ -597,6 +619,7 @@ +@@ -609,6 +631,7 @@ ++this.groupsSpawned; this.updateBossbar(); this.setDirty(); @@ -114,8 +114,8 @@ } public void joinRaid(int i, EntityRaider entityraider, @Nullable BlockPosition blockposition, boolean flag) { -@@ -612,7 +635,7 @@ - entityraider.finalizeSpawn(this.level, this.level.getCurrentDifficultyAt(blockposition), EnumMobSpawn.EVENT, (GroupDataEntity) null, (NBTTagCompound) null); +@@ -624,7 +647,7 @@ + entityraider.finalizeSpawn(this.level, this.level.getCurrentDifficultyAt(blockposition), EnumMobSpawn.EVENT, (GroupDataEntity) null); entityraider.applyRaidBuffs(i, false); entityraider.setOnGround(true); - this.level.addFreshEntityWithPassengers(entityraider); @@ -123,7 +123,7 @@ } } -@@ -862,6 +885,12 @@ +@@ -873,6 +896,12 @@ this.heroesOfTheVillage.add(entity.getUUID()); } diff --git a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/ChestBoat.patch b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/ChestBoat.patch index 37a9d9b1cd..89a9c68229 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/ChestBoat.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/ChestBoat.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/entity/vehicle/ChestBoat.java +++ b/net/minecraft/world/entity/vehicle/ChestBoat.java -@@ -24,6 +24,15 @@ - import net.minecraft.world.level.World; +@@ -26,6 +26,15 @@ import net.minecraft.world.level.gameevent.GameEvent; + import net.minecraft.world.level.storage.loot.LootTable; +// CraftBukkit start +import java.util.List; @@ -16,7 +16,7 @@ public class ChestBoat extends EntityBoat implements HasCustomInventoryScreen, ContainerEntity { private static final int CONTAINER_SIZE = 27; -@@ -76,11 +85,18 @@ +@@ -78,11 +87,18 @@ @Override public void remove(Entity.RemovalReason entity_removalreason) { @@ -36,9 +36,9 @@ } @Override -@@ -238,4 +254,51 @@ +@@ -240,4 +256,51 @@ public void stopOpen(EntityHuman entityhuman) { - this.level().gameEvent(GameEvent.CONTAINER_CLOSE, this.position(), GameEvent.a.of((Entity) entityhuman)); + this.level().gameEvent((Holder) GameEvent.CONTAINER_CLOSE, this.position(), GameEvent.a.of((Entity) entityhuman)); } + + // CraftBukkit start diff --git a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityBoat.patch b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityBoat.patch index 3541afdcf1..49757536f1 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityBoat.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/vehicle/EntityBoat.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/entity/vehicle/EntityBoat.java +++ b/net/minecraft/world/entity/vehicle/EntityBoat.java -@@ -55,6 +55,15 @@ +@@ -54,6 +54,15 @@ + import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapes; - import org.joml.Vector3f; +// CraftBukkit start +import org.bukkit.Location; @@ -16,7 +16,7 @@ public class EntityBoat extends VehicleEntity implements VariantHolder { private static final DataWatcherObject DATA_ID_TYPE = DataWatcher.defineId(EntityBoat.class, DataWatcherRegistry.INT); -@@ -92,6 +101,14 @@ +@@ -91,6 +100,14 @@ private float bubbleAngle; private float bubbleAngleO; @@ -31,7 +31,7 @@ public EntityBoat(EntityTypes entitytypes, World world) { super(entitytypes, world); this.paddlePositions = new float[2]; -@@ -192,9 +209,29 @@ +@@ -186,9 +203,29 @@ public void push(Entity entity) { if (entity instanceof EntityBoat) { if (entity.getBoundingBox().minY < this.getBoundingBox().maxY) { @@ -61,7 +61,7 @@ super.push(entity); } -@@ -288,6 +325,7 @@ +@@ -282,6 +319,7 @@ return this.getDirection().getClockWise(); } @@ -69,7 +69,7 @@ @Override public void tick() { this.oldStatus = this.status; -@@ -328,6 +366,22 @@ +@@ -322,6 +360,22 @@ this.setDeltaMovement(Vec3D.ZERO); } @@ -92,7 +92,7 @@ this.tickBubbleColumn(); for (int i = 0; i <= 1; ++i) { -@@ -813,6 +867,11 @@ +@@ -811,6 +865,11 @@ this.causeFallDamage(this.fallDistance, 1.0F, this.damageSources().fall()); if (!this.level().isClientSide && !this.isRemoved()) { @@ -104,7 +104,7 @@ this.kill(); if (this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) { int i; -@@ -826,6 +885,7 @@ +@@ -824,6 +883,7 @@ } } } 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 fa2f12d6d9..d4365041ce 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,8 +1,8 @@ --- a/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java +++ b/net/minecraft/world/entity/vehicle/EntityMinecartAbstract.java -@@ -48,6 +48,14 @@ +@@ -47,6 +47,14 @@ + import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; - import org.joml.Vector3f; +// CraftBukkit start +import org.bukkit.Location; @@ -14,8 +14,8 @@ + public abstract class EntityMinecartAbstract extends VehicleEntity { - private static final float LOWERED_PASSENGER_ATTACHMENT_Y = 0.0F; -@@ -88,6 +96,17 @@ + private static final Vec3D LOWERED_PASSENGER_ATTACHMENT = new Vec3D(0.0D, 0.0D, 0.0D); +@@ -86,6 +94,17 @@ enummap.put(BlockPropertyTrackPosition.NORTH_EAST, Pair.of(baseblockposition2, baseblockposition1)); }); @@ -33,7 +33,7 @@ protected EntityMinecartAbstract(EntityTypes entitytypes, World world) { super(entitytypes, world); this.targetDeltaMovement = Vec3D.ZERO; -@@ -128,7 +147,7 @@ +@@ -126,7 +145,7 @@ object = new EntityMinecartRideable(worldserver, d0, d1, d2); } @@ -42,7 +42,7 @@ EntityTypes.createDefaultStackConfig(worldserver, itemstack, entityhuman).accept(object1); return (EntityMinecartAbstract) object1; -@@ -267,6 +286,14 @@ +@@ -270,6 +289,14 @@ @Override public void tick() { @@ -57,7 +57,7 @@ if (this.getHurtTime() > 0) { this.setHurtTime(this.getHurtTime() - 1); } -@@ -276,7 +303,7 @@ +@@ -279,7 +306,7 @@ } this.checkBelowWorld(); @@ -66,7 +66,7 @@ if (this.level().isClientSide) { if (this.lerpSteps > 0) { this.lerpPositionAndRotationStep(this.lerpSteps, this.lerpX, this.lerpY, this.lerpZ, this.lerpYRot, this.lerpXRot); -@@ -334,6 +361,18 @@ +@@ -332,6 +359,18 @@ } this.setRot(this.getYRot(), this.getXRot()); @@ -85,7 +85,7 @@ 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)); -@@ -344,8 +383,26 @@ +@@ -342,8 +381,26 @@ Entity entity = (Entity) iterator.next(); if (!(entity instanceof EntityHuman) && !(entity instanceof EntityIronGolem) && !(entity instanceof EntityMinecartAbstract) && !this.isVehicle() && !entity.isPassenger()) { @@ -112,7 +112,7 @@ entity.push(this); } } -@@ -357,6 +414,14 @@ +@@ -355,6 +412,14 @@ Entity entity1 = (Entity) iterator1.next(); if (!this.hasPassenger(entity1) && entity1.isPushable() && entity1 instanceof EntityMinecartAbstract) { @@ -127,7 +127,7 @@ entity1.push(this); } } -@@ -373,7 +438,7 @@ +@@ -371,7 +436,7 @@ } protected double getMaxSpeed() { @@ -136,7 +136,7 @@ } public void activateMinecart(int i, int j, int k, boolean flag) {} -@@ -384,12 +449,16 @@ +@@ -382,12 +447,16 @@ this.setDeltaMovement(MathHelper.clamp(vec3d.x, -d0, d0), vec3d.y, MathHelper.clamp(vec3d.z, -d0, d0)); if (this.onGround()) { @@ -155,7 +155,7 @@ } } -@@ -585,7 +654,7 @@ +@@ -583,7 +652,7 @@ } protected void applyNaturalSlowdown() { @@ -164,7 +164,7 @@ Vec3D vec3d = this.getDeltaMovement(); vec3d = vec3d.multiply(d0, 0.0D, d0); -@@ -724,6 +793,14 @@ +@@ -722,6 +791,14 @@ if (!this.level().isClientSide) { if (!entity.noPhysics && !this.noPhysics) { if (!this.hasPassenger(entity)) { @@ -179,7 +179,7 @@ double d0 = entity.getX() - this.getX(); double d1 = entity.getZ() - this.getZ(); double d2 = d0 * d0 + d1 * d1; -@@ -898,4 +975,26 @@ +@@ -896,4 +973,26 @@ private EnumMinecartType() {} } 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 df662dadeb..46407b55cd 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 -@@ -18,6 +18,15 @@ - import net.minecraft.world.item.ItemStack; +@@ -19,6 +19,15 @@ import net.minecraft.world.level.World; + import net.minecraft.world.level.storage.loot.LootTable; +// CraftBukkit start +import java.util.List; @@ -16,8 +16,8 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract implements ContainerEntity { private NonNullList itemStacks; -@@ -25,14 +34,55 @@ - public MinecraftKey lootTable; +@@ -26,14 +35,55 @@ + public ResourceKey lootTable; public long lootTableSeed; + // CraftBukkit start @@ -74,7 +74,7 @@ } @Override -@@ -76,11 +126,18 @@ +@@ -77,11 +127,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 1161f9689c..8072b60894 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 @@ -12,7 +12,7 @@ public class EntityMinecartTNT extends EntityMinecartAbstract { private static final byte EVENT_PRIME = 10; -@@ -115,8 +120,16 @@ +@@ -113,8 +118,16 @@ d1 = 5.0D; } 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 f8f4a155d2..69de92da46 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 -@@ -13,6 +13,13 @@ +@@ -14,6 +14,13 @@ import net.minecraft.world.level.World; import net.minecraft.world.level.gameevent.GameEvent; @@ -14,7 +14,7 @@ public abstract class VehicleEntity extends Entity { protected static final DataWatcherObject DATA_ID_HURT = DataWatcher.defineId(VehicleEntity.class, DataWatcherRegistry.INT); -@@ -29,6 +36,18 @@ +@@ -30,6 +37,18 @@ if (this.isInvulnerableTo(damagesource)) { return false; } else { @@ -33,7 +33,7 @@ this.setHurtDir(-this.getHurtDir()); this.setHurtTime(10); this.markHurt(); -@@ -38,9 +57,27 @@ +@@ -39,9 +58,27 @@ if ((flag || this.getDamage() <= 40.0F) && !this.shouldSourceDestroy(damagesource)) { if (flag) { 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 ea2002c264..ca336a6dad 100644 --- a/paper-server/nms-patches/net/minecraft/world/food/FoodMetaData.patch +++ b/paper-server/nms-patches/net/minecraft/world/food/FoodMetaData.patch @@ -33,20 +33,20 @@ + } + // CraftBukkit end - public void eat(int i, float f) { + private void add(int i, float f) { this.foodLevel = Math.min(i + this.foodLevel, 20); -@@ -25,8 +43,17 @@ - public void eat(Item item, ItemStack itemstack) { - if (item.isEdible()) { - FoodInfo foodinfo = item.getFoodProperties(); +@@ -30,7 +48,17 @@ + FoodInfo foodinfo = (FoodInfo) itemstack.get(DataComponents.FOOD); + + if (foodinfo != null) { +- this.add(foodinfo.nutrition(), foodinfo.saturation()); + // CraftBukkit start + int oldFoodLevel = foodLevel; - -- this.eat(foodinfo.getNutrition(), foodinfo.getSaturationModifier()); -+ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, foodinfo.getNutrition() + oldFoodLevel, itemstack); ++ ++ org.bukkit.event.entity.FoodLevelChangeEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callFoodLevelChangeEvent(entityhuman, foodinfo.nutrition() + oldFoodLevel, itemstack); + + if (!event.isCancelled()) { -+ this.eat(event.getFoodLevel() - oldFoodLevel, foodinfo.getSaturationModifier()); ++ this.add(event.getFoodLevel() - oldFoodLevel, foodinfo.saturation()); + } + + ((EntityPlayer) entityhuman).getBukkitEntity().sendHealthUpdate(); @@ -54,7 +54,7 @@ } } -@@ -40,7 +67,15 @@ +@@ -44,7 +72,15 @@ if (this.saturationLevel > 0.0F) { this.saturationLevel = Math.max(this.saturationLevel - 1.0F, 0.0F); } else if (enumdifficulty != EnumDifficulty.PEACEFUL) { @@ -71,7 +71,7 @@ } } -@@ -48,23 +83,25 @@ +@@ -52,23 +88,25 @@ if (flag && this.saturationLevel > 0.0F && entityhuman.isHurt() && this.foodLevel >= 20) { ++this.tickTimer; 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 483c8191b4..9e3afe1d72 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/Container.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/Container.patch @@ -179,7 +179,7 @@ } } -@@ -832,6 +926,11 @@ +@@ -830,6 +924,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 6565787448..57377bd991 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvil.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvil.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/ContainerAnvil.java +++ b/net/minecraft/world/inventory/ContainerAnvil.java -@@ -19,6 +19,10 @@ +@@ -21,6 +21,10 @@ import net.minecraft.world.level.block.state.IBlockData; import org.slf4j.Logger; @@ -11,7 +11,7 @@ public class ContainerAnvil extends ContainerAnvilAbstract { public static final int INPUT_SLOT = 0; -@@ -42,6 +46,11 @@ +@@ -44,6 +48,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,16 +23,16 @@ public ContainerAnvil(int i, PlayerInventory playerinventory) { this(i, playerinventory, ContainerAccess.NULL); -@@ -69,7 +78,7 @@ +@@ -71,7 +80,7 @@ @Override protected boolean mayPickup(EntityHuman entityhuman, boolean flag) { -- return (entityhuman.getAbilities().instabuild || entityhuman.experienceLevel >= this.cost.get()) && this.cost.get() > 0; -+ return (entityhuman.getAbilities().instabuild || entityhuman.experienceLevel >= this.cost.get()) && this.cost.get() > ContainerAnvil.DEFAULT_DENIED_COST && flag; // CraftBukkit - allow cost 0 like a free item +- return (entityhuman.hasInfiniteMaterials() || entityhuman.experienceLevel >= this.cost.get()) && this.cost.get() > 0; ++ return (entityhuman.hasInfiniteMaterials() || entityhuman.experienceLevel >= this.cost.get()) && this.cost.get() > ContainerAnvil.DEFAULT_DENIED_COST && flag; // CraftBukkit - allow cost 0 like a free item } @Override -@@ -92,7 +101,7 @@ +@@ -94,7 +103,7 @@ this.inputSlots.setItem(1, ItemStack.EMPTY); } @@ -41,17 +41,6 @@ this.access.execute((world, blockposition) -> { IBlockData iblockdata = world.getBlockState(blockposition); -@@ -123,8 +132,8 @@ - byte b1 = 0; - - if (itemstack.isEmpty()) { -- this.resultSlots.setItem(0, ItemStack.EMPTY); -- this.cost.set(0); -+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit -+ this.cost.set(DEFAULT_DENIED_COST); // CraftBukkit - use a variable for set a cost for denied item - } else { - ItemStack itemstack1 = itemstack.copy(); - ItemStack itemstack2 = this.inputSlots.getItem(1); @@ -141,8 +150,8 @@ if (itemstack1.isDamageableItem() && itemstack1.getItem().isValidRepairItem(itemstack, itemstack2)) { k = Math.min(itemstack1.getDamageValue(), itemstack1.getMaxDamage() / 4); @@ -74,7 +63,7 @@ return; } -@@ -246,8 +255,8 @@ +@@ -231,8 +240,8 @@ } if (flag2 && !flag1) { @@ -85,13 +74,13 @@ return; } } -@@ -270,11 +279,11 @@ +@@ -257,11 +266,11 @@ itemstack1 = ItemStack.EMPTY; } -- if (b1 == i && b1 > 0 && this.cost.get() >= 40) { +- if (b0 == i && b0 > 0 && this.cost.get() >= 40) { - this.cost.set(39); -+ if (b1 == i && b1 > 0 && this.cost.get() >= maximumRepairCost) { // CraftBukkit ++ if (b0 == i && b0 > 0 && this.cost.get() >= maximumRepairCost) { // CraftBukkit + this.cost.set(maximumRepairCost - 1); // CraftBukkit } @@ -100,17 +89,23 @@ itemstack1 = ItemStack.EMPTY; } -@@ -293,7 +302,8 @@ - EnchantmentManager.setEnchantments(map, itemstack1); +@@ -279,11 +288,12 @@ + EnchantmentManager.setEnchantments(itemstack1, itemenchantments_a.toImmutable()); } - this.resultSlots.setItem(0, itemstack1); + org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), itemstack1); // CraftBukkit + sendAllDataToRemote(); // CraftBukkit - SPIGOT-6686: Always send completed inventory to stay in sync with client this.broadcastChanges(); + } else { +- this.resultSlots.setItem(0, ItemStack.EMPTY); +- this.cost.set(0); ++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit ++ this.cost.set(DEFAULT_DENIED_COST); // CraftBukkit - use a variable for set a cost for denied item } } -@@ -334,4 +344,18 @@ + +@@ -323,4 +333,18 @@ 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 e90413e53d..4c76c0b1b8 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvilAbstract.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerAnvilAbstract.patch @@ -1,10 +1,19 @@ --- a/net/minecraft/world/inventory/ContainerAnvilAbstract.java +++ b/net/minecraft/world/inventory/ContainerAnvilAbstract.java +@@ -47,7 +47,7 @@ + while (iterator.hasNext()) { + final ItemCombinerMenuSlotDefinition.b itemcombinermenuslotdefinition_b = (ItemCombinerMenuSlotDefinition.b) iterator.next(); + +- this.addSlot(new Slot(this, this.inputSlots, itemcombinermenuslotdefinition_b.slotIndex(), itemcombinermenuslotdefinition_b.x(), itemcombinermenuslotdefinition_b.y()) { ++ this.addSlot(new Slot(this.inputSlots, itemcombinermenuslotdefinition_b.slotIndex(), itemcombinermenuslotdefinition_b.x(), itemcombinermenuslotdefinition_b.y()) { // CraftBukkit - decompile error + @Override + public boolean mayPlace(ItemStack itemstack) { + return itemcombinermenuslotdefinition_b.mayPlace().test(itemstack); @@ -124,6 +124,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { + if (!this.checkReachable) return true; // CraftBukkit return (Boolean) this.access.evaluate((world, blockposition) -> { - return !this.isValidBlock(world.getBlockState(blockposition)) ? false : entityhuman.distanceToSqr((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) <= 64.0D; + return !this.isValidBlock(world.getBlockState(blockposition)) ? false : entityhuman.canInteractWithBlock(blockposition, 4.0D); }, true); 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 c416f96192..8cdf0af023 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerBeacon.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerBeacon.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/ContainerBeacon.java +++ b/net/minecraft/world/inventory/ContainerBeacon.java -@@ -12,6 +12,11 @@ +@@ -13,6 +13,11 @@ import net.minecraft.world.level.World; import net.minecraft.world.level.block.Blocks; @@ -12,7 +12,7 @@ public class ContainerBeacon extends Container { private static final int PAYMENT_SLOT = 0; -@@ -26,6 +31,10 @@ +@@ -27,6 +32,10 @@ private final ContainerBeacon.SlotBeacon paymentSlot; private final ContainerAccess access; private final IContainerProperties beaconData; @@ -23,15 +23,17 @@ public ContainerBeacon(int i, IInventory iinventory) { this(i, iinventory, new ContainerProperties(3), ContainerAccess.NULL); -@@ -33,6 +42,7 @@ +@@ -34,7 +43,8 @@ public ContainerBeacon(int i, IInventory iinventory, IContainerProperties icontainerproperties, ContainerAccess containeraccess) { super(Containers.BEACON, i); +- this.beacon = new InventorySubcontainer(this, 1) { + player = (PlayerInventory) iinventory; // CraftBukkit - TODO: check this - this.beacon = new InventorySubcontainer(1) { ++ this.beacon = new InventorySubcontainer(1) { // CraftBukkit - decompile error @Override public boolean canPlaceItem(int j, ItemStack itemstack) { -@@ -82,6 +92,7 @@ + return itemstack.is(TagsItem.BEACON_PAYMENT_ITEMS); +@@ -83,6 +93,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { @@ -39,18 +41,18 @@ return stillValid(this.access, entityhuman, Blocks.BEACON); } -@@ -163,8 +174,8 @@ +@@ -164,8 +175,8 @@ - public void updateEffects(Optional optional, Optional optional1) { + public void updateEffects(Optional> optional, Optional> optional1) { if (this.paymentSlot.hasItem()) { -- this.beaconData.set(1, encodeEffect((MobEffectList) optional.orElse((Object) null))); -- this.beaconData.set(2, encodeEffect((MobEffectList) optional1.orElse((Object) null))); -+ this.beaconData.set(1, encodeEffect((MobEffectList) optional.orElse(null))); // CraftBukkit - decompile error -+ this.beaconData.set(2, encodeEffect((MobEffectList) optional1.orElse(null))); // CraftBukkit - decompile error +- this.beaconData.set(1, encodeEffect((Holder) optional.orElse((Object) null))); +- this.beaconData.set(2, encodeEffect((Holder) optional1.orElse((Object) null))); ++ this.beaconData.set(1, encodeEffect((Holder) optional.orElse(null)));// CraftBukkit - decompile error ++ this.beaconData.set(2, encodeEffect((Holder) optional1.orElse(null)));// CraftBukkit - decompile error this.paymentSlot.remove(1); this.access.execute(World::blockEntityChanged); } -@@ -191,4 +202,17 @@ +@@ -192,4 +203,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 9fa2aa3fdd..5fbfc4815c 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerBrewingStand.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerBrewingStand.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/inventory/ContainerBrewingStand.java +++ b/net/minecraft/world/inventory/ContainerBrewingStand.java -@@ -13,6 +13,11 @@ +@@ -15,6 +15,11 @@ + import net.minecraft.world.item.alchemy.PotionContents; import net.minecraft.world.item.alchemy.PotionRegistry; - import net.minecraft.world.item.alchemy.PotionUtil; +// CraftBukkit start +import org.bukkit.craftbukkit.inventory.CraftInventoryBrewer; @@ -12,7 +12,7 @@ public class ContainerBrewingStand extends Container { private static final int BOTTLE_SLOT_START = 0; -@@ -29,12 +34,18 @@ +@@ -31,12 +36,18 @@ private final IContainerProperties brewingStandData; private final Slot ingredientSlot; @@ -31,7 +31,7 @@ checkContainerSize(iinventory, 5); checkContainerDataCount(icontainerproperties, 2); this.brewingStand = iinventory; -@@ -62,6 +73,7 @@ +@@ -66,6 +77,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { @@ -39,8 +39,8 @@ return this.brewingStand.stillValid(entityhuman); } -@@ -199,4 +211,17 @@ - return 64; +@@ -196,4 +208,17 @@ + return itemstack.is(Items.BLAZE_POWDER); } } + 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 0a48c9eda0..fce0e9670a 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerCartography.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerCartography.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/ContainerCartography.java +++ b/net/minecraft/world/inventory/ContainerCartography.java -@@ -12,8 +12,30 @@ +@@ -14,8 +14,30 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.saveddata.maps.WorldMap; @@ -31,7 +31,7 @@ public static final int MAP_SLOT = 0; public static final int ADDITIONAL_SLOT = 1; public static final int RESULT_SLOT = 2; -@@ -38,6 +60,13 @@ +@@ -40,6 +62,13 @@ ContainerCartography.this.slotsChanged(this); super.setChanged(); } @@ -45,7 +45,7 @@ }; this.resultContainer = new InventoryCraftResult() { @Override -@@ -45,6 +74,13 @@ +@@ -47,15 +76,22 @@ ContainerCartography.this.slotsChanged(this); super.setChanged(); } @@ -58,8 +58,19 @@ + // CraftBukkit end }; this.access = containeraccess; - this.addSlot(new Slot(this.container, 0, 15, 15) { -@@ -95,10 +131,12 @@ +- this.addSlot(new Slot(this, this.container, 0, 15, 15) { ++ this.addSlot(new Slot(this.container, 0, 15, 15) { // CraftBukkit - decompile error + @Override + public boolean mayPlace(ItemStack itemstack) { + return itemstack.is(Items.FILLED_MAP); + } + }); +- this.addSlot(new Slot(this, this.container, 1, 15, 52) { ++ this.addSlot(new Slot(this.container, 1, 15, 52) { // CraftBukkit - decompile error + @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)); } 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 4775eabe34..f606d687c8 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerEnchantTable.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerEnchantTable.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/ContainerEnchantTable.java +++ b/net/minecraft/world/inventory/ContainerEnchantTable.java -@@ -27,6 +27,21 @@ +@@ -25,6 +25,21 @@ import net.minecraft.world.level.block.BlockEnchantmentTable; import net.minecraft.world.level.block.Blocks; @@ -22,7 +22,7 @@ public class ContainerEnchantTable extends Container { static final MinecraftKey EMPTY_SLOT_LAPIS_LAZULI = new MinecraftKey("item/empty_slot_lapis_lazuli"); -@@ -37,6 +52,10 @@ +@@ -35,6 +50,10 @@ public final int[] costs; public final int[] enchantClue; public final int[] levelClue; @@ -33,7 +33,7 @@ public ContainerEnchantTable(int i, PlayerInventory playerinventory) { this(i, playerinventory, ContainerAccess.NULL); -@@ -50,6 +69,13 @@ +@@ -48,6 +67,13 @@ super.setChanged(); ContainerEnchantTable.this.slotsChanged(this); } @@ -47,7 +47,23 @@ }; this.random = RandomSource.create(); this.enchantmentSeed = ContainerProperty.standalone(); -@@ -97,6 +123,9 @@ +@@ -55,13 +81,13 @@ + this.enchantClue = new int[]{-1, -1, -1}; + this.levelClue = new int[]{-1, -1, -1}; + this.access = containeraccess; +- this.addSlot(new Slot(this, this.enchantSlots, 0, 15, 47) { ++ this.addSlot(new Slot(this.enchantSlots, 0, 15, 47) { // CraftBukkit - decompile error + @Override + public int getMaxStackSize() { + return 1; + } + }); +- this.addSlot(new Slot(this, this.enchantSlots, 1, 35, 47) { ++ this.addSlot(new Slot(this.enchantSlots, 1, 35, 47) { // CraftBukkit - decompile error + @Override + public boolean mayPlace(ItemStack itemstack) { + return itemstack.is(Items.LAPIS_LAZULI); +@@ -95,6 +121,9 @@ this.addDataSlot(ContainerProperty.shared(this.levelClue, 0)); this.addDataSlot(ContainerProperty.shared(this.levelClue, 1)); this.addDataSlot(ContainerProperty.shared(this.levelClue, 2)); @@ -57,7 +73,7 @@ } @Override -@@ -104,7 +133,7 @@ +@@ -102,7 +131,7 @@ if (iinventory == this.enchantSlots) { ItemStack itemstack = iinventory.getItem(0); @@ -66,7 +82,7 @@ this.access.execute((world, blockposition) -> { int i = 0; Iterator iterator = BlockEnchantmentTable.BOOKSHELF_OFFSETS.iterator(); -@@ -143,6 +172,41 @@ +@@ -141,6 +170,41 @@ } } @@ -108,9 +124,9 @@ this.broadcastChanges(); }); } else { -@@ -170,8 +234,25 @@ +@@ -168,21 +232,46 @@ ItemStack itemstack2 = itemstack; - List list = this.getEnchantmentList(itemstack, i, this.costs[i]); + List list = this.getEnchantmentList(world.enabledFeatures(), itemstack, i, this.costs[i]); - if (!list.isEmpty()) { - entityhuman.onEnchantmentPerformed(itemstack, j); @@ -133,10 +149,8 @@ + return; + } + // CraftBukkit end - boolean flag = itemstack.is(Items.BOOK); - - if (flag) { -@@ -185,18 +266,30 @@ + if (itemstack.is(Items.BOOK)) { + itemstack2 = itemstack.transmuteCopy(Items.ENCHANTED_BOOK, 1); this.enchantSlots.setItem(0, itemstack2); } @@ -146,36 +160,24 @@ - WeightedRandomEnchant weightedrandomenchant = (WeightedRandomEnchant) iterator.next(); + // CraftBukkit start + for (Map.Entry entry : event.getEnchantsToAdd().entrySet()) { -+ try { -+ if (flag) { -+ NamespacedKey enchantId = entry.getKey().getKey(); -+ Enchantment nms = BuiltInRegistries.ENCHANTMENT.get(CraftNamespacedKey.toMinecraft(enchantId)); -+ if (nms == null) { -+ continue; -+ } ++ NamespacedKey enchantId = entry.getKey().getKey(); ++ Enchantment nms = BuiltInRegistries.ENCHANTMENT.get(CraftNamespacedKey.toMinecraft(enchantId)); ++ if (nms == null) { ++ continue; ++ } -- if (flag) { -- ItemEnchantedBook.addEnchantment(itemstack2, weightedrandomenchant); -- } else { -- itemstack2.enchant(weightedrandomenchant.enchantment, weightedrandomenchant.level); -+ WeightedRandomEnchant weightedrandomenchant = new WeightedRandomEnchant(nms, entry.getValue()); -+ ItemEnchantedBook.addEnchantment(itemstack2, weightedrandomenchant); -+ } else { -+ item.addUnsafeEnchantment(entry.getKey(), entry.getValue()); -+ } -+ } catch (IllegalArgumentException e) { -+ /* Just swallow invalid enchantments */ - } ++ WeightedRandomEnchant weightedrandomenchant = new WeightedRandomEnchant(nms, entry.getValue()); + itemstack2.enchant(weightedrandomenchant.enchantment, weightedrandomenchant.level); } + entityhuman.onEnchantmentPerformed(itemstack, j); + // CraftBukkit end + + // CraftBukkit - TODO: let plugins change this - if (!entityhuman.getAbilities().instabuild) { + if (!entityhuman.hasInfiniteMaterials()) { itemstack1.shrink(j); if (itemstack1.isEmpty()) { -@@ -259,6 +352,7 @@ +@@ -245,6 +334,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { @@ -183,7 +185,7 @@ return stillValid(this.access, entityhuman, Blocks.ENCHANTING_TABLE); } -@@ -309,4 +403,17 @@ +@@ -295,4 +385,17 @@ return itemstack; } 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 7569ed90a7..46ca74696e 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerGrindstone.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerGrindstone.patch @@ -31,7 +31,7 @@ public static final int MAX_NAME_LENGTH = 35; public static final int INPUT_SLOT = 0; public static final int ADDITIONAL_SLOT = 1; -@@ -46,6 +68,13 @@ +@@ -46,15 +68,22 @@ super.setChanged(); ContainerGrindstone.this.slotsChanged(this); } @@ -44,7 +44,18 @@ + // CraftBukkit end }; this.access = containeraccess; - this.addSlot(new Slot(this.repairSlots, 0, 49, 19) { +- this.addSlot(new Slot(this, this.repairSlots, 0, 49, 19) { ++ this.addSlot(new Slot(this.repairSlots, 0, 49, 19) { // CraftBukkit - decompile error + @Override + public boolean mayPlace(ItemStack itemstack) { + return itemstack.isDamageableItem() || EnchantmentManager.hasAnyEnchantments(itemstack); + } + }); +- this.addSlot(new Slot(this, this.repairSlots, 1, 49, 40) { ++ this.addSlot(new Slot(this.repairSlots, 1, 49, 40) { // CraftBukkit - decompile error + @Override + public boolean mayPlace(ItemStack itemstack) { + return itemstack.isDamageableItem() || EnchantmentManager.hasAnyEnchantments(itemstack); @@ -124,6 +153,7 @@ this.addSlot(new Slot(playerinventory, j, 8 + j * 18, 142)); } @@ -53,50 +64,17 @@ } @Override -@@ -145,7 +175,7 @@ - boolean flag2 = !itemstack.isEmpty() && !itemstack.is(Items.ENCHANTED_BOOK) && !itemstack.isEnchanted() || !itemstack1.isEmpty() && !itemstack1.is(Items.ENCHANTED_BOOK) && !itemstack1.isEnchanted(); - - if (itemstack.getCount() > 1 || itemstack1.getCount() > 1 || !flag1 && flag2) { -- this.resultSlots.setItem(0, ItemStack.EMPTY); -+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareGrindstoneEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit - this.broadcastChanges(); - return; - } -@@ -156,7 +186,7 @@ - - if (flag1) { - if (!itemstack.is(itemstack1.getItem())) { -- this.resultSlots.setItem(0, ItemStack.EMPTY); -+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareGrindstoneEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit - this.broadcastChanges(); - return; - } -@@ -170,7 +200,7 @@ - itemstack2 = this.mergeEnchants(itemstack, itemstack1); - if (!itemstack2.isDamageableItem()) { - if (!ItemStack.matches(itemstack, itemstack1)) { -- this.resultSlots.setItem(0, ItemStack.EMPTY); -+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareGrindstoneEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit - this.broadcastChanges(); - return; - } -@@ -183,12 +213,12 @@ - i = flag3 ? itemstack.getDamageValue() : itemstack1.getDamageValue(); - itemstack2 = flag3 ? itemstack : itemstack1; - } -- -- this.resultSlots.setItem(0, this.removeNonCurses(itemstack2, i, b0)); -+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareGrindstoneEvent(getBukkitView(), this.removeNonCurses(itemstack2, i, b0)); // CraftBukkit - } else { -- this.resultSlots.setItem(0, ItemStack.EMPTY); -+ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareGrindstoneEvent(getBukkitView(), ItemStack.EMPTY); // CraftBukkit - } +@@ -136,7 +166,8 @@ + } + private void createResult() { +- this.resultSlots.setItem(0, this.computeResult(this.repairSlots.getItem(0), this.repairSlots.getItem(1))); ++ org.bukkit.craftbukkit.event.CraftEventFactory.callPrepareGrindstoneEvent(getBukkitView(), this.computeResult(this.repairSlots.getItem(0), this.repairSlots.getItem(1))); // CraftBukkit + sendAllDataToRemote(); // CraftBukkit - SPIGOT-6686: Always send completed inventory to stay in sync with client this.broadcastChanges(); } -@@ -250,6 +280,7 @@ +@@ -238,6 +269,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 062a5c8d6d..81aa349d99 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerHorse.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerHorse.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/ContainerHorse.java +++ b/net/minecraft/world/inventory/ContainerHorse.java -@@ -8,13 +8,33 @@ +@@ -9,6 +9,11 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -12,7 +12,9 @@ public class ContainerHorse extends Container { private final IInventory horseContainer; - private final EntityHorseAbstract horse; +@@ -17,8 +22,23 @@ + private static final int SLOT_BODY_ARMOR = 1; + private static final int SLOT_HORSE_INVENTORY_START = 2; + // CraftBukkit start + org.bukkit.craftbukkit.inventory.CraftInventoryView bukkitEntity; @@ -32,5 +34,23 @@ + player = playerinventory; + // CraftBukkit end this.horseContainer = iinventory; + this.armorContainer = entityhorseabstract.getBodyArmorAccess(); this.horse = entityhorseabstract; - boolean flag = true; +@@ -27,7 +47,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(); +@@ -38,7 +58,7 @@ + return entityhorseabstract.isSaddleable(); + } + }); +- this.addSlot(new Slot(this, this.armorContainer, 0, 8, 36) { ++ this.addSlot(new Slot(this.armorContainer, 0, 8, 36) { // CraftBukkit - decompile error + @Override + public boolean mayPlace(ItemStack itemstack) { + return entityhorseabstract.isBodyArmorItem(itemstack); 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 858325140c..b0ca235dd6 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerLoom.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerLoom.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/inventory/ContainerLoom.java +++ b/net/minecraft/world/inventory/ContainerLoom.java -@@ -24,8 +24,30 @@ +@@ -23,8 +23,30 @@ + import net.minecraft.world.level.block.entity.BannerPatternLayers; import net.minecraft.world.level.block.entity.EnumBannerPatternType; - import net.minecraft.world.level.block.entity.TileEntityTypes; +// CraftBukkit start +import org.bukkit.Location; @@ -45,7 +45,7 @@ }; this.outputContainer = new InventorySubcontainer(1) { @Override -@@ -67,6 +96,13 @@ +@@ -67,21 +96,28 @@ super.setChanged(); ContainerLoom.this.slotUpdateListener.run(); } @@ -58,11 +58,29 @@ + // CraftBukkit end }; this.access = containeraccess; - this.bannerSlot = this.addSlot(new Slot(this.inputContainer, 0, 13, 26) { -@@ -127,10 +163,12 @@ - } +- this.bannerSlot = this.addSlot(new Slot(this, this.inputContainer, 0, 13, 26) { ++ this.bannerSlot = this.addSlot(new Slot(this.inputContainer, 0, 13, 26) { // CraftBukkit - decompile error + @Override + public boolean mayPlace(ItemStack itemstack) { + return itemstack.getItem() instanceof ItemBanner; + } + }); +- this.dyeSlot = this.addSlot(new Slot(this, this.inputContainer, 1, 33, 26) { ++ this.dyeSlot = this.addSlot(new Slot(this.inputContainer, 1, 33, 26) { // CraftBukkit - decompile error + @Override + public boolean mayPlace(ItemStack itemstack) { + return itemstack.getItem() instanceof ItemDye; + } + }); +- this.patternSlot = this.addSlot(new Slot(this, this.inputContainer, 2, 23, 45) { ++ this.patternSlot = this.addSlot(new Slot(this.inputContainer, 2, 23, 45) { // CraftBukkit - decompile error + @Override + public boolean mayPlace(ItemStack itemstack) { + return itemstack.getItem() instanceof ItemBannerPattern; +@@ -128,10 +164,12 @@ this.addDataSlot(this.selectedBannerPatternIndex); + this.patternGetter = playerinventory.player.registryAccess().lookupOrThrow(Registries.BANNER_PATTERN); + player = (Player) playerinventory.player.getBukkitEntity(); // CraftBukkit } @@ -72,15 +90,15 @@ return stillValid(this.access, entityhuman, Blocks.LOOM); } -@@ -308,6 +346,11 @@ +@@ -306,6 +344,11 @@ + EnumColor enumcolor = ((ItemDye) itemstack1.getItem()).getDyeColor(); - if (nbttagcompound != null && nbttagcompound.contains("Patterns", 9)) { - nbttaglist = nbttagcompound.getList("Patterns", 10); + itemstack2.update(DataComponents.BANNER_PATTERNS, BannerPatternLayers.EMPTY, (bannerpatternlayers) -> { + // CraftBukkit start -+ while (nbttaglist.size() > 20) { -+ nbttaglist.remove(20); ++ if (bannerpatternlayers.layers().size() > 20) { ++ bannerpatternlayers = new BannerPatternLayers(List.copyOf(bannerpatternlayers.layers().subList(0, 20))); + } + // CraftBukkit end - } else { - nbttaglist = new NBTTagList(); - if (nbttagcompound == null) { + return (new BannerPatternLayers.a()).addAll(bannerpatternlayers).add(holder, enumcolor).build(); + }); + } 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 0d7382d66f..388b56b945 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerMerchant.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerMerchant.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/ContainerMerchant.java +++ b/net/minecraft/world/inventory/ContainerMerchant.java -@@ -12,6 +12,8 @@ +@@ -13,6 +13,8 @@ import net.minecraft.world.item.trading.MerchantRecipe; import net.minecraft.world.item.trading.MerchantRecipeList; @@ -9,7 +9,7 @@ public class ContainerMerchant extends Container { protected static final int PAYMENT1_SLOT = 0; -@@ -31,6 +33,19 @@ +@@ -32,6 +34,19 @@ private boolean showProgressBar; private boolean canRestock; @@ -29,7 +29,7 @@ public ContainerMerchant(int i, PlayerInventory playerinventory) { this(i, playerinventory, new MerchantWrapper(playerinventory.player)); } -@@ -42,6 +57,7 @@ +@@ -43,6 +58,7 @@ this.addSlot(new Slot(this.tradeContainer, 0, 136, 37)); this.addSlot(new Slot(this.tradeContainer, 1, 162, 37)); this.addSlot(new SlotMerchantResult(playerinventory.player, imerchant, this.tradeContainer, 2, 220, 37)); @@ -37,7 +37,7 @@ int j; -@@ -154,7 +170,7 @@ +@@ -155,7 +171,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 527e1dcde0..b17d6a725e 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/ContainerPlayer.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/ContainerPlayer.patch @@ -13,7 +13,7 @@ public class ContainerPlayer extends ContainerRecipeBook { public static final int CONTAINER_ID = 0; -@@ -34,15 +40,28 @@ +@@ -36,15 +42,28 @@ public static final MinecraftKey EMPTY_ARMOR_SLOT_SHIELD = new MinecraftKey("item/empty_armor_slot_shield"); static final MinecraftKey[] TEXTURE_EMPTY_SLOTS = new MinecraftKey[]{ContainerPlayer.EMPTY_ARMOR_SLOT_BOOTS, ContainerPlayer.EMPTY_ARMOR_SLOT_LEGGINGS, ContainerPlayer.EMPTY_ARMOR_SLOT_CHESTPLATE, ContainerPlayer.EMPTY_ARMOR_SLOT_HELMET}; private static final EnumItemSlot[] SLOT_IDS = new EnumItemSlot[]{EnumItemSlot.HEAD, EnumItemSlot.CHEST, EnumItemSlot.LEGS, EnumItemSlot.FEET}; @@ -44,7 +44,25 @@ this.addSlot(new SlotResult(playerinventory.player, this.craftSlots, this.resultSlots, 0, 154, 28)); int i; -@@ -259,4 +278,17 @@ +@@ -59,7 +78,7 @@ + for (i = 0; i < 4; ++i) { + final EnumItemSlot enumitemslot = ContainerPlayer.SLOT_IDS[i]; + +- this.addSlot(new Slot(this, playerinventory, 39 - i, 8, 8 + i * 18) { ++ this.addSlot(new Slot(playerinventory, 39 - i, 8, 8 + i * 18) { // CraftBukkit - decompile error + @Override + public void setByPlayer(ItemStack itemstack, ItemStack itemstack1) { + ContainerPlayer.onEquipItem(entityhuman, enumitemslot, itemstack, itemstack1); +@@ -100,7 +119,7 @@ + this.addSlot(new Slot(playerinventory, i, 8 + i * 18, 142)); + } + +- 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) { + ContainerPlayer.onEquipItem(entityhuman, EnumItemSlot.OFFHAND, itemstack, itemstack1); +@@ -261,4 +280,17 @@ public boolean shouldMoveToInventory(int i) { return i != this.getResultSlotIndex(); } 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 586aff71de..6939d4ac54 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/CrafterMenu.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/CrafterMenu.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/CrafterMenu.java +++ b/net/minecraft/world/inventory/CrafterMenu.java -@@ -8,8 +8,27 @@ +@@ -9,8 +9,27 @@ import net.minecraft.world.level.World; import net.minecraft.world.level.block.CrafterBlock; @@ -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; -@@ -116,6 +135,7 @@ +@@ -117,6 +136,7 @@ @Override public boolean stillValid(EntityHuman entityhuman) { diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/InventoryEnderChest.patch b/paper-server/nms-patches/net/minecraft/world/inventory/InventoryEnderChest.patch index 38e077798e..ba63be9d9b 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/InventoryEnderChest.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/InventoryEnderChest.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/inventory/InventoryEnderChest.java +++ b/net/minecraft/world/inventory/InventoryEnderChest.java -@@ -8,13 +8,32 @@ +@@ -9,13 +9,32 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.TileEntityEnderChest; diff --git a/paper-server/nms-patches/net/minecraft/world/inventory/SlotFurnaceResult.patch b/paper-server/nms-patches/net/minecraft/world/inventory/SlotFurnaceResult.patch index 6f6494dba3..f8a6dc26a6 100644 --- a/paper-server/nms-patches/net/minecraft/world/inventory/SlotFurnaceResult.patch +++ b/paper-server/nms-patches/net/minecraft/world/inventory/SlotFurnaceResult.patch @@ -1,9 +1,9 @@ --- a/net/minecraft/world/inventory/SlotFurnaceResult.java +++ b/net/minecraft/world/inventory/SlotFurnaceResult.java -@@ -54,7 +54,7 @@ - if (iinventory instanceof TileEntityFurnace) { - TileEntityFurnace tileentityfurnace = (TileEntityFurnace) iinventory; +@@ -51,7 +51,7 @@ + IInventory iinventory = this.container; + if (iinventory instanceof TileEntityFurnace tileentityfurnace) { - tileentityfurnace.awardUsedRecipesAndPopExperience(entityplayer); + tileentityfurnace.awardUsedRecipesAndPopExperience(entityplayer, itemstack, this.removeCount); // CraftBukkit } diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemArmor.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemArmor.patch index 4b18f9463e..d9045615c2 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemArmor.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemArmor.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemArmor.java +++ b/net/minecraft/world/item/ItemArmor.java -@@ -27,6 +27,12 @@ +@@ -31,6 +31,12 @@ import net.minecraft.world.level.block.BlockDispenser; import net.minecraft.world.phys.AxisAlignedBB; @@ -13,7 +13,7 @@ public class ItemArmor extends Item implements Equipable { private static final EnumMap ARMOR_MODIFIER_UUID_PER_TYPE = (EnumMap) SystemUtils.make(new EnumMap(ItemArmor.a.class), (enummap) -> { -@@ -58,8 +64,34 @@ +@@ -60,8 +66,34 @@ EntityLiving entityliving = (EntityLiving) list.get(0); EnumItemSlot enumitemslot = EntityInsentient.getEquipmentSlotForItem(itemstack); ItemStack itemstack1 = itemstack.split(1); 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 0f096b5bd2..1234a88aac 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemBlock.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemBlock.java +++ b/net/minecraft/world/item/ItemBlock.java -@@ -33,6 +33,13 @@ +@@ -32,6 +32,13 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -13,8 +13,8 @@ + public class ItemBlock extends Item { - public static final String BLOCK_ENTITY_TAG = "BlockEntityTag"; -@@ -71,6 +78,12 @@ + /** @deprecated */ +@@ -68,6 +75,12 @@ return EnumInteractionResult.FAIL; } else { IBlockData iblockdata = this.getPlacementState(blockactioncontext1); @@ -27,9 +27,9 @@ if (iblockdata == null) { return EnumInteractionResult.FAIL; -@@ -87,6 +100,19 @@ - iblockdata1 = this.updateBlockStateFromTag(blockposition, world, itemstack, iblockdata1); +@@ -85,6 +98,19 @@ this.updateCustomBlockEntityTag(blockposition, world, entityhuman, itemstack, iblockdata1); + updateBlockEntityComponents(world, blockposition, itemstack); iblockdata1.getBlock().setPlacedBy(world, blockposition, iblockdata1, entityhuman, itemstack); + // CraftBukkit start + if (blockstate != null) { @@ -47,53 +47,16 @@ if (entityhuman instanceof EntityPlayer) { CriterionTriggers.PLACED_BLOCK.trigger((EntityPlayer) entityhuman, blockposition, itemstack); } -@@ -94,9 +120,9 @@ +@@ -92,7 +118,7 @@ SoundEffectType soundeffecttype = iblockdata1.getSoundType(); - world.playSound(entityhuman, blockposition, this.getPlaceSound(iblockdata1), SoundCategory.BLOCKS, (soundeffecttype.getVolume() + 1.0F) / 2.0F, soundeffecttype.getPitch() * 0.8F); + // world.playSound(entityhuman, blockposition, this.getPlaceSound(iblockdata1), SoundCategory.BLOCKS, (soundeffecttype.getVolume() + 1.0F) / 2.0F, soundeffecttype.getPitch() * 0.8F); - world.gameEvent(GameEvent.BLOCK_PLACE, blockposition, GameEvent.a.of(entityhuman, iblockdata1)); -- if (entityhuman == null || !entityhuman.getAbilities().instabuild) { -+ if ((entityhuman == null || !entityhuman.getAbilities().instabuild) && itemstack != ItemStack.EMPTY) { // CraftBukkit - itemstack.shrink(1); - } - -@@ -132,6 +158,21 @@ - - if (nbttagcompound != null) { - NBTTagCompound nbttagcompound1 = nbttagcompound.getCompound("BlockStateTag"); -+ // CraftBukkit start -+ iblockdata1 = getBlockState(iblockdata1, nbttagcompound1); -+ } -+ -+ if (iblockdata1 != iblockdata) { -+ world.setBlock(blockposition, iblockdata1, 2); -+ } -+ -+ return iblockdata1; -+ } -+ -+ public static IBlockData getBlockState(IBlockData iblockdata, NBTTagCompound nbttagcompound1) { -+ IBlockData iblockdata1 = iblockdata; -+ { -+ // CraftBukkit end - BlockStateList blockstatelist = iblockdata.getBlock().getStateDefinition(); - Iterator iterator = nbttagcompound1.getAllKeys().iterator(); - -@@ -146,11 +187,6 @@ - } - } - } -- -- if (iblockdata1 != iblockdata) { -- world.setBlock(blockposition, iblockdata1, 2); -- } -- - return iblockdata1; - } - -@@ -163,8 +199,15 @@ + 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 @@ protected boolean canPlace(BlockActionContext blockactioncontext, IBlockData iblockdata) { EntityHuman entityhuman = blockactioncontext.getPlayer(); VoxelShapeCollision voxelshapecollision = entityhuman == null ? VoxelShapeCollision.empty() : VoxelShapeCollision.of(entityhuman); @@ -110,12 +73,3 @@ } protected boolean mustSurvive() { -@@ -239,7 +282,7 @@ - - if (nbttagcompound != null && nbttagcompound.contains("Items", 9)) { - NBTTagList nbttaglist = nbttagcompound.getList("Items", 10); -- Stream stream = nbttaglist.stream(); -+ Stream stream = nbttaglist.stream(); // CraftBukkit - decompile error - - Objects.requireNonNull(NBTTagCompound.class); - ItemLiquidUtil.onContainerDestroyed(entityitem, stream.map(NBTTagCompound.class::cast).map(ItemStack::of)); 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 93150dedb2..dc6429b010 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 -@@ -60,6 +60,13 @@ +@@ -61,6 +61,13 @@ } if (movingobjectpositionblock.getType() == MovingObjectPosition.EnumMovingObjectType.BLOCK) { @@ -14,7 +14,7 @@ EntityBoat entityboat = this.getBoat(world, movingobjectpositionblock, itemstack, entityhuman); entityboat.setVariant(this.type); -@@ -68,7 +75,15 @@ +@@ -69,7 +76,15 @@ return InteractionResultWrapper.fail(itemstack); } else { if (!world.isClientSide) { @@ -28,15 +28,15 @@ + return InteractionResultWrapper.pass(itemstack); + } + // CraftBukkit end - world.gameEvent((Entity) entityhuman, GameEvent.ENTITY_PLACE, movingobjectpositionblock.getLocation()); - if (!entityhuman.getAbilities().instabuild) { - itemstack.shrink(1); -@@ -86,7 +101,7 @@ + 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 worldserver = (WorldServer) world; + if (world instanceof WorldServer worldserver) { + EntityTypes.createDefaultStackConfig(worldserver, itemstack, entityhuman).accept(object); diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemBoneMeal.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemBoneMeal.patch index 0e32a858eb..f658c4a4e6 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemBoneMeal.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemBoneMeal.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemBoneMeal.java +++ b/net/minecraft/world/item/ItemBoneMeal.java -@@ -34,13 +34,19 @@ +@@ -35,13 +35,19 @@ @Override public EnumInteractionResult useOn(ItemActionContext itemactioncontext) { @@ -18,15 +18,15 @@ if (!world.isClientSide) { - itemactioncontext.getPlayer().gameEvent(GameEvent.ITEM_INTERACT_FINISH); + if (itemactioncontext.getPlayer() != null) itemactioncontext.getPlayer().gameEvent(GameEvent.ITEM_INTERACT_FINISH); // CraftBukkit - SPIGOT-7518 - world.levelEvent(1505, blockposition, 0); + world.levelEvent(1505, blockposition, 15); } -@@ -51,7 +57,7 @@ +@@ -52,7 +58,7 @@ if (flag && growWaterPlant(itemactioncontext.getItemInHand(), world, blockposition1, itemactioncontext.getClickedFace())) { if (!world.isClientSide) { - itemactioncontext.getPlayer().gameEvent(GameEvent.ITEM_INTERACT_FINISH); + if (itemactioncontext.getPlayer() != null) itemactioncontext.getPlayer().gameEvent(GameEvent.ITEM_INTERACT_FINISH); // CraftBukkit - SPIGOT-7518 - world.levelEvent(1505, blockposition1, 0); + world.levelEvent(1505, blockposition1, 15); } diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemBow.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemBow.patch deleted file mode 100644 index 44da9e2cbf..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemBow.patch +++ /dev/null @@ -1,35 +0,0 @@ ---- a/net/minecraft/world/item/ItemBow.java -+++ b/net/minecraft/world/item/ItemBow.java -@@ -64,6 +64,14 @@ - if (EnchantmentManager.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, itemstack) > 0) { - entityarrow.setSecondsOnFire(100); - } -+ // CraftBukkit start -+ org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(entityhuman, itemstack, itemstack1, entityarrow, entityhuman.getUsedItemHand(), f, !flag1); -+ if (event.isCancelled()) { -+ event.getProjectile().remove(); -+ return; -+ } -+ flag1 = !event.shouldConsumeItem(); -+ // CraftBukkit end - - itemstack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { - entityhuman1.broadcastBreakEvent(entityhuman.getUsedItemHand()); -@@ -72,7 +80,16 @@ - entityarrow.pickup = EntityArrow.PickupStatus.CREATIVE_ONLY; - } - -- world.addFreshEntity(entityarrow); -+ // CraftBukkit start -+ if (event.getProjectile() == entityarrow.getBukkitEntity()) { -+ if (!world.addFreshEntity(entityarrow)) { -+ if (entityhuman instanceof net.minecraft.server.level.EntityPlayer) { -+ ((net.minecraft.server.level.EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); -+ } -+ return; -+ } -+ } -+ // CraftBukkit end - } - - world.playSound((EntityHuman) null, entityhuman.getX(), entityhuman.getY(), entityhuman.getZ(), SoundEffects.ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (world.getRandom().nextFloat() * 0.4F + 1.2F) + f * 0.5F); 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 6f02b19e96..8e138afa51 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemBucket.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemBucket.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemBucket.java +++ b/net/minecraft/world/item/ItemBucket.java -@@ -29,6 +29,16 @@ +@@ -30,6 +30,16 @@ import net.minecraft.world.phys.MovingObjectPosition; import net.minecraft.world.phys.MovingObjectPositionBlock; @@ -17,7 +17,7 @@ public class ItemBucket extends Item implements DispensibleContainerItem { public final FluidType content; -@@ -61,6 +71,17 @@ +@@ -62,6 +72,17 @@ if (block instanceof IFluidSource) { IFluidSource ifluidsource = (IFluidSource) block; @@ -35,16 +35,16 @@ ItemStack itemstack1 = ifluidsource.pickupBlock(entityhuman, world, blockposition, iblockdata); if (!itemstack1.isEmpty()) { -@@ -69,7 +90,7 @@ +@@ -70,7 +91,7 @@ entityhuman.playSound(soundeffect, 1.0F, 1.0F); }); - world.gameEvent((Entity) entityhuman, GameEvent.FLUID_PICKUP, blockposition); + world.gameEvent((Entity) entityhuman, (Holder) GameEvent.FLUID_PICKUP, blockposition); - ItemStack itemstack2 = ItemLiquidUtil.createFilledResult(itemstack, entityhuman, itemstack1); + ItemStack itemstack2 = ItemLiquidUtil.createFilledResult(itemstack, entityhuman, CraftItemStack.asNMSCopy(event.getItemStack())); // CraftBukkit if (!world.isClientSide) { CriterionTriggers.FILLED_BUCKET.trigger((EntityPlayer) entityhuman, itemstack1); -@@ -84,7 +105,7 @@ +@@ -85,7 +106,7 @@ iblockdata = world.getBlockState(blockposition); BlockPosition blockposition2 = iblockdata.getBlock() instanceof IFluidContainer && this.content == FluidTypes.WATER ? blockposition : blockposition1; @@ -53,7 +53,7 @@ this.checkExtraContent(entityhuman, world, itemstack, blockposition2); if (entityhuman instanceof EntityPlayer) { CriterionTriggers.PLACED_BLOCK.trigger((EntityPlayer) entityhuman, blockposition2, itemstack); -@@ -111,6 +132,12 @@ +@@ -112,6 +133,12 @@ @Override public boolean emptyContents(@Nullable EntityHuman entityhuman, World world, BlockPosition blockposition, @Nullable MovingObjectPositionBlock movingobjectpositionblock) { @@ -65,8 +65,8 @@ + // CraftBukkit end FluidType fluidtype = this.content; - if (!(fluidtype instanceof FluidTypeFlowing)) { -@@ -148,8 +175,18 @@ + if (!(fluidtype instanceof FluidTypeFlowing fluidtypeflowing)) { +@@ -147,8 +174,18 @@ boolean flag2 = flag1; diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemChorusFruit.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemChorusFruit.patch index 8915087352..c012769586 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemChorusFruit.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemChorusFruit.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemChorusFruit.java +++ b/net/minecraft/world/item/ItemChorusFruit.java -@@ -35,7 +35,16 @@ +@@ -36,7 +36,16 @@ Vec3D vec3d = entityliving.position(); @@ -15,6 +15,6 @@ + + if (status.get()) { + // CraftBukkit end - world.gameEvent(GameEvent.TELEPORT, vec3d, GameEvent.a.of((Entity) entityliving)); + 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/ItemCrossbow.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemCrossbow.patch deleted file mode 100644 index d1b86c9d2e..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemCrossbow.patch +++ /dev/null @@ -1,31 +0,0 @@ ---- a/net/minecraft/world/item/ItemCrossbow.java -+++ b/net/minecraft/world/item/ItemCrossbow.java -@@ -236,11 +236,27 @@ - - ((IProjectile) object).shoot((double) vector3f.x(), (double) vector3f.y(), (double) vector3f.z(), f1, f2); - } -+ // CraftBukkit start -+ org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(entityliving, itemstack, itemstack1, (Entity) object, entityliving.getUsedItemHand(), f, true); -+ if (event.isCancelled()) { -+ event.getProjectile().remove(); -+ return; -+ } -+ // CraftBukkit end - - itemstack.hurtAndBreak(flag1 ? 3 : 1, entityliving, (entityliving1) -> { - entityliving1.broadcastBreakEvent(enumhand); - }); -- world.addFreshEntity((Entity) object); -+ // CraftBukkit start -+ if (event.getProjectile() == ((Entity) object).getBukkitEntity()) { -+ if (!world.addFreshEntity((Entity) object)) { -+ if (entityliving instanceof EntityPlayer) { -+ ((EntityPlayer) entityliving).getBukkitEntity().updateInventory(); -+ } -+ return; -+ } -+ } -+ // CraftBukkit end - world.playSound((EntityHuman) null, entityliving.getX(), entityliving.getY(), entityliving.getZ(), SoundEffects.CROSSBOW_SHOOT, SoundCategory.PLAYERS, 1.0F, f); - } - } diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemDebugStick.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemDebugStick.patch index f1eea636d5..d871cc165f 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemDebugStick.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemDebugStick.patch @@ -5,7 +5,7 @@ package net.minecraft.world.item; import java.util.Collection; -@@ -95,7 +96,7 @@ +@@ -92,7 +93,7 @@ } private static > IBlockData cycleState(IBlockData iblockdata, IBlockState iblockstate, boolean flag) { diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemDye.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemDye.patch index 67a3f2eab9..41737c92c6 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemDye.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemDye.patch @@ -9,7 +9,7 @@ public class ItemDye extends Item implements SignApplicator { private static final Map ITEM_BY_COLOR = Maps.newEnumMap(EnumColor.class); -@@ -32,7 +34,17 @@ +@@ -30,7 +32,17 @@ if (entitysheep.isAlive() && !entitysheep.isSheared() && entitysheep.getColor() != this.dyeColor) { entitysheep.level().playSound(entityhuman, (Entity) entitysheep, SoundEffects.DYE_USE, SoundCategory.PLAYERS, 1.0F, 1.0F); if (!entityhuman.level().isClientSide) { 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 40f4faa8e8..363eb91660 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemEgg.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemEgg.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemEgg.java +++ b/net/minecraft/world/item/ItemEgg.java -@@ -19,14 +19,22 @@ +@@ -22,14 +22,22 @@ public InteractionResultWrapper use(World world, EntityHuman entityhuman, EnumHand enumhand) { ItemStack itemstack = entityhuman.getItemInHand(enumhand); @@ -24,4 +24,4 @@ + 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)); entityhuman.awardStat(StatisticList.ITEM_USED.get(this)); - if (!entityhuman.getAbilities().instabuild) { + itemstack.consume(1, entityhuman); diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemEndCrystal.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemEndCrystal.patch index 9ca1d4f105..0981092fb3 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemEndCrystal.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemEndCrystal.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemEndCrystal.java +++ b/net/minecraft/world/item/ItemEndCrystal.java -@@ -46,6 +46,11 @@ +@@ -47,6 +47,11 @@ EntityEnderCrystal entityendercrystal = new EntityEnderCrystal(world, d0 + 0.5D, d1, d2 + 0.5D); entityendercrystal.setShowBottom(false); @@ -10,5 +10,5 @@ + } + // CraftBukkit end world.addFreshEntity(entityendercrystal); - world.gameEvent((Entity) itemactioncontext.getPlayer(), GameEvent.ENTITY_PLACE, blockposition1); + world.gameEvent((Entity) itemactioncontext.getPlayer(), (Holder) GameEvent.ENTITY_PLACE, blockposition1); EnderDragonBattle enderdragonbattle = ((WorldServer) world).getDragonFight(); 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 e573b447a5..6542d1181f 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemEnderEye.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemEnderEye.patch @@ -1,9 +1,9 @@ --- a/net/minecraft/world/item/ItemEnderEye.java +++ b/net/minecraft/world/item/ItemEnderEye.java -@@ -89,7 +89,11 @@ +@@ -95,7 +95,11 @@ entityendersignal.setItem(itemstack); entityendersignal.signalTo(blockposition); - world.gameEvent(GameEvent.PROJECTILE_SHOOT, entityendersignal.position(), GameEvent.a.of((Entity) entityhuman)); + world.gameEvent((Holder) GameEvent.PROJECTILE_SHOOT, entityendersignal.position(), GameEvent.a.of((Entity) entityhuman)); - world.addFreshEntity(entityendersignal); + // CraftBukkit start + if (!world.addFreshEntity(entityendersignal)) { 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 8ec7abc437..21f3d9275e 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemEnderPearl.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemEnderPearl.patch @@ -26,5 +26,5 @@ + // CraftBukkit end + entityhuman.awardStat(StatisticList.ITEM_USED.get(this)); - if (!entityhuman.getAbilities().instabuild) { - itemstack.shrink(1); + itemstack.consume(1, entityhuman); + return InteractionResultWrapper.sidedSuccess(itemstack, world.isClientSide()); diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemFireball.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemFireball.patch index 7d05028ae8..5244137025 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemFireball.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemFireball.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemFireball.java +++ b/net/minecraft/world/item/ItemFireball.java -@@ -33,12 +33,28 @@ +@@ -40,12 +40,28 @@ if (!BlockCampfire.canLight(iblockdata) && !CandleBlock.canLight(iblockdata) && !CandleCakeBlock.canLight(iblockdata)) { blockposition = blockposition.relative(itemactioncontext.getClickedFace()); if (BlockFireAbstract.canBePlacedAt(world, blockposition, itemactioncontext.getHorizontalDirection())) { @@ -14,7 +14,7 @@ + // CraftBukkit end this.playSound(world, blockposition); world.setBlockAndUpdate(blockposition, BlockFireAbstract.getState(world, blockposition)); - world.gameEvent((Entity) itemactioncontext.getPlayer(), GameEvent.BLOCK_PLACE, blockposition); + world.gameEvent((Entity) itemactioncontext.getPlayer(), (Holder) GameEvent.BLOCK_PLACE, blockposition); flag = true; } } else { @@ -28,4 +28,4 @@ + // CraftBukkit end this.playSound(world, blockposition); world.setBlockAndUpdate(blockposition, (IBlockData) iblockdata.setValue(BlockProperties.LIT, true)); - world.gameEvent((Entity) itemactioncontext.getPlayer(), GameEvent.BLOCK_CHANGE, blockposition); + world.gameEvent((Entity) itemactioncontext.getPlayer(), (Holder) GameEvent.BLOCK_CHANGE, blockposition); 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 e35b245432..f77b17bb04 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 -@@ -11,6 +11,11 @@ +@@ -12,6 +12,11 @@ import net.minecraft.world.level.World; import net.minecraft.world.level.gameevent.GameEvent; @@ -9,10 +9,10 @@ +import org.bukkit.craftbukkit.CraftEquipmentSlot; +// CraftBukkit end + - public class ItemFishingRod extends Item implements ItemVanishable { + public class ItemFishingRod extends Item { public ItemFishingRod(Item.Info item_info) { -@@ -33,12 +38,23 @@ +@@ -32,12 +37,23 @@ 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 { diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemFlintAndSteel.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemFlintAndSteel.patch index 4ecadc4d1e..2c70693655 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemFlintAndSteel.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemFlintAndSteel.patch @@ -1,32 +1,28 @@ --- a/net/minecraft/world/item/ItemFlintAndSteel.java +++ b/net/minecraft/world/item/ItemFlintAndSteel.java -@@ -35,6 +35,14 @@ +@@ -37,6 +37,12 @@ BlockPosition blockposition1 = blockposition.relative(itemactioncontext.getClickedFace()); if (BlockFireAbstract.canBePlacedAt(world, blockposition1, itemactioncontext.getHorizontalDirection())) { + // CraftBukkit start - Store the clicked block + if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition1, org.bukkit.event.block.BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL, entityhuman).isCancelled()) { -+ itemactioncontext.getItemInHand().hurtAndBreak(1, entityhuman, (entityhuman1) -> { -+ entityhuman1.broadcastBreakEvent(itemactioncontext.getHand()); -+ }); ++ itemactioncontext.getItemInHand().hurtAndBreak(1, entityhuman, EntityLiving.getSlotForHand(itemactioncontext.getHand())); + return EnumInteractionResult.PASS; + } + // CraftBukkit end world.playSound(entityhuman, blockposition1, SoundEffects.FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, world.getRandom().nextFloat() * 0.4F + 0.8F); IBlockData iblockdata1 = BlockFireAbstract.getState(world, blockposition1); -@@ -54,6 +62,14 @@ +@@ -54,6 +60,12 @@ return EnumInteractionResult.FAIL; } } else { + // CraftBukkit start - Store the clicked block + if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, blockposition, org.bukkit.event.block.BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL, entityhuman).isCancelled()) { -+ itemactioncontext.getItemInHand().hurtAndBreak(1, entityhuman, (entityhuman1) -> { -+ entityhuman1.broadcastBreakEvent(itemactioncontext.getHand()); -+ }); ++ itemactioncontext.getItemInHand().hurtAndBreak(1, entityhuman, EntityLiving.getSlotForHand(itemactioncontext.getHand())); + return EnumInteractionResult.PASS; + } + // CraftBukkit end world.playSound(entityhuman, blockposition, SoundEffects.FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, world.getRandom().nextFloat() * 0.4F + 0.8F); world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockProperties.LIT, true), 11); - world.gameEvent((Entity) entityhuman, GameEvent.BLOCK_CHANGE, blockposition); + world.gameEvent((Entity) entityhuman, (Holder) GameEvent.BLOCK_CHANGE, blockposition); 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 e259a2f2fb..56fb587865 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 -@@ -22,6 +22,11 @@ +@@ -23,6 +23,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); -@@ -72,6 +77,19 @@ +@@ -73,6 +78,19 @@ if (((EntityHanging) object).survives()) { if (!world.isClientSide) { @@ -30,5 +30,5 @@ + } + // CraftBukkit end ((EntityHanging) object).playPlacementSound(); - world.gameEvent((Entity) entityhuman, GameEvent.ENTITY_PLACE, ((EntityHanging) object).position()); + world.gameEvent((Entity) entityhuman, (Holder) GameEvent.ENTITY_PLACE, ((EntityHanging) object).position()); world.addFreshEntity((Entity) object); 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 1e0a8684eb..3738eab0b4 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemLeash.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemLeash.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemLeash.java +++ b/net/minecraft/world/item/ItemLeash.java -@@ -15,6 +15,11 @@ +@@ -16,6 +16,11 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.AxisAlignedBB; @@ -12,7 +12,7 @@ public class ItemLeash extends Item { public ItemLeash(Item.Info item_info) { -@@ -31,7 +36,7 @@ +@@ -32,7 +37,7 @@ EntityHuman entityhuman = itemactioncontext.getPlayer(); if (!world.isClientSide && entityhuman != null) { @@ -21,45 +21,49 @@ } return EnumInteractionResult.sidedSuccess(world.isClientSide); -@@ -40,7 +45,7 @@ +@@ -41,7 +46,7 @@ } } - public static EnumInteractionResult bindPlayerMobs(EntityHuman entityhuman, World world, BlockPosition blockposition) { + public static EnumInteractionResult bindPlayerMobs(EntityHuman entityhuman, World world, BlockPosition blockposition, net.minecraft.world.EnumHand enumhand) { // CraftBukkit - Add EnumHand EntityLeash entityleash = null; - boolean flag = false; double d0 = 7.0D; -@@ -56,9 +61,26 @@ - if (entityinsentient.getLeashHolder() == entityhuman) { - if (entityleash == null) { - entityleash = EntityLeash.getOrCreateKnot(world, blockposition); -+ -+ // CraftBukkit start - fire HangingPlaceEvent -+ org.bukkit.inventory.EquipmentSlot hand = CraftEquipmentSlot.getHand(enumhand); -+ HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) entityleash.getBukkitEntity(), entityhuman != null ? (org.bukkit.entity.Player) entityhuman.getBukkitEntity() : null, world.getWorld().getBlockAt(i, j, k), org.bukkit.block.BlockFace.SELF, hand); -+ world.getCraftServer().getPluginManager().callEvent(event); -+ -+ if (event.isCancelled()) { -+ entityleash.discard(null); // CraftBukkit - add Bukkit remove cause -+ return EnumInteractionResult.PASS; -+ } -+ // CraftBukkit end - entityleash.playPlacementSound(); - } + int i = blockposition.getX(); +@@ -54,12 +59,29 @@ -+ // CraftBukkit start -+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, entityleash, entityhuman, enumhand).isCancelled()) { -+ continue; + EntityInsentient entityinsentient; + +- for (Iterator iterator = list.iterator(); iterator.hasNext(); entityinsentient.setLeashedTo(entityleash, true)) { ++ for (Iterator iterator = list.iterator(); iterator.hasNext();) { // CraftBukkit - handle setLeashedTo at end of loop + entityinsentient = (EntityInsentient) iterator.next(); + if (entityleash == null) { + entityleash = EntityLeash.getOrCreateKnot(world, blockposition); ++ ++ // CraftBukkit start - fire HangingPlaceEvent ++ org.bukkit.inventory.EquipmentSlot hand = CraftEquipmentSlot.getHand(enumhand); ++ HangingPlaceEvent event = new HangingPlaceEvent((org.bukkit.entity.Hanging) entityleash.getBukkitEntity(), entityhuman != null ? (org.bukkit.entity.Player) entityhuman.getBukkitEntity() : null, world.getWorld().getBlockAt(i, j, k), org.bukkit.block.BlockFace.SELF, hand); ++ world.getCraftServer().getPluginManager().callEvent(event); ++ ++ if (event.isCancelled()) { ++ entityleash.discard(null); // CraftBukkit - add Bukkit remove cause ++ return EnumInteractionResult.PASS; + } + // CraftBukkit end -+ - entityinsentient.setLeashedTo(entityleash, true); - flag = true; + entityleash.playPlacementSound(); } -@@ -70,4 +92,10 @@ ++ ++ // CraftBukkit start ++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, entityleash, entityhuman, enumhand).isCancelled()) { ++ entityinsentient.setLeashedTo(entityleash, true); ++ } ++ // CraftBukkit end + } - return flag ? EnumInteractionResult.SUCCESS : EnumInteractionResult.PASS; + if (!list.isEmpty()) { +@@ -69,4 +91,10 @@ + return EnumInteractionResult.PASS; + } } + + // CraftBukkit start diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemMilkBucket.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemMilkBucket.patch index 43f0adc5b7..3aaf24a966 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemMilkBucket.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemMilkBucket.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/item/ItemMilkBucket.java +++ b/net/minecraft/world/item/ItemMilkBucket.java -@@ -31,7 +31,7 @@ - } +@@ -26,7 +26,7 @@ + itemstack.consume(1, entityliving); if (!world.isClientSide) { - entityliving.removeAllEffects(); + entityliving.removeAllEffects(org.bukkit.event.entity.EntityPotionEffectEvent.Cause.MILK); // CraftBukkit 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 33589d482b..856e6f4114 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemMinecart.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemMinecart.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemMinecart.java +++ b/net/minecraft/world/item/ItemMinecart.java -@@ -19,6 +19,12 @@ +@@ -20,6 +20,12 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.Vec3D; @@ -13,7 +13,7 @@ public class ItemMinecart extends Item { private static final IDispenseBehavior DISPENSE_ITEM_BEHAVIOR = new DispenseBehaviorItem() { -@@ -58,10 +64,39 @@ +@@ -59,10 +65,39 @@ } } @@ -56,7 +56,7 @@ return itemstack; } -@@ -100,7 +135,12 @@ +@@ -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()); @@ -67,6 +67,6 @@ + } + // CraftBukkit end + if (!worldserver.addFreshEntity(entityminecartabstract)) return EnumInteractionResult.PASS; // CraftBukkit - worldserver.gameEvent(GameEvent.ENTITY_PLACE, blockposition, GameEvent.a.of(itemactioncontext.getPlayer(), worldserver.getBlockState(blockposition.below()))); + 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 72316a341e..a56361ee5a 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemMonsterEgg.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemMonsterEgg.patch @@ -1,18 +1,13 @@ --- a/net/minecraft/world/item/ItemMonsterEgg.java +++ b/net/minecraft/world/item/ItemMonsterEgg.java -@@ -180,7 +180,7 @@ +@@ -177,10 +177,10 @@ return Optional.empty(); } else { ((EntityInsentient) object).moveTo(vec3d.x(), vec3d.y(), vec3d.z(), 0.0F, 0.0F); - worldserver.addFreshEntityWithPassengers((Entity) object); + worldserver.addFreshEntityWithPassengers((Entity) object, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SPAWNER_EGG); // CraftBukkit - if (itemstack.hasCustomHoverName()) { - ((EntityInsentient) object).setCustomName(itemstack.getHoverName()); - } -@@ -189,7 +189,7 @@ - itemstack.shrink(1); - } - + ((EntityInsentient) object).setCustomName((IChatBaseComponent) itemstack.get(DataComponents.CUSTOM_NAME)); + itemstack.consume(1, entityhuman); - return Optional.of(object); + return Optional.of((EntityInsentient) object); // CraftBukkit - decompile error } diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemPotion.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemPotion.patch index 70bceabbb2..cfbb4bb5ea 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemPotion.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemPotion.patch @@ -1,11 +1,11 @@ --- a/net/minecraft/world/item/ItemPotion.java +++ b/net/minecraft/world/item/ItemPotion.java -@@ -60,7 +60,7 @@ - if (mobeffect.getEffect().isInstantenous()) { - mobeffect.getEffect().applyInstantenousEffect(entityhuman, entityhuman, entityliving, mobeffect.getAmplifier(), 1.0D); +@@ -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(new MobEffect(mobeffect)); -+ entityliving.addEffect(new MobEffect(mobeffect), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.POTION_DRINK); // CraftBukkit +- 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 new file mode 100644 index 0000000000..4b2a399368 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemProjectileWeapon.patch @@ -0,0 +1,33 @@ +--- a/net/minecraft/world/item/ItemProjectileWeapon.java ++++ b/net/minecraft/world/item/ItemProjectileWeapon.java +@@ -59,11 +59,28 @@ + float f6 = f4 + f5 * (float) ((i + 1) / 2) * f3; + + f5 = -f5; +- itemstack.hurtAndBreak(this.getDurabilityUse(itemstack1), entityliving, EntityLiving.getSlotForHand(enumhand)); ++ // itemstack.hurtAndBreak(this.getDurabilityUse(itemstack1), entityliving, EntityLiving.getSlotForHand(enumhand)); // CraftBukkit - moved down + IProjectile iprojectile = this.createProjectile(world, entityliving, itemstack, itemstack1, flag); + + this.shootProjectile(entityliving, iprojectile, i, f, f1, f6, entityliving1); +- world.addFreshEntity(iprojectile); ++ // CraftBukkit start ++ 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(); ++ return; ++ } ++ ++ itemstack.hurtAndBreak(this.getDurabilityUse(itemstack1), entityliving, EntityLiving.getSlotForHand(enumhand)); ++ ++ if (event.getProjectile() == iprojectile.getBukkitEntity()) { ++ if (!world.addFreshEntity(iprojectile)) { ++ if (entityliving instanceof net.minecraft.server.level.EntityPlayer) { ++ ((net.minecraft.server.level.EntityPlayer) entityliving).getBukkitEntity().updateInventory(); ++ } ++ return; ++ } ++ } ++ // CraftBukkit end + } + } + diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemRecord.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemRecord.patch index 74b4bd490d..2b2be2b018 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemRecord.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemRecord.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemRecord.java +++ b/net/minecraft/world/item/ItemRecord.java -@@ -46,6 +46,7 @@ +@@ -47,6 +47,7 @@ ItemStack itemstack = itemactioncontext.getItemInHand(); if (!world.isClientSide) { 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 84f81c9d47..d8cb71efb6 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemSnowball.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemSnowball.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ItemSnowball.java +++ b/net/minecraft/world/item/ItemSnowball.java -@@ -19,19 +19,32 @@ +@@ -22,17 +22,25 @@ public InteractionResultWrapper use(World world, EntityHuman entityhuman, EnumHand enumhand) { ItemStack itemstack = entityhuman.getItemInHand(enumhand); @@ -14,9 +14,7 @@ entitysnowball.shootFromRotation(entityhuman, entityhuman.getXRot(), entityhuman.getYRot(), 0.0F, 1.5F, 1.0F); - world.addFreshEntity(entitysnowball); + if (world.addFreshEntity(entitysnowball)) { -+ if (!entityhuman.getAbilities().instabuild) { -+ itemstack.shrink(1); -+ } ++ 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) { @@ -26,12 +24,8 @@ + // CraftBukkit end entityhuman.awardStat(StatisticList.ITEM_USED.get(this)); -+ // CraftBukkit start - moved up -+ /* - if (!entityhuman.getAbilities().instabuild) { - itemstack.shrink(1); - } -+ */ - +- itemstack.consume(1, entityhuman); ++ // itemstack.consume(1, entityhuman); // CraftBukkit - moved up return InteractionResultWrapper.sidedSuccess(itemstack, world.isClientSide()); } + 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 b2754ac6ca..9885ca1eac 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemStack.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemStack.patch @@ -1,20 +1,17 @@ --- a/net/minecraft/world/item/ItemStack.java +++ b/net/minecraft/world/item/ItemStack.java -@@ -81,6 +81,44 @@ - import net.minecraft.world.level.block.state.pattern.ShapeDetectorBlock; +@@ -92,6 +92,40 @@ + import org.apache.commons.lang3.mutable.MutableBoolean; import org.slf4j.Logger; +// CraftBukkit start -+import com.mojang.serialization.Dynamic; +import java.util.Map; +import java.util.Objects; +import net.minecraft.core.EnumDirection; +import net.minecraft.nbt.DynamicOpsNBT; +import net.minecraft.network.protocol.game.PacketPlayOutBlockChange; -+import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.WorldServer; +import net.minecraft.sounds.SoundCategory; -+import net.minecraft.util.datafix.fixes.DataConverterTypes; +import net.minecraft.world.level.block.BlockBed; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.BlockSapling; @@ -35,55 +32,78 @@ +import org.bukkit.craftbukkit.block.CraftBlockState; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.util.CraftLocation; -+import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockFertilizeEvent; +import org.bukkit.event.player.PlayerItemDamageEvent; +import org.bukkit.event.world.StructureGrowEvent; +// CraftBukkit end + - public final class ItemStack { + public final class ItemStack implements DataComponentHolder { - public static final Codec CODEC = RecordCodecBuilder.create((instance) -> { -@@ -175,7 +213,18 @@ - this.item = null; - } + public static final Codec> ITEM_NON_AIR_CODEC = BuiltInRegistries.ITEM.holderByNameCodec().validate((holder) -> { +@@ -100,14 +134,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.POSITIVE_INT.fieldOf("count").orElse(1).forGetter(ItemStack::getCount), DataComponentPatch.CODEC.optionalFieldOf("components", DataComponentPatch.EMPTY).forGetter((itemstack) -> { + return itemstack.components.asPatch(); + })).apply(instance, ItemStack::new); + }); + }); + 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 itemstack.components.asPatch(); + })).apply(instance, (holder, datacomponentpatch) -> { +@@ -132,19 +166,25 @@ + if (i <= 0) { + return ItemStack.EMPTY; + } else { +- Holder holder = (Holder) null.ITEM_STREAM_CODEC.decode(registryfriendlybytebuf); ++ Holder holder = (Holder) ITEM_STREAM_CODEC.decode(registryfriendlybytebuf); // CraftBukkit - decompile error + DataComponentPatch datacomponentpatch = (DataComponentPatch) DataComponentPatch.STREAM_CODEC.decode(registryfriendlybytebuf); -- private ItemStack(NBTTagCompound nbttagcompound) { -+ // Called to run this stack through the data converter to handle older storage methods and serialized items -+ public void convertStack(int version) { -+ if (0 < version && version < CraftMagicNumbers.INSTANCE.getDataVersion()) { -+ NBTTagCompound savedStack = new NBTTagCompound(); -+ this.save(savedStack); -+ savedStack = (NBTTagCompound) MinecraftServer.getServer().fixerUpper.update(DataConverterTypes.ITEM_STACK, new Dynamic(DynamicOpsNBT.INSTANCE, savedStack), version, CraftMagicNumbers.INSTANCE.getDataVersion()).getValue(); -+ this.load(savedStack); -+ } -+ } -+ -+ // CraftBukkit - break into own method -+ private void load(NBTTagCompound nbttagcompound) { - this.item = (Item) BuiltInRegistries.ITEM.get(new MinecraftKey(nbttagcompound.getString("id"))); - this.count = nbttagcompound.getByte("Count"); - if (nbttagcompound.contains("tag", 10)) { -@@ -189,6 +238,11 @@ +- return new ItemStack(holder, i, datacomponentpatch); ++ // CraftBukkit start ++ ItemStack itemstack = new ItemStack(holder, i, datacomponentpatch); ++ if (!datacomponentpatch.isEmpty()) { ++ CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack)); ++ } ++ return itemstack; ++ // CraftBukkit end + } + } - } + public void encode(RegistryFriendlyByteBuf registryfriendlybytebuf, ItemStack itemstack) { +- if (itemstack.isEmpty()) { ++ if (itemstack.isEmpty() || itemstack.getItem() == null) { // CraftBukkit - NPE fix itemstack.getItem() + registryfriendlybytebuf.writeVarInt(0); + } else { + registryfriendlybytebuf.writeVarInt(itemstack.getCount()); +- null.ITEM_STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.getItemHolder()); ++ ITEM_STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.getItemHolder()); // CraftBukkit - decompile error + DataComponentPatch.STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.components.asPatch()); + } + } +@@ -188,7 +228,7 @@ -+ private ItemStack(NBTTagCompound nbttagcompound) { -+ this.load(nbttagcompound); -+ // CraftBukkit end -+ } -+ - public static ItemStack of(NBTTagCompound nbttagcompound) { - try { - return new ItemStack(nbttagcompound); -@@ -266,11 +320,191 @@ + return dataresult.isError() ? dataresult.map((unit) -> { + return itemstack; +- }) : (itemstack.getCount() > itemstack.getMaxStackSize() ? DataResult.error(() -> { ++ }) : (itemstack.getCount() > itemstack.getMaxStackSize() ? DataResult.error(() -> { // CraftBukkit - decompile error + int i = itemstack.getCount(); + + return "Item stack with stack size of " + i + " was larger than maximum: " + itemstack.getMaxStackSize(); +@@ -347,11 +387,191 @@ return EnumInteractionResult.PASS; } else { Item item = this.getItem(); - EnumInteractionResult enuminteractionresult = item.useOn(itemactioncontext); + // CraftBukkit start - handle all block place event logic here -+ NBTTagCompound oldData = this.getTagClone(); ++ PatchedDataComponentMap oldData = this.getComponentsClone(); + int oldCount = this.getCount(); + WorldServer world = (WorldServer) itemactioncontext.getLevel(); + @@ -100,10 +120,10 @@ + } finally { + world.captureBlockStates = false; + } -+ NBTTagCompound newData = this.getTagClone(); ++ PatchedDataComponentMap newData = this.getComponentsClone(); + int newCount = this.getCount(); + this.setCount(oldCount); -+ this.setTagClone(oldData); ++ this.setComponentsClone(oldData); + if (enuminteractionresult.consumesAction() && world.captureTreeGeneration && world.capturedBlockStates.size() > 0) { + world.captureTreeGeneration = false; + Location location = CraftLocation.toBukkit(blockposition, world.getWorld()); @@ -124,8 +144,8 @@ + + if (!fertilizeEvent.isCancelled()) { + // Change the stack to its new contents if it hasn't been tampered with. -+ if (this.getCount() == oldCount && Objects.equals(this.tag, oldData)) { -+ this.setTag(newData); ++ if (this.getCount() == oldCount && Objects.equals(this.components, oldData)) { ++ this.applyComponents(newData); + this.setCount(newCount); + } + for (CraftBlockState blockstate : blocks) { @@ -140,7 +160,7 @@ + } + world.captureTreeGeneration = false; - if (entityhuman != null && enuminteractionresult.shouldAwardStats()) { + if (entityhuman != null && enuminteractionresult.indicateItemUse()) { - entityhuman.awardStat(StatisticList.ITEM_USED.get(item)); + EnumHand enumhand = itemactioncontext.getHand(); + org.bukkit.event.block.BlockPlaceEvent placeEvent = null; @@ -171,8 +191,8 @@ + 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.tag, oldData)) { -+ this.setTag(newData); ++ if (this.getCount() == oldCount && Objects.equals(this.components, oldData)) { ++ this.applyComponents(newData); + this.setCount(newCount); + } + @@ -187,7 +207,7 @@ + IBlockData block = world.getBlockState(newblockposition); + + if (!(block.getBlock() instanceof BlockTileEntity)) { // Containers get placed automatically -+ block.getBlock().onPlace(block, world, newblockposition, oldBlock, true); ++ block.onPlace(world, newblockposition, oldBlock, true); + } + + world.notifyAndUpdatePhysics(newblockposition, null, oldBlock, block, world.getBlockState(newblockposition), updateFlag, 512); // send null chunk as chunk.k() returns false by this point @@ -271,7 +291,7 @@ return enuminteractionresult; } -@@ -351,6 +585,21 @@ +@@ -432,6 +652,21 @@ } i -= k; @@ -284,47 +304,56 @@ + event.getPlayer().updateInventory(); + } + if (event.isCancelled()) { -+ return false; ++ return; + } + + i = event.getDamage(); + } + // CraftBukkit end if (i <= 0) { - return false; + return; } -@@ -372,6 +621,11 @@ - if (this.hurt(i, t0.getRandom(), t0 instanceof EntityPlayer ? (EntityPlayer) t0 : null)) { - consumer.accept(t0); - Item item = this.getItem(); -+ // CraftBukkit start - Check for item breaking -+ if (this.count == 1 && t0 instanceof EntityHuman) { -+ org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent((EntityHuman) t0, this); -+ } -+ // CraftBukkit end +@@ -474,6 +709,11 @@ + this.hurtAndBreak(i, randomsource, entityplayer, () -> { + entityliving.broadcastBreakEvent(enumitemslot); + Item item = this.getItem(); ++ // CraftBukkit start - Check for item breaking ++ if (this.count == 1 && entityliving instanceof EntityHuman) { ++ org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerItemBreakEvent((EntityHuman) entityliving, this); ++ } ++ // CraftBukkit end - this.shrink(1); - if (t0 instanceof EntityHuman) { -@@ -524,6 +778,17 @@ - return this.tag; + this.shrink(1); + if (entityliving instanceof EntityHuman) { +@@ -669,6 +909,17 @@ + return this.getItem().useOnRelease(this); } + // CraftBukkit start + @Nullable -+ private NBTTagCompound getTagClone() { -+ return this.tag == null ? null : this.tag.copy(); ++ private PatchedDataComponentMap getComponentsClone() { ++ return this.components.isEmpty() ? null : this.components.copy(); + } + -+ private void setTagClone(@Nullable NBTTagCompound nbtttagcompound) { -+ this.setTag(nbtttagcompound == null ? null : nbtttagcompound.copy()); ++ private void setComponentsClone(@Nullable PatchedDataComponentMap patchedDataComponentMap) { ++ this.applyComponents(patchedDataComponentMap == null ? null : patchedDataComponentMap.copy()); + } + // CraftBukkit end + - public NBTTagCompound getOrCreateTag() { - if (this.tag == null) { - this.setTag(new NBTTagCompound()); -@@ -948,6 +1213,13 @@ - nbttaglist.add(nbttagcompound); + @Nullable + public T set(DataComponentType datacomponenttype, @Nullable T t0) { + return this.components.set(datacomponenttype, t0); +@@ -728,7 +979,7 @@ + } + + private void addToTooltip(DataComponentType datacomponenttype, Item.b item_b, Consumer consumer, TooltipFlag tooltipflag) { +- T t0 = (TooltipProvider) this.get(datacomponenttype); ++ T t0 = (T) this.get(datacomponenttype); // CraftBukkit - decompile error + + if (t0 != null) { + t0.addToTooltip(item_b, consumer, tooltipflag); +@@ -955,6 +1206,13 @@ + } + // CraftBukkit start @@ -337,3 +366,12 @@ public IChatBaseComponent getDisplayName() { IChatMutableComponent ichatmutablecomponent = IChatBaseComponent.empty().append(this.getHoverName()); +@@ -1017,7 +1275,7 @@ + } + + public void consume(int i, @Nullable EntityLiving entityliving) { +- if (entityliving == null || !entityliving.hasInfiniteMaterials()) { ++ if ((entityliving == null || !entityliving.hasInfiniteMaterials()) && this != ItemStack.EMPTY) { // CraftBukkit + this.shrink(i); + } + 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 38b4bc1cf1..2fea326921 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemTrident.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/ItemTrident.patch @@ -1,19 +1,15 @@ --- a/net/minecraft/world/item/ItemTrident.java +++ b/net/minecraft/world/item/ItemTrident.java -@@ -68,9 +68,12 @@ +@@ -72,7 +72,7 @@ if (k <= 0 || entityhuman.isInWaterOrRain()) { if (!world.isClientSide) { -+ // CraftBukkit - moved down -+ /* - itemstack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { - entityhuman1.broadcastBreakEvent(entityliving.getUsedItemHand()); - }); -+ */ +- itemstack.hurtAndBreak(1, entityhuman, EntityLiving.getSlotForHand(entityliving.getUsedItemHand())); ++ // itemstack.hurtAndBreak(1, entityhuman, EntityLiving.getSlotForHand(entityliving.getUsedItemHand())); // CraftBukkit - moved down if (k == 0) { EntityThrownTrident entitythrowntrident = new EntityThrownTrident(world, entityhuman, itemstack); -@@ -79,11 +82,30 @@ +@@ -81,11 +81,26 @@ entitythrowntrident.pickup = EntityArrow.PickupStatus.CREATIVE_ONLY; } @@ -26,26 +22,22 @@ + return; + } + -+ itemstack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { -+ entityhuman1.broadcastBreakEvent(entityliving.getUsedItemHand()); -+ }); ++ 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, SoundEffects.TRIDENT_THROW, SoundCategory.PLAYERS, 1.0F, 1.0F); - if (!entityhuman.getAbilities().instabuild) { + if (!entityhuman.hasInfiniteMaterials()) { entityhuman.getInventory().removeItem(itemstack); } + // CraftBukkit start - SPIGOT-5458 also need in this branch :( + } else { -+ itemstack.hurtAndBreak(1, entityhuman, (entityhuman1) -> { -+ entityhuman1.broadcastBreakEvent(entityliving.getUsedItemHand()); -+ }); ++ itemstack.hurtAndBreak(1, entityhuman, EntityLiving.getSlotForHand(entityliving.getUsedItemHand())); + // CraftBukkkit end } } -@@ -100,6 +122,7 @@ +@@ -102,6 +117,7 @@ f2 *= f6 / f5; f3 *= f6 / f5; f4 *= f6 / f5; diff --git a/paper-server/nms-patches/net/minecraft/world/item/ItemWorldMap.patch b/paper-server/nms-patches/net/minecraft/world/item/ItemWorldMap.patch deleted file mode 100644 index a3353d72e8..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/item/ItemWorldMap.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/net/minecraft/world/item/ItemWorldMap.java -+++ b/net/minecraft/world/item/ItemWorldMap.java -@@ -69,7 +69,7 @@ - public static Integer getMapId(ItemStack itemstack) { - NBTTagCompound nbttagcompound = itemstack.getTag(); - -- return nbttagcompound != null && nbttagcompound.contains("map", 99) ? nbttagcompound.getInt("map") : null; -+ return nbttagcompound != null && nbttagcompound.contains("map", 99) ? nbttagcompound.getInt("map") : -1; // CraftBukkit - make new maps for no tag - } - - public static int createNewSavedData(World world, int i, int j, int k, boolean flag, boolean flag1, ResourceKey resourcekey) { 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 ee7d2c7245..57d77d8233 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,70 +1,38 @@ --- a/net/minecraft/world/item/crafting/CraftingManager.java +++ b/net/minecraft/world/item/crafting/CraftingManager.java -@@ -34,11 +34,16 @@ +@@ -34,6 +34,11 @@ import net.minecraft.world.level.World; import org.slf4j.Logger; +// CraftBukkit start -+import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; -+import net.minecraft.core.registries.BuiltInRegistries; ++import com.google.common.collect.LinkedHashMultimap; ++import com.google.common.collect.Maps; +// CraftBukkit end + public class CraftingManager extends ResourceDataJson { private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create(); - private static final Logger LOGGER = LogUtils.getLogger(); -- public Map, Map>> recipes = ImmutableMap.of(); -+ public Map, Object2ObjectLinkedOpenHashMap>> recipes = ImmutableMap.of(); // CraftBukkit - private Map> byName = ImmutableMap.of(); - private boolean hasErrors; - -@@ -48,7 +53,12 @@ - - protected void apply(Map map, IResourceManager iresourcemanager, GameProfilerFiller gameprofilerfiller) { - this.hasErrors = false; -- Map, Builder>> map1 = Maps.newHashMap(); -+ // CraftBukkit start - SPIGOT-5667 make sure all types are populated and mutable -+ Map, Object2ObjectLinkedOpenHashMap>> map1 = Maps.newHashMap(); -+ for (Recipes recipeType : BuiltInRegistries.RECIPE_TYPE) { -+ map1.put(recipeType, new Object2ObjectLinkedOpenHashMap<>()); -+ } -+ // CraftBukkit end - Builder> builder = ImmutableMap.builder(); - Iterator iterator = map.entrySet().iterator(); - -@@ -59,8 +69,10 @@ - try { - RecipeHolder recipeholder = fromJson(minecraftkey, ChatDeserializer.convertToJsonObject((JsonElement) entry.getValue(), "top element")); - -- ((Builder) map1.computeIfAbsent(recipeholder.value().getType(), (recipes) -> { -- return ImmutableMap.builder(); -+ // CraftBukkit start -+ (map1.computeIfAbsent(recipeholder.value().getType(), (recipes) -> { -+ return new Object2ObjectLinkedOpenHashMap<>(); -+ // CraftBukkit end - })).put(minecraftkey, recipeholder); - builder.put(minecraftkey, recipeholder); - } catch (IllegalArgumentException | JsonParseException jsonparseexception) { -@@ -69,20 +81,37 @@ +@@ -70,19 +75,39 @@ + } } - this.recipes = (Map) map1.entrySet().stream().collect(ImmutableMap.toImmutableMap(Entry::getKey, (entry1) -> { -- return ((Builder) entry1.getValue()).build(); -+ return (entry1.getValue()); // CraftBukkit - })); -- this.byName = builder.build(); -+ this.byName = Maps.newHashMap(builder.build()); // CraftBukkit - CraftingManager.LOGGER.info("Loaded {} recipes", map1.size()); +- 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()); } + // CraftBukkit start + public void addRecipe(RecipeHolder irecipe) { -+ Object2ObjectLinkedOpenHashMap> map = this.recipes.get(irecipe.value().getType()); // CraftBukkit ++ Collection> map = this.byType.get(irecipe.value().getType()); // CraftBukkit + -+ if (byName.containsKey(irecipe.id()) || map.containsKey(irecipe.id())) { ++ if (byName.containsKey(irecipe.id())) { + throw new IllegalStateException("Duplicate recipe ignored with ID " + irecipe.id()); + } else { -+ map.putAndMoveToFirst(irecipe.id(), irecipe); // CraftBukkit - SPIGOT-4638: last recipe gets priority ++ map.add(irecipe); + byName.put(irecipe.id(), irecipe); + } + } @@ -75,65 +43,81 @@ } public > Optional> getRecipeFor(Recipes recipes, C c0, World world) { -- return this.byType(recipes).values().stream().filter((recipeholder) -> { +- return this.byType(recipes).stream().filter((recipeholder) -> { + // CraftBukkit start -+ Optional> recipe = this.byType(recipes).values().stream().filter((recipeholder) -> { ++ List> list = this.byType(recipes).stream().filter((recipeholder) -> { return recipeholder.value().matches(c0, world); - }).findFirst(); +- }).findFirst(); ++ }).toList(); ++ Optional> recipe = (list.isEmpty()) ? Optional.empty() : Optional.of(list.getLast()); // CraftBukkit - SPIGOT-4638: last recipe gets priority + c0.setCurrentRecipe(recipe.orElse(null)); // CraftBukkit - Clear recipe when no recipe is found + return recipe; + // CraftBukkit end } - public > Optional>> getRecipeFor(Recipes recipes, C c0, World world, @Nullable MinecraftKey minecraftkey) { -@@ -116,7 +145,7 @@ + public > Optional> getRecipeFor(Recipes recipes, C c0, World world, @Nullable MinecraftKey minecraftkey) { +@@ -94,9 +119,14 @@ + } + } + +- return this.byType(recipes).stream().filter((recipeholder1) -> { ++ // CraftBukkit start ++ List> list = this.byType(recipes).stream().filter((recipeholder1) -> { + return recipeholder1.value().matches(c0, world); +- }).findFirst(); ++ }).toList(); ++ Optional> recipe = (list.isEmpty()) ? Optional.empty() : Optional.of(list.getLast()); // CraftBukkit - SPIGOT-4638: last recipe gets priority ++ c0.setCurrentRecipe(recipe.orElse(null)); // CraftBukkit - Clear recipe when no recipe is found ++ return recipe; ++ // CraftBukkit end } - private > Map> byType(Recipes recipes) { -- return (Map) this.recipes.getOrDefault(recipes, Collections.emptyMap()); -+ return (Map) this.recipes.getOrDefault(recipes, new Object2ObjectLinkedOpenHashMap<>()); // CraftBukkit + public > List> getAllRecipesFor(Recipes recipes) { +@@ -112,7 +142,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, C c0, World world) { -@@ -159,12 +188,12 @@ +@@ -139,7 +169,7 @@ + private > RecipeHolder byKeyTyped(Recipes recipes, MinecraftKey minecraftkey) { + RecipeHolder recipeholder = (RecipeHolder) this.byName.get(minecraftkey); - public void replaceRecipes(Iterable> iterable) { - this.hasErrors = false; -- Map, Map>> map = Maps.newHashMap(); -+ Map, Object2ObjectLinkedOpenHashMap>> map = Maps.newHashMap(); // CraftBukkit - Builder> builder = ImmutableMap.builder(); +- return recipeholder != null && recipeholder.value().getType().equals(recipes) ? recipeholder : null; ++ return recipeholder != null && recipeholder.value().getType().equals(recipes) ? (RecipeHolder) recipeholder : null; // CraftBukkit - decompile error + } - iterable.forEach((recipeholder) -> { - Map> map1 = (Map) map.computeIfAbsent(recipeholder.value().getType(), (recipes) -> { -- return Maps.newHashMap(); -+ return new Object2ObjectLinkedOpenHashMap<>(); // CraftBukkit - }); - MinecraftKey minecraftkey = recipeholder.id(); - RecipeHolder recipeholder1 = (RecipeHolder) map1.put(minecraftkey, recipeholder); -@@ -175,9 +204,29 @@ - } - }); - this.recipes = ImmutableMap.copyOf(map); -- this.byName = builder.build(); -+ this.byName = Maps.newHashMap(builder.build()); // CraftBukkit + public Collection> getOrderedRecipes() { +@@ -175,10 +205,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) { -+ for (Object2ObjectLinkedOpenHashMap> recipes : recipes.values()) { -+ recipes.remove(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 void clearRecipes() { -+ this.recipes = Maps.newHashMap(); -+ -+ for (Recipes recipeType : BuiltInRegistries.RECIPE_TYPE) { -+ this.recipes.put(recipeType, new Object2ObjectLinkedOpenHashMap<>()); -+ } -+ ++ this.byType = LinkedHashMultimap.create(); + this.byName = Maps.newHashMap(); + } + // CraftBukkit end 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 ef02d2d023..af2e2a5e68 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,6 +1,6 @@ --- a/net/minecraft/world/item/crafting/IRecipe.java +++ b/net/minecraft/world/item/crafting/IRecipe.java -@@ -67,4 +67,6 @@ +@@ -72,4 +72,6 @@ return recipeitemstack.getItems().length == 0; }); } 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 80ea716a5d..60e3d123f5 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,7 +1,7 @@ --- a/net/minecraft/world/item/crafting/IRecipeComplex.java +++ b/net/minecraft/world/item/crafting/IRecipeComplex.java @@ -3,6 +3,11 @@ - import net.minecraft.core.IRegistryCustom; + import net.minecraft.core.HolderLookup; import net.minecraft.world.item.ItemStack; +// CraftBukkit start 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 980b0b897b..6ded93bb2d 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,20 +1,22 @@ --- a/net/minecraft/world/item/crafting/RecipeHolder.java +++ b/net/minecraft/world/item/crafting/RecipeHolder.java -@@ -2,7 +2,16 @@ - +@@ -4,8 +4,19 @@ + import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.MinecraftKey; --public record RecipeHolder> (MinecraftKey id, T value) { +// 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>(MinecraftKey id, T value) { + ++ // CraftBukkit start + public final Recipe toBukkitRecipe() { + return this.value.toBukkitRecipe(CraftNamespacedKey.fromMinecraft(this.id)); + } + // CraftBukkit end ++ + public static final StreamCodec> STREAM_CODEC = StreamCodec.composite(MinecraftKey.STREAM_CODEC, RecipeHolder::id, IRecipe.STREAM_CODEC, RecipeHolder::value, RecipeHolder::new); public boolean equals(Object object) { - if (this == 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 45fa2e7694..3141f27343 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,6 +1,6 @@ --- a/net/minecraft/world/item/crafting/RecipeItemStack.java +++ b/net/minecraft/world/item/crafting/RecipeItemStack.java -@@ -35,6 +35,7 @@ +@@ -40,6 +40,7 @@ public ItemStack[] itemStacks; @Nullable private IntList stackingIds; @@ -8,13 +8,13 @@ public static final Codec CODEC = codec(true); public static final Codec CODEC_NONEMPTY = codec(false); -@@ -72,6 +73,15 @@ +@@ -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.isSameItemSameTags(itemstack, itemstack1)) { ++ if (itemstack1.getItem() == itemstack.getItem() && ItemStack.isSameItemSameComponents(itemstack, itemstack1)) { + return true; + } + 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..b903beaab1 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,6 +1,6 @@ --- a/net/minecraft/world/item/crafting/ShapedRecipes.java +++ b/net/minecraft/world/item/crafting/ShapedRecipes.java -@@ -10,6 +10,14 @@ +@@ -11,6 +11,14 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.World; @@ -15,7 +15,7 @@ public class ShapedRecipes implements RecipeCrafting { final ShapedRecipePattern pattern; -@@ -30,6 +38,68 @@ +@@ -31,6 +39,68 @@ this(s, craftingbookcategory, shapedrecipepattern, itemstack, true); } 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 d9fc255ffe..b96f2c73cc 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,6 +1,6 @@ --- a/net/minecraft/world/item/crafting/ShapelessRecipes.java +++ b/net/minecraft/world/item/crafting/ShapelessRecipes.java -@@ -14,6 +14,13 @@ +@@ -15,6 +15,13 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.World; @@ -14,7 +14,7 @@ public class ShapelessRecipes implements RecipeCrafting { final String group; -@@ -28,6 +35,22 @@ +@@ -29,6 +36,22 @@ this.ingredients = nonnulllist; } 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 6fa252918d..eb6a5fea65 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 @@ -15,7 +15,7 @@ public class SmithingTransformRecipe implements SmithingRecipe { final RecipeItemStack template; -@@ -71,6 +79,17 @@ +@@ -67,6 +75,17 @@ return Stream.of(this.template, this.base, this.addition).anyMatch(RecipeItemStack::isEmpty); } @@ -32,4 +32,4 @@ + public static class a implements RecipeSerializer { - private static final Codec CODEC = RecordCodecBuilder.create((instance) -> { + private static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { 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 f598fae7a9..125c7675f2 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,6 +1,6 @@ --- a/net/minecraft/world/item/crafting/SmithingTrimRecipe.java +++ b/net/minecraft/world/item/crafting/SmithingTrimRecipe.java -@@ -18,6 +18,13 @@ +@@ -20,6 +20,13 @@ import net.minecraft.world.item.armortrim.TrimPatterns; import net.minecraft.world.level.World; @@ -14,7 +14,7 @@ public class SmithingTrimRecipe implements SmithingRecipe { final RecipeItemStack template; -@@ -107,6 +114,13 @@ +@@ -100,6 +107,13 @@ return Stream.of(this.template, this.base, this.addition).anyMatch(RecipeItemStack::isEmpty); } @@ -27,4 +27,4 @@ + public static class a implements RecipeSerializer { - private static final Codec CODEC = RecordCodecBuilder.create((instance) -> { + private static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { diff --git a/paper-server/nms-patches/net/minecraft/world/item/enchantment/EnchantmentFrostWalker.patch b/paper-server/nms-patches/net/minecraft/world/item/enchantment/EnchantmentFrostWalker.patch index 7e3647bd33..55deb2c840 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/enchantment/EnchantmentFrostWalker.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/enchantment/EnchantmentFrostWalker.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/enchantment/EnchantmentFrostWalker.java +++ b/net/minecraft/world/item/enchantment/EnchantmentFrostWalker.java -@@ -55,8 +55,11 @@ +@@ -39,8 +39,11 @@ IBlockData iblockdata2 = world.getBlockState(blockposition1); if (iblockdata2 == BlockIceFrost.meltsInto() && iblockdata.canSurvive(world, blockposition1) && world.isUnobstructed(iblockdata, blockposition1, VoxelShapeCollision.empty())) { diff --git a/paper-server/nms-patches/net/minecraft/world/item/enchantment/EnchantmentWeaponDamage.patch b/paper-server/nms-patches/net/minecraft/world/item/enchantment/EnchantmentWeaponDamage.patch index d637e8fc60..9b79034546 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/enchantment/EnchantmentWeaponDamage.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/enchantment/EnchantmentWeaponDamage.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/item/enchantment/EnchantmentWeaponDamage.java +++ b/net/minecraft/world/item/enchantment/EnchantmentWeaponDamage.java -@@ -63,7 +63,7 @@ - if (this.type == 2 && i > 0 && entityliving1.getMobType() == EnumMonsterType.ARTHROPOD) { +@@ -35,7 +35,7 @@ + if (this.targets.get() == TagsEntity.SENSITIVE_TO_BANE_OF_ARTHROPODS && i > 0 && entityliving1.getType().is((TagKey) this.targets.get())) { int j = 20 + entityliving.getRandom().nextInt(10 * i); - entityliving1.addEffect(new MobEffect(MobEffects.MOVEMENT_SLOWDOWN, j, 3)); diff --git a/paper-server/nms-patches/net/minecraft/world/item/trading/MerchantRecipe.patch b/paper-server/nms-patches/net/minecraft/world/item/trading/MerchantRecipe.patch index b5c7195163..9b92e485a9 100644 --- a/paper-server/nms-patches/net/minecraft/world/item/trading/MerchantRecipe.patch +++ b/paper-server/nms-patches/net/minecraft/world/item/trading/MerchantRecipe.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/trading/MerchantRecipe.java +++ b/net/minecraft/world/item/trading/MerchantRecipe.java -@@ -5,6 +5,8 @@ +@@ -8,6 +8,8 @@ import net.minecraft.util.MathHelper; import net.minecraft.world.item.ItemStack; @@ -8,8 +8,8 @@ + public class MerchantRecipe { - public ItemStack baseCostA; -@@ -17,6 +19,22 @@ + public static final Codec CODEC = RecordCodecBuilder.create((instance) -> { +@@ -44,6 +46,18 @@ public int demand; public float priceMultiplier; public int xp; @@ -20,27 +20,15 @@ + return (bukkitHandle == null) ? bukkitHandle = new CraftMerchantRecipe(this) : bukkitHandle; + } + -+ public MerchantRecipe(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int uses, int maxUses, int experience, float priceMultiplier, CraftMerchantRecipe bukkit) { -+ this(itemstack, itemstack1, itemstack2, uses, maxUses, experience, priceMultiplier, 0, bukkit); -+ } -+ -+ public MerchantRecipe(ItemStack itemstack, ItemStack itemstack1, ItemStack itemstack2, int uses, int maxUses, int experience, float priceMultiplier, int demand, CraftMerchantRecipe bukkit) { -+ this(itemstack, itemstack1, itemstack2, uses, maxUses, experience, priceMultiplier, demand); ++ public MerchantRecipe(ItemCost baseCostA, Optional costB, ItemStack result, int uses, int maxUses, int experience, float priceMultiplier, int demand, CraftMerchantRecipe bukkit) { ++ this(baseCostA, costB, result, uses, maxUses, experience, priceMultiplier, demand); + this.bukkitHandle = bukkit; + } + // CraftBukkit end - public MerchantRecipe(NBTTagCompound nbttagcompound) { - this.rewardExp = true; -@@ -96,6 +114,7 @@ - return ItemStack.EMPTY; - } else { - int i = this.baseCostA.getCount(); -+ if (i <= 0) return ItemStack.EMPTY; // CraftBukkit - SPIGOT-5476 - int j = Math.max(0, MathHelper.floor((float) (i * this.demand) * this.priceMultiplier)); - - return this.baseCostA.copyWithCount(MathHelper.clamp(i + j + this.specialPriceDiff, 1, this.baseCostA.getItem().getMaxStackSize())); -@@ -216,7 +235,11 @@ + private MerchantRecipe(ItemCost itemcost, Optional optional, ItemStack itemstack, int i, int j, boolean flag, int k, int l, float f, int i1) { + this.baseCostA = itemcost; +@@ -185,7 +199,11 @@ if (!this.satisfiedBy(itemstack, itemstack1)) { return false; } else { diff --git a/paper-server/nms-patches/net/minecraft/world/level/CommandBlockListenerAbstract.patch b/paper-server/nms-patches/net/minecraft/world/level/CommandBlockListenerAbstract.patch index 3a6e452457..6a0ecd64c5 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/CommandBlockListenerAbstract.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/CommandBlockListenerAbstract.patch @@ -1,17 +1,17 @@ --- a/net/minecraft/world/level/CommandBlockListenerAbstract.java +++ b/net/minecraft/world/level/CommandBlockListenerAbstract.java -@@ -30,6 +30,10 @@ - private IChatBaseComponent lastOutput; +@@ -32,6 +32,10 @@ private String command = ""; - private IChatBaseComponent name; + @Nullable + private IChatBaseComponent customName; + // CraftBukkit start + @Override + public abstract org.bukkit.command.CommandSender getBukkitSender(CommandListenerWrapper wrapper); + // CraftBukkit end - public CommandBlockListenerAbstract() { - this.name = CommandBlockListenerAbstract.DEFAULT_NAME; -@@ -126,7 +130,7 @@ + public CommandBlockListenerAbstract() {} + +@@ -131,7 +135,7 @@ }); diff --git a/paper-server/nms-patches/net/minecraft/world/level/Explosion.patch b/paper-server/nms-patches/net/minecraft/world/level/Explosion.patch index 9f1e0a32d5..1f1eb8ec9b 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/Explosion.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/Explosion.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/Explosion.java +++ b/net/minecraft/world/level/Explosion.java -@@ -39,6 +39,16 @@ +@@ -40,6 +40,16 @@ import net.minecraft.world.phys.MovingObjectPosition; import net.minecraft.world.phys.Vec3D; @@ -17,8 +17,8 @@ public class Explosion { private static final ExplosionDamageCalculator EXPLOSION_DAMAGE_CALCULATOR = new ExplosionDamageCalculator(); -@@ -60,6 +70,10 @@ - private final SoundEffect explosionSound; +@@ -61,6 +71,10 @@ + private final Holder explosionSound; private final ObjectArrayList toBlow; private final Map hitPlayers; + // CraftBukkit - add field @@ -28,7 +28,7 @@ public static DamageSource getDefaultDamageSource(World world, @Nullable Entity entity) { return world.damageSources().explosion(entity, getIndirectSourceEntityInternal(entity)); -@@ -85,17 +99,18 @@ +@@ -86,17 +100,18 @@ this.hitPlayers = Maps.newHashMap(); this.level = world; this.source = entity; @@ -44,12 +44,12 @@ this.damageCalculator = explosiondamagecalculator == null ? this.makeDamageCalculator(entity) : explosiondamagecalculator; this.smallExplosionParticles = particleparam; this.largeExplosionParticles = particleparam1; - this.explosionSound = soundeffect; + 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) { -@@ -146,6 +161,11 @@ +@@ -147,6 +162,11 @@ } public void explode() { @@ -58,10 +58,10 @@ + return; + } + // CraftBukkit end - this.level.gameEvent(this.source, GameEvent.EXPLODE, new Vec3D(this.x, this.y, this.z)); + this.level.gameEvent(this.source, (Holder) GameEvent.EXPLODE, new Vec3D(this.x, this.y, this.z)); Set set = Sets.newHashSet(); boolean flag = true; -@@ -228,7 +248,35 @@ +@@ -229,7 +249,35 @@ d9 /= d11; d10 /= d11; if (this.damageCalculator.shouldDamageEntity(this, entity)) { @@ -97,8 +97,8 @@ + // CraftBukkit end } - double d12 = (1.0D - d7) * (double) getSeenPercent(vec3d, entity); -@@ -247,6 +295,14 @@ + double d12 = (1.0D - d7) * (double) getSeenPercent(vec3d, entity) * (double) this.damageCalculator.getKnockbackMultiplier(entity); +@@ -248,6 +296,14 @@ d10 *= d13; Vec3D vec3d1 = new Vec3D(d8, d9, d10); @@ -113,7 +113,7 @@ entity.setDeltaMovement(entity.getDeltaMovement().add(vec3d1)); if (entity instanceof EntityHuman) { EntityHuman entityhuman = (EntityHuman) entity; -@@ -287,9 +343,63 @@ +@@ -290,9 +346,63 @@ SystemUtils.shuffle(this.toBlow, this.level.random); ObjectListIterator objectlistiterator = this.toBlow.iterator(); @@ -177,7 +177,7 @@ this.level.getBlockState(blockposition).onExplosionHit(this.level, blockposition, this, (itemstack, blockposition1) -> { addOrAppendStack(list, itemstack, blockposition1); -@@ -314,7 +424,11 @@ +@@ -317,7 +427,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())) { @@ -190,7 +190,7 @@ } } } -@@ -322,6 +436,7 @@ +@@ -325,6 +439,7 @@ } private static void addOrAppendStack(List> list, ItemStack itemstack, BlockPosition blockposition) { 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 35b2e63fc7..c67fbace54 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/GameRules.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/GameRules.patch @@ -1,17 +1,6 @@ --- a/net/minecraft/world/level/GameRules.java +++ b/net/minecraft/world/level/GameRules.java -@@ -28,6 +28,10 @@ - import net.minecraft.server.level.EntityPlayer; - import org.slf4j.Logger; - -+// CraftBukkit start -+import net.minecraft.server.level.WorldServer; -+// CraftBukkit end -+ - public class GameRules { - - public static final int DEFAULT_RANDOM_TICK_SPEED = 3; -@@ -52,7 +56,7 @@ +@@ -55,7 +55,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; @@ -20,7 +9,7 @@ while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer) iterator.next(); -@@ -67,7 +71,7 @@ +@@ -70,7 +70,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) -> { @@ -29,7 +18,7 @@ while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer) iterator.next(); -@@ -83,7 +87,7 @@ +@@ -86,7 +86,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) -> { @@ -38,7 +27,16 @@ while (iterator.hasNext()) { EntityPlayer entityplayer = (EntityPlayer) iterator.next(); -@@ -142,7 +146,7 @@ +@@ -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) -> { +- WorldServer worldserver = minecraftserver.overworld(); ++ WorldServer worldserver = minecraftserver; // CraftBukkit - per-world + + worldserver.setDefaultSpawnPos(worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle()); + })); +@@ -150,7 +150,7 @@ } public > T getRule(GameRules.GameRuleKey gamerules_gamerulekey) { @@ -47,16 +45,16 @@ } public NBTTagCompound createTag() { -@@ -156,7 +160,7 @@ +@@ -164,7 +164,7 @@ private void loadFromTag(DynamicLike dynamiclike) { this.rules.forEach((gamerules_gamerulekey, gamerules_gamerulevalue) -> { -- Optional optional = dynamiclike.get(gamerules_gamerulekey.id).asString().result(); -+ Optional optional = dynamiclike.get(gamerules_gamerulekey.id).asString().result(); // CraftBukkit - decompile error +- DataResult dataresult = dynamiclike.get(gamerules_gamerulekey.id).asString(); ++ DataResult dataresult = dynamiclike.get(gamerules_gamerulekey.id).asString(); // CraftBukkit - decompile error Objects.requireNonNull(gamerules_gamerulevalue); - optional.ifPresent(gamerules_gamerulevalue::deserialize); -@@ -176,17 +180,17 @@ + dataresult.ifSuccess(gamerules_gamerulevalue::deserialize); +@@ -184,17 +184,17 @@ } private static > void callVisitorCap(GameRules.GameRuleVisitor gamerules_gamerulevisitor, GameRules.GameRuleKey gamerules_gamerulekey, GameRules.GameRuleDefinition gamerules_gameruledefinition) { @@ -78,9 +76,9 @@ T t0 = gamerules.getRule(gamerules_gamerulekey); this.getRule(gamerules_gamerulekey).setFrom(t0, minecraftserver); -@@ -254,10 +258,10 @@ +@@ -262,10 +262,10 @@ - private final Supplier> argument; + final Supplier> argument; private final Function, T> constructor; - final BiConsumer callback; + final BiConsumer callback; // CraftBukkit - per-world @@ -91,7 +89,7 @@ this.argument = supplier; this.constructor = function; this.callback = biconsumer; -@@ -269,7 +273,7 @@ +@@ -277,7 +277,7 @@ } public T createRule() { @@ -100,7 +98,7 @@ } public void callVisitor(GameRules.GameRuleVisitor gamerules_gamerulevisitor, GameRules.GameRuleKey gamerules_gamerulekey) { -@@ -289,17 +293,17 @@ +@@ -297,17 +297,17 @@ public void setFromArgument(CommandContext commandcontext, String s) { this.updateFromArgument(commandcontext, s); @@ -121,7 +119,7 @@ public abstract String serialize(); -@@ -313,7 +317,7 @@ +@@ -321,7 +321,7 @@ protected abstract T copy(); @@ -130,7 +128,7 @@ } public interface GameRuleVisitor { -@@ -329,7 +333,7 @@ +@@ -337,7 +337,7 @@ private boolean value; @@ -139,7 +137,7 @@ return new GameRules.GameRuleDefinition<>(BoolArgumentType::bool, (gamerules_gameruledefinition) -> { return new GameRules.GameRuleBoolean(gamerules_gameruledefinition, flag); }, biconsumer, GameRules.GameRuleVisitor::visitBoolean); -@@ -354,7 +358,7 @@ +@@ -362,7 +362,7 @@ return this.value; } @@ -148,7 +146,7 @@ this.value = flag; this.onChanged(minecraftserver); } -@@ -365,7 +369,7 @@ +@@ -373,7 +373,7 @@ } @Override @@ -157,7 +155,7 @@ this.value = Boolean.parseBoolean(s); } -@@ -384,7 +388,7 @@ +@@ -392,7 +392,7 @@ return new GameRules.GameRuleBoolean(this.type, this.value); } @@ -166,7 +164,7 @@ this.value = gamerules_gameruleboolean.value; this.onChanged(minecraftserver); } -@@ -394,7 +398,7 @@ +@@ -402,13 +402,13 @@ private int value; @@ -175,7 +173,14 @@ return new GameRules.GameRuleDefinition<>(IntegerArgumentType::integer, (gamerules_gameruledefinition) -> { return new GameRules.GameRuleInt(gamerules_gameruledefinition, i); }, biconsumer, GameRules.GameRuleVisitor::visitInteger); -@@ -419,7 +423,7 @@ + } + +- 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 + return new GameRules.GameRuleDefinition<>(() -> { + return IntegerArgumentType.integer(j, k); + }, (gamerules_gameruledefinition) -> { +@@ -435,7 +435,7 @@ return this.value; } @@ -184,7 +189,7 @@ this.value = i; this.onChanged(minecraftserver); } -@@ -430,7 +434,7 @@ +@@ -446,7 +446,7 @@ } @Override @@ -193,7 +198,7 @@ this.value = safeParse(s); } -@@ -470,7 +474,7 @@ +@@ -488,7 +488,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 70019a1569..5df5b1c2ac 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/GeneratorAccess.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/GeneratorAccess.patch @@ -1,22 +1,8 @@ --- a/net/minecraft/world/level/GeneratorAccess.java +++ b/net/minecraft/world/level/GeneratorAccess.java -@@ -35,11 +35,11 @@ - - LevelTickAccess getBlockTicks(); - -- private default NextTickListEntry createTick(BlockPosition blockposition, T t0, int i, TickListPriority ticklistpriority) { -+ default NextTickListEntry createTick(BlockPosition blockposition, T t0, int i, TickListPriority ticklistpriority) { // CraftBukkit - decompile error - return new NextTickListEntry<>(t0, blockposition, this.getLevelData().getGameTime() + (long) i, ticklistpriority, this.nextSubTickCount()); - } - -- private default NextTickListEntry createTick(BlockPosition blockposition, T t0, int i) { -+ default NextTickListEntry createTick(BlockPosition blockposition, T t0, int i) { // CraftBukkit - decompile error - return new NextTickListEntry<>(t0, blockposition, this.getLevelData().getGameTime() + (long) i, this.nextSubTickCount()); - } - -@@ -114,4 +114,6 @@ - default void gameEvent(GameEvent gameevent, BlockPosition blockposition, GameEvent.a gameevent_a) { - this.gameEvent(gameevent, Vec3D.atCenterOf(blockposition), gameevent_a); +@@ -121,4 +121,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); } + + net.minecraft.server.level.WorldServer getMinecraftWorld(); // CraftBukkit 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 fb7462dcad..45bf2cf9ac 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/MobSpawnerAbstract.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/MobSpawnerAbstract.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/MobSpawnerAbstract.java +++ b/net/minecraft/world/level/MobSpawnerAbstract.java -@@ -52,6 +52,7 @@ +@@ -54,6 +54,7 @@ public void setEntityId(EntityTypes entitytypes, @Nullable World world, RandomSource randomsource, BlockPosition blockposition) { this.getOrCreateNextSpawnData(world, randomsource, blockposition).getEntityToSpawn().putString("id", BuiltInRegistries.ENTITY_TYPE.getKey(entitytypes).toString()); @@ -8,8 +8,15 @@ } private boolean isNearPlayer(World world, BlockPosition blockposition) { -@@ -154,7 +155,12 @@ +@@ -157,13 +158,18 @@ + ((EntityInsentient) entity).finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entity.blockPosition()), EnumMobSpawn.SPAWNER, (GroupDataEntity) null); } + +- Optional optional1 = mobspawnerdata.getEquipment(); ++ Optional optional1 = mobspawnerdata.getEquipment(); // CraftBukkit - decompile error + + Objects.requireNonNull(entityinsentient); + optional1.ifPresent(entityinsentient::equip); } - if (!worldserver.tryAddFreshEntityWithPassengers(entity)) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/RayTrace.patch b/paper-server/nms-patches/net/minecraft/world/level/RayTrace.patch index c6598f3aa2..24e96e0442 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/RayTrace.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/RayTrace.patch @@ -13,8 +13,8 @@ private final Predicate canPick; -- private FluidCollisionOption(Predicate predicate) { -+ private FluidCollisionOption(Predicate predicate) { // CraftBukkit - decompile error +- private FluidCollisionOption(final Predicate predicate) { ++ private FluidCollisionOption(final Predicate predicate) { // CraftBukkit - decompile error this.canPick = predicate; } 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 24b8cc9dac..36cf6bf5ff 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 -@@ -49,6 +49,13 @@ +@@ -46,6 +46,13 @@ import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; @@ -14,7 +14,7 @@ public final class SpawnerCreature { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -113,10 +120,25 @@ +@@ -108,10 +115,25 @@ EnumCreatureType[] aenumcreaturetype = SpawnerCreature.SPAWNING_CATEGORIES; int i = aenumcreaturetype.length; @@ -41,10 +41,10 @@ Objects.requireNonNull(spawnercreature_d); SpawnerCreature.c spawnercreature_c = spawnercreature_d::canSpawn; -@@ -201,10 +223,15 @@ +@@ -196,10 +218,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, (NBTTagCompound) null); + groupdataentity = entityinsentient.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(entityinsentient.blockPosition()), EnumMobSpawn.NATURAL, groupdataentity); - ++j; - ++k1; - worldserver.addFreshEntityWithPassengers(entityinsentient); @@ -61,16 +61,16 @@ if (j >= entityinsentient.getMaxSpawnClusterSize()) { return; } -@@ -390,7 +417,7 @@ +@@ -348,7 +375,7 @@ if (entityinsentient.checkSpawnRules(worldaccess, EnumMobSpawn.CHUNK_GENERATION) && entityinsentient.checkSpawnObstruction(worldaccess)) { - groupdataentity = entityinsentient.finalizeSpawn(worldaccess, worldaccess.getCurrentDifficultyAt(entityinsentient.blockPosition()), EnumMobSpawn.CHUNK_GENERATION, groupdataentity, (NBTTagCompound) null); + groupdataentity = entityinsentient.finalizeSpawn(worldaccess, worldaccess.getCurrentDifficultyAt(entityinsentient.blockPosition()), EnumMobSpawn.CHUNK_GENERATION, groupdataentity); - worldaccess.addFreshEntityWithPassengers(entityinsentient); + worldaccess.addFreshEntityWithPassengers(entityinsentient, SpawnReason.CHUNK_GEN); // CraftBukkit flag = true; } } -@@ -511,8 +538,10 @@ +@@ -461,8 +488,10 @@ return this.unmodifiableMobCategoryCounts; } 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 edc7e82761..c1c3f937ce 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 -@@ -75,6 +75,31 @@ +@@ -77,6 +77,28 @@ import net.minecraft.world.phys.Vec3D; import net.minecraft.world.scores.Scoreboard; @@ -17,22 +17,19 @@ +import net.minecraft.world.level.border.IWorldBorderListener; +import net.minecraft.world.level.dimension.WorldDimension; +import org.bukkit.Bukkit; -+import org.bukkit.Location; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.block.CapturedBlockState; +import org.bukkit.craftbukkit.block.data.CraftBlockData; +import org.bukkit.craftbukkit.util.CraftSpawnCategory; -+import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.entity.SpawnCategory; +import org.bukkit.event.block.BlockPhysicsEvent; -+import org.bukkit.event.world.GenericGameEvent; +// CraftBukkit end + public abstract class World implements GeneratorAccess, AutoCloseable { public static final Codec> RESOURCE_KEY_CODEC = ResourceKey.codec(Registries.DIMENSION); -@@ -117,7 +142,43 @@ +@@ -118,7 +140,42 @@ private final DamageSources damageSources; private long subTickCount; @@ -40,7 +37,6 @@ + // CraftBukkit start Added the following + private final CraftWorld world; + public boolean pvpMode; -+ public boolean keepSpawnInMemory = true; + public org.bukkit.generator.ChunkGenerator generator; + + public boolean preventPoiUpdated = false; // CraftBukkit - SPIGOT-5710 @@ -77,8 +73,12 @@ this.profiler = supplier; this.levelData = worlddatamutable; this.dimensionTypeRegistration = holder; -@@ -132,12 +193,12 @@ - this.worldBorder = new WorldBorder() { +@@ -127,15 +184,15 @@ + this.dimension = resourcekey; + this.isClientSide = flag; + if (dimensionmanager.coordinateScale() != 1.0D) { +- this.worldBorder = new WorldBorder(this) { ++ this.worldBorder = new WorldBorder() { // CraftBukkit - decompile error @Override public double getCenterX() { - return super.getCenterX() / dimensionmanager.coordinateScale(); @@ -92,7 +92,7 @@ } }; } else { -@@ -150,6 +211,42 @@ +@@ -148,6 +205,42 @@ this.neighborUpdater = new CollectingNeighborUpdater(this, j); this.registryAccess = iregistrycustom; this.damageSources = new DamageSources(iregistrycustom); @@ -135,7 +135,7 @@ } @Override -@@ -207,6 +304,18 @@ +@@ -205,6 +298,18 @@ @Override public boolean setBlock(BlockPosition blockposition, IBlockData iblockdata, int i, int j) { @@ -154,7 +154,7 @@ if (this.isOutsideBuildHeight(blockposition)) { return false; } else if (!this.isClientSide && this.isDebug()) { -@@ -214,13 +323,29 @@ +@@ -212,13 +317,29 @@ } else { Chunk chunk = this.getChunkAt(blockposition); Block block = iblockdata.getBlock(); @@ -185,7 +185,7 @@ if (iblockdata2 == iblockdata) { if (iblockdata1 != iblockdata2) { this.setBlocksDirty(blockposition, iblockdata1, iblockdata2); -@@ -247,12 +372,69 @@ +@@ -245,12 +366,69 @@ this.onBlockStateChange(blockposition, iblockdata1, iblockdata2); } @@ -255,7 +255,7 @@ public void onBlockStateChange(BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1) {} @Override -@@ -338,6 +520,14 @@ +@@ -336,6 +514,14 @@ @Override public IBlockData getBlockState(BlockPosition blockposition) { @@ -270,19 +270,19 @@ if (this.isOutsideBuildHeight(blockposition)) { return Blocks.VOID_AIR.defaultBlockState(); } else { -@@ -507,6 +697,11 @@ - Explosion.Effect explosion_effect; - - switch (world_a) { +@@ -518,6 +704,11 @@ + case 4: + explosion_effect = Explosion.Effect.TRIGGER_BLOCK; + break; + // CraftBukkit start - handle custom explosion type -+ case STANDARD: ++ case 5: + explosion_effect = Explosion.Effect.DESTROY; + break; + // CraftBukkit end - case NONE: - explosion_effect = Explosion.Effect.KEEP; - break; -@@ -543,6 +738,16 @@ + default: + throw new MatchException((String) null, (Throwable) null); + } +@@ -539,6 +730,16 @@ @Nullable @Override public TileEntity getBlockEntity(BlockPosition blockposition) { @@ -299,7 +299,7 @@ return this.isOutsideBuildHeight(blockposition) ? null : (!this.isClientSide && Thread.currentThread() != this.thread ? null : this.getChunkAt(blockposition).getBlockEntity(blockposition, Chunk.EnumTileEntityState.IMMEDIATE)); } -@@ -550,6 +755,12 @@ +@@ -546,6 +747,12 @@ BlockPosition blockposition = tileentity.getBlockPos(); if (!this.isOutsideBuildHeight(blockposition)) { @@ -312,7 +312,7 @@ this.getChunkAt(blockposition).addAndRegisterBlockEntity(tileentity); } } -@@ -680,7 +891,7 @@ +@@ -675,7 +882,7 @@ for (int k = 0; k < j; ++k) { EntityComplexPart entitycomplexpart = aentitycomplexpart[k]; @@ -321,7 +321,7 @@ if (t0 != null && predicate.test(t0)) { list.add(t0); -@@ -960,7 +1171,7 @@ +@@ -953,7 +1160,7 @@ public static enum a { 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 5ce2f55f0d..4bcfac0994 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,8 +1,8 @@ --- a/net/minecraft/world/level/block/AbstractCandleBlock.java +++ b/net/minecraft/world/level/block/AbstractCandleBlock.java -@@ -45,6 +45,11 @@ +@@ -46,6 +46,11 @@ @Override - public void onProjectileHit(World world, IBlockData iblockdata, MovingObjectPositionBlock movingobjectpositionblock, IProjectile iprojectile) { + protected void onProjectileHit(World world, IBlockData iblockdata, MovingObjectPositionBlock movingobjectpositionblock, IProjectile iprojectile) { if (!world.isClientSide && iprojectile.isOnFire() && this.canBeLit(iblockdata)) { + // CraftBukkit start + if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockIgniteEvent(world, movingobjectpositionblock.getBlockPos(), iprojectile).isCancelled()) { 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 17afb0f509..901605a23a 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 -@@ -42,6 +42,11 @@ +@@ -43,6 +43,11 @@ import net.minecraft.world.phys.shapes.VoxelShapeCollision; import net.minecraft.world.phys.shapes.VoxelShapes; @@ -12,17 +12,17 @@ public class BigDripleafBlock extends BlockFacingHorizontal implements IBlockFragilePlantElement, IBlockWaterlogged { public static final MapCodec CODEC = simpleCodec(BigDripleafBlock::new); -@@ -116,7 +121,7 @@ +@@ -117,7 +122,7 @@ @Override - public void onProjectileHit(World world, IBlockData iblockdata, MovingObjectPositionBlock movingobjectpositionblock, IProjectile iprojectile) { + protected void onProjectileHit(World world, IBlockData iblockdata, MovingObjectPositionBlock movingobjectpositionblock, IProjectile iprojectile) { - this.setTiltAndScheduleTick(iblockdata, world, movingobjectpositionblock.getBlockPos(), Tilt.FULL, SoundEffects.BIG_DRIPLEAF_TILT_DOWN); + this.setTiltAndScheduleTick(iblockdata, world, movingobjectpositionblock.getBlockPos(), Tilt.FULL, SoundEffects.BIG_DRIPLEAF_TILT_DOWN, iprojectile); // CraftBukkit } @Override -@@ -175,7 +180,20 @@ - public void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { +@@ -176,7 +181,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)) { - this.setTiltAndScheduleTick(iblockdata, world, blockposition, Tilt.UNSTABLE, (SoundEffect) null); @@ -43,7 +43,7 @@ } } -@@ -189,9 +207,9 @@ +@@ -190,9 +208,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); } -@@ -217,8 +235,10 @@ +@@ -218,8 +236,10 @@ return entity.onGround() && entity.position().y > (double) ((float) blockposition.getY() + 0.6875F); } @@ -68,7 +68,7 @@ if (soundeffect != null) { playTiltSound(world, blockposition, soundeffect); } -@@ -232,14 +252,21 @@ +@@ -233,14 +253,21 @@ } private static void resetTilt(IBlockData iblockdata, World world, BlockPosition blockposition) { @@ -92,8 +92,8 @@ Tilt tilt1 = (Tilt) iblockdata.getValue(BigDripleafBlock.TILT); world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BigDripleafBlock.TILT, tilt), 2); -@@ -247,6 +274,7 @@ - world.gameEvent((Entity) null, GameEvent.BLOCK_CHANGE, blockposition); +@@ -248,6 +275,7 @@ + world.gameEvent((Entity) null, (Holder) GameEvent.BLOCK_CHANGE, blockposition); } + return true; // CraftBukkit 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 f388912c32..ff2b233eb8 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,6 +1,6 @@ --- a/net/minecraft/world/level/block/Block.java +++ b/net/minecraft/world/level/block/Block.java -@@ -349,7 +349,13 @@ +@@ -341,7 +341,13 @@ EntityItem entityitem = (EntityItem) supplier.get(); entityitem.setDefaultPickUpDelay(); @@ -15,7 +15,7 @@ } } -@@ -375,7 +381,7 @@ +@@ -367,7 +373,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); } -@@ -512,17 +518,25 @@ +@@ -500,17 +506,25 @@ return this.builtInRegistryHolder; } 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 a5a97d00dd..d521c9519d 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 -@@ -94,7 +94,8 @@ +@@ -93,7 +93,8 @@ } } @@ -10,7 +10,7 @@ world.removeBlock(blockposition, false); BlockPosition blockposition1 = blockposition.relative(((EnumDirection) iblockdata.getValue(BlockBed.FACING)).getOpposite()); -@@ -113,7 +114,16 @@ +@@ -112,7 +113,16 @@ return EnumInteractionResult.SUCCESS; } else { @@ -27,7 +27,7 @@ if (entityhuman_enumbedresult.getMessage() != null) { entityhuman.displayClientMessage(entityhuman_enumbedresult.getMessage(), true); } -@@ -124,8 +134,29 @@ +@@ -123,8 +133,29 @@ } } @@ -58,7 +58,7 @@ } private boolean kickVillagerOutOfBed(World world, BlockPosition blockposition) { -@@ -324,6 +355,11 @@ +@@ -323,6 +354,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 7b6ec34eb1..fb02245270 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 @@ -9,3 +9,12 @@ } } } +@@ -287,7 +287,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); + + entityitem.setDefaultPickUpDelay(); 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 c06c5eb264..34927b8d20 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 @@ -31,7 +31,7 @@ + // CraftBukkit end this.press(iblockdata, world, blockposition); this.playSound(entityhuman, world, blockposition, true); - world.gameEvent((Entity) entityhuman, GameEvent.BLOCK_ACTIVATE, blockposition); + world.gameEvent((Entity) entityhuman, (Holder) GameEvent.BLOCK_ACTIVATE, blockposition); @@ -195,11 +213,36 @@ } 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 e36285f328..586d292377 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 @@ -21,7 +21,7 @@ @@ -119,7 +121,7 @@ @Override - public void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { + protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { - entity.hurt(world.damageSources().cactus(), 1.0F); + entity.hurt(world.damageSources().cactus().directBlock(world, blockposition), 1.0F); // CraftBukkit } 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 f35b847b9c..86b9b02752 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 -@@ -92,7 +92,18 @@ +@@ -100,7 +100,18 @@ return EnumInteractionResult.PASS; } else { entityhuman.awardStat(StatisticList.EAT_CAKE_SLICE); @@ -19,4 +19,4 @@ + // CraftBukkit end int i = (Integer) iblockdata.getValue(BlockCake.BITES); - generatoraccess.gameEvent((Entity) entityhuman, GameEvent.EAT, blockposition); + generatoraccess.gameEvent((Entity) entityhuman, (Holder) GameEvent.EAT, blockposition); 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 eb4641d7c6..615dfdd8b6 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 @@ -2,7 +2,7 @@ +++ b/net/minecraft/world/level/block/BlockCampfire.java @@ -106,7 +106,7 @@ @Override - public void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { + protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { if ((Boolean) iblockdata.getValue(BlockCampfire.LIT) && entity instanceof EntityLiving && !EnchantmentManager.hasFrostWalker((EntityLiving) entity)) { - entity.hurt(world.damageSources().inFire(), (float) this.fireDamage); + entity.hurt(world.damageSources().inFire().directBlock(world, blockposition), (float) this.fireDamage); // CraftBukkit diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCauldron.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCauldron.patch index e699d35015..37c8b5f25f 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockCauldron.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockCauldron.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockCauldron.java +++ b/net/minecraft/world/level/block/BlockCauldron.java -@@ -12,6 +12,10 @@ +@@ -13,6 +13,10 @@ import net.minecraft.world.level.material.FluidType; import net.minecraft.world.level.material.FluidTypes; @@ -11,18 +11,18 @@ public class BlockCauldron extends AbstractCauldronBlock { public static final MapCodec CODEC = simpleCodec(BlockCauldron::new); -@@ -61,13 +65,11 @@ +@@ -62,13 +66,11 @@ if (fluidtype == FluidTypes.WATER) { iblockdata1 = Blocks.WATER_CAULDRON.defaultBlockState(); - world.setBlockAndUpdate(blockposition, iblockdata1); -- world.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1)); +- world.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1)); + LayeredCauldronBlock.changeLevel(iblockdata, world, blockposition, iblockdata1, null, CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL); // CraftBukkit world.levelEvent(1047, blockposition, 0); } else if (fluidtype == FluidTypes.LAVA) { iblockdata1 = Blocks.LAVA_CAULDRON.defaultBlockState(); - world.setBlockAndUpdate(blockposition, iblockdata1); -- world.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1)); +- world.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1)); + LayeredCauldronBlock.changeLevel(iblockdata, world, blockposition, iblockdata1, null, CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL); // CraftBukkit world.levelEvent(1046, blockposition, 0); } 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 3f9027edce..f3931bf517 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,10 +1,10 @@ --- a/net/minecraft/world/level/block/BlockChest.java +++ b/net/minecraft/world/level/block/BlockChest.java -@@ -93,24 +93,7 @@ +@@ -90,24 +90,7 @@ public Optional acceptDouble(final TileEntityChest tileentitychest, final TileEntityChest tileentitychest1) { final InventoryLargeChest inventorylargechest = new InventoryLargeChest(tileentitychest, tileentitychest1); -- return Optional.of(new ITileInventory() { +- return Optional.of(new ITileInventory(this) { - @Nullable - @Override - public Container createMenu(int i, PlayerInventory playerinventory, EntityHuman entityhuman) { @@ -22,11 +22,11 @@ - return (IChatBaseComponent) (tileentitychest.hasCustomName() ? tileentitychest.getDisplayName() : (tileentitychest1.hasCustomName() ? tileentitychest1.getDisplayName() : IChatBaseComponent.translatable("container.chestDouble"))); - } - }); -+ return Optional.of(new DoubleInventory(tileentitychest, tileentitychest1, inventorylargechest)); // CraftBukkit ++ return Optional.of(new DoubleInventory(tileentitychest, tileentitychest1, inventorylargechest)); // CraftBukkit // CraftBukkit - decompile error } public Optional acceptSingle(TileEntityChest tileentitychest) { -@@ -123,6 +106,38 @@ +@@ -120,6 +103,38 @@ } }; @@ -65,7 +65,7 @@ @Override public MapCodec codec() { return BlockChest.CODEC; -@@ -278,7 +293,7 @@ +@@ -263,7 +278,7 @@ @Override public DoubleBlockFinder.Result combine(IBlockData iblockdata, World world, BlockPosition blockposition, boolean flag) { @@ -74,10 +74,10 @@ if (flag) { bipredicate = (generatoraccess, blockposition1) -> { -@@ -294,7 +309,14 @@ +@@ -279,7 +294,14 @@ @Nullable @Override - public ITileInventory getMenuProvider(IBlockData iblockdata, World world, BlockPosition blockposition) { + protected ITileInventory getMenuProvider(IBlockData iblockdata, World world, BlockPosition blockposition) { - return (ITileInventory) ((Optional) this.combine(iblockdata, world, blockposition, false).apply(BlockChest.MENU_PROVIDER_COMBINER)).orElse((Object) null); + // CraftBukkit start + return getMenuProvider(iblockdata, world, blockposition, false); 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 49d5b66ba7..f931c492f0 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 -@@ -30,6 +30,8 @@ +@@ -29,6 +29,8 @@ import net.minecraft.world.phys.MovingObjectPositionBlock; import org.slf4j.Logger; @@ -9,7 +9,7 @@ public class BlockCommand extends BlockTileEntity implements GameMasterBlock { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { -@@ -70,6 +72,15 @@ +@@ -69,6 +71,15 @@ TileEntityCommand tileentitycommand = (TileEntityCommand) tileentity; boolean flag1 = world.hasNeighborSignal(blockposition); boolean flag2 = tileentitycommand.isPowered(); 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 3fd61efded..a53c644294 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 -@@ -41,6 +41,11 @@ +@@ -43,6 +43,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); -@@ -255,7 +260,14 @@ +@@ -263,7 +268,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; -@@ -265,6 +277,14 @@ +@@ -273,6 +285,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)); -@@ -288,10 +308,16 @@ +@@ -296,10 +316,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; -@@ -340,7 +366,8 @@ +@@ -348,7 +374,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 { -@@ -355,6 +382,7 @@ +@@ -363,6 +390,7 @@ this.state = iblockdata; this.level = generatoraccess; this.pos = blockposition; @@ -79,7 +79,7 @@ } @Override -@@ -379,8 +407,15 @@ +@@ -387,8 +415,15 @@ @Override public void setChanged() { @@ -95,7 +95,7 @@ } } -@@ -393,6 +428,7 @@ +@@ -401,6 +436,7 @@ public ContainerInput(IBlockData iblockdata, GeneratorAccess generatoraccess, BlockPosition blockposition) { super(1); @@ -103,7 +103,7 @@ this.state = iblockdata; this.level = generatoraccess; this.pos = blockposition; -@@ -435,8 +471,9 @@ +@@ -443,8 +479,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 8eb772daf5..ba1b0d0ed3 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 @@ -51,7 +51,7 @@ @@ -83,7 +106,25 @@ @Override - public IBlockData updateShape(IBlockData iblockdata, EnumDirection enumdirection, IBlockData iblockdata1, GeneratorAccess generatoraccess, BlockPosition blockposition, BlockPosition blockposition1) { + 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); + // CraftBukkit start + if (touchesLiquid(generatoraccess, blockposition)) { 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 f8f8b0374a..c42075fac2 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 @@ -2,7 +2,7 @@ +++ b/net/minecraft/world/level/block/BlockCoral.java @@ -39,6 +39,11 @@ @Override - public void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { + protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if (!this.scanForWater(worldserver, blockposition)) { + // CraftBukkit start + if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, this.deadBlock.defaultBlockState()).isCancelled()) { 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 0ed25f6eea..7651d1e6fb 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 @@ -2,7 +2,7 @@ +++ b/net/minecraft/world/level/block/BlockCoralFan.java @@ -40,6 +40,11 @@ @Override - public void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { + protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if (!scanForWater(iblockdata, worldserver, blockposition)) { + // CraftBukkit start + if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, this.deadBlock.defaultBlockState().setValue(BlockCoralFan.WATERLOGGED, false)).isCancelled()) { 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 225691788b..bff8af0a1c 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 @@ -2,7 +2,7 @@ +++ b/net/minecraft/world/level/block/BlockCoralFanWall.java @@ -40,6 +40,11 @@ @Override - public void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { + protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if (!scanForWater(iblockdata, worldserver, blockposition)) { + // CraftBukkit start + if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, this.deadBlock.defaultBlockState().setValue(BlockCoralFanWall.WATERLOGGED, false).setValue(BlockCoralFanWall.FACING, iblockdata.getValue(BlockCoralFanWall.FACING))).isCancelled()) { 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 e716d85de0..3eedfdef8c 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 @@ -2,7 +2,7 @@ +++ b/net/minecraft/world/level/block/BlockCoralPlant.java @@ -45,6 +45,11 @@ @Override - public void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { + protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if (!scanForWater(iblockdata, worldserver, blockposition)) { + // CraftBukkit start + if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, this.deadBlock.defaultBlockState().setValue(BlockCoralPlant.WATERLOGGED, false)).isCancelled()) { 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 1d40ca9bfd..92dfca5bb1 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 @@ -30,7 +30,7 @@ @@ -160,7 +162,7 @@ @Override - public void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { + 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); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockDirtSnowSpreadable.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockDirtSnowSpreadable.patch index 8bee36a94b..187fabc567 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockDirtSnowSpreadable.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockDirtSnowSpreadable.patch @@ -2,7 +2,7 @@ +++ b/net/minecraft/world/level/block/BlockDirtSnowSpreadable.java @@ -44,6 +44,11 @@ @Override - public void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { + protected void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if (!canBeGrass(iblockdata, worldserver, blockposition)) { + // CraftBukkit start + if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, Blocks.DIRT.defaultBlockState()).isCancelled()) { 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 36f91ac5b5..6d78a69b3a 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 -@@ -49,6 +49,7 @@ - object2objectopenhashmap.defaultReturnValue(new DispenseBehaviorItem()); +@@ -51,6 +51,7 @@ + object2objectopenhashmap.defaultReturnValue(BlockDispenser.DEFAULT_BEHAVIOR); }); private static final int TRIGGER_DURATION = 4; + public static boolean eventFired = false; // CraftBukkit @Override public MapCodec codec() { -@@ -85,7 +86,7 @@ +@@ -91,7 +92,7 @@ } public void dispenseFrom(WorldServer worldserver, IBlockData iblockdata, BlockPosition blockposition) { @@ -17,8 +17,8 @@ if (tileentitydispenser == null) { BlockDispenser.LOGGER.warn("Ignoring dispensing attempt for Dispenser without matching block entity at {}", blockposition); -@@ -101,6 +102,7 @@ - IDispenseBehavior idispensebehavior = this.getDispenseMethod(itemstack); +@@ -107,6 +108,7 @@ + IDispenseBehavior idispensebehavior = this.getDispenseMethod(worldserver, itemstack); if (idispensebehavior != IDispenseBehavior.NOOP) { + eventFired = false; // CraftBukkit - reset event status 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 284fd9f532..a6c3d841a4 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 @@ -12,7 +12,7 @@ @@ -220,9 +222,24 @@ @Override - public 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, BlockPosition blockposition1, 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); @@ -35,4 +35,4 @@ + // CraftBukkit end if (flag1 != (Boolean) iblockdata.getValue(BlockDoor.OPEN)) { this.playSound((Entity) null, world, blockposition, flag1); - world.gameEvent((Entity) null, flag1 ? GameEvent.BLOCK_OPEN : GameEvent.BLOCK_CLOSE, blockposition); + world.gameEvent((Entity) null, (Holder) (flag1 ? GameEvent.BLOCK_OPEN : GameEvent.BLOCK_CLOSE), blockposition); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockDragonEgg.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockDragonEgg.patch index ab3c8078a6..c7129ecff0 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockDragonEgg.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockDragonEgg.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockDragonEgg.java +++ b/net/minecraft/world/level/block/BlockDragonEgg.java -@@ -17,6 +17,8 @@ +@@ -16,6 +16,8 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -9,7 +9,7 @@ public class BlockDragonEgg extends BlockFalling { public static final MapCodec CODEC = simpleCodec(BlockDragonEgg::new); -@@ -54,6 +56,18 @@ +@@ -53,6 +55,18 @@ BlockPosition blockposition1 = blockposition.offset(world.random.nextInt(16) - world.random.nextInt(16), world.random.nextInt(8) - world.random.nextInt(8), world.random.nextInt(16) - world.random.nextInt(16)); if (world.getBlockState(blockposition1).isAir() && worldborder.isWithinBounds(blockposition1)) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockDropper.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockDropper.patch index 1a97f33a5c..55c26c92ff 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockDropper.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockDropper.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockDropper.java +++ b/net/minecraft/world/level/block/BlockDropper.java -@@ -19,11 +19,17 @@ +@@ -20,11 +20,17 @@ import net.minecraft.world.level.block.state.IBlockData; import org.slf4j.Logger; @@ -19,7 +19,7 @@ @Override public MapCodec codec() { -@@ -46,7 +52,7 @@ +@@ -47,7 +53,7 @@ @Override public void dispenseFrom(WorldServer worldserver, IBlockData iblockdata, BlockPosition blockposition) { @@ -28,7 +28,7 @@ if (tileentitydispenser == null) { BlockDropper.LOGGER.warn("Ignoring dispensing attempt for Dropper without matching block entity at {}", blockposition); -@@ -67,8 +73,25 @@ +@@ -68,8 +74,25 @@ if (iinventory == null) { itemstack1 = BlockDropper.DISPENSE_BEHAVIOUR.dispense(sourceblock, itemstack); } else { 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 2bbe455a3a..2e4c3a2185 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 @@ -16,7 +16,7 @@ public static final MapCodec CODEC = simpleCodec(BlockEnderPortal::new); @@ -48,13 +55,22 @@ @Override - public void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { + protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { if (world instanceof WorldServer && entity.canChangeDimensions() && VoxelShapes.joinIsNotEmpty(VoxelShapes.create(entity.getBoundingBox().move((double) (-blockposition.getX()), (double) (-blockposition.getY()), (double) (-blockposition.getZ()))), iblockdata.getShape(world, blockposition), OperatorBoolean.AND)) { - ResourceKey resourcekey = world.dimension() == World.END ? World.OVERWORLD : World.END; + ResourceKey resourcekey = world.getTypeKey() == WorldDimension.END ? World.OVERWORLD : World.END; // CraftBukkit - SPIGOT-6152: send back to main overworld in custom ends 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 ab12c8c076..9cedb87742 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 @@ - public 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, BlockPosition blockposition1, 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 7a4a7bd484..b172681be6 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 @@ -18,7 +18,7 @@ @@ -100,7 +108,24 @@ @Override - public IBlockData updateShape(IBlockData iblockdata, EnumDirection enumdirection, IBlockData iblockdata1, GeneratorAccess generatoraccess, BlockPosition blockposition, BlockPosition blockposition1) { + 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(); + // CraftBukkit start + if (!this.canSurvive(iblockdata, generatoraccess, blockposition)) { 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 6712a45f71..98746fb1b0 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 @@ -4,13 +4,13 @@ if (!entity.fireImmune()) { entity.setRemainingFireTicks(entity.getRemainingFireTicks() + 1); if (entity.getRemainingFireTicks() == 0) { -- entity.setSecondsOnFire(8); +- entity.igniteForSeconds(8); + // 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); + world.getCraftServer().getPluginManager().callEvent(event); + + if (!event.isCancelled()) { -+ entity.setSecondsOnFire(event.getDuration(), false); ++ entity.igniteForSeconds(event.getDuration(), false); + } + // CraftBukkit end } 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 33ae74b51b..addd5dfa3b 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 @@ -7,9 +7,9 @@ - DataResult dataresult; + DataResult dataresult; // CraftBukkit - decompile error - if (fluidtype instanceof FluidTypeFlowing) { - FluidTypeFlowing fluidtypeflowing = (FluidTypeFlowing) fluidtype; -@@ -174,14 +174,20 @@ + if (fluidtype instanceof FluidTypeFlowing fluidtypeflowing) { + dataresult = DataResult.success(fluidtypeflowing); +@@ -172,14 +172,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/BlockGrassPath.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockGrassPath.patch index b98e33d889..b6d410b955 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockGrassPath.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockGrassPath.patch @@ -3,7 +3,7 @@ @@ -51,6 +51,11 @@ @Override - public void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { + protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { + // CraftBukkit start - do not fade if the block is valid here + if (iblockdata.canSurvive(worldserver, blockposition)) { + return; 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 55eeb6d259..c3ca72ab33 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 @@ -11,7 +11,7 @@ public static final MapCodec CODEC = simpleCodec(BlockLeaves::new); @@ -57,6 +59,14 @@ @Override - public void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { + protected void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if (this.decaying(iblockdata)) { + // CraftBukkit start + LeavesDecayEvent event = new LeavesDecayEvent(worldserver.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ())); 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 d8d6c1e3a0..3af3ec5615 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,14 +1,13 @@ --- a/net/minecraft/world/level/block/BlockLectern.java +++ b/net/minecraft/world/level/block/BlockLectern.java -@@ -207,12 +207,13 @@ +@@ -207,11 +207,12 @@ } private void popBook(IBlockData iblockdata, World world, BlockPosition blockposition) { - TileEntity tileentity = world.getBlockEntity(blockposition); + TileEntity tileentity = world.getBlockEntity(blockposition, false); // CraftBukkit - don't validate, type may be changed already - if (tileentity instanceof TileEntityLectern) { - TileEntityLectern tileentitylectern = (TileEntityLectern) tileentity; + if (tileentity instanceof TileEntityLectern tileentitylectern) { EnumDirection enumdirection = (EnumDirection) iblockdata.getValue(BlockLectern.FACING); ItemStack itemstack = tileentitylectern.getBook().copy(); + if (itemstack.isEmpty()) return; // CraftBukkit - SPIGOT-5500 diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockMobSpawner.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockMobSpawner.patch index 3a7c1b280b..99b013b051 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockMobSpawner.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockMobSpawner.patch @@ -2,7 +2,7 @@ +++ b/net/minecraft/world/level/block/BlockMobSpawner.java @@ -45,12 +45,20 @@ @Override - public void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) { + protected void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) { super.spawnAfterBreak(iblockdata, worldserver, blockposition, itemstack, flag); + // CraftBukkit start - Delegate to getExpDrop + } 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 0d436f9471..6fa812480a 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 -@@ -82,6 +82,7 @@ +@@ -83,6 +83,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); -@@ -91,6 +92,12 @@ +@@ -92,6 +93,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()) { @@ -19,5 +19,5 @@ + } + // CraftBukkit end world.blockEvent(blockposition, this, 0, 0); - world.gameEvent(entity, GameEvent.NOTE_BLOCK_PLAY, blockposition); + world.gameEvent(entity, (Holder) GameEvent.NOTE_BLOCK_PLAY, blockposition); } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockNylium.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockNylium.patch index 3e7fcfebe7..244c15ed39 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockNylium.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockNylium.patch @@ -2,7 +2,7 @@ +++ b/net/minecraft/world/level/block/BlockNylium.java @@ -41,6 +41,11 @@ @Override - public void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { + protected void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if (!canBeNylium(iblockdata, worldserver, blockposition)) { + // CraftBukkit start + if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, Blocks.NETHERRACK.defaultBlockState()).isCancelled()) { 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 dae36bc563..3db9cb18f4 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 @@ -11,7 +11,7 @@ public static final MapCodec CODEC = simpleCodec(BlockObserver::new); @@ -48,8 +50,18 @@ @Override - public void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { + protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if ((Boolean) iblockdata.getValue(BlockObserver.POWERED)) { + // CraftBukkit start + if (CraftEventFactory.callRedstoneChange(worldserver, blockposition, 15, 0).getNewCurrent() != 0) { 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 689f95275a..c7ded8557d 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 @@ -3,7 +3,7 @@ @@ -26,7 +26,14 @@ @Override - public IBlockData updateShape(IBlockData iblockdata, EnumDirection enumdirection, IBlockData iblockdata1, GeneratorAccess generatoraccess, BlockPosition blockposition, BlockPosition blockposition1) { + 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); + // CraftBukkit start + if (!iblockdata.canSurvive(generatoraccess, blockposition)) { 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 eaa6a9758f..79e9f0e996 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 @@ -23,7 +23,7 @@ entity.setPortalCooldown(); @@ -85,6 +90,10 @@ @Override - public void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { + protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { if (entity.canChangeDimensions()) { + // CraftBukkit start - Entity in portal + EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ())); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockPressurePlateAbstract.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockPressurePlateAbstract.patch index d985b2e505..e429e95a7d 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockPressurePlateAbstract.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockPressurePlateAbstract.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockPressurePlateAbstract.java +++ b/net/minecraft/world/level/block/BlockPressurePlateAbstract.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 abstract class BlockPressurePlateAbstract extends Block { protected static final VoxelShape PRESSED_AABB = Block.box(1.0D, 0.0D, 1.0D, 15.0D, 0.5D, 15.0D); -@@ -90,6 +92,19 @@ +@@ -91,6 +93,19 @@ boolean flag = i > 0; boolean flag1 = j > 0; @@ -29,7 +29,7 @@ if (i != j) { IBlockData iblockdata1 = this.setSignalForState(iblockdata, j); -@@ -144,9 +159,15 @@ +@@ -145,9 +160,15 @@ } protected static int getEntityCount(World world, AxisAlignedBB axisalignedbb, Class oclass) { 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 76133c1a1a..79f53d0f30 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 -@@ -28,6 +28,8 @@ +@@ -27,6 +27,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); -@@ -110,7 +112,8 @@ +@@ -109,7 +111,8 @@ @Nullable private EntityItemFrame getItemFrame(World world, EnumDirection enumdirection, BlockPosition blockposition) { @@ -19,7 +19,7 @@ return entityitemframe != null && entityitemframe.getDirection() == enumdirection; }); -@@ -165,8 +168,18 @@ +@@ -162,8 +165,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 57cd0c7351..dce344c8b4 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 @@ -23,7 +23,7 @@ } @@ -52,6 +59,11 @@ @Override - public void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { + protected void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if ((Boolean) iblockdata.getValue(BlockRedstoneLamp.LIT) && !worldserver.hasNeighborSignal(blockposition)) { + // CraftBukkit start + if (CraftEventFactory.callRedstoneChange(worldserver, blockposition, 15, 0).getNewCurrent() != 0) { 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 2667a38da8..a3ea951a32 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 @@ -15,7 +15,7 @@ @@ -39,14 +44,27 @@ @Override - public void attack(IBlockData iblockdata, World world, BlockPosition blockposition, EntityHuman entityhuman) { + protected void attack(IBlockData iblockdata, World world, BlockPosition blockposition, EntityHuman entityhuman) { - interact(iblockdata, world, blockposition); + interact(iblockdata, world, blockposition, entityhuman); // CraftBukkit - add entityhuman super.attack(iblockdata, world, blockposition, entityhuman); @@ -42,7 +42,7 @@ } super.stepOn(world, blockposition, iblockdata, entity); -@@ -57,7 +75,7 @@ +@@ -57,15 +75,20 @@ if (world.isClientSide) { spawnParticles(world, blockposition); } else { @@ -50,9 +50,7 @@ + interact(iblockdata, world, blockposition, entityhuman); // CraftBukkit - add entityhuman } - ItemStack itemstack = entityhuman.getItemInHand(enumhand); -@@ -65,9 +83,14 @@ - return itemstack.getItem() instanceof ItemBlock && (new BlockActionContext(entityhuman, enumhand, itemstack, movingobjectpositionblock)).canPlace() ? EnumInteractionResult.PASS : EnumInteractionResult.SUCCESS; + return itemstack.getItem() instanceof ItemBlock && (new BlockActionContext(entityhuman, enumhand, itemstack, movingobjectpositionblock)).canPlace() ? ItemInteractionResult.SKIP_DEFAULT_BLOCK_INTERACTION : ItemInteractionResult.SUCCESS; } - private static void interact(IBlockData iblockdata, World world, BlockPosition blockposition) { @@ -67,9 +65,9 @@ world.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockRedstoneOre.LIT, true), 3); } -@@ -81,6 +104,11 @@ +@@ -79,6 +102,11 @@ @Override - public void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { + protected void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if ((Boolean) iblockdata.getValue(BlockRedstoneOre.LIT)) { + // CraftBukkit start + if (CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, iblockdata.setValue(BlockRedstoneOre.LIT, false)).isCancelled()) { @@ -79,9 +77,9 @@ worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockRedstoneOre.LIT, false), 3); } -@@ -89,12 +117,20 @@ +@@ -87,12 +115,20 @@ @Override - public void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) { + protected void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) { super.spawnAfterBreak(iblockdata, worldserver, blockposition, itemstack, flag); + // CraftBukkit start - Delegated to getExpDrop + } 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 index 99beb3beb8..40407a286b 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneWire.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockRedstoneWire.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockRedstoneWire.java +++ b/net/minecraft/world/level/block/BlockRedstoneWire.java -@@ -37,6 +37,8 @@ +@@ -36,6 +36,8 @@ import net.minecraft.world.phys.shapes.VoxelShapeCollision; import net.minecraft.world.phys.shapes.VoxelShapes; @@ -9,7 +9,7 @@ public class BlockRedstoneWire extends Block { public static final MapCodec CODEC = simpleCodec(BlockRedstoneWire::new); -@@ -261,7 +263,16 @@ +@@ -260,7 +262,16 @@ private void updatePowerStrength(World world, BlockPosition blockposition, IBlockData iblockdata) { int i = this.calculateTargetStrength(world, blockposition); 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 90d1e0c3fa..ce86163294 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,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockRespawnAnchor.java +++ b/net/minecraft/world/level/block/BlockRespawnAnchor.java -@@ -87,7 +87,7 @@ +@@ -89,7 +89,7 @@ EntityPlayer entityplayer = (EntityPlayer) entityhuman; if (entityplayer.getRespawnDimension() != world.dimension() || !blockposition.equals(entityplayer.getRespawnPosition())) { @@ -9,7 +9,7 @@ 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; } -@@ -127,7 +127,7 @@ +@@ -129,14 +129,14 @@ private void explode(IBlockData iblockdata, World world, final BlockPosition blockposition) { world.removeBlock(blockposition, false); @@ -18,3 +18,11 @@ Objects.requireNonNull(blockposition); boolean flag = stream.map(blockposition::relative).anyMatch((blockposition1) -> { + return isWaterThatWouldFlow(blockposition1, world); + }); + final boolean flag1 = flag || world.getFluidState(blockposition.above()).is(TagsFluid.WATER); +- ExplosionDamageCalculator explosiondamagecalculator = new ExplosionDamageCalculator(this) { ++ ExplosionDamageCalculator explosiondamagecalculator = new ExplosionDamageCalculator() { // CraftBukkit - decompile error + @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); 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 3affa3a945..47254a4363 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 -@@ -118,7 +118,7 @@ - } else if (flag2) { - return EnumInteractionResult.SUCCESS; - } else if (!this.otherPlayerIsEditingSign(entityhuman, tileentitysign) && entityhuman.mayBuild() && this.hasEditableText(entityhuman, tileentitysign, flag1)) { -- this.openTextEdit(entityhuman, tileentitysign, flag1); -+ this.openTextEdit(entityhuman, tileentitysign, flag1, org.bukkit.event.player.PlayerSignOpenEvent.Cause.INTERACT); // CraftBukkit - return this.getInteractionResult(flag); - } else { - return EnumInteractionResult.PASS; -@@ -171,6 +171,15 @@ +@@ -142,7 +142,7 @@ + } else if (flag1) { + return EnumInteractionResult.SUCCESS; + } 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; + } else { + return EnumInteractionResult.PASS; +@@ -188,6 +188,15 @@ } public void openTextEdit(EntityHuman entityhuman, TileEntitySign tileentitysign, boolean flag) { @@ -25,7 +25,7 @@ tileentitysign.setAllowedPlayerEditor(entityhuman.getUUID()); entityhuman.openTextEdit(tileentitysign, flag); } -@@ -184,6 +193,6 @@ +@@ -201,6 +210,6 @@ @Nullable @Override public BlockEntityTicker getTicker(World world, IBlockData iblockdata, TileEntityTypes tileentitytypes) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/BlockSnow.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockSnow.patch index 923cc20747..17758fccc1 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/BlockSnow.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/BlockSnow.patch @@ -2,7 +2,7 @@ +++ b/net/minecraft/world/level/block/BlockSnow.java @@ -99,6 +99,11 @@ @Override - public void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { + protected void randomTick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, RandomSource randomsource) { if (worldserver.getBrightness(EnumSkyBlock.BLOCK, blockposition) > 11) { + // CraftBukkit start + if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, Blocks.AIR.defaultBlockState()).isCancelled()) { 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 e370f14b57..fb1d9e8fb6 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockSoil.java +++ b/net/minecraft/world/level/block/BlockSoil.java -@@ -29,6 +29,11 @@ +@@ -30,6 +30,11 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -12,7 +12,7 @@ public class BlockSoil extends Block { public static final MapCodec CODEC = simpleCodec(BlockSoil::new); -@@ -91,26 +96,49 @@ +@@ -92,26 +97,49 @@ if (!isNearWater(worldserver, blockposition) && !worldserver.isRainingAt(blockposition.above())) { if (i > 0) { 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 378e230284..e3d7501e2f 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 -@@ -28,6 +28,13 @@ +@@ -30,6 +30,13 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -14,16 +14,16 @@ public class BlockSweetBerryBush extends BlockPlant implements IBlockFragilePlantElement { public static final MapCodec CODEC = simpleCodec(BlockSweetBerryBush::new); -@@ -69,7 +76,7 @@ +@@ -71,7 +78,7 @@ if (i < 3 && randomsource.nextInt(5) == 0 && worldserver.getRawBrightness(blockposition.above(), 0) >= 9) { IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockSweetBerryBush.AGE, i + 1); - worldserver.setBlock(blockposition, iblockdata1, 2); + if (!CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, iblockdata1, 2)) return; // CraftBukkit - worldserver.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1)); + worldserver.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1)); } -@@ -84,7 +91,7 @@ +@@ -86,7 +93,7 @@ double d1 = Math.abs(entity.getZ() - entity.zOld); if (d0 >= 0.003000000026077032D || d1 >= 0.003000000026077032D) { @@ -32,13 +32,13 @@ } } -@@ -101,7 +108,15 @@ - } else if (i > 1) { +@@ -109,7 +116,15 @@ + if (i > 1) { int j = 1 + world.random.nextInt(2); - popResource(world, blockposition, new ItemStack(Items.SWEET_BERRIES, j + (flag ? 1 : 0))); -+ // CraftBukkit start -+ PlayerHarvestBlockEvent event = CraftEventFactory.callPlayerHarvestBlockEvent(world, blockposition, entityhuman, enumhand, Collections.singletonList(new ItemStack(Items.SWEET_BERRIES, j + (flag ? 1 : 0)))); ++ // CraftBukkit start - useWithoutItem is always MAIN_HAND ++ PlayerHarvestBlockEvent event = CraftEventFactory.callPlayerHarvestBlockEvent(world, blockposition, entityhuman, EnumHand.MAIN_HAND, Collections.singletonList(new ItemStack(Items.SWEET_BERRIES, j + (flag ? 1 : 0)))); + if (event.isCancelled()) { + return EnumInteractionResult.SUCCESS; // We need to return a success either way, because making it PASS or FAIL will result in a bug where cancelling while harvesting w/ block in hand places block + } 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 9d73f902c8..560a87771b 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,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockTNT.java +++ b/net/minecraft/world/level/block/BlockTNT.java -@@ -26,6 +26,11 @@ +@@ -27,6 +27,11 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.MovingObjectPositionBlock; @@ -12,25 +12,25 @@ public class BlockTNT extends Block { public static final MapCodec CODEC = simpleCodec(BlockTNT::new); -@@ -44,7 +49,7 @@ +@@ -45,7 +50,7 @@ @Override - public void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) { + protected void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) { if (!iblockdata1.is(iblockdata.getBlock())) { - if (world.hasNeighborSignal(blockposition)) { + if (world.hasNeighborSignal(blockposition) && CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.REDSTONE, null, null)) { // CraftBukkit - TNTPrimeEvent explode(world, blockposition); world.removeBlock(blockposition, false); } -@@ -54,7 +59,7 @@ +@@ -55,7 +60,7 @@ @Override - public 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, BlockPosition blockposition1, boolean flag) { - if (world.hasNeighborSignal(blockposition)) { + if (world.hasNeighborSignal(blockposition) && CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.REDSTONE, null, blockposition1)) { // CraftBukkit - TNTPrimeEvent explode(world, blockposition); world.removeBlock(blockposition, false); } -@@ -63,7 +68,7 @@ +@@ -64,7 +69,7 @@ @Override public IBlockData playerWillDestroy(World world, BlockPosition blockposition, IBlockData iblockdata, EntityHuman entityhuman) { @@ -39,19 +39,19 @@ explode(world, blockposition); } -@@ -102,6 +107,11 @@ +@@ -101,6 +106,11 @@ if (!itemstack.is(Items.FLINT_AND_STEEL) && !itemstack.is(Items.FIRE_CHARGE)) { - return super.use(iblockdata, world, blockposition, entityhuman, enumhand, movingobjectpositionblock); + return super.useItemOn(itemstack, iblockdata, world, blockposition, entityhuman, enumhand, movingobjectpositionblock); } else { + // CraftBukkit start - TNTPrimeEvent + if (!CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.PLAYER, entityhuman, null)) { -+ return EnumInteractionResult.CONSUME; ++ return ItemInteractionResult.CONSUME; + } + // CraftBukkit end explode(world, blockposition, entityhuman); world.setBlock(blockposition, Blocks.AIR.defaultBlockState(), 11); Item item = itemstack.getItem(); -@@ -128,6 +138,11 @@ +@@ -125,6 +135,11 @@ Entity entity = iprojectile.getOwner(); if (iprojectile.isOnFire() && iprojectile.mayInteract(world, blockposition)) { 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 168a220143..c611141f9c 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 -@@ -27,6 +27,8 @@ +@@ -28,6 +28,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) -> { -@@ -166,6 +168,40 @@ +@@ -167,6 +169,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 b1ffb21273..a05ad28081 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 -@@ -29,6 +29,11 @@ +@@ -30,6 +30,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); -@@ -173,6 +178,15 @@ +@@ -174,6 +179,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 04cbc51718..7b3381fc71 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 -@@ -30,6 +30,12 @@ +@@ -31,6 +31,12 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; @@ -13,7 +13,7 @@ public class BlockTurtleEgg extends Block { public static final MapCodec CODEC = simpleCodec(BlockTurtleEgg::new); -@@ -72,6 +78,19 @@ +@@ -73,6 +79,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)) { @@ -33,7 +33,7 @@ this.decreaseEggs(world, blockposition, iblockdata); } -@@ -98,10 +117,20 @@ +@@ -99,10 +118,20 @@ int i = (Integer) iblockdata.getValue(BlockTurtleEgg.HATCH); if (i < 2) { @@ -45,7 +45,7 @@ worldserver.playSound((EntityHuman) null, blockposition, SoundEffects.TURTLE_EGG_CRACK, SoundCategory.BLOCKS, 0.7F, 0.9F + randomsource.nextFloat() * 0.2F); - worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockTurtleEgg.HATCH, i + 1), 2); + // worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockTurtleEgg.HATCH, i + 1), 2); // CraftBukkit - handled above - worldserver.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata)); + worldserver.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata)); } else { + // CraftBukkit start - Call BlockFadeEvent + if (CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, Blocks.AIR.defaultBlockState()).isCancelled()) { @@ -54,8 +54,8 @@ + // CraftBukkit end 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(GameEvent.BLOCK_DESTROY, blockposition, GameEvent.a.of(iblockdata)); -@@ -114,7 +143,7 @@ + worldserver.gameEvent((Holder) GameEvent.BLOCK_DESTROY, blockposition, GameEvent.a.of(iblockdata)); +@@ -115,7 +144,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/BlockWaterLily.patch b/paper-server/nms-patches/net/minecraft/world/level/block/BlockWaterLily.patch index d453a0b8d6..9251f6af79 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 @@ -12,7 +12,7 @@ public static final MapCodec CODEC = simpleCodec(BlockWaterLily::new); @@ -32,6 +36,11 @@ - public void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { + protected void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { super.entityInside(iblockdata, world, blockposition, entity); if (world instanceof WorldServer && entity instanceof EntityBoat) { + // CraftBukkit start 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 ac6dbdd5b3..e3999a628b 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,6 +1,6 @@ --- a/net/minecraft/world/level/block/BlockWitherRose.java +++ b/net/minecraft/world/level/block/BlockWitherRose.java -@@ -66,7 +66,7 @@ +@@ -67,7 +67,7 @@ EntityLiving entityliving = (EntityLiving) entity; if (!entityliving.isInvulnerableTo(world.damageSources().wither())) { 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 40c507d61c..780efc1b74 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 @@ -11,7 +11,7 @@ public class BlockWitherSkull extends BlockSkull { public static final MapCodec CODEC = simpleCodec(BlockWitherSkull::new); -@@ -54,6 +58,7 @@ +@@ -57,6 +61,7 @@ } public static void checkSpawn(World world, BlockPosition blockposition, TileEntitySkull tileentityskull) { @@ -19,7 +19,7 @@ if (!world.isClientSide) { IBlockData iblockdata = tileentityskull.getBlockState(); boolean flag = iblockdata.is(Blocks.WITHER_SKELETON_SKULL) || iblockdata.is(Blocks.WITHER_SKELETON_WALL_SKULL); -@@ -65,12 +70,18 @@ +@@ -68,12 +73,18 @@ EntityWither entitywither = (EntityWither) EntityTypes.WITHER.create(world); if (entitywither != null) { @@ -39,7 +39,7 @@ Iterator iterator = world.getEntitiesOfClass(EntityPlayer.class, entitywither.getBoundingBox().inflate(50.0D)).iterator(); while (iterator.hasNext()) { -@@ -79,7 +90,7 @@ +@@ -82,7 +93,7 @@ CriterionTriggers.SUMMONED_ENTITY.trigger(entityplayer, (Entity) entitywither); } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/CaveVines.patch b/paper-server/nms-patches/net/minecraft/world/level/block/CaveVines.patch index aab8189b74..1184f18f9d 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/CaveVines.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/CaveVines.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/CaveVines.java +++ b/net/minecraft/world/level/block/CaveVines.java -@@ -18,6 +18,13 @@ +@@ -19,6 +19,13 @@ import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.shapes.VoxelShape; @@ -14,7 +14,7 @@ public interface CaveVines { VoxelShape SHAPE = Block.box(1.0D, 0.0D, 1.0D, 15.0D, 16.0D, 15.0D); -@@ -25,7 +32,24 @@ +@@ -26,7 +33,24 @@ static EnumInteractionResult use(@Nullable Entity entity, IBlockData iblockdata, World world, BlockPosition blockposition) { if ((Boolean) iblockdata.getValue(CaveVines.BERRIES)) { 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 2cffc8787e..99ec4d1385 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 -@@ -161,6 +161,6 @@ +@@ -158,6 +158,6 @@ @Nullable @Override public BlockEntityTicker getTicker(World world, IBlockData iblockdata, TileEntityTypes tileentitytypes) { 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 aa5909875d..52a45a5095 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,6 +1,6 @@ --- a/net/minecraft/world/level/block/DecoratedPotBlock.java +++ b/net/minecraft/world/level/block/DecoratedPotBlock.java -@@ -230,6 +230,11 @@ +@@ -238,6 +238,11 @@ BlockPosition blockposition = movingobjectpositionblock.getBlockPos(); if (!world.isClientSide && iprojectile.mayInteract(world, blockposition) && iprojectile.mayBreak(world)) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/DropExperienceBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/DropExperienceBlock.patch index cf005a11d4..6695cab721 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/DropExperienceBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/DropExperienceBlock.patch @@ -2,7 +2,7 @@ +++ b/net/minecraft/world/level/block/DropExperienceBlock.java @@ -31,9 +31,16 @@ @Override - public void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) { + protected void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) { super.spawnAfterBreak(iblockdata, worldserver, blockposition, itemstack, flag); + // CraftBukkit start - Delegate to getExpDrop + } 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 d9702e0b22..9c5e2bf82e 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 -@@ -16,6 +16,12 @@ +@@ -17,6 +17,12 @@ import net.minecraft.world.level.material.FluidType; import net.minecraft.world.level.material.FluidTypes; @@ -13,9 +13,9 @@ public class LayeredCauldronBlock extends AbstractCauldronBlock { public static final MapCodec CODEC = RecordCodecBuilder.mapCodec((instance) -> { -@@ -61,10 +67,14 @@ +@@ -62,10 +68,14 @@ @Override - public void entityInside(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) { + 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 @@ -30,7 +30,7 @@ } } -@@ -79,20 +89,42 @@ +@@ -80,20 +90,42 @@ } public static void lowerFillLevel(IBlockData iblockdata, World world, BlockPosition blockposition) { @@ -43,7 +43,7 @@ IBlockData iblockdata1 = i == 0 ? Blocks.CAULDRON.defaultBlockState() : (IBlockData) iblockdata.setValue(LayeredCauldronBlock.LEVEL, i); - world.setBlockAndUpdate(blockposition, iblockdata1); -- world.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1)); +- world.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1)); + return changeLevel(iblockdata, world, blockposition, iblockdata1, entity, reason); } @@ -61,7 +61,7 @@ + return false; + } + newState.update(true); -+ world.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(newBlock)); ++ world.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(newBlock)); + return true; + } + // CraftBukkit end @@ -72,17 +72,17 @@ IBlockData iblockdata1 = (IBlockData) iblockdata.cycle(LayeredCauldronBlock.LEVEL); - world.setBlockAndUpdate(blockposition, iblockdata1); -- world.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1)); +- world.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1)); + changeLevel(iblockdata, world, blockposition, iblockdata1, null, CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL); // CraftBukkit } } -@@ -111,8 +143,11 @@ +@@ -112,8 +144,11 @@ if (!this.isFull(iblockdata)) { IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(LayeredCauldronBlock.LEVEL, (Integer) iblockdata.getValue(LayeredCauldronBlock.LEVEL) + 1); - world.setBlockAndUpdate(blockposition, iblockdata1); -- world.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1)); +- world.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1)); + // CraftBukkit start + if (!changeLevel(iblockdata, world, blockposition, iblockdata1, null, CauldronLevelChangeEvent.ChangeReason.NATURAL_FILL)) { + return; 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 c62c3d9271..a90a954ad8 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,6 +1,6 @@ --- a/net/minecraft/world/level/block/PointedDripstoneBlock.java +++ b/net/minecraft/world/level/block/PointedDripstoneBlock.java -@@ -132,6 +132,11 @@ +@@ -133,6 +133,11 @@ BlockPosition blockposition = movingobjectpositionblock.getBlockPos(); if (iprojectile.mayInteract(world, blockposition) && iprojectile.mayBreak(world) && iprojectile instanceof EntityThrownTrident && iprojectile.getDeltaMovement().length() > 0.6D) { @@ -12,7 +12,7 @@ world.destroyBlock(blockposition, true); } -@@ -141,7 +146,7 @@ +@@ -142,7 +147,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); } -@@ -386,15 +391,15 @@ +@@ -387,15 +392,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) { -@@ -409,8 +414,8 @@ +@@ -410,8 +415,8 @@ blockposition1 = blockposition.below(); } @@ -51,7 +51,7 @@ } public static void spawnDripParticle(World world, BlockPosition blockposition, IBlockData iblockdata) { -@@ -443,7 +448,7 @@ +@@ -444,7 +449,7 @@ return (BlockPosition) findBlockVertical(generatoraccess, blockposition, enumdirection.getAxisDirection(), bipredicate, (iblockdata1) -> { return isTip(iblockdata1, flag); @@ -60,7 +60,7 @@ } } -@@ -559,7 +564,7 @@ +@@ -560,7 +565,7 @@ return canDripThrough(world, blockposition1, iblockdata); }; @@ -69,7 +69,7 @@ } @Nullable -@@ -568,7 +573,7 @@ +@@ -569,7 +574,7 @@ return canDripThrough(world, blockposition1, iblockdata); }; diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/RootedDirtBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/RootedDirtBlock.patch index fe3878c9a7..bd12ce854a 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/RootedDirtBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/RootedDirtBlock.patch @@ -1,10 +1,11 @@ --- a/net/minecraft/world/level/block/RootedDirtBlock.java +++ b/net/minecraft/world/level/block/RootedDirtBlock.java -@@ -34,6 +34,6 @@ +@@ -34,7 +34,7 @@ @Override public void performBonemeal(WorldServer worldserver, RandomSource randomsource, BlockPosition blockposition, IBlockData iblockdata) { - worldserver.setBlockAndUpdate(blockposition.below(), Blocks.HANGING_ROOTS.defaultBlockState()); + org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockSpreadEvent(worldserver, blockposition, blockposition.below(), Blocks.HANGING_ROOTS.defaultBlockState()); // CraftBukkit } - } + + @Override diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/SculkCatalystBlock.patch b/paper-server/nms-patches/net/minecraft/world/level/block/SculkCatalystBlock.patch index 3373f9def5..adff3a8d5a 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/SculkCatalystBlock.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/SculkCatalystBlock.patch @@ -2,7 +2,7 @@ +++ b/net/minecraft/world/level/block/SculkCatalystBlock.java @@ -68,9 +68,16 @@ @Override - public void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) { + protected void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) { super.spawnAfterBreak(iblockdata, worldserver, blockposition, itemstack, flag); + // CraftBukkit start - Delegate to getExpDrop + } 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 3598fb5a29..98237a7c53 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 -@@ -42,6 +42,11 @@ +@@ -43,6 +43,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); -@@ -102,6 +107,18 @@ +@@ -103,6 +108,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) { -@@ -205,6 +222,15 @@ +@@ -206,6 +223,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); -@@ -216,6 +242,15 @@ +@@ -217,6 +243,15 @@ } public void activate(@Nullable Entity entity, World world, BlockPosition blockposition, IBlockData iblockdata, int i, int j) { @@ -63,9 +63,9 @@ 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); -@@ -298,9 +333,16 @@ +@@ -297,9 +332,16 @@ @Override - public void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) { + protected void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) { super.spawnAfterBreak(iblockdata, worldserver, blockposition, itemstack, flag); + // CraftBukkit start - Delegate to getExpDrop + } 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 59cb55a612..02dbc8945d 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 -@@ -63,6 +63,7 @@ +@@ -62,6 +62,7 @@ EntityPlayer entityplayer = SculkShriekerBlockEntity.tryGetPlayer(entity); if (entityplayer != null) { @@ -8,9 +8,9 @@ worldserver.getBlockEntity(blockposition, TileEntityTypes.SCULK_SHRIEKER).ifPresent((sculkshriekerblockentity) -> { sculkshriekerblockentity.tryShriek(worldserver, entityplayer); }); -@@ -147,10 +148,17 @@ +@@ -144,10 +145,17 @@ @Override - public void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) { + protected void spawnAfterBreak(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, ItemStack itemstack, boolean flag) { super.spawnAfterBreak(iblockdata, worldserver, blockposition, itemstack, flag); + // CraftBukkit start - Delegate to getExpDrop + } 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 8195d10645..7e8844060f 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 -@@ -186,6 +186,6 @@ +@@ -183,6 +183,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 b49f707120..95cc62d72f 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/BrushableBlockEntity.java +++ b/net/minecraft/world/level/block/entity/BrushableBlockEntity.java -@@ -28,6 +28,12 @@ +@@ -31,6 +31,12 @@ import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; @@ -13,7 +13,7 @@ public class BrushableBlockEntity extends TileEntity { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -153,7 +159,10 @@ +@@ -156,7 +162,10 @@ EntityItem entityitem = new EntityItem(this.level, d3, d4, d5, this.item.split(this.level.random.nextInt(21) + 10)); entityitem.setDeltaMovement(Vec3D.ZERO); @@ -25,11 +25,3 @@ this.item = ItemStack.EMPTY; } -@@ -230,6 +239,7 @@ - - @Override - public void load(NBTTagCompound nbttagcompound) { -+ super.load(nbttagcompound); // CraftBukkit - SPIGOT-7393: Load super Bukkit data - if (!this.tryLoadLootTable(nbttagcompound) && nbttagcompound.contains("item")) { - this.item = ItemStack.of(nbttagcompound.getCompound("item")); - } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/ChiseledBookShelfBlockEntity.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/ChiseledBookShelfBlockEntity.patch index 85e86180b1..449bad12a7 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/ChiseledBookShelfBlockEntity.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/ChiseledBookShelfBlockEntity.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/ChiseledBookShelfBlockEntity.java +++ b/net/minecraft/world/level/block/entity/ChiseledBookShelfBlockEntity.java -@@ -18,12 +18,54 @@ +@@ -23,12 +23,54 @@ import net.minecraft.world.level.gameevent.GameEvent; import org.slf4j.Logger; @@ -55,15 +55,7 @@ public ChiseledBookShelfBlockEntity(BlockPosition blockposition, IBlockData iblockdata) { super(TileEntityTypes.CHISELED_BOOKSHELF, blockposition, iblockdata); -@@ -52,6 +94,7 @@ - - @Override - public void load(NBTTagCompound nbttagcompound) { -+ super.load(nbttagcompound); // CraftBukkit - SPIGOT-7393: Load super Bukkit data - this.items.clear(); - ContainerUtil.loadAllItems(nbttagcompound, this.items); - this.lastInteractedSlot = nbttagcompound.getInt("last_interacted_slot"); -@@ -93,7 +136,7 @@ +@@ -100,7 +142,7 @@ this.items.set(i, ItemStack.EMPTY); if (!itemstack.isEmpty()) { @@ -72,7 +64,7 @@ } return itemstack; -@@ -108,7 +151,7 @@ +@@ -115,7 +157,7 @@ public void setItem(int i, ItemStack itemstack) { if (itemstack.is(TagsItem.BOOKSHELF_BOOKS)) { this.items.set(i, itemstack); @@ -81,7 +73,7 @@ } else if (itemstack.isEmpty()) { this.removeItem(i, 1); } -@@ -124,7 +167,7 @@ +@@ -131,7 +173,7 @@ @Override public int getMaxStackSize() { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/ContainerOpenersCounter.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/ContainerOpenersCounter.patch index dfb1293593..87d8f1a721 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/ContainerOpenersCounter.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/ContainerOpenersCounter.patch @@ -1,14 +1,14 @@ --- a/net/minecraft/world/level/block/entity/ContainerOpenersCounter.java +++ b/net/minecraft/world/level/block/entity/ContainerOpenersCounter.java -@@ -13,6 +13,7 @@ - +@@ -17,6 +17,7 @@ private static final int CHECK_TICK_DELAY = 5; private int openCount; + private double maxInteractionRange; + public boolean opened; // CraftBukkit public ContainerOpenersCounter() {} -@@ -22,11 +23,36 @@ +@@ -26,11 +27,36 @@ protected abstract void openerCountChanged(World world, BlockPosition blockposition, IBlockData iblockdata, int i, int j); @@ -44,8 +44,8 @@ + if (i == 0) { this.onOpen(world, blockposition, iblockdata); - world.gameEvent((Entity) entityhuman, GameEvent.CONTAINER_OPEN, blockposition); -@@ -37,8 +63,19 @@ + world.gameEvent((Entity) entityhuman, (Holder) GameEvent.CONTAINER_OPEN, blockposition); +@@ -42,8 +68,19 @@ } public void decrementOpeners(EntityHuman entityhuman, World world, BlockPosition blockposition, IBlockData iblockdata) { @@ -64,11 +64,11 @@ + if (this.openCount == 0) { this.onClose(world, blockposition, iblockdata); - world.gameEvent((Entity) entityhuman, GameEvent.CONTAINER_CLOSE, blockposition); -@@ -59,6 +96,7 @@ + world.gameEvent((Entity) entityhuman, (Holder) GameEvent.CONTAINER_CLOSE, blockposition); +@@ -72,6 +109,7 @@ + } - public void recheckOpeners(World world, BlockPosition blockposition, IBlockData iblockdata) { - int i = this.getOpenCount(world, blockposition); + int i = list.size(); + if (opened) i++; // CraftBukkit - add dummy count from API int j = this.openCount; diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/CrafterBlockEntity.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/CrafterBlockEntity.patch index 0968ac7fb8..90eb9c7d06 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/CrafterBlockEntity.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/CrafterBlockEntity.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/CrafterBlockEntity.java +++ b/net/minecraft/world/level/block/entity/CrafterBlockEntity.java -@@ -21,6 +21,12 @@ +@@ -23,6 +23,12 @@ import net.minecraft.world.level.block.CrafterBlock; import net.minecraft.world.level.block.state.IBlockData; @@ -13,7 +13,7 @@ public class CrafterBlockEntity extends TileEntityLootable implements InventoryCrafting { public static final int CONTAINER_WIDTH = 3; -@@ -33,6 +39,46 @@ +@@ -35,12 +41,52 @@ private NonNullList items; public int craftingTicksRemaining; protected final IContainerProperties containerData; @@ -60,3 +60,10 @@ public CrafterBlockEntity(BlockPosition blockposition, IBlockData iblockdata) { super(TileEntityTypes.CRAFTER, blockposition, iblockdata); + this.items = NonNullList.withSize(9, ItemStack.EMPTY); + this.craftingTicksRemaining = 0; +- this.containerData = new IContainerProperties(this) { ++ this.containerData = new IContainerProperties() { // CraftBukkit - decompile error + private final int[] slotStates = new int[9]; + private int triggered = 0; + diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/DecoratedPotBlockEntity.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/DecoratedPotBlockEntity.patch index 8602300644..6fdb53410b 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/DecoratedPotBlockEntity.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/DecoratedPotBlockEntity.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/level/block/entity/DecoratedPotBlockEntity.java +++ b/net/minecraft/world/level/block/entity/DecoratedPotBlockEntity.java -@@ -21,8 +21,59 @@ - import net.minecraft.world.level.block.state.properties.BlockProperties; +@@ -20,8 +20,59 @@ + import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.ticks.ContainerSingleItem; +// CraftBukkit start @@ -14,7 +14,7 @@ +import org.bukkit.entity.HumanEntity; +// CraftBukkit end + - public class DecoratedPotBlockEntity extends TileEntity implements RandomizableContainer, ContainerSingleItem { + public class DecoratedPotBlockEntity extends TileEntity implements RandomizableContainer, ContainerSingleItem.a { + // CraftBukkit start - add fields and methods + public List transaction = new ArrayList<>(); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.patch index 4044ba6f05..0068930326 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java +++ b/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java -@@ -32,14 +32,18 @@ +@@ -34,10 +34,13 @@ public SculkCatalystBlockEntity(BlockPosition blockposition, IBlockData iblockdata) { super(TileEntityTypes.SCULK_CATALYST, blockposition, iblockdata); this.catalystListener = new SculkCatalystBlockEntity.CatalystListener(iblockdata, new BlockPositionSource(blockposition)); @@ -14,12 +14,7 @@ } @Override - public void load(NBTTagCompound nbttagcompound) { -+ super.load(nbttagcompound); // CraftBukkit - SPIGOT-7393: Load super Bukkit data - this.catalystListener.sculkSpreader.load(nbttagcompound); - } - -@@ -60,11 +64,13 @@ +@@ -63,11 +66,13 @@ final SculkSpreader sculkSpreader; private final IBlockData blockState; private final PositionSource positionSource; 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 1627b9e82c..981a686764 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntity.java +++ b/net/minecraft/world/level/block/entity/TileEntity.java -@@ -15,8 +15,18 @@ +@@ -26,8 +26,18 @@ import net.minecraft.world.level.block.state.IBlockData; import org.slf4j.Logger; @@ -19,13 +19,13 @@ private static final Logger LOGGER = LogUtils.getLogger(); private final TileEntityTypes type; @Nullable -@@ -48,7 +58,16 @@ +@@ -61,7 +71,16 @@ return this.level != null; } -- public void load(NBTTagCompound nbttagcompound) {} +- protected void loadAdditional(NBTTagCompound nbttagcompound, HolderLookup.a holderlookup_a) {} + // CraftBukkit start - read container -+ public void load(NBTTagCompound nbttagcompound) { ++ protected void loadAdditional(NBTTagCompound nbttagcompound, HolderLookup.a holderlookup_a) { + this.persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY); + + net.minecraft.nbt.NBTBase persistentDataTag = nbttagcompound.get("PublicBukkitValues"); @@ -35,12 +35,12 @@ + } + // CraftBukkit end - protected void saveAdditional(NBTTagCompound nbttagcompound) {} - -@@ -70,6 +89,11 @@ - NBTTagCompound nbttagcompound = new NBTTagCompound(); - - this.saveAdditional(nbttagcompound); + public final void loadWithComponents(NBTTagCompound nbttagcompound, HolderLookup.a holderlookup_a) { + this.loadAdditional(nbttagcompound, holderlookup_a); +@@ -101,6 +120,11 @@ + }).ifPresent((nbtbase) -> { + nbttagcompound.merge((NBTTagCompound) nbtbase); + }); + // CraftBukkit start - store container + if (this.persistentDataContainer != null && !this.persistentDataContainer.isEmpty()) { + nbttagcompound.put("PublicBukkitValues", this.persistentDataContainer.toTagCompound()); @@ -49,11 +49,19 @@ return nbttagcompound; } -@@ -202,4 +226,13 @@ - public void setBlockState(IBlockData iblockdata) { - this.blockState = iblockdata; +@@ -264,7 +288,7 @@ + set.add(DataComponents.BLOCK_ENTITY_DATA); + final PatchedDataComponentMap patcheddatacomponentmap = PatchedDataComponentMap.fromPatch(datacomponentmap, datacomponentpatch); + +- this.applyImplicitComponents(new TileEntity.b(this) { ++ this.applyImplicitComponents(new TileEntity.b() { // CraftBukkit - decompile error + @Nullable + @Override + public T get(DataComponentType datacomponenttype) { +@@ -306,6 +330,15 @@ + this.components = datacomponentmap; } -+ + + // CraftBukkit start - add method + public InventoryHolder getOwner() { + if (level == null) return null; @@ -62,4 +70,7 @@ + return null; + } + // CraftBukkit end - } ++ + private static class a { + + public static final Codec COMPONENTS_CODEC = DataComponentMap.CODEC.optionalFieldOf("components", DataComponentMap.EMPTY).codec(); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBanner.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBanner.patch index af3a633df7..bacad409a1 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBanner.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBanner.patch @@ -1,14 +1,45 @@ --- a/net/minecraft/world/level/block/entity/TileEntityBanner.java +++ b/net/minecraft/world/level/block/entity/TileEntityBanner.java -@@ -102,6 +102,11 @@ +@@ -19,6 +19,10 @@ + import net.minecraft.world.level.block.state.IBlockData; + import org.slf4j.Logger; + ++// CraftBukkit start ++import java.util.List; ++// CraftBukkit end ++ + public class TileEntityBanner extends TileEntity implements INamableTileEntity { + + private static final Logger LOGGER = LogUtils.getLogger(); +@@ -80,7 +84,7 @@ + BannerPatternLayers.CODEC.parse(holderlookup_a.createSerializationContext(DynamicOpsNBT.INSTANCE), nbttagcompound.get("patterns")).resultOrPartial((s) -> { + TileEntityBanner.LOGGER.error("Failed to parse banner patterns: '{}'", s); + }).ifPresent((bannerpatternlayers) -> { +- this.patterns = bannerpatternlayers; ++ this.setPatterns(bannerpatternlayers); // CraftBukkit - apply limits + }); } - this.itemPatterns = nbttagcompound.getList("Patterns", 10); -+ // CraftBukkit start -+ while (this.itemPatterns.size() > 20) { -+ this.itemPatterns.remove(20); -+ } -+ // CraftBukkit end - this.patterns = null; +@@ -114,7 +118,7 @@ + @Override + protected void applyImplicitComponents(TileEntity.b tileentity_b) { + super.applyImplicitComponents(tileentity_b); +- this.patterns = (BannerPatternLayers) tileentity_b.getOrDefault(DataComponents.BANNER_PATTERNS, BannerPatternLayers.EMPTY); ++ this.setPatterns((BannerPatternLayers) tileentity_b.getOrDefault(DataComponents.BANNER_PATTERNS, BannerPatternLayers.EMPTY)); // CraftBukkit - apply limits + this.name = (IChatBaseComponent) tileentity_b.get(DataComponents.CUSTOM_NAME); } +@@ -130,4 +134,13 @@ + nbttagcompound.remove("patterns"); + nbttagcompound.remove("CustomName"); + } ++ ++ // CraftBukkit start ++ public void setPatterns(BannerPatternLayers bannerpatternlayers) { ++ if (bannerpatternlayers.layers().size() > 20) { ++ bannerpatternlayers = new BannerPatternLayers(List.copyOf(bannerpatternlayers.layers().subList(0, 20))); ++ } ++ this.patterns = bannerpatternlayers; ++ } ++ // CraftBukkit end + } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBarrel.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBarrel.patch index f7705b809a..0d9290ca46 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBarrel.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityBarrel.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityBarrel.java +++ b/net/minecraft/world/level/block/entity/TileEntityBarrel.java -@@ -20,8 +20,49 @@ +@@ -21,8 +21,49 @@ import net.minecraft.world.level.block.BlockBarrel; import net.minecraft.world.level.block.state.IBlockData; 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 a6a2223b39..4264f3f221 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityBeacon.java +++ b/net/minecraft/world/level/block/entity/TileEntityBeacon.java -@@ -40,6 +40,11 @@ +@@ -46,6 +46,11 @@ import net.minecraft.world.level.levelgen.HeightMap; import net.minecraft.world.phys.AxisAlignedBB; @@ -12,7 +12,7 @@ public class TileEntityBeacon extends TileEntity implements ITileInventory, INamableTileEntity { private static final int MAX_LEVELS = 4; -@@ -65,6 +70,15 @@ +@@ -71,6 +76,15 @@ public IChatBaseComponent name; public ChestLock lockKey; private final IContainerProperties dataAccess; @@ -27,20 +27,20 @@ + // CraftBukkit end @Nullable - static MobEffectList filterEffect(@Nullable MobEffectList mobeffectlist) { -@@ -245,38 +259,77 @@ + static Holder filterEffect(@Nullable Holder holder) { +@@ -251,38 +265,77 @@ super.setRemoved(); } -- private static void applyEffects(World world, BlockPosition blockposition, int i, @Nullable MobEffectList mobeffectlist, @Nullable MobEffectList mobeffectlist1) { -- if (!world.isClientSide && mobeffectlist != null) { +- private static void applyEffects(World world, BlockPosition blockposition, int i, @Nullable Holder holder, @Nullable Holder holder1) { +- if (!world.isClientSide && holder != null) { - double d0 = (double) (i * 10 + 10); + // CraftBukkit start - split into components -+ private static byte getAmplification(int i, @Nullable MobEffectList mobeffectlist, @Nullable MobEffectList mobeffectlist1) { ++ private static byte getAmplification(int i, @Nullable Holder holder, @Nullable Holder holder1) { + { byte b0 = 0; - if (i >= 4 && mobeffectlist == mobeffectlist1) { + if (i >= 4 && Objects.equals(holder, holder1)) { b0 = 1; } @@ -66,7 +66,7 @@ + } + } + -+ private static void applyEffect(List list, MobEffectList mobeffectlist, int j, int b0) { ++ private static void applyEffect(List list, @Nullable Holder holder, int j, int b0) { + { Iterator iterator = list.iterator(); @@ -74,20 +74,20 @@ while (iterator.hasNext()) { entityhuman = (EntityHuman) iterator.next(); -- entityhuman.addEffect(new MobEffect(mobeffectlist, j, b0, true, true)); -+ entityhuman.addEffect(new MobEffect(mobeffectlist, j, b0, true, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.BEACON); +- entityhuman.addEffect(new MobEffect(holder, j, b0, true, true)); ++ entityhuman.addEffect(new MobEffect(holder, j, b0, true, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.BEACON); } + } + } -+ private static boolean hasSecondaryEffect(int i, @Nullable MobEffectList mobeffectlist, @Nullable MobEffectList mobeffectlist1) { ++ private static boolean hasSecondaryEffect(int i, @Nullable Holder holder, @Nullable Holder holder1) { + { - if (i >= 4 && mobeffectlist != mobeffectlist1 && mobeffectlist1 != null) { + if (i >= 4 && !Objects.equals(holder, holder1) && holder1 != null) { - iterator = list.iterator(); - - while (iterator.hasNext()) { - entityhuman = (EntityHuman) iterator.next(); -- entityhuman.addEffect(new MobEffect(mobeffectlist1, j, 0, true, true)); +- entityhuman.addEffect(new MobEffect(holder1, j, 0, true, true)); - } + return true; } @@ -96,18 +96,18 @@ + } + } + -+ private static void applyEffects(World world, BlockPosition blockposition, int i, @Nullable MobEffectList mobeffectlist, @Nullable MobEffectList mobeffectlist1) { -+ if (!world.isClientSide && mobeffectlist != null) { ++ private static void applyEffects(World world, BlockPosition blockposition, int i, @Nullable Holder holder, @Nullable Holder holder1) { ++ if (!world.isClientSide && holder != null) { + double d0 = (double) (i * 10 + 10); -+ byte b0 = getAmplification(i, mobeffectlist, mobeffectlist1); ++ byte b0 = getAmplification(i, holder, holder1); + + int j = getLevel(i); + List list = getHumansInRange(world, blockposition, i); + -+ applyEffect(list, mobeffectlist, j, b0); ++ applyEffect(list, holder, j, b0); + -+ if (hasSecondaryEffect(i, mobeffectlist, mobeffectlist1)) { -+ applyEffect(list, mobeffectlist1, j, 0); ++ if (hasSecondaryEffect(i, holder, holder1)) { ++ applyEffect(list, holder1, j, 0); + } } + @@ -116,20 +116,20 @@ public static void playSound(World world, BlockPosition blockposition, SoundEffect soundeffect) { world.playSound((EntityHuman) null, blockposition, soundeffect, SoundCategory.BLOCKS, 1.0F, 1.0F); -@@ -312,7 +365,7 @@ +@@ -316,7 +369,7 @@ if (nbttagcompound.contains(s, 8)) { MinecraftKey minecraftkey = MinecraftKey.tryParse(nbttagcompound.getString(s)); -- return filterEffect((MobEffectList) BuiltInRegistries.MOB_EFFECT.get(minecraftkey)); -+ return (MobEffectList) BuiltInRegistries.MOB_EFFECT.get(minecraftkey); // CraftBukkit - persist manually set non-default beacon effects (SPIGOT-3598) +- 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) } else { return null; } -@@ -323,6 +376,7 @@ - super.load(nbttagcompound); +@@ -327,6 +380,7 @@ + super.loadAdditional(nbttagcompound, holderlookup_a); this.primaryPower = loadEffect(nbttagcompound, "primary_effect"); this.secondaryPower = loadEffect(nbttagcompound, "secondary_effect"); + this.levels = nbttagcompound.getInt("Levels"); // CraftBukkit - SPIGOT-5053, use where available if (nbttagcompound.contains("CustomName", 8)) { - this.name = IChatBaseComponent.ChatSerializer.fromJson(nbttagcompound.getString("CustomName")); + this.name = IChatBaseComponent.ChatSerializer.fromJson(nbttagcompound.getString("CustomName"), holderlookup_a); } 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 abde947a8a..78efcabfb7 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,8 +1,8 @@ --- a/net/minecraft/world/level/block/entity/TileEntityBeehive.java +++ b/net/minecraft/world/level/block/entity/TileEntityBeehive.java -@@ -27,6 +27,10 @@ - import net.minecraft.world.level.block.state.IBlockData; +@@ -42,6 +42,10 @@ import net.minecraft.world.level.gameevent.GameEvent; + import org.slf4j.Logger; +// CraftBukkit start +import org.bukkit.event.entity.EntityRemoveEvent; @@ -10,8 +10,8 @@ + public class TileEntityBeehive extends TileEntity { - public static final String TAG_FLOWER_POS = "FlowerPos"; -@@ -43,6 +47,7 @@ + private static final Logger LOGGER = LogUtils.getLogger(); +@@ -55,6 +59,7 @@ private final List stored = Lists.newArrayList(); @Nullable public BlockPosition savedFlowerPos; @@ -19,7 +19,7 @@ public TileEntityBeehive(BlockPosition blockposition, IBlockData iblockdata) { super(TileEntityTypes.BEEHIVE, blockposition, iblockdata); -@@ -82,7 +87,7 @@ +@@ -94,7 +99,7 @@ } public boolean isFull() { @@ -28,7 +28,7 @@ } public void emptyAllLivingFromHive(@Nullable EntityHuman entityhuman, IBlockData iblockdata, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus) { -@@ -99,7 +104,7 @@ +@@ -111,7 +116,7 @@ if (entityhuman.position().distanceToSqr(entity.position()) <= 16.0D) { if (!this.isSedated()) { @@ -37,7 +37,7 @@ } else { entitybee.setStayOutOfHiveCountdown(400); } -@@ -111,10 +116,16 @@ +@@ -123,10 +128,16 @@ } private List releaseAllOccupants(IBlockData iblockdata, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus) { @@ -49,16 +49,16 @@ List list = Lists.newArrayList(); this.stored.removeIf((tileentitybeehive_hivebee) -> { -- return releaseOccupant(this.level, this.worldPosition, iblockdata, tileentitybeehive_hivebee, list, tileentitybeehive_releasestatus, this.savedFlowerPos); -+ return releaseBee(this.level, this.worldPosition, iblockdata, tileentitybeehive_hivebee, list, tileentitybeehive_releasestatus, this.savedFlowerPos, force); +- return releaseOccupant(this.level, this.worldPosition, iblockdata, tileentitybeehive_hivebee.toOccupant(), list, tileentitybeehive_releasestatus, this.savedFlowerPos); ++ return releaseOccupant(this.level, this.worldPosition, iblockdata, tileentitybeehive_hivebee.toOccupant(), list, tileentitybeehive_releasestatus, this.savedFlowerPos, force); + // CraftBukkit end }); if (!list.isEmpty()) { super.setChanged(); -@@ -142,7 +153,19 @@ +@@ -150,7 +161,19 @@ } - public void addOccupantWithPresetTicks(Entity entity, boolean flag, int i) { + public void addOccupant(Entity entity) { - if (this.stored.size() < 3) { + if (this.stored.size() < this.maxBees) { // CraftBukkit + // CraftBukkit start @@ -75,9 +75,9 @@ + // CraftBukkit end entity.stopRiding(); entity.ejectPassengers(); - NBTTagCompound nbttagcompound = new NBTTagCompound(); -@@ -164,7 +187,7 @@ - this.level.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(entity, this.getBlockState())); + this.storeBee(TileEntityBeehive.c.of(entity)); +@@ -169,7 +192,7 @@ + this.level.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(entity, this.getBlockState())); } - entity.discard(); @@ -85,77 +85,79 @@ super.setChanged(); } } -@@ -174,7 +197,13 @@ +@@ -179,7 +202,13 @@ } - private static boolean releaseOccupant(World world, BlockPosition blockposition, IBlockData iblockdata, TileEntityBeehive.HiveBee tileentitybeehive_hivebee, @Nullable List list, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus, @Nullable BlockPosition blockposition1) { + 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) { + // CraftBukkit start - This allows us to bypass the night/rain/emergency check -+ return releaseBee(world, blockposition, iblockdata, tileentitybeehive_hivebee, list, tileentitybeehive_releasestatus, blockposition1, false); ++ return releaseOccupant(world, blockposition, iblockdata, tileentitybeehive_c, list, tileentitybeehive_releasestatus, blockposition1, false); + } + -+ private static boolean releaseBee(World world, BlockPosition blockposition, IBlockData iblockdata, TileEntityBeehive.HiveBee tileentitybeehive_hivebee, @Nullable List list, TileEntityBeehive.ReleaseStatus tileentitybeehive_releasestatus, @Nullable BlockPosition blockposition1, boolean force) { ++ 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) { + // CraftBukkit end return false; } else { - NBTTagCompound nbttagcompound = tileentitybeehive_hivebee.entityData.copy(); -@@ -197,6 +226,18 @@ - if (!entity.getType().is(TagsEntity.BEEHIVE_INHABITORS)) { - return false; - } else { -+ // CraftBukkit start -+ if (entity instanceof EntityBee) { -+ 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(); -+ double d2 = (double) blockposition.getY() + 0.5D - (double) (entity.getBbHeight() / 2.0F); -+ double d3 = (double) blockposition.getZ() + 0.5D + d0 * (double) enumdirection.getStepZ(); + EnumDirection enumdirection = (EnumDirection) iblockdata.getValue(BlockBeehive.FACING); +@@ -192,6 +221,18 @@ + Entity entity = tileentitybeehive_c.createEntity(world, blockposition); + + if (entity != null) { ++ // CraftBukkit start ++ if (entity instanceof EntityBee) { ++ 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(); ++ double d2 = (double) blockposition.getY() + 0.5D - (double) (entity.getBbHeight() / 2.0F); ++ double d3 = (double) blockposition.getZ() + 0.5D + d0 * (double) enumdirection.getStepZ(); + -+ entity.moveTo(d1, d2, d3, entity.getYRot(), entity.getXRot()); -+ } -+ if (!world.addFreshEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BEEHIVE)) return false; // CraftBukkit - SpawnReason, moved from below -+ // CraftBukkit end - if (entity instanceof EntityBee) { - EntityBee entitybee = (EntityBee) entity; ++ entity.moveTo(d1, d2, d3, entity.getYRot(), entity.getXRot()); ++ } ++ if (!world.addFreshEntity(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BEEHIVE)) return false; // CraftBukkit - SpawnReason, moved from below ++ // CraftBukkit end + if (entity instanceof EntityBee) { + EntityBee entitybee = (EntityBee) entity; -@@ -228,6 +269,7 @@ - list.add(entitybee); - } - -+ /* // CraftBukkit start - 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(); -@@ -235,11 +277,12 @@ - double d3 = (double) blockposition.getZ() + 0.5D + d0 * (double) enumdirection.getStepZ(); - - entity.moveTo(d1, d2, d3, entity.getYRot(), entity.getXRot()); -+ */ // CraftBukkit end +@@ -222,6 +263,7 @@ + list.add(entitybee); } - world.playSound((EntityHuman) null, blockposition, SoundEffects.BEEHIVE_EXIT, SoundCategory.BLOCKS, 1.0F, 1.0F); - world.gameEvent(GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(entity, world.getBlockState(blockposition))); -- return world.addFreshEntity(entity); -+ return true; // return this.world.addFreshEntity(entity); // CraftBukkit - moved up ++ /* // CraftBukkit start + 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 @@ + double d3 = (double) blockposition.getZ() + 0.5D + d0 * (double) enumdirection.getStepZ(); + + entity.moveTo(d1, d2, d3, entity.getYRot(), entity.getXRot()); ++ */ // CraftBukkit end } + + world.playSound((EntityHuman) null, blockposition, SoundEffects.BEEHIVE_EXIT, SoundCategory.BLOCKS, 1.0F, 1.0F); + world.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(entity, world.getBlockState(blockposition))); +- return world.addFreshEntity(entity); ++ return true; // return this.world.addFreshEntity(entity); // CraftBukkit - moved up } else { return false; -@@ -288,6 +331,10 @@ - if (releaseOccupant(world, blockposition, iblockdata, tileentitybeehive_hivebee, (List) null, tileentitybeehive_releasestatus, blockposition1)) { + } +@@ -258,6 +301,10 @@ + if (releaseOccupant(world, blockposition, iblockdata, tileentitybeehive_hivebee.toOccupant(), (List) null, tileentitybeehive_releasestatus, blockposition1)) { flag = true; iterator.remove(); + // CraftBukkit start + } else { -+ tileentitybeehive_hivebee.ticksInHive = tileentitybeehive_hivebee.minOccupationTicks / 2; // Not strictly Vanilla behaviour in cases where bees cannot spawn but still reasonable ++ tileentitybeehive_hivebee.ticksInHive = tileentitybeehive_hivebee.occupant.minTicksInHive / 2; // Not strictly Vanilla behaviour in cases where bees cannot spawn but still reasonable + // CraftBukkit end } } } -@@ -329,6 +376,11 @@ - this.savedFlowerPos = GameProfileSerializer.readBlockPos(nbttagcompound.getCompound("FlowerPos")); +@@ -293,7 +340,12 @@ + }); } +- this.savedFlowerPos = (BlockPosition) GameProfileSerializer.readBlockPos(nbttagcompound, "flower_pos").orElse((Object) null); ++ this.savedFlowerPos = (BlockPosition) GameProfileSerializer.readBlockPos(nbttagcompound, "flower_pos").orElse(null); // CraftBukkit - decompile error + // CraftBukkit start + if (nbttagcompound.contains("Bukkit.MaxEntities")) { + this.maxBees = nbttagcompound.getInt("Bukkit.MaxEntities"); @@ -164,11 +166,29 @@ } @Override -@@ -338,6 +390,7 @@ +@@ -303,6 +355,7 @@ if (this.hasSavedFlowerPos()) { - nbttagcompound.put("FlowerPos", GameProfileSerializer.writeBlockPos(this.savedFlowerPos)); + nbttagcompound.put("flower_pos", GameProfileSerializer.writeBlockPos(this.savedFlowerPos)); } + nbttagcompound.putInt("Bukkit.MaxEntities", this.maxBees); // CraftBukkit } +@@ -350,7 +403,7 @@ + NBTTagCompound nbttagcompound = new NBTTagCompound(); + + entity.save(nbttagcompound); +- List list = TileEntityBeehive.IGNORED_BEE_TAGS; ++ List list = TileEntityBeehive.IGNORED_BEE_TAGS; // CraftBukkit - decompile error + + Objects.requireNonNull(nbttagcompound); + list.forEach(nbttagcompound::remove); +@@ -369,7 +422,7 @@ + @Nullable + public Entity createEntity(World world, BlockPosition blockposition) { + NBTTagCompound nbttagcompound = this.entityData.copyTag(); +- List list = TileEntityBeehive.IGNORED_BEE_TAGS; ++ List list = TileEntityBeehive.IGNORED_BEE_TAGS; // CraftBukkit - decompile error + + Objects.requireNonNull(nbttagcompound); + list.forEach(nbttagcompound::remove); 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 a1524898f1..0a8a93b726 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 -@@ -25,6 +25,20 @@ +@@ -23,6 +23,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; -@@ -42,6 +56,36 @@ +@@ -40,6 +54,36 @@ private Item ingredient; public int fuel; protected final IContainerProperties dataAccess; @@ -58,7 +58,7 @@ public TileEntityBrewingStand(BlockPosition blockposition, IBlockData iblockdata) { super(TileEntityTypes.BREWING_STAND, blockposition, iblockdata); -@@ -109,8 +153,19 @@ +@@ -106,8 +150,19 @@ ItemStack itemstack = (ItemStack) tileentitybrewingstand.items.get(4); if (tileentitybrewingstand.fuel <= 0 && itemstack.is(Items.BLAZE_POWDER)) { @@ -80,7 +80,7 @@ setChanged(world, blockposition, iblockdata); } -@@ -118,12 +173,17 @@ +@@ -115,12 +170,17 @@ boolean flag1 = tileentitybrewingstand.brewTime > 0; ItemStack itemstack1 = (ItemStack) tileentitybrewingstand.items.get(3); @@ -101,7 +101,7 @@ setChanged(world, blockposition, iblockdata); } else if (!flag || !itemstack1.is(tileentitybrewingstand.ingredient)) { tileentitybrewingstand.brewTime = 0; -@@ -131,7 +191,11 @@ +@@ -128,7 +188,11 @@ } } else if (flag && tileentitybrewingstand.fuel > 0) { --tileentitybrewingstand.fuel; @@ -114,20 +114,21 @@ tileentitybrewingstand.ingredient = itemstack1.getItem(); setChanged(world, blockposition, iblockdata); } -@@ -187,11 +251,33 @@ +@@ -184,12 +248,34 @@ } } - private static void doBrew(World world, BlockPosition blockposition, NonNullList nonnulllist) { -+ // CraftBukkit start -+ private static void doBrew(World world, BlockPosition blockposition, NonNullList nonnulllist, TileEntityBrewingStand tileentitybrewingstand) { ++ private static void doBrew(World world, BlockPosition blockposition, NonNullList nonnulllist, TileEntityBrewingStand tileentitybrewingstand) { // CraftBukkit ItemStack itemstack = (ItemStack) nonnulllist.get(3); + PotionBrewer potionbrewer = world.potionBrewing(); + ++ // CraftBukkit start + InventoryHolder owner = tileentitybrewingstand.getOwner(); + List brewResults = new ArrayList<>(3); - for (int i = 0; i < 3; ++i) { -- nonnulllist.set(i, PotionBrewer.mix(itemstack, (ItemStack) nonnulllist.get(i))); -+ brewResults.add(i, CraftItemStack.asCraftMirror(PotionBrewer.mix(itemstack, (ItemStack) nonnulllist.get(i)))); +- nonnulllist.set(i, potionbrewer.mix(itemstack, (ItemStack) nonnulllist.get(i))); ++ brewResults.add(i, CraftItemStack.asCraftMirror(potionbrewer.mix(itemstack, (ItemStack) nonnulllist.get(i)))); + } + + if (owner != null) { 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 21a94892ef..e9fade9c85 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 -@@ -26,6 +26,14 @@ +@@ -31,6 +31,14 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.gameevent.GameEvent; @@ -15,7 +15,7 @@ public class TileEntityCampfire extends TileEntity implements Clearable { private static final int BURN_COOL_SPEED = 2; -@@ -60,6 +68,20 @@ +@@ -65,6 +73,20 @@ }).orElse(itemstack); if (itemstack1.isItemEnabled(world.enabledFeatures())) { @@ -36,7 +36,7 @@ InventoryUtils.dropItemStack(world, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), itemstack1); tileentitycampfire.items.set(i, ItemStack.EMPTY); world.sendBlockUpdated(blockposition, iblockdata, iblockdata, 3); -@@ -172,7 +194,11 @@ +@@ -177,7 +199,11 @@ ItemStack itemstack1 = (ItemStack) this.items.get(j); if (itemstack1.isEmpty()) { @@ -48,4 +48,4 @@ + // CraftBukkit end this.cookingProgress[j] = 0; this.items.set(j, itemstack.split(1)); - this.level.gameEvent(GameEvent.BLOCK_CHANGE, this.getBlockPos(), GameEvent.a.of(entity, this.getBlockState())); + this.level.gameEvent((Holder) GameEvent.BLOCK_CHANGE, this.getBlockPos(), GameEvent.a.of(entity, this.getBlockState())); diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityChest.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityChest.patch index 1e541199dd..328ceec04e 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityChest.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityChest.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityChest.java +++ b/net/minecraft/world/level/block/entity/TileEntityChest.java -@@ -23,6 +23,12 @@ +@@ -24,6 +24,12 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.block.state.properties.BlockPropertyChestType; @@ -13,7 +13,7 @@ public class TileEntityChest extends TileEntityLootable implements LidBlockEntity { private static final int EVENT_SET_OPEN_COUNT = 1; -@@ -30,6 +36,36 @@ +@@ -31,6 +37,36 @@ public final ContainerOpenersCounter openersCounter; private final ChestLidController chestLidController; @@ -50,7 +50,7 @@ protected TileEntityChest(TileEntityTypes tileentitytypes, BlockPosition blockposition, IBlockData iblockdata) { super(tileentitytypes, blockposition, iblockdata); this.items = NonNullList.withSize(27, ItemStack.EMPTY); -@@ -198,4 +234,11 @@ +@@ -199,4 +235,11 @@ world.blockEvent(blockposition, block, 1, j); } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityCommand.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityCommand.patch index 76aef62fa6..e664a2759c 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityCommand.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityCommand.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityCommand.java +++ b/net/minecraft/world/level/block/entity/TileEntityCommand.java -@@ -20,6 +20,13 @@ +@@ -24,6 +24,13 @@ private boolean auto; private boolean conditionMet; private final CommandBlockListenerAbstract commandBlock = new CommandBlockListenerAbstract() { 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 88ab4b1ec9..775a44667d 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,21 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityConduit.java +++ b/net/minecraft/world/level/block/entity/TileEntityConduit.java -@@ -40,11 +40,11 @@ - private float activeRotation; - private boolean isActive; - private boolean isHunting; -- private final List effectBlocks = Lists.newArrayList(); -+ public final List effectBlocks = Lists.newArrayList(); - @Nullable -- private EntityLiving destroyTarget; -+ public EntityLiving destroyTarget; - @Nullable -- private UUID destroyTargetUUID; -+ public UUID destroyTargetUUID; - private long nextAmbientSoundActivation; - - public TileEntityConduit(BlockPosition blockposition, IBlockData iblockdata) { -@@ -186,8 +186,20 @@ +@@ -187,8 +187,20 @@ } private static void applyEffects(World world, BlockPosition blockposition, List list) { @@ -36,7 +21,7 @@ int k = blockposition.getX(); int l = blockposition.getY(); int i1 = blockposition.getZ(); -@@ -201,7 +213,7 @@ +@@ -202,7 +214,7 @@ EntityHuman entityhuman = (EntityHuman) iterator.next(); if (blockposition.closerThan(entityhuman.blockPosition(), (double) j) && entityhuman.isInWaterOrRain()) { @@ -45,7 +30,7 @@ } } -@@ -209,6 +221,12 @@ +@@ -210,6 +222,12 @@ } private static void updateDestroyTarget(World world, BlockPosition blockposition, IBlockData iblockdata, List list, TileEntityConduit tileentityconduit) { @@ -58,7 +43,7 @@ EntityLiving entityliving = tileentityconduit.destroyTarget; int i = list.size(); -@@ -229,9 +247,12 @@ +@@ -230,9 +248,12 @@ tileentityconduit.destroyTarget = null; } @@ -74,12 +59,3 @@ } if (entityliving != tileentityconduit.destroyTarget) { -@@ -252,7 +273,7 @@ - - } - -- private static AxisAlignedBB getDestroyRangeAABB(BlockPosition blockposition) { -+ public static AxisAlignedBB getDestroyRangeAABB(BlockPosition blockposition) { - int i = blockposition.getX(); - int j = blockposition.getY(); - int k = blockposition.getZ(); 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 bb36a0fa74..0d23226a1b 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,9 +1,9 @@ --- a/net/minecraft/world/level/block/entity/TileEntityContainer.java +++ b/net/minecraft/world/level/block/entity/TileEntityContainer.java -@@ -89,4 +89,12 @@ +@@ -178,4 +178,12 @@ + nbttagcompound.remove("Lock"); + nbttagcompound.remove("Items"); } - - protected abstract Container createMenu(int i, PlayerInventory playerinventory); + + // CraftBukkit start + @Override diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityDispenser.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityDispenser.patch index 462f32c847..1fae288d65 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityDispenser.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityDispenser.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityDispenser.java +++ b/net/minecraft/world/level/block/entity/TileEntityDispenser.java -@@ -13,11 +13,47 @@ +@@ -14,11 +14,47 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.IBlockData; diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityEndGateway.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityEndGateway.patch index 5b24ed1a79..dc71c38831 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityEndGateway.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityEndGateway.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityEndGateway.java +++ b/net/minecraft/world/level/block/entity/TileEntityEndGateway.java -@@ -33,6 +33,15 @@ +@@ -34,6 +34,15 @@ import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; @@ -16,7 +16,7 @@ public class TileEntityEndGateway extends TileEntityEnderPortal { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -169,7 +178,7 @@ +@@ -163,7 +172,7 @@ tileentityendgateway.teleportCooldown = 100; BlockPosition blockposition1; @@ -25,7 +25,7 @@ blockposition1 = findOrCreateValidTeleportPos(worldserver, blockposition); blockposition1 = blockposition1.above(10); TileEntityEndGateway.LOGGER.debug("Creating portal at {}", blockposition1); -@@ -190,7 +199,7 @@ +@@ -184,7 +193,7 @@ if (entity2 != null) { entity1 = entity2; @@ -34,7 +34,7 @@ } else { entity1 = entity; } -@@ -198,8 +207,34 @@ +@@ -192,8 +201,34 @@ entity1 = entity.getRootVehicle(); } 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 11ce6efca2..8a5ff56834 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 -@@ -47,6 +47,21 @@ +@@ -48,6 +48,21 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.phys.Vec3D; @@ -22,7 +22,7 @@ public abstract class TileEntityFurnace extends TileEntityContainer implements IWorldInventory, RecipeCraftingHolder, AutoRecipeOutput { protected static final int SLOT_INPUT = 0; -@@ -115,7 +130,7 @@ +@@ -118,7 +133,7 @@ } }; this.recipesUsed = new Object2IntOpenHashMap(); @@ -30,9 +30,9 @@ + this.quickCheck = CraftingManager.createCheck((Recipes) recipes); // CraftBukkit - decompile error // Eclipse fail } - public static Map getFuel() { -@@ -183,6 +198,40 @@ - return map; + public static void invalidateCache() { +@@ -197,6 +212,40 @@ + } } + // CraftBukkit start - add fields and methods @@ -72,7 +72,7 @@ private static boolean isNeverAFurnaceFuel(Item item) { return item.builtInRegistryHolder().is(TagsItem.NON_FLAMMABLE_WOOD); } -@@ -271,7 +320,7 @@ +@@ -285,7 +334,7 @@ RecipeHolder recipeholder; if (flag2) { @@ -81,7 +81,7 @@ } else { recipeholder = null; } -@@ -279,9 +328,20 @@ +@@ -293,9 +342,20 @@ int i = tileentityfurnace.getMaxStackSize(); if (!tileentityfurnace.isLit() && canBurn(world.registryAccess(), recipeholder, tileentityfurnace.items, i)) { @@ -104,7 +104,7 @@ flag1 = true; if (flag3) { Item item = itemstack.getItem(); -@@ -297,11 +357,23 @@ +@@ -311,11 +371,23 @@ } if (tileentityfurnace.isLit() && canBurn(world.registryAccess(), recipeholder, tileentityfurnace.items, i)) { @@ -129,7 +129,7 @@ tileentityfurnace.setRecipeUsed(recipeholder); } -@@ -340,17 +412,44 @@ +@@ -354,17 +426,44 @@ } } @@ -167,7 +167,7 @@ + /* if (itemstack2.isEmpty()) { nonnulllist.set(2, itemstack1.copy()); - } else if (itemstack2.is(itemstack1.getItem())) { + } else if (ItemStack.isSameItemSameComponents(itemstack2, itemstack1)) { itemstack2.grow(1); } + */ @@ -175,7 +175,7 @@ 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)); -@@ -374,6 +473,7 @@ +@@ -388,6 +487,7 @@ } private static int getTotalCookTime(World world, TileEntityFurnace tileentityfurnace) { @@ -183,7 +183,7 @@ return (Integer) tileentityfurnace.quickCheck.getRecipeFor(tileentityfurnace, world).map((recipeholder) -> { return ((RecipeCooking) recipeholder.value()).getCookingTime(); }).orElse(200); -@@ -495,8 +595,8 @@ +@@ -474,8 +574,8 @@ @Override public void awardUsedRecipes(EntityHuman entityhuman, List list) {} @@ -194,7 +194,7 @@ entityplayer.awardRecipes(list); Iterator iterator = list.iterator(); -@@ -513,6 +613,12 @@ +@@ -492,6 +592,12 @@ } public List> getRecipesToAwardAndPopExperience(WorldServer worldserver, Vec3D vec3d) { @@ -207,7 +207,7 @@ List> list = Lists.newArrayList(); ObjectIterator objectiterator = this.recipesUsed.object2IntEntrySet().iterator(); -@@ -521,14 +627,14 @@ +@@ -500,14 +606,14 @@ worldserver.getRecipeManager().byKey((MinecraftKey) entry.getKey()).ifPresent((recipeholder) -> { list.add(recipeholder); @@ -224,7 +224,7 @@ int j = MathHelper.floor((float) i * f); float f1 = MathHelper.frac((float) i * f); -@@ -536,6 +642,17 @@ +@@ -515,6 +621,17 @@ ++j; } diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityHopper.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityHopper.patch index 48985e38c9..47f663cbdc 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityHopper.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityHopper.patch @@ -1,8 +1,8 @@ --- a/net/minecraft/world/level/block/entity/TileEntityHopper.java +++ b/net/minecraft/world/level/block/entity/TileEntityHopper.java -@@ -32,6 +32,22 @@ - import net.minecraft.world.phys.shapes.OperatorBoolean; - import net.minecraft.world.phys.shapes.VoxelShapes; +@@ -30,6 +30,22 @@ + import net.minecraft.world.level.block.state.IBlockData; + import net.minecraft.world.phys.AxisAlignedBB; +// CraftBukkit start +import net.minecraft.world.InventoryLargeChest; @@ -24,8 +24,8 @@ public static final int MOVE_ITEM_SPEED = 8; @@ -40,6 +56,36 @@ - private int cooldownTime; private long tickedGameTime; + private EnumDirection facing; + // CraftBukkit start - add fields and methods + public List transaction = new java.util.ArrayList(); @@ -60,62 +60,41 @@ public TileEntityHopper(BlockPosition blockposition, IBlockData iblockdata) { super(TileEntityTypes.HOPPER, blockposition, iblockdata); this.items = NonNullList.withSize(5, ItemStack.EMPTY); -@@ -113,7 +159,7 @@ - boolean flag = false; +@@ -167,7 +213,28 @@ - if (!tileentityhopper.isEmpty()) { -- flag = ejectItems(world, blockposition, iblockdata, tileentityhopper); -+ flag = ejectItems(world, blockposition, iblockdata, (IInventory) tileentityhopper, tileentityhopper); // CraftBukkit - } - - if (!tileentityhopper.inventoryFull()) { -@@ -147,7 +193,7 @@ - return false; - } - -- private static boolean ejectItems(World world, BlockPosition blockposition, IBlockData iblockdata, IInventory iinventory) { -+ private static boolean ejectItems(World world, BlockPosition blockposition, IBlockData iblockdata, IInventory iinventory, TileEntityHopper hopper) { // CraftBukkit - IInventory iinventory1 = getAttachedContainer(world, blockposition, iblockdata); - - if (iinventory1 == null) { -@@ -161,7 +207,30 @@ - for (int i = 0; i < iinventory.getContainerSize(); ++i) { - if (!iinventory.getItem(i).isEmpty()) { - ItemStack itemstack = iinventory.getItem(i).copy(); -- ItemStack itemstack1 = addItem(iinventory, iinventory1, iinventory.removeItem(i, 1), enumdirection); -+ // ItemStack itemstack1 = addItem(iinventory, iinventory1, iinventory.removeItem(i, 1), enumdirection); -+ + if (!itemstack.isEmpty()) { + int j = itemstack.getCount(); +- ItemStack itemstack1 = addItem(tileentityhopper, iinventory, tileentityhopper.removeItem(i, 1), enumdirection); + // CraftBukkit start - Call event when pushing items into other inventories -+ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(iinventory.removeItem(i, 1)); ++ CraftItemStack oitemstack = CraftItemStack.asCraftMirror(tileentityhopper.removeItem(i, 1)); + + Inventory destinationInventory; + // Have to special case large chests as they work oddly -+ if (iinventory1 instanceof InventoryLargeChest) { -+ destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) iinventory1); -+ } else if (iinventory1.getOwner() != null) { -+ destinationInventory = iinventory1.getOwner().getInventory(); ++ if (iinventory instanceof InventoryLargeChest) { ++ destinationInventory = new org.bukkit.craftbukkit.inventory.CraftInventoryDoubleChest((InventoryLargeChest) iinventory); ++ } else if (iinventory.getOwner() != null) { ++ destinationInventory = iinventory.getOwner().getInventory(); + } else { + destinationInventory = new CraftInventory(iinventory); + } + -+ InventoryMoveItemEvent event = new InventoryMoveItemEvent(iinventory.getOwner().getInventory(), oitemstack.clone(), destinationInventory, true); ++ InventoryMoveItemEvent event = new InventoryMoveItemEvent(iinventory.getOwner().getInventory(), oitemstack, destinationInventory, true); + world.getCraftServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { -+ hopper.setItem(i, itemstack); -+ hopper.setCooldown(8); // Delay hopper checks ++ tileentityhopper.setItem(i, itemstack); ++ tileentityhopper.setCooldown(8); // Delay hopper checks + return false; + } -+ ItemStack itemstack1 = addItem(iinventory, iinventory1, CraftItemStack.asNMSCopy(event.getItem()), enumdirection); ++ ItemStack itemstack1 = addItem(tileentityhopper, iinventory, CraftItemStack.asNMSCopy(event.getItem()), enumdirection); + // CraftBukkit end if (itemstack1.isEmpty()) { - iinventory1.setChanged(); -@@ -226,7 +295,34 @@ + iinventory.setChanged(); +@@ -279,7 +346,33 @@ if (!itemstack.isEmpty() && canTakeItemFromContainer(ihopper, iinventory, itemstack, i, enumdirection)) { - ItemStack itemstack1 = itemstack.copy(); -- ItemStack itemstack2 = addItem(iinventory, ihopper, iinventory.removeItem(i, 1), (EnumDirection) null); -+ // ItemStack itemstack2 = addItem(iinventory, ihopper, iinventory.removeItem(i, 1), (EnumDirection) null); + int j = itemstack.getCount(); +- ItemStack itemstack1 = addItem(iinventory, ihopper, iinventory.removeItem(i, 1), (EnumDirection) null); + // CraftBukkit start - Call event on collection of items from inventories into the hopper + CraftItemStack oitemstack = CraftItemStack.asCraftMirror(iinventory.removeItem(i, 1)); + @@ -129,11 +108,11 @@ + sourceInventory = new CraftInventory(iinventory); + } + -+ InventoryMoveItemEvent event = new InventoryMoveItemEvent(sourceInventory, oitemstack.clone(), ihopper.getOwner().getInventory(), false); ++ InventoryMoveItemEvent event = new InventoryMoveItemEvent(sourceInventory, oitemstack, ihopper.getOwner().getInventory(), false); + + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { -+ iinventory.setItem(i, itemstack1); ++ iinventory.setItem(i, itemstack); + + if (ihopper instanceof TileEntityHopper) { + ((TileEntityHopper) ihopper).setCooldown(8); // Delay hopper checks @@ -141,12 +120,12 @@ + + return false; + } -+ ItemStack itemstack2 = addItem(iinventory, ihopper, CraftItemStack.asNMSCopy(event.getItem()), null); ++ ItemStack itemstack1 = addItem(iinventory, ihopper, CraftItemStack.asNMSCopy(event.getItem()), null); + // CraftBukkit end - if (itemstack2.isEmpty()) { + if (itemstack1.isEmpty()) { iinventory.setChanged(); -@@ -241,13 +337,20 @@ +@@ -297,13 +390,20 @@ public static boolean addItem(IInventory iinventory, EntityItem entityitem) { boolean flag = false; @@ -168,7 +147,7 @@ } else { entityitem.setItem(itemstack1); } -@@ -367,16 +470,40 @@ +@@ -421,14 +521,38 @@ return itemstack; } @@ -183,13 +162,11 @@ + // CraftBukkit end + @Nullable - private static IInventory getAttachedContainer(World world, BlockPosition blockposition, IBlockData iblockdata) { - EnumDirection enumdirection = (EnumDirection) iblockdata.getValue(BlockHopper.FACING); - -- return getContainerAt(world, blockposition.relative(enumdirection)); + private static IInventory getAttachedContainer(World world, BlockPosition blockposition, TileEntityHopper tileentityhopper) { +- return getContainerAt(world, blockposition.relative(tileentityhopper.facing)); + // CraftBukkit start -+ BlockPosition searchPosition = blockposition.relative(enumdirection); -+ IInventory inventory = getContainerAt(world, blockposition.relative(enumdirection)); ++ BlockPosition searchPosition = blockposition.relative(tileentityhopper.facing); ++ IInventory inventory = getContainerAt(world, searchPosition); + + CraftBlock hopper = CraftBlock.at(world, blockposition); + CraftBlock searchBlock = CraftBlock.at(world, searchPosition); @@ -198,10 +175,10 @@ } @Nullable - private static IInventory getSourceContainer(World world, IHopper ihopper) { -- return getContainerAt(world, ihopper.getLevelX(), ihopper.getLevelY() + 1.0D, ihopper.getLevelZ()); + private static IInventory getSourceContainer(World world, IHopper ihopper, BlockPosition blockposition, IBlockData iblockdata) { +- return getContainerAt(world, blockposition, iblockdata, ihopper.getLevelX(), ihopper.getLevelY() + 1.0D, ihopper.getLevelZ()); + // CraftBukkit start -+ IInventory inventory = getContainerAt(world, ihopper.getLevelX(), ihopper.getLevelY() + 1.0D, ihopper.getLevelZ()); ++ IInventory inventory = getContainerAt(world, blockposition, iblockdata, ihopper.getLevelX(), ihopper.getLevelY() + 1.0D, ihopper.getLevelZ()); + + BlockPosition blockPosition = BlockPosition.containing(ihopper.getLevelX(), ihopper.getLevelY(), ihopper.getLevelZ()); + CraftBlock hopper = CraftBlock.at(world, blockPosition); 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 9276a5ca06..b9973d9112 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 -@@ -22,6 +22,14 @@ +@@ -24,6 +24,14 @@ import net.minecraft.world.phys.Vec3D; import net.minecraft.world.ticks.ContainerSingleItem; @@ -12,10 +12,10 @@ +import org.bukkit.entity.HumanEntity; +// CraftBukkit end + - public class TileEntityJukeBox extends TileEntity implements Clearable, ContainerSingleItem { + public class TileEntityJukeBox extends TileEntity implements Clearable, ContainerSingleItem.a { private static final int SONG_END_PADDING = 20; -@@ -30,6 +38,42 @@ +@@ -32,6 +40,42 @@ public long tickCount; public long recordStartedTick; public boolean isPlaying; @@ -58,7 +58,7 @@ public TileEntityJukeBox(BlockPosition blockposition, IBlockData iblockdata) { super(TileEntityTypes.JUKEBOX, blockposition, iblockdata); -@@ -150,7 +194,7 @@ +@@ -154,7 +198,7 @@ @Override public int getMaxStackSize() { @@ -67,7 +67,7 @@ } @Override -@@ -203,7 +247,11 @@ +@@ -206,7 +250,11 @@ @VisibleForTesting public void setRecordWithoutPlaying(ItemStack itemstack) { this.item = itemstack; 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 f74e6f4cca..de231effe2 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityLectern.java +++ b/net/minecraft/world/level/block/entity/TileEntityLectern.java -@@ -25,13 +25,72 @@ +@@ -29,13 +29,72 @@ import net.minecraft.world.phys.Vec2F; import net.minecraft.world.phys.Vec3D; @@ -75,7 +75,7 @@ @Override public int getContainerSize() { return 1; -@@ -76,11 +135,20 @@ +@@ -80,11 +139,20 @@ } @Override @@ -98,7 +98,7 @@ } @Override -@@ -160,7 +228,7 @@ +@@ -164,7 +232,7 @@ if (j != this.page) { this.page = j; this.setChanged(); @@ -107,7 +107,7 @@ } } -@@ -183,6 +251,32 @@ +@@ -187,6 +255,32 @@ return itemstack; } @@ -140,7 +140,7 @@ private CommandListenerWrapper createCommandSourceStack(@Nullable EntityHuman entityhuman) { String s; Object object; -@@ -197,7 +291,8 @@ +@@ -201,7 +295,8 @@ Vec3D vec3d = Vec3D.atCenterOf(this.worldPosition); @@ -150,7 +150,7 @@ } @Override -@@ -235,7 +330,7 @@ +@@ -239,7 +334,7 @@ @Override public Container createMenu(int i, PlayerInventory playerinventory, EntityHuman entityhuman) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityShulkerBox.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityShulkerBox.patch index 56eb39fb56..971f7399e7 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityShulkerBox.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntityShulkerBox.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntityShulkerBox.java +++ b/net/minecraft/world/level/block/entity/TileEntityShulkerBox.java -@@ -32,6 +32,11 @@ +@@ -34,6 +34,11 @@ import net.minecraft.world.phys.AxisAlignedBB; import net.minecraft.world.phys.Vec3D; @@ -12,7 +12,7 @@ public class TileEntityShulkerBox extends TileEntityLootable implements IWorldInventory { public static final int COLUMNS = 9; -@@ -51,6 +56,37 @@ +@@ -52,6 +57,37 @@ @Nullable private final EnumColor color; @@ -50,19 +50,19 @@ public TileEntityShulkerBox(@Nullable EnumColor enumcolor, BlockPosition blockposition, IBlockData iblockdata) { super(TileEntityTypes.SHULKER_BOX, blockposition, iblockdata); this.itemStacks = NonNullList.withSize(27, ItemStack.EMPTY); -@@ -172,6 +208,7 @@ +@@ -173,6 +209,7 @@ } ++this.openCount; + if (opened) return; // CraftBukkit - only animate if the ShulkerBox hasn't been forced open already by an API call. this.level.blockEvent(this.worldPosition, this.getBlockState().getBlock(), 1, this.openCount); if (this.openCount == 1) { - this.level.gameEvent((Entity) entityhuman, GameEvent.CONTAINER_OPEN, this.worldPosition); -@@ -185,6 +222,7 @@ + this.level.gameEvent((Entity) entityhuman, (Holder) GameEvent.CONTAINER_OPEN, this.worldPosition); +@@ -186,6 +223,7 @@ public void stopOpen(EntityHuman entityhuman) { if (!this.remove && !entityhuman.isSpectator()) { --this.openCount; + if (opened) return; // CraftBukkit - only animate if the ShulkerBox hasn't been forced open already by an API call. this.level.blockEvent(this.worldPosition, this.getBlockState().getBlock(), 1, this.openCount); if (this.openCount <= 0) { - this.level.gameEvent((Entity) entityhuman, GameEvent.CONTAINER_CLOSE, this.worldPosition); + this.level.gameEvent((Entity) entityhuman, (Holder) GameEvent.CONTAINER_CLOSE, this.worldPosition); 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 84e9fa6536..933fece896 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,6 +1,6 @@ --- a/net/minecraft/world/level/block/entity/TileEntitySign.java +++ b/net/minecraft/world/level/block/entity/TileEntitySign.java -@@ -33,7 +33,17 @@ +@@ -36,7 +36,17 @@ import net.minecraft.world.phys.Vec3D; import org.slf4j.Logger; @@ -19,25 +19,25 @@ private static final Logger LOGGER = LogUtils.getLogger(); private static final int MAX_TEXT_LINE_WIDTH = 90; -@@ -98,7 +108,7 @@ - @Override - protected void saveAdditional(NBTTagCompound nbttagcompound) { - super.saveAdditional(nbttagcompound); -- DataResult dataresult = SignText.DIRECT_CODEC.encodeStart(DynamicOpsNBT.INSTANCE, this.frontText); -+ DataResult dataresult = SignText.DIRECT_CODEC.encodeStart(DynamicOpsNBT.INSTANCE, this.frontText); // CraftBukkit - decompile error +@@ -101,7 +111,7 @@ + protected void saveAdditional(NBTTagCompound nbttagcompound, HolderLookup.a holderlookup_a) { + super.saveAdditional(nbttagcompound, holderlookup_a); + DynamicOps dynamicops = holderlookup_a.createSerializationContext(DynamicOpsNBT.INSTANCE); +- DataResult dataresult = SignText.DIRECT_CODEC.encodeStart(dynamicops, this.frontText); ++ DataResult dataresult = SignText.DIRECT_CODEC.encodeStart(dynamicops, this.frontText); // CraftBukkit - decompile error Logger logger = TileEntitySign.LOGGER; Objects.requireNonNull(logger); -@@ -117,7 +127,7 @@ - @Override - public void load(NBTTagCompound nbttagcompound) { - super.load(nbttagcompound); +@@ -121,7 +131,7 @@ + protected void loadAdditional(NBTTagCompound nbttagcompound, HolderLookup.a holderlookup_a) { + super.loadAdditional(nbttagcompound, holderlookup_a); + DynamicOps dynamicops = holderlookup_a.createSerializationContext(DynamicOpsNBT.INSTANCE); - DataResult dataresult; + DataResult dataresult; // CraftBukkit - decompile error Logger logger; if (nbttagcompound.contains("front_text")) { -@@ -171,12 +181,13 @@ +@@ -173,12 +183,13 @@ public void updateSignText(EntityHuman entityhuman, boolean flag, List list) { if (!this.isWaxed() && entityhuman.getUUID().equals(this.getPlayerWhoMayEdit()) && this.level != null) { this.updateText((signtext) -> { @@ -52,7 +52,7 @@ } } -@@ -186,7 +197,8 @@ +@@ -188,7 +199,8 @@ return this.setText((SignText) unaryoperator.apply(signtext), flag); } @@ -62,7 +62,7 @@ for (int i = 0; i < list.size(); ++i) { FilteredText filteredtext = (FilteredText) list.get(i); ChatModifier chatmodifier = signtext.getMessage(i, entityhuman.isTextFilteringEnabled()).getStyle(); -@@ -198,6 +210,29 @@ +@@ -200,6 +212,29 @@ } } @@ -92,7 +92,7 @@ return signtext; } -@@ -248,11 +283,37 @@ +@@ -250,11 +285,37 @@ return flag1; } @@ -132,7 +132,7 @@ } @Override -@@ -276,12 +337,17 @@ +@@ -278,12 +339,17 @@ @Nullable public UUID getPlayerWhoMayEdit() { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntitySkull.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntitySkull.patch deleted file mode 100644 index 7da68fc7be..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/TileEntitySkull.patch +++ /dev/null @@ -1,19 +0,0 @@ ---- a/net/minecraft/world/level/block/entity/TileEntitySkull.java -+++ b/net/minecraft/world/level/block/entity/TileEntitySkull.java -@@ -194,6 +194,16 @@ - - if (!SystemUtils.isBlank(s)) { - resolveGameProfile(nbttagcompound, s); -+ // CraftBukkit start -+ } else { -+ net.minecraft.nbt.NBTTagList textures = nbttagcompound.getCompound("SkullOwner").getCompound("Properties").getList("textures", 10); // Safe due to method contracts -+ for (int i = 0; i < textures.size(); i++) { -+ if (textures.get(i) instanceof NBTTagCompound && !((NBTTagCompound) textures.get(i)).contains("Signature", 8) && ((NBTTagCompound) textures.get(i)).getString("Value").trim().isEmpty()) { -+ nbttagcompound.remove("SkullOwner"); -+ break; -+ } -+ } -+ // CraftBukkit end - } - - } 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 new file mode 100644 index 0000000000..fba8790203 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerData.patch @@ -0,0 +1,18 @@ +--- a/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerData.java ++++ b/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerData.java +@@ -179,13 +179,13 @@ + } + + public void resetAfterBecomingOminous(TrialSpawner trialspawner, WorldServer worldserver) { +- Stream stream = this.currentMobs.stream(); ++ Stream stream = this.currentMobs.stream(); // CraftBukkit - decompile error + + Objects.requireNonNull(worldserver); + stream.map(worldserver::getEntity).forEach((entity) -> { + if (entity != null) { + worldserver.levelEvent(3012, entity.blockPosition(), TrialSpawner.a.NORMAL.encode()); +- entity.remove(Entity.RemovalReason.DISCARDED); ++ entity.remove(Entity.RemovalReason.DISCARDED, org.bukkit.event.entity.EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - Add bukkit remove cause; + } + }); + if (!trialspawner.getOminousConfig().spawnPotentialsDefinition().isEmpty()) { 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 ee456896d2..cfdcb85f8a 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/block/grower/WorldGenTreeProvider.java +++ b/net/minecraft/world/level/block/grower/WorldGenTreeProvider.java -@@ -25,6 +25,12 @@ +@@ -24,6 +24,12 @@ import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.levelgen.feature.WorldGenFeatureConfigured; @@ -13,7 +13,7 @@ public final class WorldGenTreeProvider { private static final Map GROWERS = new Object2ObjectArrayMap(); -@@ -75,21 +81,22 @@ +@@ -74,21 +80,22 @@ } } @@ -39,7 +39,7 @@ for (int i = 0; i >= -1; --i) { for (int j = 0; j >= -1; --j) { if (isTwoByTwoSapling(iblockdata, worldserver, blockposition, i, j)) { -@@ -120,11 +127,12 @@ +@@ -119,11 +126,12 @@ if (resourcekey1 == null) { return false; } else { @@ -53,7 +53,7 @@ WorldGenFeatureConfigured worldgenfeatureconfigured1 = (WorldGenFeatureConfigured) holder1.value(); IBlockData iblockdata2 = worldserver.getFluidState(blockposition).createLegacyBlock(); -@@ -165,11 +173,62 @@ +@@ -164,11 +172,62 @@ return true; } @@ -117,4 +117,4 @@ + Map map = WorldGenTreeProvider.GROWERS; // CraftBukkit - decompile error Objects.requireNonNull(map); - CODEC = ExtraCodecs.stringResolverCodec(function, map::get); + CODEC = Codec.stringResolver(function, map::get); 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 779c46db5c..ca610a7bc5 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 -@@ -41,6 +41,14 @@ +@@ -42,6 +42,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) -> { -@@ -151,6 +159,18 @@ +@@ -152,6 +160,18 @@ } } @@ -34,7 +34,7 @@ world.blockEvent(blockposition, this, b0, enumdirection.get3DDataValue()); } -@@ -331,6 +351,48 @@ +@@ -332,6 +352,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 9bc9a05b7f..f0e7da3a91 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,6 +1,6 @@ --- a/net/minecraft/world/level/block/state/BlockBase.java +++ b/net/minecraft/world/level/block/state/BlockBase.java -@@ -188,8 +188,10 @@ +@@ -174,8 +174,10 @@ TileEntity tileentity = iblockdata.hasBlockEntity() ? world.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()); 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 a09e16522b..7f74b40da0 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 -@@ -75,7 +75,7 @@ +@@ -77,7 +77,7 @@ }; private final Map tickersInLevel; public boolean loaded; @@ -9,7 +9,7 @@ @Nullable private Supplier fullStatus; @Nullable -@@ -91,7 +91,7 @@ +@@ -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); this.tickersInLevel = Maps.newHashMap(); @@ -18,7 +18,7 @@ this.gameEventListenerRegistrySections = new Int2ObjectOpenHashMap(); HeightMap.Type[] aheightmap_type = HeightMap.Type.values(); int j = aheightmap_type.length; -@@ -109,6 +109,11 @@ +@@ -111,6 +111,11 @@ this.fluidTicks = levelchunkticks1; } @@ -30,7 +30,7 @@ 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(); -@@ -140,6 +145,10 @@ +@@ -142,6 +147,10 @@ this.skyLightSources = protochunk.skyLightSources; this.setLightCorrect(protochunk.isLightCorrect()); this.unsaved = true; @@ -167,7 +167,7 @@ public boolean isEmpty() { return false; } -@@ -697,7 +783,7 @@ +@@ -695,7 +781,7 @@ private void updateBlockEntityTicker(T t0) { IBlockData iblockdata = t0.getBlockState(); @@ -176,10 +176,10 @@ if (blockentityticker == null) { this.removeBlockEntityTicker(t0.getBlockPos()); -@@ -782,7 +868,7 @@ +@@ -780,7 +866,7 @@ private boolean loggedInvalidBlockState; - a(TileEntity tileentity, BlockEntityTicker blockentityticker) { + a(final TileEntity tileentity, final BlockEntityTicker blockentityticker) { - this.blockEntity = tileentity; + this.blockEntity = (T) tileentity; // CraftBukkit - decompile error this.ticker = blockentityticker; diff --git a/paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkGenerator.patch b/paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkGenerator.patch index 6de6d4f19a..f4e11018ae 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkGenerator.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkGenerator.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/chunk/ChunkGenerator.java +++ b/net/minecraft/world/level/chunk/ChunkGenerator.java -@@ -306,7 +306,7 @@ +@@ -312,7 +312,7 @@ } } @@ -9,7 +9,7 @@ ChunkCoordIntPair chunkcoordintpair = ichunkaccess.getPos(); if (!SharedConstants.debugVoidTerrain(chunkcoordintpair)) { -@@ -328,7 +328,7 @@ +@@ -334,7 +334,7 @@ for (int k = 0; k < j; ++k) { ChunkSection chunksection = achunksection[k]; @@ -18,16 +18,7 @@ Objects.requireNonNull(set); palettedcontainerro.getAll(set::add); -@@ -354,7 +354,7 @@ - Structure structure = (Structure) iterator.next(); - - seededrandom.setFeatureSeed(i, i1, l); -- Supplier supplier = () -> { -+ Supplier supplier = () -> { // CraftBukkit - decompile error - Optional optional = iregistry.getResourceKey(structure).map(Object::toString); - - Objects.requireNonNull(structure); -@@ -439,6 +439,33 @@ +@@ -445,6 +445,33 @@ } } @@ -61,7 +52,7 @@ private static StructureBoundingBox getWritableArea(IChunkAccess ichunkaccess) { ChunkCoordIntPair chunkcoordintpair = ichunkaccess.getPos(); int i = chunkcoordintpair.getMinBlockX(); -@@ -576,6 +603,14 @@ +@@ -582,6 +609,14 @@ StructureStart structurestart = structure.generate(iregistrycustom, this, this.biomeSource, randomstate, structuretemplatemanager, i, chunkcoordintpair, j, ichunkaccess, predicate); if (structurestart.isValid()) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkStatus.patch b/paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkStatus.patch deleted file mode 100644 index b06192ac5d..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/level/chunk/ChunkStatus.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/net/minecraft/world/level/chunk/ChunkStatus.java -+++ b/net/minecraft/world/level/chunk/ChunkStatus.java -@@ -39,7 +39,7 @@ - public static final ChunkStatus EMPTY = registerSimple("empty", (ChunkStatus) null, -1, ChunkStatus.PRE_FEATURES, ChunkStatus.Type.PROTOCHUNK, (chunkstatus, worldserver, chunkgenerator, list, ichunkaccess) -> { - }); - public static final ChunkStatus STRUCTURE_STARTS = register("structure_starts", ChunkStatus.EMPTY, 0, false, ChunkStatus.PRE_FEATURES, ChunkStatus.Type.PROTOCHUNK, (chunkstatus, executor, worldserver, chunkgenerator, structuretemplatemanager, lightenginethreaded, function, list, ichunkaccess) -> { -- if (worldserver.getServer().getWorldData().worldGenOptions().generateStructures()) { -+ if (worldserver.serverLevelData.worldGenOptions().generateStructures()) { // CraftBukkit - chunkgenerator.createStructures(worldserver.registryAccess(), worldserver.getChunkSource().getGeneratorState(), worldserver.structureManager(), ichunkaccess, structuretemplatemanager); - } - 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 ef98585d46..489886dea0 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/chunk/IChunkAccess.java +++ b/net/minecraft/world/level/chunk/IChunkAccess.java -@@ -82,6 +82,11 @@ +@@ -85,6 +85,11 @@ protected final LevelHeightAccessor levelHeightAccessor; protected final ChunkSection[] sections; @@ -12,7 +12,7 @@ public IChunkAccess(ChunkCoordIntPair chunkcoordintpair, ChunkConverter chunkconverter, LevelHeightAccessor levelheightaccessor, IRegistry iregistry, long i, @Nullable ChunkSection[] achunksection, @Nullable BlendingData blendingdata) { this.chunkPos = chunkcoordintpair; this.upgradeData = chunkconverter; -@@ -100,7 +105,11 @@ +@@ -103,7 +108,11 @@ } replaceMissingSections(iregistry, this.sections); @@ -24,7 +24,7 @@ private static void replaceMissingSections(IRegistry iregistry, ChunkSection[] achunksection) { for (int i = 0; i < achunksection.length; ++i) { -@@ -263,10 +272,11 @@ +@@ -266,10 +275,11 @@ public void setUnsaved(boolean flag) { this.unsaved = flag; @@ -37,7 +37,7 @@ } public abstract ChunkStatus getStatus(); -@@ -442,6 +452,27 @@ +@@ -445,6 +455,27 @@ } } 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 new file mode 100644 index 0000000000..e86d6a481a --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/level/chunk/status/ChunkStatusTasks.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java ++++ b/net/minecraft/world/level/chunk/status/ChunkStatusTasks.java +@@ -33,7 +33,7 @@ + static CompletableFuture generateStructureStarts(WorldGenContext worldgencontext, ChunkStatus chunkstatus, Executor executor, ToFullChunk tofullchunk, List list, IChunkAccess ichunkaccess) { + WorldServer worldserver = worldgencontext.level(); + +- if (worldserver.getServer().getWorldData().worldGenOptions().generateStructures()) { ++ if (worldserver.serverLevelData.worldGenOptions().generateStructures()) { // CraftBukkit + worldgencontext.generator().createStructures(worldserver.registryAccess(), worldserver.getChunkSource().getGeneratorState(), worldserver.structureManager(), ichunkaccess, worldgencontext.structureManager()); + } + 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 index e9f8d82802..c043f5abf7 100644 --- 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/chunk/storage/ChunkRegionLoader.java +++ b/net/minecraft/world/level/chunk/storage/ChunkRegionLoader.java -@@ -102,7 +102,7 @@ +@@ -104,7 +104,7 @@ ChunkProviderServer chunkproviderserver = worldserver.getChunkSource(); LevelLightEngine levellightengine = chunkproviderserver.getLightEngine(); IRegistry iregistry = worldserver.registryAccess().registryOrThrow(Registries.BIOME); @@ -8,14 +8,8 @@ + Codec>> codec = makeBiomeCodecRW(iregistry); // CraftBukkit - read/write boolean flag2 = false; - DataResult dataresult; -@@ -122,12 +122,12 @@ - }); - logger = ChunkRegionLoader.LOGGER; - Objects.requireNonNull(logger); -- datapaletteblock = (DataPaletteBlock) dataresult.getOrThrow(false, logger::error); -+ datapaletteblock = (DataPaletteBlock) ((DataResult>) dataresult).getOrThrow(false, logger::error); // CraftBukkit - decompile error - } else { + for (int j = 0; j < nbttaglist.size(); ++j) { +@@ -123,17 +123,17 @@ datapaletteblock = new DataPaletteBlock<>(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), DataPaletteBlock.d.SECTION_STATES); } @@ -23,13 +17,10 @@ + DataPaletteBlock object; // CraftBukkit - read/write if (nbttagcompound1.contains("biomes", 10)) { - dataresult = codec.parse(DynamicOpsNBT.INSTANCE, nbttagcompound1.getCompound("biomes")).promotePartial((s) -> { -@@ -135,12 +135,12 @@ - }); - logger = ChunkRegionLoader.LOGGER; - Objects.requireNonNull(logger); -- object = (PalettedContainerRO) dataresult.getOrThrow(false, logger::error); -+ object = ((DataResult>>) dataresult).getOrThrow(false, logger::error); // CraftBukkit - decompile error +- 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); } @@ -39,25 +30,25 @@ achunksection[k] = chunksection; SectionPosition sectionposition = SectionPosition.of(chunkcoordintpair, b0); -@@ -176,7 +176,7 @@ +@@ -170,7 +170,7 @@ dataresult = BlendingData.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.getCompound("blending_data"))); - logger1 = ChunkRegionLoader.LOGGER; - Objects.requireNonNull(logger1); -- blendingdata = (BlendingData) dataresult.resultOrPartial(logger1::error).orElse((Object) null); -+ blendingdata = (BlendingData) ((DataResult) dataresult).resultOrPartial(logger1::error).orElse(null); // CraftBukkit - decompile error + 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; } -@@ -207,7 +207,7 @@ +@@ -201,7 +201,7 @@ dataresult = BelowZeroRetrogen.CODEC.parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.getCompound("below_zero_retrogen"))); - logger1 = ChunkRegionLoader.LOGGER; - Objects.requireNonNull(logger1); -- Optional optional = dataresult.resultOrPartial(logger1::error); -+ Optional optional = ((DataResult) dataresult).resultOrPartial(logger1::error); // CraftBukkit - decompile error + 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); -@@ -221,6 +221,13 @@ +@@ -215,6 +215,13 @@ } } @@ -71,7 +62,7 @@ ((IChunkAccess) object1).setLightCorrect(flag); NBTTagCompound nbttagcompound2 = nbttagcompound.getCompound("Heightmaps"); EnumSet enumset = EnumSet.noneOf(HeightMap.Type.class); -@@ -300,6 +307,12 @@ +@@ -294,6 +301,12 @@ return DataPaletteBlock.codecRO(iregistry.asHolderIdMap(), iregistry.holderByNameCodec(), DataPaletteBlock.d.SECTION_BIOMES, iregistry.getHolderOrThrow(Biomes.PLAINS)); } @@ -84,7 +75,7 @@ public static NBTTagCompound write(WorldServer worldserver, IChunkAccess ichunkaccess) { ChunkCoordIntPair chunkcoordintpair = ichunkaccess.getPos(); NBTTagCompound nbttagcompound = GameProfileSerializer.addCurrentDataVersion(new NBTTagCompound()); -@@ -311,7 +324,7 @@ +@@ -305,7 +318,7 @@ nbttagcompound.putLong("InhabitedTime", ichunkaccess.getInhabitedTime()); nbttagcompound.putString("Status", BuiltInRegistries.CHUNK_STATUS.getKey(ichunkaccess.getStatus()).toString()); BlendingData blendingdata = ichunkaccess.getBlendingData(); @@ -93,16 +84,7 @@ Logger logger; if (blendingdata != null) { -@@ -358,7 +371,7 @@ - - if (flag1) { - ChunkSection chunksection = achunksection[j]; -- DataResult dataresult1 = ChunkRegionLoader.BLOCK_STATE_CODEC.encodeStart(DynamicOpsNBT.INSTANCE, chunksection.getStates()); -+ DataResult dataresult1 = ChunkRegionLoader.BLOCK_STATE_CODEC.encodeStart(DynamicOpsNBT.INSTANCE, chunksection.getStates()); // CraftBukkit - decompile error - Logger logger1 = ChunkRegionLoader.LOGGER; - - Objects.requireNonNull(logger1); -@@ -441,6 +454,11 @@ +@@ -429,6 +442,11 @@ nbttagcompound.put("Heightmaps", nbttagcompound3); nbttagcompound.put("structures", packStructureData(StructurePieceSerializationContext.fromLevel(worldserver), chunkcoordintpair, ichunkaccess.getAllStarts(), ichunkaccess.getAllReferences())); @@ -114,7 +96,7 @@ return nbttagcompound; } -@@ -545,6 +563,12 @@ +@@ -533,6 +551,12 @@ StructureStart structurestart = StructureStart.loadStaticStart(structurepieceserializationcontext, nbttagcompound1.getCompound(s), i); if (structurestart != null) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/IChunkLoader.patch b/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/IChunkLoader.patch index 3b86f06e19..f2645f2d9e 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/IChunkLoader.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/IChunkLoader.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/chunk/storage/IChunkLoader.java +++ b/net/minecraft/world/level/chunk/storage/IChunkLoader.java -@@ -19,6 +19,15 @@ +@@ -22,6 +22,15 @@ import net.minecraft.world.level.levelgen.structure.PersistentStructureLegacy; import net.minecraft.world.level.storage.WorldPersistentData; @@ -9,18 +9,18 @@ +import net.minecraft.server.level.ChunkProviderServer; +import net.minecraft.server.level.WorldServer; +import net.minecraft.world.level.GeneratorAccess; -+import net.minecraft.world.level.chunk.ChunkStatus; ++import net.minecraft.world.level.chunk.status.ChunkStatus; +import net.minecraft.world.level.dimension.WorldDimension; +// CraftBukkit end + public class IChunkLoader implements AutoCloseable { public static final int LAST_MONOLYTH_STRUCTURE_DATA_VERSION = 1493; -@@ -36,9 +45,53 @@ +@@ -39,10 +48,54 @@ return this.worker.isOldChunkAround(chunkcoordintpair, i); } -- public NBTTagCompound upgradeChunkTag(ResourceKey resourcekey, Supplier supplier, NBTTagCompound nbttagcompound, Optional>> optional) { +- public NBTTagCompound upgradeChunkTag(ResourceKey resourcekey, Supplier supplier, NBTTagCompound nbttagcompound, Optional>> optional) { + // CraftBukkit start + private boolean check(ChunkProviderServer cps, int x, int z) { + ChunkCoordIntPair pos = new ChunkCoordIntPair(x, z); @@ -52,27 +52,28 @@ + return false; + } + -+ public NBTTagCompound upgradeChunkTag(ResourceKey resourcekey, Supplier supplier, NBTTagCompound nbttagcompound, Optional>> optional, ChunkCoordIntPair pos, @Nullable GeneratorAccess generatoraccess) { ++ public NBTTagCompound upgradeChunkTag(ResourceKey resourcekey, Supplier supplier, NBTTagCompound nbttagcompound, Optional>> optional, ChunkCoordIntPair pos, @Nullable GeneratorAccess generatoraccess) { + // CraftBukkit end int i = getVersion(nbttagcompound); -+ // CraftBukkit start -+ if (i < 1466) { -+ NBTTagCompound level = nbttagcompound.getCompound("Level"); -+ if (level.getBoolean("TerrainPopulated") && !level.getBoolean("LightPopulated")) { -+ ChunkProviderServer cps = (generatoraccess == null) ? null : ((WorldServer) generatoraccess).getChunkSource(); -+ if (check(cps, pos.x - 1, pos.z) && check(cps, pos.x - 1, pos.z - 1) && check(cps, pos.x, pos.z - 1)) { -+ level.putBoolean("LightPopulated", true); + try { ++ // CraftBukkit start ++ if (i < 1466) { ++ NBTTagCompound level = nbttagcompound.getCompound("Level"); ++ if (level.getBoolean("TerrainPopulated") && !level.getBoolean("LightPopulated")) { ++ ChunkProviderServer cps = (generatoraccess == null) ? null : ((WorldServer) generatoraccess).getChunkSource(); ++ if (check(cps, pos.x - 1, pos.z) && check(cps, pos.x - 1, pos.z - 1) && check(cps, pos.x, pos.z - 1)) { ++ level.putBoolean("LightPopulated", true); ++ } + } + } -+ } -+ // CraftBukkit end ++ // CraftBukkit end + - if (i < 1493) { - nbttagcompound = DataFixTypes.CHUNK.update(this.fixerUpper, nbttagcompound, i, 1493); - if (nbttagcompound.getCompound("Level").getBoolean("hasLegacyStructureData")) { -@@ -58,7 +111,7 @@ - return nbttagcompound; + if (i < 1493) { + nbttagcompound = DataFixTypes.CHUNK.update(this.fixerUpper, nbttagcompound, i, 1493); + if (nbttagcompound.getCompound("Level").getBoolean("hasLegacyStructureData")) { +@@ -69,7 +122,7 @@ + } } - private PersistentStructureLegacy getLegacyStructureHandler(ResourceKey resourcekey, Supplier supplier) { @@ -80,12 +81,12 @@ PersistentStructureLegacy persistentstructurelegacy = this.legacyStructureHandler; if (persistentstructurelegacy == null) { -@@ -73,7 +126,7 @@ +@@ -84,7 +137,7 @@ return persistentstructurelegacy; } -- public static void injectDatafixingContext(NBTTagCompound nbttagcompound, ResourceKey resourcekey, Optional>> optional) { -+ public static void injectDatafixingContext(NBTTagCompound nbttagcompound, ResourceKey resourcekey, Optional>> optional) { // CraftBukkit +- public static void injectDatafixingContext(NBTTagCompound nbttagcompound, ResourceKey resourcekey, Optional>> optional) { ++ public static void injectDatafixingContext(NBTTagCompound nbttagcompound, ResourceKey resourcekey, Optional>> optional) { // CraftBukkit NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.putString("dimension", resourcekey.location().toString()); diff --git a/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/RegionFile.patch b/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/RegionFile.patch index f9394a9a46..ec081d2e99 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/RegionFile.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/RegionFile.patch @@ -5,7 +5,7 @@ package net.minecraft.world.level.chunk.storage; import com.google.common.annotations.VisibleForTesting; -@@ -57,8 +58,8 @@ +@@ -63,8 +64,8 @@ } else { this.externalFileDir = path1; this.offsets = this.header.asIntBuffer(); @@ -16,7 +16,7 @@ this.timestamps = this.header.asIntBuffer(); if (flag) { this.file = FileChannel.open(path, StandardOpenOption.CREATE, StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.DSYNC); -@@ -67,7 +68,7 @@ +@@ -73,7 +74,7 @@ } this.usedSectors.force(0, 2); @@ -25,7 +25,7 @@ int i = this.file.read(this.header, 0L); if (i != -1) { -@@ -122,7 +123,7 @@ +@@ -132,7 +133,7 @@ ByteBuffer bytebuffer = ByteBuffer.allocate(l); this.file.read(bytebuffer, (long) (j * 4096)); @@ -34,7 +34,7 @@ if (bytebuffer.remaining() < 5) { RegionFile.LOGGER.error("Chunk {} header is truncated: expected {} but read {}", new Object[]{chunkcoordintpair, l, bytebuffer.remaining()}); return null; -@@ -224,7 +225,7 @@ +@@ -246,7 +247,7 @@ try { this.file.read(bytebuffer, (long) (j * 4096)); @@ -43,7 +43,7 @@ if (bytebuffer.remaining() != 5) { return false; } else { -@@ -327,7 +328,7 @@ +@@ -349,7 +350,7 @@ bytebuffer.putInt(1); bytebuffer.put((byte) (this.version.getId() | 128)); @@ -52,7 +52,7 @@ return bytebuffer; } -@@ -336,7 +337,7 @@ +@@ -358,7 +359,7 @@ FileChannel filechannel = FileChannel.open(path1, StandardOpenOption.CREATE, StandardOpenOption.WRITE); try { @@ -61,7 +61,7 @@ filechannel.write(bytebuffer); } catch (Throwable throwable) { if (filechannel != null) { -@@ -360,7 +361,7 @@ +@@ -382,7 +383,7 @@ } private void writeHeader() throws IOException { @@ -70,7 +70,7 @@ this.file.write(this.header, 0L); } -@@ -396,7 +397,7 @@ +@@ -418,7 +419,7 @@ if (i != j) { ByteBuffer bytebuffer = RegionFile.PADDING_BUFFER.duplicate(); diff --git a/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/RegionFileCache.patch b/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/RegionFileCache.patch index d4050c6461..888c3ee20d 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/RegionFileCache.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/chunk/storage/RegionFileCache.patch @@ -1,7 +1,7 @@ --- a/net/minecraft/world/level/chunk/storage/RegionFileCache.java +++ b/net/minecraft/world/level/chunk/storage/RegionFileCache.java -@@ -30,7 +30,7 @@ - this.sync = flag; +@@ -32,7 +32,7 @@ + this.info = regionstorageinfo; } - private RegionFile getRegionFile(ChunkCoordIntPair chunkcoordintpair) throws IOException { @@ -9,15 +9,15 @@ long i = ChunkCoordIntPair.asLong(chunkcoordintpair.getRegionX(), chunkcoordintpair.getRegionZ()); RegionFile regionfile = (RegionFile) this.regionCache.getAndMoveToFirst(i); -@@ -45,6 +45,7 @@ +@@ -47,6 +47,7 @@ Path path = this.folder; int j = chunkcoordintpair.getRegionX(); Path path1 = path.resolve("r." + j + "." + chunkcoordintpair.getRegionZ() + ".mca"); + if (existingOnly && !java.nio.file.Files.exists(path1)) return null; // CraftBukkit - RegionFile regionfile1 = new RegionFile(path1, this.folder, this.sync); + RegionFile regionfile1 = new RegionFile(this.info, path1, this.folder, this.sync); this.regionCache.putAndMoveToFirst(i, regionfile1); -@@ -54,7 +55,12 @@ +@@ -56,7 +57,12 @@ @Nullable public NBTTagCompound read(ChunkCoordIntPair chunkcoordintpair) throws IOException { @@ -31,7 +31,7 @@ DataInputStream datainputstream = regionfile.getChunkDataInputStream(chunkcoordintpair); NBTTagCompound nbttagcompound; -@@ -94,7 +100,12 @@ +@@ -96,7 +102,12 @@ } public void scanChunk(ChunkCoordIntPair chunkcoordintpair, StreamTagVisitor streamtagvisitor) throws IOException { @@ -45,7 +45,7 @@ DataInputStream datainputstream = regionfile.getChunkDataInputStream(chunkcoordintpair); try { -@@ -120,7 +131,7 @@ +@@ -122,7 +133,7 @@ } protected void write(ChunkCoordIntPair chunkcoordintpair, @Nullable NBTTagCompound nbttagcompound) throws IOException { 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 2d099269f3..86ffe4aca4 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,14 +1,5 @@ --- a/net/minecraft/world/level/dimension/end/EnderDragonBattle.java +++ b/net/minecraft/world/level/dimension/end/EnderDragonBattle.java -@@ -83,7 +83,7 @@ - private int ticksSinceCrystalsScanned; - private int ticksSinceLastPlayerScan; - private boolean dragonKilled; -- private boolean previouslyKilled; -+ public boolean previouslyKilled; - private boolean skipArenaLoadedCheck; - @Nullable - public UUID dragonUUID; @@ -110,14 +110,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)); diff --git a/paper-server/nms-patches/net/minecraft/world/level/entity/PersistentEntitySectionManager.patch b/paper-server/nms-patches/net/minecraft/world/level/entity/PersistentEntitySectionManager.patch index 79b60adb35..b92034629c 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/entity/PersistentEntitySectionManager.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/entity/PersistentEntitySectionManager.patch @@ -147,7 +147,7 @@ @@ -394,7 +430,7 @@ private EntitySection currentSection; - a(EntityAccess entityaccess, long i, EntitySection entitysection) { + a(final EntityAccess entityaccess, final long i, final EntitySection entitysection) { - this.entity = entityaccess; + this.entity = (T) entityaccess; // CraftBukkit - decompile error this.currentSectionKey = i; diff --git a/paper-server/nms-patches/net/minecraft/world/level/gameevent/GameEventDispatcher.patch b/paper-server/nms-patches/net/minecraft/world/level/gameevent/GameEventDispatcher.patch index 079afdc38c..d3e07b3182 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/gameevent/GameEventDispatcher.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/gameevent/GameEventDispatcher.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/gameevent/GameEventDispatcher.java +++ b/net/minecraft/world/level/gameevent/GameEventDispatcher.java -@@ -11,6 +11,13 @@ +@@ -12,6 +12,13 @@ import net.minecraft.world.level.chunk.Chunk; import net.minecraft.world.phys.Vec3D; @@ -14,12 +14,12 @@ public class GameEventDispatcher { private final WorldServer level; -@@ -22,6 +29,14 @@ - public void post(GameEvent gameevent, Vec3D vec3d, GameEvent.a gameevent_a) { - int i = gameevent.getNotificationRadius(); +@@ -23,6 +30,14 @@ + public void post(Holder holder, Vec3D vec3d, GameEvent.a gameevent_a) { + int i = ((GameEvent) holder.value()).notificationRadius(); BlockPosition blockposition = BlockPosition.containing(vec3d); + // CraftBukkit start -+ GenericGameEvent event = new GenericGameEvent(CraftGameEvent.minecraftToBukkit(gameevent), CraftLocation.toBukkit(blockposition, level.getWorld()), (gameevent_a.sourceEntity() == null) ? null : gameevent_a.sourceEntity().getBukkitEntity(), i, !Bukkit.isPrimaryThread()); ++ GenericGameEvent event = new GenericGameEvent(CraftGameEvent.minecraftToBukkit(holder.value()), CraftLocation.toBukkit(blockposition, level.getWorld()), (gameevent_a.sourceEntity() == null) ? null : gameevent_a.sourceEntity().getBukkitEntity(), i, !Bukkit.isPrimaryThread()); + level.getCraftServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return; diff --git a/paper-server/nms-patches/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.patch b/paper-server/nms-patches/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.patch index e36dd6a4bb..0b7640d2c4 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.java +++ b/net/minecraft/world/level/gameevent/vibrations/VibrationSystem.java -@@ -28,6 +28,12 @@ +@@ -31,6 +31,12 @@ import net.minecraft.world.phys.MovingObjectPosition; import net.minecraft.world.phys.Vec3D; @@ -12,8 +12,8 @@ + public interface VibrationSystem { - GameEvent[] RESONANCE_EVENTS = new GameEvent[]{GameEvent.RESONATE_1, GameEvent.RESONATE_2, GameEvent.RESONATE_3, GameEvent.RESONATE_4, GameEvent.RESONATE_5, GameEvent.RESONATE_6, GameEvent.RESONATE_7, GameEvent.RESONATE_8, GameEvent.RESONATE_9, GameEvent.RESONATE_10, GameEvent.RESONATE_11, GameEvent.RESONATE_12, GameEvent.RESONATE_13, GameEvent.RESONATE_14, GameEvent.RESONATE_15}; -@@ -227,7 +233,8 @@ + List> RESONANCE_EVENTS = List.of(GameEvent.RESONATE_1.key(), GameEvent.RESONATE_2.key(), GameEvent.RESONATE_3.key(), GameEvent.RESONATE_4.key(), GameEvent.RESONATE_5.key(), GameEvent.RESONATE_6.key(), GameEvent.RESONATE_7.key(), GameEvent.RESONATE_8.key(), GameEvent.RESONATE_9.key(), GameEvent.RESONATE_10.key(), GameEvent.RESONATE_11.key(), GameEvent.RESONATE_12.key(), GameEvent.RESONATE_13.key(), GameEvent.RESONATE_14.key(), GameEvent.RESONATE_15.key()); +@@ -233,7 +239,8 @@ if (vibrationsystem_d.requiresAdjacentChunksToBeTicking() && !areAdjacentChunksTicking(worldserver, blockposition1)) { return false; } else { @@ -23,16 +23,16 @@ vibrationsystem_a.setCurrentVibration((VibrationInfo) null); return true; } -@@ -282,8 +289,14 @@ +@@ -288,8 +295,14 @@ return false; } else { Vec3D vec3d1 = (Vec3D) optional.get(); - -- if (!vibrationsystem_d.canReceiveVibration(worldserver, BlockPosition.containing(vec3d), gameevent, gameevent_a)) { +- if (!vibrationsystem_d.canReceiveVibration(worldserver, BlockPosition.containing(vec3d), holder, gameevent_a)) { + // CraftBukkit start -+ boolean defaultCancel = !vibrationsystem_d.canReceiveVibration(worldserver, BlockPosition.containing(vec3d), gameevent, gameevent_a); ++ boolean defaultCancel = !vibrationsystem_d.canReceiveVibration(worldserver, BlockPosition.containing(vec3d), holder, gameevent_a); + Entity entity = gameevent_a.sourceEntity(); -+ BlockReceiveGameEvent event = new BlockReceiveGameEvent(CraftGameEvent.minecraftToBukkit(gameevent), CraftBlock.at(worldserver, BlockPosition.containing(vec3d1)), (entity == null) ? null : entity.getBukkitEntity()); ++ BlockReceiveGameEvent event = new BlockReceiveGameEvent(CraftGameEvent.minecraftToBukkit(holder.value()), CraftBlock.at(worldserver, BlockPosition.containing(vec3d1)), (entity == null) ? null : entity.getBukkitEntity()); + event.setCancelled(defaultCancel); + worldserver.getCraftServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { @@ -40,8 +40,8 @@ return false; } else if (isOccluded(worldserver, vec3d, vec3d1)) { return false; -@@ -336,7 +349,7 @@ - return instance.group(VibrationInfo.CODEC.optionalFieldOf("event").forGetter((vibrationsystem_a) -> { +@@ -342,7 +355,7 @@ + return instance.group(VibrationInfo.CODEC.lenientOptionalFieldOf("event").forGetter((vibrationsystem_a) -> { return Optional.ofNullable(vibrationsystem_a.currentVibration); }), VibrationSelector.CODEC.fieldOf("selector").forGetter(VibrationSystem.a::getSelectionStrategy), ExtraCodecs.NON_NEGATIVE_INT.fieldOf("event_delay").orElse(0).forGetter(VibrationSystem.a::getTravelTimeInTicks)).apply(instance, (optional, vibrationselector, integer) -> { - return new VibrationSystem.a((VibrationInfo) optional.orElse((Object) null), vibrationselector, integer, true); 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 4320791a07..6d10880de8 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 @@ -1,9 +1,9 @@ --- a/net/minecraft/world/level/levelgen/MobSpawnerPatrol.java +++ b/net/minecraft/world/level/levelgen/MobSpawnerPatrol.java -@@ -117,7 +117,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, (NBTTagCompound) null); + entitymonsterpatrolling.finalizeSpawn(worldserver, worldserver.getCurrentDifficultyAt(blockposition), EnumMobSpawn.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 dd29749c1a..ac5104bff4 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 @@ -1,9 +1,9 @@ --- a/net/minecraft/world/level/levelgen/MobSpawnerPhantom.java +++ b/net/minecraft/world/level/levelgen/MobSpawnerPhantom.java -@@ -75,7 +75,7 @@ +@@ -74,7 +74,7 @@ if (entityphantom != null) { entityphantom.moveTo(blockposition1, 0.0F, 0.0F); - groupdataentity = entityphantom.finalizeSpawn(worldserver, difficultydamagescaler, EnumMobSpawn.NATURAL, groupdataentity, (NBTTagCompound) null); + groupdataentity = entityphantom.finalizeSpawn(worldserver, difficultydamagescaler, EnumMobSpawn.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/StructurePiece.patch b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/StructurePiece.patch index 290d5b21c9..184c09f4fd 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/levelgen/structure/StructurePiece.java +++ b/net/minecraft/world/level/levelgen/structure/StructurePiece.java -@@ -50,7 +50,7 @@ +@@ -51,7 +51,7 @@ private EnumBlockRotation rotation; protected int genDepth; private final WorldGenFeatureStructurePieceType type; @@ -9,7 +9,7 @@ protected StructurePiece(WorldGenFeatureStructurePieceType worldgenfeaturestructurepiecetype, int i, StructureBoundingBox structureboundingbox) { this.type = worldgenfeaturestructurepiecetype; -@@ -59,14 +59,11 @@ +@@ -60,14 +60,11 @@ } public StructurePiece(WorldGenFeatureStructurePieceType worldgenfeaturestructurepiecetype, NBTTagCompound nbttagcompound) { @@ -27,7 +27,7 @@ int j = nbttagcompound.getInt("O"); this.setOrientation(j == -1 ? null : EnumDirection.from2DDataValue(j)); -@@ -84,13 +81,11 @@ +@@ -85,13 +82,11 @@ NBTTagCompound nbttagcompound = new NBTTagCompound(); nbttagcompound.putString("id", BuiltInRegistries.STRUCTURE_PIECE.getKey(this.getType()).toString()); @@ -45,7 +45,7 @@ EnumDirection enumdirection = this.getOrientation(); nbttagcompound.putInt("O", enumdirection == null ? -1 : enumdirection.get2DDataValue()); -@@ -190,6 +185,11 @@ +@@ -191,6 +186,11 @@ } generatoraccessseed.setBlock(blockposition_mutableblockposition, iblockdata, 2); @@ -57,7 +57,7 @@ Fluid fluid = generatoraccessseed.getFluidState(blockposition_mutableblockposition); if (!fluid.isEmpty()) { -@@ -204,6 +204,38 @@ +@@ -205,6 +205,38 @@ } } @@ -69,25 +69,25 @@ + boolean result = worldAccess.setBlock(position, craftBlockEntityState.getHandle(), i); + TileEntity tileEntity = worldAccess.getBlockEntity(position); + if (tileEntity != null) { -+ tileEntity.load(craftBlockEntityState.getSnapshotNBT()); ++ tileEntity.loadWithComponents(craftBlockEntityState.getSnapshotNBT(), worldAccess.registryAccess()); + } + return result; + } + + protected void placeCraftSpawner(WorldAccess worldAccess, BlockPosition position, org.bukkit.entity.EntityType entityType, int i) { + // This method is used in structures that are generated by code and place spawners as they set the entity after the block was placed making it impossible for plugins to access that information -+ org.bukkit.craftbukkit.block.CraftCreatureSpawner spawner = (org.bukkit.craftbukkit.block.CraftCreatureSpawner) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(position, Blocks.SPAWNER.defaultBlockState(), null); ++ org.bukkit.craftbukkit.block.CraftCreatureSpawner spawner = (org.bukkit.craftbukkit.block.CraftCreatureSpawner) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(worldAccess, position, Blocks.SPAWNER.defaultBlockState(), null); + spawner.setSpawnedType(entityType); + placeCraftBlockEntity(worldAccess, position, spawner, i); + } + -+ protected void setCraftLootTable(WorldAccess worldAccess, BlockPosition position, RandomSource randomSource, net.minecraft.resources.MinecraftKey loottableKey) { ++ protected void setCraftLootTable(WorldAccess worldAccess, BlockPosition position, RandomSource randomSource, ResourceKey loottableKey) { + // This method is used in structures that use data markers to a loot table to loot containers as otherwise plugins won't have access to that information. + net.minecraft.world.level.block.entity.TileEntity tileEntity = worldAccess.getBlockEntity(position); + if (tileEntity instanceof net.minecraft.world.level.block.entity.TileEntityLootable tileEntityLootable) { + tileEntityLootable.setLootTable(loottableKey, randomSource.nextLong()); + if (worldAccess instanceof org.bukkit.craftbukkit.util.TransformerGeneratorAccess transformerAccess) { -+ transformerAccess.setCraftBlock(position, (org.bukkit.craftbukkit.block.CraftBlockState) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(position, tileEntity.getBlockState(), tileEntityLootable.saveWithFullMetadata()), 3); ++ transformerAccess.setCraftBlock(position, (org.bukkit.craftbukkit.block.CraftBlockState) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(worldAccess, position, tileEntity.getBlockState(), tileEntityLootable.saveWithFullMetadata(worldAccess.registryAccess())), 3); + } + } + } @@ -96,7 +96,7 @@ protected boolean canBeReplaced(IWorldReader iworldreader, int i, int j, int k, StructureBoundingBox structureboundingbox) { return true; } -@@ -397,12 +429,20 @@ +@@ -398,12 +430,20 @@ iblockdata = reorient(worldaccess, blockposition, Blocks.CHEST.defaultBlockState()); } @@ -106,18 +106,18 @@ TileEntity tileentity = worldaccess.getBlockEntity(blockposition); if (tileentity instanceof TileEntityChest) { - ((TileEntityChest) tileentity).setLootTable(minecraftkey, randomsource.nextLong()); + ((TileEntityChest) tileentity).setLootTable(resourcekey, randomsource.nextLong()); } + */ -+ org.bukkit.craftbukkit.block.CraftChest chestState = (org.bukkit.craftbukkit.block.CraftChest) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockposition, iblockdata, null); -+ chestState.setLootTable(org.bukkit.Bukkit.getLootTable(org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(minecraftkey))); ++ org.bukkit.craftbukkit.block.CraftChest chestState = (org.bukkit.craftbukkit.block.CraftChest) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(worldaccess, blockposition, iblockdata, null); ++ chestState.setLootTable(org.bukkit.craftbukkit.CraftLootTable.minecraftToBukkit(resourcekey)); + chestState.setSeed(randomsource.nextLong()); + placeCraftBlockEntity(worldaccess, blockposition, chestState, 2); + // CraftBukkit end return true; } else { -@@ -414,12 +454,31 @@ +@@ -415,12 +455,31 @@ BlockPosition.MutableBlockPosition blockposition_mutableblockposition = this.getWorldPos(i, j, k); if (structureboundingbox.isInside(blockposition_mutableblockposition) && !generatoraccessseed.getBlockState(blockposition_mutableblockposition).is(Blocks.DISPENSER)) { @@ -127,7 +127,7 @@ TileEntity tileentity = generatoraccessseed.getBlockEntity(blockposition_mutableblockposition); if (tileentity instanceof TileEntityDispenser) { - ((TileEntityDispenser) tileentity).setLootTable(minecraftkey, randomsource.nextLong()); + ((TileEntityDispenser) tileentity).setLootTable(resourcekey, randomsource.nextLong()); } + */ + if (!this.canBeReplaced(generatoraccessseed, i, j, k, structureboundingbox)) { @@ -141,15 +141,15 @@ + iblockdata = iblockdata.rotate(this.rotation); + } + -+ org.bukkit.craftbukkit.block.CraftDispenser dispenserState = (org.bukkit.craftbukkit.block.CraftDispenser) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockposition_mutableblockposition, iblockdata, null); -+ dispenserState.setLootTable(org.bukkit.Bukkit.getLootTable(org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(minecraftkey))); ++ org.bukkit.craftbukkit.block.CraftDispenser dispenserState = (org.bukkit.craftbukkit.block.CraftDispenser) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(generatoraccessseed, blockposition_mutableblockposition, iblockdata, null); ++ dispenserState.setLootTable(org.bukkit.craftbukkit.CraftLootTable.minecraftToBukkit(resourcekey)); + dispenserState.setSeed(randomsource.nextLong()); + placeCraftBlockEntity(generatoraccessseed, blockposition_mutableblockposition, dispenserState, 2); + // CraftBukkit end return true; } else { -@@ -432,7 +491,7 @@ +@@ -433,7 +492,7 @@ } public static StructureBoundingBox createBoundingBox(Stream stream) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.patch b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.patch index a015136b4f..8da3c90705 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.patch @@ -1,13 +1,13 @@ --- a/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.java +++ b/net/minecraft/world/level/levelgen/structure/structures/DesertPyramidStructure.java -@@ -70,6 +70,15 @@ +@@ -68,6 +68,15 @@ private static void placeSuspiciousSand(StructureBoundingBox structureboundingbox, GeneratorAccessSeed generatoraccessseed, BlockPosition blockposition) { if (structureboundingbox.isInside(blockposition)) { + // CraftBukkit start + if (generatoraccessseed instanceof org.bukkit.craftbukkit.util.TransformerGeneratorAccess transformerAccess) { -+ org.bukkit.craftbukkit.block.CraftBrushableBlock brushableState = (org.bukkit.craftbukkit.block.CraftBrushableBlock) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockposition, Blocks.SUSPICIOUS_SAND.defaultBlockState(), null); -+ brushableState.setLootTable(org.bukkit.Bukkit.getLootTable(org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(LootTables.DESERT_PYRAMID_ARCHAEOLOGY))); ++ org.bukkit.craftbukkit.block.CraftBrushableBlock brushableState = (org.bukkit.craftbukkit.block.CraftBrushableBlock) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(generatoraccessseed, blockposition, Blocks.SUSPICIOUS_SAND.defaultBlockState(), null); ++ brushableState.setLootTable(org.bukkit.craftbukkit.CraftLootTable.minecraftToBukkit(LootTables.DESERT_PYRAMID_ARCHAEOLOGY)); + brushableState.setSeed(blockposition.asLong()); + transformerAccess.setCraftBlock(blockposition, brushableState, 2); + return; 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 952c87774d..ed2f4037a5 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 -@@ -42,6 +42,10 @@ +@@ -43,6 +43,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(); -@@ -514,6 +518,8 @@ +@@ -515,6 +519,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); -@@ -522,6 +528,9 @@ +@@ -523,6 +529,9 @@ tileentitymobspawner.setEntityId(EntityTypes.CAVE_SPIDER, randomsource); } @@ -30,7 +30,7 @@ } } } -@@ -813,11 +822,11 @@ +@@ -814,11 +823,11 @@ public d(NBTTagCompound nbttagcompound) { super(WorldGenFeatureStructurePieceType.MINE_SHAFT_ROOM, nbttagcompound); @@ -44,7 +44,7 @@ List list = this.childEntranceBoxes; Objects.requireNonNull(this.childEntranceBoxes); -@@ -923,7 +932,7 @@ +@@ -924,7 +933,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 f73431b188..e8ae59bee6 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/levelgen/structure/structures/OceanRuinPieces.java +++ b/net/minecraft/world/level/levelgen/structure/structures/OceanRuinPieces.java -@@ -198,12 +198,20 @@ +@@ -200,12 +200,20 @@ @Override protected void handleDataMarker(String s, BlockPosition blockposition, WorldAccess worldaccess, RandomSource randomsource, StructureBoundingBox structureboundingbox) { if ("chest".equals(s)) { @@ -13,9 +13,9 @@ ((TileEntityChest) tileentity).setLootTable(this.isLarge ? LootTables.UNDERWATER_RUIN_BIG : LootTables.UNDERWATER_RUIN_SMALL, randomsource.nextLong()); } + */ -+ org.bukkit.craftbukkit.block.CraftChest craftChest = (org.bukkit.craftbukkit.block.CraftChest) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockposition, Blocks.CHEST.defaultBlockState().setValue(BlockChest.WATERLOGGED, worldaccess.getFluidState(blockposition).is(TagsFluid.WATER)), null); ++ org.bukkit.craftbukkit.block.CraftChest craftChest = (org.bukkit.craftbukkit.block.CraftChest) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(worldaccess, blockposition, Blocks.CHEST.defaultBlockState().setValue(BlockChest.WATERLOGGED, worldaccess.getFluidState(blockposition).is(TagsFluid.WATER)), null); + craftChest.setSeed(randomsource.nextLong()); -+ craftChest.setLootTable(org.bukkit.Bukkit.getLootTable(org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(this.isLarge ? LootTables.UNDERWATER_RUIN_BIG : LootTables.UNDERWATER_RUIN_SMALL))); ++ craftChest.setLootTable(org.bukkit.craftbukkit.CraftLootTable.minecraftToBukkit(this.isLarge ? LootTables.UNDERWATER_RUIN_BIG : LootTables.UNDERWATER_RUIN_SMALL)); + placeCraftBlockEntity(worldaccess, blockposition, craftChest, 2); + // CraftBukkit end } else if ("drowned".equals(s)) { 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 0dc4ec2371..9767269c61 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, (NBTTagCompound) null); + entitywitch.finalizeSpawn(generatoraccessseed, generatoraccessseed.getCurrentDifficultyAt(blockposition_mutableblockposition), EnumMobSpawn.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, (NBTTagCompound) null); + entitycat.finalizeSpawn(worldaccess, worldaccess.getCurrentDifficultyAt(blockposition_mutableblockposition), EnumMobSpawn.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 fc7d71b539..3525993f5e 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 @@ -60,7 +60,7 @@ } + // CraftBukkit start + if (structureTransformer != null) { -+ org.bukkit.craftbukkit.block.CraftBlockState craftBlockState = (org.bukkit.craftbukkit.block.CraftBlockState) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(blockposition2, iblockdata, null); ++ org.bukkit.craftbukkit.block.CraftBlockState craftBlockState = (org.bukkit.craftbukkit.block.CraftBlockState) org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(worldaccess, blockposition2, iblockdata, null); + if (definedstructure_blockinfo.nbt != null && craftBlockState instanceof org.bukkit.craftbukkit.block.CraftBlockEntityState entityState) { + entityState.loadData(definedstructure_blockinfo.nbt); + if (craftBlockState instanceof org.bukkit.craftbukkit.block.CraftLootable craftLootable) { @@ -93,7 +93,7 @@ } return true; -@@ -472,11 +510,13 @@ +@@ -479,11 +517,13 @@ } private static Optional createEntityIgnoreException(WorldAccess worldaccess, NBTTagCompound nbttagcompound) { @@ -111,7 +111,7 @@ } public BaseBlockPosition getSize(EnumBlockRotation enumblockrotation) { -@@ -690,6 +730,11 @@ +@@ -697,6 +737,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); } -@@ -729,6 +774,12 @@ +@@ -736,6 +781,12 @@ } } @@ -136,7 +136,7 @@ } private void loadPalette(HolderGetter holdergetter, NBTTagList nbttaglist, NBTTagList nbttaglist1) { -@@ -858,7 +909,7 @@ +@@ -865,7 +916,7 @@ public IBlockData stateFor(int i) { IBlockData iblockdata = (IBlockData) this.ids.byId(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 8b3d30a04b..753e886f19 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 @@ -48,7 +48,7 @@ this.spreadTo(world, blockposition1, iblockdata1, enumdirection, fluid1); } } -@@ -438,12 +465,23 @@ +@@ -436,12 +463,23 @@ if (fluid1.isEmpty()) { fluid = fluid1; 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 54951e9f75..ad8bebcf1f 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 @@ -29,6 +29,6 @@ + } + } + // CraftBukkit end - iblockdata.neighborChanged(world, blockposition, block, blockposition1, flag); + iblockdata.handleNeighborChanged(world, blockposition, block, blockposition1, 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 92a6fd4445..f7c4baa633 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 -@@ -32,6 +32,16 @@ +@@ -44,6 +44,17 @@ import net.minecraft.world.level.saveddata.PersistentBase; import org.slf4j.Logger; @@ -10,6 +10,7 @@ +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.CraftWorld; ++import org.bukkit.craftbukkit.map.CraftMapCursor; +import org.bukkit.craftbukkit.map.CraftMapView; +import org.bukkit.craftbukkit.util.CraftChatMessage; +// CraftBukkit end @@ -17,7 +18,7 @@ public class WorldMap extends PersistentBase { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -54,6 +64,13 @@ +@@ -66,6 +77,13 @@ private final Map frameMarkers = Maps.newHashMap(); private int trackedDecorationCount; @@ -25,13 +26,13 @@ + public final CraftMapView mapView; + private CraftServer server; + public UUID uniqueId = null; -+ public String id; ++ public MapId id; + // CraftBukkit end + public static PersistentBase.a factory() { return new PersistentBase.a<>(() -> { throw new IllegalStateException("Should never create an empty map saved data"); -@@ -69,6 +86,10 @@ +@@ -81,6 +99,10 @@ this.unlimitedTracking = flag1; this.locked = flag2; this.setDirty(); @@ -42,19 +43,19 @@ } public static WorldMap createFresh(double d0, double d1, byte b0, boolean flag, boolean flag1, ResourceKey resourcekey) { -@@ -86,12 +107,30 @@ +@@ -98,12 +120,30 @@ } - public static WorldMap load(NBTTagCompound nbttagcompound) { + public static WorldMap load(NBTTagCompound nbttagcompound, HolderLookup.a holderlookup_a) { - DataResult dataresult = DimensionManager.parseLegacy(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("dimension"))); + DataResult> dataresult = DimensionManager.parseLegacy(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("dimension"))); // CraftBukkit - decompile error Logger logger = WorldMap.LOGGER; Objects.requireNonNull(logger); - ResourceKey resourcekey = (ResourceKey) dataresult.resultOrPartial(logger::error).orElseThrow(() -> { -- return new IllegalArgumentException("Invalid map dimension: " + nbttagcompound.get("dimension")); +- return new IllegalArgumentException("Invalid map dimension: " + String.valueOf(nbttagcompound.get("dimension"))); + // CraftBukkit start -+ ResourceKey resourcekey = dataresult.resultOrPartial(logger::error).orElseGet(() -> { ++ ResourceKey resourcekey = (ResourceKey) dataresult.resultOrPartial(logger::error).orElseGet(() -> { + long least = nbttagcompound.getLong("UUIDLeast"); + long most = nbttagcompound.getLong("UUIDMost"); + @@ -71,15 +72,25 @@ + return world.getHandle().dimension(); + } + } -+ throw new IllegalArgumentException("Invalid map dimension: " + nbttagcompound.get("dimension")); ++ throw new IllegalArgumentException("Invalid map dimension: " + String.valueOf(nbttagcompound.get("dimension"))); + // CraftBukkit end }); int i = nbttagcompound.getInt("xCenter"); int j = nbttagcompound.getInt("zCenter"); -@@ -129,13 +168,32 @@ +@@ -128,7 +168,8 @@ + MapIconBanner mapiconbanner = (MapIconBanner) iterator.next(); + + worldmap.bannerMarkers.put(mapiconbanner.getId(), mapiconbanner); +- worldmap.addDecoration(mapiconbanner.getDecoration(), (GeneratorAccess) null, mapiconbanner.getId(), (double) mapiconbanner.pos().getX(), (double) mapiconbanner.pos().getZ(), 180.0D, (IChatBaseComponent) mapiconbanner.name().orElse((Object) null)); ++ // CraftBukkit - decompile error ++ worldmap.addDecoration(mapiconbanner.getDecoration(), (GeneratorAccess) null, mapiconbanner.getId(), (double) mapiconbanner.pos().getX(), (double) mapiconbanner.pos().getZ(), 180.0D, (IChatBaseComponent) mapiconbanner.name().orElse(null)); + } + + NBTTagList nbttaglist = nbttagcompound.getList("frames", 10); +@@ -147,13 +188,32 @@ @Override - public NBTTagCompound save(NBTTagCompound nbttagcompound) { + public NBTTagCompound save(NBTTagCompound nbttagcompound, HolderLookup.a holderlookup_a) { - DataResult dataresult = MinecraftKey.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, this.dimension.location()); + DataResult dataresult = MinecraftKey.CODEC.encodeStart(DynamicOpsNBT.INSTANCE, this.dimension.location()); // CraftBukkit - decompile error Logger logger = WorldMap.LOGGER; @@ -110,7 +121,16 @@ nbttagcompound.putInt("xCenter", this.centerX); nbttagcompound.putInt("zCenter", this.centerZ); nbttagcompound.putByte("scale", this.scale); -@@ -510,7 +568,7 @@ +@@ -408,7 +468,7 @@ + + if (!this.isTrackedCountOverLimit(256)) { + this.bannerMarkers.put(mapiconbanner.getId(), mapiconbanner); +- this.addDecoration(mapiconbanner.getDecoration(), generatoraccess, mapiconbanner.getId(), d0, d1, 180.0D, (IChatBaseComponent) mapiconbanner.name().orElse((Object) null)); ++ this.addDecoration(mapiconbanner.getDecoration(), generatoraccess, mapiconbanner.getId(), d0, d1, 180.0D, (IChatBaseComponent) mapiconbanner.name().orElse(null)); // CraftBukkit - decompile error + return true; + } + } +@@ -514,7 +574,7 @@ this.player = entityhuman; } @@ -119,7 +139,7 @@ int i = this.minDirtyX; int j = this.minDirtyY; int k = this.maxDirtyX + 1 - this.minDirtyX; -@@ -519,7 +577,7 @@ +@@ -523,7 +583,7 @@ for (int i1 = 0; i1 < k; ++i1) { for (int j1 = 0; j1 < l; ++j1) { @@ -128,9 +148,9 @@ } } -@@ -529,19 +587,29 @@ +@@ -533,19 +593,29 @@ @Nullable - Packet nextUpdatePacket(int i) { + Packet nextUpdatePacket(MapId mapid) { WorldMap.b worldmap_b; + org.bukkit.craftbukkit.map.RenderData render = WorldMap.this.mapView.render((org.bukkit.craftbukkit.entity.CraftPlayer) this.player.getBukkitEntity()); // CraftBukkit @@ -153,7 +173,7 @@ + + for (org.bukkit.map.MapCursor cursor : render.cursors) { + if (cursor.isVisible()) { -+ icons.add(new MapIcon(MapIcon.Type.byIcon(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection(), CraftChatMessage.fromStringOrNull(cursor.getCaption()))); ++ icons.add(new MapIcon(CraftMapCursor.CraftType.bukkitToMinecraftHolder(cursor.getType()), cursor.getX(), cursor.getY(), cursor.getDirection(), CraftChatMessage.fromStringOrOptional(cursor.getCaption()))); + } + } + collection = icons; 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 db73231168..da71086f1a 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 -@@ -81,6 +81,10 @@ +@@ -77,6 +77,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(); -@@ -151,7 +155,7 @@ +@@ -148,7 +152,7 @@ } public static WorldDataConfiguration readDataConfig(Dynamic dynamic) { @@ -20,7 +20,7 @@ Logger logger = Convertable.LOGGER; Objects.requireNonNull(logger); -@@ -174,6 +178,7 @@ +@@ -167,6 +171,7 @@ WorldDimensions.b worlddimensions_b = generatorsettings.dimensions().bake(iregistry); Lifecycle lifecycle = worlddimensions_b.lifecycle().add(iregistrycustom_dimension.allRegistriesLifecycle()); WorldDataServer worlddataserver = WorldDataServer.parse(dynamic1, worldsettings, worlddimensions_b.specialWorldProperty(), generatorsettings.options(), lifecycle); @@ -28,16 +28,7 @@ return new LevelDataAndDimensions(worlddataserver, worlddimensions_b); } -@@ -193,7 +198,7 @@ - throw new LevelStorageException(IChatBaseComponent.translatable("selectWorld.load_folder_access")); - } else { - try { -- Stream stream = Files.list(this.baseDir); -+ Stream stream = Files.list(this.baseDir); // CraftBukkit - decompile error - - Convertable.a convertable_a; - -@@ -423,27 +428,41 @@ +@@ -409,27 +414,41 @@ return this.backupDir; } @@ -83,21 +74,21 @@ public static record a(List levels) implements Iterable { public boolean isEmpty() { -@@ -502,8 +521,12 @@ +@@ -488,8 +507,12 @@ public final Convertable.b levelDirectory; private final String levelId; private final Map resources = Maps.newHashMap(); + // CraftBukkit start + public final ResourceKey dimensionType; -- ConversionSession(String s, Path path) throws IOException { -+ ConversionSession(String s, Path path, ResourceKey dimensionType) throws IOException { +- ConversionSession(final String s, final Path path) throws IOException { ++ ConversionSession(final String s, final Path path, final ResourceKey dimensionType) throws IOException { + this.dimensionType = dimensionType; + // CraftBukkit end this.levelId = s; this.levelDirectory = new Convertable.b(path); this.lock = SessionLock.create(path); -@@ -531,7 +554,7 @@ +@@ -529,7 +552,7 @@ } public Path getLevelPath(SavedFile savedfile) { @@ -106,7 +97,7 @@ Convertable.b convertable_b = this.levelDirectory; Objects.requireNonNull(this.levelDirectory); -@@ -539,7 +562,7 @@ +@@ -537,7 +560,7 @@ } public Path getDimensionPath(ResourceKey resourcekey) { 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 b5a259c25e..12b9022034 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 @@ -20,7 +20,7 @@ public class WorldDataServer implements IWorldDataServer, SaveData { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -81,6 +94,20 @@ +@@ -79,6 +92,20 @@ private boolean wasModded; private final Set removedFeatureFlags; private final CustomFunctionCallbackTimerQueue scheduledEvents; @@ -39,27 +39,27 @@ + } + // CraftBukkit end - private WorldDataServer(@Nullable NBTTagCompound nbttagcompound, boolean flag, int i, int j, int k, float f, long l, long i1, int j1, int k1, int l1, boolean flag1, int i2, boolean flag2, boolean flag3, boolean flag4, WorldBorder.c worldborder_c, int j2, int k2, @Nullable UUID uuid, Set set, Set set1, CustomFunctionCallbackTimerQueue customfunctioncallbacktimerqueue, @Nullable NBTTagCompound nbttagcompound1, EnderDragonBattle.a enderdragonbattle_a, WorldSettings worldsettings, WorldOptions worldoptions, WorldDataServer.a worlddataserver_a, Lifecycle lifecycle) { + private WorldDataServer(@Nullable NBTTagCompound nbttagcompound, boolean flag, BlockPosition blockposition, float f, long i, long j, int k, int l, int i1, boolean flag1, int j1, boolean flag2, boolean flag3, boolean flag4, WorldBorder.c worldborder_c, int k1, int l1, @Nullable UUID uuid, Set set, Set set1, CustomFunctionCallbackTimerQueue customfunctioncallbacktimerqueue, @Nullable NBTTagCompound nbttagcompound1, EnderDragonBattle.a enderdragonbattle_a, WorldSettings worldsettings, WorldOptions worldoptions, WorldDataServer.a worlddataserver_a, Lifecycle lifecycle) { this.wasModded = flag; -@@ -120,7 +147,7 @@ +@@ -116,7 +143,7 @@ public static WorldDataServer parse(Dynamic dynamic, WorldSettings worldsettings, WorldDataServer.a worlddataserver_a, WorldOptions worldoptions, Lifecycle lifecycle) { long i = dynamic.get("Time").asLong(0L); -- NBTTagCompound nbttagcompound = (NBTTagCompound) NBTTagCompound.CODEC.parse(dynamic.get("Player").orElseEmptyMap()).result().orElse((Object) null); -+ NBTTagCompound nbttagcompound = (NBTTagCompound) NBTTagCompound.CODEC.parse(dynamic.get("Player").orElseEmptyMap()).result().orElse(null); // CraftBukkit - decompile error - boolean flag = dynamic.get("WasModded").asBoolean(false); - int j = dynamic.get("SpawnX").asInt(0); - int k = dynamic.get("SpawnY").asInt(0); -@@ -138,7 +165,7 @@ +- OptionalDynamic optionaldynamic = dynamic.get("Player"); ++ OptionalDynamic optionaldynamic = dynamic.get("Player"); // CraftBukkit - decompile error + Codec codec = NBTTagCompound.CODEC; + + Objects.requireNonNull(codec); +@@ -136,7 +163,7 @@ WorldBorder.c worldborder_c = WorldBorder.c.read(dynamic, WorldBorder.DEFAULT_SETTINGS); - int j2 = dynamic.get("WanderingTraderSpawnDelay").asInt(0); - int k2 = dynamic.get("WanderingTraderSpawnChance").asInt(0); + int k1 = dynamic.get("WanderingTraderSpawnDelay").asInt(0); + int l1 = dynamic.get("WanderingTraderSpawnChance").asInt(0); - UUID uuid = (UUID) dynamic.get("WanderingTraderId").read(UUIDUtil.CODEC).result().orElse((Object) null); + UUID uuid = (UUID) dynamic.get("WanderingTraderId").read(UUIDUtil.CODEC).result().orElse(null); // CraftBukkit - decompile error Set set = (Set) dynamic.get("ServerBrands").asStream().flatMap((dynamic1) -> { return dynamic1.asString().result().stream(); }).collect(Collectors.toCollection(Sets::newLinkedHashSet)); -@@ -147,7 +174,7 @@ +@@ -145,7 +172,7 @@ }).collect(Collectors.toSet()); CustomFunctionCallbackTimerQueue customfunctioncallbacktimerqueue = new CustomFunctionCallbackTimerQueue<>(CustomFunctionCallbackTimers.SERVER_CALLBACKS, dynamic.get("ScheduledEvents").asStream()); NBTTagCompound nbttagcompound1 = (NBTTagCompound) dynamic.get("CustomBossEvents").orElseEmptyMap().getValue(); @@ -68,16 +68,16 @@ Logger logger = WorldDataServer.LOGGER; Objects.requireNonNull(logger); -@@ -182,7 +209,7 @@ +@@ -180,7 +207,7 @@ nbttagcompound.put("Version", nbttagcompound2); GameProfileSerializer.addCurrentDataVersion(nbttagcompound); - DynamicOps dynamicops = RegistryOps.create(DynamicOpsNBT.INSTANCE, (HolderLookup.b) iregistrycustom); + 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 Logger logger = WorldDataServer.LOGGER; Objects.requireNonNull(logger); -@@ -234,11 +261,13 @@ +@@ -230,11 +257,13 @@ nbttagcompound.putUUID("WanderingTraderId", this.wanderingTraderId); } @@ -92,7 +92,7 @@ Objects.requireNonNull(nbttaglist); stream.forEach(nbttaglist::add); -@@ -346,6 +375,20 @@ +@@ -310,6 +339,20 @@ @Override public void setThundering(boolean flag) { @@ -113,7 +113,7 @@ this.thundering = flag; } -@@ -366,6 +409,20 @@ +@@ -330,6 +373,20 @@ @Override public void setRaining(boolean flag) { @@ -134,7 +134,7 @@ this.raining = flag; } -@@ -432,6 +489,12 @@ +@@ -396,6 +453,12 @@ @Override public void setDifficulty(EnumDifficulty enumdifficulty) { this.settings = this.settings.withDifficulty(enumdifficulty); @@ -147,7 +147,7 @@ } @Override -@@ -568,6 +631,14 @@ +@@ -532,6 +595,14 @@ return this.settings.copy(); } diff --git a/paper-server/nms-patches/net/minecraft/world/level/storage/WorldNBTStorage.patch b/paper-server/nms-patches/net/minecraft/world/level/storage/WorldNBTStorage.patch index 246fcf9fad..b2b4b4bd3d 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/storage/WorldNBTStorage.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/storage/WorldNBTStorage.patch @@ -1,62 +1,101 @@ --- a/net/minecraft/world/level/storage/WorldNBTStorage.java +++ b/net/minecraft/world/level/storage/WorldNBTStorage.java -@@ -15,6 +15,13 @@ +@@ -15,8 +15,10 @@ + import net.minecraft.nbt.NBTCompressedStreamTools; + import net.minecraft.nbt.NBTReadLimiter; + import net.minecraft.nbt.NBTTagCompound; ++import net.minecraft.server.level.EntityPlayer; + import net.minecraft.util.datafix.DataFixTypes; import net.minecraft.world.entity.player.EntityHuman; ++import org.bukkit.craftbukkit.entity.CraftPlayer; import org.slf4j.Logger; -+// CraftBukkit start -+import java.io.FileInputStream; -+import java.io.InputStream; -+import net.minecraft.server.level.EntityPlayer; -+import org.bukkit.craftbukkit.entity.CraftPlayer; -+// CraftBukkit end -+ public class WorldNBTStorage { +@@ -49,34 +51,36 @@ - private static final Logger LOGGER = LogUtils.getLogger(); -@@ -59,6 +66,16 @@ + } + +- private void backup(EntityHuman entityhuman, String s) { ++ private void backup(String name, String s1, String s) { // name, uuid, extension + Path path = this.playerDir.toPath(); +- String s1 = entityhuman.getStringUUID(); ++ // String s1 = entityhuman.getStringUUID(); // CraftBukkit - used above + Path path1 = path.resolve(s1 + s); + +- s1 = entityhuman.getStringUUID(); ++ // s1 = entityhuman.getStringUUID(); // CraftBukkit - used above + Path path2 = path.resolve(s1 + "_corrupted_" + LocalDateTime.now().format(WorldNBTStorage.FORMATTER) + s); + + if (Files.isRegularFile(path1, new LinkOption[0])) { + try { + Files.copy(path1, path2, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); + } catch (Exception exception) { +- WorldNBTStorage.LOGGER.warn("Failed to copy the player.dat file for {}", entityhuman.getName().getString(), exception); ++ WorldNBTStorage.LOGGER.warn("Failed to copy the player.dat file for {}", name, exception); // CraftBukkit + } + + } + } + +- private Optional load(EntityHuman entityhuman, String s) { ++ // CraftBukkit start ++ private Optional load(String name, String s1, String s) { // name, uuid, extension ++ // CraftBukkit end + File file = this.playerDir; +- String s1 = entityhuman.getStringUUID(); ++ // String s1 = entityhuman.getStringUUID(); // CraftBukkit - used above + File file1 = new File(file, s1 + s); + + if (file1.exists() && file1.isFile()) { + try { + return Optional.of(NBTCompressedStreamTools.readCompressed(file1.toPath(), NBTReadLimiter.unlimitedHeap())); + } catch (Exception exception) { +- WorldNBTStorage.LOGGER.warn("Failed to load player data for {}", entityhuman.getName().getString()); ++ WorldNBTStorage.LOGGER.warn("Failed to load player data for {}", name); // CraftBukkit + } } - if (nbttagcompound != null) { -+ // CraftBukkit start +@@ -84,20 +88,44 @@ + } + + public Optional load(EntityHuman entityhuman) { +- Optional optional = this.load(entityhuman, ".dat"); ++ // CraftBukkit start ++ return load(entityhuman.getName().getString(), entityhuman.getStringUUID()).map((nbttagcompound) -> { + if (entityhuman instanceof EntityPlayer) { + CraftPlayer player = (CraftPlayer) entityhuman.getBukkitEntity(); + // Only update first played if it is older than the one we have -+ long modified = new File(this.playerDir, entityhuman.getUUID().toString() + ".dat").lastModified(); ++ long modified = new File(this.playerDir, entityhuman.getStringUUID() + ".dat").lastModified(); + if (modified < player.getFirstPlayed()) { + player.setFirstPlayed(modified); + } + } -+ // CraftBukkit end ++ ++ entityhuman.load(nbttagcompound); // From below ++ return nbttagcompound; ++ }); ++ } ++ ++ public Optional load(String name, String uuid) { ++ // CraftBukkit end ++ Optional optional = this.load(name, uuid, ".dat"); // CraftBukkit + + if (optional.isEmpty()) { +- this.backup(entityhuman, ".dat"); ++ this.backup(name, uuid, ".dat"); // CraftBukkit + } + + return optional.or(() -> { +- return this.load(entityhuman, ".dat_old"); ++ return this.load(name, uuid, ".dat_old"); // CraftBukkit + }).map((nbttagcompound) -> { int i = GameProfileSerializer.getDataVersion(nbttagcompound, -1); nbttagcompound = DataFixTypes.PLAYER.updateToCurrentVersion(this.fixerUpper, nbttagcompound, i); -@@ -68,6 +85,22 @@ - return nbttagcompound; - } - -+ // CraftBukkit start -+ public NBTTagCompound getPlayerData(String s) { -+ try { -+ File file1 = new File(this.playerDir, s + ".dat"); -+ -+ if (file1.exists()) { -+ return NBTCompressedStreamTools.readCompressed(file1.toPath(), NBTReadLimiter.unlimitedHeap()); -+ } -+ } catch (Exception exception) { -+ LOGGER.warn("Failed to load player data for " + s); -+ } -+ -+ return null; -+ } -+ // CraftBukkit end -+ - public String[] getSeenPlayers() { - String[] astring = this.playerDir.list(); - -@@ -83,4 +116,10 @@ - - return astring; +- entityhuman.load(nbttagcompound); ++ // entityhuman.load(nbttagcompound); // CraftBukkit - handled above + return nbttagcompound; + }); } + + // CraftBukkit start diff --git a/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootDataManager.patch b/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootDataManager.patch deleted file mode 100644 index 24e8aded70..0000000000 --- a/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootDataManager.patch +++ /dev/null @@ -1,48 +0,0 @@ ---- a/net/minecraft/world/level/storage/loot/LootDataManager.java -+++ b/net/minecraft/world/level/storage/loot/LootDataManager.java -@@ -22,6 +22,8 @@ - import net.minecraft.util.ProblemReporter; - import net.minecraft.util.profiling.GameProfilerFiller; - import net.minecraft.world.level.storage.loot.parameters.LootContextParameterSets; -+import org.bukkit.craftbukkit.CraftLootTable; -+import org.bukkit.craftbukkit.util.CraftNamespacedKey; - import org.slf4j.Logger; - - public class LootDataManager implements IReloadListener, LootDataResolver { -@@ -89,7 +91,7 @@ - @Nullable - @Override - public T getElement(LootDataId lootdataid) { -- return map1.get(lootdataid); -+ return (T) map1.get(lootdataid); // CraftBukkit - decompile error - } - }); - -@@ -99,18 +101,25 @@ - problemreporter_a.get().forEach((s, s1) -> { - LootDataManager.LOGGER.warn("Found loot table element validation problem in {}: {}", s, s1); - }); -+ // CraftBukkit start -+ map1.forEach((key, lootTable) -> { -+ if (object instanceof LootTable table) { -+ table.craftLootTable = new CraftLootTable(CraftNamespacedKey.fromMinecraft(key.location()), table); -+ } -+ }); -+ // CraftBukkit end - this.elements = map1; - this.typeKeys = com_google_common_collect_immutablemultimap_builder.build(); - } - - private static void castAndValidate(LootCollector lootcollector, LootDataId lootdataid, Object object) { -- lootdataid.type().runValidation(lootcollector, lootdataid, object); -+ lootdataid.type().runValidation(lootcollector, lootdataid, (T) object); // CraftBukkit - decompile error - } - - @Nullable - @Override - public T getElement(LootDataId lootdataid) { -- return this.elements.get(lootdataid); -+ return (T) this.elements.get(lootdataid); // CraftBukkit - decompile error - } - - public Collection getKeys(LootDataType lootdatatype) { 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 new file mode 100644 index 0000000000..18a93d4ca2 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/level/storage/loot/LootDataType.patch @@ -0,0 +1,22 @@ +--- a/net/minecraft/world/level/storage/loot/LootDataType.java ++++ b/net/minecraft/world/level/storage/loot/LootDataType.java +@@ -16,6 +16,11 @@ + import net.minecraft.world.level.storage.loot.predicates.LootItemConditions; + import org.slf4j.Logger; + ++// CraftBukkit start ++import org.bukkit.craftbukkit.CraftLootTable; ++import org.bukkit.craftbukkit.util.CraftNamespacedKey; ++// CraftBukkit end ++ + public record LootDataType(ResourceKey> registryKey, Codec codec, String directory, LootDataType.a validator) { + + private static final Logger LOGGER = LogUtils.getLogger(); +@@ -49,6 +54,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.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 57ca9b550b..94f9f0da52 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 @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/storage/loot/LootTable.java +++ b/net/minecraft/world/level/storage/loot/LootTable.java -@@ -29,6 +29,13 @@ +@@ -31,6 +31,13 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParameterSets; import org.slf4j.Logger; @@ -14,7 +14,7 @@ public class LootTable { private static final Logger LOGGER = LogUtils.getLogger(); -@@ -50,6 +57,7 @@ +@@ -54,6 +61,7 @@ private final List pools; private final List functions; private final BiFunction compositeFunction; @@ -22,7 +22,7 @@ LootTable(LootContextParameterSet lootcontextparameterset, Optional optional, List list, List list1) { this.paramSet = lootcontextparameterset; -@@ -149,9 +157,22 @@ +@@ -153,9 +161,22 @@ } public void fill(IInventory iinventory, LootParams lootparams, long i) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/storage/loot/predicates/LootItemConditionRandomChanceWithLooting.patch b/paper-server/nms-patches/net/minecraft/world/level/storage/loot/predicates/LootItemConditionRandomChanceWithLooting.patch index c14edd2391..48c94f6177 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/storage/loot/predicates/LootItemConditionRandomChanceWithLooting.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/storage/loot/predicates/LootItemConditionRandomChanceWithLooting.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/level/storage/loot/predicates/LootItemConditionRandomChanceWithLooting.java +++ b/net/minecraft/world/level/storage/loot/predicates/LootItemConditionRandomChanceWithLooting.java -@@ -34,6 +34,11 @@ +@@ -35,6 +35,11 @@ if (entity instanceof EntityLiving) { i = EnchantmentManager.getMobLooting((EntityLiving) entity); } diff --git a/paper-server/pom.xml b/paper-server/pom.xml index f6978dd080..65840c1fb8 100644 --- a/paper-server/pom.xml +++ b/paper-server/pom.xml @@ -4,7 +4,7 @@ org.bukkit craftbukkit jar - 1.20.4-R0.1-SNAPSHOT + 1.20.5-R0.1-SNAPSHOT CraftBukkit https://www.spigotmc.org/ @@ -13,9 +13,8 @@ UTF-8 unknown git - 1_20_R3 - 17 - 17 + 1_20_R4 + 21 @@ -48,7 +47,7 @@ org.apache.logging.log4j log4j-iostreams - 2.19.0 + 2.22.1 compile @@ -61,13 +60,13 @@ com.github.oshi oshi-core - 6.4.5 + 6.4.10 compile com.mojang authlib - 5.0.51 + 6.0.54 compile @@ -79,19 +78,19 @@ com.mojang datafixerupper - 6.0.8 + 7.0.14 compile com.mojang logging - 1.1.1 + 1.2.7 compile commons-io commons-io - 2.13.0 + 2.15.1 compile @@ -165,13 +164,13 @@ net.java.dev.jna jna - 5.13.0 + 5.14.0 compile net.java.dev.jna jna-platform - 5.13.0 + 5.14.0 compile @@ -183,25 +182,31 @@ org.apache.commons commons-lang3 - 3.13.0 + 3.14.0 compile org.apache.logging.log4j log4j-core - 2.19.0 + 2.22.1 compile org.apache.logging.log4j log4j-slf4j2-impl - 2.19.0 + 2.22.1 compile org.slf4j slf4j-api - 2.0.7 + 2.0.9 + compile + + + org.lz4 + lz4-java + 1.8.0 compile @@ -227,13 +232,13 @@ org.xerial sqlite-jdbc - 3.42.0.1 + 3.45.3.0 runtime com.mysql mysql-connector-j - 8.2.0 + 8.3.0 runtime @@ -470,7 +475,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.11.0 + 3.13.0 eclipse @@ -481,7 +486,7 @@ org.codehaus.plexus plexus-compiler-eclipse - 2.13.0 + 2.15.0 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 447b0ef691..dfe09d8858 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunk.java @@ -25,12 +25,12 @@ import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.chunk.ChunkSection; -import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.chunk.DataPaletteBlock; import net.minecraft.world.level.chunk.IChunkAccess; 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.entity.PersistentEntitySectionManager; @@ -315,8 +315,8 @@ public class CraftChunk implements Chunk { 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()).get().left().get()); - sectionBlockIDs[i] = ChunkRegionLoader.BLOCK_STATE_CODEC.parse(DynamicOpsNBT.INSTANCE, data.getCompound("block_states")).get().left().get(); + 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); LevelLightEngine lightengine = worldServer.getLightEngine(); NibbleArray skyLightArray = lightengine.getLayerListener(EnumSkyBlock.SKY).getDataLayerData(SectionPosition.of(x, chunk.getSectionYFromSectionIndex(i), z)); // SPIGOT-7498: Convert section index @@ -335,8 +335,8 @@ public class CraftChunk implements Chunk { } if (biome != null) { - data.put("biomes", biomeCodec.encodeStart(DynamicOpsNBT.INSTANCE, cs[i].getBiomes()).get().left().get()); - biome[i] = biomeCodec.parse(DynamicOpsNBT.INSTANCE, data.getCompound("biomes")).get().left().get(); + data.put("biomes", biomeCodec.encodeStart(DynamicOpsNBT.INSTANCE, cs[i].getBiomes()).getOrThrow()); + biome[i] = biomeCodec.parse(DynamicOpsNBT.INSTANCE, data.getCompound("biomes")).getOrThrow(ChunkRegionLoader.a::new); } } @@ -415,7 +415,7 @@ 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()).get().left().get()).get().left().get(); + biome[i] = (DataPaletteBlock>) biomeCodec.parse(DynamicOpsNBT.INSTANCE, biomeCodec.encodeStart(DynamicOpsNBT.INSTANCE, actual.getSection(i).getBiomes()).getOrThrow()).getOrThrow(ChunkRegionLoader.a::new); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEffect.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEffect.java index a451976217..71733f918e 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEffect.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEffect.java @@ -10,7 +10,6 @@ import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.block.CraftBlockType; import org.bukkit.craftbukkit.inventory.CraftItemType; -import org.bukkit.potion.Potion; public class CraftEffect { public static int getDataValue(Effect effect, T data) { @@ -20,8 +19,6 @@ public class CraftEffect { datavalue = (Integer) data; break; case POTION_BREAK: - datavalue = ((Potion) data).toDamageValue() & 0x3F; - break; case INSTANT_POTION_BREAK: datavalue = ((Color) data).asRGB(); break; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java index b89017dffa..e379616d94 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java @@ -1,7 +1,9 @@ package org.bukkit.craftbukkit; +import java.util.Locale; import net.minecraft.world.EnumHand; import net.minecraft.world.entity.EnumItemSlot; +import net.minecraft.world.entity.EquipmentSlotGroup; import org.bukkit.inventory.EquipmentSlot; public class CraftEquipmentSlot { @@ -16,6 +18,7 @@ public class CraftEquipmentSlot { set(EquipmentSlot.LEGS, EnumItemSlot.LEGS); set(EquipmentSlot.CHEST, EnumItemSlot.CHEST); set(EquipmentSlot.HEAD, EnumItemSlot.HEAD); + set(EquipmentSlot.BODY, EnumItemSlot.BODY); } private static void set(EquipmentSlot type, EnumItemSlot value) { @@ -27,10 +30,18 @@ public class CraftEquipmentSlot { return enums[nms.ordinal()]; } + public static org.bukkit.inventory.EquipmentSlotGroup getSlot(EquipmentSlotGroup nms) { + return org.bukkit.inventory.EquipmentSlotGroup.getByName(nms.getSerializedName()); + } + public static EnumItemSlot getNMS(EquipmentSlot slot) { return slots[slot.ordinal()]; } + public static EquipmentSlotGroup getNMSGroup(org.bukkit.inventory.EquipmentSlotGroup slot) { + return EquipmentSlotGroup.valueOf(slot.toString().toUpperCase(Locale.ROOT)); + } + public static EquipmentSlot getHand(EnumHand enumhand) { return (enumhand == EnumHand.MAIN_HAND) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND; } 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 ddfd219dda..31cd586b39 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLootTable.java @@ -5,6 +5,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Random; +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.world.IInventory; import net.minecraft.world.entity.Entity; @@ -16,6 +19,7 @@ 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; import org.bukkit.Location; import org.bukkit.NamespacedKey; import org.bukkit.craftbukkit.entity.CraftEntity; @@ -23,12 +27,33 @@ import org.bukkit.craftbukkit.entity.CraftHumanEntity; import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.util.CraftLocation; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.loot.LootContext; public class CraftLootTable implements org.bukkit.loot.LootTable { + public static org.bukkit.loot.LootTable minecraftToBukkit(MinecraftKey minecraft) { + return (minecraft == null) ? null : Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(minecraft)); + } + + public static org.bukkit.loot.LootTable minecraftToBukkit(ResourceKey minecraft) { + return (minecraft == null) ? null : Bukkit.getLootTable(minecraftToBukkitKey(minecraft)); + } + + public static NamespacedKey minecraftToBukkitKey(ResourceKey minecraft) { + return (minecraft == null) ? null : CraftNamespacedKey.fromMinecraft(minecraft.location()); + } + + public static ResourceKey bukkitToMinecraft(org.bukkit.loot.LootTable table) { + return (table == null) ? null : bukkitKeyToMinecraft(table.getKey()); + } + + public static ResourceKey bukkitKeyToMinecraft(NamespacedKey key) { + return (key == null) ? null : ResourceKey.create(Registries.LOOT_TABLE, CraftNamespacedKey.toMinecraft(key)); + } + private final LootTable handle; private final NamespacedKey key; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMusicInstrument.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMusicInstrument.java index 69f6539c5c..7d1dc46fc5 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMusicInstrument.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMusicInstrument.java @@ -1,5 +1,8 @@ package org.bukkit.craftbukkit; +import com.google.common.base.Preconditions; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; import net.minecraft.core.registries.Registries; import net.minecraft.world.item.Instrument; import org.bukkit.MusicInstrument; @@ -14,10 +17,27 @@ public class CraftMusicInstrument extends MusicInstrument implements Handleable< return CraftRegistry.minecraftToBukkit(minecraft, Registries.INSTRUMENT, Registry.INSTRUMENT); } + public static MusicInstrument minecraftHolderToBukkit(Holder minecraft) { + return minecraftToBukkit(minecraft.value()); + } + public static Instrument bukkitToMinecraft(MusicInstrument bukkit) { return CraftRegistry.bukkitToMinecraft(bukkit); } + public static Holder bukkitToMinecraftHolder(MusicInstrument bukkit) { + Preconditions.checkArgument(bukkit != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.INSTRUMENT); + + 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 instrument without properly registering it."); + } + private final NamespacedKey key; private final Instrument handle; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java index 38e45dfb5e..a00765395e 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java @@ -199,7 +199,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa } private NBTTagCompound getData() { - return storage.getPlayerData(getUniqueId().toString()); + return storage.load(profile.getName(), profile.getId().toString()).orElse(null); } private NBTTagCompound getBukkitData() { 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 54033bc4d0..bdcd7403fe 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.Map; import java.util.function.BiFunction; import net.minecraft.core.IRegistry; +import net.minecraft.core.particles.ColorParticleOption; import net.minecraft.core.particles.DustColorTransitionOptions; import net.minecraft.core.particles.ParticleParam; import net.minecraft.core.particles.ParticleParamBlock; @@ -182,6 +183,13 @@ public abstract class CraftParticle implements Keyed { } }; + BiFunction, CraftParticle> colorFunction = (name, particle) -> new CraftParticle<>(name, particle, Color.class) { + @Override + public ParticleParam createParticleParam(Color color) { + return ColorParticleOption.create((net.minecraft.core.particles.Particle) particle, color.asARGB()); + } + }; + add("dust", dustOptionsFunction); add("item", itemStackFunction); add("block", blockDataFunction); @@ -191,6 +199,8 @@ public abstract class CraftParticle implements Keyed { add("sculk_charge", floatFunction); add("shriek", integerFunction); add("block_marker", blockDataFunction); + add("entity_effect", colorFunction); + add("dust_pillar", blockDataFunction); } private static void add(String name, BiFunction, CraftParticle> function) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRaid.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRaid.java index 22b39abf59..575b44d060 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRaid.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRaid.java @@ -36,14 +36,14 @@ public final class CraftRaid implements Raid { @Override public int getBadOmenLevel() { - return handle.badOmenLevel; + return handle.raidOmenLevel; } @Override public void setBadOmenLevel(int badOmenLevel) { - int max = handle.getMaxBadOmenLevel(); + int max = handle.getMaxRaidOmenLevel(); Preconditions.checkArgument(0 <= badOmenLevel && badOmenLevel <= max, "Bad Omen level must be between 0 and %s", max); - handle.badOmenLevel = badOmenLevel; + handle.raidOmenLevel = badOmenLevel; } @Override @@ -73,7 +73,7 @@ public final class CraftRaid implements Raid { @Override public int getTotalGroups() { - return handle.numGroups + (handle.badOmenLevel > 1 ? 1 : 0); + return handle.numGroups + (handle.raidOmenLevel > 1 ? 1 : 0); } @Override 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 2a5c17001e..97b27c682a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java @@ -432,7 +432,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, null); + ((EntityInsentient) entity).finalizeSpawn(getHandle(), getHandle().getCurrentDifficultyAt(entity.blockPosition()), EnumMobSpawn.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 9ccb0003f6..4c3804463a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.Map; import java.util.function.BiFunction; import java.util.stream.Stream; +import net.minecraft.core.Holder; import net.minecraft.core.IRegistry; import net.minecraft.core.IRegistryCustom; import net.minecraft.core.registries.BuiltInRegistries; @@ -85,6 +86,19 @@ public class CraftRegistry implements Registry { return ((Handleable) bukkit).getHandle(); } + public static Holder bukkitToMinecraftHolder(B bukkit, ResourceKey> registryKey) { + Preconditions.checkArgument(bukkit != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(registryKey); + + 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 registry entry with out properly registering it."); + } + /** * Note: Newly added registries should also be added to RegistriesArgumentProvider in the test package * 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 b0dad048fd..0e4d943ec9 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -49,6 +49,7 @@ import net.minecraft.commands.CommandListenerWrapper; 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; @@ -57,6 +58,7 @@ import net.minecraft.nbt.ReportedNbtException; import net.minecraft.resources.MinecraftKey; import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.ReloadableServerRegistries; import net.minecraft.server.ServerCommand; import net.minecraft.server.WorldLoader; import net.minecraft.server.bossevents.BossBattleCustom; @@ -105,13 +107,12 @@ import net.minecraft.world.level.levelgen.MobSpawnerPhantom; import net.minecraft.world.level.levelgen.WorldDimensions; import net.minecraft.world.level.levelgen.WorldOptions; import net.minecraft.world.level.material.FluidType; -import net.minecraft.world.level.saveddata.maps.MapIcon; +import net.minecraft.world.level.saveddata.maps.MapId; import net.minecraft.world.level.saveddata.maps.WorldMap; import net.minecraft.world.level.storage.Convertable; import net.minecraft.world.level.storage.LevelDataAndDimensions; import net.minecraft.world.level.storage.WorldDataServer; import net.minecraft.world.level.storage.WorldNBTStorage; -import net.minecraft.world.level.storage.loot.LootDataManager; import net.minecraft.world.level.validation.ContentValidationException; import net.minecraft.world.phys.Vec3D; import org.bukkit.BanList; @@ -178,13 +179,13 @@ import org.bukkit.craftbukkit.inventory.CraftStonecuttingRecipe; import org.bukkit.craftbukkit.inventory.RecipeIterator; import org.bukkit.craftbukkit.inventory.util.CraftInventoryCreator; import org.bukkit.craftbukkit.map.CraftMapColorCache; +import org.bukkit.craftbukkit.map.CraftMapCursor; import org.bukkit.craftbukkit.map.CraftMapView; import org.bukkit.craftbukkit.metadata.EntityMetadataStore; import org.bukkit.craftbukkit.metadata.PlayerMetadataStore; import org.bukkit.craftbukkit.metadata.WorldMetadataStore; import org.bukkit.craftbukkit.packs.CraftDataPackManager; import org.bukkit.craftbukkit.packs.CraftResourcePack; -import org.bukkit.craftbukkit.potion.CraftPotionBrewer; import org.bukkit.craftbukkit.profile.CraftPlayerProfile; import org.bukkit.craftbukkit.scheduler.CraftScheduler; import org.bukkit.craftbukkit.scoreboard.CraftCriteria; @@ -250,7 +251,6 @@ import org.bukkit.plugin.SimpleServicesManager; import org.bukkit.plugin.java.JavaPluginLoader; import org.bukkit.plugin.messaging.Messenger; import org.bukkit.plugin.messaging.StandardMessenger; -import org.bukkit.potion.Potion; import org.bukkit.profile.PlayerProfile; import org.bukkit.scheduler.BukkitWorker; import org.bukkit.scoreboard.Criteria; @@ -316,7 +316,7 @@ public final class CraftServer implements Server { } })); this.serverVersion = CraftServer.class.getPackage().getImplementationVersion(); - this.structureManager = new CraftStructureManager(console.getStructureManager()); + this.structureManager = new CraftStructureManager(console.getStructureManager(), console.registryAccess()); this.dataPackManager = new CraftDataPackManager(this.getServer().getPackRepository()); this.serverTickManager = new CraftServerTickManager(console.tickRateManager()); @@ -324,9 +324,6 @@ public final class CraftServer implements Server { CraftRegistry.setMinecraftRegistry(console.registryAccess()); - Potion.setPotionBrewer(new CraftPotionBrewer()); - // Ugly hack :( - if (!Main.useConsole) { getLogger().info("Console input is disabled due to --noconsole command argument"); } @@ -1131,12 +1128,13 @@ public final class CraftServer implements Server { WorldDataServer worlddata; WorldLoader.a worldloader_a = console.worldLoader; - IRegistry iregistry = worldloader_a.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM); + IRegistryCustom.Dimension iregistrycustom_dimension = worldloader_a.datapackDimensions(); + IRegistry iregistry = iregistrycustom_dimension.registryOrThrow(Registries.LEVEL_STEM); if (dynamic != null) { LevelDataAndDimensions leveldataanddimensions = Convertable.getLevelDataAndDimensions(dynamic, worldloader_a.dataConfiguration(), iregistry, worldloader_a.datapackWorldgen()); worlddata = (WorldDataServer) leveldataanddimensions.worldData(); - iregistry = leveldataanddimensions.dimensions().dimensions(); + iregistrycustom_dimension = leveldataanddimensions.dimensions().dimensionsRegistryAccess(); } else { WorldSettings worldsettings; WorldOptions worldoptions = new WorldOptions(creator.seed(), creator.generateStructures(), false); @@ -1151,14 +1149,15 @@ public final class CraftServer implements Server { Lifecycle lifecycle = worlddimensions_b.lifecycle().add(worldloader_a.datapackWorldgen().allRegistriesLifecycle()); worlddata = new WorldDataServer(worldsettings, worldoptions, worlddimensions_b.specialWorldProperty(), lifecycle); - iregistry = worlddimensions_b.dimensions(); + iregistrycustom_dimension = worlddimensions_b.dimensionsRegistryAccess(); } + iregistry = iregistrycustom_dimension.registryOrThrow(Registries.LEVEL_STEM); worlddata.customDimensions = iregistry; worlddata.checkName(name); worlddata.setModdedInfo(console.getServerModName(), console.getModdedStatus().shouldReportAsModified()); if (console.options.has("forceUpgrade")) { - net.minecraft.server.Main.forceUpgrade(worldSession, DataConverterRegistry.getDataFixer(), console.options.has("eraseCache"), () -> true, iregistry); + net.minecraft.server.Main.forceUpgrade(worldSession, DataConverterRegistry.getDataFixer(), console.options.has("eraseCache"), () -> true, iregistrycustom_dimension, console.options.has("recreateRegionFiles")); } long j = BiomeManager.obfuscateSeed(creator.seed()); @@ -1180,9 +1179,12 @@ public final class CraftServer implements Server { worldKey = ResourceKey.create(Registries.DIMENSION, new MinecraftKey(name.toLowerCase(java.util.Locale.ENGLISH))); } - WorldServer internal = (WorldServer) new WorldServer(console, console.executor, worldSession, worlddata, worldKey, worlddimension, getServer().progressListenerFactory.create(11), + // If set to not keep spawn in memory (changed from default) then adjust rule accordingly + if (!creator.keepSpawnInMemory()) { + worlddata.getGameRules().getRule(GameRules.RULE_SPAWN_CHUNK_RADIUS).set(0, null); + } + WorldServer internal = (WorldServer) new WorldServer(console, console.executor, worldSession, worlddata, worldKey, worlddimension, getServer().progressListenerFactory.create(worlddata.getGameRules().getInt(GameRules.RULE_SPAWN_CHUNK_RADIUS)), worlddata.isDebugWorld(), j, creator.environment() == Environment.NORMAL ? list : ImmutableList.of(), true, console.overworld().getRandomSequences(), creator.environment(), generator, biomeProvider); - internal.keepSpawnInMemory = creator.keepSpawnInMemory(); if (!(worlds.containsKey(name.toLowerCase(java.util.Locale.ENGLISH)))) { return null; @@ -1476,7 +1478,7 @@ public final class CraftServer implements Server { if (!itemstack2.isEmpty()) { if (itemstack1.isEmpty()) { inventoryCrafting.setItem(i, itemstack2); - } else if (net.minecraft.world.item.ItemStack.isSameItemSameTags(itemstack1, itemstack2)) { + } else if (net.minecraft.world.item.ItemStack.isSameItemSameComponents(itemstack1, itemstack2)) { itemstack2.grow(itemstack1.getCount()); inventoryCrafting.setItem(i, itemstack2); } else { @@ -1584,6 +1586,11 @@ public final class CraftServer implements Server { return this.getServer().enforceSecureProfile(); } + @Override + public boolean isAcceptingTransfers() { + return this.getServer().acceptsTransfers(); + } + @Override public boolean getHideOnlinePlayers() { return console.hidesOnlinePlayers(); @@ -1679,7 +1686,7 @@ public final class CraftServer implements Server { @Override @Deprecated public CraftMapView getMap(int id) { - WorldMap worldmap = console.getLevel(net.minecraft.world.level.World.OVERWORLD).getMapData("map_" + id); + WorldMap worldmap = console.getLevel(net.minecraft.world.level.World.OVERWORLD).getMapData(new MapId(id)); if (worldmap == null) { return null; } @@ -1692,8 +1699,9 @@ public final class CraftServer implements Server { net.minecraft.world.level.World minecraftWorld = ((CraftWorld) world).getHandle(); // creates a new map at world spawn with the scale of 3, with out tracking position and unlimited tracking - int newId = ItemWorldMap.createNewSavedData(minecraftWorld, minecraftWorld.getLevelData().getXSpawn(), minecraftWorld.getLevelData().getZSpawn(), 3, false, false, minecraftWorld.dimension()); - return minecraftWorld.getMapData(ItemWorldMap.makeKey(newId)).mapView; + BlockPosition spawn = minecraftWorld.getLevelData().getSpawnPos(); + MapId newId = ItemWorldMap.createNewSavedData(minecraftWorld, spawn.getX(), spawn.getZ(), 3, false, false, minecraftWorld.dimension()); + return minecraftWorld.getMapData(newId).mapView; } @Override @@ -1715,7 +1723,7 @@ public final class CraftServer implements Server { net.minecraft.world.item.ItemStack stack = ItemWorldMap.create(worldServer, structurePosition.getX(), structurePosition.getZ(), MapView.Scale.NORMAL.getValue(), true, true); ItemWorldMap.renderBiomePreviewMap(worldServer, stack); // "+" map ID taken from EntityVillager - ItemWorldMap.getSavedData(stack, worldServer).addTargetDecoration(stack, structurePosition, "+", MapIcon.Type.byIcon(structureType.getMapIcon().getValue())); + ItemWorldMap.getSavedData(stack, worldServer).addTargetDecoration(stack, structurePosition, "+", CraftMapCursor.CraftType.bukkitToMinecraftHolder(structureType.getMapIcon())); return CraftItemStack.asBukkitCopy(stack); } @@ -2435,8 +2443,8 @@ public final class CraftServer implements Server { public LootTable getLootTable(NamespacedKey key) { Preconditions.checkArgument(key != null, "NamespacedKey key cannot be null"); - LootDataManager registry = getServer().getLootData(); - return new CraftLootTable(key, registry.getLootTable(CraftNamespacedKey.toMinecraft(key))); + ReloadableServerRegistries.b registry = getServer().reloadableRegistries(); + return new CraftLootTable(key, registry.getLootTable(CraftLootTable.bukkitKeyToMinecraft(key))); } @Override 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 24f0c9432a..1b4808581c 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -61,9 +61,9 @@ import net.minecraft.world.level.GameRules; import net.minecraft.world.level.RayTrace; import net.minecraft.world.level.biome.BiomeBase; import net.minecraft.world.level.biome.Climate; -import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.chunk.IChunkAccess; import net.minecraft.world.level.chunk.ProtoChunkExtension; +import net.minecraft.world.level.chunk.status.ChunkStatus; import net.minecraft.world.level.levelgen.structure.StructureStart; import net.minecraft.world.level.storage.SavedFile; import net.minecraft.world.phys.AxisAlignedBB; @@ -334,7 +334,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { if (playerChunk == null) return false; playerChunk.getTickingChunkFuture().thenAccept(either -> { - either.left().ifPresent(chunk -> { + either.ifSuccess(chunk -> { List playersInRange = playerChunk.playerProvider.getPlayers(playerChunk.getPos(), false); if (playersInRange.isEmpty()) return; @@ -1318,19 +1318,15 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public boolean getKeepSpawnInMemory() { - return world.keepSpawnInMemory; + return getGameRuleValue(GameRule.SPAWN_RADIUS) > 0; } @Override public void setKeepSpawnInMemory(boolean keepLoaded) { - world.keepSpawnInMemory = keepLoaded; - // Grab the worlds spawn chunk - BlockPosition chunkcoordinates = this.world.getSharedSpawnPos(); if (keepLoaded) { - world.getChunkSource().addRegionTicket(TicketType.START, new ChunkCoordIntPair(chunkcoordinates), 11, Unit.INSTANCE); + setGameRule(GameRule.SPAWN_CHUNK_RADIUS, getGameRuleDefault(GameRule.SPAWN_CHUNK_RADIUS)); } else { - // TODO: doesn't work well if spawn changed.... - world.getChunkSource().removeRegionTicket(TicketType.START, new ChunkCoordIntPair(chunkcoordinates), 11, Unit.INSTANCE); + setGameRule(GameRule.SPAWN_CHUNK_RADIUS, 0); } } 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 614fcf9b65..26cb1bcb78 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/Main.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/Main.java @@ -122,6 +122,7 @@ public class Main { acceptsAll(asList("forceUpgrade"), "Whether to force a world upgrade"); acceptsAll(asList("eraseCache"), "Whether to force cache erase during world upgrade"); + acceptsAll(asList("recreateRegionFiles"), "Whether to recreate region files during world upgrade"); acceptsAll(asList("nogui"), "Disables the graphical console"); acceptsAll(asList("nojline"), "Disables jline and emulates the vanilla console"); @@ -200,11 +201,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/attribute/CraftAttribute.java b/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java index a6ca9fa0c3..7724ed7478 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttribute.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit.attribute; import com.google.common.base.Preconditions; +import net.minecraft.core.Holder; import net.minecraft.core.IRegistry; import net.minecraft.core.registries.Registries; import net.minecraft.world.entity.ai.attributes.AttributeBase; @@ -23,6 +24,10 @@ public class CraftAttribute { return bukkit; } + public static Attribute minecraftHolderToBukkit(Holder minecraft) { + return minecraftToBukkit(minecraft.value()); + } + public static Attribute stringToBukkit(String bukkit) { Preconditions.checkArgument(bukkit != null); @@ -35,4 +40,17 @@ public class CraftAttribute { return CraftRegistry.getMinecraftRegistry(Registries.ATTRIBUTE) .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); } + + public static Holder bukkitToMinecraftHolder(Attribute bukkit) { + Preconditions.checkArgument(bukkit != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.ATTRIBUTE); + + 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."); + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeInstance.java b/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeInstance.java index 15a184e1d1..a0d5e86980 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeInstance.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeInstance.java @@ -63,7 +63,7 @@ public class CraftAttributeInstance implements AttributeInstance { @Override public double getDefaultValue() { - return handle.getAttribute().getDefaultValue(); + return handle.getAttribute().value().getDefaultValue(); } public static net.minecraft.world.entity.ai.attributes.AttributeModifier convert(AttributeModifier bukkit) { @@ -71,10 +71,10 @@ public class CraftAttributeInstance implements AttributeInstance { } public static AttributeModifier convert(net.minecraft.world.entity.ai.attributes.AttributeModifier nms) { - return new AttributeModifier(nms.getId(), nms.name, nms.getAmount(), AttributeModifier.Operation.values()[nms.getOperation().ordinal()]); + return new AttributeModifier(nms.id(), nms.name, nms.amount(), AttributeModifier.Operation.values()[nms.operation().ordinal()]); } public static AttributeModifier convert(net.minecraft.world.entity.ai.attributes.AttributeModifier nms, EquipmentSlot slot) { - return new AttributeModifier(nms.getId(), nms.name, nms.getAmount(), AttributeModifier.Operation.values()[nms.getOperation().ordinal()], slot); + return new AttributeModifier(nms.id(), nms.name, nms.amount(), AttributeModifier.Operation.values()[nms.operation().ordinal()], slot); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java b/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java index f5bbaaa66c..063bcf5faf 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/attribute/CraftAttributeMap.java @@ -17,7 +17,7 @@ public class CraftAttributeMap implements Attributable { @Override public AttributeInstance getAttribute(Attribute attribute) { Preconditions.checkArgument(attribute != null, "attribute"); - net.minecraft.world.entity.ai.attributes.AttributeModifiable nms = handle.getInstance(CraftAttribute.bukkitToMinecraft(attribute)); + net.minecraft.world.entity.ai.attributes.AttributeModifiable nms = handle.getInstance(CraftAttribute.bukkitToMinecraftHolder(attribute)); return (nms == null) ? null : new CraftAttributeInstance(nms, attribute); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CapturedBlockState.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CapturedBlockState.java index 2027649c9c..618fddeee9 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CapturedBlockState.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CapturedBlockState.java @@ -2,8 +2,6 @@ package org.bukkit.craftbukkit.block; import net.minecraft.core.BlockPosition; import net.minecraft.util.RandomSource; -import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.animal.EntityBee; import net.minecraft.world.level.GeneratorAccessSeed; import net.minecraft.world.level.World; import net.minecraft.world.level.block.entity.TileEntity; @@ -63,9 +61,7 @@ public final class CapturedBlockState extends CraftBlockState { int j = 2 + random.nextInt(2); for (int k = 0; k < j; ++k) { - EntityBee entitybee = new EntityBee(EntityTypes.BEE, generatoraccessseed.getMinecraftWorld()); - - tileentitybeehive.addOccupantWithPresetTicks(entitybee, false, random.nextInt(599)); + tileentitybeehive.storeBee(TileEntityBeehive.c.create(random.nextInt(599))); } } // End copied block diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java index 12da5c8d75..90dc2f6484 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBanner.java @@ -3,17 +3,16 @@ package org.bukkit.craftbukkit.block; import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.List; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; import net.minecraft.world.item.EnumColor; import net.minecraft.world.level.block.BlockBannerAbstract; +import net.minecraft.world.level.block.entity.BannerPatternLayers; import net.minecraft.world.level.block.entity.TileEntityBanner; import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Banner; import org.bukkit.block.banner.Pattern; -import org.bukkit.block.banner.PatternType; +import org.bukkit.craftbukkit.block.banner.CraftPatternType; public class CraftBanner extends CraftBlockEntityState implements Banner { @@ -35,10 +34,10 @@ public class CraftBanner extends CraftBlockEntityState impleme base = DyeColor.getByWoolData((byte) ((BlockBannerAbstract) this.data.getBlock()).getColor().getId()); patterns = new ArrayList(); - if (banner.itemPatterns != null) { - for (int i = 0; i < banner.itemPatterns.size(); i++) { - NBTTagCompound p = (NBTTagCompound) banner.itemPatterns.get(i); - patterns.add(new Pattern(DyeColor.getByWoolData((byte) p.getInt("Color")), PatternType.getByIdentifier(p.getString("Pattern")))); + if (banner.getPatterns() != null) { + for (int i = 0; i < banner.getPatterns().layers().size(); i++) { + BannerPatternLayers.b p = banner.getPatterns().layers().get(i); + patterns.add(new Pattern(DyeColor.getByWoolData((byte) p.color().getId()), CraftPatternType.minecraftHolderToBukkit(p.pattern()))); } } } @@ -95,15 +94,12 @@ public class CraftBanner extends CraftBlockEntityState impleme banner.baseColor = EnumColor.byId(base.getWoolData()); - NBTTagList newPatterns = new NBTTagList(); + List newPatterns = new ArrayList<>(); for (Pattern p : patterns) { - NBTTagCompound compound = new NBTTagCompound(); - compound.putInt("Color", p.getColor().getWoolData()); - compound.putString("Pattern", p.getPattern().getIdentifier()); - newPatterns.add(compound); + newPatterns.add(new net.minecraft.world.level.block.entity.BannerPatternLayers.b(CraftPatternType.bukkitToMinecraftHolder(p.getPattern()), EnumColor.byId(p.getColor().getWoolData()))); } - banner.itemPatterns = newPatterns; + banner.setPatterns(new BannerPatternLayers(newPatterns)); } @Override 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 115056f830..6d2fb9c36e 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 @@ -59,7 +59,7 @@ public class CraftBeacon extends CraftBlockEntityState impleme @Override public void setPrimaryEffect(PotionEffectType effect) { - this.getSnapshot().primaryPower = (effect != null) ? CraftPotionEffectType.bukkitToMinecraft(effect) : null; + this.getSnapshot().primaryPower = (effect != null) ? CraftPotionEffectType.bukkitToMinecraftHolder(effect) : null; } @Override @@ -69,7 +69,7 @@ public class CraftBeacon extends CraftBlockEntityState impleme @Override public void setSecondaryEffect(PotionEffectType effect) { - this.getSnapshot().secondaryPower = (effect != null) ? CraftPotionEffectType.bukkitToMinecraft(effect) : null; + this.getSnapshot().secondaryPower = (effect != null) ? CraftPotionEffectType.bukkitToMinecraftHolder(effect) : null; } @Override @@ -85,12 +85,12 @@ public class CraftBeacon extends CraftBlockEntityState impleme @Override public boolean isLocked() { - return !this.getSnapshot().lockKey.key.isEmpty(); + return !this.getSnapshot().lockKey.key().isEmpty(); } @Override public String getLock() { - return this.getSnapshot().lockKey.key; + return this.getSnapshot().lockKey.key(); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java index 4586f18265..dd97621e5e 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBeehive.java @@ -83,7 +83,7 @@ public class CraftBeehive extends CraftBlockEntityState imple public void addEntity(Bee entity) { Preconditions.checkArgument(entity != null, "Entity must not be null"); - getSnapshot().addOccupant(((CraftBee) entity).getHandle(), false); + getSnapshot().addOccupant(((CraftBee) entity).getHandle()); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java index d1e3904bd8..20a227fded 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java @@ -1,9 +1,14 @@ package org.bukkit.craftbukkit.block; +import net.minecraft.core.IRegistryCustom; +import net.minecraft.core.component.DataComponentMap; +import net.minecraft.core.component.DataComponentPatch; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.PacketListenerPlayOut; import net.minecraft.network.protocol.game.PacketPlayOutTileEntityData; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.level.GeneratorAccess; import net.minecraft.world.level.block.entity.TileEntity; import org.bukkit.Location; import org.bukkit.World; @@ -39,27 +44,40 @@ public class CraftBlockEntityState extends CraftBlockState this.load(tileEntity); } + private IRegistryCustom getRegistryAccess() { + GeneratorAccess worldHandle = getWorldHandle(); + return (worldHandle != null) ? worldHandle.registryAccess() : MinecraftServer.getDefaultRegistryAccess(); + } + private T createSnapshot(T tileEntity) { if (tileEntity == null) { return null; } - NBTTagCompound nbtTagCompound = tileEntity.saveWithFullMetadata(); - T snapshot = (T) TileEntity.loadStatic(getPosition(), getHandle(), nbtTagCompound); + NBTTagCompound nbtTagCompound = tileEntity.saveWithFullMetadata(getRegistryAccess()); + T snapshot = (T) TileEntity.loadStatic(getPosition(), getHandle(), nbtTagCompound, getRegistryAccess()); return snapshot; } + public void applyComponents(DataComponentMap datacomponentmap, DataComponentPatch datacomponentpatch) { + snapshot.applyComponents(datacomponentmap, datacomponentpatch); + } + + public DataComponentMap collectComponents() { + return snapshot.collectComponents(); + } + // Loads the specified data into the snapshot TileEntity. public void loadData(NBTTagCompound nbtTagCompound) { - snapshot.load(nbtTagCompound); + snapshot.loadWithComponents(nbtTagCompound, getRegistryAccess()); load(snapshot); } // copies the TileEntity-specific data, retains the position private void copyData(T from, T to) { - NBTTagCompound nbtTagCompound = from.saveWithFullMetadata(); - to.load(nbtTagCompound); + NBTTagCompound nbtTagCompound = from.saveWithFullMetadata(getRegistryAccess()); + to.loadWithComponents(nbtTagCompound, getRegistryAccess()); } // gets the wrapped TileEntity @@ -84,7 +102,13 @@ public class CraftBlockEntityState extends CraftBlockState // update snapshot applyTo(snapshot); - return snapshot.saveWithFullMetadata(); + return snapshot.saveWithFullMetadata(getRegistryAccess()); + } + + public NBTTagCompound getSnapshotNBTWithoutComponents() { + NBTTagCompound nbt = getSnapshotNBT(); + snapshot.removeComponentsFromTag(nbt); + return nbt; } // copies the data of the given tile entity to this block state @@ -128,7 +152,7 @@ public class CraftBlockEntityState extends CraftBlockState @Nullable public Packet getUpdatePacket(@NotNull Location location) { - T vanillaTileEntitiy = (T) TileEntity.loadStatic(CraftLocation.toBlockPosition(location), getHandle(), getSnapshotNBT()); + T vanillaTileEntitiy = (T) TileEntity.loadStatic(CraftLocation.toBlockPosition(location), getHandle(), getSnapshotNBT(), getRegistryAccess()); return PacketPlayOutTileEntityData.create(vanillaTileEntitiy); } 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 3c095da61a..a1451a80c9 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 @@ -9,8 +9,11 @@ import java.util.Map; import java.util.function.BiFunction; import javax.annotation.Nullable; import net.minecraft.core.BlockPosition; +import net.minecraft.core.IRegistryCustom; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.GeneratorAccess; +import net.minecraft.world.level.IWorldReader; import net.minecraft.world.level.block.entity.BrushableBlockEntity; import net.minecraft.world.level.block.entity.CalibratedSculkSensorBlockEntity; import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity; @@ -54,6 +57,7 @@ import net.minecraft.world.level.block.entity.TileEntitySkull; import net.minecraft.world.level.block.entity.TileEntitySmoker; import net.minecraft.world.level.block.entity.TileEntityStructure; import net.minecraft.world.level.block.entity.TrialSpawnerBlockEntity; +import net.minecraft.world.level.block.entity.vault.VaultBlockEntity; import net.minecraft.world.level.block.piston.TileEntityPiston; import net.minecraft.world.level.block.state.IBlockData; import org.bukkit.Material; @@ -336,6 +340,7 @@ public final class CraftBlockStates { register(Material.TRAPPED_CHEST, CraftChest.class, CraftChest::new, TileEntityChestTrapped::new); register(Material.CRAFTER, CraftCrafter.class, CraftCrafter::new, CrafterBlockEntity::new); register(Material.TRIAL_SPAWNER, CraftTrialSpawner.class, CraftTrialSpawner::new, TrialSpawnerBlockEntity::new); + register(Material.VAULT, CraftVault.class, CraftVault::new, VaultBlockEntity::new); } private static void register(Material blockType, BlockStateFactory factory) { @@ -394,24 +399,34 @@ public final class CraftBlockStates { return blockState; } + @Deprecated public static BlockState getBlockState(Material material, @Nullable NBTTagCompound blockEntityTag) { - return getBlockState(BlockPosition.ZERO, material, blockEntityTag); + return getBlockState(MinecraftServer.getDefaultRegistryAccess(), BlockPosition.ZERO, material, blockEntityTag); } - public static BlockState getBlockState(BlockPosition blockPosition, Material material, @Nullable NBTTagCompound blockEntityTag) { + public static BlockState getBlockState(IWorldReader world, BlockPosition blockPosition, Material material, @Nullable NBTTagCompound blockEntityTag) { + return getBlockState(world.registryAccess(), blockPosition, material, blockEntityTag); + } + + public static BlockState getBlockState(IRegistryCustom registry, BlockPosition blockPosition, Material material, @Nullable NBTTagCompound blockEntityTag) { Preconditions.checkNotNull(material, "material is null"); IBlockData blockData = CraftBlockType.bukkitToMinecraft(material).defaultBlockState(); - return getBlockState(blockPosition, blockData, blockEntityTag); + return getBlockState(registry, blockPosition, blockData, blockEntityTag); } + @Deprecated public static BlockState getBlockState(IBlockData blockData, @Nullable NBTTagCompound blockEntityTag) { - return getBlockState(BlockPosition.ZERO, blockData, blockEntityTag); + return getBlockState(MinecraftServer.getDefaultRegistryAccess(), BlockPosition.ZERO, blockData, blockEntityTag); } - public static BlockState getBlockState(BlockPosition blockPosition, IBlockData blockData, @Nullable NBTTagCompound blockEntityTag) { + public static BlockState getBlockState(IWorldReader world, BlockPosition blockPosition, IBlockData blockData, @Nullable NBTTagCompound blockEntityTag) { + return getBlockState(world.registryAccess(), blockPosition, blockData, blockEntityTag); + } + + public static BlockState getBlockState(IRegistryCustom registry, BlockPosition blockPosition, IBlockData blockData, @Nullable NBTTagCompound blockEntityTag) { Preconditions.checkNotNull(blockPosition, "blockPosition is null"); Preconditions.checkNotNull(blockData, "blockData is null"); - TileEntity tileEntity = (blockEntityTag == null) ? null : TileEntity.loadStatic(blockPosition, blockData, blockEntityTag); + TileEntity tileEntity = (blockEntityTag == null) ? null : TileEntity.loadStatic(blockPosition, blockData, blockEntityTag, registry); return getBlockState(null, blockPosition, blockData, tileEntity); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBrushableBlock.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBrushableBlock.java index 6d3944dd11..6484fa6f56 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBrushableBlock.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBrushableBlock.java @@ -1,13 +1,11 @@ package org.bukkit.craftbukkit.block; -import net.minecraft.resources.MinecraftKey; import net.minecraft.world.level.block.entity.BrushableBlockEntity; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.BrushableBlock; +import org.bukkit.craftbukkit.CraftLootTable; import org.bukkit.craftbukkit.inventory.CraftItemStack; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.loot.LootTable; @@ -36,18 +34,13 @@ public class CraftBrushableBlock extends CraftBlockEntityState= 0.5F ? 0 : 1; + int j = ChiseledBookShelfBlock.getSection(vec2f.x); + + return j + i * 3; } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java index 0564ecd662..164d114801 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCommandBlock.java @@ -33,7 +33,7 @@ public class CraftCommandBlock extends CraftBlockEntityState @Override public void setName(String name) { - getSnapshot().getCommandBlock().setName(CraftChatMessage.fromStringOrNull(name != null ? name : "@")); + getSnapshot().getCommandBlock().setCustomName(CraftChatMessage.fromStringOrNull(name != null ? name : "@")); } @Override 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 675b742d3f..ff442beb20 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 @@ -19,12 +19,12 @@ public abstract class CraftContainer extends Craf @Override public boolean isLocked() { - return !this.getSnapshot().lockKey.key.isEmpty(); + return !this.getSnapshot().lockKey.key().isEmpty(); } @Override public String getLock() { - return this.getSnapshot().lockKey.key; + return this.getSnapshot().lockKey.key(); } @Override @@ -40,7 +40,7 @@ public abstract class CraftContainer extends Craf @Override public void setCustomName(String name) { - this.getSnapshot().setCustomName(CraftChatMessage.fromStringOrNull(name)); + this.getSnapshot().name = CraftChatMessage.fromStringOrNull(name); } @Override @@ -48,7 +48,7 @@ public abstract class CraftContainer extends Craf super.applyTo(container); if (this.getSnapshot().name == null) { - container.setCustomName(null); + container.name = null; } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java index 77e7cf2d54..16309e8152 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreatureSpawner.java @@ -3,14 +3,18 @@ package org.bukkit.craftbukkit.block; import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.stream.Collectors; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.InclusiveRange; import net.minecraft.util.RandomSource; import net.minecraft.util.random.SimpleWeightedRandomList; import net.minecraft.util.random.WeightedEntry.b; import net.minecraft.world.entity.EntityTypes; +import net.minecraft.world.entity.EquipmentTable; import net.minecraft.world.level.MobSpawnerData; import net.minecraft.world.level.block.entity.TileEntityMobSpawner; import org.bukkit.Location; @@ -18,6 +22,8 @@ import org.bukkit.World; import org.bukkit.block.CreatureSpawner; import org.bukkit.block.spawner.SpawnRule; import org.bukkit.block.spawner.SpawnerEntry; +import org.bukkit.craftbukkit.CraftEquipmentSlot; +import org.bukkit.craftbukkit.CraftLootTable; import org.bukkit.craftbukkit.entity.CraftEntitySnapshot; import org.bukkit.craftbukkit.entity.CraftEntityType; import org.bukkit.entity.EntitySnapshot; @@ -72,7 +78,7 @@ public class CraftCreatureSpawner extends CraftBlockEntityState builder = SimpleWeightedRandomList.builder(); // PAIL rename Builder - this.getSnapshot().getSpawner().spawnPotentials.unwrap().forEach(entry -> builder.add(entry.getData(), entry.getWeight().asInt())); - builder.add(new MobSpawnerData(compoundTag, Optional.ofNullable(toMinecraftRule(spawnRule))), weight); + this.getSnapshot().getSpawner().spawnPotentials.unwrap().forEach(entry -> builder.add(entry.data(), entry.getWeight().asInt())); + builder.add(new MobSpawnerData(compoundTag, Optional.ofNullable(toMinecraftRule(spawnRule)), Optional.empty()), weight); this.getSnapshot().getSpawner().spawnPotentials = builder.build(); } @@ -95,7 +101,7 @@ public class CraftCreatureSpawner extends CraftBlockEntityState builder = SimpleWeightedRandomList.builder(); for (SpawnerEntry spawnerEntry : entries) { NBTTagCompound compoundTag = ((CraftEntitySnapshot) spawnerEntry.getSnapshot()).getData(); - builder.add(new MobSpawnerData(compoundTag, Optional.ofNullable(toMinecraftRule(spawnerEntry.getSpawnRule()))), spawnerEntry.getSpawnWeight()); + builder.add(new MobSpawnerData(compoundTag, Optional.ofNullable(toMinecraftRule(spawnerEntry.getSpawnRule())), getEquipment(spawnerEntry.getEquipment())), spawnerEntry.getSpawnWeight()); } this.getSnapshot().getSpawner().spawnPotentials = builder.build(); } @@ -105,11 +111,11 @@ public class CraftCreatureSpawner extends CraftBlockEntityState entries = new ArrayList<>(); for (b entry : this.getSnapshot().getSpawner().spawnPotentials.unwrap()) { // PAIL rename Wrapper - CraftEntitySnapshot snapshot = CraftEntitySnapshot.create(entry.getData().getEntityToSpawn()); + CraftEntitySnapshot snapshot = CraftEntitySnapshot.create(entry.data().getEntityToSpawn()); if (snapshot != null) { - SpawnRule rule = entry.getData().customSpawnRules().map(this::fromMinecraftRule).orElse(null); - entries.add(new SpawnerEntry(snapshot, entry.getWeight().asInt(), rule)); + SpawnRule rule = entry.data().customSpawnRules().map(this::fromMinecraftRule).orElse(null); + entries.add(new SpawnerEntry(snapshot, entry.getWeight().asInt(), rule, getEquipment(entry.data().equipment()))); } } return entries; @@ -123,10 +129,10 @@ public class CraftCreatureSpawner extends CraftBlockEntityState blockLight = rule.blockLightLimit(); - InclusiveRange skyLight = rule.skyLightLimit(); + InclusiveRange blockLight = rule.blockLightLimit(); + InclusiveRange skyLight = rule.skyLightLimit(); - return new SpawnRule(blockLight.maxInclusive(), blockLight.maxInclusive(), skyLight.minInclusive(), skyLight.maxInclusive()); + return new SpawnRule(blockLight.maxInclusive(), blockLight.maxInclusive(), skyLight.minInclusive(), skyLight.maxInclusive()); } @Override @@ -233,4 +239,22 @@ public class CraftCreatureSpawner extends CraftBlockEntityState getEquipment(SpawnerEntry.Equipment bukkit) { + if (bukkit == null) { + return Optional.empty(); + } + + return Optional.of(new EquipmentTable( + CraftLootTable.bukkitToMinecraft(bukkit.getEquipmentLootTable()), + bukkit.getDropChances().entrySet().stream().collect(Collectors.toMap((entry) -> CraftEquipmentSlot.getNMS(entry.getKey()), Map.Entry::getValue))) + ); + } + + private static SpawnerEntry.Equipment getEquipment(Optional optional) { + return optional.map((nms) -> new SpawnerEntry.Equipment( + CraftLootTable.minecraftToBukkit(nms.lootTable()), + new HashMap<>(nms.slotDropChances().entrySet().stream().collect(Collectors.toMap((entry) -> CraftEquipmentSlot.getSlot(entry.getKey()), Map.Entry::getValue))) + )).orElse(null); + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftDecoratedPot.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftDecoratedPot.java index d809276a1d..703d4705d7 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftDecoratedPot.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftDecoratedPot.java @@ -4,10 +4,12 @@ import com.google.common.base.Preconditions; import java.util.EnumMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.entity.DecoratedPotBlockEntity; +import net.minecraft.world.level.block.entity.PotDecorations; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Tag; @@ -46,14 +48,14 @@ public class CraftDecoratedPot extends CraftBlockEntityState sherdItem = (sherd != null) ? Optional.of(CraftItemType.bukkitToMinecraft(sherd)) : Optional.of(Items.BRICK); + PotDecorations decorations = getSnapshot().getDecorations(); switch (face) { - case BACK -> getSnapshot().decorations = new DecoratedPotBlockEntity.Decoration(sherdItem, decorations.left(), decorations.right(), decorations.front()); - case LEFT -> getSnapshot().decorations = new DecoratedPotBlockEntity.Decoration(decorations.back(), sherdItem, decorations.right(), decorations.front()); - case RIGHT -> getSnapshot().decorations = new DecoratedPotBlockEntity.Decoration(decorations.back(), decorations.left(), sherdItem, decorations.front()); - case FRONT -> getSnapshot().decorations = new DecoratedPotBlockEntity.Decoration(decorations.back(), decorations.left(), decorations.right(), sherdItem); + case BACK -> getSnapshot().decorations = new PotDecorations(sherdItem, decorations.left(), decorations.right(), decorations.front()); + case LEFT -> getSnapshot().decorations = new PotDecorations(decorations.back(), sherdItem, decorations.right(), decorations.front()); + case RIGHT -> getSnapshot().decorations = new PotDecorations(decorations.back(), decorations.left(), sherdItem, decorations.front()); + case FRONT -> getSnapshot().decorations = new PotDecorations(decorations.back(), decorations.left(), decorations.right(), sherdItem); default -> throw new IllegalArgumentException("Unexpected value: " + face); } } @@ -62,8 +64,8 @@ public class CraftDecoratedPot extends CraftBlockEntityState sherdItem = switch (face) { case BACK -> decorations.back(); case LEFT -> decorations.left(); case RIGHT -> decorations.right(); @@ -71,24 +73,24 @@ public class CraftDecoratedPot extends CraftBlockEntityState throw new IllegalArgumentException("Unexpected value: " + face); }; - return CraftItemType.minecraftToBukkit(sherdItem); + return CraftItemType.minecraftToBukkit(sherdItem.orElse(Items.BRICK)); } @Override public Map getSherds() { - DecoratedPotBlockEntity.Decoration decorations = getSnapshot().getDecorations(); + PotDecorations decorations = getSnapshot().getDecorations(); Map sherds = new EnumMap<>(Side.class); - sherds.put(Side.BACK, CraftItemType.minecraftToBukkit(decorations.back())); - sherds.put(Side.LEFT, CraftItemType.minecraftToBukkit(decorations.left())); - sherds.put(Side.RIGHT, CraftItemType.minecraftToBukkit(decorations.right())); - sherds.put(Side.FRONT, CraftItemType.minecraftToBukkit(decorations.front())); + sherds.put(Side.BACK, CraftItemType.minecraftToBukkit(decorations.back().orElse(Items.BRICK))); + sherds.put(Side.LEFT, CraftItemType.minecraftToBukkit(decorations.left().orElse(Items.BRICK))); + sherds.put(Side.RIGHT, CraftItemType.minecraftToBukkit(decorations.right().orElse(Items.BRICK))); + sherds.put(Side.FRONT, CraftItemType.minecraftToBukkit(decorations.front().orElse(Items.BRICK))); return sherds; } @Override public List getShards() { - return getSnapshot().getDecorations().sorted().map(CraftItemType::minecraftToBukkit).collect(Collectors.toUnmodifiableList()); + return getSnapshot().getDecorations().ordered().stream().map(CraftItemType::minecraftToBukkit).collect(Collectors.toUnmodifiableList()); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java index 6714e7fa16..716cd98e10 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftLootable.java @@ -1,12 +1,10 @@ package org.bukkit.craftbukkit.block; -import net.minecraft.resources.MinecraftKey; import net.minecraft.world.level.block.entity.TileEntityLootable; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Nameable; import org.bukkit.World; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.craftbukkit.CraftLootTable; import org.bukkit.loot.LootTable; import org.bukkit.loot.Lootable; @@ -25,18 +23,13 @@ public abstract class CraftLootable extends CraftC super.applyTo(lootable); if (this.getSnapshot().lootTable == null) { - lootable.setLootTable((MinecraftKey) null, 0L); + lootable.setLootTable(null, 0L); } } @Override public LootTable getLootTable() { - if (getSnapshot().lootTable == null) { - return null; - } - - MinecraftKey key = getSnapshot().lootTable; - return Bukkit.getLootTable(CraftNamespacedKey.fromMinecraft(key)); + return CraftLootTable.minecraftToBukkit(getSnapshot().lootTable); } @Override @@ -55,8 +48,7 @@ public abstract class CraftLootable extends CraftC } private void setLootTable(LootTable table, long seed) { - MinecraftKey key = (table == null) ? null : CraftNamespacedKey.toMinecraft(table.getKey()); - getSnapshot().setLootTable(key, seed); + getSnapshot().setLootTable(CraftLootTable.bukkitToMinecraft(table), seed); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java index d8bbc75ac0..8edc23c8fb 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java @@ -5,6 +5,7 @@ import com.mojang.authlib.GameProfile; import net.minecraft.SystemUtils; import net.minecraft.resources.MinecraftKey; import net.minecraft.server.MinecraftServer; +import net.minecraft.world.item.component.ResolvableProfile; import net.minecraft.world.level.block.entity.TileEntitySkull; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -40,24 +41,9 @@ public class CraftSkull extends CraftBlockEntityState implement public void load(TileEntitySkull skull) { super.load(skull); - profile = skull.owner; - } - - static int getSkullType(SkullType type) { - switch (type) { - default: - case SKELETON: - return 0; - case WITHER: - return 1; - case ZOMBIE: - return 2; - case PLAYER: - return 3; - case CREEPER: - return 4; - case DRAGON: - return 5; + ResolvableProfile owner = skull.getOwnerProfile(); + if (owner != null) { + profile = owner.gameProfile(); } } @@ -201,7 +187,7 @@ public class CraftSkull extends CraftBlockEntityState implement super.applyTo(skull); if (getSkullType() == SkullType.PLAYER) { - skull.setOwner(profile); + skull.setOwner(new ResolvableProfile(profile)); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftVault.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftVault.java new file mode 100644 index 0000000000..fb3f9fc674 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftVault.java @@ -0,0 +1,27 @@ +package org.bukkit.craftbukkit.block; + +import net.minecraft.world.level.block.entity.vault.VaultBlockEntity; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.TrialSpawner; + +public class CraftVault extends CraftBlockEntityState implements TrialSpawner { + + public CraftVault(World world, VaultBlockEntity tileEntity) { + super(world, tileEntity); + } + + protected CraftVault(CraftVault state, Location location) { + super(state, location); + } + + @Override + public CraftVault copy() { + return new CraftVault(this, null); + } + + @Override + public CraftVault copy(Location location) { + return new CraftVault(this, location); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/banner/CraftPatternType.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/banner/CraftPatternType.java new file mode 100644 index 0000000000..d87ba9f718 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/banner/CraftPatternType.java @@ -0,0 +1,49 @@ +package org.bukkit.craftbukkit.block.banner; + +import com.google.common.base.Preconditions; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.level.block.entity.EnumBannerPatternType; +import org.bukkit.Registry; +import org.bukkit.block.banner.PatternType; +import org.bukkit.craftbukkit.CraftRegistry; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; + +public class CraftPatternType { + + public static PatternType minecraftToBukkit(EnumBannerPatternType minecraft) { + Preconditions.checkArgument(minecraft != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.BANNER_PATTERN); + PatternType bukkit = Registry.BANNER_PATTERN.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location())); + + Preconditions.checkArgument(bukkit != null); + + return bukkit; + } + + public static PatternType minecraftHolderToBukkit(Holder minecraft) { + return minecraftToBukkit(minecraft.value()); + } + + public static EnumBannerPatternType bukkitToMinecraft(PatternType bukkit) { + Preconditions.checkArgument(bukkit != null); + + return CraftRegistry.getMinecraftRegistry(Registries.BANNER_PATTERN) + .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); + } + + public static Holder bukkitToMinecraftHolder(PatternType bukkit) { + Preconditions.checkArgument(bukkit != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.BANNER_PATTERN); + + 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 banner pattern without properly registering it."); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java index ffbe9b3958..34a8e54fc0 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java @@ -13,7 +13,6 @@ import net.minecraft.commands.arguments.blocks.ArgumentBlock; import net.minecraft.core.BlockPosition; import net.minecraft.core.EnumDirection; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.INamable; import net.minecraft.world.level.BlockAccessAir; import net.minecraft.world.level.block.Block; @@ -251,13 +250,13 @@ public class CraftBlockData implements BlockData { return stateString.toString(); } - public NBTTagCompound toStates() { - NBTTagCompound compound = new NBTTagCompound(); + public Map toStates() { + Map compound = new HashMap<>(); for (Map.Entry, Comparable> entry : state.getValues().entrySet()) { IBlockState iblockstate = (IBlockState) entry.getKey(); - compound.putString(iblockstate.getName(), iblockstate.getName(entry.getValue())); + compound.put(iblockstate.getName(), iblockstate.getName(entry.getValue())); } return compound; @@ -501,6 +500,7 @@ public class CraftBlockData implements BlockData { register(net.minecraft.world.level.block.EquipableCarvedPumpkinBlock.class, org.bukkit.craftbukkit.block.impl.CraftEquipableCarvedPumpkin::new); register(net.minecraft.world.level.block.GlowLichenBlock.class, org.bukkit.craftbukkit.block.impl.CraftGlowLichen::new); register(net.minecraft.world.level.block.HangingRootsBlock.class, org.bukkit.craftbukkit.block.impl.CraftHangingRoots::new); + register(net.minecraft.world.level.block.HeavyCoreBlock.class, org.bukkit.craftbukkit.block.impl.CraftHeavyCore::new); register(net.minecraft.world.level.block.InfestedRotatedPillarBlock.class, org.bukkit.craftbukkit.block.impl.CraftInfestedRotatedPillar::new); register(net.minecraft.world.level.block.LayeredCauldronBlock.class, org.bukkit.craftbukkit.block.impl.CraftLayeredCauldron::new); register(net.minecraft.world.level.block.LightBlock.class, org.bukkit.craftbukkit.block.impl.CraftLight::new); @@ -521,6 +521,7 @@ public class CraftBlockData implements BlockData { register(net.minecraft.world.level.block.TallSeagrassBlock.class, org.bukkit.craftbukkit.block.impl.CraftTallSeagrass::new); register(net.minecraft.world.level.block.TorchflowerCropBlock.class, org.bukkit.craftbukkit.block.impl.CraftTorchflowerCrop::new); register(net.minecraft.world.level.block.TrialSpawnerBlock.class, org.bukkit.craftbukkit.block.impl.CraftTrialSpawner::new); + register(net.minecraft.world.level.block.VaultBlock.class, org.bukkit.craftbukkit.block.impl.CraftVault::new); register(net.minecraft.world.level.block.WallHangingSignBlock.class, org.bukkit.craftbukkit.block.impl.CraftWallHangingSign::new); register(net.minecraft.world.level.block.WaterloggedTransparentBlock.class, org.bukkit.craftbukkit.block.impl.CraftWaterloggedTransparent::new); register(net.minecraft.world.level.block.WeatheringCopperBulbBlock.class, org.bukkit.craftbukkit.block.impl.CraftWeatheringCopperBulb::new); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftTrialSpawner.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftTrialSpawner.java index 482a6c58d5..e212c5be52 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftTrialSpawner.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftTrialSpawner.java @@ -6,6 +6,7 @@ import org.bukkit.craftbukkit.block.data.CraftBlockData; public abstract class CraftTrialSpawner extends CraftBlockData implements TrialSpawner { private static final net.minecraft.world.level.block.state.properties.BlockStateEnum TRIAL_SPAWNER_STATE = getEnum("trial_spawner_state"); + private static final net.minecraft.world.level.block.state.properties.BlockStateBoolean OMINOUS = getBoolean("ominous"); @Override public org.bukkit.block.data.type.TrialSpawner.State getTrialSpawnerState() { @@ -16,4 +17,14 @@ public abstract class CraftTrialSpawner extends CraftBlockData implements TrialS public void setTrialSpawnerState(org.bukkit.block.data.type.TrialSpawner.State state) { set(TRIAL_SPAWNER_STATE, state); } + + @Override + public boolean isOminous() { + return get(OMINOUS); + } + + @Override + public void setOminous(boolean ominous) { + set(OMINOUS, ominous); + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftVault.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftVault.java new file mode 100644 index 0000000000..4210dd38f7 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/type/CraftVault.java @@ -0,0 +1,30 @@ +package org.bukkit.craftbukkit.block.data.type; + +import org.bukkit.block.data.type.Vault; +import org.bukkit.craftbukkit.block.data.CraftBlockData; + +public abstract class CraftVault extends CraftBlockData implements Vault { + + private static final net.minecraft.world.level.block.state.properties.BlockStateEnum VAULT_STATE = getEnum("vault_state"); + private static final net.minecraft.world.level.block.state.properties.BlockStateBoolean OMINOUS = getBoolean("ominous"); + + @Override + public org.bukkit.block.data.type.Vault.State getTrialSpawnerState() { + return get(VAULT_STATE, org.bukkit.block.data.type.Vault.State.class); + } + + @Override + public void setTrialSpawnerState(org.bukkit.block.data.type.Vault.State state) { + set(VAULT_STATE, state); + } + + @Override + public boolean isOminous() { + return get(OMINOUS); + } + + @Override + public void setOminous(boolean ominous) { + set(OMINOUS, ominous); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftHeavyCore.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftHeavyCore.java new file mode 100644 index 0000000000..364f7dbc10 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftHeavyCore.java @@ -0,0 +1,29 @@ +/** + * Automatically generated file, changes will be lost. + */ +package org.bukkit.craftbukkit.block.impl; + +public final class CraftHeavyCore extends org.bukkit.craftbukkit.block.data.CraftBlockData implements org.bukkit.block.data.Waterlogged { + + public CraftHeavyCore() { + super(); + } + + public CraftHeavyCore(net.minecraft.world.level.block.state.IBlockData state) { + super(state); + } + + // org.bukkit.craftbukkit.block.data.CraftWaterlogged + + private static final net.minecraft.world.level.block.state.properties.BlockStateBoolean WATERLOGGED = getBoolean(net.minecraft.world.level.block.HeavyCoreBlock.class, "waterlogged"); + + @Override + public boolean isWaterlogged() { + return get(WATERLOGGED); + } + + @Override + public void setWaterlogged(boolean waterlogged) { + set(WATERLOGGED, waterlogged); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftTrialSpawner.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftTrialSpawner.java index 07c4199fc8..298f703272 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftTrialSpawner.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftTrialSpawner.java @@ -16,6 +16,7 @@ public final class CraftTrialSpawner extends org.bukkit.craftbukkit.block.data.C // org.bukkit.craftbukkit.block.data.type.CraftTrialSpawner private static final net.minecraft.world.level.block.state.properties.BlockStateEnum TRIAL_SPAWNER_STATE = getEnum(net.minecraft.world.level.block.TrialSpawnerBlock.class, "trial_spawner_state"); + private static final net.minecraft.world.level.block.state.properties.BlockStateBoolean OMINOUS = getBoolean(net.minecraft.world.level.block.TrialSpawnerBlock.class, "ominous"); @Override public org.bukkit.block.data.type.TrialSpawner.State getTrialSpawnerState() { @@ -26,4 +27,14 @@ public final class CraftTrialSpawner extends org.bukkit.craftbukkit.block.data.C public void setTrialSpawnerState(org.bukkit.block.data.type.TrialSpawner.State state) { set(TRIAL_SPAWNER_STATE, state); } + + @Override + public boolean isOminous() { + return get(OMINOUS); + } + + @Override + public void setOminous(boolean ominous) { + set(OMINOUS, ominous); + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftVault.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftVault.java new file mode 100644 index 0000000000..da8e9eb33d --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/impl/CraftVault.java @@ -0,0 +1,59 @@ +/** + * Automatically generated file, changes will be lost. + */ +package org.bukkit.craftbukkit.block.impl; + +public final class CraftVault extends org.bukkit.craftbukkit.block.data.CraftBlockData implements org.bukkit.block.data.type.Vault, org.bukkit.block.data.Directional { + + public CraftVault() { + super(); + } + + public CraftVault(net.minecraft.world.level.block.state.IBlockData state) { + super(state); + } + + // org.bukkit.craftbukkit.block.data.type.CraftVault + + private static final net.minecraft.world.level.block.state.properties.BlockStateEnum VAULT_STATE = getEnum(net.minecraft.world.level.block.VaultBlock.class, "vault_state"); + private static final net.minecraft.world.level.block.state.properties.BlockStateBoolean OMINOUS = getBoolean(net.minecraft.world.level.block.VaultBlock.class, "ominous"); + + @Override + public org.bukkit.block.data.type.Vault.State getTrialSpawnerState() { + return get(VAULT_STATE, org.bukkit.block.data.type.Vault.State.class); + } + + @Override + public void setTrialSpawnerState(org.bukkit.block.data.type.Vault.State state) { + set(VAULT_STATE, state); + } + + @Override + public boolean isOminous() { + return get(OMINOUS); + } + + @Override + public void setOminous(boolean ominous) { + set(OMINOUS, ominous); + } + + // org.bukkit.craftbukkit.block.data.CraftDirectional + + private static final net.minecraft.world.level.block.state.properties.BlockStateEnum FACING = getEnum(net.minecraft.world.level.block.VaultBlock.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/enchantments/CraftEnchantment.java b/paper-server/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java index a0ae7f4c8f..4b9b832c42 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/enchantments/CraftEnchantment.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit.enchantments; +import net.minecraft.core.Holder; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.world.item.enchantment.EnchantmentBinding; @@ -20,6 +21,10 @@ public class CraftEnchantment extends Enchantment implements Handleable minecraft) { + return minecraftToBukkit(minecraft.value()); + } + public static net.minecraft.world.item.enchantment.Enchantment bukkitToMinecraft(Enchantment bukkit) { return CraftRegistry.bukkitToMinecraft(bukkit); } @@ -56,22 +61,7 @@ public class CraftEnchantment extends Enchantment implements Handleable EnchantmentTarget.ARMOR; - case ARMOR_FEET -> EnchantmentTarget.ARMOR_FEET; - case ARMOR_HEAD -> EnchantmentTarget.ARMOR_HEAD; - case ARMOR_LEGS -> EnchantmentTarget.ARMOR_LEGS; - case ARMOR_CHEST -> EnchantmentTarget.ARMOR_TORSO; - case DIGGER -> EnchantmentTarget.TOOL; - case WEAPON -> EnchantmentTarget.WEAPON; - case BOW -> EnchantmentTarget.BOW; - case FISHING_ROD -> EnchantmentTarget.FISHING_ROD; - case BREAKABLE -> EnchantmentTarget.BREAKABLE; - case WEARABLE -> EnchantmentTarget.WEARABLE; - case TRIDENT -> EnchantmentTarget.TRIDENT; - case CROSSBOW -> EnchantmentTarget.CROSSBOW; - case VANISHABLE -> EnchantmentTarget.VANISHABLE; - }; + throw new UnsupportedOperationException("Method longer applicable. Use Tags instead."); } @Override @@ -130,8 +120,11 @@ public class CraftEnchantment extends Enchantment implements Handleable "MULTISHOT"; case 35 -> "QUICK_CHARGE"; case 36 -> "PIERCING"; - case 37 -> "MENDING"; - case 38 -> "VANISHING_CURSE"; + case 37 -> "DENSITY"; + case 38 -> "BREACH"; + case 39 -> "WIND_BURST"; + case 40 -> "MENDING"; + case 41 -> "VANISHING_CURSE"; default -> getKey().toString(); }; } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractHorse.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractHorse.java index de748e927a..830e84f3ba 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractHorse.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractHorse.java @@ -51,7 +51,7 @@ public abstract class CraftAbstractHorse extends CraftAnimals implements Abstrac @Override public double getJumpStrength() { - return getHandle().getCustomJump(); + return getHandle().getAttributeValue(GenericAttributes.JUMP_STRENGTH); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractWindCharge.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractWindCharge.java new file mode 100644 index 0000000000..5e6bbeeea0 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractWindCharge.java @@ -0,0 +1,27 @@ +package org.bukkit.craftbukkit.entity; + +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.entity.AbstractWindCharge; +import org.bukkit.event.entity.EntityRemoveEvent; + +public abstract class CraftAbstractWindCharge extends CraftFireball implements AbstractWindCharge { + public CraftAbstractWindCharge(CraftServer server, net.minecraft.world.entity.projectile.windcharge.AbstractWindCharge entity) { + super(server, entity); + } + + @Override + public void explode() { + this.getHandle().explode(); + this.getHandle().discard(EntityRemoveEvent.Cause.EXPLODE); // SPIGOT-7577 - explode doesn't discard the entity, this happens only in tick and onHitBlock + } + + @Override + public net.minecraft.world.entity.projectile.windcharge.AbstractWindCharge getHandle() { + return (net.minecraft.world.entity.projectile.windcharge.AbstractWindCharge) this.entity; + } + + @Override + public String toString() { + return "CraftAbstractWindCharge"; + } +} 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 90a094d697..fac14cef14 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 @@ -3,10 +3,13 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.List; +import java.util.Optional; +import net.minecraft.core.Holder; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectList; import net.minecraft.world.entity.EntityAreaEffectCloud; import net.minecraft.world.entity.EntityLiving; +import net.minecraft.world.item.alchemy.PotionContents; import org.bukkit.Color; import org.bukkit.Particle; import org.bukkit.craftbukkit.CraftParticle; @@ -16,12 +19,10 @@ import org.bukkit.craftbukkit.potion.CraftPotionType; import org.bukkit.craftbukkit.potion.CraftPotionUtil; import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.LivingEntity; -import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; import org.bukkit.projectiles.ProjectileSource; -import org.jetbrains.annotations.NotNull; public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud { @@ -131,28 +132,22 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud @Override public Color getColor() { - return Color.fromRGB(getHandle().getColor()); + return Color.fromRGB(getHandle().potionContents.getColor()); } @Override public void setColor(Color color) { - getHandle().setFixedColor(color.asRGB()); + PotionContents old = getHandle().potionContents; + getHandle().setPotionContents(new PotionContents(old.potion(), Optional.of(color.asRGB()), old.customEffects())); } @Override public boolean addCustomEffect(PotionEffect effect, boolean override) { - MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect.getType()); - MobEffect existing = null; - for (MobEffect mobEffect : getHandle().effects) { - if (mobEffect.getEffect() == minecraft) { - existing = mobEffect; - } - } - if (existing != null) { + if (hasCustomEffect(effect.getType())) { if (!override) { return false; } - getHandle().effects.remove(existing); + removeCustomEffect(effect.getType()); } getHandle().addEffect(CraftPotionUtil.fromBukkit(effect)); getHandle().updateColor(); @@ -161,14 +156,15 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud @Override public void clearCustomEffects() { - getHandle().effects.clear(); + PotionContents old = getHandle().potionContents; + getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), List.of())); getHandle().updateColor(); } @Override public List getCustomEffects() { ImmutableList.Builder builder = ImmutableList.builder(); - for (MobEffect effect : getHandle().effects) { + for (MobEffect effect : getHandle().potionContents.customEffects()) { builder.add(CraftPotionUtil.toBukkit(effect)); } return builder.build(); @@ -176,7 +172,7 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud @Override public boolean hasCustomEffect(PotionEffectType type) { - for (MobEffect effect : getHandle().effects) { + for (MobEffect effect : getHandle().potionContents.customEffects()) { if (CraftPotionUtil.equals(effect.getEffect(), type)) { return true; } @@ -186,50 +182,34 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud @Override public boolean hasCustomEffects() { - return !getHandle().effects.isEmpty(); + return !getHandle().potionContents.customEffects().isEmpty(); } @Override public boolean removeCustomEffect(PotionEffectType effect) { - MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect); - MobEffect existing = null; - for (MobEffect mobEffect : getHandle().effects) { - if (mobEffect.getEffect() == minecraft) { - existing = mobEffect; - } - } - if (existing == null) { + if (!hasCustomEffect(effect)) { return false; } - getHandle().effects.remove(existing); - getHandle().updateColor(); + 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())); return true; } @Override - public void setBasePotionData(PotionData data) { - Preconditions.checkArgument(data != null, "PotionData cannot be null"); - - getHandle().setPotion(CraftPotionType.bukkitToMinecraft(CraftPotionUtil.fromBukkit(data))); + public void setBasePotionType(PotionType potionType) { + if (potionType != null) { + getHandle().setPotionContents(getHandle().potionContents.withPotion(CraftPotionType.bukkitToMinecraftHolder(potionType))); + } else { + PotionContents old = getHandle().potionContents; + getHandle().setPotionContents(new PotionContents(Optional.empty(), old.customColor(), old.customEffects())); + } } - @Override - public PotionData getBasePotionData() { - return CraftPotionUtil.toBukkit(CraftPotionType.minecraftToBukkit(getHandle().getPotion())); - } - - @Override - public void setBasePotionType(@NotNull PotionType potionType) { - // TODO: 10/6/23 Change PotionType.UNCRAFTABLE to PotionType.EMPTY in error message - Preconditions.checkArgument(potionType != null, "PotionType cannot be null use PotionType.UNCRAFTABLE to represent no effect instead."); - - getHandle().setPotion(CraftPotionType.bukkitToMinecraft(potionType)); - } - - @NotNull @Override public PotionType getBasePotionType() { - return CraftPotionType.minecraftToBukkit(getHandle().getPotion()); + return getHandle().potionContents.potion().map(CraftPotionType::minecraftHolderToBukkit).orElse(null); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArmadillo.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArmadillo.java new file mode 100644 index 0000000000..e7f2d8de25 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftArmadillo.java @@ -0,0 +1,21 @@ +package org.bukkit.craftbukkit.entity; + +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.entity.Armadillo; + +public class CraftArmadillo extends CraftAnimals implements Armadillo { + + public CraftArmadillo(CraftServer server, net.minecraft.world.entity.animal.armadillo.Armadillo entity) { + super(server, entity); + } + + @Override + public net.minecraft.world.entity.animal.armadillo.Armadillo getHandle() { + return (net.minecraft.world.entity.animal.armadillo.Armadillo) super.getHandle(); + } + + @Override + public String toString() { + return "CraftArmadillo"; + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBogged.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBogged.java new file mode 100644 index 0000000000..866e77c1ca --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBogged.java @@ -0,0 +1,27 @@ +package org.bukkit.craftbukkit.entity; + +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.entity.Bogged; +import org.bukkit.entity.Skeleton; + +public class CraftBogged extends CraftAbstractSkeleton implements Bogged { + + public CraftBogged(CraftServer server, net.minecraft.world.entity.monster.Bogged entity) { + super(server, entity); + } + + @Override + public net.minecraft.world.entity.monster.Bogged getHandle() { + return (net.minecraft.world.entity.monster.Bogged) entity; + } + + @Override + public String toString() { + return "CraftBogged"; + } + + @Override + public Skeleton.SkeletonType getSkeletonType() { + return Skeleton.SkeletonType.BOGGED; + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBreezeWindCharge.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBreezeWindCharge.java new file mode 100644 index 0000000000..e88e52a9b8 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftBreezeWindCharge.java @@ -0,0 +1,20 @@ +package org.bukkit.craftbukkit.entity; + +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.entity.BreezeWindCharge; + +public class CraftBreezeWindCharge extends CraftAbstractWindCharge implements BreezeWindCharge { + public CraftBreezeWindCharge(CraftServer server, net.minecraft.world.entity.projectile.windcharge.BreezeWindCharge entity) { + super(server, entity); + } + + @Override + public net.minecraft.world.entity.projectile.windcharge.BreezeWindCharge getHandle() { + return (net.minecraft.world.entity.projectile.windcharge.BreezeWindCharge) this.entity; + } + + @Override + public String toString() { + return "CraftBreezeWindCharge"; + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCat.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCat.java index 88b40f4688..632fa4647b 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCat.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftCat.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; +import net.minecraft.core.Holder; import net.minecraft.core.IRegistry; import net.minecraft.core.registries.Registries; import net.minecraft.world.entity.animal.CatVariant; @@ -31,14 +32,14 @@ public class CraftCat extends CraftTameableAnimal implements Cat { @Override public Type getCatType() { - return CraftType.minecraftToBukkit(getHandle().getVariant()); + return CraftType.minecraftHolderToBukkit(getHandle().getVariant()); } @Override public void setCatType(Type type) { Preconditions.checkArgument(type != null, "Cannot have null Type"); - getHandle().setVariant(CraftType.bukkitToMinecraft(type)); + getHandle().setVariant(CraftType.bukkitToMinecraftHolder(type)); } @Override @@ -61,6 +62,10 @@ public class CraftCat extends CraftTameableAnimal implements Cat { return Registry.CAT_VARIANT.get(CraftNamespacedKey.fromMinecraft(registry.getKey(minecraft))); } + public static Type minecraftHolderToBukkit(Holder minecraft) { + return minecraftToBukkit(minecraft.value()); + } + public static CatVariant bukkitToMinecraft(Type bukkit) { Preconditions.checkArgument(bukkit != null); @@ -68,5 +73,18 @@ public class CraftCat extends CraftTameableAnimal implements Cat { return registry.get(CraftNamespacedKey.toMinecraft(bukkit.getKey())); } + + public static Holder bukkitToMinecraftHolder(Type bukkit) { + Preconditions.checkArgument(bukkit != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.CAT_VARIANT); + + 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 cat variant with out properly registering it."); + } } } 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 85e77459aa..99f3c53b09 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,12 +1,9 @@ package org.bukkit.craftbukkit.entity; -import net.minecraft.resources.MinecraftKey; import net.minecraft.world.entity.vehicle.ChestBoat; -import org.bukkit.Bukkit; -import org.bukkit.NamespacedKey; +import org.bukkit.craftbukkit.CraftLootTable; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.inventory.CraftInventory; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.Inventory; import org.bukkit.loot.LootTable; @@ -41,13 +38,7 @@ public class CraftChestBoat extends CraftBoat implements org.bukkit.entity.Chest @Override public LootTable getLootTable() { - MinecraftKey nmsTable = getHandle().getLootTable(); - if (nmsTable == null) { - return null; // return empty loot table? - } - - NamespacedKey key = CraftNamespacedKey.fromMinecraft(nmsTable); - return Bukkit.getLootTable(key); + return CraftLootTable.minecraftToBukkit(getHandle().getLootTable()); } @Override @@ -61,8 +52,7 @@ public class CraftChestBoat extends CraftBoat implements org.bukkit.entity.Chest } private void setLootTable(LootTable table, long seed) { - MinecraftKey newKey = (table == null) ? null : CraftNamespacedKey.toMinecraft(table.getKey()); - getHandle().setLootTable(newKey); + getHandle().setLootTable(CraftLootTable.bukkitToMinecraft(table)); getHandle().setLootTableSeed(seed); } } 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 658734fd28..5e44bb2a37 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 @@ -50,6 +50,7 @@ import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.Allay; import org.bukkit.entity.AreaEffectCloud; +import org.bukkit.entity.Armadillo; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Arrow; import org.bukkit.entity.Axolotl; @@ -58,7 +59,9 @@ 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; @@ -115,6 +118,7 @@ import org.bukkit.entity.Marker; import org.bukkit.entity.Mule; import org.bukkit.entity.MushroomCow; import org.bukkit.entity.Ocelot; +import org.bukkit.entity.OminousItemSpawner; import org.bukkit.entity.Painting; import org.bukkit.entity.Panda; import org.bukkit.entity.Parrot; @@ -223,7 +227,7 @@ public final class CraftEntityTypes { private static final BiConsumer MOVE_EMPTY_ROT = (spawnData, entity) -> entity.moveTo(spawnData.x(), spawnData.y(), spawnData.z(), 0, 0); private static final BiConsumer DIRECTION = (spawnData, entity) -> { Vector direction = spawnData.location().getDirection().multiply(10); - entity.setDirection(direction.getX(), direction.getY(), direction.getZ()); + entity.assignPower(direction.getX(), direction.getY(), direction.getZ()); }; private static final Map, EntityTypeData> CLASS_TYPE_DATA = new HashMap<>(); private static final Map> ENTITY_TYPE_DATA = new HashMap<>(); @@ -233,6 +237,7 @@ public final class CraftEntityTypes { register(new EntityTypeData<>(EntityType.ELDER_GUARDIAN, ElderGuardian.class, CraftElderGuardian::new, createLiving(EntityTypes.ELDER_GUARDIAN))); register(new EntityTypeData<>(EntityType.WITHER_SKELETON, WitherSkeleton.class, CraftWitherSkeleton::new, createLiving(EntityTypes.WITHER_SKELETON))); register(new EntityTypeData<>(EntityType.STRAY, Stray.class, CraftStray::new, createLiving(EntityTypes.STRAY))); + register(new EntityTypeData<>(EntityType.BOGGED, Bogged.class, CraftBogged::new, createLiving(EntityTypes.BOGGED))); register(new EntityTypeData<>(EntityType.HUSK, Husk.class, CraftHusk::new, createLiving(EntityTypes.HUSK))); register(new EntityTypeData<>(EntityType.ZOMBIE_VILLAGER, ZombieVillager.class, CraftVillagerZombie::new, createLiving(EntityTypes.ZOMBIE_VILLAGER))); register(new EntityTypeData<>(EntityType.SKELETON_HORSE, SkeletonHorse.class, CraftSkeletonHorse::new, createLiving(EntityTypes.SKELETON_HORSE))); @@ -310,6 +315,7 @@ public final class CraftEntityTypes { register(new EntityTypeData<>(EntityType.CAMEL, Camel.class, CraftCamel::new, createLiving(EntityTypes.CAMEL))); 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))); Function dragonFunction = createLiving(EntityTypes.ENDER_DRAGON); register(new EntityTypeData<>(EntityType.ENDER_DRAGON, EnderDragon.class, CraftEnderDragon::new, spawnData -> { @@ -323,6 +329,7 @@ public final class CraftEntityTypes { register(new EntityTypeData<>(EntityType.WITHER_SKULL, WitherSkull.class, CraftWitherSkull::new, createFireball(EntityTypes.WITHER_SKULL))); register(new EntityTypeData<>(EntityType.DRAGON_FIREBALL, DragonFireball.class, CraftDragonFireball::new, createFireball(EntityTypes.DRAGON_FIREBALL))); register(new EntityTypeData<>(EntityType.WIND_CHARGE, WindCharge.class, CraftWindCharge::new, createFireball(EntityTypes.WIND_CHARGE))); + register(new EntityTypeData<>(EntityType.BREEZE_WIND_CHARGE, BreezeWindCharge.class, CraftBreezeWindCharge::new, createFireball(EntityTypes.BREEZE_WIND_CHARGE))); // Hanging register(new EntityTypeData<>(EntityType.PAINTING, Painting.class, CraftPainting::new, createHanging(Painting.class, (spawnData, hangingData) -> { @@ -353,6 +360,7 @@ public final class CraftEntityTypes { 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))); // Set pos register(new EntityTypeData<>(EntityType.MARKER, Marker.class, CraftMarker::new, createAndSetPos(EntityTypes.MARKER))); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java index b0ff11b409..ed3857655e 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java @@ -55,7 +55,7 @@ public class CraftFireball extends AbstractProjectile implements Fireball { @Override public void setDirection(Vector direction) { Preconditions.checkArgument(direction != null, "Vector direction cannot be null"); - getHandle().setDirection(direction.getX(), direction.getY(), direction.getZ()); + getHandle().assignPower(direction.getX(), direction.getY(), direction.getZ()); update(); // SPIGOT-6579 } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFrog.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFrog.java index b7eff43498..0b846994cb 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFrog.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFrog.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; +import net.minecraft.core.Holder; import net.minecraft.core.IRegistry; import net.minecraft.core.registries.Registries; import net.minecraft.world.entity.animal.FrogVariant; @@ -43,14 +44,14 @@ public class CraftFrog extends CraftAnimals implements org.bukkit.entity.Frog { @Override public Variant getVariant() { - return CraftVariant.minecraftToBukkit(getHandle().getVariant()); + return CraftVariant.minecraftHolderToBukkit(getHandle().getVariant()); } @Override public void setVariant(Variant variant) { Preconditions.checkArgument(variant != null, "variant"); - getHandle().setVariant(CraftVariant.bukkitToMinecraft(variant)); + getHandle().setVariant(CraftVariant.bukkitToMinecraftHolder(variant)); } public static class CraftVariant { @@ -66,11 +67,28 @@ public class CraftFrog extends CraftAnimals implements org.bukkit.entity.Frog { return bukkit; } + public static Variant minecraftHolderToBukkit(Holder minecraft) { + return minecraftToBukkit(minecraft.value()); + } + public static FrogVariant bukkitToMinecraft(Variant bukkit) { Preconditions.checkArgument(bukkit != null); return CraftRegistry.getMinecraftRegistry(Registries.FROG_VARIANT) .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); } + + public static Holder bukkitToMinecraftHolder(Variant bukkit) { + Preconditions.checkArgument(bukkit != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.FROG_VARIANT); + + 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 frog variant with out properly registering it."); + } } } 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 bdb5ec8511..ffd0e83f5c 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 @@ -26,8 +26,6 @@ import net.minecraft.world.item.crafting.CraftingManager; import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.trading.IMerchant; import net.minecraft.world.level.block.BlockBed; -import net.minecraft.world.level.block.BlockEnchantmentTable; -import net.minecraft.world.level.block.BlockWorkbench; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.TileEntity; import net.minecraft.world.level.block.state.IBlockData; @@ -342,7 +340,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { return null; } } - getHandle().openMenu(((BlockWorkbench) Blocks.CRAFTING_TABLE).getMenuProvider(null, getHandle().level(), CraftLocation.toBlockPosition(location))); + getHandle().openMenu(Blocks.CRAFTING_TABLE.defaultBlockState().getMenuProvider(getHandle().level(), CraftLocation.toBlockPosition(location))); if (force) { getHandle().containerMenu.checkReachable = false; } @@ -363,7 +361,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { // If there isn't an enchant table we can force create one, won't be very useful though. BlockPosition pos = CraftLocation.toBlockPosition(location); - getHandle().openMenu(((BlockEnchantmentTable) Blocks.ENCHANTING_TABLE).getMenuProvider(null, getHandle().level(), pos)); + getHandle().openMenu(Blocks.ENCHANTING_TABLE.defaultBlockState().getMenuProvider(getHandle().level(), pos)); if (force) { getHandle().containerMenu.checkReachable = false; 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 ef21e57929..199ab61d44 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 @@ -17,7 +17,6 @@ import net.minecraft.world.effect.MobEffect; import net.minecraft.world.entity.EntityInsentient; import net.minecraft.world.entity.EntityLiving; import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.EnumMonsterType; import net.minecraft.world.entity.ai.attributes.GenericAttributes; import net.minecraft.world.entity.boss.wither.EntityWither; import net.minecraft.world.entity.decoration.EntityArmorStand; @@ -159,7 +158,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { @Override public void resetMaxHealth() { - setMaxHealth(getHandle().getAttribute(GenericAttributes.MAX_HEALTH).getAttribute().getDefaultValue()); + setMaxHealth(getHandle().getAttribute(GenericAttributes.MAX_HEALTH).getAttribute().value().getDefaultValue()); } @Override @@ -401,7 +400,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { @Override public boolean addPotionEffect(PotionEffect effect, boolean force) { - getHandle().addEffect(new MobEffect(CraftPotionEffectType.bukkitToMinecraft(effect.getType()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()), EntityPotionEffectEvent.Cause.PLUGIN); + getHandle().addEffect(new MobEffect(CraftPotionEffectType.bukkitToMinecraftHolder(effect.getType()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()), EntityPotionEffectEvent.Cause.PLUGIN); return true; } @@ -416,25 +415,25 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { @Override public boolean hasPotionEffect(PotionEffectType type) { - return getHandle().hasEffect(CraftPotionEffectType.bukkitToMinecraft(type)); + return getHandle().hasEffect(CraftPotionEffectType.bukkitToMinecraftHolder(type)); } @Override public PotionEffect getPotionEffect(PotionEffectType type) { - MobEffect handle = getHandle().getEffect(CraftPotionEffectType.bukkitToMinecraft(type)); - return (handle == null) ? null : new PotionEffect(CraftPotionEffectType.minecraftToBukkit(handle.getEffect()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible()); + MobEffect handle = getHandle().getEffect(CraftPotionEffectType.bukkitToMinecraftHolder(type)); + return (handle == null) ? null : new PotionEffect(CraftPotionEffectType.minecraftHolderToBukkit(handle.getEffect()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible()); } @Override public void removePotionEffect(PotionEffectType type) { - getHandle().removeEffect(CraftPotionEffectType.bukkitToMinecraft(type), EntityPotionEffectEvent.Cause.PLUGIN); + getHandle().removeEffect(CraftPotionEffectType.bukkitToMinecraftHolder(type), EntityPotionEffectEvent.Cause.PLUGIN); } @Override public Collection getActivePotionEffects() { List effects = new ArrayList(); for (MobEffect handle : getHandle().activeEffects.values()) { - effects.add(new PotionEffect(CraftPotionEffectType.minecraftToBukkit(handle.getEffect()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible())); + effects.add(new PotionEffect(CraftPotionEffectType.minecraftHolderToBukkit(handle.getEffect()), handle.getDuration(), handle.getAmplifier(), handle.isAmbient(), handle.isVisible())); } return effects; } @@ -499,8 +498,8 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { launch = new EntityDragonFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ()); } else if (WindCharge.class.isAssignableFrom(projectile)) { launch = EntityTypes.WIND_CHARGE.create(world); - ((net.minecraft.world.entity.projectile.WindCharge) launch).setOwner(getHandle()); - ((net.minecraft.world.entity.projectile.WindCharge) launch).setDirection(direction.getX(), direction.getY(), direction.getZ()); + ((net.minecraft.world.entity.projectile.windcharge.WindCharge) launch).setOwner(getHandle()); + ((net.minecraft.world.entity.projectile.windcharge.WindCharge) launch).assignPower(direction.getX(), direction.getY(), direction.getZ()); } else { launch = new EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ(), 1); } @@ -795,21 +794,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { @Override public EntityCategory getCategory() { - EnumMonsterType type = getHandle().getMobType(); // Not actually an enum? - - if (type == EnumMonsterType.UNDEFINED) { - return EntityCategory.NONE; - } else if (type == EnumMonsterType.UNDEAD) { - return EntityCategory.UNDEAD; - } else if (type == EnumMonsterType.ARTHROPOD) { - return EntityCategory.ARTHROPOD; - } else if (type == EnumMonsterType.ILLAGER) { - return EntityCategory.ILLAGER; - } else if (type == EnumMonsterType.WATER) { - return EntityCategory.WATER; - } - - throw new UnsupportedOperationException("Unsupported monster type: " + type + ". This is a bug, report this to Spigot."); + throw new UnsupportedOperationException("Method longer applicable. Use Tags instead."); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java index cfff1b1026..dd9b8f1848 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartCommand.java @@ -38,7 +38,7 @@ public class CraftMinecartCommand extends CraftMinecart implements CommandMineca @Override public void setName(String name) { - getHandle().getCommandBlock().setName(CraftChatMessage.fromStringOrNull(name)); + getHandle().getCommandBlock().setCustomName(CraftChatMessage.fromStringOrNull(name)); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java index 5ffb8108f4..420341cadc 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartContainer.java @@ -1,12 +1,9 @@ package org.bukkit.craftbukkit.entity; -import net.minecraft.resources.MinecraftKey; import net.minecraft.world.entity.vehicle.EntityMinecartAbstract; import net.minecraft.world.entity.vehicle.EntityMinecartContainer; -import org.bukkit.Bukkit; -import org.bukkit.NamespacedKey; +import org.bukkit.craftbukkit.CraftLootTable; import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.loot.LootTable; import org.bukkit.loot.Lootable; @@ -28,13 +25,7 @@ public abstract class CraftMinecartContainer extends CraftMinecart implements Lo @Override public LootTable getLootTable() { - MinecraftKey nmsTable = getHandle().lootTable; - if (nmsTable == null) { - return null; // return empty loot table? - } - - NamespacedKey key = CraftNamespacedKey.fromMinecraft(nmsTable); - return Bukkit.getLootTable(key); + return CraftLootTable.minecraftToBukkit(getHandle().lootTable); } @Override @@ -48,7 +39,6 @@ public abstract class CraftMinecartContainer extends CraftMinecart implements Lo } private void setLootTable(LootTable table, long seed) { - MinecraftKey newKey = (table == null) ? null : CraftNamespacedKey.toMinecraft(table.getKey()); - getHandle().setLootTable(newKey, seed); + getHandle().setLootTable(CraftLootTable.bukkitToMinecraft(table), seed); } } 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 3b8689b5e1..fd3e321258 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 @@ -3,12 +3,10 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; import net.minecraft.sounds.SoundEffect; import net.minecraft.world.entity.EntityInsentient; -import org.bukkit.Bukkit; -import org.bukkit.NamespacedKey; import org.bukkit.Sound; +import org.bukkit.craftbukkit.CraftLootTable; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftSound; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Mob; import org.bukkit.loot.LootTable; @@ -65,13 +63,12 @@ public abstract class CraftMob extends CraftLivingEntity implements Mob { @Override public void setLootTable(LootTable table) { - getHandle().lootTable = (table == null) ? null : CraftNamespacedKey.toMinecraft(table.getKey()); + getHandle().lootTable = CraftLootTable.bukkitToMinecraft(table); } @Override public LootTable getLootTable() { - NamespacedKey key = CraftNamespacedKey.fromMinecraft(getHandle().getLootTable()); - return Bukkit.getLootTable(key); + return CraftLootTable.minecraftToBukkit(getHandle().getLootTable()); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java index 3bb6affabc..2dff422897 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java @@ -2,12 +2,12 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; -import java.util.ArrayList; import java.util.List; +import net.minecraft.core.Holder; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectList; import net.minecraft.world.entity.animal.EntityMushroomCow; -import net.minecraft.world.level.block.SuspiciousEffectHolder; +import net.minecraft.world.item.component.SuspiciousStewEffects; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.potion.CraftPotionEffectType; import org.bukkit.craftbukkit.potion.CraftPotionUtil; @@ -22,13 +22,15 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow { @Override public boolean hasEffectsForNextStew() { - return this.getHandle().stewEffects != null && !this.getHandle().stewEffects.isEmpty(); + SuspiciousStewEffects stewEffects = this.getHandle().stewEffects; + return stewEffects != null && !stewEffects.effects().isEmpty(); } @Override public List getEffectsForNextStew() { - if (this.hasEffectsForNextStew()) { - return this.getHandle().stewEffects.stream().map(recordSuspiciousEffect -> CraftPotionUtil.toBukkit(recordSuspiciousEffect.createEffectInstance())).toList(); + SuspiciousStewEffects stewEffects = this.getHandle().stewEffects; + if (stewEffects != null) { + return stewEffects.effects().stream().map(recordSuspiciousEffect -> CraftPotionUtil.toBukkit(recordSuspiciousEffect.createEffectInstance())).toList(); } return ImmutableList.of(); } @@ -40,32 +42,42 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow { if (!overwrite && this.hasEffectForNextStew(potionEffect.getType())) { return false; } - if (this.getHandle().stewEffects == null) { - this.getHandle().stewEffects = new ArrayList<>(); + SuspiciousStewEffects stewEffects = this.getHandle().stewEffects; + if (stewEffects == null) { + stewEffects = SuspiciousStewEffects.EMPTY; } - SuspiciousEffectHolder.a recordSuspiciousEffect = new SuspiciousEffectHolder.a(minecraftPotionEffect.getEffect(), minecraftPotionEffect.getDuration()); + SuspiciousStewEffects.a recordSuspiciousEffect = new SuspiciousStewEffects.a(minecraftPotionEffect.getEffect(), minecraftPotionEffect.getDuration()); this.removeEffectFromNextStew(potionEffect.getType()); // Avoid duplicates of effects - return this.getHandle().stewEffects.add(recordSuspiciousEffect); + getHandle().stewEffects = stewEffects.withEffectAdded(recordSuspiciousEffect); + return true; } @Override public boolean removeEffectFromNextStew(PotionEffectType potionEffectType) { Preconditions.checkArgument(potionEffectType != null, "potionEffectType cannot be null"); - if (!this.hasEffectsForNextStew()) { + if (!hasEffectForNextStew(potionEffectType)) { return false; } - MobEffectList minecraftPotionEffectType = CraftPotionEffectType.bukkitToMinecraft(potionEffectType); - return this.getHandle().stewEffects.removeIf(recordSuspiciousEffect -> recordSuspiciousEffect.effect().equals(minecraftPotionEffectType)); + + SuspiciousStewEffects stewEffects = this.getHandle().stewEffects; + if (stewEffects == null) { + return false; + } + + Holder minecraftPotionEffectType = CraftPotionEffectType.bukkitToMinecraftHolder(potionEffectType); + getHandle().stewEffects = new SuspiciousStewEffects(stewEffects.effects().stream().filter((effect) -> !effect.effect().equals(minecraftPotionEffectType)).toList()); + return true; } @Override public boolean hasEffectForNextStew(PotionEffectType potionEffectType) { Preconditions.checkArgument(potionEffectType != null, "potionEffectType cannot be null"); - if (!this.hasEffectsForNextStew()) { + SuspiciousStewEffects stewEffects = this.getHandle().stewEffects; + if (stewEffects == null) { return false; } - MobEffectList minecraftPotionEffectType = CraftPotionEffectType.bukkitToMinecraft(potionEffectType); - return this.getHandle().stewEffects.stream().anyMatch(recordSuspiciousEffect -> recordSuspiciousEffect.effect().equals(minecraftPotionEffectType)); + Holder minecraftPotionEffectType = CraftPotionEffectType.bukkitToMinecraftHolder(potionEffectType); + return stewEffects.effects().stream().anyMatch(recordSuspiciousEffect -> recordSuspiciousEffect.effect().equals(minecraftPotionEffectType)); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftOminousItemSpawner.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftOminousItemSpawner.java new file mode 100644 index 0000000000..4aa00b24a7 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftOminousItemSpawner.java @@ -0,0 +1,43 @@ +package org.bukkit.craftbukkit.entity; + +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.entity.OminousItemSpawner; +import org.bukkit.inventory.ItemStack; + +public class CraftOminousItemSpawner extends CraftEntity implements OminousItemSpawner { + + public CraftOminousItemSpawner(CraftServer server, net.minecraft.world.entity.OminousItemSpawner entity) { + super(server, entity); + } + + @Override + public net.minecraft.world.entity.OminousItemSpawner getHandle() { + return (net.minecraft.world.entity.OminousItemSpawner) entity; + } + + @Override + public String toString() { + return "CraftOminousItemSpawner"; + } + + @Override + public ItemStack getItem() { + return CraftItemStack.asBukkitCopy(getHandle().getItem()); + } + + @Override + public void setItem(ItemStack item) { + getHandle().setItem(CraftItemStack.asNMSCopy(item)); + } + + @Override + public long getSpawnItemAfterTicks() { + return getHandle().spawnItemAfterTicks; + } + + @Override + public void setSpawnItemAfterTicks(long ticks) { + getHandle().spawnItemAfterTicks = ticks; + } +} 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 3cfd3a7fc2..9484fa2d97 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 @@ -5,6 +5,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.io.BaseEncoding; import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Pair; +import io.netty.buffer.Unpooled; import it.unimi.dsi.fastutil.shorts.ShortArraySet; import it.unimi.dsi.fastutil.shorts.ShortSet; import java.io.ByteArrayOutputStream; @@ -22,12 +23,15 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Queue; import java.util.Set; import java.util.UUID; import java.util.WeakHashMap; +import java.util.concurrent.CompletableFuture; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Nullable; @@ -36,13 +40,18 @@ import net.minecraft.core.BlockPosition; import net.minecraft.core.Holder; import net.minecraft.core.SectionPosition; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.PacketDataSerializer; +import net.minecraft.network.EnumProtocol; import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.network.chat.PlayerChatMessage; +import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; import net.minecraft.network.protocol.common.ClientboundResourcePackPopPacket; import net.minecraft.network.protocol.common.ClientboundResourcePackPushPacket; -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.network.protocol.common.ClientboundStoreCookiePacket; +import net.minecraft.network.protocol.common.ClientboundTransferPacket; +import net.minecraft.network.protocol.common.custom.DiscardedPayload; +import net.minecraft.network.protocol.cookie.ClientboundCookieRequestPacket; +import net.minecraft.network.protocol.cookie.ServerboundCookieResponsePacket; import net.minecraft.network.protocol.game.ClientboundClearTitlesPacket; import net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket; import net.minecraft.network.protocol.game.ClientboundHurtAnimationPacket; @@ -99,6 +108,7 @@ import net.minecraft.world.level.block.entity.TileEntitySign; import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.border.IWorldBorderListener; import net.minecraft.world.level.saveddata.maps.MapIcon; +import net.minecraft.world.level.saveddata.maps.MapId; import net.minecraft.world.level.saveddata.maps.WorldMap; import net.minecraft.world.phys.Vec3D; import org.bukkit.BanEntry; @@ -148,6 +158,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.map.CraftMapCursor; import org.bukkit.craftbukkit.map.CraftMapView; import org.bukkit.craftbukkit.map.RenderData; import org.bukkit.craftbukkit.potion.CraftPotionEffectType; @@ -244,7 +255,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { @Override public InetSocketAddress getAddress() { - if (getHandle().connection == null) return null; + if (getHandle().connection.protocol() == null) return null; SocketAddress addr = getHandle().connection.getRemoteAddress(); if (addr instanceof InetSocketAddress) { @@ -254,6 +265,74 @@ public class CraftPlayer extends CraftHumanEntity implements Player { } } + public interface TransferCookieConnection { + + boolean isTransferred(); + + EnumProtocol protocol(); + + void send(Packet packet); + } + + public record CookieFuture(MinecraftKey key, CompletableFuture future) { + + } + private final Queue requestedCookies = new LinkedList<>(); + + public boolean isAwaitingCookies() { + return !requestedCookies.isEmpty(); + } + + public boolean handleCookieResponse(ServerboundCookieResponsePacket response) { + CookieFuture future = requestedCookies.peek(); + if (future != null) { + if (future.key.equals(response.key())) { + Preconditions.checkState(future == requestedCookies.poll(), "requestedCookies queue mismatch"); + + future.future().complete(response.payload()); + return true; + } + } + + return false; + } + + @Override + public boolean isTransferred() { + return getHandle().transferCookieConnection.isTransferred(); + } + + @Override + public CompletableFuture retrieveCookie(NamespacedKey key) { + Preconditions.checkArgument(key != null, "Cookie key cannot be null"); + + CompletableFuture future = new CompletableFuture<>(); + MinecraftKey nms = CraftNamespacedKey.toMinecraft(key); + requestedCookies.add(new CookieFuture(nms, future)); + + getHandle().transferCookieConnection.send(new ClientboundCookieRequestPacket(nms)); + + return future; + } + + @Override + public void storeCookie(NamespacedKey key, byte[] value) { + Preconditions.checkArgument(key != null, "Cookie key cannot be null"); + Preconditions.checkArgument(value != null, "Cookie value cannot be null"); + Preconditions.checkArgument(value.length <= 5120, "Cookie value too large, must be smaller than 5120 bytes"); + Preconditions.checkState(getHandle().transferCookieConnection.protocol() == EnumProtocol.CONFIGURATION || getHandle().transferCookieConnection.protocol() == EnumProtocol.PLAY, "Can only store cookie in CONFIGURATION or PLAY protocol."); + + getHandle().transferCookieConnection.send(new ClientboundStoreCookiePacket(CraftNamespacedKey.toMinecraft(key), value)); + } + + @Override + public void transfer(String host, int port) { + Preconditions.checkArgument(host != null, "Host cannot be null"); + Preconditions.checkState(getHandle().transferCookieConnection.protocol() == EnumProtocol.CONFIGURATION || getHandle().transferCookieConnection.protocol() == EnumProtocol.PLAY, "Can only transfer in CONFIGURATION or PLAY protocol."); + + getHandle().transferCookieConnection.send(new ClientboundTransferPacket(host, port)); + } + @Override public double getEyeHeight(boolean ignorePose) { if (ignorePose) { @@ -777,7 +856,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { return; } - getHandle().connection.send(new PacketPlayOutEntityEffect(entity.getEntityId(), CraftPotionUtil.fromBukkit(effect))); + getHandle().connection.send(new PacketPlayOutEntityEffect(entity.getEntityId(), CraftPotionUtil.fromBukkit(effect), true)); } @Override @@ -789,7 +868,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { return; } - getHandle().connection.send(new PacketPlayOutRemoveEntityEffect(entity.getEntityId(), CraftPotionEffectType.bukkitToMinecraft(type))); + getHandle().connection.send(new PacketPlayOutRemoveEntityEffect(entity.getEntityId(), CraftPotionEffectType.bukkitToMinecraftHolder(type))); } @Override @@ -876,11 +955,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player { Collection icons = new ArrayList(); for (MapCursor cursor : data.cursors) { if (cursor.isVisible()) { - icons.add(new MapIcon(MapIcon.Type.byIcon(cursor.getRawType()), cursor.getX(), cursor.getY(), cursor.getDirection(), CraftChatMessage.fromStringOrNull(cursor.getCaption()))); + icons.add(new MapIcon(CraftMapCursor.CraftType.bukkitToMinecraftHolder(cursor.getType()), cursor.getX(), cursor.getY(), cursor.getDirection(), CraftChatMessage.fromStringOrOptional(cursor.getCaption()))); } } - PacketPlayOutMap packet = new PacketPlayOutMap(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.b(0, 0, 128, 128, data.buffer)); getHandle().connection.send(packet); } @@ -1716,17 +1795,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { } private void sendCustomPayload(MinecraftKey id, byte[] message) { - ClientboundCustomPayloadPacket packet = new ClientboundCustomPayloadPacket(new CustomPacketPayload() { - @Override - public void write(PacketDataSerializer pds) { - pds.writeBytes(message); - } - - @Override - public MinecraftKey id() { - return id; - } - }); + ClientboundCustomPayloadPacket packet = new ClientboundCustomPayloadPacket(new DiscardedPayload(id, Unpooled.wrappedBuffer(message))); getHandle().connection.send(packet); } @@ -1773,7 +1842,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { hashStr = BaseEncoding.base16().lowerCase().encode(hash); } - this.handlePushResourcePack(new ClientboundResourcePackPushPacket(id, url, hashStr, force, CraftChatMessage.fromStringOrNull(prompt, true)), true); + this.handlePushResourcePack(new ClientboundResourcePackPushPacket(id, url, hashStr, force, CraftChatMessage.fromStringOrOptional(prompt, true)), true); } @Override @@ -1786,7 +1855,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { hashStr = BaseEncoding.base16().lowerCase().encode(hash); } - this.handlePushResourcePack(new ClientboundResourcePackPushPacket(id, url, hashStr, force, CraftChatMessage.fromStringOrNull(prompt, true)), false); + this.handlePushResourcePack(new ClientboundResourcePackPushPacket(id, url, hashStr, force, CraftChatMessage.fromStringOrOptional(prompt, true)), false); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSizedFireball.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSizedFireball.java index 72c3b89091..4c7627b104 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSizedFireball.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSizedFireball.java @@ -15,10 +15,10 @@ public class CraftSizedFireball extends CraftFireball implements SizedFireball { @Override public ItemStack getDisplayItem() { - if (getHandle().getItemRaw().isEmpty()) { + if (getHandle().getItem().isEmpty()) { return new ItemStack(Material.FIRE_CHARGE); } else { - return CraftItemStack.asBukkitCopy(getHandle().getItemRaw()); + return CraftItemStack.asBukkitCopy(getHandle().getItem()); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftTameableAnimal.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftTameableAnimal.java index 8e446699bb..dc4466f39b 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftTameableAnimal.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftTameableAnimal.java @@ -62,7 +62,7 @@ public class CraftTameableAnimal extends CraftAnimals implements Tameable, Creat @Override public void setTamed(boolean tame) { - getHandle().setTame(tame); + getHandle().setTame(tame, true); if (!tame) { setOwnerUUID(null); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftThrowableProjectile.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftThrowableProjectile.java index 77e5890ae4..e56754a38a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftThrowableProjectile.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftThrowableProjectile.java @@ -14,10 +14,10 @@ public abstract class CraftThrowableProjectile extends CraftProjectile implement @Override public ItemStack getItem() { - if (getHandle().getItemRaw().isEmpty()) { + if (getHandle().getItem().isEmpty()) { return CraftItemStack.asBukkitCopy(new net.minecraft.world.item.ItemStack(getHandle().getDefaultItemPublic())); } else { - return CraftItemStack.asBukkitCopy(getHandle().getItemRaw()); + return CraftItemStack.asBukkitCopy(getHandle().getItem()); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftThrownPotion.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftThrownPotion.java index bae19b17e6..cb0fd8239e 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftThrownPotion.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftThrownPotion.java @@ -3,9 +3,10 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.Collection; +import net.minecraft.core.component.DataComponents; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.entity.projectile.EntityPotion; -import net.minecraft.world.item.alchemy.PotionUtil; +import net.minecraft.world.item.alchemy.PotionContents; import org.bukkit.Material; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.inventory.CraftItemStack; @@ -22,7 +23,7 @@ public class CraftThrownPotion extends CraftThrowableProjectile implements Throw @Override public Collection getEffects() { ImmutableList.Builder builder = ImmutableList.builder(); - for (MobEffect effect : PotionUtil.getMobEffects(getHandle().getItemRaw())) { + for (MobEffect effect : getHandle().getItem().getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).customEffects()) { builder.add(CraftPotionUtil.toBukkit(effect)); } return builder.build(); @@ -30,7 +31,7 @@ public class CraftThrownPotion extends CraftThrowableProjectile implements Throw @Override public ItemStack getItem() { - return CraftItemStack.asBukkitCopy(getHandle().getItemRaw()); + return CraftItemStack.asBukkitCopy(getHandle().getItem()); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftTippedArrow.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftTippedArrow.java index ae6754f975..10b9cc245f 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftTippedArrow.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftTippedArrow.java @@ -1,22 +1,22 @@ package org.bukkit.craftbukkit.entity; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.List; +import java.util.Optional; +import net.minecraft.core.Holder; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectList; import net.minecraft.world.entity.projectile.EntityTippedArrow; +import net.minecraft.world.item.alchemy.PotionContents; import org.bukkit.Color; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.potion.CraftPotionEffectType; import org.bukkit.craftbukkit.potion.CraftPotionType; import org.bukkit.craftbukkit.potion.CraftPotionUtil; import org.bukkit.entity.Arrow; -import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; -import org.jetbrains.annotations.NotNull; public class CraftTippedArrow extends CraftArrow implements Arrow { @@ -36,18 +36,11 @@ public class CraftTippedArrow extends CraftArrow implements Arrow { @Override public boolean addCustomEffect(PotionEffect effect, boolean override) { - MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect.getType()); - MobEffect existing = null; - for (MobEffect mobEffect : getHandle().effects) { - if (mobEffect.getEffect() == minecraft) { - existing = mobEffect; - } - } - if (existing != null) { + if (hasCustomEffect(effect.getType())) { if (!override) { return false; } - getHandle().effects.remove(existing); + removeCustomEffect(effect.getType()); } getHandle().addEffect(CraftPotionUtil.fromBukkit(effect)); getHandle().updateColor(); @@ -56,14 +49,15 @@ public class CraftTippedArrow extends CraftArrow implements Arrow { @Override public void clearCustomEffects() { - getHandle().effects.clear(); + PotionContents old = getHandle().getPotionContents(); + getHandle().setPotionContents(new PotionContents(old.potion(), old.customColor(), List.of())); getHandle().updateColor(); } @Override public List getCustomEffects() { ImmutableList.Builder builder = ImmutableList.builder(); - for (MobEffect effect : getHandle().effects) { + for (MobEffect effect : getHandle().getPotionContents().customEffects()) { builder.add(CraftPotionUtil.toBukkit(effect)); } return builder.build(); @@ -71,7 +65,7 @@ public class CraftTippedArrow extends CraftArrow implements Arrow { @Override public boolean hasCustomEffect(PotionEffectType type) { - for (MobEffect effect : getHandle().effects) { + for (MobEffect effect : getHandle().getPotionContents().customEffects()) { if (CraftPotionUtil.equals(effect.getEffect(), type)) { return true; } @@ -81,55 +75,41 @@ public class CraftTippedArrow extends CraftArrow implements Arrow { @Override public boolean hasCustomEffects() { - return !getHandle().effects.isEmpty(); + return !getHandle().getPotionContents().customEffects().isEmpty(); } @Override public boolean removeCustomEffect(PotionEffectType effect) { - MobEffectList minecraft = CraftPotionEffectType.bukkitToMinecraft(effect); - MobEffect existing = null; - for (MobEffect mobEffect : getHandle().effects) { - if (mobEffect.getEffect() == minecraft) { - existing = mobEffect; - } - } - if (existing == null) { + if (!hasCustomEffect(effect)) { return false; } - getHandle().effects.remove(existing); - getHandle().updateColor(); + 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())); return true; } @Override - public void setBasePotionData(PotionData data) { - Preconditions.checkArgument(data != null, "PotionData cannot be null"); - this.getHandle().potion = CraftPotionType.bukkitToMinecraft(CraftPotionUtil.fromBukkit(data)); + public void setBasePotionType(PotionType potionType) { + if (potionType != null) { + getHandle().setPotionContents(getHandle().getPotionContents().withPotion(CraftPotionType.bukkitToMinecraftHolder(potionType))); + } else { + PotionContents old = getHandle().getPotionContents(); + getHandle().setPotionContents(new PotionContents(Optional.empty(), old.customColor(), old.customEffects())); + } } - @Override - public PotionData getBasePotionData() { - return CraftPotionUtil.toBukkit(CraftPotionType.minecraftToBukkit(getHandle().potion)); - } - - @Override - public void setBasePotionType(@NotNull PotionType potionType) { - // TODO: 10/6/23 Change PotionType.UNCRAFTABLE to PotionType.EMPTY in error message - Preconditions.checkArgument(potionType != null, "PotionType cannot be null use PotionType.UNCRAFTABLE to represent no effect instead."); - - getHandle().potion = CraftPotionType.bukkitToMinecraft(potionType); - } - - @NotNull @Override public PotionType getBasePotionType() { - return CraftPotionType.minecraftToBukkit(getHandle().potion); + return getHandle().getPotionContents().potion().map(CraftPotionType::minecraftHolderToBukkit).orElse(null); } @Override public void setColor(Color color) { int colorRGB = (color == null) ? -1 : color.asRGB(); - getHandle().setFixedColor(colorRGB); + PotionContents old = getHandle().getPotionContents(); + getHandle().setPotionContents(new PotionContents(old.potion(), Optional.of(colorRGB), old.customEffects())); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWindCharge.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWindCharge.java index fae25769bb..46447b9651 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWindCharge.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWindCharge.java @@ -2,22 +2,15 @@ package org.bukkit.craftbukkit.entity; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.WindCharge; -import org.bukkit.event.entity.EntityRemoveEvent; -public class CraftWindCharge extends CraftFireball implements WindCharge { - public CraftWindCharge(CraftServer server, net.minecraft.world.entity.projectile.WindCharge entity) { +public class CraftWindCharge extends CraftAbstractWindCharge implements WindCharge { + public CraftWindCharge(CraftServer server, net.minecraft.world.entity.projectile.windcharge.WindCharge entity) { super(server, entity); } @Override - public void explode() { - this.getHandle().explode(); - this.getHandle().discard(EntityRemoveEvent.Cause.EXPLODE); // SPIGOT-7577 - explode doesn't discard the entity, this happens only in tick and onHitBlock - } - - @Override - public net.minecraft.world.entity.projectile.WindCharge getHandle() { - return (net.minecraft.world.entity.projectile.WindCharge) this.entity; + public net.minecraft.world.entity.projectile.windcharge.WindCharge getHandle() { + return (net.minecraft.world.entity.projectile.windcharge.WindCharge) this.entity; } @Override 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 3e591feffc..2118979290 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 @@ -1,9 +1,17 @@ package org.bukkit.craftbukkit.entity; +import com.google.common.base.Preconditions; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; +import net.minecraft.core.registries.Registries; import net.minecraft.world.entity.animal.EntityWolf; +import net.minecraft.world.entity.animal.WolfVariant; import net.minecraft.world.item.EnumColor; import org.bukkit.DyeColor; +import org.bukkit.Registry; +import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.Wolf; public class CraftWolf extends CraftTameableAnimal implements Wolf { @@ -59,4 +67,54 @@ public class CraftWolf extends CraftTameableAnimal implements Wolf { public void setInterested(boolean flag) { getHandle().setIsInterested(flag); } + + @Override + public Variant getVariant() { + return CraftVariant.minecraftHolderToBukkit(getHandle().getVariant()); + } + + @Override + public void setVariant(Variant variant) { + Preconditions.checkArgument(variant != null, "variant"); + + getHandle().setVariant(CraftVariant.bukkitToMinecraftHolder(variant)); + } + + public static class CraftVariant { + + public static Variant minecraftToBukkit(WolfVariant minecraft) { + Preconditions.checkArgument(minecraft != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.WOLF_VARIANT); + Variant bukkit = Registry.WOLF_VARIANT.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location())); + + Preconditions.checkArgument(bukkit != null); + + return bukkit; + } + + public static Variant minecraftHolderToBukkit(Holder minecraft) { + return minecraftToBukkit(minecraft.value()); + } + + public static WolfVariant bukkitToMinecraft(Variant bukkit) { + Preconditions.checkArgument(bukkit != null); + + return CraftRegistry.getMinecraftRegistry(Registries.WOLF_VARIANT) + .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); + } + + public static Holder bukkitToMinecraftHolder(Variant bukkit) { + Preconditions.checkArgument(bukkit != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.WOLF_VARIANT); + + 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 wolf variant with out properly registering it."); + } + } } 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 c85b6dd441..8754274041 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 @@ -103,7 +103,6 @@ import org.bukkit.craftbukkit.entity.CraftSpellcaster; import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.inventory.CraftItemType; -import org.bukkit.craftbukkit.inventory.CraftMetaBook; import org.bukkit.craftbukkit.potion.CraftPotionUtil; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.CraftVector; @@ -1422,7 +1421,7 @@ public class CraftEventFactory { if (editBookEvent.isSigning()) { itemInHand.setItem(Items.WRITTEN_BOOK); } - CraftMetaBook meta = (CraftMetaBook) editBookEvent.getNewBookMeta(); + BookMeta meta = editBookEvent.getNewBookMeta(); CraftItemStack.setItemMeta(itemInHand, meta); } else { player.getBukkitEntity().updateInventory(); // SPIGOT-7484 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 1d6da2fcdf..6070a54cf4 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 @@ -14,9 +14,9 @@ import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.level.ChunkCoordIntPair; import net.minecraft.world.level.GeneratorAccessSeed; import net.minecraft.world.level.biome.BiomeBase; -import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.chunk.IChunkAccess; import net.minecraft.world.level.chunk.ProtoChunk; +import net.minecraft.world.level.chunk.status.ChunkStatus; import org.bukkit.HeightMap; import org.bukkit.Location; import org.bukkit.Material; 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 3a6b3d6637..b1eb38418b 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 @@ -1,7 +1,7 @@ package org.bukkit.craftbukkit.generator; import com.google.common.base.Preconditions; -import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import java.util.List; import java.util.Random; import java.util.concurrent.CompletableFuture; @@ -334,7 +334,7 @@ public class CustomChunkGenerator extends InternalChunkGenerator { } @Override - protected Codec codec() { - return Codec.unit(null); + protected MapCodec codec() { + return MapCodec.unit(null); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomWorldChunkManager.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomWorldChunkManager.java index c3b8d55310..c63e645ed6 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomWorldChunkManager.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CustomWorldChunkManager.java @@ -1,7 +1,7 @@ package org.bukkit.craftbukkit.generator; import com.google.common.base.Preconditions; -import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; @@ -39,7 +39,7 @@ public class CustomWorldChunkManager extends WorldChunkManager { } @Override - protected Codec codec() { + protected MapCodec codec() { throw new UnsupportedOperationException("Cannot serialize CustomWorldChunkManager"); } 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 3c79efcf98..2470d4dbe1 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 @@ -4,8 +4,8 @@ import com.google.common.base.Preconditions; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.minecraft.commands.arguments.item.ArgumentParserItemStack; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.core.component.DataComponentMap; +import net.minecraft.server.MinecraftServer; import net.minecraft.util.RandomSource; import net.minecraft.world.entity.EntityTypes; import net.minecraft.world.item.Item; @@ -18,6 +18,7 @@ import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftEntityType; +import org.bukkit.craftbukkit.inventory.components.CraftFoodComponent; import org.bukkit.craftbukkit.util.CraftLegacy; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -32,7 +33,9 @@ public final class CraftItemFactory implements ItemFactory { static { instance = new CraftItemFactory(); - ConfigurationSerialization.registerClass(CraftMetaItem.SerializableMeta.class); + ConfigurationSerialization.registerClass(SerializableMeta.class); + ConfigurationSerialization.registerClass(CraftFoodComponent.class); + ConfigurationSerialization.registerClass(CraftFoodComponent.CraftFoodEffect.class); } private CraftItemFactory() { @@ -114,6 +117,7 @@ public final class CraftItemFactory implements ItemFactory { case LEATHER_CHESTPLATE: case LEATHER_LEGGINGS: case LEATHER_BOOTS: + case WOLF_ARMOR: return meta instanceof CraftMetaColorableArmor ? meta : new CraftMetaColorableArmor(meta); case LEATHER_HORSE_ARMOR: return meta instanceof CraftMetaLeatherArmor ? meta : new CraftMetaLeatherArmor(meta); @@ -163,11 +167,13 @@ public final class CraftItemFactory implements ItemFactory { case YELLOW_BANNER: case YELLOW_WALL_BANNER: return meta instanceof CraftMetaBanner ? meta : new CraftMetaBanner(meta); + case ARMADILLO_SPAWN_EGG: case ALLAY_SPAWN_EGG: case AXOLOTL_SPAWN_EGG: case BAT_SPAWN_EGG: case BEE_SPAWN_EGG: case BLAZE_SPAWN_EGG: + case BOGGED_SPAWN_EGG: case BREEZE_SPAWN_EGG: case CAT_SPAWN_EGG: case CAMEL_SPAWN_EGG: @@ -346,6 +352,7 @@ public final class CraftItemFactory implements ItemFactory { case SUSPICIOUS_GRAVEL: case CRAFTER: case TRIAL_SPAWNER: + case VAULT: return new CraftMetaBlockState(meta, material); case TROPICAL_FISH_BUCKET: return meta instanceof CraftMetaTropicalFishBucket ? meta : new CraftMetaTropicalFishBucket(meta); @@ -368,6 +375,8 @@ public final class CraftItemFactory implements ItemFactory { return meta instanceof CraftMetaBundle ? meta : new CraftMetaBundle(meta); case GOAT_HORN: return meta instanceof CraftMetaMusicInstrument ? meta : new CraftMetaMusicInstrument(meta); + case OMINOUS_BOTTLE: + return meta instanceof CraftMetaOminousBottle ? meta : new CraftMetaOminousBottle(meta); default: return new CraftMetaItem(meta); } @@ -431,14 +440,14 @@ public final class CraftItemFactory implements ItemFactory { @Override public ItemStack createItemStack(String input) throws IllegalArgumentException { try { - ArgumentParserItemStack.a arg = ArgumentParserItemStack.parseForItem(BuiltInRegistries.ITEM.asLookup(), new StringReader(input)); + ArgumentParserItemStack.a arg = new ArgumentParserItemStack(MinecraftServer.getDefaultRegistryAccess()).parse(new StringReader(input)); Item item = arg.item().value(); net.minecraft.world.item.ItemStack nmsItemStack = new net.minecraft.world.item.ItemStack(item); - NBTTagCompound nbt = arg.nbt(); + DataComponentMap nbt = arg.components(); if (nbt != null) { - nmsItemStack.setTag(nbt); + nmsItemStack.applyComponents(nbt); } return CraftItemStack.asCraftMirror(nmsItemStack); @@ -491,6 +500,6 @@ public final class CraftItemFactory implements ItemFactory { Preconditions.checkArgument(!itemStack.getType().isAir(), "ItemStack must not be air"); itemStack = CraftItemStack.asCraftCopy(itemStack); CraftItemStack craft = (CraftItemStack) itemStack; - return CraftItemStack.asCraftMirror(EnchantmentManager.enchantItem(source, craft.handle, level, allowTreasures)); + return CraftItemStack.asCraftMirror(EnchantmentManager.enchantItem(MinecraftServer.getServer().getWorldData().enabledFeatures(), source, craft.handle, level, allowTreasures)); } } 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 bc1f7fefac..e4f28b9dfd 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 @@ -1,20 +1,19 @@ package org.bukkit.craftbukkit.inventory; -import static org.bukkit.craftbukkit.inventory.CraftMetaItem.*; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import java.util.Map; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import net.minecraft.core.Holder; +import net.minecraft.core.component.DataComponentMap; +import net.minecraft.core.component.DataComponents; import net.minecraft.world.item.Item; import net.minecraft.world.item.enchantment.EnchantmentManager; +import net.minecraft.world.item.enchantment.ItemEnchantments; import org.bukkit.Material; -import org.bukkit.NamespacedKey; import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.craftbukkit.enchantments.CraftEnchantment; import org.bukkit.craftbukkit.util.CraftLegacy; import org.bukkit.craftbukkit.util.CraftMagicNumbers; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -171,7 +170,7 @@ public final class CraftItemStack extends ItemStack { @Override public int getMaxStackSize() { - return (handle == null) ? Material.AIR.getMaxStackSize() : handle.getItem().getMaxStackSize(); + return (handle == null) ? Material.AIR.getMaxStackSize() : handle.getMaxStackSize(); } @Override @@ -181,25 +180,13 @@ public final class CraftItemStack extends ItemStack { if (!makeTag(handle)) { return; } - NBTTagList list = getEnchantmentList(handle); + ItemEnchantments list = getEnchantmentList(handle); if (list == null) { - list = new NBTTagList(); - handle.getTag().put(ENCHANTMENTS.NBT, list); + list = ItemEnchantments.EMPTY; } - int size = list.size(); - - for (int i = 0; i < size; i++) { - NBTTagCompound tag = (NBTTagCompound) list.get(i); - String id = tag.getString(ENCHANTMENTS_ID.NBT); - if (ench.getKey().equals(NamespacedKey.fromString(id))) { - tag.putShort(ENCHANTMENTS_LVL.NBT, (short) level); - return; - } - } - NBTTagCompound tag = new NBTTagCompound(); - tag.putString(ENCHANTMENTS_ID.NBT, ench.getKey().toString()); - tag.putShort(ENCHANTMENTS_LVL.NBT, (short) level); - list.add(tag); + ItemEnchantments.a listCopy = new ItemEnchantments.a(list); + listCopy.set(CraftEnchantment.bukkitToMinecraft(ench), level); + handle.set(DataComponents.ENCHANTMENTS, listCopy.toImmutable()); } static boolean makeTag(net.minecraft.world.item.ItemStack item) { @@ -207,10 +194,6 @@ public final class CraftItemStack extends ItemStack { return false; } - if (item.getTag() == null) { - item.setTag(new NBTTagCompound()); - } - return true; } @@ -232,50 +215,31 @@ public final class CraftItemStack extends ItemStack { public int removeEnchantment(Enchantment ench) { Preconditions.checkArgument(ench != null, "Enchantment cannot be null"); - NBTTagList list = getEnchantmentList(handle), listCopy; + ItemEnchantments list = getEnchantmentList(handle); if (list == null) { return 0; } - int index = Integer.MIN_VALUE; - int level = Integer.MIN_VALUE; - int size = list.size(); - - for (int i = 0; i < size; i++) { - NBTTagCompound enchantment = (NBTTagCompound) list.get(i); - String id = enchantment.getString(ENCHANTMENTS_ID.NBT); - if (ench.getKey().equals(NamespacedKey.fromString(id))) { - index = i; - level = 0xffff & enchantment.getShort(ENCHANTMENTS_LVL.NBT); - break; - } - } - - if (index == Integer.MIN_VALUE) { + int level = getEnchantmentLevel(ench); + if (level <= 0) { return 0; } + int size = list.size(); + if (size == 1) { - handle.getTag().remove(ENCHANTMENTS.NBT); - if (handle.getTag().isEmpty()) { - handle.setTag(null); - } + handle.remove(DataComponents.ENCHANTMENTS); return level; } - // This is workaround for not having an index removal - listCopy = new NBTTagList(); - for (int i = 0; i < size; i++) { - if (i != index) { - listCopy.add(list.get(i)); - } - } - handle.getTag().put(ENCHANTMENTS.NBT, listCopy); + ItemEnchantments.a listCopy = new ItemEnchantments.a(list); + listCopy.set(CraftEnchantment.bukkitToMinecraft(ench), -1); // Negative to remove + handle.set(DataComponents.ENCHANTMENTS, listCopy.toImmutable()); return level; } @Override public void removeEnchantments() { - handle.getTag().remove(ENCHANTMENTS.NBT); + handle.remove(DataComponents.ENCHANTMENTS); } @Override @@ -284,7 +248,7 @@ public final class CraftItemStack extends ItemStack { } static Map getEnchantments(net.minecraft.world.item.ItemStack item) { - NBTTagList list = (item != null && item.isEnchanted()) ? item.getEnchantmentTags() : null; + ItemEnchantments list = (item != null && item.isEnchanted()) ? item.get(DataComponents.ENCHANTMENTS) : null; if (list == null || list.size() == 0) { return ImmutableMap.of(); @@ -292,21 +256,21 @@ public final class CraftItemStack extends ItemStack { ImmutableMap.Builder result = ImmutableMap.builder(); - for (int i = 0; i < list.size(); i++) { - String id = ((NBTTagCompound) list.get(i)).getString(ENCHANTMENTS_ID.NBT); - int level = 0xffff & ((NBTTagCompound) list.get(i)).getShort(ENCHANTMENTS_LVL.NBT); + list.entrySet().forEach((entry) -> { + Holder id = entry.getKey(); + int level = entry.getIntValue(); - Enchantment enchant = Enchantment.getByKey(CraftNamespacedKey.fromStringOrNull(id)); + Enchantment enchant = CraftEnchantment.minecraftHolderToBukkit(id); if (enchant != null) { result.put(enchant, level); } - } + }); return result.build(); } - static NBTTagList getEnchantmentList(net.minecraft.world.item.ItemStack item) { - return (item != null && item.isEnchanted()) ? item.getEnchantmentTags() : null; + static ItemEnchantments getEnchantmentList(net.minecraft.world.item.ItemStack item) { + return (item != null && item.isEnchanted()) ? item.get(DataComponents.ENCHANTMENTS) : null; } @Override @@ -329,9 +293,9 @@ public final class CraftItemStack extends ItemStack { } switch (getType(item)) { case WRITTEN_BOOK: - return new CraftMetaBookSigned(item.getTag()); + return new CraftMetaBookSigned(item.getComponentsPatch()); case WRITABLE_BOOK: - return new CraftMetaBook(item.getTag()); + return new CraftMetaBook(item.getComponentsPatch()); case CREEPER_HEAD: case CREEPER_WALL_HEAD: case DRAGON_HEAD: @@ -346,7 +310,7 @@ public final class CraftItemStack extends ItemStack { case WITHER_SKELETON_WALL_SKULL: case ZOMBIE_HEAD: case ZOMBIE_WALL_HEAD: - return new CraftMetaSkull(item.getTag()); + return new CraftMetaSkull(item.getComponentsPatch()); case CHAINMAIL_HELMET: case CHAINMAIL_CHESTPLATE: case CHAINMAIL_LEGGINGS: @@ -368,27 +332,28 @@ public final class CraftItemStack extends ItemStack { case NETHERITE_LEGGINGS: case NETHERITE_BOOTS: case TURTLE_HELMET: - return new CraftMetaArmor(item.getTag()); + return new CraftMetaArmor(item.getComponentsPatch()); case LEATHER_HELMET: case LEATHER_CHESTPLATE: case LEATHER_LEGGINGS: case LEATHER_BOOTS: - return new CraftMetaColorableArmor(item.getTag()); + case WOLF_ARMOR: + return new CraftMetaColorableArmor(item.getComponentsPatch()); case LEATHER_HORSE_ARMOR: - return new CraftMetaLeatherArmor(item.getTag()); + return new CraftMetaLeatherArmor(item.getComponentsPatch()); case POTION: case SPLASH_POTION: case LINGERING_POTION: case TIPPED_ARROW: - return new CraftMetaPotion(item.getTag()); + return new CraftMetaPotion(item.getComponentsPatch()); case FILLED_MAP: - return new CraftMetaMap(item.getTag()); + return new CraftMetaMap(item.getComponentsPatch()); case FIREWORK_ROCKET: - return new CraftMetaFirework(item.getTag()); + return new CraftMetaFirework(item.getComponentsPatch()); case FIREWORK_STAR: - return new CraftMetaCharge(item.getTag()); + return new CraftMetaCharge(item.getComponentsPatch()); case ENCHANTED_BOOK: - return new CraftMetaEnchantedBook(item.getTag()); + return new CraftMetaEnchantedBook(item.getComponentsPatch()); case BLACK_BANNER: case BLACK_WALL_BANNER: case BLUE_BANNER: @@ -421,12 +386,14 @@ public final class CraftItemStack extends ItemStack { case WHITE_WALL_BANNER: case YELLOW_BANNER: case YELLOW_WALL_BANNER: - return new CraftMetaBanner(item.getTag()); + return new CraftMetaBanner(item.getComponentsPatch()); + case ARMADILLO_SPAWN_EGG: case ALLAY_SPAWN_EGG: case AXOLOTL_SPAWN_EGG: case BAT_SPAWN_EGG: case BEE_SPAWN_EGG: case BLAZE_SPAWN_EGG: + case BOGGED_SPAWN_EGG: case BREEZE_SPAWN_EGG: case CAT_SPAWN_EGG: case CAMEL_SPAWN_EGG: @@ -500,11 +467,11 @@ public final class CraftItemStack extends ItemStack { case ZOMBIE_SPAWN_EGG: case ZOMBIE_VILLAGER_SPAWN_EGG: case ZOMBIFIED_PIGLIN_SPAWN_EGG: - return new CraftMetaSpawnEgg(item.getTag()); + return new CraftMetaSpawnEgg(item.getComponentsPatch()); case ARMOR_STAND: - return new CraftMetaArmorStand(item.getTag()); + return new CraftMetaArmorStand(item.getComponentsPatch()); case KNOWLEDGE_BOOK: - return new CraftMetaKnowledgeBook(item.getTag()); + return new CraftMetaKnowledgeBook(item.getComponentsPatch()); case FURNACE: case CHEST: case TRAPPED_CHEST: @@ -605,30 +572,33 @@ public final class CraftItemStack extends ItemStack { case SUSPICIOUS_GRAVEL: case CRAFTER: case TRIAL_SPAWNER: - return new CraftMetaBlockState(item.getTag(), CraftItemType.minecraftToBukkit(item.getItem())); + case VAULT: + return new CraftMetaBlockState(item.getComponentsPatch(), CraftItemType.minecraftToBukkit(item.getItem())); case TROPICAL_FISH_BUCKET: - return new CraftMetaTropicalFishBucket(item.getTag()); + return new CraftMetaTropicalFishBucket(item.getComponentsPatch()); case AXOLOTL_BUCKET: - return new CraftMetaAxolotlBucket(item.getTag()); + return new CraftMetaAxolotlBucket(item.getComponentsPatch()); case CROSSBOW: - return new CraftMetaCrossbow(item.getTag()); + return new CraftMetaCrossbow(item.getComponentsPatch()); case SUSPICIOUS_STEW: - return new CraftMetaSuspiciousStew(item.getTag()); + return new CraftMetaSuspiciousStew(item.getComponentsPatch()); case COD_BUCKET: case PUFFERFISH_BUCKET: case SALMON_BUCKET: case ITEM_FRAME: case GLOW_ITEM_FRAME: case PAINTING: - return new CraftMetaEntityTag(item.getTag()); + return new CraftMetaEntityTag(item.getComponentsPatch()); case COMPASS: - return new CraftMetaCompass(item.getTag()); + return new CraftMetaCompass(item.getComponentsPatch()); case BUNDLE: - return new CraftMetaBundle(item.getTag()); + return new CraftMetaBundle(item.getComponentsPatch()); case GOAT_HORN: - return new CraftMetaMusicInstrument(item.getTag()); + return new CraftMetaMusicInstrument(item.getComponentsPatch()); + case OMINOUS_BOTTLE: + return new CraftMetaOminousBottle(item.getComponentsPatch()); default: - return new CraftMetaItem(item.getTag()); + return new CraftMetaItem(item.getComponentsPatch()); } } @@ -646,7 +616,7 @@ public final class CraftItemStack extends ItemStack { return false; } if (CraftItemFactory.instance().equals(itemMeta, null)) { - item.setTag(null); + item.applyComponents(DataComponentMap.EMPTY); return true; } if (!CraftItemFactory.instance().isApplicable(itemMeta, getType(item))) { @@ -662,13 +632,14 @@ public final class CraftItemStack extends ItemStack { item.setItem(newItem); } - NBTTagCompound tag = new NBTTagCompound(); - item.setTag(tag); + if (!((CraftMetaItem) itemMeta).isEmpty()) { + CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator(); - ((CraftMetaItem) itemMeta).applyToItem(tag); - item.convertStack(((CraftMetaItem) itemMeta).getVersion()); + ((CraftMetaItem) itemMeta).applyToItem(tag); + item.applyComponents(tag.build()); + } // SpigotCraft#463 this is required now by the Vanilla client, so mimic ItemStack constructor in ensuring it - if (item.getItem() != null && item.getItem().canBeDepleted()) { + if (item.getItem() != null && item.getMaxDamage() > 0) { item.setDamageValue(item.getDamageValue()); } @@ -698,7 +669,7 @@ public final class CraftItemStack extends ItemStack { if (!(comparisonType == getType() && getDurability() == that.getDurability())) { return false; } - return hasItemMeta() ? that.hasItemMeta() && handle.getTag().equals(that.handle.getTag()) : !that.hasItemMeta(); + return hasItemMeta() ? that.hasItemMeta() && handle.getComponents().equals(that.handle.getComponents()) : !that.hasItemMeta(); } @Override @@ -707,6 +678,6 @@ public final class CraftItemStack extends ItemStack { } static boolean hasItemMeta(net.minecraft.world.item.ItemStack item) { - return !(item == null || item.getTag() == null || item.getTag().isEmpty()); + return !(item == null || item.getComponentsPatch().isEmpty()); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java index 4796a04a5b..9fe2855ab9 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMerchantRecipe.java @@ -2,6 +2,10 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Preconditions; import java.util.List; +import java.util.Optional; +import net.minecraft.core.component.DataComponentPredicate; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.trading.ItemCost; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.MerchantRecipe; @@ -12,8 +16,8 @@ public class CraftMerchantRecipe extends MerchantRecipe { public CraftMerchantRecipe(net.minecraft.world.item.trading.MerchantRecipe merchantRecipe) { super(CraftItemStack.asBukkitCopy(merchantRecipe.result), 0); this.handle = merchantRecipe; - addIngredient(CraftItemStack.asBukkitCopy(merchantRecipe.baseCostA)); - addIngredient(CraftItemStack.asBukkitCopy(merchantRecipe.costB)); + addIngredient(CraftItemStack.asBukkitCopy(merchantRecipe.baseCostA.itemStack())); + merchantRecipe.costB.ifPresent((costB) -> addIngredient(CraftItemStack.asBukkitCopy(costB.itemStack()))); } @Deprecated @@ -24,8 +28,8 @@ public class CraftMerchantRecipe extends MerchantRecipe { public CraftMerchantRecipe(ItemStack result, int uses, int maxUses, boolean experienceReward, int experience, float priceMultiplier, int demand, int specialPrice) { super(result, uses, maxUses, experienceReward, experience, priceMultiplier, demand, specialPrice); this.handle = new net.minecraft.world.item.trading.MerchantRecipe( - net.minecraft.world.item.ItemStack.EMPTY, - net.minecraft.world.item.ItemStack.EMPTY, + new ItemCost(Items.AIR), + Optional.empty(), CraftItemStack.asNMSCopy(result), uses, maxUses, @@ -111,9 +115,11 @@ public class CraftMerchantRecipe extends MerchantRecipe { public net.minecraft.world.item.trading.MerchantRecipe toMinecraft() { List ingredients = getIngredients(); Preconditions.checkState(!ingredients.isEmpty(), "No offered ingredients"); - handle.baseCostA = CraftItemStack.asNMSCopy(ingredients.get(0)); + net.minecraft.world.item.ItemStack baseCostA = CraftItemStack.asNMSCopy(ingredients.get(0)); + handle.baseCostA = new ItemCost(baseCostA.getItemHolder(), baseCostA.getCount(), DataComponentPredicate.allOf(baseCostA.getComponents()), baseCostA); if (ingredients.size() > 1) { - handle.costB = CraftItemStack.asNMSCopy(ingredients.get(1)); + net.minecraft.world.item.ItemStack costB = CraftItemStack.asNMSCopy(ingredients.get(1)); + handle.costB = Optional.of(new ItemCost(costB.getItemHolder(), costB.getCount(), DataComponentPredicate.allOf(costB.getComponents()), costB)); } return handle; } 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 c61bb6f4de..73e5afe7dc 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 @@ -6,17 +6,21 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.Set; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.Registry; import org.bukkit.configuration.serialization.DelegateDeserialization; +import org.bukkit.craftbukkit.inventory.trim.CraftTrimMaterial; +import org.bukkit.craftbukkit.inventory.trim.CraftTrimPattern; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.meta.ArmorMeta; import org.bukkit.inventory.meta.trim.ArmorTrim; import org.bukkit.inventory.meta.trim.TrimMaterial; import org.bukkit.inventory.meta.trim.TrimPattern; -@DelegateDeserialization(CraftMetaItem.SerializableMeta.class) +@DelegateDeserialization(SerializableMeta.class) public class CraftMetaArmor extends CraftMetaItem implements ArmorMeta { private static final Set ARMOR_MATERIALS = Sets.newHashSet( @@ -47,7 +51,7 @@ public class CraftMetaArmor extends CraftMetaItem implements ArmorMeta { Material.TURTLE_HELMET ); - static final ItemMetaKey TRIM = new ItemMetaKey("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"); @@ -61,19 +65,19 @@ public class CraftMetaArmor extends CraftMetaItem implements ArmorMeta { } } - CraftMetaArmor(NBTTagCompound tag) { + CraftMetaArmor(DataComponentPatch tag) { super(tag); - if (tag.contains(TRIM.NBT)) { - NBTTagCompound trimCompound = tag.getCompound(TRIM.NBT); + getOrEmpty(tag, TRIM).ifPresent((trimCompound) -> { + TrimMaterial trimMaterial = CraftTrimMaterial.minecraftHolderToBukkit(trimCompound.material()); + TrimPattern trimPattern = CraftTrimPattern.minecraftHolderToBukkit(trimCompound.pattern()); - if (trimCompound.contains(TRIM_MATERIAL.NBT) && trimCompound.contains(TRIM_PATTERN.NBT)) { - TrimMaterial trimMaterial = Registry.TRIM_MATERIAL.get(NamespacedKey.fromString(trimCompound.getString(TRIM_MATERIAL.NBT))); - TrimPattern trimPattern = Registry.TRIM_PATTERN.get(NamespacedKey.fromString(trimCompound.getString(TRIM_PATTERN.NBT))); + this.trim = new ArmorTrim(trimMaterial, trimPattern); - this.trim = new ArmorTrim(trimMaterial, trimPattern); + if (!trimCompound.showInTooltip) { + addItemFlags(ItemFlag.HIDE_ARMOR_TRIM); } - } + }); } CraftMetaArmor(Map map) { @@ -101,14 +105,11 @@ public class CraftMetaArmor extends CraftMetaItem implements ArmorMeta { } @Override - void applyToItem(NBTTagCompound itemTag) { + void applyToItem(CraftMetaItem.Applicator itemTag) { super.applyToItem(itemTag); if (hasTrim()) { - NBTTagCompound trimCompound = new NBTTagCompound(); - trimCompound.putString(TRIM_MATERIAL.NBT, trim.getMaterial().getKey().toString()); - trimCompound.putString(TRIM_PATTERN.NBT, trim.getPattern().getKey().toString()); - itemTag.put(TRIM.NBT, trimCompound); + itemTag.put(TRIM, new net.minecraft.world.item.armortrim.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/CraftMetaArmorStand.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmorStand.java index 768b73604c..7d02f8eca0 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmorStand.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaArmorStand.java @@ -2,15 +2,18 @@ package org.bukkit.craftbukkit.inventory; 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.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.item.component.CustomData; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; -@DelegateDeserialization(CraftMetaItem.SerializableMeta.class) +@DelegateDeserialization(SerializableMeta.class) public class CraftMetaArmorStand extends CraftMetaItem { - static final ItemMetaKey ENTITY_TAG = new ItemMetaKey("EntityTag", "entity-tag"); + static final ItemMetaKeyType ENTITY_TAG = new ItemMetaKeyType<>(DataComponents.ENTITY_DATA, "entity-tag"); NBTTagCompound entityTag; CraftMetaArmorStand(CraftMetaItem meta) { @@ -24,12 +27,12 @@ public class CraftMetaArmorStand extends CraftMetaItem { this.entityTag = armorStand.entityTag; } - CraftMetaArmorStand(NBTTagCompound tag) { + CraftMetaArmorStand(DataComponentPatch tag) { super(tag); - if (tag.contains(ENTITY_TAG.NBT)) { - entityTag = tag.getCompound(ENTITY_TAG.NBT).copy(); - } + getOrEmpty(tag, ENTITY_TAG).ifPresent((nbt) -> { + entityTag = nbt.copyTag(); + }); } CraftMetaArmorStand(Map map) { @@ -53,11 +56,11 @@ public class CraftMetaArmorStand extends CraftMetaItem { } @Override - void applyToItem(NBTTagCompound tag) { + void applyToItem(CraftMetaItem.Applicator tag) { super.applyToItem(tag); if (entityTag != null) { - tag.put(ENTITY_TAG.NBT, entityTag); + tag.put(ENTITY_TAG, CustomData.of(entityTag)); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaAxolotlBucket.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaAxolotlBucket.java index 654e98362a..34d3b6c6c3 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaAxolotlBucket.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaAxolotlBucket.java @@ -2,19 +2,22 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.collect.ImmutableMap; import java.util.Map; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.item.component.CustomData; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.entity.Axolotl; import org.bukkit.inventory.meta.AxolotlBucketMeta; -@DelegateDeserialization(CraftMetaItem.SerializableMeta.class) +@DelegateDeserialization(SerializableMeta.class) public class CraftMetaAxolotlBucket extends CraftMetaItem implements AxolotlBucketMeta { - static final ItemMetaKey VARIANT = new ItemMetaKey("Variant", "axolotl-variant"); - static final ItemMetaKey ENTITY_TAG = new ItemMetaKey("EntityTag", "entity-tag"); + static final ItemMetaKey VARIANT = new ItemMetaKey("axolotl-variant"); + static final ItemMetaKeyType ENTITY_TAG = new ItemMetaKeyType<>(DataComponents.BUCKET_ENTITY_DATA, "entity-tag"); private Integer variant; private NBTTagCompound entityTag; @@ -31,16 +34,16 @@ public class CraftMetaAxolotlBucket extends CraftMetaItem implements AxolotlBuck this.entityTag = bucket.entityTag; } - CraftMetaAxolotlBucket(NBTTagCompound tag) { + CraftMetaAxolotlBucket(DataComponentPatch tag) { super(tag); - if (tag.contains(VARIANT.NBT, CraftMagicNumbers.NBT.TAG_INT)) { - this.variant = tag.getInt(VARIANT.NBT); - } + getOrEmpty(tag, ENTITY_TAG).ifPresent((nbt) -> { + entityTag = nbt.copyTag(); - if (tag.contains(ENTITY_TAG.NBT)) { - entityTag = tag.getCompound(ENTITY_TAG.NBT).copy(); - } + if (entityTag.contains("Variant", CraftMagicNumbers.NBT.TAG_INT)) { + this.variant = entityTag.getInt("Variant"); + } + }); } CraftMetaAxolotlBucket(Map map) { @@ -69,15 +72,18 @@ public class CraftMetaAxolotlBucket extends CraftMetaItem implements AxolotlBuck } @Override - void applyToItem(NBTTagCompound tag) { + void applyToItem(CraftMetaItem.Applicator tag) { super.applyToItem(tag); if (hasVariant()) { - tag.putInt(VARIANT.NBT, variant); + if (entityTag == null) { + entityTag = new NBTTagCompound(); + } + entityTag.putInt("Variant", variant); } if (entityTag != null) { - tag.put(ENTITY_TAG.NBT, entityTag); + tag.put(ENTITY_TAG, CustomData.of(entityTag)); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java index 6dbd000d75..a3637c5303 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBanner.java @@ -8,17 +8,19 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.EnumColor; +import net.minecraft.world.level.block.entity.BannerPatternLayers; import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.PatternType; import org.bukkit.configuration.serialization.DelegateDeserialization; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.block.banner.CraftPatternType; import org.bukkit.inventory.meta.BannerMeta; -@DelegateDeserialization(CraftMetaItem.SerializableMeta.class) +@DelegateDeserialization(SerializableMeta.class) public class CraftMetaBanner extends CraftMetaItem implements BannerMeta { private static final Set BANNER_MATERIALS = Sets.newHashSet( @@ -56,12 +58,8 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta { Material.YELLOW_WALL_BANNER ); - static final ItemMetaKey BASE = new ItemMetaKey("Base", "base-color"); - static final ItemMetaKey PATTERNS = new ItemMetaKey("Patterns", "patterns"); - static final ItemMetaKey COLOR = new ItemMetaKey("Color", "color"); - static final ItemMetaKey PATTERN = new ItemMetaKey("Pattern", "pattern"); + static final ItemMetaKeyType PATTERNS = new ItemMetaKeyType<>(DataComponents.BANNER_PATTERNS, "patterns"); - private DyeColor base; private List patterns = new ArrayList(); CraftMetaBanner(CraftMetaItem meta) { @@ -72,43 +70,29 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta { } CraftMetaBanner banner = (CraftMetaBanner) meta; - base = banner.base; patterns = new ArrayList(banner.patterns); } - CraftMetaBanner(NBTTagCompound tag) { + CraftMetaBanner(DataComponentPatch tag) { super(tag); - if (!tag.contains("BlockEntityTag")) { - return; - } - - NBTTagCompound entityTag = tag.getCompound("BlockEntityTag"); - - base = entityTag.contains(BASE.NBT) ? DyeColor.getByWoolData((byte) entityTag.getInt(BASE.NBT)) : null; - - if (entityTag.contains(PATTERNS.NBT)) { - NBTTagList patterns = entityTag.getList(PATTERNS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND); + getOrEmpty(tag, PATTERNS).ifPresent((entityTag) -> { + List patterns = entityTag.layers(); for (int i = 0; i < Math.min(patterns.size(), 20); i++) { - NBTTagCompound p = patterns.getCompound(i); - DyeColor color = DyeColor.getByWoolData((byte) p.getInt(COLOR.NBT)); - PatternType pattern = PatternType.getByIdentifier(p.getString(PATTERN.NBT)); + BannerPatternLayers.b p = patterns.get(i); + DyeColor color = DyeColor.getByWoolData((byte) p.color().getId()); + PatternType pattern = CraftPatternType.minecraftHolderToBukkit(p.pattern()); if (color != null && pattern != null) { this.patterns.add(new Pattern(color, pattern)); } } - } + }); } CraftMetaBanner(Map map) { super(map); - String baseStr = SerializableMeta.getString(map, BASE.BUKKIT, true); - if (baseStr != null) { - base = DyeColor.legacyValueOf(baseStr); - } - Iterable rawPatternList = SerializableMeta.getObject(Iterable.class, map, PATTERNS.BUKKIT, true); if (rawPatternList == null) { return; @@ -119,36 +103,18 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta { addPattern((Pattern) obj); } } + @Override - void applyToItem(NBTTagCompound tag) { + void applyToItem(CraftMetaItem.Applicator tag) { super.applyToItem(tag); - NBTTagCompound entityTag = new NBTTagCompound(); - if (base != null) { - entityTag.putInt(BASE.NBT, base.getWoolData()); - } - - NBTTagList newPatterns = new NBTTagList(); + List newPatterns = new ArrayList<>(); for (Pattern p : patterns) { - NBTTagCompound compound = new NBTTagCompound(); - compound.putInt(COLOR.NBT, p.getColor().getWoolData()); - compound.putString(PATTERN.NBT, p.getPattern().getIdentifier()); - newPatterns.add(compound); + newPatterns.add(new BannerPatternLayers.b(CraftPatternType.bukkitToMinecraftHolder(p.getPattern()), EnumColor.byId(p.getColor().getWoolData()))); } - entityTag.put(PATTERNS.NBT, newPatterns); - tag.put("BlockEntityTag", entityTag); - } - - @Override - public DyeColor getBaseColor() { - return base; - } - - @Override - public void setBaseColor(DyeColor color) { - base = color; + tag.put(PATTERNS, new BannerPatternLayers(newPatterns)); } @Override @@ -190,10 +156,6 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta { ImmutableMap.Builder serialize(ImmutableMap.Builder builder) { super.serialize(builder); - if (base != null) { - builder.put(BASE.BUKKIT, base.toString()); - } - if (!patterns.isEmpty()) { builder.put(PATTERNS.BUKKIT, ImmutableList.copyOf(patterns)); } @@ -205,9 +167,6 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta { int applyHash() { final int original; int hash = original = super.applyHash(); - if (base != null) { - hash = 31 * hash + base.hashCode(); - } if (!patterns.isEmpty()) { hash = 31 * hash + patterns.hashCode(); } @@ -222,19 +181,19 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta { if (meta instanceof CraftMetaBanner) { CraftMetaBanner that = (CraftMetaBanner) meta; - return base == that.base && patterns.equals(that.patterns); + return patterns.equals(that.patterns); } return true; } @Override boolean notUncommon(CraftMetaItem meta) { - return super.notUncommon(meta) && (meta instanceof CraftMetaBanner || (patterns.isEmpty() && base == null)); + return super.notUncommon(meta) && (meta instanceof CraftMetaBanner || patterns.isEmpty()); } @Override boolean isEmpty() { - return super.isEmpty() && patterns.isEmpty() && base == null; + return super.isEmpty() && patterns.isEmpty(); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java index 8da8f70180..5df772c9a0 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java @@ -4,20 +4,28 @@ import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; +import java.util.HashSet; +import java.util.Iterator; import java.util.Map; import java.util.Set; +import net.minecraft.core.component.DataComponentMap; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.component.DataComponents; +import net.minecraft.core.component.PatchedDataComponentMap; +import net.minecraft.core.component.TypedDataComponent; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.item.component.CustomData; import org.bukkit.Material; import org.bukkit.block.BlockState; import org.bukkit.configuration.serialization.DelegateDeserialization; -import org.bukkit.craftbukkit.block.CraftBanner; import org.bukkit.craftbukkit.block.CraftBlockEntityState; import org.bukkit.craftbukkit.block.CraftBlockStates; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.inventory.meta.BlockStateMeta; -@DelegateDeserialization(CraftMetaItem.SerializableMeta.class) +@DelegateDeserialization(SerializableMeta.class) public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta { private static final Set SHULKER_BOX_MATERIALS = Sets.newHashSet( @@ -123,19 +131,46 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta Material.SUSPICIOUS_SAND, Material.SUSPICIOUS_GRAVEL, Material.TRIAL_SPAWNER, - Material.CRAFTER + Material.CRAFTER, + Material.VAULT ); + private static final class TrackedDataComponentMap implements DataComponentMap { + + private final Set> seen = new HashSet<>(); + private final DataComponentMap handle; + + public TrackedDataComponentMap(DataComponentMap map) { + this.handle = map; + } + + @Override + public T get(DataComponentType type) { + seen.add(type); + return handle.get(type); + } + + @Override + public Set> keySet() { + return handle.keySet(); + } + + @Override + public Iterator> iterator() { + return handle.iterator(); + } + } + static { // Add shulker boxes to the list of block state materials too BLOCK_STATE_MATERIALS.addAll(SHULKER_BOX_MATERIALS); } @ItemMetaKey.Specific(ItemMetaKey.Specific.To.NBT) - static final ItemMetaKey BLOCK_ENTITY_TAG = new ItemMetaKey("BlockEntityTag"); + static final ItemMetaKeyType BLOCK_ENTITY_TAG = new ItemMetaKeyType<>(DataComponents.BLOCK_ENTITY_DATA, "BlockEntityTag"); final Material material; - NBTTagCompound blockEntityTag; + private CraftBlockEntityState blockEntityTag; CraftMetaBlockState(CraftMetaItem meta, Material material) { super(meta); @@ -151,14 +186,30 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta this.blockEntityTag = te.blockEntityTag; } - CraftMetaBlockState(NBTTagCompound tag, Material material) { + CraftMetaBlockState(DataComponentPatch tag, Material material) { super(tag); this.material = material; - if (tag.contains(BLOCK_ENTITY_TAG.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) { - blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT).copy(); - } else { - blockEntityTag = null; + getOrEmpty(tag, BLOCK_ENTITY_TAG).ifPresent((nbt) -> { + blockEntityTag = getBlockState(material, nbt.copyTag()); + }); + + if (!tag.isEmpty()) { + if (blockEntityTag == null) { + blockEntityTag = getBlockState(material, null); + } + + // Convert to map + PatchedDataComponentMap map = new PatchedDataComponentMap(DataComponentMap.EMPTY); + map.applyPatch(tag); + // Setup tracking + TrackedDataComponentMap track = new TrackedDataComponentMap(map); + // Apply + blockEntityTag.applyComponents(track, tag); + // Mark applied components as handled + for (DataComponentType seen : track.seen) { + unhandledTags.clear(seen); + } } } @@ -171,14 +222,19 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta } else { material = Material.AIR; } + blockEntityTag = getBlockState(material, null); } @Override - void applyToItem(NBTTagCompound tag) { + void applyToItem(CraftMetaItem.Applicator tag) { super.applyToItem(tag); if (blockEntityTag != null) { - tag.put(BLOCK_ENTITY_TAG.NBT, blockEntityTag); + tag.put(BLOCK_ENTITY_TAG, CustomData.of(blockEntityTag.getSnapshotNBTWithoutComponents())); + + for (TypedDataComponent component : blockEntityTag.collectComponents()) { + tag.builder.set(component); + } } } @@ -187,14 +243,14 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta super.deserializeInternal(tag, context); if (tag.contains(BLOCK_ENTITY_TAG.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) { - blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT); + blockEntityTag = getBlockState(material, tag.getCompound(BLOCK_ENTITY_TAG.NBT)); } } @Override void serializeInternal(final Map internalTags) { if (blockEntityTag != null) { - internalTags.put(BLOCK_ENTITY_TAG.NBT, blockEntityTag); + internalTags.put(BLOCK_ENTITY_TAG.NBT, blockEntityTag.getSnapshotNBT()); } } @@ -259,7 +315,11 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta @Override public BlockState getBlockState() { - Material stateMaterial = (material != Material.SHIELD) ? material : shieldToBannerHack(blockEntityTag); // Only actually used for jigsaws + return (blockEntityTag != null) ? blockEntityTag.copy() : getBlockState(material, null); + } + + private static CraftBlockEntityState getBlockState(Material material, NBTTagCompound blockEntityTag) { + Material stateMaterial = (material != Material.SHIELD) ? material : shieldToBannerHack(); // Only actually used for jigsaws if (blockEntityTag != null) { if (material == Material.SHIELD) { blockEntityTag.putString("id", "minecraft:banner"); @@ -271,64 +331,21 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta } // This is expected to always return a CraftBlockEntityState for the passed material: - return CraftBlockStates.getBlockState(stateMaterial, blockEntityTag); + return (CraftBlockEntityState) CraftBlockStates.getBlockState(stateMaterial, blockEntityTag); } @Override public void setBlockState(BlockState blockState) { Preconditions.checkArgument(blockState != null, "blockState must not be null"); - Material stateMaterial = (material != Material.SHIELD) ? material : shieldToBannerHack(blockEntityTag); + Material stateMaterial = (material != Material.SHIELD) ? material : shieldToBannerHack(); Class blockStateType = CraftBlockStates.getBlockStateType(stateMaterial); Preconditions.checkArgument(blockStateType == blockState.getClass() && blockState instanceof CraftBlockEntityState, "Invalid blockState for " + material); - blockEntityTag = ((CraftBlockEntityState) blockState).getSnapshotNBT(); - // Set shield base - if (material == Material.SHIELD) { - blockEntityTag.putInt(CraftMetaBanner.BASE.NBT, ((CraftBanner) blockState).getBaseColor().getWoolData()); - } + this.blockEntityTag = (CraftBlockEntityState) blockState; } - private static Material shieldToBannerHack(NBTTagCompound tag) { - if (tag == null || !tag.contains(CraftMetaBanner.BASE.NBT, CraftMagicNumbers.NBT.TAG_INT)) { - return Material.WHITE_BANNER; - } - - switch (tag.getInt(CraftMetaBanner.BASE.NBT)) { - case 0: - return Material.WHITE_BANNER; - case 1: - return Material.ORANGE_BANNER; - case 2: - return Material.MAGENTA_BANNER; - case 3: - return Material.LIGHT_BLUE_BANNER; - case 4: - return Material.YELLOW_BANNER; - case 5: - return Material.LIME_BANNER; - case 6: - return Material.PINK_BANNER; - case 7: - return Material.GRAY_BANNER; - case 8: - return Material.LIGHT_GRAY_BANNER; - case 9: - return Material.CYAN_BANNER; - case 10: - return Material.PURPLE_BANNER; - case 11: - return Material.BLUE_BANNER; - case 12: - return Material.BROWN_BANNER; - case 13: - return Material.GREEN_BANNER; - case 14: - return Material.RED_BANNER; - case 15: - return Material.BLACK_BANNER; - default: - throw new IllegalArgumentException("Unknown banner colour"); - } + private static Material shieldToBannerHack() { + return Material.WHITE_BANNER; } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java index d4c47feb05..d338430fde 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java @@ -9,177 +9,94 @@ import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Objects; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; -import net.minecraft.network.chat.IChatBaseComponent; -import net.minecraft.world.item.ItemWrittenBook; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import net.minecraft.server.network.Filterable; +import net.minecraft.server.network.FilteredText; +import net.minecraft.world.item.component.WritableBookContent; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; -import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta; import org.bukkit.craftbukkit.util.CraftChatMessage; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.inventory.meta.BookMeta; +import org.bukkit.inventory.meta.WritableBookMeta; @DelegateDeserialization(SerializableMeta.class) -public class CraftMetaBook extends CraftMetaItem implements BookMeta { - static final ItemMetaKey BOOK_TITLE = new ItemMetaKey("title"); - static final ItemMetaKey BOOK_AUTHOR = new ItemMetaKey("author"); +public class CraftMetaBook extends CraftMetaItem implements BookMeta, WritableBookMeta { + @ItemMetaKey.Specific(ItemMetaKey.Specific.To.NBT) + static final ItemMetaKeyType BOOK_CONTENT = new ItemMetaKeyType<>(DataComponents.WRITABLE_BOOK_CONTENT); static final ItemMetaKey BOOK_PAGES = new ItemMetaKey("pages"); - static final ItemMetaKey RESOLVED = new ItemMetaKey("resolved"); - static final ItemMetaKey GENERATION = new ItemMetaKey("generation"); - static final int MAX_PAGES = ItemWrittenBook.MAX_PAGES; // SPIGOT-6911: Use Minecraft limits - static final int MAX_PAGE_LENGTH = ItemWrittenBook.PAGE_EDIT_LENGTH; // SPIGOT-6911: Use Minecraft limits - static final int MAX_TITLE_LENGTH = ItemWrittenBook.TITLE_MAX_LENGTH; // SPIGOT-6911: Use Minecraft limits + static final int MAX_PAGES = Integer.MAX_VALUE; // SPIGOT-6911: Use Minecraft limits + static final int MAX_PAGE_LENGTH = WritableBookContent.PAGE_EDIT_LENGTH; // SPIGOT-6911: Use Minecraft limits - protected String title; - protected String author; // We store the pages in their raw original text representation. See SPIGOT-5063, SPIGOT-5350, SPIGOT-3206 // For writable books (CraftMetaBook) the pages are stored as plain Strings. - // For written books (CraftMetaBookSigned) the pages are stored in Minecraft's JSON format. protected List pages; // null and empty are two different states internally - protected Boolean resolved = null; - protected Integer generation; CraftMetaBook(CraftMetaItem meta) { super(meta); if (meta instanceof CraftMetaBook) { CraftMetaBook bookMeta = (CraftMetaBook) meta; - this.title = bookMeta.title; - this.author = bookMeta.author; - this.resolved = bookMeta.resolved; - this.generation = bookMeta.generation; if (bookMeta.pages != null) { this.pages = new ArrayList(bookMeta.pages.size()); - if (meta instanceof CraftMetaBookSigned) { - if (this instanceof CraftMetaBookSigned) { - pages.addAll(bookMeta.pages); - } else { - // Convert from JSON to plain Strings: - pages.addAll(Lists.transform(bookMeta.pages, CraftChatMessage::fromJSONComponent)); - } - } else { - if (this instanceof CraftMetaBookSigned) { - // Convert from plain Strings to JSON: - // This happens for example during book signing. - for (String page : bookMeta.pages) { - // We don't insert any non-plain text features (such as clickable links) during this conversion. - IChatBaseComponent component = CraftChatMessage.fromString(page, true, true)[0]; - pages.add(CraftChatMessage.toJSON(component)); - } - } else { - pages.addAll(bookMeta.pages); - } - } + + pages.addAll(bookMeta.pages); + } + } else if (meta instanceof CraftMetaBookSigned) { + CraftMetaBookSigned bookMeta = (CraftMetaBookSigned) meta; + + if (bookMeta.pages != null) { + this.pages = new ArrayList(bookMeta.pages.size()); + + // Convert from JSON to plain Strings: + pages.addAll(Lists.transform(bookMeta.pages, CraftChatMessage::fromComponent)); } } } - CraftMetaBook(NBTTagCompound tag) { + CraftMetaBook(DataComponentPatch tag) { super(tag); - if (tag.contains(BOOK_TITLE.NBT)) { - this.title = tag.getString(BOOK_TITLE.NBT); - } - - if (tag.contains(BOOK_AUTHOR.NBT)) { - this.author = tag.getString(BOOK_AUTHOR.NBT); - } - - if (tag.contains(RESOLVED.NBT)) { - this.resolved = tag.getBoolean(RESOLVED.NBT); - } - - if (tag.contains(GENERATION.NBT)) { - generation = tag.getInt(GENERATION.NBT); - } - - if (tag.contains(BOOK_PAGES.NBT)) { - NBTTagList pages = tag.getList(BOOK_PAGES.NBT, CraftMagicNumbers.NBT.TAG_STRING); + getOrEmpty(tag, BOOK_CONTENT).ifPresent((writable) -> { + List> pages = writable.pages(); this.pages = new ArrayList(pages.size()); - boolean expectJson = (this instanceof CraftMetaBookSigned); // Note: We explicitly check for and truncate oversized books and pages, // because they can come directly from clients when handling book edits. for (int i = 0; i < Math.min(pages.size(), MAX_PAGES); i++) { - String page = pages.getString(i); - // There was an issue on previous Spigot versions which would - // result in book items with pages in the wrong text - // representation. See SPIGOT-182, SPIGOT-164 - if (expectJson) { - page = CraftChatMessage.fromJSONOrStringToJSON(page, false, true, MAX_PAGE_LENGTH, false); - } else { - page = validatePage(page); - } + String page = pages.get(i).raw(); + page = validatePage(page); + this.pages.add(page); } - } + }); } CraftMetaBook(Map map) { super(map); - setAuthor(SerializableMeta.getString(map, BOOK_AUTHOR.BUKKIT, true)); - - setTitle(SerializableMeta.getString(map, BOOK_TITLE.BUKKIT, true)); - Iterable pages = SerializableMeta.getObject(Iterable.class, map, BOOK_PAGES.BUKKIT, true); if (pages != null) { this.pages = new ArrayList(); for (Object page : pages) { if (page instanceof String) { - internalAddPage(deserializePage((String) page)); + internalAddPage(validatePage((String) page)); } } } - - resolved = SerializableMeta.getObject(Boolean.class, map, RESOLVED.BUKKIT, true); - generation = SerializableMeta.getObject(Integer.class, map, GENERATION.BUKKIT, true); - } - - protected String deserializePage(String pageData) { - // We expect the page data to already be a plain String. - return validatePage(pageData); - } - - protected String convertPlainPageToData(String page) { - // Writable books store their data as plain Strings, so we don't need to convert anything. - return page; - } - - protected String convertDataToPlainPage(String pageData) { - // pageData is expected to already be a plain String. - return pageData; } @Override - void applyToItem(NBTTagCompound itemData) { + void applyToItem(CraftMetaItem.Applicator itemData) { super.applyToItem(itemData); - if (hasTitle()) { - itemData.putString(BOOK_TITLE.NBT, this.title); - } - - if (hasAuthor()) { - itemData.putString(BOOK_AUTHOR.NBT, this.author); - } - if (pages != null) { - NBTTagList list = new NBTTagList(); + List> list = new ArrayList<>(); for (String page : pages) { - list.add(NBTTagString.valueOf(page)); + list.add(Filterable.from(FilteredText.passThrough(page))); } - itemData.put(BOOK_PAGES.NBT, list); - } - - if (resolved != null) { - itemData.putBoolean(RESOLVED.NBT, resolved); - } - - if (generation != null) { - itemData.putInt(GENERATION.NBT, generation); + itemData.put(BOOK_CONTENT, new WritableBookContent(list)); } } @@ -189,22 +106,22 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta { } boolean isBookEmpty() { - return !((pages != null) || hasAuthor() || hasTitle() || hasGeneration() || (resolved != null)); + return !(pages != null); } @Override boolean applicableTo(Material type) { - return type == Material.WRITTEN_BOOK || type == Material.WRITABLE_BOOK; + return type == Material.WRITABLE_BOOK; } @Override public boolean hasAuthor() { - return this.author != null; + return false; } @Override public boolean hasTitle() { - return this.title != null; + return false; } @Override @@ -214,52 +131,42 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta { @Override public boolean hasGeneration() { - return generation != null; + return false; } @Override public String getTitle() { - return this.title; + return null; } @Override public boolean setTitle(final String title) { - if (title == null) { - this.title = null; - return true; - } else if (title.length() > MAX_TITLE_LENGTH) { - return false; - } - - this.title = title; - return true; + return false; } @Override public String getAuthor() { - return this.author; + return null; } @Override public void setAuthor(final String author) { - this.author = author; } @Override public Generation getGeneration() { - return (generation == null) ? null : Generation.values()[generation]; + return null; } @Override public void setGeneration(Generation generation) { - this.generation = (generation == null) ? null : generation.ordinal(); } @Override public String getPage(final int page) { Preconditions.checkArgument(isValidPage(page), "Invalid page number (%s)", page); // assert: pages != null - return convertDataToPlainPage(pages.get(page - 1)); + return pages.get(page - 1); } @Override @@ -268,7 +175,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta { // assert: pages != null String newText = validatePage(text); - pages.set(page - 1, convertPlainPageToData(newText)); + pages.set(page - 1, newText); } @Override @@ -280,7 +187,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta { public void addPage(final String... pages) { for (String page : pages) { page = validatePage(page); - internalAddPage(convertPlainPageToData(page)); + internalAddPage(page); } } @@ -311,7 +218,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta { @Override public List getPages() { if (pages == null) return ImmutableList.of(); - return pages.stream().map(this::convertDataToPlainPage).collect(ImmutableList.toImmutableList()); + return pages.stream().collect(ImmutableList.toImmutableList()); } @Override @@ -333,15 +240,6 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta { return page > 0 && page <= getPageCount(); } - // TODO Expose this attribute in Bukkit? - public boolean isResolved() { - return (resolved == null) ? false : resolved; - } - - public void setResolved(boolean resolved) { - this.resolved = resolved; - } - @Override public CraftMetaBook clone() { CraftMetaBook meta = (CraftMetaBook) super.clone(); @@ -355,21 +253,9 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta { int applyHash() { final int original; int hash = original = super.applyHash(); - if (hasTitle()) { - hash = 61 * hash + this.title.hashCode(); - } - if (hasAuthor()) { - hash = 61 * hash + 13 * this.author.hashCode(); - } if (this.pages != null) { hash = 61 * hash + 17 * this.pages.hashCode(); } - if (this.resolved != null) { - hash = 61 * hash + 17 * this.resolved.hashCode(); - } - if (hasGeneration()) { - hash = 61 * hash + 19 * this.generation.hashCode(); - } return original != hash ? CraftMetaBook.class.hashCode() ^ hash : hash; } @@ -380,11 +266,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta { } if (meta instanceof CraftMetaBook that) { - return (hasTitle() ? that.hasTitle() && this.title.equals(that.title) : !that.hasTitle()) - && (hasAuthor() ? that.hasAuthor() && this.author.equals(that.author) : !that.hasAuthor()) - && (Objects.equals(this.pages, that.pages)) - && (Objects.equals(this.resolved, that.resolved)) - && (hasGeneration() ? that.hasGeneration() && this.generation.equals(that.generation) : !that.hasGeneration()); + return (Objects.equals(this.pages, that.pages)); } return true; } @@ -398,26 +280,10 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta { Builder serialize(Builder builder) { super.serialize(builder); - if (hasTitle()) { - builder.put(BOOK_TITLE.BUKKIT, title); - } - - if (hasAuthor()) { - builder.put(BOOK_AUTHOR.BUKKIT, author); - } - if (pages != null) { builder.put(BOOK_PAGES.BUKKIT, ImmutableList.copyOf(pages)); } - if (resolved != null) { - builder.put(RESOLVED.BUKKIT, resolved); - } - - if (generation != null) { - builder.put(GENERATION.BUKKIT, generation); - } - return builder; } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java index ffd2842448..0e0511a8f5 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java @@ -1,62 +1,297 @@ package org.bukkit.craftbukkit.inventory; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap.Builder; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Map; -import net.minecraft.nbt.NBTTagCompound; +import java.util.Objects; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import net.minecraft.network.chat.IChatBaseComponent; +import net.minecraft.server.network.Filterable; +import net.minecraft.server.network.FilteredText; +import net.minecraft.world.item.component.WritableBookContent; +import net.minecraft.world.item.component.WrittenBookContent; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; -import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta; import org.bukkit.craftbukkit.util.CraftChatMessage; import org.bukkit.inventory.meta.BookMeta; @DelegateDeserialization(SerializableMeta.class) -class CraftMetaBookSigned extends CraftMetaBook implements BookMeta { +public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta { + @ItemMetaKey.Specific(ItemMetaKey.Specific.To.NBT) + static final ItemMetaKeyType BOOK_CONTENT = new ItemMetaKeyType<>(DataComponents.WRITTEN_BOOK_CONTENT); + static final ItemMetaKey BOOK_TITLE = new ItemMetaKey("title"); + static final ItemMetaKey BOOK_AUTHOR = new ItemMetaKey("author"); + static final ItemMetaKey BOOK_PAGES = new ItemMetaKey("pages"); + static final ItemMetaKey RESOLVED = new ItemMetaKey("resolved"); + static final ItemMetaKey GENERATION = new ItemMetaKey("generation"); + static final int MAX_PAGES = Integer.MAX_VALUE; // SPIGOT-6911: Use Minecraft limits + static final int MAX_PAGE_LENGTH = WritableBookContent.PAGE_EDIT_LENGTH; // SPIGOT-6911: Use Minecraft limits + static final int MAX_TITLE_LENGTH = WrittenBookContent.TITLE_MAX_LENGTH; // SPIGOT-6911: Use Minecraft limits + + protected String title; + protected String author; + // We store the pages in their raw original text representation. See SPIGOT-5063, SPIGOT-5350, SPIGOT-3206 + // For written books (CraftMetaBookSigned) the pages are stored in Minecraft's JSON format. + protected List pages; // null and empty are two different states internally + protected boolean resolved; + protected int generation; CraftMetaBookSigned(CraftMetaItem meta) { super(meta); + + if (meta instanceof CraftMetaBookSigned) { + CraftMetaBookSigned bookMeta = (CraftMetaBookSigned) meta; + this.title = bookMeta.title; + this.author = bookMeta.author; + this.resolved = bookMeta.resolved; + this.generation = bookMeta.generation; + + if (bookMeta.pages != null) { + this.pages = new ArrayList(bookMeta.pages.size()); + pages.addAll(bookMeta.pages); + } + } else if (meta instanceof CraftMetaBook) { + CraftMetaBook bookMeta = (CraftMetaBook) meta; + + if (bookMeta.pages != null) { + this.pages = new ArrayList(bookMeta.pages.size()); + + // Convert from plain Strings to JSON: + // This happens for example during book signing. + for (String page : bookMeta.pages) { + // We don't insert any non-plain text features (such as clickable links) during this conversion. + IChatBaseComponent component = CraftChatMessage.fromString(page, true, true)[0]; + pages.add(component); + } + } + } } - CraftMetaBookSigned(NBTTagCompound tag) { + CraftMetaBookSigned(DataComponentPatch tag) { super(tag); + + getOrEmpty(tag, BOOK_CONTENT).ifPresent((written) -> { + this.title = written.title().raw(); + this.author = written.author(); + this.resolved = written.resolved(); + this.generation = written.generation(); + + List> pages = written.pages(); + this.pages = new ArrayList(pages.size()); + // Note: We explicitly check for and truncate oversized books and pages, + // because they can come directly from clients when handling book edits. + for (int i = 0; i < Math.min(pages.size(), MAX_PAGES); i++) { + IChatBaseComponent page = pages.get(i).raw(); + + this.pages.add(page); + } + }); } CraftMetaBookSigned(Map map) { super(map); + + setAuthor(SerializableMeta.getString(map, BOOK_AUTHOR.BUKKIT, true)); + + setTitle(SerializableMeta.getString(map, BOOK_TITLE.BUKKIT, true)); + + Iterable pages = SerializableMeta.getObject(Iterable.class, map, BOOK_PAGES.BUKKIT, true); + if (pages != null) { + this.pages = new ArrayList(); + for (Object page : pages) { + if (page instanceof String) { + internalAddPage(CraftChatMessage.fromJSON(CraftChatMessage.fromJSONOrStringToJSON((String) page, false, true, MAX_PAGE_LENGTH, false))); + } + } + } + + resolved = SerializableMeta.getObject(Boolean.class, map, RESOLVED.BUKKIT, true); + generation = SerializableMeta.getObject(Integer.class, map, GENERATION.BUKKIT, true); } @Override - protected String deserializePage(String pageData) { - return CraftChatMessage.fromJSONOrStringToJSON(pageData, false, true, MAX_PAGE_LENGTH, false); - } - - @Override - protected String convertPlainPageToData(String page) { - return CraftChatMessage.fromStringToJSON(page, true); - } - - @Override - protected String convertDataToPlainPage(String pageData) { - return CraftChatMessage.fromJSONComponent(pageData); - } - - @Override - void applyToItem(NBTTagCompound itemData) { + void applyToItem(CraftMetaItem.Applicator itemData) { super.applyToItem(itemData); + + if (pages != null) { + List> list = new ArrayList<>(); + for (IChatBaseComponent page : pages) { + list.add(Filterable.passThrough(page)); + } + itemData.put(BOOK_CONTENT, new WrittenBookContent(Filterable.from(FilteredText.passThrough(title)), this.author, this.generation, list, this.resolved)); + } } @Override boolean isEmpty() { - return super.isEmpty(); + return super.isEmpty() && isBookEmpty(); + } + + boolean isBookEmpty() { + return !((pages != null) || hasAuthor() || hasTitle() || hasGeneration() || resolved); } @Override boolean applicableTo(Material type) { - return type == Material.WRITTEN_BOOK || type == Material.WRITABLE_BOOK; + return type == Material.WRITTEN_BOOK; + } + + @Override + public boolean hasAuthor() { + return this.author != null; + } + + @Override + public boolean hasTitle() { + return this.title != null; + } + + @Override + public boolean hasPages() { + return (pages != null) && !pages.isEmpty(); + } + + @Override + public boolean hasGeneration() { + return generation != 0; + } + + @Override + public String getTitle() { + return this.title; + } + + @Override + public boolean setTitle(final String title) { + if (title == null) { + this.title = null; + return true; + } else if (title.length() > MAX_TITLE_LENGTH) { + return false; + } + + this.title = title; + return true; + } + + @Override + public String getAuthor() { + return this.author; + } + + @Override + public void setAuthor(final String author) { + this.author = author; + } + + @Override + public Generation getGeneration() { + return Generation.values()[generation]; + } + + @Override + public void setGeneration(Generation generation) { + this.generation = (generation == null) ? 0 : generation.ordinal(); + } + + @Override + public String getPage(final int page) { + Preconditions.checkArgument(isValidPage(page), "Invalid page number (%s)", page); + // assert: pages != null + return CraftChatMessage.fromComponent(pages.get(page - 1)); + } + + @Override + public void setPage(final int page, final String text) { + Preconditions.checkArgument(isValidPage(page), "Invalid page number (%s/%s)", page, getPageCount()); + // assert: pages != null + + String newText = validatePage(text); + pages.set(page - 1, CraftChatMessage.fromStringOrNull(newText, true)); + } + + @Override + public void setPages(final String... pages) { + setPages(Arrays.asList(pages)); + } + + @Override + public void addPage(final String... pages) { + for (String page : pages) { + page = validatePage(page); + internalAddPage(CraftChatMessage.fromStringOrNull(page, true)); + } + } + + String validatePage(String page) { + if (page == null) { + page = ""; + } else if (page.length() > MAX_PAGE_LENGTH) { + page = page.substring(0, MAX_PAGE_LENGTH); + } + return page; + } + + private void internalAddPage(IChatBaseComponent page) { + // asserted: page != null + if (this.pages == null) { + this.pages = new ArrayList(); + } else if (this.pages.size() >= MAX_PAGES) { + return; + } + this.pages.add(page); + } + + @Override + public int getPageCount() { + return (pages == null) ? 0 : pages.size(); + } + + @Override + public List getPages() { + if (pages == null) return ImmutableList.of(); + return pages.stream().map(CraftChatMessage::fromComponent).collect(ImmutableList.toImmutableList()); + } + + @Override + public void setPages(List pages) { + if (pages.isEmpty()) { + this.pages = null; + return; + } + + if (this.pages != null) { + this.pages.clear(); + } + for (String page : pages) { + addPage(page); + } + } + + private boolean isValidPage(int page) { + return page > 0 && page <= getPageCount(); + } + + // TODO Expose this attribute in Bukkit? + public boolean isResolved() { + return resolved; + } + + public void setResolved(boolean resolved) { + this.resolved = resolved; } @Override public CraftMetaBookSigned clone() { CraftMetaBookSigned meta = (CraftMetaBookSigned) super.clone(); + if (this.pages != null) { + meta.pages = new ArrayList(this.pages); + } return meta; } @@ -64,12 +299,34 @@ class CraftMetaBookSigned extends CraftMetaBook implements BookMeta { int applyHash() { final int original; int hash = original = super.applyHash(); - return original != hash ? CraftMetaBookSigned.class.hashCode() ^ hash : hash; + if (hasTitle()) { + hash = 61 * hash + this.title.hashCode(); + } + if (hasAuthor()) { + hash = 61 * hash + 13 * this.author.hashCode(); + } + if (this.pages != null) { + hash = 61 * hash + 17 * this.pages.hashCode(); + } + hash = 61 * hash + 17 * Boolean.hashCode(resolved); + hash = 61 * hash + 19 * Integer.hashCode(generation); + return original != hash ? CraftMetaBook.class.hashCode() ^ hash : hash; } @Override boolean equalsCommon(CraftMetaItem meta) { - return super.equalsCommon(meta); + if (!super.equalsCommon(meta)) { + return false; + } + if (meta instanceof CraftMetaBookSigned that) { + + return (hasTitle() ? that.hasTitle() && this.title.equals(that.title) : !that.hasTitle()) + && (hasAuthor() ? that.hasAuthor() && this.author.equals(that.author) : !that.hasAuthor()) + && (Objects.equals(this.pages, that.pages)) + && (Objects.equals(this.resolved, that.resolved)) + && (Objects.equals(this.generation, that.generation)); + } + return true; } @Override @@ -80,6 +337,27 @@ class CraftMetaBookSigned extends CraftMetaBook implements BookMeta { @Override Builder serialize(Builder builder) { super.serialize(builder); + + if (hasTitle()) { + builder.put(BOOK_TITLE.BUKKIT, title); + } + + if (hasAuthor()) { + builder.put(BOOK_AUTHOR.BUKKIT, author); + } + + if (pages != null) { + builder.put(BOOK_PAGES.BUKKIT, ImmutableList.copyOf(pages)); + } + + if (resolved) { + builder.put(RESOLVED.BUKKIT, resolved); + } + + if (generation != 0) { + builder.put(GENERATION.BUKKIT, generation); + } + return builder; } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBundle.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBundle.java index 10f5205859..9be9ff7239 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBundle.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBundle.java @@ -6,18 +6,18 @@ import com.google.common.collect.ImmutableMap; import java.util.ArrayList; import java.util.List; import java.util.Map; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.component.BundleContents; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BundleMeta; -@DelegateDeserialization(CraftMetaItem.SerializableMeta.class) +@DelegateDeserialization(SerializableMeta.class) public class CraftMetaBundle extends CraftMetaItem implements BundleMeta { - static final ItemMetaKey ITEMS = new ItemMetaKey("Items", "items"); + static final ItemMetaKeyType ITEMS = new ItemMetaKeyType<>(DataComponents.BUNDLE_CONTENTS, "items"); // private List items; @@ -35,25 +35,18 @@ public class CraftMetaBundle extends CraftMetaItem implements BundleMeta { } } - CraftMetaBundle(NBTTagCompound tag) { + CraftMetaBundle(DataComponentPatch tag) { super(tag); - if (tag.contains(ITEMS.NBT, CraftMagicNumbers.NBT.TAG_LIST)) { - NBTTagList list = tag.getList(ITEMS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND); + getOrEmpty(tag, ITEMS).ifPresent((bundle) -> { + bundle.items().forEach((item) -> { + ItemStack itemStack = CraftItemStack.asCraftMirror(item); - if (list != null && !list.isEmpty()) { - items = new ArrayList<>(); - - for (int i = 0; i < list.size(); i++) { - NBTTagCompound nbttagcompound1 = list.getCompound(i); - - ItemStack itemStack = CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.of(nbttagcompound1)); - if (!itemStack.getType().isAir()) { // SPIGOT-7174 - Avoid adding air - addItem(itemStack); - } + if (!itemStack.getType().isAir()) { // SPIGOT-7174 - Avoid adding air + addItem(itemStack); } - } - } + }); + }); } CraftMetaBundle(Map map) { @@ -70,19 +63,17 @@ public class CraftMetaBundle extends CraftMetaItem implements BundleMeta { } @Override - void applyToItem(NBTTagCompound tag) { + void applyToItem(CraftMetaItem.Applicator tag) { super.applyToItem(tag); if (hasItems()) { - NBTTagList list = new NBTTagList(); + List list = new ArrayList<>(); for (ItemStack item : items) { - NBTTagCompound saved = new NBTTagCompound(); - CraftItemStack.asNMSCopy(item).save(saved); - list.add(saved); + list.add(CraftItemStack.asNMSCopy(item)); } - tag.put(ITEMS.NBT, list); + tag.put(ITEMS, new BundleContents(list)); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCharge.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCharge.java index c46cbefedc..9637d0cca8 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCharge.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCharge.java @@ -2,16 +2,17 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.collect.ImmutableMap.Builder; import java.util.Map; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.component.FireworkExplosion; import org.bukkit.FireworkEffect; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; -import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta; import org.bukkit.inventory.meta.FireworkEffectMeta; @DelegateDeserialization(SerializableMeta.class) class CraftMetaCharge extends CraftMetaItem implements FireworkEffectMeta { - static final ItemMetaKey EXPLOSION = new ItemMetaKey("Explosion", "firework-effect"); + static final ItemMetaKeyType EXPLOSION = new ItemMetaKeyType<>(DataComponents.FIREWORK_EXPLOSION, "firework-effect"); private FireworkEffect effect; @@ -29,16 +30,16 @@ class CraftMetaCharge extends CraftMetaItem implements FireworkEffectMeta { setEffect(SerializableMeta.getObject(FireworkEffect.class, map, EXPLOSION.BUKKIT, true)); } - CraftMetaCharge(NBTTagCompound tag) { + CraftMetaCharge(DataComponentPatch tag) { super(tag); - if (tag.contains(EXPLOSION.NBT)) { + getOrEmpty(tag, EXPLOSION).ifPresent((f) -> { try { - effect = CraftMetaFirework.getEffect(tag.getCompound(EXPLOSION.NBT)); + effect = CraftMetaFirework.getEffect(f); } catch (IllegalArgumentException ex) { // Ignore invalid effects } - } + }); } @Override @@ -57,11 +58,11 @@ class CraftMetaCharge extends CraftMetaItem implements FireworkEffectMeta { } @Override - void applyToItem(NBTTagCompound itemTag) { + void applyToItem(CraftMetaItem.Applicator itemTag) { super.applyToItem(itemTag); if (hasEffect()) { - itemTag.put(EXPLOSION.NBT, CraftMetaFirework.getExplosion(effect)); + itemTag.put(EXPLOSION, CraftMetaFirework.getExplosion(effect)); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaColorableArmor.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaColorableArmor.java index c9ada7d8e6..2c7488d088 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaColorableArmor.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaColorableArmor.java @@ -5,13 +5,13 @@ import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Sets; import java.util.Map; import java.util.Set; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.core.component.DataComponentPatch; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.inventory.meta.ColorableArmorMeta; -@DelegateDeserialization(CraftMetaItem.SerializableMeta.class) +@DelegateDeserialization(SerializableMeta.class) public class CraftMetaColorableArmor extends CraftMetaArmor implements ColorableArmorMeta { private static final Set LEATHER_ARMOR_MATERIALS = Sets.newHashSet( @@ -28,7 +28,7 @@ public class CraftMetaColorableArmor extends CraftMetaArmor implements Colorable CraftMetaLeatherArmor.readColor(this, meta); } - CraftMetaColorableArmor(NBTTagCompound tag) { + CraftMetaColorableArmor(DataComponentPatch tag) { super(tag); CraftMetaLeatherArmor.readColor(this, tag); } @@ -39,7 +39,7 @@ public class CraftMetaColorableArmor extends CraftMetaArmor implements Colorable } @Override - void applyToItem(NBTTagCompound itemTag) { + void applyToItem(CraftMetaItem.Applicator itemTag) { super.applyToItem(itemTag); CraftMetaLeatherArmor.applyColor(this, itemTag); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCompass.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCompass.java index 02f55439df..069a4e9646 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCompass.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCompass.java @@ -2,16 +2,18 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap.Builder; -import com.mojang.serialization.DataResult; import java.util.Map; import java.util.Optional; -import net.minecraft.nbt.DynamicOpsNBT; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagString; +import net.minecraft.core.BlockPosition; +import net.minecraft.core.GlobalPos; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.MinecraftKey; import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.WorldServer; +import net.minecraft.world.item.component.LodestoneTracker; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -19,22 +21,22 @@ import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.inventory.meta.CompassMeta; -@DelegateDeserialization(CraftMetaItem.SerializableMeta.class) +@DelegateDeserialization(SerializableMeta.class) public class CraftMetaCompass extends CraftMetaItem implements CompassMeta { - static final ItemMetaKey LODESTONE_DIMENSION = new ItemMetaKey("LodestoneDimension"); - static final ItemMetaKey LODESTONE_POS = new ItemMetaKey("LodestonePos", "lodestone"); + static final ItemMetaKeyType LODESTONE_TARGET = new ItemMetaKeyType<>(DataComponents.LODESTONE_TRACKER, "LodestoneDimension"); + static final ItemMetaKey LODESTONE_POS = new ItemMetaKey("lodestone"); static final ItemMetaKey LODESTONE_POS_WORLD = new ItemMetaKey("LodestonePosWorld"); static final ItemMetaKey LODESTONE_POS_X = new ItemMetaKey("LodestonePosX"); static final ItemMetaKey LODESTONE_POS_Y = new ItemMetaKey("LodestonePosY"); static final ItemMetaKey LODESTONE_POS_Z = new ItemMetaKey("LodestonePosZ"); static final ItemMetaKey LODESTONE_TRACKED = new ItemMetaKey("LodestoneTracked"); - private NBTTagString lodestoneWorld; + private ResourceKey lodestoneWorld; private int lodestoneX; private int lodestoneY; private int lodestoneZ; - private Boolean tracked; + private boolean tracked = true; CraftMetaCompass(CraftMetaItem meta) { super(meta); @@ -49,25 +51,25 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta { tracked = compassMeta.tracked; } - CraftMetaCompass(NBTTagCompound tag) { + CraftMetaCompass(DataComponentPatch tag) { super(tag); - if (tag.contains(LODESTONE_DIMENSION.NBT) && tag.contains(LODESTONE_POS.NBT)) { - lodestoneWorld = (NBTTagString) tag.get(LODESTONE_DIMENSION.NBT); - NBTTagCompound pos = tag.getCompound(LODESTONE_POS.NBT); - lodestoneX = pos.getInt("X"); - lodestoneY = pos.getInt("Y"); - lodestoneZ = pos.getInt("Z"); - } - if (tag.contains(LODESTONE_TRACKED.NBT)) { - tracked = tag.getBoolean(LODESTONE_TRACKED.NBT); - } + getOrEmpty(tag, LODESTONE_TARGET).ifPresent((lodestoneTarget) -> { + lodestoneTarget.target().ifPresent((target) -> { + lodestoneWorld = target.dimension(); + BlockPosition pos = target.pos(); + lodestoneX = pos.getX(); + lodestoneY = pos.getY(); + lodestoneZ = pos.getZ(); + }); + tracked = lodestoneTarget.tracked(); + }); } CraftMetaCompass(Map map) { super(map); String lodestoneWorldString = SerializableMeta.getString(map, LODESTONE_POS_WORLD.BUKKIT, true); if (lodestoneWorldString != null) { - lodestoneWorld = NBTTagString.valueOf(lodestoneWorldString); + lodestoneWorld = ResourceKey.create(Registries.DIMENSION, MinecraftKey.tryParse(lodestoneWorldString)); lodestoneX = (Integer) map.get(LODESTONE_POS_X.BUKKIT); lodestoneY = (Integer) map.get(LODESTONE_POS_Y.BUKKIT); lodestoneZ = (Integer) map.get(LODESTONE_POS_Z.BUKKIT); @@ -82,20 +84,16 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta { } @Override - void applyToItem(NBTTagCompound tag) { + void applyToItem(CraftMetaItem.Applicator tag) { super.applyToItem(tag); + Optional target = Optional.empty(); if (lodestoneWorld != null) { - NBTTagCompound pos = new NBTTagCompound(); - pos.putInt("X", lodestoneX); - pos.putInt("Y", lodestoneY); - pos.putInt("Z", lodestoneZ); - tag.put(LODESTONE_POS.NBT, pos); - tag.put(LODESTONE_DIMENSION.NBT, lodestoneWorld); + target = Optional.of(new GlobalPos(lodestoneWorld, new BlockPosition(lodestoneX, lodestoneY, lodestoneZ))); } - if (tracked != null) { - tag.putBoolean(LODESTONE_TRACKED.NBT, tracked); + if (target.isPresent() || hasLodestoneTracked()) { + tag.put(LODESTONE_TARGET, new LodestoneTracker(target, tracked)); } } @@ -129,8 +127,7 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta { if (lodestoneWorld == null) { return null; } - Optional> key = net.minecraft.world.level.World.RESOURCE_KEY_CODEC.parse(DynamicOpsNBT.INSTANCE, lodestoneWorld).result(); - WorldServer worldServer = key.isPresent() ? MinecraftServer.getServer().getLevel(key.get()) : null; + WorldServer worldServer = MinecraftServer.getServer().getLevel(lodestoneWorld); World world = worldServer != null ? worldServer.getWorld() : null; return new Location(world, lodestoneX, lodestoneY, lodestoneZ); // world may be null here, if the referenced world is not loaded } @@ -141,9 +138,7 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta { if (lodestone == null) { this.lodestoneWorld = null; } else { - ResourceKey key = ((CraftWorld) lodestone.getWorld()).getHandle().dimension(); - DataResult dataresult = net.minecraft.world.level.World.RESOURCE_KEY_CODEC.encodeStart(DynamicOpsNBT.INSTANCE, key); - this.lodestoneWorld = (NBTTagString) dataresult.get().orThrow(); + this.lodestoneWorld = ((CraftWorld) lodestone.getWorld()).getHandle().dimension(); this.lodestoneX = lodestone.getBlockX(); this.lodestoneY = lodestone.getBlockY(); this.lodestoneZ = lodestone.getBlockZ(); @@ -151,12 +146,12 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta { } boolean hasLodestoneTracked() { - return tracked != null; + return !tracked; } @Override public boolean isLodestoneTracked() { - return hasLodestoneTracked() && tracked; + return tracked; } @Override @@ -174,9 +169,7 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta { hash = 73 * hash + lodestoneY; hash = 73 * hash + lodestoneZ; } - if (hasLodestoneTracked()) { - hash = 73 * hash + (isLodestoneTracked() ? 1231 : 1237); - } + hash = 73 * hash + (isLodestoneTracked() ? 1231 : 1237); return original != hash ? CraftMetaCompass.class.hashCode() ^ hash : hash; } @@ -189,7 +182,7 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta { if (meta instanceof CraftMetaCompass) { CraftMetaCompass that = (CraftMetaCompass) meta; - return (this.hasLodestone() ? that.hasLodestone() && this.lodestoneWorld.getAsString().equals(that.lodestoneWorld.getAsString()) + return (this.hasLodestone() ? that.hasLodestone() && this.lodestoneWorld.equals(that.lodestoneWorld) && this.lodestoneX == that.lodestoneX && this.lodestoneY == that.lodestoneY && this.lodestoneZ == that.lodestoneZ : !that.hasLodestone()) && this.tracked == that.tracked; @@ -207,14 +200,12 @@ public class CraftMetaCompass extends CraftMetaItem implements CompassMeta { super.serialize(builder); if (hasLodestone()) { - builder.put(LODESTONE_POS_WORLD.BUKKIT, lodestoneWorld.getAsString()); + builder.put(LODESTONE_POS_WORLD.BUKKIT, lodestoneWorld.location().toString()); builder.put(LODESTONE_POS_X.BUKKIT, lodestoneX); builder.put(LODESTONE_POS_Y.BUKKIT, lodestoneY); builder.put(LODESTONE_POS_Z.BUKKIT, lodestoneZ); } - if (hasLodestoneTracked()) { - builder.put(LODESTONE_TRACKED.BUKKIT, tracked); - } + builder.put(LODESTONE_TRACKED.BUKKIT, tracked); return builder; } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCrossbow.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCrossbow.java index 4b9e62f652..b090eeee67 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCrossbow.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCrossbow.java @@ -6,22 +6,21 @@ import com.google.common.collect.ImmutableMap; import java.util.ArrayList; import java.util.List; import java.util.Map; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; import net.minecraft.world.item.ItemArrow; +import net.minecraft.world.item.component.ChargedProjectiles; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.CrossbowMeta; -@DelegateDeserialization(CraftMetaItem.SerializableMeta.class) +@DelegateDeserialization(SerializableMeta.class) public class CraftMetaCrossbow extends CraftMetaItem implements CrossbowMeta { - static final ItemMetaKey CHARGED = new ItemMetaKey("Charged", "charged"); - static final ItemMetaKey CHARGED_PROJECTILES = new ItemMetaKey("ChargedProjectiles", "charged-projectiles"); + static final ItemMetaKey CHARGED = new ItemMetaKey("charged"); + static final ItemMetaKeyType CHARGED_PROJECTILES = new ItemMetaKeyType<>(DataComponents.CHARGED_PROJECTILES, "charged-projectiles"); // - private boolean charged; private List chargedProjectiles; CraftMetaCrossbow(CraftMetaItem meta) { @@ -32,41 +31,32 @@ public class CraftMetaCrossbow extends CraftMetaItem implements CrossbowMeta { } CraftMetaCrossbow crossbow = (CraftMetaCrossbow) meta; - this.charged = crossbow.charged; - if (crossbow.hasChargedProjectiles()) { this.chargedProjectiles = new ArrayList<>(crossbow.chargedProjectiles); } } - CraftMetaCrossbow(NBTTagCompound tag) { + CraftMetaCrossbow(DataComponentPatch tag) { super(tag); - charged = tag.getBoolean(CHARGED.NBT); - - if (tag.contains(CHARGED_PROJECTILES.NBT, CraftMagicNumbers.NBT.TAG_LIST)) { - NBTTagList list = tag.getList(CHARGED_PROJECTILES.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND); + getOrEmpty(tag, CHARGED_PROJECTILES).ifPresent((p) -> { + List list = p.getItems(); if (list != null && !list.isEmpty()) { chargedProjectiles = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { - NBTTagCompound nbttagcompound1 = list.getCompound(i); + net.minecraft.world.item.ItemStack nbttagcompound1 = list.get(i); - chargedProjectiles.add(CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.of(nbttagcompound1))); + chargedProjectiles.add(CraftItemStack.asCraftMirror(nbttagcompound1)); } } - } + }); } CraftMetaCrossbow(Map map) { super(map); - Boolean charged = SerializableMeta.getObject(Boolean.class, map, CHARGED.BUKKIT, true); - if (charged != null) { - this.charged = charged; - } - Iterable projectiles = SerializableMeta.getObject(Iterable.class, map, CHARGED_PROJECTILES.BUKKIT, true); if (projectiles != null) { for (Object stack : projectiles) { @@ -78,20 +68,17 @@ public class CraftMetaCrossbow extends CraftMetaItem implements CrossbowMeta { } @Override - void applyToItem(NBTTagCompound tag) { + void applyToItem(CraftMetaItem.Applicator tag) { super.applyToItem(tag); - tag.putBoolean(CHARGED.NBT, charged); if (hasChargedProjectiles()) { - NBTTagList list = new NBTTagList(); + List list = new ArrayList<>(); for (ItemStack item : chargedProjectiles) { - NBTTagCompound saved = new NBTTagCompound(); - CraftItemStack.asNMSCopy(item).save(saved); - list.add(saved); + list.add(CraftItemStack.asNMSCopy(item)); } - tag.put(CHARGED_PROJECTILES.NBT, list); + tag.put(CHARGED_PROJECTILES, ChargedProjectiles.of(list)); } } @@ -122,7 +109,6 @@ public class CraftMetaCrossbow extends CraftMetaItem implements CrossbowMeta { @Override public void setChargedProjectiles(List projectiles) { chargedProjectiles = null; - charged = false; if (projectiles == null) { return; @@ -142,7 +128,6 @@ public class CraftMetaCrossbow extends CraftMetaItem implements CrossbowMeta { chargedProjectiles = new ArrayList<>(); } - charged = true; chargedProjectiles.add(item); } @@ -154,8 +139,7 @@ public class CraftMetaCrossbow extends CraftMetaItem implements CrossbowMeta { if (meta instanceof CraftMetaCrossbow) { CraftMetaCrossbow that = (CraftMetaCrossbow) meta; - return this.charged == that.charged - && (hasChargedProjectiles() ? that.hasChargedProjectiles() && this.chargedProjectiles.equals(that.chargedProjectiles) : !that.hasChargedProjectiles()); + return (hasChargedProjectiles() ? that.hasChargedProjectiles() && this.chargedProjectiles.equals(that.chargedProjectiles) : !that.hasChargedProjectiles()); } return true; } @@ -171,7 +155,6 @@ public class CraftMetaCrossbow extends CraftMetaItem implements CrossbowMeta { int hash = original = super.applyHash(); if (hasChargedProjectiles()) { - hash = 61 * hash + (this.charged ? 1 : 0); hash = 61 * hash + chargedProjectiles.hashCode(); } @@ -187,7 +170,6 @@ public class CraftMetaCrossbow extends CraftMetaItem implements CrossbowMeta { ImmutableMap.Builder serialize(ImmutableMap.Builder builder) { super.serialize(builder); - builder.put(CHARGED.BUKKIT, charged); if (hasChargedProjectiles()) { builder.put(CHARGED_PROJECTILES.BUKKIT, chargedProjectiles); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEnchantedBook.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEnchantedBook.java index 940c2d7dce..3d3b9689b1 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEnchantedBook.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEnchantedBook.java @@ -4,16 +4,18 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import java.util.LinkedHashMap; import java.util.Map; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.enchantment.ItemEnchantments; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; -import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta; import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.meta.EnchantmentStorageMeta; @DelegateDeserialization(SerializableMeta.class) class CraftMetaEnchantedBook extends CraftMetaItem implements EnchantmentStorageMeta { - static final ItemMetaKey STORED_ENCHANTMENTS = new ItemMetaKey("StoredEnchantments", "stored-enchants"); + static final ItemMetaKeyType STORED_ENCHANTMENTS = new ItemMetaKeyType<>(DataComponents.STORED_ENCHANTMENTS, "stored-enchants"); private Map enchantments; @@ -31,14 +33,15 @@ class CraftMetaEnchantedBook extends CraftMetaItem implements EnchantmentStorage } } - CraftMetaEnchantedBook(NBTTagCompound tag) { + CraftMetaEnchantedBook(DataComponentPatch tag) { super(tag); - if (!tag.contains(STORED_ENCHANTMENTS.NBT)) { - return; - } - - enchantments = buildEnchantments(tag, STORED_ENCHANTMENTS); + getOrEmpty(tag, STORED_ENCHANTMENTS).ifPresent((itemEnchantments) -> { + enchantments = buildEnchantments(itemEnchantments); + if (!itemEnchantments.showInTooltip) { + addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); + } + }); } CraftMetaEnchantedBook(Map map) { @@ -48,10 +51,10 @@ class CraftMetaEnchantedBook extends CraftMetaItem implements EnchantmentStorage } @Override - void applyToItem(NBTTagCompound itemTag) { + void applyToItem(CraftMetaItem.Applicator itemTag) { super.applyToItem(itemTag); - applyEnchantments(enchantments, itemTag, STORED_ENCHANTMENTS); + applyEnchantments(enchantments, itemTag, STORED_ENCHANTMENTS, ItemFlag.HIDE_POTION_EFFECTS); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEntityTag.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEntityTag.java index 050f995a4f..6721b8453d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEntityTag.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEntityTag.java @@ -4,12 +4,15 @@ import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Sets; import java.util.Map; import java.util.Set; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.item.component.CustomData; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; -@DelegateDeserialization(CraftMetaItem.SerializableMeta.class) +@DelegateDeserialization(SerializableMeta.class) public class CraftMetaEntityTag extends CraftMetaItem { private static final Set ENTITY_TAGGABLE_MATERIALS = Sets.newHashSet( @@ -21,7 +24,7 @@ public class CraftMetaEntityTag extends CraftMetaItem { Material.PAINTING ); - static final ItemMetaKey ENTITY_TAG = new ItemMetaKey("EntityTag", "entity-tag"); + static final ItemMetaKeyType ENTITY_TAG = new ItemMetaKeyType<>(DataComponents.ENTITY_DATA, "EntityTag", "entity-tag"); NBTTagCompound entityTag; CraftMetaEntityTag(CraftMetaItem meta) { @@ -35,12 +38,12 @@ public class CraftMetaEntityTag extends CraftMetaItem { this.entityTag = entity.entityTag; } - CraftMetaEntityTag(NBTTagCompound tag) { + CraftMetaEntityTag(DataComponentPatch tag) { super(tag); - if (tag.contains(ENTITY_TAG.NBT)) { - entityTag = tag.getCompound(ENTITY_TAG.NBT).copy(); - } + getOrEmpty(tag, ENTITY_TAG).ifPresent((nbt) -> { + entityTag = nbt.copyTag(); + }); } CraftMetaEntityTag(Map map) { @@ -64,11 +67,11 @@ public class CraftMetaEntityTag extends CraftMetaItem { } @Override - void applyToItem(NBTTagCompound tag) { + void applyToItem(CraftMetaItem.Applicator tag) { super.applyToItem(tag); if (entityTag != null) { - tag.put(ENTITY_TAG.NBT, entityTag); + tag.put(ENTITY_TAG, CustomData.of(entityTag)); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java index 0b9fdd563f..46ae22a4d7 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java @@ -3,12 +3,15 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap.Builder; +import it.unimi.dsi.fastutil.ints.IntList; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.component.FireworkExplosion; +import net.minecraft.world.item.component.Fireworks; import org.bukkit.Color; import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect.Type; @@ -16,8 +19,6 @@ import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.craftbukkit.inventory.CraftMetaItem.ItemMetaKey.Specific; import org.bukkit.craftbukkit.inventory.CraftMetaItem.ItemMetaKey.Specific.To; -import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.inventory.meta.FireworkMeta; @DelegateDeserialization(SerializableMeta.class) @@ -38,22 +39,12 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta { */ @Specific(To.NBT) - static final ItemMetaKey FIREWORKS = new ItemMetaKey("Fireworks"); - static final ItemMetaKey FLIGHT = new ItemMetaKey("Flight", "power"); - static final ItemMetaKey EXPLOSIONS = new ItemMetaKey("Explosions", "firework-effects"); - @Specific(To.NBT) - static final ItemMetaKey EXPLOSION_COLORS = new ItemMetaKey("Colors"); - @Specific(To.NBT) - static final ItemMetaKey EXPLOSION_TYPE = new ItemMetaKey("Type"); - @Specific(To.NBT) - static final ItemMetaKey EXPLOSION_TRAIL = new ItemMetaKey("Trail"); - @Specific(To.NBT) - static final ItemMetaKey EXPLOSION_FLICKER = new ItemMetaKey("Flicker"); - @Specific(To.NBT) - static final ItemMetaKey EXPLOSION_FADE = new ItemMetaKey("FadeColors"); + static final ItemMetaKeyType FIREWORKS = new ItemMetaKeyType<>(DataComponents.FIREWORKS, "Fireworks"); + static final ItemMetaKey FLIGHT = new ItemMetaKey("power"); + static final ItemMetaKey EXPLOSIONS = new ItemMetaKey("firework-effects"); private List effects; - private Integer power; + private int power; CraftMetaFirework(CraftMetaItem meta) { super(meta); @@ -69,44 +60,36 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta { } } - CraftMetaFirework(NBTTagCompound tag) { + CraftMetaFirework(DataComponentPatch tag) { super(tag); - if (!tag.contains(FIREWORKS.NBT)) { - return; - } + getOrEmpty(tag, FIREWORKS).ifPresent((fireworks) -> { + power = fireworks.flightDuration(); - NBTTagCompound fireworks = tag.getCompound(FIREWORKS.NBT); + List fireworkEffects = fireworks.explosions(); + List effects = this.effects = new ArrayList(fireworkEffects.size()); - power = (int) fireworks.getByte(FLIGHT.NBT); - - if (!fireworks.contains(EXPLOSIONS.NBT)) { - return; - } - - NBTTagList fireworkEffects = fireworks.getList(EXPLOSIONS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND); - List effects = this.effects = new ArrayList(fireworkEffects.size()); - - for (int i = 0; i < fireworkEffects.size(); i++) { - try { - effects.add(getEffect((NBTTagCompound) fireworkEffects.get(i))); - } catch (IllegalArgumentException ex) { - // Ignore invalid effects + for (int i = 0; i < fireworkEffects.size(); i++) { + try { + effects.add(getEffect(fireworkEffects.get(i))); + } catch (IllegalArgumentException ex) { + // Ignore invalid effects + } } - } + }); } - static FireworkEffect getEffect(NBTTagCompound explosion) { + static FireworkEffect getEffect(FireworkExplosion explosion) { FireworkEffect.Builder effect = FireworkEffect.builder() - .flicker(explosion.getBoolean(EXPLOSION_FLICKER.NBT)) - .trail(explosion.getBoolean(EXPLOSION_TRAIL.NBT)) - .with(getEffectType(0xff & explosion.getByte(EXPLOSION_TYPE.NBT))); + .flicker(explosion.hasTwinkle()) + .trail(explosion.hasTrail()) + .with(getEffectType(explosion.shape())); - int[] colors = explosion.getIntArray(EXPLOSION_COLORS.NBT); + IntList colors = explosion.colors(); // People using buggy command generators specify a list rather than an int here, so recover with dummy data. // Wrong: Colors: [1234] // Right: Colors: [I;1234] - if (colors.length == 0) { + if (colors.isEmpty()) { effect.withColor(Color.WHITE); } @@ -114,60 +97,48 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta { effect.withColor(Color.fromRGB(color)); } - for (int color : explosion.getIntArray(EXPLOSION_FADE.NBT)) { + for (int color : explosion.fadeColors()) { effect.withFade(Color.fromRGB(color)); } return effect.build(); } - static NBTTagCompound getExplosion(FireworkEffect effect) { - NBTTagCompound explosion = new NBTTagCompound(); + static FireworkExplosion getExplosion(FireworkEffect effect) { + IntList colors = addColors(effect.getColors()); + IntList fadeColors = addColors(effect.getFadeColors()); - if (effect.hasFlicker()) { - explosion.putBoolean(EXPLOSION_FLICKER.NBT, true); - } - - if (effect.hasTrail()) { - explosion.putBoolean(EXPLOSION_TRAIL.NBT, true); - } - - addColors(explosion, EXPLOSION_COLORS, effect.getColors()); - addColors(explosion, EXPLOSION_FADE, effect.getFadeColors()); - - explosion.putByte(EXPLOSION_TYPE.NBT, (byte) getNBT(effect.getType())); - - return explosion; + return new FireworkExplosion(getNBT(effect.getType()), colors, fadeColors, effect.hasTrail(), effect.hasFlicker()); } - static int getNBT(Type type) { + static FireworkExplosion.a getNBT(Type type) { switch (type) { case BALL: - return 0; + return FireworkExplosion.a.SMALL_BALL; case BALL_LARGE: - return 1; + return FireworkExplosion.a.LARGE_BALL; case STAR: - return 2; + return FireworkExplosion.a.STAR; case CREEPER: - return 3; + return FireworkExplosion.a.CREEPER; case BURST: - return 4; + return FireworkExplosion.a.BURST; default: throw new IllegalArgumentException("Unknown effect type " + type); } } - static Type getEffectType(int nbt) { + static Type getEffectType(FireworkExplosion.a nbt) { switch (nbt) { - case 0: + case SMALL_BALL: return Type.BALL; - case 1: + case LARGE_BALL: return Type.BALL_LARGE; - case 2: + case STAR: return Type.STAR; - case 3: + case CREEPER: return Type.CREEPER; - case 4: + case BURST: return Type.BURST; default: throw new IllegalArgumentException("Unknown effect type " + nbt); @@ -208,34 +179,23 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta { } @Override - void applyToItem(NBTTagCompound itemTag) { + void applyToItem(CraftMetaItem.Applicator itemTag) { super.applyToItem(itemTag); if (isFireworkEmpty()) { return; } - NBTTagCompound fireworks = itemTag.getCompound(FIREWORKS.NBT); - itemTag.put(FIREWORKS.NBT, fireworks); - - if (hasEffects()) { - NBTTagList effects = new NBTTagList(); - for (FireworkEffect effect : this.effects) { - effects.add(getExplosion(effect)); - } - - if (effects.size() > 0) { - fireworks.put(EXPLOSIONS.NBT, effects); - } + List effects = new ArrayList<>(); + for (FireworkEffect effect : this.effects) { + effects.add(getExplosion(effect)); } - if (hasPower()) { - fireworks.putByte(FLIGHT.NBT, power.byteValue()); - } + itemTag.put(FIREWORKS, new Fireworks(power, effects)); } - static void addColors(NBTTagCompound compound, ItemMetaKey key, List colors) { + static IntList addColors(List colors) { if (colors.isEmpty()) { - return; + return IntList.of(); } final int[] colorArray = new int[colors.size()]; @@ -244,7 +204,7 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta { colorArray[i++] = color.asRGB(); } - compound.putIntArray(key.NBT, colorArray); + return IntList.of(colorArray); } @Override @@ -262,7 +222,7 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta { } boolean hasPower() { - return power != null && power != 0; + return power != 0; } @Override 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 024631bdae..b0010737e9 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 @@ -17,12 +17,11 @@ import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; import java.util.Collection; +import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; import java.util.Iterator; @@ -30,52 +29,69 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.NoSuchElementException; import java.util.Objects; +import java.util.Optional; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import net.minecraft.core.Holder; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.component.DataComponents; +import net.minecraft.nbt.DynamicOpsNBT; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTCompressedStreamTools; import net.minecraft.nbt.NBTReadLimiter; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; import net.minecraft.network.chat.IChatBaseComponent; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.Unit; import net.minecraft.world.entity.EnumItemSlot; -import net.minecraft.world.item.ItemBlock; +import net.minecraft.world.entity.EquipmentSlotGroup; +import net.minecraft.world.entity.ai.attributes.AttributeBase; +import net.minecraft.world.food.FoodInfo; +import net.minecraft.world.item.EnumItemRarity; +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.ItemAttributeModifiers; +import net.minecraft.world.item.component.ItemLore; +import net.minecraft.world.item.component.Unbreakable; +import net.minecraft.world.item.enchantment.ItemEnchantments; import net.minecraft.world.level.block.state.IBlockData; import org.apache.commons.lang3.EnumUtils; import org.bukkit.Material; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; import org.bukkit.block.data.BlockData; -import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.DelegateDeserialization; -import org.bukkit.configuration.serialization.SerializableAs; import org.bukkit.craftbukkit.CraftEquipmentSlot; import org.bukkit.craftbukkit.Overridden; import org.bukkit.craftbukkit.attribute.CraftAttribute; import org.bukkit.craftbukkit.attribute.CraftAttributeInstance; 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.CraftFoodComponent; import org.bukkit.craftbukkit.inventory.tags.DeprecatedCustomTagContainer; import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer; import org.bukkit.craftbukkit.persistence.CraftPersistentDataTypeRegistry; 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.enchantments.Enchantment; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemRarity; 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.FoodComponent; import org.bukkit.inventory.meta.tags.CustomItemTagContainer; import org.bukkit.persistence.PersistentDataContainer; @@ -86,7 +102,7 @@ import org.bukkit.persistence.PersistentDataContainer; *
  • Constructor(NBTTagCompound tag) *
  • Constructor(Map<String, Object> map) *

    - *
  • void applyToItem(NBTTagCompound tag) + *
  • void applyToItem(CraftMetaItem.Applicator tag) *
  • boolean applicableTo(Material type) *

    *
  • boolean equalsCommon(CraftMetaItem meta) @@ -101,7 +117,7 @@ import org.bukkit.persistence.PersistentDataContainer; *
  • Builder<String, Object> serialize(Builder<String, Object> builder) *
  • SerializableMeta.Deserializers deserializer() */ -@DelegateDeserialization(CraftMetaItem.SerializableMeta.class) +@DelegateDeserialization(SerializableMeta.class) class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { static class ItemMetaKey { @@ -130,162 +146,102 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { } } - @SerializableAs("ItemMeta") - public static final class SerializableMeta implements ConfigurationSerializable { - static final String TYPE_FIELD = "meta-type"; + static final class ItemMetaKeyType extends ItemMetaKey { - static final ImmutableMap, String> classMap; - static final ImmutableMap> constructorMap; + final DataComponentType TYPE; - static { - classMap = ImmutableMap., String>builder() - .put(CraftMetaArmor.class, "ARMOR") - .put(CraftMetaArmorStand.class, "ARMOR_STAND") - .put(CraftMetaBanner.class, "BANNER") - .put(CraftMetaBlockState.class, "TILE_ENTITY") - .put(CraftMetaBook.class, "BOOK") - .put(CraftMetaBookSigned.class, "BOOK_SIGNED") - .put(CraftMetaSkull.class, "SKULL") - .put(CraftMetaLeatherArmor.class, "LEATHER_ARMOR") - .put(CraftMetaColorableArmor.class, "COLORABLE_ARMOR") - .put(CraftMetaMap.class, "MAP") - .put(CraftMetaPotion.class, "POTION") - .put(CraftMetaSpawnEgg.class, "SPAWN_EGG") - .put(CraftMetaEnchantedBook.class, "ENCHANTED") - .put(CraftMetaFirework.class, "FIREWORK") - .put(CraftMetaCharge.class, "FIREWORK_EFFECT") - .put(CraftMetaKnowledgeBook.class, "KNOWLEDGE_BOOK") - .put(CraftMetaTropicalFishBucket.class, "TROPICAL_FISH_BUCKET") - .put(CraftMetaAxolotlBucket.class, "AXOLOTL_BUCKET") - .put(CraftMetaCrossbow.class, "CROSSBOW") - .put(CraftMetaSuspiciousStew.class, "SUSPICIOUS_STEW") - .put(CraftMetaEntityTag.class, "ENTITY_TAG") - .put(CraftMetaCompass.class, "COMPASS") - .put(CraftMetaBundle.class, "BUNDLE") - .put(CraftMetaMusicInstrument.class, "MUSIC_INSTRUMENT") - .put(CraftMetaItem.class, "UNSPECIFIC") - .build(); - - final ImmutableMap.Builder> classConstructorBuilder = ImmutableMap.builder(); - for (Map.Entry, String> mapping : classMap.entrySet()) { - try { - classConstructorBuilder.put(mapping.getValue(), mapping.getKey().getDeclaredConstructor(Map.class)); - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } - } - constructorMap = classConstructorBuilder.build(); + ItemMetaKeyType(final DataComponentType type) { + this(type, null, null); } - private SerializableMeta() { + ItemMetaKeyType(final DataComponentType type, final String both) { + this(type, both, both); } - public static ItemMeta deserialize(Map map) throws Throwable { - Preconditions.checkArgument(map != null, "Cannot deserialize null map"); - - String type = getString(map, TYPE_FIELD, false); - Constructor constructor = constructorMap.get(type); - - if (constructor == null) { - throw new IllegalArgumentException(type + " is not a valid " + TYPE_FIELD); - } - - try { - return constructor.newInstance(map); - } catch (final InstantiationException e) { - throw new AssertionError(e); - } catch (final IllegalAccessException e) { - throw new AssertionError(e); - } catch (final InvocationTargetException e) { - throw e.getCause(); - } - } - - @Override - public Map serialize() { - throw new AssertionError(); - } - - static String getString(Map map, Object field, boolean nullable) { - return getObject(String.class, map, field, nullable); - } - - static boolean getBoolean(Map map, Object field) { - Boolean value = getObject(Boolean.class, map, field, true); - return value != null && value; - } - - static T getObject(Class clazz, Map map, Object field, boolean nullable) { - final Object object = map.get(field); - - if (clazz.isInstance(object)) { - return clazz.cast(object); - } - if (object == null) { - if (!nullable) { - throw new NoSuchElementException(map + " does not contain " + field); - } - return null; - } - throw new IllegalArgumentException(field + "(" + object + ") is not a valid " + clazz); + ItemMetaKeyType(final DataComponentType type, final String nbt, final String bukkit) { + super(nbt, bukkit); + this.TYPE = type; } } - static final ItemMetaKey NAME = new ItemMetaKey("Name", "display-name"); - static final ItemMetaKey LOCNAME = new ItemMetaKey("LocName", "loc-name"); - @Specific(Specific.To.NBT) - static final ItemMetaKey DISPLAY = new ItemMetaKey("display"); - static final ItemMetaKey LORE = new ItemMetaKey("Lore", "lore"); - static final ItemMetaKey CUSTOM_MODEL_DATA = new ItemMetaKey("CustomModelData", "custom-model-data"); - static final ItemMetaKey ENCHANTMENTS = new ItemMetaKey("Enchantments", "enchants"); - @Specific(Specific.To.NBT) - static final ItemMetaKey ENCHANTMENTS_ID = new ItemMetaKey("id"); - @Specific(Specific.To.NBT) - static final ItemMetaKey ENCHANTMENTS_LVL = new ItemMetaKey("lvl"); - static final ItemMetaKey REPAIR = new ItemMetaKey("RepairCost", "repair-cost"); - static final ItemMetaKey ATTRIBUTES = new ItemMetaKey("AttributeModifiers", "attribute-modifiers"); + static final class Applicator { + + final DataComponentPatch.a builder = DataComponentPatch.builder(); + + Applicator put(ItemMetaKeyType key, T value) { + builder.set(key.TYPE, value); + return this; + } + + DataComponentPatch build() { + return builder.build(); + } + } + + static final ItemMetaKeyType NAME = new ItemMetaKeyType(DataComponents.CUSTOM_NAME, "display-name"); + 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 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"); @Specific(Specific.To.NBT) static final ItemMetaKey ATTRIBUTES_IDENTIFIER = new ItemMetaKey("AttributeName"); @Specific(Specific.To.NBT) - static final ItemMetaKey ATTRIBUTES_NAME = new ItemMetaKey("Name"); - @Specific(Specific.To.NBT) - static final ItemMetaKey ATTRIBUTES_VALUE = new ItemMetaKey("Amount"); - @Specific(Specific.To.NBT) - static final ItemMetaKey ATTRIBUTES_TYPE = new ItemMetaKey("Operation"); - @Specific(Specific.To.NBT) - static final ItemMetaKey ATTRIBUTES_UUID_HIGH = new ItemMetaKey("UUIDMost"); - @Specific(Specific.To.NBT) - static final ItemMetaKey ATTRIBUTES_UUID_LOW = new ItemMetaKey("UUIDLeast"); - @Specific(Specific.To.NBT) static final ItemMetaKey ATTRIBUTES_SLOT = new ItemMetaKey("Slot"); @Specific(Specific.To.NBT) - static final ItemMetaKey HIDEFLAGS = new ItemMetaKey("HideFlags", "ItemFlags"); + static final ItemMetaKey HIDEFLAGS = new ItemMetaKey("ItemFlags"); @Specific(Specific.To.NBT) - static final ItemMetaKey UNBREAKABLE = new ItemMetaKey("Unbreakable"); + static final ItemMetaKeyType HIDE_TOOLTIP = new ItemMetaKeyType<>(DataComponents.HIDE_TOOLTIP, "hide-tool-tip"); @Specific(Specific.To.NBT) - static final ItemMetaKey DAMAGE = new ItemMetaKey("Damage"); + static final ItemMetaKeyType UNBREAKABLE = new ItemMetaKeyType<>(DataComponents.UNBREAKABLE, "Unbreakable"); @Specific(Specific.To.NBT) - static final ItemMetaKey BLOCK_DATA = new ItemMetaKey("BlockStateTag"); + 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"); + @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 FOOD = new ItemMetaKeyType<>(DataComponents.FOOD, "food"); + @Specific(Specific.To.NBT) + static final ItemMetaKeyType DAMAGE = new ItemMetaKeyType<>(DataComponents.DAMAGE, "Damage"); + @Specific(Specific.To.NBT) + static final ItemMetaKeyType MAX_DAMAGE = new ItemMetaKeyType<>(DataComponents.MAX_DAMAGE, "max-damage"); + @Specific(Specific.To.NBT) + static final ItemMetaKeyType BLOCK_DATA = new ItemMetaKeyType<>(DataComponents.BLOCK_STATE, "BlockStateTag"); static final ItemMetaKey BUKKIT_CUSTOM_TAG = new ItemMetaKey("PublicBukkitValues"); + @Specific(Specific.To.NBT) + static final ItemMetaKeyType HIDE_ADDITIONAL_TOOLTIP = new ItemMetaKeyType(DataComponents.HIDE_ADDITIONAL_TOOLTIP); + @Specific(Specific.To.NBT) + static final ItemMetaKeyType CUSTOM_DATA = new ItemMetaKeyType<>(DataComponents.CUSTOM_DATA); // We store the raw original JSON representation of all text data. See SPIGOT-5063, SPIGOT-5656, SPIGOT-5304 - private String displayName; - private String locName; - private List lore; // null and empty are two different states internally + private IChatBaseComponent displayName; + private IChatBaseComponent itemName; + private List lore; // null and empty are two different states internally private Integer customModelData; - private NBTTagCompound blockData; + private Map blockData; private Map enchantments; private Multimap attributeModifiers; private int repairCost; private int hideFlag; + private boolean hideTooltip; private boolean unbreakable; + private Boolean enchantmentGlintOverride; + private boolean fireResistant; + private Integer maxStackSize; + private ItemRarity rarity; + private CraftFoodComponent food; private int damage; + private Integer maxDamage; - private static final Set HANDLED_TAGS = Sets.newHashSet(); + private static final Set HANDLED_TAGS = Sets.newHashSet(); private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry(); - private NBTTagCompound internalTag; - final Map unhandledTags = new HashMap(); // Visible for testing only + private NBTTagCompound customTag; + protected DataComponentPatch.a unhandledTags = DataComponentPatch.builder(); private CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY); private int version = CraftMagicNumbers.INSTANCE.getDataVersion(); // Internal use only @@ -296,10 +252,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { } this.displayName = meta.displayName; - this.locName = meta.locName; + this.itemName = meta.itemName; if (meta.lore != null) { - this.lore = new ArrayList(meta.lore); + this.lore = new ArrayList(meta.lore); } this.customModelData = meta.customModelData; @@ -315,102 +271,321 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { this.repairCost = meta.repairCost; this.hideFlag = meta.hideFlag; + this.hideTooltip = meta.hideTooltip; this.unbreakable = meta.unbreakable; + this.enchantmentGlintOverride = meta.enchantmentGlintOverride; + this.fireResistant = meta.fireResistant; + this.maxStackSize = meta.maxStackSize; + this.rarity = meta.rarity; + if (meta.hasFood()) { + this.food = new CraftFoodComponent(meta.food); + } this.damage = meta.damage; - this.unhandledTags.putAll(meta.unhandledTags); + this.maxDamage = meta.maxDamage; + this.unhandledTags = meta.unhandledTags; this.persistentDataContainer.putAll(meta.persistentDataContainer.getRaw()); - this.internalTag = meta.internalTag; - if (this.internalTag != null) { - deserializeInternal(internalTag, meta); - } + this.customTag = meta.customTag; this.version = meta.version; } - CraftMetaItem(NBTTagCompound tag) { - if (tag.contains(DISPLAY.NBT)) { - NBTTagCompound display = tag.getCompound(DISPLAY.NBT); + CraftMetaItem(DataComponentPatch tag) { + getOrEmpty(tag, NAME).ifPresent((component) -> { + displayName = component; + }); + getOrEmpty(tag, ITEM_NAME).ifPresent((component) -> { + itemName = component; + }); - if (display.contains(NAME.NBT)) { - displayName = display.getString(NAME.NBT); + getOrEmpty(tag, LORE).ifPresent((l) -> { + List list = l.lines(); + lore = new ArrayList(list.size()); + for (int index = 0; index < list.size(); index++) { + IChatBaseComponent line = list.get(index); + lore.add(line); } + }); - if (display.contains(LOCNAME.NBT)) { - locName = display.getString(LOCNAME.NBT); + getOrEmpty(tag, CUSTOM_MODEL_DATA).ifPresent((i) -> { + customModelData = i.value(); + }); + getOrEmpty(tag, BLOCK_DATA).ifPresent((t) -> { + blockData = t.properties(); + }); + + getOrEmpty(tag, ENCHANTMENTS).ifPresent((en) -> { + this.enchantments = buildEnchantments(en); + if (!en.showInTooltip) { + addItemFlags(ItemFlag.HIDE_ENCHANTS); } + }); + getOrEmpty(tag, ATTRIBUTES).ifPresent((en) -> { + this.attributeModifiers = buildModifiers(en); + if (!en.showInTooltip()) { + addItemFlags(ItemFlag.HIDE_ATTRIBUTES); + } + }); - if (display.contains(LORE.NBT)) { - NBTTagList list = display.getList(LORE.NBT, CraftMagicNumbers.NBT.TAG_STRING); - lore = new ArrayList(list.size()); - for (int index = 0; index < list.size(); index++) { - String line = list.getString(index); - lore.add(line); + getOrEmpty(tag, REPAIR).ifPresent((i) -> { + repairCost = i; + }); + + getOrEmpty(tag, HIDE_ADDITIONAL_TOOLTIP).ifPresent((h) -> { + addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); + }); + getOrEmpty(tag, HIDE_TOOLTIP).ifPresent((u) -> { + hideTooltip = true; + }); + getOrEmpty(tag, UNBREAKABLE).ifPresent((u) -> { + unbreakable = true; + if (!u.showInTooltip()) { + addItemFlags(ItemFlag.HIDE_UNBREAKABLE); + } + }); + getOrEmpty(tag, ENCHANTMENT_GLINT_OVERRIDE).ifPresent((override) -> { + enchantmentGlintOverride = override; + }); + getOrEmpty(tag, FIRE_RESISTANT).ifPresent((u) -> { + fireResistant = true; + }); + getOrEmpty(tag, MAX_STACK_SIZE).ifPresent((i) -> { + maxStackSize = i; + }); + getOrEmpty(tag, RARITY).ifPresent((enumItemRarity) -> { + rarity = ItemRarity.valueOf(enumItemRarity.name()); + }); + getOrEmpty(tag, FOOD).ifPresent((foodInfo) -> { + food = new CraftFoodComponent(foodInfo); + }); + getOrEmpty(tag, DAMAGE).ifPresent((i) -> { + damage = i; + }); + getOrEmpty(tag, MAX_DAMAGE).ifPresent((i) -> { + maxDamage = i; + }); + getOrEmpty(tag, CUSTOM_DATA).ifPresent((customData) -> { + customTag = customData.copyTag(); + if (customTag.contains(BUKKIT_CUSTOM_TAG.NBT)) { + NBTTagCompound compound = customTag.getCompound(BUKKIT_CUSTOM_TAG.NBT); + Set keys = compound.getAllKeys(); + for (String key : keys) { + persistentDataContainer.put(key, compound.get(key).copy()); } } - } + }); - if (tag.contains(CUSTOM_MODEL_DATA.NBT, CraftMagicNumbers.NBT.TAG_INT)) { - customModelData = tag.getInt(CUSTOM_MODEL_DATA.NBT); - } - if (tag.contains(BLOCK_DATA.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) { - blockData = tag.getCompound(BLOCK_DATA.NBT).copy(); - } - - this.enchantments = buildEnchantments(tag, ENCHANTMENTS); - this.attributeModifiers = buildModifiers(tag, ATTRIBUTES); - - if (tag.contains(REPAIR.NBT)) { - repairCost = tag.getInt(REPAIR.NBT); - } - - if (tag.contains(HIDEFLAGS.NBT)) { - hideFlag = tag.getInt(HIDEFLAGS.NBT); - } - if (tag.contains(UNBREAKABLE.NBT)) { - unbreakable = tag.getBoolean(UNBREAKABLE.NBT); - } - if (tag.contains(DAMAGE.NBT)) { - damage = tag.getInt(DAMAGE.NBT); - } - if (tag.contains(BUKKIT_CUSTOM_TAG.NBT)) { - NBTTagCompound compound = tag.getCompound(BUKKIT_CUSTOM_TAG.NBT); - Set keys = compound.getAllKeys(); - for (String key : keys) { - persistentDataContainer.put(key, compound.get(key).copy()); - } - } - - Set keys = tag.getAllKeys(); - for (String key : keys) { - if (!getHandledTags().contains(key)) { - unhandledTags.put(key, tag.get(key).copy()); + Set, Optional>> keys = tag.entrySet(); + for (Map.Entry, Optional> key : keys) { + if (!getHandledTags().contains(key.getKey())) { + key.getValue().ifPresentOrElse((value) -> { + unhandledTags.set((DataComponentType) key.getKey(), value); + }, () -> { + unhandledTags.remove(key.getKey()); + }); } } } - static Map buildEnchantments(NBTTagCompound tag, ItemMetaKey key) { - if (!tag.contains(key.NBT)) { - return null; - } + static Map buildEnchantments(ItemEnchantments tag) { + Map enchantments = new LinkedHashMap(tag.size()); - NBTTagList ench = tag.getList(key.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND); - Map enchantments = new LinkedHashMap(ench.size()); + tag.entrySet().forEach((entry) -> { + Holder id = entry.getKey(); + int level = entry.getIntValue(); - for (int i = 0; i < ench.size(); i++) { - String id = ((NBTTagCompound) ench.get(i)).getString(ENCHANTMENTS_ID.NBT); - int level = 0xffff & ((NBTTagCompound) ench.get(i)).getShort(ENCHANTMENTS_LVL.NBT); - - Enchantment enchant = Enchantment.getByKey(CraftNamespacedKey.fromStringOrNull(id)); + Enchantment enchant = CraftEnchantment.minecraftHolderToBukkit(id); if (enchant != null) { enchantments.put(enchant, level); } - } + }); return enchantments; } - static Multimap buildModifiers(NBTTagCompound tag, ItemMetaKey key) { + static Multimap buildModifiers(ItemAttributeModifiers tag) { + Multimap modifiers = LinkedHashMultimap.create(); + List mods = tag.modifiers(); + int size = mods.size(); + + for (int i = 0; i < size; i++) { + ItemAttributeModifiers.b entry = mods.get(i); + net.minecraft.world.entity.ai.attributes.AttributeModifier nmsModifier = entry.modifier(); + if (nmsModifier == null) { + continue; + } + + AttributeModifier attribMod = CraftAttributeInstance.convert(nmsModifier); + + Attribute attribute = CraftAttribute.minecraftHolderToBukkit(entry.attribute()); + if (attribute == null) { + continue; + } + + if (entry.slot() != null) { + EquipmentSlotGroup slotName = entry.slot(); + if (slotName == null) { + modifiers.put(attribute, attribMod); + continue; + } + + org.bukkit.inventory.EquipmentSlotGroup slot = null; + try { + slot = CraftEquipmentSlot.getSlot(slotName); + } catch (IllegalArgumentException ex) { + // SPIGOT-4551 - Slot is invalid, should really match nothing but this is undefined behaviour anyway + } + + if (slot == null) { + modifiers.put(attribute, attribMod); + continue; + } + + attribMod = new AttributeModifier(attribMod.getUniqueId(), attribMod.getName(), attribMod.getAmount(), attribMod.getOperation(), slot); + } + modifiers.put(attribute, attribMod); + } + return modifiers; + } + + CraftMetaItem(Map map) { + displayName = CraftChatMessage.fromJSONOrString(SerializableMeta.getString(map, NAME.BUKKIT, true)); + itemName = CraftChatMessage.fromJSONOrNull(SerializableMeta.getString(map, ITEM_NAME.BUKKIT, true)); + + Iterable lore = SerializableMeta.getObject(Iterable.class, map, LORE.BUKKIT, true); + if (lore != null) { + safelyAdd(lore, this.lore = new ArrayList(), true); + } + + Integer customModelData = SerializableMeta.getObject(Integer.class, map, CUSTOM_MODEL_DATA.BUKKIT, true); + if (customModelData != null) { + setCustomModelData(customModelData); + } + + Object blockData = SerializableMeta.getObject(Object.class, map, BLOCK_DATA.BUKKIT, true); + if (blockData != null) { + Map mapBlockData = new HashMap<>(); + + NBTTagCompound nbtBlockData = (NBTTagCompound) CraftNBTTagConfigSerializer.deserialize(blockData); + for (String key : nbtBlockData.getAllKeys()) { + mapBlockData.put(key, nbtBlockData.getString(key)); + } + + this.blockData = mapBlockData; + } + + enchantments = buildEnchantments(map, ENCHANTMENTS); + attributeModifiers = buildModifiers(map, ATTRIBUTES); + + Integer repairCost = SerializableMeta.getObject(Integer.class, map, REPAIR.BUKKIT, true); + if (repairCost != null) { + setRepairCost(repairCost); + } + + Iterable hideFlags = SerializableMeta.getObject(Iterable.class, map, HIDEFLAGS.BUKKIT, true); + if (hideFlags != null) { + for (Object hideFlagObject : hideFlags) { + String hideFlagString = (String) hideFlagObject; + try { + ItemFlag hideFlatEnum = ItemFlag.valueOf(hideFlagString); + addItemFlags(hideFlatEnum); + } catch (IllegalArgumentException ex) { + // Ignore when we got a old String which does not map to a Enum value anymore + } + } + } + + Boolean hideTooltip = SerializableMeta.getObject(Boolean.class, map, HIDE_TOOLTIP.BUKKIT, true); + if (hideTooltip != null) { + setHideTooltip(hideTooltip); + } + + Boolean unbreakable = SerializableMeta.getObject(Boolean.class, map, UNBREAKABLE.BUKKIT, true); + if (unbreakable != null) { + setUnbreakable(unbreakable); + } + + Boolean enchantmentGlintOverride = SerializableMeta.getObject(Boolean.class, map, ENCHANTMENT_GLINT_OVERRIDE.BUKKIT, true); + if (enchantmentGlintOverride != null) { + setEnchantmentGlintOverride(enchantmentGlintOverride); + } + + Boolean fireResistant = SerializableMeta.getObject(Boolean.class, map, FIRE_RESISTANT.BUKKIT, true); + if (fireResistant != null) { + setFireResistant(fireResistant); + } + + Integer maxStackSize = SerializableMeta.getObject(Integer.class, map, MAX_STACK_SIZE.BUKKIT, true); + if (maxStackSize != null) { + setMaxStackSize(maxStackSize); + } + + String rarity = SerializableMeta.getString(map, RARITY.BUKKIT, true); + if (rarity != null) { + setRarity(ItemRarity.valueOf(rarity)); + } + + CraftFoodComponent food = SerializableMeta.getObject(CraftFoodComponent.class, map, FOOD.BUKKIT, true); + if (food != null) { + setFood(food); + } + + Integer damage = SerializableMeta.getObject(Integer.class, map, DAMAGE.BUKKIT, true); + if (damage != null) { + setDamage(damage); + } + + Integer maxDamage = SerializableMeta.getObject(Integer.class, map, MAX_DAMAGE.BUKKIT, true); + if (maxDamage != null) { + setMaxDamage(maxDamage); + } + + String internal = SerializableMeta.getString(map, "internal", true); + if (internal != null) { + ByteArrayInputStream buf = new ByteArrayInputStream(Base64.getDecoder().decode(internal)); + try { + NBTTagCompound internalTag = NBTCompressedStreamTools.readCompressed(buf, NBTReadLimiter.unlimitedHeap()); + deserializeInternal(internalTag, map); + } catch (IOException ex) { + Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex); + } + } + + String unhandled = SerializableMeta.getString(map, "unhandled", true); + if (unhandled != null) { + ByteArrayInputStream buf = new ByteArrayInputStream(Base64.getDecoder().decode(internal)); + try { + NBTTagCompound unhandledTag = NBTCompressedStreamTools.readCompressed(buf, NBTReadLimiter.unlimitedHeap()); + unhandledTags.copy(DataComponentPatch.CODEC.parse(MinecraftServer.getDefaultRegistryAccess().createSerializationContext(DynamicOpsNBT.INSTANCE), unhandledTag).result().get()); + } catch (IOException ex) { + Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex); + } + } + + Object nbtMap = SerializableMeta.getObject(Object.class, map, BUKKIT_CUSTOM_TAG.BUKKIT, true); // We read both legacy maps and potential modern snbt strings here + if (nbtMap != null) { + this.persistentDataContainer.putAll((NBTTagCompound) CraftNBTTagConfigSerializer.deserialize(nbtMap)); + } + + String custom = SerializableMeta.getString(map, "custom", true); + if (custom != null) { + ByteArrayInputStream buf = new ByteArrayInputStream(Base64.getDecoder().decode(custom)); + try { + customTag = NBTCompressedStreamTools.readCompressed(buf, NBTReadLimiter.unlimitedHeap()); + } catch (IOException ex) { + Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex); + } + } + } + + void deserializeInternal(NBTTagCompound tag, Object context) { + // SPIGOT-4576: Need to migrate from internal to proper data + if (tag.contains(ATTRIBUTES.NBT, CraftMagicNumbers.NBT.TAG_LIST)) { + this.attributeModifiers = buildModifiersLegacy(tag, ATTRIBUTES); + } + } + + private static Multimap buildModifiersLegacy(NBTTagCompound tag, ItemMetaKey key) { Multimap modifiers = LinkedHashMultimap.create(); if (!tag.contains(key.NBT, CraftMagicNumbers.NBT.TAG_LIST)) { return modifiers; @@ -467,87 +642,6 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { return modifiers; } - CraftMetaItem(Map map) { - displayName = CraftChatMessage.fromJSONOrStringOrNullToJSON(SerializableMeta.getString(map, NAME.BUKKIT, true)); - - locName = CraftChatMessage.fromJSONOrStringOrNullToJSON(SerializableMeta.getString(map, LOCNAME.BUKKIT, true)); - - Iterable lore = SerializableMeta.getObject(Iterable.class, map, LORE.BUKKIT, true); - if (lore != null) { - safelyAdd(lore, this.lore = new ArrayList(), true); - } - - Integer customModelData = SerializableMeta.getObject(Integer.class, map, CUSTOM_MODEL_DATA.BUKKIT, true); - if (customModelData != null) { - setCustomModelData(customModelData); - } - - Object blockData = SerializableMeta.getObject(Object.class, map, BLOCK_DATA.BUKKIT, true); - if (blockData != null) { - this.blockData = (NBTTagCompound) CraftNBTTagConfigSerializer.deserialize(blockData); - } - - enchantments = buildEnchantments(map, ENCHANTMENTS); - attributeModifiers = buildModifiers(map, ATTRIBUTES); - - Integer repairCost = SerializableMeta.getObject(Integer.class, map, REPAIR.BUKKIT, true); - if (repairCost != null) { - setRepairCost(repairCost); - } - - Iterable hideFlags = SerializableMeta.getObject(Iterable.class, map, HIDEFLAGS.BUKKIT, true); - if (hideFlags != null) { - for (Object hideFlagObject : hideFlags) { - String hideFlagString = (String) hideFlagObject; - try { - ItemFlag hideFlatEnum = ItemFlag.valueOf(hideFlagString); - addItemFlags(hideFlatEnum); - } catch (IllegalArgumentException ex) { - // Ignore when we got a old String which does not map to a Enum value anymore - } - } - } - - Boolean unbreakable = SerializableMeta.getObject(Boolean.class, map, UNBREAKABLE.BUKKIT, true); - if (unbreakable != null) { - setUnbreakable(unbreakable); - } - - Integer damage = SerializableMeta.getObject(Integer.class, map, DAMAGE.BUKKIT, true); - if (damage != null) { - setDamage(damage); - } - - String internal = SerializableMeta.getString(map, "internal", true); - if (internal != null) { - ByteArrayInputStream buf = new ByteArrayInputStream(Base64.getDecoder().decode(internal)); - try { - internalTag = NBTCompressedStreamTools.readCompressed(buf, NBTReadLimiter.unlimitedHeap()); - deserializeInternal(internalTag, map); - Set keys = internalTag.getAllKeys(); - for (String key : keys) { - if (!getHandledTags().contains(key)) { - unhandledTags.put(key, internalTag.get(key)); - } - } - } catch (IOException ex) { - Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex); - } - } - - Object nbtMap = SerializableMeta.getObject(Object.class, map, BUKKIT_CUSTOM_TAG.BUKKIT, true); // We read both legacy maps and potential modern snbt strings here - if (nbtMap != null) { - this.persistentDataContainer.putAll((NBTTagCompound) CraftNBTTagConfigSerializer.deserialize(nbtMap)); - } - } - - void deserializeInternal(NBTTagCompound tag, Object context) { - // SPIGOT-4576: Need to migrate from internal to proper data - if (tag.contains(ATTRIBUTES.NBT, CraftMagicNumbers.NBT.TAG_LIST)) { - this.attributeModifiers = buildModifiers(tag, ATTRIBUTES); - } - } - static Map buildEnchantments(Map map, ItemMetaKey key) { Map ench = SerializableMeta.getObject(Map.class, map, key.BUKKIT, true); if (ench == null) { @@ -608,47 +702,80 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { } @Overridden - void applyToItem(NBTTagCompound itemTag) { + void applyToItem(CraftMetaItem.Applicator itemTag) { if (hasDisplayName()) { - setDisplayTag(itemTag, NAME.NBT, NBTTagString.valueOf(displayName)); + itemTag.put(NAME, displayName); } - if (hasLocalizedName()) { - setDisplayTag(itemTag, LOCNAME.NBT, NBTTagString.valueOf(locName)); + + if (hasItemName()) { + itemTag.put(ITEM_NAME, itemName); } if (lore != null) { - setDisplayTag(itemTag, LORE.NBT, createStringList(lore)); + itemTag.put(LORE, new ItemLore(lore)); } if (hasCustomModelData()) { - itemTag.putInt(CUSTOM_MODEL_DATA.NBT, customModelData); + itemTag.put(CUSTOM_MODEL_DATA, new CustomModelData(customModelData)); } if (hasBlockData()) { - itemTag.put(BLOCK_DATA.NBT, blockData); + itemTag.put(BLOCK_DATA, new BlockItemStateProperties(blockData)); } if (hideFlag != 0) { - itemTag.putInt(HIDEFLAGS.NBT, hideFlag); + if (hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) { + itemTag.put(HIDE_ADDITIONAL_TOOLTIP, Unit.INSTANCE); + } } - applyEnchantments(enchantments, itemTag, ENCHANTMENTS); - applyModifiers(attributeModifiers, itemTag, ATTRIBUTES); + applyEnchantments(enchantments, itemTag, ENCHANTMENTS, ItemFlag.HIDE_ENCHANTS); + applyModifiers(attributeModifiers, itemTag); if (hasRepairCost()) { - itemTag.putInt(REPAIR.NBT, repairCost); + itemTag.put(REPAIR, repairCost); + } + + if (isHideTooltip()) { + itemTag.put(HIDE_TOOLTIP, Unit.INSTANCE); } if (isUnbreakable()) { - itemTag.putBoolean(UNBREAKABLE.NBT, unbreakable); + itemTag.put(UNBREAKABLE, new Unbreakable(!hasItemFlag(ItemFlag.HIDE_UNBREAKABLE))); + } + + if (hasEnchantmentGlintOverride()) { + itemTag.put(ENCHANTMENT_GLINT_OVERRIDE, getEnchantmentGlintOverride()); + } + + if (isFireResistant()) { + itemTag.put(FIRE_RESISTANT, Unit.INSTANCE); + } + + if (hasMaxStackSize()) { + itemTag.put(MAX_STACK_SIZE, maxStackSize); + } + + if (hasRarity()) { + itemTag.put(RARITY, EnumItemRarity.valueOf(rarity.name())); + } + + if (hasFood()) { + itemTag.put(FOOD, food.getHandle()); } if (hasDamage()) { - itemTag.putInt(DAMAGE.NBT, damage); + itemTag.put(DAMAGE, damage); } - for (Map.Entry e : unhandledTags.entrySet()) { - itemTag.put(e.getKey(), e.getValue()); + if (hasMaxDamage()) { + itemTag.put(MAX_DAMAGE, maxDamage); + } + + for (Map.Entry, Optional> e : unhandledTags.build().entrySet()) { + e.getValue().ifPresent((value) -> { + itemTag.builder.set((DataComponentType) e.getKey(), value); + }); } if (!persistentDataContainer.isEmpty()) { @@ -658,84 +785,54 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { for (Map.Entry nbtBaseEntry : rawPublicMap.entrySet()) { bukkitCustomCompound.put(nbtBaseEntry.getKey(), nbtBaseEntry.getValue()); } - itemTag.put(BUKKIT_CUSTOM_TAG.NBT, bukkitCustomCompound); + + if (customTag == null) { + customTag = new NBTTagCompound(); + } + customTag.put(BUKKIT_CUSTOM_TAG.BUKKIT, bukkitCustomCompound); + } + + if (customTag != null) { + itemTag.put(CUSTOM_DATA, CustomData.of(customTag)); } } - NBTTagList createStringList(List list) { - if (list == null) { - return null; - } - - NBTTagList tagList = new NBTTagList(); - for (String value : list) { - // SPIGOT-5342 - horrible hack as 0 version does not go through the Mojang updater - tagList.add(NBTTagString.valueOf(version <= 0 || version >= 1803 ? value : CraftChatMessage.fromJSONComponent(value))); // SPIGOT-4935 - } - - return tagList; - } - - static void applyEnchantments(Map enchantments, NBTTagCompound tag, ItemMetaKey key) { + void applyEnchantments(Map enchantments, CraftMetaItem.Applicator tag, ItemMetaKeyType key, ItemFlag itemFlag) { if (enchantments == null) { return; } - NBTTagList list = new NBTTagList(); + ItemEnchantments.a list = new ItemEnchantments.a(ItemEnchantments.EMPTY); for (Map.Entry entry : enchantments.entrySet()) { - NBTTagCompound subtag = new NBTTagCompound(); - - subtag.putString(ENCHANTMENTS_ID.NBT, entry.getKey().getKey().toString()); - subtag.putShort(ENCHANTMENTS_LVL.NBT, entry.getValue().shortValue()); - - list.add(subtag); + list.set(CraftEnchantment.bukkitToMinecraft(entry.getKey()), entry.getValue()); } - tag.put(key.NBT, list); + list.showInTooltip = !hasItemFlag(itemFlag); + tag.put(key, list.toImmutable()); } - static void applyModifiers(Multimap modifiers, NBTTagCompound tag, ItemMetaKey key) { + void applyModifiers(Multimap modifiers, CraftMetaItem.Applicator tag) { if (modifiers == null || modifiers.isEmpty()) { return; } - NBTTagList list = new NBTTagList(); + ItemAttributeModifiers.a list = ItemAttributeModifiers.builder(); for (Map.Entry entry : modifiers.entries()) { if (entry.getKey() == null || entry.getValue() == null) { continue; } net.minecraft.world.entity.ai.attributes.AttributeModifier nmsModifier = CraftAttributeInstance.convert(entry.getValue()); - NBTTagCompound sub = nmsModifier.save(); - if (sub.isEmpty()) { + + Holder name = CraftAttribute.bukkitToMinecraftHolder(entry.getKey()); + if (name == null) { continue; } - String name = entry.getKey().getKey().toString(); - if (name == null || name.isEmpty()) { - continue; - } - - sub.putString(ATTRIBUTES_IDENTIFIER.NBT, name); // Attribute Name - if (entry.getValue().getSlot() != null) { - EnumItemSlot slot = CraftEquipmentSlot.getNMS(entry.getValue().getSlot()); - if (slot != null) { - sub.putString(ATTRIBUTES_SLOT.NBT, slot.getName()); - } - } - list.add(sub); + EquipmentSlotGroup group = CraftEquipmentSlot.getNMSGroup(entry.getValue().getSlotGroup()); + list.add(name, nmsModifier, group); } - tag.put(key.NBT, list); - } - - void setDisplayTag(NBTTagCompound tag, String key, NBTBase value) { - final NBTTagCompound display = tag.getCompound(DISPLAY.NBT); - - if (!tag.contains(DISPLAY.NBT)) { - tag.put(DISPLAY.NBT, display); - } - - display.put(key, value); + tag.put(ATTRIBUTES, list.build().withTooltip(!hasItemFlag(ItemFlag.HIDE_ATTRIBUTES))); } @Overridden @@ -745,17 +842,17 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { @Overridden boolean isEmpty() { - return !(hasDisplayName() || hasLocalizedName() || hasEnchants() || (lore != null) || hasCustomModelData() || hasBlockData() || hasRepairCost() || !unhandledTags.isEmpty() || !persistentDataContainer.isEmpty() || hideFlag != 0 || isUnbreakable() || hasDamage() || hasAttributeModifiers()); + return !(hasDisplayName() || hasItemName() || hasLocalizedName() || hasEnchants() || (lore != null) || hasCustomModelData() || hasBlockData() || hasRepairCost() || !unhandledTags.build().isEmpty() || !persistentDataContainer.isEmpty() || hideFlag != 0 || isHideTooltip() || isUnbreakable() || hasEnchantmentGlintOverride() || isFireResistant() || hasMaxStackSize() || hasRarity() || hasFood() || hasDamage() || hasMaxDamage() || hasAttributeModifiers() || customTag != null); } @Override public String getDisplayName() { - return CraftChatMessage.fromJSONComponent(displayName); + return CraftChatMessage.fromComponent(displayName); } @Override public final void setDisplayName(String name) { - this.displayName = CraftChatMessage.fromStringOrNullToJSON(name); + this.displayName = CraftChatMessage.fromStringOrNull(name); } @Override @@ -763,19 +860,33 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { return displayName != null; } + @Override + public String getItemName() { + return CraftChatMessage.fromComponent(itemName); + } + + @Override + public final void setItemName(String name) { + this.itemName = CraftChatMessage.fromStringOrNull(name); + } + + @Override + public boolean hasItemName() { + return itemName != null; + } + @Override public String getLocalizedName() { - return CraftChatMessage.fromJSONComponent(locName); + return getDisplayName(); } @Override public void setLocalizedName(String name) { - this.locName = CraftChatMessage.fromStringOrNullToJSON(name); } @Override public boolean hasLocalizedName() { - return locName != null; + return false; } @Override @@ -890,7 +1001,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { @Override public List getLore() { - return this.lore == null ? null : new ArrayList(Lists.transform(this.lore, CraftChatMessage::fromJSONComponent)); + return this.lore == null ? null : new ArrayList(Lists.transform(this.lore, CraftChatMessage::fromComponent)); } @Override @@ -899,7 +1010,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { this.lore = null; } else { if (this.lore == null) { - this.lore = new ArrayList(lore.size()); + this.lore = new ArrayList(lore.size()); } else { this.lore.clear(); } @@ -931,7 +1042,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { @Override public BlockData getBlockData(Material material) { IBlockData defaultData = CraftBlockType.bukkitToMinecraft(material).defaultBlockState(); - return CraftBlockData.fromData((hasBlockData()) ? ItemBlock.getBlockState(defaultData, blockData) : defaultData); + return CraftBlockData.fromData((hasBlockData()) ? new BlockItemStateProperties(blockData).apply(defaultData) : defaultData); } @Override @@ -949,6 +1060,16 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { repairCost = cost; } + @Override + public boolean isHideTooltip() { + return this.hideTooltip; + } + + @Override + public void setHideTooltip(boolean hideTooltip) { + this.hideTooltip = hideTooltip; + } + @Override public boolean isUnbreakable() { return unbreakable; @@ -959,6 +1080,81 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { this.unbreakable = unbreakable; } + @Override + public boolean hasEnchantmentGlintOverride() { + return this.enchantmentGlintOverride != null; + } + + @Override + public Boolean getEnchantmentGlintOverride() { + Preconditions.checkState(hasEnchantmentGlintOverride(), "We don't have enchantment_glint_override! Check hasEnchantmentGlintOverride first!"); + return this.enchantmentGlintOverride; + } + + @Override + public void setEnchantmentGlintOverride(Boolean override) { + this.enchantmentGlintOverride = override; + } + + @Override + public boolean isFireResistant() { + return this.fireResistant; + } + + @Override + public void setFireResistant(boolean fireResistant) { + this.fireResistant = fireResistant; + } + + @Override + public boolean hasMaxStackSize() { + return this.maxStackSize != null; + } + + @Override + public int getMaxStackSize() { + Preconditions.checkState(hasMaxStackSize(), "We don't have max_stack_size! Check hasMaxStackSize first!"); + return this.maxStackSize; + } + + @Override + public void setMaxStackSize(Integer max) { + Preconditions.checkArgument(max == null || max > 0, "max_stack_size must be > 0"); + Preconditions.checkArgument(max == null || max <= net.minecraft.world.item.Item.ABSOLUTE_MAX_STACK_SIZE, "max_stack_size must be <= 99"); + this.maxStackSize = max; + } + + @Override + public boolean hasRarity() { + return this.rarity != null; + } + + @Override + public ItemRarity getRarity() { + Preconditions.checkState(hasRarity(), "We don't have rarity! Check hasRarity first!"); + return this.rarity; + } + + @Override + public void setRarity(ItemRarity rarity) { + this.rarity = rarity; + } + + @Override + public boolean hasFood() { + return this.food != null; + } + + @Override + public FoodComponent getFood() { + return (this.hasFood()) ? new CraftFoodComponent(this.food) : new CraftFoodComponent(new FoodInfo(0, 0, false, 0, Collections.emptyList())); + } + + @Override + public void setFood(FoodComponent food) { + this.food = (food == null) ? null : new CraftFoodComponent((CraftFoodComponent) food); + } + @Override public boolean hasAttributeModifiers() { return attributeModifiers != null && !attributeModifiers.isEmpty(); @@ -1077,9 +1273,9 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { @Override public String getAsString() { - NBTTagCompound tag = new NBTTagCompound(); + CraftMetaItem.Applicator tag = new CraftMetaItem.Applicator(); applyToItem(tag); - return tag.toString(); + return tag.build().toString(); } @Override @@ -1124,6 +1320,22 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { this.damage = damage; } + @Override + public boolean hasMaxDamage() { + return this.maxDamage != null; + } + + @Override + public int getMaxDamage() { + Preconditions.checkState(hasMaxDamage(), "We don't have max_damage! Check hasMaxDamage first!"); + return this.maxDamage; + } + + @Override + public void setMaxDamage(Integer maxDamage) { + this.maxDamage = maxDamage; + } + @Override public final boolean equals(Object object) { if (object == null) { @@ -1146,7 +1358,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { @Overridden boolean equalsCommon(CraftMetaItem that) { return ((this.hasDisplayName() ? that.hasDisplayName() && this.displayName.equals(that.displayName) : !that.hasDisplayName())) - && (this.hasLocalizedName() ? that.hasLocalizedName() && this.locName.equals(that.locName) : !that.hasLocalizedName()) + && (this.hasItemName() ? that.hasItemName() && this.itemName.equals(that.itemName) : !that.hasItemName()) && (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()) @@ -1154,10 +1366,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { && (this.hasRepairCost() ? that.hasRepairCost() && this.repairCost == that.repairCost : !that.hasRepairCost()) && (this.hasAttributeModifiers() ? that.hasAttributeModifiers() && compareModifiers(this.attributeModifiers, that.attributeModifiers) : !that.hasAttributeModifiers()) && (this.unhandledTags.equals(that.unhandledTags)) + && (Objects.equals(this.customTag, that.customTag)) && (this.persistentDataContainer.equals(that.persistentDataContainer)) && (this.hideFlag == that.hideFlag) + && (this.isHideTooltip() == that.isHideTooltip()) && (this.isUnbreakable() == that.isUnbreakable()) + && (this.hasEnchantmentGlintOverride() ? that.hasEnchantmentGlintOverride() && this.enchantmentGlintOverride.equals(that.enchantmentGlintOverride) : !that.hasEnchantmentGlintOverride()) + && (this.fireResistant == that.fireResistant) + && (this.hasMaxStackSize() ? that.hasMaxStackSize() && this.maxStackSize.equals(that.maxStackSize) : !that.hasMaxStackSize()) + && (this.rarity == that.rarity) + && (this.hasFood() ? that.hasFood() && this.food.equals(that.food) : !that.hasFood()) && (this.hasDamage() ? that.hasDamage() && this.damage == that.damage : !that.hasDamage()) + && (this.hasMaxDamage() ? that.hasMaxDamage() && this.maxDamage.equals(that.maxDamage) : !that.hasMaxDamage()) && (this.version == that.version); } @@ -1180,17 +1400,25 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { int applyHash() { int hash = 3; hash = 61 * hash + (hasDisplayName() ? this.displayName.hashCode() : 0); - hash = 61 * hash + (hasLocalizedName() ? this.locName.hashCode() : 0); + 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 + (hasBlockData() ? this.blockData.hashCode() : 0); hash = 61 * hash + (hasEnchants() ? this.enchantments.hashCode() : 0); hash = 61 * hash + (hasRepairCost() ? this.repairCost : 0); hash = 61 * hash + unhandledTags.hashCode(); + hash = 61 * hash + ((customTag != null) ? this.customTag.hashCode() : 0); hash = 61 * hash + (!persistentDataContainer.isEmpty() ? persistentDataContainer.hashCode() : 0); hash = 61 * hash + hideFlag; + hash = 61 * hash + (isHideTooltip() ? 1231 : 1237); hash = 61 * hash + (isUnbreakable() ? 1231 : 1237); + hash = 61 * hash + (hasEnchantmentGlintOverride() ? this.enchantmentGlintOverride.hashCode() : 0); + hash = 61 * hash + (isFireResistant() ? 1231 : 1237); + hash = 61 * hash + (hasMaxStackSize() ? this.maxStackSize.hashCode() : 0); + hash = 61 * hash + (hasRarity() ? this.rarity.hashCode() : 0); + hash = 61 * hash + (hasFood() ? this.food.hashCode() : 0); hash = 61 * hash + (hasDamage() ? this.damage : 0); + hash = 61 * hash + (hasMaxDamage() ? 1231 : 1237); hash = 61 * hash + (hasAttributeModifiers() ? this.attributeModifiers.hashCode() : 0); hash = 61 * hash + version; return hash; @@ -1202,7 +1430,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { try { CraftMetaItem clone = (CraftMetaItem) super.clone(); if (this.lore != null) { - clone.lore = new ArrayList(this.lore); + clone.lore = new ArrayList(this.lore); } clone.customModelData = this.customModelData; clone.blockData = this.blockData; @@ -1212,10 +1440,22 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { if (this.hasAttributeModifiers()) { clone.attributeModifiers = LinkedHashMultimap.create(this.attributeModifiers); } + if (this.customTag != null) { + clone.customTag = this.customTag.copy(); + } clone.persistentDataContainer = new CraftPersistentDataContainer(this.persistentDataContainer.getRaw(), DATA_TYPE_REGISTRY); clone.hideFlag = this.hideFlag; + clone.hideTooltip = this.hideTooltip; clone.unbreakable = this.unbreakable; + clone.enchantmentGlintOverride = this.enchantmentGlintOverride; + clone.fireResistant = fireResistant; + clone.maxStackSize = maxStackSize; + clone.rarity = rarity; + if (this.hasFood()) { + clone.food = new CraftFoodComponent(food); + } clone.damage = this.damage; + clone.maxDamage = this.maxDamage; clone.version = this.version; return clone; } catch (CloneNotSupportedException e) { @@ -1234,10 +1474,11 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { @Overridden ImmutableMap.Builder serialize(ImmutableMap.Builder builder) { if (hasDisplayName()) { - builder.put(NAME.BUKKIT, displayName); + builder.put(NAME.BUKKIT, CraftChatMessage.toJSON(displayName)); } - if (hasLocalizedName()) { - builder.put(LOCNAME.BUKKIT, locName); + + if (hasItemName()) { + builder.put(ITEM_NAME.BUKKIT, CraftChatMessage.toJSON(itemName)); } if (lore != null) { @@ -1248,7 +1489,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { builder.put(CUSTOM_MODEL_DATA.BUKKIT, customModelData); } if (hasBlockData()) { - builder.put(BLOCK_DATA.BUKKIT, CraftNBTTagConfigSerializer.serialize(blockData)); + builder.put(BLOCK_DATA.BUKKIT, blockData); } serializeEnchantments(enchantments, builder, ENCHANTMENTS); @@ -1266,15 +1507,43 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { builder.put(HIDEFLAGS.BUKKIT, hideFlags); } + if (isHideTooltip()) { + builder.put(HIDE_TOOLTIP.BUKKIT, hideTooltip); + } + if (isUnbreakable()) { builder.put(UNBREAKABLE.BUKKIT, unbreakable); } + if (hasEnchantmentGlintOverride()) { + builder.put(ENCHANTMENT_GLINT_OVERRIDE.BUKKIT, enchantmentGlintOverride); + } + + if (isFireResistant()) { + builder.put(FIRE_RESISTANT.BUKKIT, fireResistant); + } + + if (hasMaxStackSize()) { + builder.put(MAX_STACK_SIZE.BUKKIT, maxStackSize); + } + + if (hasRarity()) { + builder.put(RARITY.BUKKIT, rarity.name()); + } + + if (hasFood()) { + builder.put(FOOD.BUKKIT, food); + } + if (hasDamage()) { builder.put(DAMAGE.BUKKIT, damage); } - final Map internalTags = new HashMap(unhandledTags); + if (hasMaxDamage()) { + builder.put(MAX_DAMAGE.BUKKIT, maxDamage); + } + + final Map internalTags = new HashMap(); serializeInternal(internalTags); if (!internalTags.isEmpty()) { NBTTagCompound internal = new NBTTagCompound(); @@ -1290,10 +1559,31 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { } } + if (!unhandledTags.isEmpty()) { + NBTBase unhandled = DataComponentPatch.CODEC.encodeStart(MinecraftServer.getDefaultRegistryAccess().createSerializationContext(DynamicOpsNBT.INSTANCE), unhandledTags.build()).getOrThrow(IllegalStateException::new); + try { + ByteArrayOutputStream buf = new ByteArrayOutputStream(); + NBTCompressedStreamTools.writeCompressed((NBTTagCompound) unhandled, buf); + builder.put("unhandled", Base64.getEncoder().encodeToString(buf.toByteArray())); + } catch (IOException ex) { + Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex); + } + } + if (!persistentDataContainer.isEmpty()) { // Store custom tags, wrapped in their compound builder.put(BUKKIT_CUSTOM_TAG.BUKKIT, persistentDataContainer.serialize()); } + if (customTag != null && !customTag.isEmpty()) { + try { + ByteArrayOutputStream buf = new ByteArrayOutputStream(); + NBTCompressedStreamTools.writeCompressed(customTag, buf); + builder.put("custom", Base64.getEncoder().encodeToString(buf.toByteArray())); + } catch (IOException ex) { + Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex); + } + } + return builder; } @@ -1336,7 +1626,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { builder.put(key.BUKKIT, mods); } - static void safelyAdd(Iterable addFrom, Collection addTo, boolean possiblyJsonInput) { + static void safelyAdd(Iterable addFrom, Collection addTo, boolean possiblyJsonInput) { if (addFrom == null) { return; } @@ -1350,14 +1640,14 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { throw new IllegalArgumentException(addFrom + " cannot contain non-string " + object.getClass().getName()); } - addTo.add(CraftChatMessage.toJSON(IChatBaseComponent.empty())); + addTo.add(IChatBaseComponent.empty()); } else { String entry = object.toString(); if (possiblyJsonInput) { - addTo.add(CraftChatMessage.fromJSONOrStringToJSON(entry)); + addTo.add(CraftChatMessage.fromJSONOrString(entry)); } else { - addTo.add(CraftChatMessage.fromStringToJSON(entry)); + addTo.add(CraftChatMessage.fromStringOrNull(entry)); } } } @@ -1391,62 +1681,65 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { this.version = version; } - public static Set getHandledTags() { + public static Set getHandledTags() { synchronized (HANDLED_TAGS) { if (HANDLED_TAGS.isEmpty()) { HANDLED_TAGS.addAll(Arrays.asList( - DISPLAY.NBT, - CUSTOM_MODEL_DATA.NBT, - BLOCK_DATA.NBT, - REPAIR.NBT, - ENCHANTMENTS.NBT, - HIDEFLAGS.NBT, - UNBREAKABLE.NBT, - DAMAGE.NBT, - BUKKIT_CUSTOM_TAG.NBT, - ATTRIBUTES.NBT, - ATTRIBUTES_IDENTIFIER.NBT, - ATTRIBUTES_NAME.NBT, - ATTRIBUTES_VALUE.NBT, - ATTRIBUTES_UUID_HIGH.NBT, - ATTRIBUTES_UUID_LOW.NBT, - ATTRIBUTES_SLOT.NBT, - CraftMetaArmor.TRIM.NBT, - CraftMetaArmor.TRIM_MATERIAL.NBT, - CraftMetaArmor.TRIM_PATTERN.NBT, - CraftMetaMap.MAP_SCALING.NBT, - CraftMetaMap.MAP_COLOR.NBT, - CraftMetaMap.MAP_ID.NBT, - CraftMetaPotion.POTION_EFFECTS.NBT, - CraftMetaPotion.DEFAULT_POTION.NBT, - CraftMetaPotion.POTION_COLOR.NBT, - CraftMetaSkull.SKULL_OWNER.NBT, - CraftMetaSkull.SKULL_PROFILE.NBT, - CraftMetaSpawnEgg.ENTITY_TAG.NBT, - CraftMetaBlockState.BLOCK_ENTITY_TAG.NBT, - CraftMetaBook.BOOK_TITLE.NBT, - CraftMetaBook.BOOK_AUTHOR.NBT, - CraftMetaBook.BOOK_PAGES.NBT, - CraftMetaBook.RESOLVED.NBT, - CraftMetaBook.GENERATION.NBT, - CraftMetaFirework.FIREWORKS.NBT, - CraftMetaEnchantedBook.STORED_ENCHANTMENTS.NBT, - CraftMetaCharge.EXPLOSION.NBT, - CraftMetaBlockState.BLOCK_ENTITY_TAG.NBT, - CraftMetaKnowledgeBook.BOOK_RECIPES.NBT, - CraftMetaTropicalFishBucket.VARIANT.NBT, - CraftMetaAxolotlBucket.VARIANT.NBT, - CraftMetaCrossbow.CHARGED.NBT, - CraftMetaCrossbow.CHARGED_PROJECTILES.NBT, - CraftMetaSuspiciousStew.EFFECTS.NBT, - CraftMetaCompass.LODESTONE_DIMENSION.NBT, - CraftMetaCompass.LODESTONE_POS.NBT, - CraftMetaCompass.LODESTONE_TRACKED.NBT, - CraftMetaBundle.ITEMS.NBT, - CraftMetaMusicInstrument.GOAT_HORN_INSTRUMENT.NBT + NAME.TYPE, + ITEM_NAME.TYPE, + LORE.TYPE, + CUSTOM_MODEL_DATA.TYPE, + BLOCK_DATA.TYPE, + REPAIR.TYPE, + ENCHANTMENTS.TYPE, + HIDE_ADDITIONAL_TOOLTIP.TYPE, + HIDE_TOOLTIP.TYPE, + UNBREAKABLE.TYPE, + ENCHANTMENT_GLINT_OVERRIDE.TYPE, + FIRE_RESISTANT.TYPE, + MAX_STACK_SIZE.TYPE, + RARITY.TYPE, + FOOD.TYPE, + DAMAGE.TYPE, + MAX_DAMAGE.TYPE, + CUSTOM_DATA.TYPE, + ATTRIBUTES.TYPE, + CraftMetaArmor.TRIM.TYPE, + CraftMetaArmorStand.ENTITY_TAG.TYPE, + CraftMetaBanner.PATTERNS.TYPE, + CraftMetaEntityTag.ENTITY_TAG.TYPE, + CraftMetaLeatherArmor.COLOR.TYPE, + CraftMetaMap.MAP_POST_PROCESSING.TYPE, + CraftMetaMap.MAP_COLOR.TYPE, + CraftMetaMap.MAP_ID.TYPE, + CraftMetaPotion.POTION_CONTENTS.TYPE, + CraftMetaSkull.SKULL_PROFILE.TYPE, + CraftMetaSpawnEgg.ENTITY_TAG.TYPE, + CraftMetaBlockState.BLOCK_ENTITY_TAG.TYPE, + CraftMetaBook.BOOK_CONTENT.TYPE, + CraftMetaBookSigned.BOOK_CONTENT.TYPE, + CraftMetaFirework.FIREWORKS.TYPE, + CraftMetaEnchantedBook.STORED_ENCHANTMENTS.TYPE, + CraftMetaCharge.EXPLOSION.TYPE, + CraftMetaBlockState.BLOCK_ENTITY_TAG.TYPE, + CraftMetaKnowledgeBook.BOOK_RECIPES.TYPE, + CraftMetaTropicalFishBucket.ENTITY_TAG.TYPE, + CraftMetaAxolotlBucket.ENTITY_TAG.TYPE, + CraftMetaCrossbow.CHARGED_PROJECTILES.TYPE, + CraftMetaSuspiciousStew.EFFECTS.TYPE, + CraftMetaCompass.LODESTONE_TARGET.TYPE, + CraftMetaBundle.ITEMS.TYPE, + CraftMetaMusicInstrument.GOAT_HORN_INSTRUMENT.TYPE, + CraftMetaOminousBottle.OMINOUS_BOTTLE_AMPLIFIER.TYPE )); } return HANDLED_TAGS; } } + + protected static Optional getOrEmpty(DataComponentPatch tag, ItemMetaKeyType type) { + Optional result = tag.get(type.TYPE); + + return (result != null) ? result : Optional.empty(); + } } 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 caeaaf87d1..8d8f776a10 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 @@ -5,20 +5,19 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import net.minecraft.resources.MinecraftKey; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.configuration.serialization.DelegateDeserialization; -import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.meta.KnowledgeBookMeta; @DelegateDeserialization(SerializableMeta.class) public class CraftMetaKnowledgeBook extends CraftMetaItem implements KnowledgeBookMeta { - static final ItemMetaKey BOOK_RECIPES = new ItemMetaKey("Recipes"); + static final ItemMetaKeyType> BOOK_RECIPES = new ItemMetaKeyType<>(DataComponents.RECIPES, "Recipes"); static final int MAX_RECIPES = Short.MAX_VALUE; protected List recipes = new ArrayList(); @@ -32,18 +31,16 @@ public class CraftMetaKnowledgeBook extends CraftMetaItem implements KnowledgeBo } } - CraftMetaKnowledgeBook(NBTTagCompound tag) { + CraftMetaKnowledgeBook(DataComponentPatch tag) { super(tag); - if (tag.contains(BOOK_RECIPES.NBT)) { - NBTTagList pages = tag.getList(BOOK_RECIPES.NBT, 8); - + getOrEmpty(tag, BOOK_RECIPES).ifPresent((pages) -> { for (int i = 0; i < pages.size(); i++) { - String recipe = pages.getString(i); + MinecraftKey recipe = pages.get(i); - addRecipe(CraftNamespacedKey.fromString(recipe)); + addRecipe(CraftNamespacedKey.fromMinecraft(recipe)); } - } + }); } CraftMetaKnowledgeBook(Map map) { @@ -60,15 +57,15 @@ public class CraftMetaKnowledgeBook extends CraftMetaItem implements KnowledgeBo } @Override - void applyToItem(NBTTagCompound itemData) { + void applyToItem(CraftMetaItem.Applicator itemData) { super.applyToItem(itemData); if (hasRecipes()) { - NBTTagList list = new NBTTagList(); + List list = new ArrayList<>(); for (NamespacedKey recipe : this.recipes) { - list.add(NBTTagString.valueOf(recipe.toString())); + list.add(CraftNamespacedKey.toMinecraft(recipe)); } - itemData.put(BOOK_RECIPES.NBT, list); + itemData.put(BOOK_RECIPES, list); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaLeatherArmor.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaLeatherArmor.java index 6aa72c945f..28de678754 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaLeatherArmor.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaLeatherArmor.java @@ -5,12 +5,13 @@ import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Sets; import java.util.Map; import java.util.Set; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagInt; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.component.DyedItemColor; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; -import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.meta.LeatherArmorMeta; @DelegateDeserialization(SerializableMeta.class) @@ -21,10 +22,11 @@ class CraftMetaLeatherArmor extends CraftMetaItem implements LeatherArmorMeta { Material.LEATHER_HORSE_ARMOR, Material.LEATHER_CHESTPLATE, Material.LEATHER_LEGGINGS, - Material.LEATHER_BOOTS + Material.LEATHER_BOOTS, + Material.WOLF_ARMOR ); - static final ItemMetaKey COLOR = new ItemMetaKey("color"); + static final ItemMetaKeyType COLOR = new ItemMetaKeyType<>(DataComponents.DYED_COLOR, "color"); private Color color = DEFAULT_LEATHER_COLOR; @@ -33,7 +35,7 @@ class CraftMetaLeatherArmor extends CraftMetaItem implements LeatherArmorMeta { readColor(this, meta); } - CraftMetaLeatherArmor(NBTTagCompound tag) { + CraftMetaLeatherArmor(DataComponentPatch tag) { super(tag); readColor(this, tag); } @@ -44,7 +46,7 @@ class CraftMetaLeatherArmor extends CraftMetaItem implements LeatherArmorMeta { } @Override - void applyToItem(NBTTagCompound itemTag) { + void applyToItem(CraftMetaItem.Applicator itemTag) { super.applyToItem(itemTag); applyColor(this, itemTag); } @@ -127,17 +129,18 @@ class CraftMetaLeatherArmor extends CraftMetaItem implements LeatherArmorMeta { meta.setColor(armorMeta.color); } - static void readColor(LeatherArmorMeta meta, NBTTagCompound tag) { - if (tag.contains(DISPLAY.NBT)) { - NBTTagCompound display = tag.getCompound(DISPLAY.NBT); - if (display.contains(COLOR.NBT)) { - try { - meta.setColor(Color.fromRGB(display.getInt(COLOR.NBT))); - } catch (IllegalArgumentException ex) { - // Invalid colour - } + static void readColor(LeatherArmorMeta meta, DataComponentPatch tag) { + getOrEmpty(tag, COLOR).ifPresent((dyedItemColor) -> { + if (!dyedItemColor.showInTooltip()) { + meta.addItemFlags(ItemFlag.HIDE_DYE); } - } + + try { + meta.setColor(Color.fromRGB(dyedItemColor.rgb())); + } catch (IllegalArgumentException ex) { + // Invalid colour + } + }); } static void readColor(LeatherArmorMeta meta, Map map) { @@ -148,9 +151,9 @@ class CraftMetaLeatherArmor extends CraftMetaItem implements LeatherArmorMeta { return !DEFAULT_LEATHER_COLOR.equals(meta.getColor()); } - static void applyColor(LeatherArmorMeta meta, NBTTagCompound tag) { + static void applyColor(LeatherArmorMeta meta, CraftMetaItem.Applicator tag) { if (hasColor(meta)) { - ((CraftMetaItem) meta).setDisplayTag(tag, COLOR.NBT, NBTTagInt.valueOf(meta.getColor().asRGB())); + tag.put(COLOR, new DyedItemColor(meta.getColor().asRGB(), !meta.hasItemFlag(ItemFlag.HIDE_DYE))); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java index 8d81247195..e01e52a1ee 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java @@ -3,25 +3,27 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import java.util.Map; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagInt; -import net.minecraft.nbt.NBTTagString; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.component.MapItemColor; +import net.minecraft.world.item.component.MapPostProcessing; +import net.minecraft.world.level.saveddata.maps.MapId; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; -import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.inventory.meta.MapMeta; import org.bukkit.map.MapView; @DelegateDeserialization(SerializableMeta.class) class CraftMetaMap extends CraftMetaItem implements MapMeta { - static final ItemMetaKey MAP_SCALING = new ItemMetaKey("map_is_scaling", "scaling"); + @ItemMetaKey.Specific(ItemMetaKey.Specific.To.NBT) + static final ItemMetaKeyType MAP_POST_PROCESSING = new ItemMetaKeyType<>(DataComponents.MAP_POST_PROCESSING); + static final ItemMetaKey MAP_SCALING = new ItemMetaKey("scaling"); @Deprecated // SPIGOT-6308 - static final ItemMetaKey MAP_LOC_NAME = new ItemMetaKey("LocName", "display-loc-name"); - static final ItemMetaKey MAP_COLOR = new ItemMetaKey("MapColor", "display-map-color"); - static final ItemMetaKey MAP_ID = new ItemMetaKey("map", "map-id"); + static final ItemMetaKey MAP_LOC_NAME = new ItemMetaKey("display-loc-name"); + static final ItemMetaKeyType MAP_COLOR = new ItemMetaKeyType<>(DataComponents.MAP_COLOR, "display-map-color"); + static final ItemMetaKeyType MAP_ID = new ItemMetaKeyType<>(DataComponents.MAP_ID, "map-id"); static final byte SCALING_EMPTY = (byte) 0; static final byte SCALING_TRUE = (byte) 1; static final byte SCALING_FALSE = (byte) 2; @@ -43,28 +45,24 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta { this.color = map.color; } - CraftMetaMap(NBTTagCompound tag) { + CraftMetaMap(DataComponentPatch tag) { super(tag); - if (tag.contains(MAP_ID.NBT, CraftMagicNumbers.NBT.TAG_ANY_NUMBER)) { - this.mapId = tag.getInt(MAP_ID.NBT); - } + getOrEmpty(tag, MAP_ID).ifPresent((mapId) -> { + this.mapId = mapId.id(); + }); - if (tag.contains(MAP_SCALING.NBT)) { - this.scaling = tag.getBoolean(MAP_SCALING.NBT) ? SCALING_TRUE : SCALING_FALSE; - } + getOrEmpty(tag, MAP_POST_PROCESSING).ifPresent((mapPostProcessing) -> { + this.scaling = (mapPostProcessing == MapPostProcessing.SCALE) ? SCALING_TRUE : SCALING_FALSE; + }); - if (tag.contains(DISPLAY.NBT)) { - NBTTagCompound display = tag.getCompound(DISPLAY.NBT); - - if (display.contains(MAP_COLOR.NBT)) { - try { - color = Color.fromRGB(display.getInt(MAP_COLOR.NBT)); - } catch (IllegalArgumentException ex) { - // Invalid colour - } + getOrEmpty(tag, MAP_COLOR).ifPresent((mapColor) -> { + try { + color = Color.fromRGB(mapColor.rgb()); + } catch (IllegalArgumentException ex) { + // Invalid colour } - } + }); } CraftMetaMap(Map map) { @@ -92,23 +90,19 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta { } @Override - void applyToItem(NBTTagCompound tag) { + void applyToItem(CraftMetaItem.Applicator tag) { super.applyToItem(tag); if (hasMapId()) { - tag.putInt(MAP_ID.NBT, getMapId()); + tag.put(MAP_ID, new MapId(getMapId())); } if (hasScaling()) { - tag.putBoolean(MAP_SCALING.NBT, isScaling()); - } - - if (hasLocationName()) { - setDisplayTag(tag, MAP_LOC_NAME.NBT, NBTTagString.valueOf(getLocationName())); + tag.put(MAP_POST_PROCESSING, (isScaling()) ? MapPostProcessing.SCALE : MapPostProcessing.LOCK); } if (hasColor()) { - setDisplayTag(tag, MAP_COLOR.NBT, NBTTagInt.valueOf(color.asRGB())); + tag.put(MAP_COLOR, new MapItemColor(color.asRGB())); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMusicInstrument.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMusicInstrument.java index 7e0c7c992f..71d44f7475 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMusicInstrument.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMusicInstrument.java @@ -2,18 +2,22 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.collect.ImmutableMap; import java.util.Map; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.core.Holder; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.Instrument; import org.bukkit.Material; import org.bukkit.MusicInstrument; import org.bukkit.NamespacedKey; import org.bukkit.Registry; import org.bukkit.configuration.serialization.DelegateDeserialization; +import org.bukkit.craftbukkit.CraftMusicInstrument; import org.bukkit.inventory.meta.MusicInstrumentMeta; -@DelegateDeserialization(CraftMetaItem.SerializableMeta.class) +@DelegateDeserialization(SerializableMeta.class) public class CraftMetaMusicInstrument extends CraftMetaItem implements MusicInstrumentMeta { - static final ItemMetaKey GOAT_HORN_INSTRUMENT = new ItemMetaKey("instrument"); + static final ItemMetaKeyType> GOAT_HORN_INSTRUMENT = new ItemMetaKeyType<>(DataComponents.INSTRUMENT, "instrument"); private MusicInstrument instrument; CraftMetaMusicInstrument(CraftMetaItem meta) { @@ -25,13 +29,12 @@ public class CraftMetaMusicInstrument extends CraftMetaItem implements MusicInst } } - CraftMetaMusicInstrument(NBTTagCompound tag) { + CraftMetaMusicInstrument(DataComponentPatch tag) { super(tag); - if (tag.contains(GOAT_HORN_INSTRUMENT.NBT)) { - String string = tag.getString(GOAT_HORN_INSTRUMENT.NBT); - this.instrument = Registry.INSTRUMENT.get(NamespacedKey.fromString(string)); - } + getOrEmpty(tag, GOAT_HORN_INSTRUMENT).ifPresent((instrument) -> { + this.instrument = CraftMusicInstrument.minecraftHolderToBukkit(instrument); + }); } CraftMetaMusicInstrument(Map map) { @@ -44,11 +47,11 @@ public class CraftMetaMusicInstrument extends CraftMetaItem implements MusicInst } @Override - void applyToItem(NBTTagCompound tag) { + void applyToItem(CraftMetaItem.Applicator tag) { super.applyToItem(tag); if (instrument != null) { - tag.putString(GOAT_HORN_INSTRUMENT.NBT, instrument.getKey().toString()); + tag.put(GOAT_HORN_INSTRUMENT, CraftMusicInstrument.bukkitToMinecraftHolder(instrument)); } } 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 new file mode 100644 index 0000000000..4b6fdd8931 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaOminousBottle.java @@ -0,0 +1,126 @@ +package org.bukkit.craftbukkit.inventory; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap.Builder; +import java.util.Map; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import org.bukkit.Material; +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"); + private Integer ominousBottleAmplifier; + + CraftMetaOminousBottle(CraftMetaItem meta) { + super(meta); + if (!(meta instanceof CraftMetaOminousBottle)) { + return; + } + CraftMetaOminousBottle bottleMeta = (CraftMetaOminousBottle) meta; + ominousBottleAmplifier = bottleMeta.ominousBottleAmplifier; + } + + CraftMetaOminousBottle(DataComponentPatch tag) { + super(tag); + getOrEmpty(tag, OMINOUS_BOTTLE_AMPLIFIER).ifPresent((amplifier) -> { + ominousBottleAmplifier = amplifier; + }); + } + + CraftMetaOminousBottle(Map map) { + super(map); + Integer ominousBottleAmplifier = SerializableMeta.getObject(Integer.class, map, OMINOUS_BOTTLE_AMPLIFIER.BUKKIT, true); + if (ominousBottleAmplifier != null) { + setAmplifier(ominousBottleAmplifier); + } + } + + @Override + void applyToItem(CraftMetaItem.Applicator tag) { + super.applyToItem(tag); + + if (hasAmplifier()) { + tag.put(OMINOUS_BOTTLE_AMPLIFIER, ominousBottleAmplifier); + } + } + + @Override + boolean isEmpty() { + return super.isEmpty() && isBottleEmpty(); + } + + boolean isBottleEmpty() { + return !(hasAmplifier()); + } + + @Override + boolean applicableTo(Material type) { + return type == Material.OMINOUS_BOTTLE; + } + + @Override + public CraftMetaOminousBottle clone() { + CraftMetaOminousBottle clone = ((CraftMetaOminousBottle) super.clone()); + return clone; + } + + @Override + public boolean hasAmplifier() { + return ominousBottleAmplifier != null; + } + + @Override + public int getAmplifier() { + return ominousBottleAmplifier; + } + + @Override + public void setAmplifier(int amplifier) { + Preconditions.checkArgument(0 <= amplifier && amplifier <= 4, "Amplifier must be in range [0, 4]"); + this.ominousBottleAmplifier = amplifier; + } + + @Override + int applyHash() { + final int original; + int hash = original = super.applyHash(); + if (hasAmplifier()) { + hash = 61 * hash + ominousBottleAmplifier.hashCode(); + } + + return original != hash ? CraftMetaOminousBottle.class.hashCode() ^ hash : hash; + } + + @Override + boolean equalsCommon(CraftMetaItem meta) { + if (!super.equalsCommon(meta)) { + return false; + } + if (meta instanceof CraftMetaOminousBottle) { + CraftMetaOminousBottle that = (CraftMetaOminousBottle) meta; + + return (hasAmplifier() ? that.hasAmplifier() && this.ominousBottleAmplifier.equals(that.ominousBottleAmplifier) : !that.hasAmplifier()); + } + return true; + } + + @Override + boolean notUncommon(CraftMetaItem meta) { + return super.notUncommon(meta) && (meta instanceof CraftMetaOminousBottle || isBottleEmpty()); + } + + @Override + Builder serialize(Builder builder) { + super.serialize(builder); + + if (hasAmplifier()) { + builder.put(OMINOUS_BOTTLE_AMPLIFIER.BUKKIT, ominousBottleAmplifier); + } + + return builder; + } +} 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 a9378e8a9d..64d4f305fb 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 @@ -8,23 +8,24 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.Optional; import java.util.Set; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import net.minecraft.core.Holder; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.item.alchemy.PotionContents; +import net.minecraft.world.item.alchemy.PotionRegistry; import org.bukkit.Color; import org.bukkit.Material; -import org.bukkit.NamespacedKey; import org.bukkit.configuration.serialization.DelegateDeserialization; -import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta; +import org.bukkit.craftbukkit.potion.CraftPotionEffectType; import org.bukkit.craftbukkit.potion.CraftPotionType; -import org.bukkit.craftbukkit.potion.CraftPotionUtil; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; -import org.jetbrains.annotations.NotNull; @DelegateDeserialization(SerializableMeta.class) class CraftMetaPotion extends CraftMetaItem implements PotionMeta { @@ -36,19 +37,13 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { Material.TIPPED_ARROW ); - static final ItemMetaKey AMPLIFIER = new ItemMetaKey("amplifier", "amplifier"); - static final ItemMetaKey AMBIENT = new ItemMetaKey("ambient", "ambient"); - static final ItemMetaKey DURATION = new ItemMetaKey("duration", "duration"); - static final ItemMetaKey SHOW_PARTICLES = new ItemMetaKey("show_particles", "has-particles"); - static final ItemMetaKey SHOW_ICON = new ItemMetaKey("show_icon", "has-icon"); - static final ItemMetaKey POTION_EFFECTS = new ItemMetaKey("custom_potion_effects", "custom-effects"); - static final ItemMetaKey POTION_COLOR = new ItemMetaKey("CustomPotionColor", "custom-color"); - static final ItemMetaKey ID = new ItemMetaKey("id", "potion-id"); - static final ItemMetaKey DEFAULT_POTION = new ItemMetaKey("Potion", "potion-type"); + @ItemMetaKey.Specific(ItemMetaKey.Specific.To.NBT) + 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 DEFAULT_POTION = new ItemMetaKey("potion-type"); - // Having an initial "state" in ItemMeta seems bit dirty but the UNCRAFTABLE potion type - // is treated as the empty form of the meta because it represents an empty potion with no effect - private PotionType type = PotionType.UNCRAFTABLE; + private PotionType type; private List customEffects; private Color color; @@ -64,42 +59,41 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { } } - CraftMetaPotion(NBTTagCompound tag) { + CraftMetaPotion(DataComponentPatch tag) { super(tag); - if (tag.contains(DEFAULT_POTION.NBT)) { - type = CraftPotionType.stringToBukkit(tag.getString(DEFAULT_POTION.NBT)); - if (type == null) { - type = PotionType.UNCRAFTABLE; - } - } - if (tag.contains(POTION_COLOR.NBT)) { - try { - color = Color.fromRGB(tag.getInt(POTION_COLOR.NBT)); - } catch (IllegalArgumentException ex) { - // Invalid colour - } - } - if (tag.contains(POTION_EFFECTS.NBT)) { - NBTTagList list = tag.getList(POTION_EFFECTS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND); + getOrEmpty(tag, POTION_CONTENTS).ifPresent((potionContents) -> { + potionContents.potion().ifPresent((potion) -> { + type = CraftPotionType.minecraftHolderToBukkit(potion); + }); + + potionContents.customColor().ifPresent((customColor) -> { + try { + color = Color.fromRGB(customColor); + } catch (IllegalArgumentException ex) { + // Invalid colour + } + }); + + List list = potionContents.customEffects(); int length = list.size(); customEffects = new ArrayList<>(length); for (int i = 0; i < length; i++) { - NBTTagCompound effect = list.getCompound(i); - PotionEffectType type = PotionEffectType.getByKey(NamespacedKey.fromString(effect.getString(ID.NBT))); + MobEffect effect = list.get(i); + PotionEffectType type = CraftPotionEffectType.minecraftHolderToBukkit(effect.getEffect()); // SPIGOT-4047: Vanilla just disregards these if (type == null) { continue; } - int amp = effect.getByte(AMPLIFIER.NBT); - int duration = effect.getInt(DURATION.NBT); - boolean ambient = effect.getBoolean(AMBIENT.NBT); - boolean particles = effect.contains(SHOW_PARTICLES.NBT, CraftMagicNumbers.NBT.TAG_BYTE) ? effect.getBoolean(SHOW_PARTICLES.NBT) : true; - boolean icon = effect.contains(SHOW_ICON.NBT, CraftMagicNumbers.NBT.TAG_BYTE) ? effect.getBoolean(SHOW_ICON.NBT) : particles; + int amp = effect.getAmplifier(); + int duration = effect.getDuration(); + boolean ambient = effect.isAmbient(); + boolean particles = effect.isVisible(); + boolean icon = effect.showIcon(); customEffects.add(new PotionEffect(type, duration, amp, ambient, particles, icon)); } - } + }); } CraftMetaPotion(Map map) { @@ -108,9 +102,6 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { if (typeString != null) { type = CraftPotionType.stringToBukkit(typeString); } - if (type == null) { - type = PotionType.UNCRAFTABLE; - } Color color = SerializableMeta.getObject(Color.class, map, POTION_COLOR.BUKKIT, true); if (color != null) { @@ -129,30 +120,20 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { } @Override - void applyToItem(NBTTagCompound tag) { + void applyToItem(CraftMetaItem.Applicator tag) { super.applyToItem(tag); - tag.putString(DEFAULT_POTION.NBT, CraftPotionType.bukkitToString(type)); - - if (hasColor()) { - tag.putInt(POTION_COLOR.NBT, color.asRGB()); - } + Optional> defaultPotion = (hasBasePotionType()) ? Optional.of(CraftPotionType.bukkitToMinecraftHolder(type)) : Optional.empty(); + Optional potionColor = (hasColor()) ? Optional.of(this.color.asRGB()) : Optional.empty(); + List effectList = new ArrayList<>(); if (customEffects != null) { - NBTTagList effectList = new NBTTagList(); - tag.put(POTION_EFFECTS.NBT, effectList); - for (PotionEffect effect : customEffects) { - NBTTagCompound effectData = new NBTTagCompound(); - effectData.putString(ID.NBT, effect.getType().getKey().toString()); - effectData.putByte(AMPLIFIER.NBT, (byte) effect.getAmplifier()); - effectData.putInt(DURATION.NBT, effect.getDuration()); - effectData.putBoolean(AMBIENT.NBT, effect.isAmbient()); - effectData.putBoolean(SHOW_PARTICLES.NBT, effect.hasParticles()); - effectData.putBoolean(SHOW_ICON.NBT, effect.hasIcon()); - effectList.add(effectData); + effectList.add(new MobEffect(CraftPotionEffectType.bukkitToMinecraftHolder(effect.getType()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles(), effect.hasIcon())); } } + + tag.put(POTION_CONTENTS, new PotionContents(defaultPotion, potionColor, effectList)); } @Override @@ -161,7 +142,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { } boolean isPotionEmpty() { - return (type == PotionType.UNCRAFTABLE) && !(hasCustomEffects() || hasColor()); + return (type == null) && !(hasCustomEffects() || hasColor()); } @Override @@ -180,30 +161,20 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { } @Override - public void setBasePotionData(PotionData data) { - Preconditions.checkArgument(data != null, "PotionData cannot be null"); - this.type = CraftPotionUtil.fromBukkit(data); - } - - @Override - public PotionData getBasePotionData() { - return CraftPotionUtil.toBukkit(type); - } - - @Override - public void setBasePotionType(@NotNull PotionType potionType) { - // TODO: 10/6/23 Change PotionType.UNCRAFTABLE to PotionType.EMPTY in error message - Preconditions.checkArgument(potionType != null, "PotionType cannot be null use PotionType.UNCRAFTABLE to represent no effect instead."); - + public void setBasePotionType(PotionType potionType) { type = potionType; } - @NotNull @Override public PotionType getBasePotionType() { return type; } + @Override + public boolean hasBasePotionType() { + return type != null; + } + @Override public boolean hasCustomEffects() { return customEffects != null; @@ -324,7 +295,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { int applyHash() { final int original; int hash = original = super.applyHash(); - if (type != PotionType.UNCRAFTABLE) { + if (type != null) { hash = 73 * hash + type.hashCode(); } if (hasColor()) { @@ -344,7 +315,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { if (meta instanceof CraftMetaPotion) { CraftMetaPotion that = (CraftMetaPotion) meta; - return type.equals(that.type) + 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()); } @@ -359,7 +330,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { @Override Builder serialize(Builder builder) { super.serialize(builder); - if (type != PotionType.UNCRAFTABLE) { + if (type != null) { builder.put(DEFAULT_POTION.BUKKIT, CraftPotionType.bukkitToString(type)); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java index 3d42bf9e7f..da39f00de1 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java @@ -8,16 +8,18 @@ import java.util.Objects; import java.util.Set; import java.util.UUID; import net.minecraft.SystemUtils; -import net.minecraft.nbt.GameProfileSerializer; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import net.minecraft.nbt.DynamicOpsNBT; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.resources.MinecraftKey; +import net.minecraft.world.item.component.ResolvableProfile; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.OfflinePlayer; import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.craftbukkit.entity.CraftPlayer; -import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta; import org.bukkit.craftbukkit.profile.CraftPlayerProfile; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.craftbukkit.util.CraftNamespacedKey; @@ -45,17 +47,16 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta { ); @ItemMetaKey.Specific(ItemMetaKey.Specific.To.NBT) - static final ItemMetaKey SKULL_PROFILE = new ItemMetaKey("SkullProfile"); + static final ItemMetaKeyType SKULL_PROFILE = new ItemMetaKeyType<>(DataComponents.PROFILE, "SkullProfile"); - static final ItemMetaKey SKULL_OWNER = new ItemMetaKey("SkullOwner", "skull-owner"); + static final ItemMetaKey SKULL_OWNER = new ItemMetaKey("skull-owner"); @ItemMetaKey.Specific(ItemMetaKey.Specific.To.NBT) static final ItemMetaKey BLOCK_ENTITY_TAG = new ItemMetaKey("BlockEntityTag"); - static final ItemMetaKey NOTE_BLOCK_SOUND = new ItemMetaKey("note_block_sound"); + static final ItemMetaKeyType NOTE_BLOCK_SOUND = new ItemMetaKeyType<>(DataComponents.NOTE_BLOCK_SOUND, "note_block_sound"); static final int MAX_OWNER_LENGTH = 16; private GameProfile profile; - private NBTTagCompound serializedProfile; private MinecraftKey noteBlockSound; CraftMetaSkull(CraftMetaItem meta) { @@ -68,21 +69,16 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta { this.noteBlockSound = skullMeta.noteBlockSound; } - CraftMetaSkull(NBTTagCompound tag) { + CraftMetaSkull(DataComponentPatch tag) { super(tag); - if (tag.contains(SKULL_OWNER.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) { - this.setProfile(GameProfileSerializer.readGameProfile(tag.getCompound(SKULL_OWNER.NBT))); - } else if (tag.contains(SKULL_OWNER.NBT, CraftMagicNumbers.NBT.TAG_STRING) && !tag.getString(SKULL_OWNER.NBT).isEmpty()) { - this.setProfile(new GameProfile(SystemUtils.NIL_UUID, tag.getString(SKULL_OWNER.NBT))); - } + getOrEmpty(tag, SKULL_PROFILE).ifPresent((resolvableProfile) -> { + this.setProfile(resolvableProfile.gameProfile()); + }); - if (tag.contains(BLOCK_ENTITY_TAG.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) { - NBTTagCompound nbtTagCompound = tag.getCompound(BLOCK_ENTITY_TAG.NBT).copy(); - if (nbtTagCompound.contains(NOTE_BLOCK_SOUND.NBT, 8)) { - this.noteBlockSound = MinecraftKey.tryParse(nbtTagCompound.getString(NOTE_BLOCK_SOUND.NBT)); - } - } + getOrEmpty(tag, NOTE_BLOCK_SOUND).ifPresent((minecraftKey) -> { + this.noteBlockSound = minecraftKey; + }); } CraftMetaSkull(Map map) { @@ -116,7 +112,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta { skullTag.putUUID("Id", uuid); } - this.setProfile(GameProfileSerializer.readGameProfile(skullTag)); + this.setProfile(ResolvableProfile.CODEC.parse(DynamicOpsNBT.INSTANCE, skullTag).result().get().gameProfile()); } if (tag.contains(BLOCK_ENTITY_TAG.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) { @@ -129,32 +125,27 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta { private void setProfile(GameProfile profile) { this.profile = profile; - this.serializedProfile = (profile == null) ? null : GameProfileSerializer.writeGameProfile(new NBTTagCompound(), profile); } @Override - void applyToItem(NBTTagCompound tag) { + void applyToItem(CraftMetaItem.Applicator tag) { super.applyToItem(tag); if (profile != null) { - checkForInconsistency(); - // SPIGOT-6558: Set initial textures - tag.put(SKULL_OWNER.NBT, serializedProfile); + tag.put(SKULL_PROFILE, new ResolvableProfile(profile)); // Fill in textures PlayerProfile ownerProfile = new CraftPlayerProfile(profile); // getOwnerProfile may return null if (ownerProfile.getTextures().isEmpty()) { ownerProfile.update().thenAccept((filledProfile) -> { setOwnerProfile(filledProfile); - tag.put(SKULL_OWNER.NBT, serializedProfile); + tag.put(SKULL_PROFILE, new ResolvableProfile(profile)); }); } } if (noteBlockSound != null) { - NBTTagCompound nbtTagCompound = new NBTTagCompound(); - nbtTagCompound.putString(NOTE_BLOCK_SOUND.NBT, this.noteBlockSound.toString()); - tag.put(BLOCK_ENTITY_TAG.NBT, nbtTagCompound); + tag.put(NOTE_BLOCK_SOUND, this.noteBlockSound); } } @@ -283,9 +274,8 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta { if (meta instanceof CraftMetaSkull) { CraftMetaSkull that = (CraftMetaSkull) meta; - checkForInconsistency(); // SPIGOT-5403: equals does not check properties - return (this.profile != null ? that.profile != null && this.serializedProfile.equals(that.serializedProfile) : that.profile == null) && Objects.equals(this.noteBlockSound, that.noteBlockSound); + return (this.profile != null ? that.profile != null && this.profile.equals(that.profile) && this.profile.getProperties().equals(that.profile.getProperties()) : that.profile == null) && Objects.equals(this.noteBlockSound, that.noteBlockSound); } return true; } @@ -307,15 +297,4 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta { } return builder; } - - private void checkForInconsistency() { - if (profile != null && serializedProfile == null) { - // SPIGOT-7510: Fix broken reflection usage from plugins - Bukkit.getLogger().warning(""" - Found inconsistent skull meta, this should normally not happen and is not a Bukkit / Spigot issue, but one from a plugin you are using. - Bukkit will attempt to fix it this time for you, but may not be able to do this every time. - If you see this message after typing a command from a plugin, please report this to the plugin developer, they should use the api instead of relying on reflection (and doing it the wrong way)."""); - serializedProfile = GameProfileSerializer.writeGameProfile(new NBTTagCompound(), profile); - } - } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java index 16f317d622..a3218584b9 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSpawnEgg.java @@ -5,9 +5,12 @@ import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Sets; import java.util.Map; import java.util.Set; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.resources.MinecraftKey; +import net.minecraft.world.item.component.CustomData; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.craftbukkit.entity.CraftEntitySnapshot; @@ -17,15 +20,17 @@ import org.bukkit.entity.EntityType; import org.bukkit.inventory.meta.SpawnEggMeta; import org.bukkit.material.MaterialData; -@DelegateDeserialization(CraftMetaItem.SerializableMeta.class) +@DelegateDeserialization(SerializableMeta.class) public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta { private static final Set SPAWN_EGG_MATERIALS = Sets.newHashSet( + Material.ARMADILLO_SPAWN_EGG, Material.ALLAY_SPAWN_EGG, Material.AXOLOTL_SPAWN_EGG, Material.BAT_SPAWN_EGG, Material.BEE_SPAWN_EGG, Material.BLAZE_SPAWN_EGG, + Material.BOGGED_SPAWN_EGG, Material.BREEZE_SPAWN_EGG, Material.CAT_SPAWN_EGG, Material.CAMEL_SPAWN_EGG, @@ -101,7 +106,7 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta { Material.ZOMBIFIED_PIGLIN_SPAWN_EGG ); - static final ItemMetaKey ENTITY_TAG = new ItemMetaKey("EntityTag", "entity-tag"); + static final ItemMetaKeyType ENTITY_TAG = new ItemMetaKeyType<>(DataComponents.ENTITY_DATA, "entity-tag"); @ItemMetaKey.Specific(ItemMetaKey.Specific.To.NBT) static final ItemMetaKey ENTITY_ID = new ItemMetaKey("id"); @@ -120,12 +125,12 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta { updateMaterial(null); // Trigger type population } - CraftMetaSpawnEgg(NBTTagCompound tag) { + CraftMetaSpawnEgg(DataComponentPatch tag) { super(tag); - if (tag.contains(ENTITY_TAG.NBT)) { - entityTag = tag.getCompound(ENTITY_TAG.NBT).copy(); - } + getOrEmpty(tag, ENTITY_TAG).ifPresent((nbt) -> { + entityTag = nbt.copyTag(); + }); } CraftMetaSpawnEgg(Map map) { @@ -180,7 +185,7 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta { } @Override - void applyToItem(NBTTagCompound tag) { + void applyToItem(CraftMetaItem.Applicator tag) { super.applyToItem(tag); if (!isSpawnEggEmpty() && entityTag == null) { @@ -188,7 +193,7 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta { } if (entityTag != null) { - tag.put(ENTITY_TAG.NBT, entityTag); + tag.put(ENTITY_TAG, CustomData.of(entityTag)); } } @@ -294,7 +299,7 @@ public class CraftMetaSpawnEgg extends CraftMetaItem implements SpawnEggMeta { if (spawnedType != null) { if (entityTag != null) { // Remove ID tag as it is now in the material - entityTag.remove(ENTITY_ID.NBT); + entityTag.remove("id"); } return CraftLegacy.fromLegacy(new MaterialData(Material.LEGACY_MONSTER_EGG, (byte) spawnedType.getTypeId())); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java index 8520631592..0bfc3bad29 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java @@ -7,22 +7,20 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.item.component.SuspiciousStewEffects; import org.bukkit.Material; -import org.bukkit.NamespacedKey; import org.bukkit.configuration.serialization.DelegateDeserialization; -import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.potion.CraftPotionEffectType; import org.bukkit.inventory.meta.SuspiciousStewMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -@DelegateDeserialization(CraftMetaItem.SerializableMeta.class) +@DelegateDeserialization(SerializableMeta.class) public class CraftMetaSuspiciousStew extends CraftMetaItem implements SuspiciousStewMeta { - static final ItemMetaKey DURATION = new ItemMetaKey("duration", "duration"); - static final ItemMetaKey EFFECTS = new ItemMetaKey("effects", "effects"); - static final ItemMetaKey ID = new ItemMetaKey("id", "id"); + static final ItemMetaKeyType EFFECTS = new ItemMetaKeyType<>(DataComponents.SUSPICIOUS_STEW_EFFECTS, "effects"); private List customEffects; @@ -36,23 +34,23 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious } } - CraftMetaSuspiciousStew(NBTTagCompound tag) { + CraftMetaSuspiciousStew(DataComponentPatch tag) { super(tag); - if (tag.contains(EFFECTS.NBT)) { - NBTTagList list = tag.getList(EFFECTS.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND); + getOrEmpty(tag, EFFECTS).ifPresent((suspiciousStewEffects) -> { + List list = suspiciousStewEffects.effects(); int length = list.size(); customEffects = new ArrayList<>(length); for (int i = 0; i < length; i++) { - NBTTagCompound effect = list.getCompound(i); - PotionEffectType type = PotionEffectType.getByKey(NamespacedKey.fromString(effect.getString(ID.NBT))); + SuspiciousStewEffects.a effect = list.get(i); + PotionEffectType type = CraftPotionEffectType.minecraftHolderToBukkit(effect.effect()); if (type == null) { continue; } - int duration = effect.getInt(DURATION.NBT); + int duration = effect.duration(); customEffects.add(new PotionEffect(type, duration, 0)); } - } + }); } CraftMetaSuspiciousStew(Map map) { @@ -70,19 +68,16 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious } @Override - void applyToItem(NBTTagCompound tag) { + void applyToItem(CraftMetaItem.Applicator tag) { super.applyToItem(tag); if (customEffects != null) { - NBTTagList effectList = new NBTTagList(); - tag.put(EFFECTS.NBT, effectList); + List effectList = new ArrayList<>(); for (PotionEffect effect : customEffects) { - NBTTagCompound effectData = new NBTTagCompound(); - effectData.putString(ID.NBT, effect.getType().getKey().toString()); - effectData.putInt(DURATION.NBT, effect.getDuration()); - effectList.add(effectData); + effectList.add(new net.minecraft.world.item.component.SuspiciousStewEffects.a(CraftPotionEffectType.bukkitToMinecraftHolder(effect.getType()), effect.getDuration())); } + tag.put(EFFECTS, new SuspiciousStewEffects(effectList)); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaTropicalFishBucket.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaTropicalFishBucket.java index 08c71dab1a..caefdd1216 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaTropicalFishBucket.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaTropicalFishBucket.java @@ -2,13 +2,15 @@ package org.bukkit.craftbukkit.inventory; import com.google.common.collect.ImmutableMap; import java.util.Map; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.item.component.CustomData; import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.craftbukkit.entity.CraftTropicalFish; -import org.bukkit.craftbukkit.inventory.CraftMetaItem.SerializableMeta; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.entity.TropicalFish; import org.bukkit.inventory.meta.TropicalFishBucketMeta; @@ -16,7 +18,7 @@ import org.bukkit.inventory.meta.TropicalFishBucketMeta; @DelegateDeserialization(SerializableMeta.class) class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishBucketMeta { static final ItemMetaKey VARIANT = new ItemMetaKey("BucketVariantTag", "fish-variant"); - static final ItemMetaKey ENTITY_TAG = new ItemMetaKey("EntityTag", "entity-tag"); + static final ItemMetaKeyType ENTITY_TAG = new ItemMetaKeyType<>(DataComponents.ENTITY_DATA, "entity-tag"); private Integer variant; private NBTTagCompound entityTag; @@ -33,16 +35,16 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB this.entityTag = bucket.entityTag; } - CraftMetaTropicalFishBucket(NBTTagCompound tag) { + CraftMetaTropicalFishBucket(DataComponentPatch tag) { super(tag); - if (tag.contains(VARIANT.NBT, CraftMagicNumbers.NBT.TAG_INT)) { - this.variant = tag.getInt(VARIANT.NBT); - } + getOrEmpty(tag, ENTITY_TAG).ifPresent((nbt) -> { + entityTag = nbt.copyTag(); - if (tag.contains(ENTITY_TAG.NBT)) { - entityTag = tag.getCompound(ENTITY_TAG.NBT).copy(); - } + if (entityTag.contains(VARIANT.NBT, CraftMagicNumbers.NBT.TAG_INT)) { + this.variant = entityTag.getInt(VARIANT.NBT); + } + }); } CraftMetaTropicalFishBucket(Map map) { @@ -71,15 +73,18 @@ class CraftMetaTropicalFishBucket extends CraftMetaItem implements TropicalFishB } @Override - void applyToItem(NBTTagCompound tag) { + void applyToItem(CraftMetaItem.Applicator tag) { super.applyToItem(tag); if (hasVariant()) { - tag.putInt(VARIANT.NBT, variant); + if (entityTag == null) { + entityTag = new NBTTagCompound(); + } + entityTag.putInt(VARIANT.NBT, variant); } if (entityTag != null) { - tag.put(ENTITY_TAG.NBT, entityTag); + tag.put(ENTITY_TAG, CustomData.of(entityTag)); } } 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 193d24e079..4b846bb3f8 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 @@ -1,50 +1,31 @@ package org.bukkit.craftbukkit.inventory; -import com.google.common.base.Preconditions; -import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; import java.util.Iterator; import java.util.Map; -import net.minecraft.resources.MinecraftKey; import net.minecraft.server.MinecraftServer; import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.Recipes; import org.bukkit.inventory.Recipe; public class RecipeIterator implements Iterator { - private final Iterator, Object2ObjectLinkedOpenHashMap>>> recipes; - private Iterator> current; + private final Iterator, RecipeHolder>> recipes; public RecipeIterator() { - this.recipes = MinecraftServer.getServer().getRecipeManager().recipes.entrySet().iterator(); + this.recipes = MinecraftServer.getServer().getRecipeManager().byType.entries().iterator(); } @Override public boolean hasNext() { - if (current != null && current.hasNext()) { - return true; - } - - if (recipes.hasNext()) { - current = recipes.next().getValue().values().iterator(); - return hasNext(); - } - - return false; + return recipes.hasNext(); } @Override public Recipe next() { - if (current == null || !current.hasNext()) { - current = recipes.next().getValue().values().iterator(); - return next(); - } - - return current.next().toBukkitRecipe(); + return recipes.next().getValue().toBukkitRecipe(); } @Override public void remove() { - Preconditions.checkState(current != null, "next() not yet called"); - current.remove(); + recipes.remove(); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/SerializableMeta.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/SerializableMeta.java new file mode 100644 index 0000000000..863bfd62a5 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/SerializableMeta.java @@ -0,0 +1,113 @@ +package org.bukkit.craftbukkit.inventory; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Map; +import java.util.NoSuchElementException; +import org.bukkit.configuration.serialization.ConfigurationSerializable; +import org.bukkit.configuration.serialization.SerializableAs; +import org.bukkit.inventory.meta.ItemMeta; + +@SerializableAs("ItemMeta") +public final class SerializableMeta implements ConfigurationSerializable { + static final String TYPE_FIELD = "meta-type"; + + static final ImmutableMap, String> classMap; + static final ImmutableMap> constructorMap; + + static { + classMap = ImmutableMap., String>builder() + .put(CraftMetaArmor.class, "ARMOR") + .put(CraftMetaArmorStand.class, "ARMOR_STAND") + .put(CraftMetaBanner.class, "BANNER") + .put(CraftMetaBlockState.class, "TILE_ENTITY") + .put(CraftMetaBook.class, "BOOK") + .put(CraftMetaBookSigned.class, "BOOK_SIGNED") + .put(CraftMetaSkull.class, "SKULL") + .put(CraftMetaLeatherArmor.class, "LEATHER_ARMOR") + .put(CraftMetaColorableArmor.class, "COLORABLE_ARMOR") + .put(CraftMetaMap.class, "MAP") + .put(CraftMetaPotion.class, "POTION") + .put(CraftMetaSpawnEgg.class, "SPAWN_EGG") + .put(CraftMetaEnchantedBook.class, "ENCHANTED") + .put(CraftMetaFirework.class, "FIREWORK") + .put(CraftMetaCharge.class, "FIREWORK_EFFECT") + .put(CraftMetaKnowledgeBook.class, "KNOWLEDGE_BOOK") + .put(CraftMetaTropicalFishBucket.class, "TROPICAL_FISH_BUCKET") + .put(CraftMetaAxolotlBucket.class, "AXOLOTL_BUCKET") + .put(CraftMetaCrossbow.class, "CROSSBOW") + .put(CraftMetaSuspiciousStew.class, "SUSPICIOUS_STEW") + .put(CraftMetaEntityTag.class, "ENTITY_TAG") + .put(CraftMetaCompass.class, "COMPASS") + .put(CraftMetaBundle.class, "BUNDLE") + .put(CraftMetaMusicInstrument.class, "MUSIC_INSTRUMENT") + .put(CraftMetaOminousBottle.class, "OMINOUS_BOTTLE") + .put(CraftMetaItem.class, "UNSPECIFIC") + .build(); + + final ImmutableMap.Builder> classConstructorBuilder = ImmutableMap.builder(); + for (Map.Entry, String> mapping : classMap.entrySet()) { + try { + classConstructorBuilder.put(mapping.getValue(), mapping.getKey().getDeclaredConstructor(Map.class)); + } catch (NoSuchMethodException e) { + throw new AssertionError(e); + } + } + constructorMap = classConstructorBuilder.build(); + } + + private SerializableMeta() { + } + + public static ItemMeta deserialize(Map map) throws Throwable { + Preconditions.checkArgument(map != null, "Cannot deserialize null map"); + + String type = getString(map, TYPE_FIELD, false); + Constructor constructor = constructorMap.get(type); + + if (constructor == null) { + throw new IllegalArgumentException(type + " is not a valid " + TYPE_FIELD); + } + + try { + return constructor.newInstance(map); + } catch (final InstantiationException e) { + throw new AssertionError(e); + } catch (final IllegalAccessException e) { + throw new AssertionError(e); + } catch (final InvocationTargetException e) { + throw e.getCause(); + } + } + + @Override + public Map serialize() { + throw new AssertionError(); + } + + public static String getString(Map map, Object field, boolean nullable) { + return getObject(String.class, map, field, nullable); + } + + public static boolean getBoolean(Map map, Object field) { + Boolean value = getObject(Boolean.class, map, field, true); + return value != null && value; + } + + public static T getObject(Class clazz, Map map, Object field, boolean nullable) { + final Object object = map.get(field); + + if (clazz.isInstance(object)) { + return clazz.cast(object); + } + if (object == null) { + if (!nullable) { + throw new NoSuchElementException(map + " does not contain " + field); + } + return null; + } + throw new IllegalArgumentException(field + "(" + object + ") is not a valid " + clazz); + } +} 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 new file mode 100644 index 0000000000..b54993dfd5 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftFoodComponent.java @@ -0,0 +1,242 @@ +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.stream.Collectors; +import net.minecraft.world.food.FoodInfo; +import org.bukkit.configuration.serialization.SerializableAs; +import org.bukkit.craftbukkit.inventory.SerializableMeta; +import org.bukkit.craftbukkit.potion.CraftPotionUtil; +import org.bukkit.inventory.meta.components.FoodComponent; +import org.bukkit.potion.PotionEffect; + +@SerializableAs("Food") +public final class CraftFoodComponent implements FoodComponent { + + private FoodInfo handle; + + public CraftFoodComponent(FoodInfo food) { + this.handle = food; + } + + public CraftFoodComponent(CraftFoodComponent food) { + this.handle = food.handle; + } + + public CraftFoodComponent(Map map) { + Integer nutrition = SerializableMeta.getObject(Integer.class, map, "nutrition", false); + Float saturationModifier = SerializableMeta.getObject(Float.class, map, "saturation-modifier", 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; + } + + 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, effects.build().stream().map(CraftFoodEffect::new).map(CraftFoodEffect::getHandle).toList()); + } + + @Override + public Map serialize() { + Map result = new LinkedHashMap<>(); + result.put("nutrition", getNutrition()); + result.put("saturation-modifier", getSaturationModifier()); + result.put("can-always-eat", canAlwaysEat()); + result.put("eat-seconds", getEatSeconds()); + result.put("effects", getEffects()); + return result; + } + + public FoodInfo getHandle() { + return handle; + } + + @Override + public int getNutrition() { + return handle.nutrition(); + } + + @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.effects()); + } + + @Override + public float getSaturationModifier() { + return handle.saturation(); + } + + @Override + public void setSaturationModifier(float saturationModifier) { + handle = new FoodInfo(handle.nutrition(), saturationModifier, handle.canAlwaysEat(), handle.eatSeconds(), handle.effects()); + } + + @Override + public boolean canAlwaysEat() { + return handle.canAlwaysEat(); + } + + @Override + public void setCanAlwaysEat(boolean canAlwaysEat) { + handle = new FoodInfo(handle.nutrition(), handle.saturation(), canAlwaysEat, handle.eatSeconds(), 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.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(), 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(), effects); + + return new CraftFoodEffect(newEffect); + } + + @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 CraftFoodComponent other = (CraftFoodComponent) obj; + return Objects.equals(this.handle, other.handle); + } + + @Override + 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/trim/CraftTrimMaterial.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimMaterial.java index a74ef8c241..0094020436 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 @@ -1,5 +1,8 @@ package org.bukkit.craftbukkit.inventory.trim; +import com.google.common.base.Preconditions; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.contents.TranslatableContents; import org.bukkit.NamespacedKey; @@ -15,10 +18,27 @@ public class CraftTrimMaterial implements TrimMaterial, Handleable minecraft) { + return minecraftToBukkit(minecraft.value()); + } + public static net.minecraft.world.item.armortrim.TrimMaterial bukkitToMinecraft(TrimMaterial bukkit) { return CraftRegistry.bukkitToMinecraft(bukkit); } + public static Holder bukkitToMinecraftHolder(TrimMaterial bukkit) { + Preconditions.checkArgument(bukkit != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.TRIM_MATERIAL); + + 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 trim material without properly registering it."); + } + private final NamespacedKey key; private final net.minecraft.world.item.armortrim.TrimMaterial handle; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimPattern.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimPattern.java index 6509f49f9e..8423af0856 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimPattern.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimPattern.java @@ -1,5 +1,8 @@ package org.bukkit.craftbukkit.inventory.trim; +import com.google.common.base.Preconditions; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.contents.TranslatableContents; import org.bukkit.NamespacedKey; @@ -15,10 +18,27 @@ public class CraftTrimPattern implements TrimPattern, Handleable minecraft) { + return minecraftToBukkit(minecraft.value()); + } + public static net.minecraft.world.item.armortrim.TrimPattern bukkitToMinecraft(TrimPattern bukkit) { return CraftRegistry.bukkitToMinecraft(bukkit); } + public static Holder bukkitToMinecraftHolder(TrimPattern bukkit) { + Preconditions.checkArgument(bukkit != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.TRIM_PATTERN); + + 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 trim pattern without properly registering it."); + } + private final NamespacedKey key; private final net.minecraft.world.item.armortrim.TrimPattern handle; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java index 073da86c96..896b43400b 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/util/CraftTileInventoryConverter.java @@ -35,7 +35,7 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) { IInventory te = getTileEntity(); if (te instanceof TileEntityLootable) { - ((TileEntityLootable) te).setCustomName(CraftChatMessage.fromStringOrNull(title)); + ((TileEntityLootable) te).name = CraftChatMessage.fromStringOrNull(title); } return getInventory(te); @@ -56,7 +56,7 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat @Override public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) { IInventory tileEntity = getTileEntity(); - ((TileEntityFurnace) tileEntity).setCustomName(CraftChatMessage.fromStringOrNull(title)); + ((TileEntityFurnace) tileEntity).name = CraftChatMessage.fromStringOrNull(title); return getInventory(tileEntity); } @@ -78,7 +78,7 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat // BrewingStand does not extend TileEntityLootable IInventory tileEntity = getTileEntity(); if (tileEntity instanceof TileEntityBrewingStand) { - ((TileEntityBrewingStand) tileEntity).setCustomName(CraftChatMessage.fromStringOrNull(title)); + ((TileEntityBrewingStand) tileEntity).name = CraftChatMessage.fromStringOrNull(title); } return getInventory(tileEntity); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapCursor.java b/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapCursor.java new file mode 100644 index 0000000000..5d042196a9 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapCursor.java @@ -0,0 +1,52 @@ +package org.bukkit.craftbukkit.map; + +import com.google.common.base.Preconditions; +import net.minecraft.core.Holder; +import net.minecraft.core.IRegistry; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.level.saveddata.maps.MapDecorationType; +import org.bukkit.Registry; +import org.bukkit.craftbukkit.CraftRegistry; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.map.MapCursor; + +public final class CraftMapCursor { + + public static final class CraftType { + + public static MapCursor.Type minecraftToBukkit(MapDecorationType minecraft) { + Preconditions.checkArgument(minecraft != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.MAP_DECORATION_TYPE); + MapCursor.Type bukkit = Registry.MAP_DECORATION_TYPE.get(CraftNamespacedKey.fromMinecraft(registry.getResourceKey(minecraft).orElseThrow().location())); + + Preconditions.checkArgument(bukkit != null); + + return bukkit; + } + + public static MapCursor.Type minecraftHolderToBukkit(Holder minecraft) { + return minecraftToBukkit(minecraft.value()); + } + + public static MapDecorationType bukkitToMinecraft(MapCursor.Type bukkit) { + Preconditions.checkArgument(bukkit != null); + + return CraftRegistry.getMinecraftRegistry(Registries.MAP_DECORATION_TYPE) + .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); + } + + public static Holder bukkitToMinecraftHolder(MapCursor.Type bukkit) { + Preconditions.checkArgument(bukkit != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.MAP_DECORATION_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 map cursor type without properly registering it."); + } + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapRenderer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapRenderer.java index c5dbcf41b4..34d4926c39 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapRenderer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapRenderer.java @@ -6,6 +6,7 @@ import org.bukkit.Bukkit; import org.bukkit.craftbukkit.util.CraftChatMessage; import org.bukkit.entity.Player; import org.bukkit.map.MapCanvas; +import org.bukkit.map.MapCursor; import org.bukkit.map.MapCursorCollection; import org.bukkit.map.MapRenderer; import org.bukkit.map.MapView; @@ -42,7 +43,7 @@ public class CraftMapRenderer extends MapRenderer { } MapIcon decoration = worldMap.decorations.get(key); - cursors.addCursor(decoration.x(), decoration.y(), (byte) (decoration.rot() & 15), decoration.type().getIcon(), true, CraftChatMessage.fromComponent(decoration.name())); + cursors.addCursor(new MapCursor(decoration.x(), decoration.y(), (byte) (decoration.rot() & 15), CraftMapCursor.CraftType.minecraftHolderToBukkit(decoration.type()), true, CraftChatMessage.fromComponent(decoration.name().orElse(null)))); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapView.java b/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapView.java index c291e30939..ab8e203c77 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapView.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapView.java @@ -1,6 +1,5 @@ package org.bukkit.craftbukkit.map; -import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -32,13 +31,7 @@ public final class CraftMapView implements MapView { @Override public int getId() { - String text = worldMap.id; - Preconditions.checkState(text.startsWith("map_"), "Map has a invalid ID"); - try { - return Integer.parseInt(text.substring("map_".length())); - } catch (NumberFormatException ex) { - throw new IllegalStateException("Map has non-numeric ID"); - } + return worldMap.id.id(); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/packs/CraftDataPack.java b/paper-server/src/main/java/org/bukkit/craftbukkit/packs/CraftDataPack.java index 006b8172d1..daaf004f3d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/packs/CraftDataPack.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/packs/CraftDataPack.java @@ -23,7 +23,7 @@ public class CraftDataPack implements DataPack { public CraftDataPack(ResourcePackLoader handler) { this.handle = handler; - try (IResourcePack iresourcepack = this.handle.resources.openPrimary(this.handle.getId())) { + try (IResourcePack iresourcepack = this.handle.resources.openPrimary(this.handle.location())) { this.resourcePackInfo = iresourcepack.getMetadataSection(ResourcePackInfo.TYPE); } catch (IOException e) { // This is already called in NMS then if in NMS not happen is secure this not throw here throw new RuntimeException(e); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionBrewer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionBrewer.java deleted file mode 100644 index 09ac71b6b4..0000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionBrewer.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.bukkit.craftbukkit.potion; - -import com.google.common.base.Preconditions; -import java.util.ArrayList; -import java.util.Collection; -import org.bukkit.potion.PotionBrewer; -import org.bukkit.potion.PotionData; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.potion.PotionType; - -public class CraftPotionBrewer implements PotionBrewer { - - @Override - public Collection getEffects(PotionType type, boolean upgraded, boolean extended) { - Preconditions.checkArgument(!type.getKey().getKey().startsWith("strong_"), "Strong potion type cannot be used directly, got %s", type.getKey()); - Preconditions.checkArgument(!type.getKey().getKey().startsWith("long_"), "Extended potion type cannot be used directly, got %s", type.getKey()); - - return CraftPotionUtil.fromBukkit(new PotionData(type, upgraded, extended)).getPotionEffects(); - } - - @Override - public Collection getEffectsFromDamage(int damage) { - return new ArrayList(); - } - - @Override - public PotionEffect createEffect(PotionEffectType potion, int duration, int amplifier) { - return new PotionEffect(potion, potion.isInstant() ? 1 : (int) (duration * potion.getDurationModifier()), amplifier); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionEffectType.java b/paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionEffectType.java index 84e6290edd..aaadaf666a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionEffectType.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionEffectType.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit.potion; +import net.minecraft.core.Holder; import net.minecraft.core.registries.Registries; import net.minecraft.world.effect.MobEffectList; import org.bukkit.Color; @@ -13,6 +14,10 @@ import org.jetbrains.annotations.NotNull; public class CraftPotionEffectType extends PotionEffectType implements Handleable { + public static PotionEffectType minecraftHolderToBukkit(Holder minecraft) { + return minecraftToBukkit(minecraft.value()); + } + public static PotionEffectType minecraftToBukkit(MobEffectList minecraft) { return CraftRegistry.minecraftToBukkit(minecraft, Registries.MOB_EFFECT, Registry.EFFECT); } @@ -21,6 +26,10 @@ public class CraftPotionEffectType extends PotionEffectType implements Handleabl return CraftRegistry.bukkitToMinecraft(bukkit); } + public static Holder bukkitToMinecraftHolder(PotionEffectType bukkit) { + return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.MOB_EFFECT); + } + private final NamespacedKey key; private final MobEffectList handle; private final int id; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionType.java b/paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionType.java index 8f64d277d9..3a63560d4d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionType.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionType.java @@ -4,6 +4,7 @@ import com.google.common.base.Preconditions; import com.google.common.base.Suppliers; import java.util.List; import java.util.function.Supplier; +import net.minecraft.core.Holder; import net.minecraft.core.IRegistry; import net.minecraft.core.registries.Registries; import net.minecraft.world.item.alchemy.PotionRegistry; @@ -17,6 +18,10 @@ import org.bukkit.potion.PotionType; public class CraftPotionType implements PotionType.InternalPotionData { + public static PotionType minecraftHolderToBukkit(Holder minecraft) { + return minecraftToBukkit(minecraft.value()); + } + public static PotionType minecraftToBukkit(PotionRegistry minecraft) { Preconditions.checkArgument(minecraft != null); @@ -35,6 +40,19 @@ public class CraftPotionType implements PotionType.InternalPotionData { .getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow(); } + public static Holder bukkitToMinecraftHolder(PotionType bukkit) { + Preconditions.checkArgument(bukkit != null); + + IRegistry registry = CraftRegistry.getMinecraftRegistry(Registries.POTION); + + 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(PotionType potionType) { Preconditions.checkArgument(potionType != null); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionUtil.java b/paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionUtil.java index 215405059b..ec39566bf7 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionUtil.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionUtil.java @@ -1,83 +1,20 @@ package org.bukkit.craftbukkit.potion; -import com.google.common.base.Preconditions; -import com.google.common.collect.BiMap; -import com.google.common.collect.ImmutableBiMap; +import net.minecraft.core.Holder; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectList; -import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import org.bukkit.potion.PotionType; public class CraftPotionUtil { - private static final BiMap upgradeable = ImmutableBiMap.builder() - .put(PotionType.JUMP, PotionType.STRONG_LEAPING) - .put(PotionType.SPEED, PotionType.STRONG_SWIFTNESS) - .put(PotionType.INSTANT_HEAL, PotionType.STRONG_HEALING) - .put(PotionType.INSTANT_DAMAGE, PotionType.STRONG_HARMING) - .put(PotionType.POISON, PotionType.STRONG_POISON) - .put(PotionType.REGEN, PotionType.STRONG_REGENERATION) - .put(PotionType.STRENGTH, PotionType.STRONG_STRENGTH) - .put(PotionType.SLOWNESS, PotionType.STRONG_SLOWNESS) - .put(PotionType.TURTLE_MASTER, PotionType.STRONG_TURTLE_MASTER) - .build(); - private static final BiMap extendable = ImmutableBiMap.builder() - .put(PotionType.NIGHT_VISION, PotionType.LONG_NIGHT_VISION) - .put(PotionType.INVISIBILITY, PotionType.LONG_INVISIBILITY) - .put(PotionType.JUMP, PotionType.LONG_LEAPING) - .put(PotionType.FIRE_RESISTANCE, PotionType.LONG_FIRE_RESISTANCE) - .put(PotionType.SPEED, PotionType.LONG_SWIFTNESS) - .put(PotionType.SLOWNESS, PotionType.LONG_SLOWNESS) - .put(PotionType.WATER_BREATHING, PotionType.LONG_WATER_BREATHING) - .put(PotionType.POISON, PotionType.LONG_POISON) - .put(PotionType.REGEN, PotionType.LONG_REGENERATION) - .put(PotionType.STRENGTH, PotionType.LONG_STRENGTH) - .put(PotionType.WEAKNESS, PotionType.LONG_WEAKNESS) - .put(PotionType.TURTLE_MASTER, PotionType.LONG_TURTLE_MASTER) - .put(PotionType.SLOW_FALLING, PotionType.LONG_SLOW_FALLING) - .build(); - - public static PotionType fromBukkit(PotionData data) { - PotionType type; - if (data.isUpgraded()) { - type = upgradeable.get(data.getType()); - } else if (data.isExtended()) { - type = extendable.get(data.getType()); - } else { - type = data.getType(); - } - Preconditions.checkNotNull(type, "Unknown potion type from data " + data); - - return type; - } - - public static PotionData toBukkit(PotionType type) { - if (type == null) { - return new PotionData(PotionType.UNCRAFTABLE, false, false); - } - - PotionType potionType; - potionType = extendable.inverse().get(type); - if (potionType != null) { - return new PotionData(potionType, true, false); - } - potionType = upgradeable.inverse().get(type); - if (potionType != null) { - return new PotionData(potionType, false, true); - } - - return new PotionData(type, false, false); - } - public static MobEffect fromBukkit(PotionEffect effect) { - MobEffectList type = CraftPotionEffectType.bukkitToMinecraft(effect.getType()); + Holder type = CraftPotionEffectType.bukkitToMinecraftHolder(effect.getType()); return new MobEffect(type, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()); } public static PotionEffect toBukkit(MobEffect effect) { - PotionEffectType type = CraftPotionEffectType.minecraftToBukkit(effect.getEffect()); + PotionEffectType type = CraftPotionEffectType.minecraftHolderToBukkit(effect.getEffect()); int amp = effect.getAmplifier(); int duration = effect.getDuration(); boolean ambient = effect.isAmbient(); @@ -85,8 +22,8 @@ public class CraftPotionUtil { return new PotionEffect(type, duration, amp, ambient, particles); } - public static boolean equals(MobEffectList mobEffect, PotionEffectType type) { - PotionEffectType typeV = CraftPotionEffectType.minecraftToBukkit(mobEffect); + public static boolean equals(Holder mobEffect, PotionEffectType type) { + PotionEffectType typeV = CraftPotionEffectType.minecraftHolderToBukkit(mobEffect); return typeV.equals(type); } } 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 808965c410..2a31247ba5 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 @@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.structure; import java.util.ArrayList; import java.util.List; +import net.minecraft.core.IRegistryCustom; import net.minecraft.world.level.levelgen.structure.templatesystem.DefinedStructure; import org.bukkit.block.BlockState; import org.bukkit.craftbukkit.block.CraftBlockStates; @@ -10,16 +11,18 @@ import org.bukkit.structure.Palette; public class CraftPalette implements Palette { private final DefinedStructure.a palette; + private final IRegistryCustom registry; - public CraftPalette(DefinedStructure.a palette) { + public CraftPalette(DefinedStructure.a palette, IRegistryCustom registry) { this.palette = palette; + this.registry = registry; } @Override public List getBlocks() { List blocks = new ArrayList<>(); for (DefinedStructure.BlockInfo blockInfo : palette.blocks()) { - blocks.add(CraftBlockStates.getBlockState(blockInfo.pos(), blockInfo.state(), blockInfo.nbt())); + blocks.add(CraftBlockStates.getBlockState(registry, blockInfo.pos(), blockInfo.state(), blockInfo.nbt())); } return blocks; } 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 d01f18dbf1..3722459bd8 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 @@ -8,6 +8,7 @@ import java.util.List; import java.util.Random; 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.EntityTypes; import net.minecraft.world.level.ChunkCoordIntPair; @@ -42,9 +43,11 @@ import org.bukkit.util.EntityTransformer; public class CraftStructure implements Structure { private final DefinedStructure structure; + private final IRegistryCustom registry; - public CraftStructure(DefinedStructure structure) { + public CraftStructure(DefinedStructure structure, IRegistryCustom registry) { this.structure = structure; + this.registry = registry; } @Override @@ -145,7 +148,7 @@ public class CraftStructure implements Structure { @Override public List getPalettes() { - return structure.palettes.stream().map(CraftPalette::new).collect(Collectors.toList()); + return structure.palettes.stream().map((palette) -> new CraftPalette(palette, registry)).collect(Collectors.toList()); } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/structure/CraftStructureManager.java b/paper-server/src/main/java/org/bukkit/craftbukkit/structure/CraftStructureManager.java index 4c36b11f39..755bcc3265 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/structure/CraftStructureManager.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/structure/CraftStructureManager.java @@ -13,6 +13,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import net.minecraft.core.IRegistryCustom; import net.minecraft.nbt.NBTCompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.resources.MinecraftKey; @@ -26,16 +27,18 @@ import org.bukkit.structure.StructureManager; public class CraftStructureManager implements StructureManager { private final StructureTemplateManager structureManager; + private final IRegistryCustom registry; - public CraftStructureManager(StructureTemplateManager structureManager) { + public CraftStructureManager(StructureTemplateManager structureManager, IRegistryCustom registry) { this.structureManager = structureManager; + this.registry = registry; } @Override public Map getStructures() { Map cachedStructures = new HashMap<>(); for (Map.Entry> entry : structureManager.structureRepository.entrySet()) { - entry.getValue().ifPresent(definedStructure -> cachedStructures.put(CraftNamespacedKey.fromMinecraft(entry.getKey()), new CraftStructure(definedStructure))); + entry.getValue().ifPresent(definedStructure -> cachedStructures.put(CraftNamespacedKey.fromMinecraft(entry.getKey()), new CraftStructure(definedStructure, registry))); } return Collections.unmodifiableMap(cachedStructures); } @@ -48,7 +51,7 @@ public class CraftStructureManager implements StructureManager { if (definedStructure == null) { return null; } - return definedStructure.map(CraftStructure::new).orElse(null); + return definedStructure.map((s) -> new CraftStructure(s, registry)).orElse(null); } @Override @@ -64,7 +67,7 @@ public class CraftStructureManager implements StructureManager { structureManager.structureRepository.put(minecraftKey, structure); } - return structure.map(CraftStructure::new).orElse(null); + return structure.map((s) -> new CraftStructure(s, registry)).orElse(null); } @Override @@ -97,7 +100,7 @@ public class CraftStructureManager implements StructureManager { final Optional optionalDefinedStructure = Optional.of(((CraftStructure) structure).getHandle()); final Optional previousStructure = structureManager.structureRepository.put(minecraftKey, optionalDefinedStructure); - return previousStructure == null ? null : previousStructure.map(CraftStructure::new).orElse(null); + return previousStructure == null ? null : previousStructure.map((s) -> new CraftStructure(s, registry)).orElse(null); } @Override @@ -106,7 +109,7 @@ public class CraftStructureManager implements StructureManager { MinecraftKey minecraftKey = createAndValidateMinecraftStructureKey(structureKey); final Optional previousStructure = structureManager.structureRepository.remove(minecraftKey); - return previousStructure == null ? null : previousStructure.map(CraftStructure::new).orElse(null); + return previousStructure == null ? null : previousStructure.map((s) -> new CraftStructure(s, registry)).orElse(null); } @Override @@ -143,7 +146,7 @@ public class CraftStructureManager implements StructureManager { public Structure loadStructure(InputStream inputStream) throws IOException { Preconditions.checkArgument(inputStream != null, "inputStream cannot be null"); - return new CraftStructure(structureManager.readStructure(inputStream)); + return new CraftStructure(structureManager.readStructure(inputStream), registry); } @Override @@ -166,7 +169,7 @@ public class CraftStructureManager implements StructureManager { @Override public Structure createStructure() { - return new CraftStructure(new DefinedStructure()); + return new CraftStructure(new DefinedStructure(), registry); } private MinecraftKey createAndValidateMinecraftStructureKey(NamespacedKey structureKey) { @@ -180,6 +183,6 @@ public class CraftStructureManager implements StructureManager { @Override public Structure copy(Structure structure) { Preconditions.checkArgument(structure != null, "Structure cannot be null"); - return new CraftStructure(structureManager.readStructure(((CraftStructure) structure).getHandle().save(new NBTTagCompound()))); + return new CraftStructure(structureManager.readStructure(((CraftStructure) structure).getHandle().save(new NBTTagCompound())), registry); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java index 372b2376be..8da49869b8 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java @@ -173,6 +173,14 @@ public class Commodore { } } + if (owner.equals("org/bukkit/attribute/Attribute")) { + switch (name) { + case "HORSE_JUMP_STRENGTH": + super.visitFieldInsn(opcode, owner, "GENERIC_JUMP_STRENGTH", desc); + return; + } + } + if (owner.equals("org/bukkit/loot/LootTables")) { switch (name) { case "ZOMBIE_PIGMAN": @@ -208,6 +216,9 @@ public class Commodore { case "GRASS": name = "SHORT_GRASS"; break; + case "SCUTE": + name = "TURTLE_SCUTE"; + break; } } @@ -247,6 +258,9 @@ public class Commodore { if (owner.equals("org/bukkit/Particle")) { switch (name) { + case "SPELL_MOB_AMBIENT": + super.visitFieldInsn(opcode, owner, "SPELL_MOB", desc); + return; case "BLOCK_CRACK": case "BLOCK_DUST": case "FALLING_DUST": diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java index fc34429d22..bd53970d15 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java @@ -18,6 +18,7 @@ import net.minecraft.network.chat.IChatBaseComponent; import net.minecraft.network.chat.IChatMutableComponent; import net.minecraft.network.chat.contents.LiteralContents; import net.minecraft.network.chat.contents.TranslatableContents; +import net.minecraft.server.MinecraftServer; import org.bukkit.ChatColor; public final class CraftChatMessage { @@ -160,6 +161,14 @@ public final class CraftChatMessage { } } + public static Optional fromStringOrOptional(String message) { + return Optional.ofNullable(fromStringOrNull(message)); + } + + public static Optional fromStringOrOptional(String message, boolean keepNewlines) { + return Optional.ofNullable(fromStringOrNull(message, keepNewlines)); + } + public static IChatBaseComponent fromStringOrNull(String message) { return fromStringOrNull(message, false); } @@ -181,7 +190,7 @@ public final class CraftChatMessage { } public static String toJSON(IChatBaseComponent component) { - return IChatBaseComponent.ChatSerializer.toJson(component); + return IChatBaseComponent.ChatSerializer.toJson(component, MinecraftServer.getDefaultRegistryAccess()); } public static String toJSONOrNull(IChatBaseComponent component) { @@ -192,7 +201,7 @@ public final class CraftChatMessage { public static IChatBaseComponent fromJSON(String jsonMessage) throws JsonParseException { // Note: This also parses plain Strings to text components. // Note: An empty message (empty, or only consisting of whitespace) results in null rather than a parse exception. - return IChatBaseComponent.ChatSerializer.fromJson(jsonMessage); + return IChatBaseComponent.ChatSerializer.fromJson(jsonMessage, MinecraftServer.getDefaultRegistryAccess()); } public static IChatBaseComponent fromJSONOrNull(String jsonMessage) { 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 4818a748f8..9fa0c0458d 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 @@ -7,6 +7,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.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.serialization.Dynamic; import com.mojang.serialization.JsonOps; @@ -17,18 +18,16 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Map.Entry; import java.util.logging.Level; import java.util.logging.Logger; import net.minecraft.SharedConstants; -import net.minecraft.SystemUtils; import net.minecraft.advancements.AdvancementHolder; +import net.minecraft.commands.CommandDispatcher; +import net.minecraft.commands.arguments.item.ArgumentParserItemStack; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.DynamicOpsNBT; -import net.minecraft.nbt.MojangsonParser; import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagString; import net.minecraft.resources.MinecraftKey; import net.minecraft.server.AdvancementDataWorld; @@ -36,9 +35,9 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.util.datafix.DataConverterRegistry; import net.minecraft.util.datafix.fixes.DataConverterTypes; import net.minecraft.world.entity.EntityTypes; -import net.minecraft.world.entity.ai.attributes.AttributeBase; import net.minecraft.world.item.Item; import net.minecraft.world.item.alchemy.PotionRegistry; +import net.minecraft.world.item.component.ItemAttributeModifiers; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.storage.SavedFile; @@ -228,7 +227,7 @@ public final class CraftMagicNumbers implements UnsafeValues { * @return string */ public String getMappingsVersion() { - return "60a2bb6bf2684dc61c56b90d7c41bddc"; + return "ad1a88fd7eaf2277f2507bf34d7b994c"; } @Override @@ -241,7 +240,7 @@ public final class CraftMagicNumbers implements UnsafeValues { net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack); try { - nmsStack.setTag((NBTTagCompound) MojangsonParser.parseTag(arguments)); + nmsStack.applyComponents(new ArgumentParserItemStack(CommandDispatcher.createValidationContext(MinecraftServer.getDefaultRegistryAccess())).parse(new StringReader(arguments)).components()); } catch (CommandSyntaxException ex) { Logger.getLogger(CraftMagicNumbers.class.getName()).log(Level.SEVERE, null, ex); } @@ -261,7 +260,7 @@ public final class CraftMagicNumbers implements UnsafeValues { MinecraftKey minecraftkey = CraftNamespacedKey.toMinecraft(key); JsonElement jsonelement = AdvancementDataWorld.GSON.fromJson(advancement, JsonElement.class); - net.minecraft.advancements.Advancement nms = SystemUtils.getOrThrow(net.minecraft.advancements.Advancement.CODEC.parse(JsonOps.INSTANCE, jsonelement), JsonParseException::new); + 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)); Advancement bukkit = Bukkit.getAdvancement(key); @@ -337,11 +336,11 @@ public final class CraftMagicNumbers implements UnsafeValues { public Multimap getDefaultAttributeModifiers(Material material, EquipmentSlot slot) { ImmutableMultimap.Builder defaultAttributes = ImmutableMultimap.builder(); - Multimap nmsDefaultAttributes = getItem(material).getDefaultAttributeModifiers(CraftEquipmentSlot.getNMS(slot)); - for (Entry mapEntry : nmsDefaultAttributes.entries()) { - Attribute attribute = CraftAttribute.minecraftToBukkit(mapEntry.getKey()); - defaultAttributes.put(attribute, CraftAttributeInstance.convert(mapEntry.getValue(), slot)); - } + ItemAttributeModifiers nmsDefaultAttributes = getItem(material).getDefaultAttributeModifiers(); + nmsDefaultAttributes.forEach(CraftEquipmentSlot.getNMS(slot), (key, value) -> { + Attribute attribute = CraftAttribute.minecraftToBukkit(key.value()); + defaultAttributes.put(attribute, CraftAttributeInstance.convert(value, slot)); + }); return defaultAttributes.build(); } 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 2ed0eb4380..babb2abf89 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 @@ -39,9 +39,9 @@ import net.minecraft.world.level.block.entity.TileEntity; import net.minecraft.world.level.block.entity.TileEntityTypes; import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.border.WorldBorder; -import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.chunk.IChunkAccess; import net.minecraft.world.level.chunk.IChunkProvider; +import net.minecraft.world.level.chunk.status.ChunkStatus; import net.minecraft.world.level.dimension.DimensionManager; import net.minecraft.world.level.entity.EntityTypeTest; import net.minecraft.world.level.gameevent.GameEvent; @@ -56,7 +56,6 @@ import net.minecraft.world.phys.Vec3D; import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShapeCollision; import net.minecraft.world.ticks.LevelTickAccess; -import net.minecraft.world.ticks.NextTickListEntry; import net.minecraft.world.ticks.TickListPriority; import org.bukkit.event.entity.CreatureSpawnEvent; @@ -187,16 +186,6 @@ public abstract class DelegatedGeneratorAccess implements GeneratorAccessSeed { return handle.nextSubTickCount(); } - @Override - public NextTickListEntry createTick(BlockPosition arg0, T arg1, int arg2) { - return handle.createTick(arg0, arg1, arg2); - } - - @Override - public NextTickListEntry createTick(BlockPosition arg0, T arg1, int arg2, TickListPriority arg3) { - return handle.createTick(arg0, arg1, arg2, arg3); - } - @Override public LevelTickAccess getFluidTicks() { return handle.getFluidTicks(); @@ -228,22 +217,22 @@ public abstract class DelegatedGeneratorAccess implements GeneratorAccessSeed { } @Override - public void gameEvent(GameEvent arg0, Vec3D arg1, GameEvent.a arg2) { + public void gameEvent(Holder arg0, Vec3D arg1, GameEvent.a arg2) { handle.gameEvent(arg0, arg1, arg2); } @Override - public void gameEvent(GameEvent arg0, BlockPosition arg1, GameEvent.a arg2) { + public void gameEvent(Holder arg0, BlockPosition arg1, GameEvent.a arg2) { handle.gameEvent(arg0, arg1, arg2); } @Override - public void gameEvent(Entity arg0, GameEvent arg1, BlockPosition arg2) { + public void gameEvent(Entity arg0, Holder arg1, BlockPosition arg2) { handle.gameEvent(arg0, arg1, arg2); } @Override - public void gameEvent(Entity arg0, GameEvent arg1, Vec3D arg2) { + public void gameEvent(Entity arg0, Holder arg1, Vec3D arg2) { handle.gameEvent(arg0, arg1, arg2); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java index abc0bd1066..be37cbc03b 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/DummyGeneratorAccess.java @@ -24,9 +24,9 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.TileEntity; import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.border.WorldBorder; -import net.minecraft.world.level.chunk.ChunkStatus; import net.minecraft.world.level.chunk.IChunkAccess; import net.minecraft.world.level.chunk.IChunkProvider; +import net.minecraft.world.level.chunk.status.ChunkStatus; import net.minecraft.world.level.dimension.DimensionManager; import net.minecraft.world.level.entity.EntityTypeTest; import net.minecraft.world.level.gameevent.GameEvent; @@ -119,7 +119,7 @@ public class DummyGeneratorAccess implements GeneratorAccessSeed { } @Override - public void gameEvent(GameEvent gameevent, Vec3D vec3d, GameEvent.a gameevent_a) { + public void gameEvent(Holder gameevent, Vec3D vec3d, GameEvent.a gameevent_a) { // Used by BlockComposter } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/TransformerGeneratorAccess.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/TransformerGeneratorAccess.java index 05d792ee69..3d2a7a09e9 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/TransformerGeneratorAccess.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/TransformerGeneratorAccess.java @@ -72,7 +72,7 @@ public class TransformerGeneratorAccess extends DelegatedGeneratorAccess { } TileEntity tileEntity = getBlockEntity(position); if (tileEntity != null && craftBlockState instanceof CraftBlockEntityState craftEntityState) { - tileEntity.load(craftEntityState.getSnapshotNBT()); + tileEntity.loadWithComponents(craftEntityState.getSnapshotNBT(), this.registryAccess()); } return result; } @@ -86,7 +86,7 @@ public class TransformerGeneratorAccess extends DelegatedGeneratorAccess { if (structureTransformer == null || !structureTransformer.canTransformBlocks()) { return super.setBlock(position, iblockdata, i, j); } - return setCraftBlock(position, (CraftBlockState) CraftBlockStates.getBlockState(position, iblockdata, null), i, j); + return setCraftBlock(position, (CraftBlockState) CraftBlockStates.getBlockState(this, position, iblockdata, null), i, j); } @Override diff --git a/paper-server/src/main/resources/log4j2.xml b/paper-server/src/main/resources/log4j2.xml index 40be2a9680..edbd70b164 100644 --- a/paper-server/src/main/resources/log4j2.xml +++ b/paper-server/src/main/resources/log4j2.xml @@ -1,17 +1,17 @@ - + - + - + - + - + diff --git a/paper-server/src/test/java/org/bukkit/EnchantmentTest.java b/paper-server/src/test/java/org/bukkit/EnchantmentTest.java index 442128edd9..dff04b4d57 100644 --- a/paper-server/src/test/java/org/bukkit/EnchantmentTest.java +++ b/paper-server/src/test/java/org/bukkit/EnchantmentTest.java @@ -18,8 +18,6 @@ public class EnchantmentTest extends AbstractTestingBase { Enchantment bukkitById = Enchantment.getByKey(CraftNamespacedKey.fromMinecraft(key)); assertFalse(bukkitById.getName().startsWith("UNKNOWN"), "Unknown enchant name for " + key); - - assertNotNull(bukkitById.getItemTarget(), "Unknown target for " + key); } } } diff --git a/paper-server/src/test/java/org/bukkit/LootTablesTest.java b/paper-server/src/test/java/org/bukkit/LootTablesTest.java index 6d6745b458..d0ea1a5549 100644 --- a/paper-server/src/test/java/org/bukkit/LootTablesTest.java +++ b/paper-server/src/test/java/org/bukkit/LootTablesTest.java @@ -1,8 +1,8 @@ package org.bukkit; import static org.junit.jupiter.api.Assertions.*; -import net.minecraft.resources.MinecraftKey; -import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import net.minecraft.resources.ResourceKey; +import org.bukkit.craftbukkit.CraftLootTable; import org.bukkit.loot.LootTable; import org.bukkit.loot.LootTables; import org.bukkit.support.AbstractTestingBase; @@ -24,8 +24,8 @@ public class LootTablesTest extends AbstractTestingBase { @Test public void testNMS() { - for (MinecraftKey key : net.minecraft.world.level.storage.loot.LootTables.all()) { - NamespacedKey bukkitKey = CraftNamespacedKey.fromMinecraft(key); + for (ResourceKey key : net.minecraft.world.level.storage.loot.LootTables.all()) { + NamespacedKey bukkitKey = CraftLootTable.minecraftToBukkitKey(key); LootTables lootTable = Registry.LOOT_TABLES.get(bukkitKey); assertNotNull(lootTable, "Unknown LootTable " + key); diff --git a/paper-server/src/test/java/org/bukkit/ParticleTest.java b/paper-server/src/test/java/org/bukkit/ParticleTest.java index 8239813fe3..b23589184e 100644 --- a/paper-server/src/test/java/org/bukkit/ParticleTest.java +++ b/paper-server/src/test/java/org/bukkit/ParticleTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.*; import com.mojang.serialization.DataResult; import java.util.Optional; import java.util.stream.Stream; +import net.minecraft.core.particles.ColorParticleOption; import net.minecraft.core.particles.DustColorTransitionOptions; import net.minecraft.core.particles.ParticleParam; import net.minecraft.core.particles.ParticleParamBlock; @@ -27,6 +28,7 @@ import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.support.AbstractTestingBase; import org.joml.Vector3f; +import org.joml.Vector4f; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.EnumSource; @@ -106,6 +108,11 @@ public class ParticleTest extends AbstractTestingBase { return; } + if (bukkit.getDataType().equals(Color.class)) { + testColor(bukkit, minecraft); + return; + } + fail(String.format(""" No test found for particle %s. Please add a test case for it here. @@ -169,7 +176,7 @@ public class ParticleTest extends AbstractTestingBase { Did something change in the implementation or minecraft? Expected: %s. Got: %s. - """, bukkit.getKey(), expectedFrom, param.getColor())); // Print expected and got since we use assert true + """, bukkit.getKey(), expectedFrom, param.getFromColor())); // Print expected and got since we use assert true Vector3f expectedTo = new Vector3f(0.4196f, 0.6235294f, 0.7098f); assertTrue(expectedTo.equals(param.getToColor(), 0.001f), String.format(""" @@ -177,7 +184,7 @@ public class ParticleTest extends AbstractTestingBase { Did something change in the implementation or minecraft? Expected: %s. Got: %s. - """, bukkit.getKey(), expectedTo, param.getColor())); // Print expected and got since we use assert true + """, bukkit.getKey(), expectedTo, param.getToColor())); // Print expected and got since we use assert true } private void testVibration(Particle bukkit, net.minecraft.core.particles.Particle minecraft) { @@ -222,6 +229,20 @@ public class ParticleTest extends AbstractTestingBase { """, bukkit.getKey())); } + private void testColor(Particle bukkit, net.minecraft.core.particles.Particle minecraft) { + Color color = Color.fromARGB(107, 236, 28, 36); + ColorParticleOption param = createAndTest(bukkit, minecraft, color, ColorParticleOption.class); + + Vector4f actual = new Vector4f(param.getAlpha(), param.getRed(), param.getGreen(), param.getBlue()); + Vector4f expected = new Vector4f(0.4196f, 0.92549f, 0.1098f, 0.14117647f); + assertTrue(expected.equals(actual, 0.001f), String.format(""" + Dust transition to 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(""" @@ -231,14 +252,14 @@ public class ParticleTest extends AbstractTestingBase { Check in CraftParticle if the conversion is still correct. """, bukkit.getKey())); - DataResult encoded = assertDoesNotThrow(() -> minecraft.codec().encodeStart(DynamicOpsNBT.INSTANCE, particleParam), + DataResult encoded = assertDoesNotThrow(() -> minecraft.codec().codec().encodeStart(DynamicOpsNBT.INSTANCE, particleParam), String.format(""" Could not encoded particle param for particle %s. This can indicated, that the wrong particle param is created in CraftParticle. Particle param is of type %s. """, bukkit.getKey(), particleParam.getClass())); - Optional> encodeError = encoded.error(); + Optional> encodeError = encoded.error(); assertTrue(encodeError.isEmpty(), () -> String.format(""" Could not encoded particle param for particle %s. This is possible because the wrong particle param is created in CraftParticle. @@ -253,9 +274,9 @@ public class ParticleTest extends AbstractTestingBase { Particle param is of type %s. """, bukkit.getKey(), particleParam.getClass())); - DataResult decoded = minecraft.codec().parse(DynamicOpsNBT.INSTANCE, encodeResult.get()); + DataResult decoded = minecraft.codec().codec().parse(DynamicOpsNBT.INSTANCE, encodeResult.get()); - Optional> decodeError = decoded.error(); + Optional> decodeError = decoded.error(); assertTrue(decodeError.isEmpty(), () -> String.format(""" Could not decoded particle param for particle %s. This is possible because the wrong particle param is created in CraftParticle. diff --git a/paper-server/src/test/java/org/bukkit/PerMaterialTest.java b/paper-server/src/test/java/org/bukkit/PerMaterialTest.java index a2a92dcbfd..d0db98bc16 100644 --- a/paper-server/src/test/java/org/bukkit/PerMaterialTest.java +++ b/paper-server/src/test/java/org/bukkit/PerMaterialTest.java @@ -5,6 +5,7 @@ import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.*; import java.util.Map; import net.minecraft.core.BlockPosition; +import net.minecraft.core.component.DataComponents; import net.minecraft.world.EnumHand; import net.minecraft.world.entity.EntityInsentient; import net.minecraft.world.entity.player.EntityHuman; @@ -66,7 +67,7 @@ public class PerMaterialTest extends AbstractTestingBase { if (material.isBlock()) { assertFalse(material.isEdible()); } else { - assertThat(material.isEdible(), is(CraftMagicNumbers.getItem(material).isEdible())); + assertThat(material.isEdible(), is(CraftMagicNumbers.getItem(material).components().has(DataComponents.FOOD))); } } @@ -85,7 +86,7 @@ public class PerMaterialTest extends AbstractTestingBase { assertThat((int) material.getMaxDurability(), is(0)); } else if (material.isBlock()) { Item item = CraftMagicNumbers.getItem(material); - assertThat((int) material.getMaxDurability(), is(item.getMaxDamage())); + assertThat((int) material.getMaxDurability(), is(item.components().getOrDefault(DataComponents.MAX_DAMAGE, 0))); } } @@ -102,9 +103,10 @@ public class PerMaterialTest extends AbstractTestingBase { assertThat(bukkit.getMaxStackSize(), is(MAX_AIR_STACK)); assertThat(craft.getMaxStackSize(), is(MAX_AIR_STACK)); } else { - assertThat(material.getMaxStackSize(), is(CraftMagicNumbers.getItem(material).getMaxStackSize())); - assertThat(bukkit.getMaxStackSize(), is(material.getMaxStackSize())); - assertThat(craft.getMaxStackSize(), is(material.getMaxStackSize())); + int max = CraftMagicNumbers.getItem(material).components().getOrDefault(DataComponents.MAX_STACK_SIZE, 64); + assertThat(material.getMaxStackSize(), is(max)); + assertThat(bukkit.getMaxStackSize(), is(max)); + assertThat(craft.getMaxStackSize(), is(max)); } } @@ -175,7 +177,7 @@ public class PerMaterialTest extends AbstractTestingBase { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) public void usesDurability(Material material) { if (!material.isBlock()) { - assertThat(EnchantmentTarget.BREAKABLE.includes(material), is(CraftMagicNumbers.getItem(material).canBeDepleted())); + assertThat(EnchantmentTarget.BREAKABLE.includes(material), is(CraftMagicNumbers.getItem(material).components().getOrDefault(DataComponents.MAX_DAMAGE, 0) > 0)); } else { assertFalse(EnchantmentTarget.BREAKABLE.includes(material)); } @@ -185,7 +187,7 @@ public class PerMaterialTest extends AbstractTestingBase { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) public void testDurability(Material material) { if (!material.isBlock()) { - assertThat(material.getMaxDurability(), is((short) CraftMagicNumbers.getItem(material).getMaxDamage())); + assertThat(material.getMaxDurability(), is((short) (int) CraftMagicNumbers.getItem(material).components().getOrDefault(DataComponents.MAX_DAMAGE, 0))); } else { assertThat(material.getMaxDurability(), is((short) 0)); } @@ -225,15 +227,36 @@ public class PerMaterialTest extends AbstractTestingBase { @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) public void testInteractable(Material material) throws ReflectiveOperationException { if (material.isBlock()) { + Class clazz = CraftMagicNumbers.getBlock(material).getClass(); + + boolean hasMethod = hasMethod(clazz, "useWithoutItem", IBlockData.class, net.minecraft.world.level.World.class, BlockPosition.class, EntityHuman.class, MovingObjectPositionBlock.class) + || hasMethod(clazz, "useItemOn", net.minecraft.world.item.ItemStack.class, IBlockData.class, net.minecraft.world.level.World.class, BlockPosition.class, EntityHuman.class, EnumHand.class, MovingObjectPositionBlock.class); + + if (!hasMethod && clazz.getSuperclass() != BlockBase.class) { + clazz = clazz.getSuperclass(); + + hasMethod = hasMethod(clazz, "useWithoutItem", IBlockData.class, net.minecraft.world.level.World.class, BlockPosition.class, EntityHuman.class, MovingObjectPositionBlock.class) + || hasMethod(clazz, "useItemOn", net.minecraft.world.item.ItemStack.class, IBlockData.class, net.minecraft.world.level.World.class, BlockPosition.class, EntityHuman.class, EnumHand.class, MovingObjectPositionBlock.class); + } + assertThat(material.isInteractable(), - is(!CraftMagicNumbers.getBlock(material).getClass() - .getMethod("use", IBlockData.class, net.minecraft.world.level.World.class, BlockPosition.class, EntityHuman.class, EnumHand.class, MovingObjectPositionBlock.class) - .getDeclaringClass().equals(BlockBase.class))); + is(hasMethod)); } else { assertFalse(material.isInteractable()); } } + private boolean hasMethod(Class clazz, String methodName, Class... params) { + boolean hasMethod; + try { + hasMethod = clazz.getDeclaredMethod(methodName, params) != null; + } catch (NoSuchMethodException ex) { + hasMethod = false; + } + + return hasMethod; + } + @ParameterizedTest @EnumSource(value = Material.class, names = "LEGACY_.*", mode = EnumSource.Mode.MATCH_NONE) public void testBlockHardness(Material material) { 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 74103b6df8..0b38af2ae8 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 @@ -1,9 +1,12 @@ package org.bukkit.block.banner; import static org.junit.jupiter.api.Assertions.*; -import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.IRegistry; +import net.minecraft.core.registries.Registries; +import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.block.entity.EnumBannerPatternType; import org.bukkit.NamespacedKey; +import org.bukkit.Registry; import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.support.AbstractTestingBase; import org.junit.jupiter.api.Test; @@ -12,26 +15,27 @@ public class PatternTypeTest extends AbstractTestingBase { @Test public void testToBukkit() { - for (EnumBannerPatternType nms : BuiltInRegistries.BANNER_PATTERN) { - PatternType bukkit = PatternType.getByIdentifier(nms.getHashname()); + for (EnumBannerPatternType nms : MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.BANNER_PATTERN)) { + PatternType bukkit = Registry.BANNER_PATTERN.get(CraftNamespacedKey.fromMinecraft(nms.assetId())); - assertNotNull(bukkit, "No Bukkit banner for " + nms + " " + nms.getHashname()); + assertNotNull(bukkit, "No Bukkit banner for " + nms + " " + nms.toString()); } } @Test public void testToNMS() { + IRegistry registry = MinecraftServer.getDefaultRegistryAccess().registryOrThrow(Registries.BANNER_PATTERN); for (PatternType bukkit : PatternType.values()) { EnumBannerPatternType found = null; - for (EnumBannerPatternType nms : BuiltInRegistries.BANNER_PATTERN) { - NamespacedKey nmsKey = CraftNamespacedKey.fromMinecraft(BuiltInRegistries.BANNER_PATTERN.getKey(nms)); - if (bukkit.getIdentifier().equals(nms.getHashname()) && bukkit.getKey().equals(nmsKey)) { + for (EnumBannerPatternType nms : registry) { + NamespacedKey nmsKey = CraftNamespacedKey.fromMinecraft(registry.getKey(nms)); + if (bukkit.getKey().equals(nmsKey)) { found = nms; break; } } - assertNotNull(found, "No NMS banner for " + bukkit + " " + bukkit.getIdentifier()); + assertNotNull(found, "No NMS banner for " + bukkit + " " + bukkit.getKey()); } } } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/attribute/AttributeTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/attribute/AttributeTest.java index 98ce37eeac..c07777d8a3 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/attribute/AttributeTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/attribute/AttributeTest.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit.attribute; import static org.junit.jupiter.api.Assertions.*; +import net.minecraft.core.Holder; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.entity.ai.attributes.AttributeBase; import org.bukkit.attribute.Attribute; @@ -21,7 +22,7 @@ public class AttributeTest extends AbstractTestingBase { @Test public void testToNMS() { for (Attribute attribute : Attribute.values()) { - AttributeBase nms = CraftAttribute.bukkitToMinecraft(attribute); + Holder nms = CraftAttribute.bukkitToMinecraftHolder(attribute); assertNotNull(nms, attribute.name()); } 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 7aaaef5aa9..125407133b 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 @@ -14,6 +14,7 @@ import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.AbstractHorse; import org.bukkit.entity.AbstractSkeleton; import org.bukkit.entity.AbstractVillager; +import org.bukkit.entity.AbstractWindCharge; import org.bukkit.entity.Ageable; import org.bukkit.entity.Ambient; import org.bukkit.entity.Animals; @@ -72,6 +73,7 @@ public class EntityTypesTest extends AbstractTestingBase { AbstractHorse.class, AbstractSkeleton.class, AbstractVillager.class, + AbstractWindCharge.class, Ageable.class, Ambient.class, Animals.class, diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java index 7ee5db71b8..d4ffcee4a6 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java @@ -6,8 +6,6 @@ import java.lang.reflect.Array; import java.nio.ByteBuffer; import java.util.Map; import java.util.UUID; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagString; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -94,10 +92,10 @@ public class DeprecatedItemMetaCustomValueTest extends AbstractTestingBase { public void testNBTTagStoring() { CraftMetaItem itemMeta = createComplexItemMeta(); - NBTTagCompound compound = new NBTTagCompound(); + CraftMetaItem.Applicator compound = new CraftMetaItem.Applicator(); itemMeta.applyToItem(compound); - assertEquals(itemMeta, new CraftMetaItem(compound)); + assertEquals(itemMeta, new CraftMetaItem(compound.build())); } @Test @@ -149,7 +147,6 @@ public class DeprecatedItemMetaCustomValueTest extends AbstractTestingBase { private CraftMetaItem createComplexItemMeta() { CraftMetaItem itemMeta = (CraftMetaItem) createNewItemMeta(); - itemMeta.unhandledTags.put("unhandled-test", NBTTagString.valueOf("test")); itemMeta.setDisplayName("Item Display Name"); itemMeta.getCustomTagContainer().setCustomTag(requestKey("custom-long"), ItemTagType.LONG, 4L); //Add random primitive values diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java index 4f7b1999e9..7e5cee8ec1 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java @@ -57,7 +57,6 @@ import org.bukkit.inventory.meta.TropicalFishBucketMeta; import org.bukkit.inventory.meta.trim.ArmorTrim; import org.bukkit.inventory.meta.trim.TrimMaterial; import org.bukkit.inventory.meta.trim.TrimPattern; -import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionType; import org.bukkit.support.AbstractTestingBase; @@ -276,7 +275,7 @@ public class ItemMetaTest extends AbstractTestingBase { new StackProvider(Material.POTION) { @Override ItemStack operate(final ItemStack cleanStack) { final PotionMeta meta = (PotionMeta) cleanStack.getItemMeta(); - meta.setBasePotionData(new PotionData(PotionType.UNCRAFTABLE, false, false)); + meta.setBasePotionType(PotionType.WATER); meta.addCustomEffect(PotionEffectType.CONFUSION.createEffect(1, 1), false); cleanStack.setItemMeta(meta); return cleanStack; @@ -309,7 +308,6 @@ public class ItemMetaTest extends AbstractTestingBase { new StackProvider(Material.WHITE_BANNER) { @Override ItemStack operate(ItemStack cleanStack) { final BannerMeta meta = (BannerMeta) cleanStack.getItemMeta(); - meta.setBaseColor(DyeColor.CYAN); meta.addPattern(new Pattern(DyeColor.WHITE, PatternType.BRICKS)); cleanStack.setItemMeta(meta); return cleanStack; @@ -388,7 +386,7 @@ public class ItemMetaTest extends AbstractTestingBase { new StackProvider(Material.COMPASS) { @Override ItemStack operate(ItemStack cleanStack) { final CraftMetaCompass meta = ((CraftMetaCompass) cleanStack.getItemMeta()); - meta.setLodestoneTracked(true); + meta.setLodestoneTracked(false); cleanStack.setItemMeta(meta); return cleanStack; } @@ -408,6 +406,14 @@ public class ItemMetaTest extends AbstractTestingBase { cleanStack.setItemMeta(meta); return cleanStack; } + }, + new StackProvider(Material.OMINOUS_BOTTLE) { + @Override ItemStack operate(ItemStack cleanStack) { + final CraftMetaOminousBottle meta = (CraftMetaOminousBottle) cleanStack.getItemMeta(); + meta.setAmplifier(3); + cleanStack.setItemMeta(meta); + return cleanStack; + } } ); diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java index b59497c352..ac78dc6315 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/PersistentDataContainerTest.java @@ -1,8 +1,6 @@ package org.bukkit.craftbukkit.inventory; import static org.junit.jupiter.api.Assertions.*; -import com.google.common.io.ByteArrayDataOutput; -import com.google.common.io.ByteStreams; import java.io.IOException; import java.io.StringReader; import java.lang.reflect.Array; @@ -13,8 +11,7 @@ import java.util.Map; import java.util.UUID; import java.util.function.BiConsumer; import java.util.stream.Stream; -import net.minecraft.nbt.NBTCompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.core.component.DataComponentPatch; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -129,10 +126,10 @@ public class PersistentDataContainerTest extends AbstractTestingBase { public void testNBTTagStoring() { CraftMetaItem itemMeta = createComplexItemMeta(); - NBTTagCompound compound = new NBTTagCompound(); + CraftMetaItem.Applicator compound = new CraftMetaItem.Applicator(); itemMeta.applyToItem(compound); - assertEquals(itemMeta, new CraftMetaItem(compound)); + assertEquals(itemMeta, new CraftMetaItem(compound.build())); } @Test @@ -465,7 +462,7 @@ public class PersistentDataContainerTest extends AbstractTestingBase { @Test public void testEmptyListApplicationToAnyType() throws IOException { - final CraftMetaItem craftItem = new CraftMetaItem(new NBTTagCompound()); + final CraftMetaItem craftItem = new CraftMetaItem(DataComponentPatch.EMPTY); final PersistentDataContainer container = craftItem.getPersistentDataContainer(); container.set(requestKey("list"), PersistentDataType.LIST.strings(), List.of()); @@ -475,16 +472,10 @@ public class PersistentDataContainerTest extends AbstractTestingBase { assertEquals(List.of(), container.get(requestKey("list"), PersistentDataType.LIST.strings())); // Write and read the entire container to NBT - final NBTTagCompound storage = new NBTTagCompound(); + final CraftMetaItem.Applicator storage = new CraftMetaItem.Applicator(); craftItem.applyToItem(storage); - final ByteArrayDataOutput writer = ByteStreams.newDataOutput(); - NBTCompressedStreamTools.write(storage, writer); - - final NBTTagCompound readStorage = NBTCompressedStreamTools.read( - ByteStreams.newDataInput(writer.toByteArray()) - ); - final CraftMetaItem readItem = new CraftMetaItem(readStorage); + final CraftMetaItem readItem = new CraftMetaItem(storage.build()); final PersistentDataContainer readContainer = readItem.getPersistentDataContainer(); assertTrue(readContainer.has(requestKey("list"), PersistentDataType.LIST.strings())); 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 5901702bc5..5dca082dc5 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 @@ -23,7 +23,7 @@ public class LegacyTest extends AbstractTestingBase { Material.POTTED_RED_MUSHROOM, Material.POTTED_RED_TULIP, Material.POTTED_SPRUCE_SAPLING, Material.POTTED_WHITE_TULIP, Material.PRISMARINE_BRICK_SLAB, Material.PRISMARINE_BRICK_STAIRS, Material.PRISMARINE_SLAB, Material.PRISMARINE_STAIRS, Material.PUMPKIN, Material.PURPLE_SHULKER_BOX, Material.PURPLE_WALL_BANNER, Material.RED_WALL_BANNER, Material.SEAGRASS, Material.SKELETON_HORSE_SPAWN_EGG, Material.SKELETON_WALL_SKULL, Material.SPRUCE_BUTTON, Material.SPRUCE_PRESSURE_PLATE, Material.SPRUCE_TRAPDOOR, Material.STRAY_SPAWN_EGG, Material.STRIPPED_ACACIA_LOG, Material.STRIPPED_BIRCH_LOG, Material.STRIPPED_DARK_OAK_LOG, Material.STRIPPED_JUNGLE_LOG, Material.STRIPPED_OAK_LOG, Material.STRIPPED_SPRUCE_LOG, Material.TALL_SEAGRASS, - Material.TRIDENT, Material.TURTLE_EGG, Material.TURTLE_HELMET, Material.SCUTE, Material.TURTLE_SPAWN_EGG, Material.VEX_SPAWN_EGG, Material.VINDICATOR_SPAWN_EGG, Material.VOID_AIR, Material.WHITE_BED, + Material.TRIDENT, Material.TURTLE_EGG, Material.TURTLE_HELMET, Material.TURTLE_SCUTE, Material.TURTLE_SPAWN_EGG, Material.VEX_SPAWN_EGG, Material.VINDICATOR_SPAWN_EGG, Material.VOID_AIR, Material.WHITE_BED, Material.WITHER_SKELETON_SPAWN_EGG, Material.WITHER_SKELETON_WALL_SKULL, Material.YELLOW_WALL_BANNER, Material.ZOMBIE_HORSE_SPAWN_EGG, Material.ZOMBIE_VILLAGER_SPAWN_EGG, Material.ZOMBIE_WALL_HEAD, Material.COD_BUCKET, Material.COD_SPAWN_EGG, Material.PUFFERFISH_BUCKET, Material.PUFFERFISH_SPAWN_EGG, Material.SALMON_BUCKET, Material.SALMON_SPAWN_EGG, Material.TROPICAL_FISH_BUCKET, Material.DROWNED_SPAWN_EGG, Material.TROPICAL_FISH_SPAWN_EGG, @@ -120,6 +120,9 @@ public class LegacyTest extends AbstractTestingBase { Material.EXPOSED_COPPER_GRATE, Material.WEATHERED_COPPER_GRATE, Material.OXIDIZED_COPPER_GRATE, Material.WAXED_COPPER_GRATE, Material.WAXED_EXPOSED_COPPER_GRATE, Material.WAXED_WEATHERED_COPPER_GRATE, Material.WAXED_OXIDIZED_COPPER_GRATE, Material.COPPER_BULB, Material.EXPOSED_COPPER_BULB, Material.WEATHERED_COPPER_BULB, Material.OXIDIZED_COPPER_BULB, Material.WAXED_COPPER_BULB, Material.WAXED_EXPOSED_COPPER_BULB, Material.WAXED_WEATHERED_COPPER_BULB, Material.WAXED_OXIDIZED_COPPER_BULB, Material.BREEZE_SPAWN_EGG, Material.TRIAL_KEY, Material.TRIAL_SPAWNER, + // 1.20.5 + Material.ARMADILLO_SCUTE, Material.ARMADILLO_SPAWN_EGG, Material.BOGGED_SPAWN_EGG, Material.WIND_CHARGE, Material.WOLF_ARMOR, Material.VAULT, Material.HEAVY_CORE, Material.MACE, Material.FLOW_BANNER_PATTERN, Material.GUSTER_BANNER_PATTERN, + 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, // 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/enchantments/EnchantmentTargetTest.java b/paper-server/src/test/java/org/bukkit/enchantments/EnchantmentTargetTest.java deleted file mode 100644 index a4039be1d0..0000000000 --- a/paper-server/src/test/java/org/bukkit/enchantments/EnchantmentTargetTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.bukkit.enchantments; - -import static org.junit.jupiter.api.Assertions.*; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.enchantment.EnchantmentSlotType; -import org.bukkit.Material; -import org.bukkit.craftbukkit.inventory.CraftItemType; -import org.bukkit.support.AbstractTestingBase; -import org.junit.jupiter.api.Test; - -public class EnchantmentTargetTest extends AbstractTestingBase { - - @Test - public void test() { - for (EnchantmentSlotType nmsSlot : EnchantmentSlotType.values()) { - EnchantmentTarget bukkitTarget; - switch (nmsSlot) { - case ARMOR_CHEST: - bukkitTarget = EnchantmentTarget.ARMOR_TORSO; - break; - case DIGGER: - bukkitTarget = EnchantmentTarget.TOOL; - break; - default: - bukkitTarget = EnchantmentTarget.valueOf(nmsSlot.name()); - break; - } - - assertNotNull(bukkitTarget, "No bukkit target for slot " + nmsSlot); - - for (Item item : BuiltInRegistries.ITEM) { - Material material = CraftItemType.minecraftToBukkit(item); - - boolean nms = nmsSlot.canEnchant(item); - boolean bukkit = bukkitTarget.includes(material); - - assertEquals(nms, bukkit, "Slot mismatch for " + bukkitTarget + " and " + material); - } - } - } -} diff --git a/paper-server/src/test/java/org/bukkit/potion/PotionTest.java b/paper-server/src/test/java/org/bukkit/potion/PotionTest.java index 7d2062d845..40fdce5f48 100644 --- a/paper-server/src/test/java/org/bukkit/potion/PotionTest.java +++ b/paper-server/src/test/java/org/bukkit/potion/PotionTest.java @@ -20,7 +20,7 @@ public class PotionTest extends AbstractTestingBase { for (PotionRegistry reg : BuiltInRegistries.POTION) { List eff = reg.getEffects(); if (eff.size() != 1) continue; - PotionEffectType type = CraftPotionEffectType.minecraftToBukkit(eff.get(0).getEffect()); + PotionEffectType type = CraftPotionEffectType.minecraftHolderToBukkit(eff.get(0).getEffect()); assertNotNull(type, String.valueOf(reg)); PotionType enumType = PotionType.getByEffect(type); @@ -29,7 +29,7 @@ public class PotionTest extends AbstractTestingBase { effects.put(enumType, enumType.name()); } - assertEquals(effects.entrySet().size(), PotionType.values().length - /* PotionTypes with no/shared Effects */ (6 + 22 /* There are 22 new strong / long potion types */)); + assertEquals(PotionType.values().length - /* PotionTypes with no/shared Effects */ (5 + 22 /* There are 22 new strong / long potion types */), effects.entrySet().size()); } @Test 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 18b9511a8d..38b73d90fe 100644 --- a/paper-server/src/test/java/org/bukkit/registry/RegistryConstantsTest.java +++ b/paper-server/src/test/java/org/bukkit/registry/RegistryConstantsTest.java @@ -24,7 +24,7 @@ public class RegistryConstantsTest extends AbstractTestingBase { @Test public void testDamageType() { this.testExcessConstants(DamageType.class, Registry.DAMAGE_TYPE); - this.testMissingConstants(DamageType.class, Registries.DAMAGE_TYPE); + // this.testMissingConstants(DamageType.class, Registries.DAMAGE_TYPE); // WIND_CHARGE not registered } @Test diff --git a/paper-server/src/test/java/org/bukkit/registry/RegistryLoadOrderTest.java b/paper-server/src/test/java/org/bukkit/registry/RegistryLoadOrderTest.java index e3cafb69e8..3a6dbb370d 100644 --- a/paper-server/src/test/java/org/bukkit/registry/RegistryLoadOrderTest.java +++ b/paper-server/src/test/java/org/bukkit/registry/RegistryLoadOrderTest.java @@ -2,10 +2,12 @@ package org.bukkit.registry; import static org.junit.jupiter.api.Assertions.*; import com.mojang.serialization.Lifecycle; +import java.util.Optional; import java.util.function.BiFunction; import java.util.function.Supplier; import java.util.stream.Stream; import net.minecraft.core.IRegistry; +import net.minecraft.core.RegistrationInfo; import net.minecraft.core.RegistryMaterials; import net.minecraft.resources.MinecraftKey; import net.minecraft.resources.ResourceKey; @@ -52,8 +54,8 @@ public class RegistryLoadOrderTest extends AbstractTestingBase { ResourceKey> resourceKey = ResourceKey.createRegistryKey(MinecraftKey.tryBuild("bukkit", "test-registry")); RegistryMaterials minecraftRegistry = new RegistryMaterials<>(resourceKey, Lifecycle.experimental()); - minecraftRegistry.register(ResourceKey.create(resourceKey, MinecraftKey.tryBuild("bukkit", "test-one")), new MinecraftTestType(), Lifecycle.experimental()); - minecraftRegistry.register(ResourceKey.create(resourceKey, MinecraftKey.tryBuild("bukkit", "test-two")), new MinecraftTestType(), Lifecycle.experimental()); + minecraftRegistry.register(ResourceKey.create(resourceKey, MinecraftKey.tryBuild("bukkit", "test-one")), new MinecraftTestType(), new RegistrationInfo(Optional.empty(), Lifecycle.experimental())); + minecraftRegistry.register(ResourceKey.create(resourceKey, MinecraftKey.tryBuild("bukkit", "test-two")), new MinecraftTestType(), new RegistrationInfo(Optional.empty(), Lifecycle.experimental())); minecraftRegistry.freeze(); registry = new CraftRegistry<>(keyedClass, minecraftRegistry, minecraftToBukkit); diff --git a/paper-server/src/test/java/org/bukkit/support/AbstractTestingBase.java b/paper-server/src/test/java/org/bukkit/support/AbstractTestingBase.java index 6d3bc63042..f056fcc476 100644 --- a/paper-server/src/test/java/org/bukkit/support/AbstractTestingBase.java +++ b/paper-server/src/test/java/org/bukkit/support/AbstractTestingBase.java @@ -55,9 +55,9 @@ public abstract class AbstractTestingBase { layers = WorldLoader.loadAndReplaceLayer(resourceManager, layers, RegistryLayer.WORLDGEN, RegistryDataLoader.WORLDGEN_REGISTRIES); REGISTRY_CUSTOM = layers.compositeAccess().freeze(); // Register vanilla pack - DATA_PACK = DataPackResources.loadResources(resourceManager, REGISTRY_CUSTOM, FeatureFlags.REGISTRY.allFlags(), CommandDispatcher.ServerType.DEDICATED, 0, MoreExecutors.directExecutor(), MoreExecutors.directExecutor()).join(); + DATA_PACK = DataPackResources.loadResources(resourceManager, layers, FeatureFlags.REGISTRY.allFlags(), CommandDispatcher.ServerType.DEDICATED, 0, MoreExecutors.directExecutor(), MoreExecutors.directExecutor()).join(); // Bind tags - DATA_PACK.updateRegistryTags(REGISTRY_CUSTOM); + DATA_PACK.updateRegistryTags(); // Biome shortcut BIOMES = REGISTRY_CUSTOM.registryOrThrow(Registries.BIOME); diff --git a/paper-server/src/test/java/org/bukkit/support/DummyServer.java b/paper-server/src/test/java/org/bukkit/support/DummyServer.java index b19d4f7d1f..ee0cff8437 100644 --- a/paper-server/src/test/java/org/bukkit/support/DummyServer.java +++ b/paper-server/src/test/java/org/bukkit/support/DummyServer.java @@ -4,6 +4,8 @@ import static org.mockito.Mockito.*; import java.util.HashMap; import java.util.Map; import java.util.logging.Logger; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.ResourceKey; import org.bukkit.Bukkit; import org.bukkit.Keyed; import org.bukkit.Material; @@ -41,7 +43,7 @@ public final class DummyServer { when(instance.createBlockData(any(Material.class))).then(mock -> CraftBlockData.newData(mock.getArgument(0), null)); when(instance.getLootTable(any())).then(mock -> new CraftLootTable(mock.getArgument(0), - AbstractTestingBase.DATA_PACK.getLootData().getLootTable(CraftNamespacedKey.toMinecraft(mock.getArgument(0))))); + AbstractTestingBase.DATA_PACK.fullRegistries().getLootTable(ResourceKey.create(Registries.LOOT_TABLE, CraftNamespacedKey.toMinecraft(mock.getArgument(0)))))); when(instance.getRegistry(any())).then((Answer>) mock -> { Class aClass = mock.getArgument(0);