9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-19 14:59:32 +00:00
Files
LeavesMC/leaves-server/minecraft-patches/features/0028-PCA-sync-protocol.patch
MC_XiaoHei 90080d238e 1.21.10 (#752)
---------

Co-authored-by: Lumine1909 <133463833+Lumine1909@users.noreply.github.com>
Co-authored-by: violetc <58360096+s-yh-china@users.noreply.github.com>
Co-authored-by: Helvetica Volubi <88063803+Suisuroru@users.noreply.github.com>
2025-11-28 03:15:54 +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 c87a1a5e3696e40f9f0d6f4d93e102e73325d4f8..b01f53af58afdde22f062e6d16888bf09ee98805 100644
--- a/net/minecraft/world/entity/animal/horse/AbstractHorse.java
+++ b/net/minecraft/world/entity/animal/horse/AbstractHorse.java
@@ -306,6 +306,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 6bb17ecbd93f6ced5436cf75f3695f44eedd4bd9..ea7364f3cc9f339578232ba1103008a9ed50234a 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(type, 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 0f9bfcd1eab023c1772e9fafcda85d110904bd1c..8fdde0cc090c80b65b4c0d679bf4b412b6b761ee 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 d8176f1f36f12fe179b5a63e6bf8f290a7a7461d..37bbd8d2cf412983fc4eb89737b3343f17364cae 100644
--- a/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
@@ -430,6 +430,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 75c09a2079c89f9346391abdd01ef8790b9cbb13..6741fe3abc4396236dc0ca31074e36d66e42c39a 100644
--- a/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
@@ -124,6 +124,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 f0673167d6273c7689cd58ac8f51e51649cb3ad0..03c9a2d253ba6fec39a0322eb74ac611fdc8b7f0 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 5b28e257982c911f4d8ffe286dc125b3f9b64ee4..a4d3d5b6830d156c76e381c5437867c0ed104016 100644
--- a/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
@@ -334,4 +334,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 6b1299c20573ca009f6bffce829a4a593f548fce..5b209de34bd425bf6c209a5317603f1c6d7280bf 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 4d268864656ad67e6971b74534e25ac47d922cbd..68fcb64d13bbd61ad78137f101ab20264f402df8 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;