From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Mon, 3 Feb 2025 13:17:03 +0800 Subject: [PATCH] PCA sync protocol This patch is Powered by plusls-carpet-addition(https://github.com/plusls/plusls-carpet-addition) diff --git a/net/minecraft/world/entity/animal/horse/AbstractHorse.java b/net/minecraft/world/entity/animal/horse/AbstractHorse.java index 31ed5d7cfbda1a1f98ebfc89f5cbc65332cabdae..18c683f7d7e18200a24cfc8d26e83f578681f7f5 100644 --- a/net/minecraft/world/entity/animal/horse/AbstractHorse.java +++ b/net/minecraft/world/entity/animal/horse/AbstractHorse.java @@ -305,6 +305,13 @@ public abstract class AbstractHorse extends Animal implements HasCustomInventory public void createInventory() { SimpleContainer simpleContainer = this.inventory; this.inventory = new SimpleContainer(this.getInventorySize(), (org.bukkit.entity.AbstractHorse) this.getBukkitEntity()); // CraftBukkit + // Leaves start - pca + this.inventory.addListener(inv -> { + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncEntityToClient(this); + } + }); + // Leaves end - pca if (simpleContainer != null) { int min = Math.min(simpleContainer.getContainerSize(), this.inventory.getContainerSize()); diff --git a/net/minecraft/world/entity/npc/AbstractVillager.java b/net/minecraft/world/entity/npc/AbstractVillager.java index f8782cdcf3015cad2693663a3c222bd60822f45b..38572ecba568072b132b9e7fc12e6c0c38edd2e2 100644 --- a/net/minecraft/world/entity/npc/AbstractVillager.java +++ b/net/minecraft/world/entity/npc/AbstractVillager.java @@ -48,6 +48,15 @@ public abstract class AbstractVillager extends AgeableMob implements InventoryCa super(entityType, level); this.setPathfindingMalus(PathType.DANGER_FIRE, 16.0F); this.setPathfindingMalus(PathType.DAMAGE_FIRE, -1.0F); + // Leaves start - pca + if (!this.level().isClientSide()) { + this.inventory.addListener(inventory -> { + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncEntityToClient(this); + } + }); + } + // Leaves end - pca } @Override diff --git a/net/minecraft/world/entity/vehicle/AbstractMinecartContainer.java b/net/minecraft/world/entity/vehicle/AbstractMinecartContainer.java index 6a008c86f4e360c916b93f0e3a62a9d8b43e74e6..7781ca07a0c8fe1140f341b695e66de95802ee2e 100644 --- a/net/minecraft/world/entity/vehicle/AbstractMinecartContainer.java +++ b/net/minecraft/world/entity/vehicle/AbstractMinecartContainer.java @@ -65,6 +65,11 @@ public abstract class AbstractMinecartContainer extends AbstractMinecart impleme @Override public void setChanged() { + // Leaves start - pca + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncEntityToClient(this); + } + // Leaves end - pca } @Override diff --git a/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java b/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java index 36a72a11d28f99bfe85868461925b778cc01478e..bebe8737b71fc37336342f14b6ea4cfab12d3f34 100644 --- a/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java +++ b/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java @@ -429,6 +429,16 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit } } + // Leaves start - pca + @Override + public void setChanged() { + super.setChanged(); + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncBlockEntityToClient(this); + } + } + // Leaves end - pca + @Override public void setRecipeUsed(@Nullable RecipeHolder recipe) { if (recipe != null) { diff --git a/net/minecraft/world/level/block/entity/BarrelBlockEntity.java b/net/minecraft/world/level/block/entity/BarrelBlockEntity.java index d679ab599dfd0bdbdc3ab5530d7fcd1c38baf7fa..f0ba09c0edc598dfc4e501ba69016e8a2f8d3a7c 100644 --- a/net/minecraft/world/level/block/entity/BarrelBlockEntity.java +++ b/net/minecraft/world/level/block/entity/BarrelBlockEntity.java @@ -121,6 +121,16 @@ public class BarrelBlockEntity extends RandomizableContainerBlockEntity { this.items = items; } + // Leaves start - pca + @Override + public void setChanged() { + super.setChanged(); + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncBlockEntityToClient(this); + } + } + // Leaves end - pca + @Override protected Component getDefaultName() { return Component.translatable("container.barrel"); diff --git a/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java b/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java index 91f7ee163107d846e7f6a5783be6eff96e783886..cbbe3dee3dda06d0e2451597dae0ac03009330e0 100644 --- a/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java +++ b/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java @@ -147,6 +147,11 @@ public class BeehiveBlockEntity extends BlockEntity { super.setChanged(); } + // Leaves start - pca + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncBlockEntityToClient(this); + } + // Leaves end - pca return list; } @@ -204,6 +209,11 @@ public class BeehiveBlockEntity extends BlockEntity { this.level.gameEvent(GameEvent.BLOCK_CHANGE, blockPos, GameEvent.Context.of(bee, this.getBlockState())); } + // Leaves start - pca + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncBlockEntityToClient(this); + } + // Leaves end - pca bee.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.ENTER_BLOCK); // CraftBukkit - add Bukkit remove cause super.setChanged(); } @@ -325,6 +335,11 @@ public class BeehiveBlockEntity extends BlockEntity { if (releaseOccupant(level, pos, state, beeData.toOccupant(), null, beeReleaseStatus, savedFlowerPos)) { flag = true; iterator.remove(); + // Leaves start - pca + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncBlockEntityToClient(java.util.Objects.requireNonNull(level.getBlockEntity(pos))); + } + // Leaves end - pca } // Paper start - Fix bees aging inside; use exitTickCounter to keep actual bee life else if (level.paperConfig().entities.behavior.cooldownFailedBeehiveReleases) { @@ -358,6 +373,11 @@ public class BeehiveBlockEntity extends BlockEntity { input.read("bees", BeehiveBlockEntity.Occupant.LIST_CODEC).orElse(List.of()).forEach(this::storeBee); this.savedFlowerPos = input.read("flower_pos", BlockPos.CODEC).orElse(null); this.maxBees = input.getIntOr("Bukkit.MaxEntities", MAX_OCCUPANTS); // Paper - persist max bukkit occupants + // Leaves start - pca + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncBlockEntityToClient(this); + } + // Leaves end - pca } @Override diff --git a/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java b/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java index 79a9f1c87de30cda479b55cf70fbc3219a3dcad4..7eac2188a38fff2ecfa4082b5d023b111cf7d8f6 100644 --- a/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java +++ b/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java @@ -331,4 +331,14 @@ public class BrewingStandBlockEntity extends BaseContainerBlockEntity implements protected AbstractContainerMenu createMenu(int id, Inventory player) { return new BrewingStandMenu(id, player, this, this.dataAccess); } + + // Leaves start - pca + @Override + public void setChanged() { + super.setChanged(); + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncBlockEntityToClient(this); + } + } + // Leaves end - pca } diff --git a/net/minecraft/world/level/block/entity/ChestBlockEntity.java b/net/minecraft/world/level/block/entity/ChestBlockEntity.java index b7d94ebe0ee995392c355c4237da8443dcc79b21..784e146b28370dc2dac094d5f2ac654a5bc47e01 100644 --- a/net/minecraft/world/level/block/entity/ChestBlockEntity.java +++ b/net/minecraft/world/level/block/entity/ChestBlockEntity.java @@ -202,6 +202,16 @@ public class ChestBlockEntity extends RandomizableContainerBlockEntity implement otherChest.setItems(items); } + // Leaves start - pca + @Override + public void setChanged() { + super.setChanged(); + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncBlockEntityToClient(this); + } + } + // Leaves end - pca + @Override protected AbstractContainerMenu createMenu(int id, Inventory player) { return ChestMenu.threeRows(id, player, this); diff --git a/net/minecraft/world/level/block/entity/ComparatorBlockEntity.java b/net/minecraft/world/level/block/entity/ComparatorBlockEntity.java index 6b5179ae4269829b1e356840c9a8c33153334c32..b78ee57634471bc6e5308fb30c8f974fdce516de 100644 --- a/net/minecraft/world/level/block/entity/ComparatorBlockEntity.java +++ b/net/minecraft/world/level/block/entity/ComparatorBlockEntity.java @@ -25,6 +25,16 @@ public class ComparatorBlockEntity extends BlockEntity { this.output = input.getIntOr("OutputSignal", 0); } + // Leaves start - pca + @Override + public void setChanged() { + super.setChanged(); + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncBlockEntityToClient(this); + } + } + // Leaves end - pca + public int getOutputSignal() { return this.output; } diff --git a/net/minecraft/world/level/block/entity/DispenserBlockEntity.java b/net/minecraft/world/level/block/entity/DispenserBlockEntity.java index ae52dc75335799e55e403e3d3f11e9f1d67e4305..36b9362e1ce31b63c100ec65921e095fb7871e82 100644 --- a/net/minecraft/world/level/block/entity/DispenserBlockEntity.java +++ b/net/minecraft/world/level/block/entity/DispenserBlockEntity.java @@ -104,6 +104,16 @@ public class DispenserBlockEntity extends RandomizableContainerBlockEntity { return stack; } + // Leaves start - pca + @Override + public void setChanged() { + super.setChanged(); + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncBlockEntityToClient(this); + } + } + // Leaves end - pca + @Override protected Component getDefaultName() { return Component.translatable("container.dispenser"); diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java index 800b7e78ae989868ed0b9e060c80dcd002759412..5f42af7c6fc82d6672ed06a2315254c9c5886ce4 100644 --- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java +++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java @@ -122,6 +122,16 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen this.facing = blockState.getValue(HopperBlock.FACING); } + // Leaves start - pca + @Override + public void setChanged() { + super.setChanged(); + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncBlockEntityToClient(this); + } + } + // Leaves end - pca + @Override protected Component getDefaultName() { return Component.translatable("container.hopper"); @@ -198,6 +208,11 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen if (flag) { blockEntity.setCooldown(level.spigotConfig.hopperTransfer); // Spigot setChanged(level, pos, state); + // Leaves start - pca + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncBlockEntityToClient(blockEntity); + } + // Leaves end - pca return true; } } diff --git a/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java b/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java index ebea67223ce1d350087c73dff0cc3fe6d7b47ca0..a820ab9a2b6dc6b95d4de61aaaad4e79c521efe4 100644 --- a/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java +++ b/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java @@ -267,6 +267,16 @@ public class ShulkerBoxBlockEntity extends RandomizableContainerBlockEntity impl this.itemStacks = items; } + // Leaves start - pca + @Override + public void setChanged() { + super.setChanged(); + if (org.leavesmc.leaves.LeavesConfig.protocol.pca.enable) { + org.leavesmc.leaves.protocol.PcaSyncProtocol.syncBlockEntityToClient(this); + } + } + // Leaves end - pca + @Override public int[] getSlotsForFace(Direction side) { return SLOTS;