9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2026-01-06 15:51:33 +00:00
Files
LeavesMC/leaves-server/minecraft-patches/features/0028-PCA-sync-protocol.patch
2025-09-25 15:54:57 +08:00

292 lines
14 KiB
Diff

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 fde1f235332127f727da8491e03b54680e42ea4a..32e8f67e61b7611c846a75cac042dcf7860d5f69 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 cf4703cb909aa5906fdd689082208ea4dd77fc0f..54ba469380b51b38327c107e3a1c5574395f3507 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 8643d46d21852e9e14f9b2448f1c0eb26a737ebb..991ae9f719e63cb77e692213d4a80f0486b86528 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 f8cad05f5f1692c9a8701ff01f33d83477600c34..e265dbe8f84f80314f3e19c3724fff24929e3a13 100644
--- a/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
@@ -123,6 +123,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 DEFAULT_NAME;
diff --git a/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java b/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java
index 2e58d918abe1d825af3b05dfd38d76cc12df3403..be0693e53eb7dc6851a8bc642a072797cf2efe90 100644
--- a/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/BeehiveBlockEntity.java
@@ -149,6 +149,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;
}
@@ -206,6 +211,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();
}
@@ -327,6 +337,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 8602a42967ebc28821d6156c07e0aad69c12fa9d..6124a10814c1122ea1685646541395b452e9d4b3 100644
--- a/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
@@ -332,4 +332,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 c0d4dd95812172a86e5b6f4217bf3cb9d7ee6f2a..8a6593f99525bc3375d8c4a263f2fd12635ca7c5 100644
--- a/net/minecraft/world/level/block/entity/ChestBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/ChestBlockEntity.java
@@ -214,6 +214,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 b4a155cc914092dad83977df714fbbc033c69d19..2fbfe925c81126cb99a4330a232d7d1b1f035973 100644
--- a/net/minecraft/world/level/block/entity/DispenserBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/DispenserBlockEntity.java
@@ -105,6 +105,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 DEFAULT_NAME;
diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
index 28348e3881c3c8591053a01b193fb2a956f79726..ab88bca97fe275528a2feb22e5da89252be683c3 100644
--- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java
@@ -123,6 +123,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 DEFAULT_NAME;
@@ -199,6 +209,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 e2a2811464ff7455e513944b7565f9f226a5ed34..10c123b9cffdc79d069a82d09e57b24bc1572771 100644
--- a/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java
@@ -268,6 +268,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;