mirror of
https://github.com/Samsuik/Sakura.git
synced 2026-01-06 15:41:49 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@6e598f8 Fix incorrect createPath overload arguments, fixes #12043 (#12794) PaperMC/Paper@f7d5a0a [ci skip] Add remote build cache configuration through Gradle properties (#12797) PaperMC/Paper@b4466ec Dialog API (#12671) PaperMC/Paper@a939945 Fixup sendAllDataToRemote calls PaperMC/Paper@cb47e01 Remove more dead code, fix pre-existing desync when cancelling and closing container PaperMC/Paper@4076453 Specify the class loader when loading services (#12829) PaperMC/Paper@1bf6364 Update Mache for horse decompile fix PaperMC/Paper@76fb506 Add vanilla error message to precondition for DialogBaseImpl (#12831) PaperMC/Paper@fcfc6c3 Expose HexColor argument type (#12833) PaperMC/Paper@4000fcc Fix typo in PluginBootstrap javadocs (#12821) PaperMC/Paper@25d358c [ci skip] javadoc: Fix grammatical error for getState (#12817) PaperMC/Paper@ba7c982 Add missing Range annotations to dialog types PaperMC/Paper@533d93c Don't consume anchor charge if loc changes (#12835) PaperMC/Paper@d9b5003 Dried Ghast events and Happy Ghast spawn reason (#12788) PaperMC/Paper@bda8406 [ci skip] fix typo in AttributeInstance (#12843) PaperMC/Paper@94d60e1 Copy thrown pearls list for removal (#12840) PaperMC/Paper@21fb542 Do not write fall_distance tag unless it already existed before PaperMC/Paper@04f9519 Fix spawners converted from 1.21.4 not running finalisation logic PaperMC/Paper@22d80a3 [ci skip] Update Gradle wrapper and Fill plugin (#12846) PaperMC/Paper@a6e0c08 Add getRotation to Location (#12799) PaperMC/Paper@e792779 Allow AreaEffectCloud#setColor to reset color for null (#12760)
345 lines
18 KiB
Diff
345 lines
18 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samsuik <kfian294ma4@gmail.com>
|
|
Date: Sat, 9 Sep 2023 18:39:15 +0100
|
|
Subject: [PATCH] Merge Cannon Entities
|
|
|
|
|
|
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
|
index 5f38281763419123a0611cbb34d9a02a0e0302ea..5ddfbddbef13b58bf509e4c60bbd72cde2a7f59d 100644
|
|
--- a/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
|
@@ -691,6 +691,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
// Paper end - rewrite chunk system
|
|
this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit
|
|
this.levelTickScheduler.registerNewTask(this.explosionPositions::clear, 0); // Sakura - client visibility settings
|
|
+ this.levelTickScheduler.registerNewTask(this.mergeHandler::expire, 200); // Sakura - merge cannon entities
|
|
}
|
|
|
|
// Paper start
|
|
@@ -805,6 +806,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
}
|
|
|
|
io.papermc.paper.entity.activation.ActivationRange.activateEntities(this); // Paper - EAR
|
|
+ final Entity[] previousEntity = new Entity[1]; // Sakura - merge cannon entities
|
|
this.entityTickList
|
|
.forEach(
|
|
entity -> {
|
|
@@ -823,6 +825,15 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
entity.stopRiding();
|
|
}
|
|
|
|
+ // Sakura start - merge cannon entities
|
|
+ Entity previous = previousEntity[0];
|
|
+ if (this.mergeHandler.tryMerge(entity, previous)) {
|
|
+ return;
|
|
+ } else {
|
|
+ previousEntity[0] = entity;
|
|
+ }
|
|
+ // Sakura end - merge cannon entities
|
|
+
|
|
profilerFiller.push("tick");
|
|
this.guardEntityTick(this::tickNonPassenger, entity);
|
|
profilerFiller.pop();
|
|
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
|
index b0b611e641ff1b81fb9dbee31de3e8e94be08338..1dab546bcf31c4c773cff99a8f28c5c4b0da4747 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -566,6 +566,27 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
return to.entityState() != null && to.entityState().comparePositionAndMotion(this);
|
|
}
|
|
// Sakura end - store entity data/state
|
|
+ // Sakura start - merge cannon entities
|
|
+ public final void updateBukkitHandle(Entity entity) {
|
|
+ if (this.bukkitEntity != null) {
|
|
+ this.bukkitEntity.setHandle(entity);
|
|
+ } else {
|
|
+ this.bukkitEntity = entity.getBukkitEntity();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public final long getPackedOriginPosition() {
|
|
+ if (this.origin != null) {
|
|
+ return BlockPos.asLong(
|
|
+ Mth.floor(this.origin.x()),
|
|
+ Mth.floor(this.origin.y()),
|
|
+ Mth.floor(this.origin.z())
|
|
+ );
|
|
+ } else {
|
|
+ return Long.MIN_VALUE;
|
|
+ }
|
|
+ }
|
|
+ // Sakura end - merge cannon entities
|
|
|
|
public Entity(EntityType<?> entityType, Level level) {
|
|
this.type = entityType;
|
|
@@ -5177,6 +5198,11 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
if (this.removalReason != Entity.RemovalReason.UNLOADED_TO_CHUNK) { this.getPassengers().forEach(Entity::stopRiding); } // Paper - rewrite chunk system
|
|
this.levelCallback.onRemove(removalReason);
|
|
this.onRemoval(removalReason);
|
|
+ // Sakura start - merge cannon entities
|
|
+ if (removalReason == RemovalReason.DISCARDED) {
|
|
+ this.level.mergeHandler.removeEntity(this);
|
|
+ }
|
|
+ // Sakura end - merge cannon entities
|
|
// Paper start - Folia schedulers
|
|
if (!(this instanceof ServerPlayer) && removalReason != RemovalReason.CHANGED_DIMENSION && !alreadyRemoved) {
|
|
// Players need to be special cased, because they are regularly removed from the world
|
|
diff --git a/net/minecraft/world/entity/item/FallingBlockEntity.java b/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
index 860efa7bf6643ab9f05e97fefec280dffa76ba0e..d65df5f13e038d109870d1f7fba50d2260489d49 100644
|
|
--- a/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
+++ b/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
@@ -53,7 +53,7 @@ import net.minecraft.world.phys.HitResult;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import org.slf4j.Logger;
|
|
|
|
-public class FallingBlockEntity extends Entity {
|
|
+public class FallingBlockEntity extends Entity implements me.samsuik.sakura.entity.merge.MergeableEntity { // Sakura - merge cannon entities
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
|
private static final BlockState DEFAULT_BLOCK_STATE = Blocks.SAND.defaultBlockState();
|
|
private static final int DEFAULT_TIME = 0;
|
|
@@ -75,12 +75,63 @@ public class FallingBlockEntity extends Entity {
|
|
public boolean autoExpire = true; // Paper - Expand FallingBlock API
|
|
public boolean heightParity; // Sakura - falling block height parity api
|
|
|
|
+ // Sakura start - merge cannon entities
|
|
+ private final me.samsuik.sakura.entity.merge.MergeEntityData mergeData = new me.samsuik.sakura.entity.merge.MergeEntityData(this);
|
|
+
|
|
+ @Override
|
|
+ public final me.samsuik.sakura.entity.merge.MergeEntityData getMergeEntityData() {
|
|
+ return this.mergeData;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public final boolean isSafeToMergeInto(me.samsuik.sakura.entity.merge.MergeableEntity entity, boolean ticksLived) {
|
|
+ return entity instanceof FallingBlockEntity fbe
|
|
+ && fbe.blockState.equals(this.blockState)
|
|
+ && (!ticksLived || fbe.time - 1 == this.time);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public final void respawnEntity(int count) {
|
|
+ while (count-- >= 1) {
|
|
+ // Unlike PrimedTnt we have to try respawn each stacked entity
|
|
+ FallingBlockEntity fallingBlock = new FallingBlockEntity(EntityType.FALLING_BLOCK, this.level());
|
|
+
|
|
+ // Try to stack the falling block
|
|
+ this.entityState().apply(fallingBlock);
|
|
+ fallingBlock.blockState = this.blockState;
|
|
+ fallingBlock.spawnReason = this.spawnReason;
|
|
+ fallingBlock.time = this.time - 1;
|
|
+ fallingBlock.tick();
|
|
+
|
|
+ // If you horizontal stack into a moving piston block this condition will be met.
|
|
+ if (!fallingBlock.isRemoved()) {
|
|
+ this.mergeData.count = count + 1;
|
|
+ fallingBlock.storeEntityState();
|
|
+ fallingBlock.entityState().apply(this);
|
|
+ break;
|
|
+ } else if (count == 0) {
|
|
+ this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DESPAWN);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public @Nullable ItemEntity spawnAtLocation(ServerLevel level, net.minecraft.world.level.ItemLike item) { // may be overridden by plugins
|
|
+ ItemEntity itemEntity = null;
|
|
+ for (int i = 0; i < this.mergeData.count; ++i) {
|
|
+ itemEntity = super.spawnAtLocation(level, item);
|
|
+ }
|
|
+ return itemEntity;
|
|
+ }
|
|
+ // Sakura end - merge cannon entities
|
|
+
|
|
public FallingBlockEntity(EntityType<? extends FallingBlockEntity> entityType, Level level) {
|
|
super(entityType, level);
|
|
this.dropItem = level.sakuraConfig().cannons.sand.dropItems; // Sakura - configure falling blocks dropping items
|
|
this.heightParity = level.sakuraConfig().cannons.mechanics.fallingBlockParity; // Sakura - configure cannon mechanics
|
|
this.isFallingBlock = true; // Sakura - client visibility settings
|
|
this.loadChunks = level.sakuraConfig().cannons.loadChunks; // Sakura - load chunks on movement
|
|
+ this.mergeData.mergeLevel = level.sakuraConfig().cannons.mergeLevel; // Sakura - merge cannon entities
|
|
}
|
|
|
|
public FallingBlockEntity(Level level, double x, double y, double z, BlockState state) {
|
|
@@ -240,6 +291,7 @@ public class FallingBlockEntity extends Entity {
|
|
return;
|
|
}
|
|
// CraftBukkit end
|
|
+ if (this.tryToRespawnEntity()) return; // Sakura - merge cannon entities
|
|
if (this.level().setBlock(blockPos, this.blockState, 3)) {
|
|
((ServerLevel)this.level())
|
|
.getChunkSource()
|
|
@@ -347,6 +399,11 @@ public class FallingBlockEntity extends Entity {
|
|
|
|
output.putBoolean("CancelDrop", this.cancelDrop);
|
|
if (!this.autoExpire) output.putBoolean("Paper.AutoExpire", false); // Paper - Expand FallingBlock API
|
|
+ // Sakura start - merge cannon entities; save to nbt
|
|
+ if (this.mergeData.count != 1) {
|
|
+ output.putInt("merge_count", this.mergeData.count);
|
|
+ }
|
|
+ // Sakura end - merge cannon entities; save to nbt
|
|
}
|
|
|
|
@Override
|
|
@@ -361,6 +418,7 @@ public class FallingBlockEntity extends Entity {
|
|
this.blockData = input.read("TileEntityData", CompoundTag.CODEC).map(blockData -> this.level().paperConfig().entities.spawning.filterBadTileEntityNbtFromFallingBlocks && this.blockState.getBlock() instanceof net.minecraft.world.level.block.GameMasterBlock ? null : blockData).map(CompoundTag::copy).orElse(null); // Paper - Filter bad block entity nbt data from falling blocks
|
|
this.cancelDrop = input.getBooleanOr("CancelDrop", false);
|
|
this.autoExpire = input.getBooleanOr("Paper.AutoExpire", true); // Paper - Expand FallingBlock API
|
|
+ this.mergeData.count = input.getIntOr("merge_count", 1); // Sakura - merge cannon entities; load from nbt
|
|
}
|
|
|
|
public void setHurtsEntities(float fallDamagePerDistance, int fallDamageMax) {
|
|
diff --git a/net/minecraft/world/entity/item/PrimedTnt.java b/net/minecraft/world/entity/item/PrimedTnt.java
|
|
index 2e7f6e3941b34323768e43870541c8e4156c9a8f..0c8343075f5523aa200b58f2afd313d718408ac8 100644
|
|
--- a/net/minecraft/world/entity/item/PrimedTnt.java
|
|
+++ b/net/minecraft/world/entity/item/PrimedTnt.java
|
|
@@ -34,7 +34,7 @@ import org.bukkit.event.entity.EntityRemoveEvent;
|
|
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
|
// CraftBukkit end
|
|
|
|
-public class PrimedTnt extends Entity implements TraceableEntity {
|
|
+public class PrimedTnt extends Entity implements TraceableEntity, me.samsuik.sakura.entity.merge.MergeableEntity { // Sakura - merge cannon entities
|
|
private static final EntityDataAccessor<Integer> DATA_FUSE_ID = SynchedEntityData.defineId(PrimedTnt.class, EntityDataSerializers.INT);
|
|
private static final EntityDataAccessor<BlockState> DATA_BLOCK_STATE_ID = SynchedEntityData.defineId(PrimedTnt.class, EntityDataSerializers.BLOCK_STATE);
|
|
private static final short DEFAULT_FUSE_TIME = 80;
|
|
@@ -60,11 +60,48 @@ public class PrimedTnt extends Entity implements TraceableEntity {
|
|
public float explosionPower = 4.0F;
|
|
public boolean isIncendiary = false; // CraftBukkit
|
|
|
|
+ // Sakura start - merge cannon entities
|
|
+ private final me.samsuik.sakura.entity.merge.MergeEntityData mergeData = new me.samsuik.sakura.entity.merge.MergeEntityData(this);
|
|
+
|
|
+ @Override
|
|
+ public final me.samsuik.sakura.entity.merge.MergeEntityData getMergeEntityData() {
|
|
+ return this.mergeData;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public final boolean isSafeToMergeInto(me.samsuik.sakura.entity.merge.MergeableEntity entity, boolean ticksLived) {
|
|
+ return entity instanceof PrimedTnt tnt
|
|
+ && tnt.getFuse() + 1 == this.getFuse()
|
|
+ // required to prevent issues with powdered snow
|
|
+ && (tnt.entityState().fallDistance() == this.fallDistance
|
|
+ || tnt.entityState().fallDistance() > 2.5f && this.fallDistance > 2.5f);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public final void respawnEntity(int count) {
|
|
+ PrimedTnt tnt = new PrimedTnt(EntityType.TNT, this.level());
|
|
+ tnt.updateBukkitHandle(this); // update handle for plugins
|
|
+ while (count-- > 1) {
|
|
+ this.setFuse(100); // Prevent unwanted explosions while ticking
|
|
+
|
|
+ // Cause an explosion to affect this entity
|
|
+ tnt.setPos(this.position());
|
|
+ tnt.setDeltaMovement(this.getDeltaMovement());
|
|
+ this.entityState().apply(this);
|
|
+ tnt.explode();
|
|
+ this.storeEntityState();
|
|
+
|
|
+ this.tick();
|
|
+ }
|
|
+ }
|
|
+ // Sakura end - merge cannon entities
|
|
+
|
|
public PrimedTnt(EntityType<? extends PrimedTnt> entityType, Level level) {
|
|
super(entityType, level);
|
|
this.blocksBuilding = true;
|
|
this.isPrimedTNT = true; // Sakura - client visibility settings
|
|
this.loadChunks = level.sakuraConfig().cannons.loadChunks; // Sakura - load chunks on movement
|
|
+ this.mergeData.mergeLevel = level.sakuraConfig().cannons.mergeLevel; // Sakura - merge cannon entities
|
|
}
|
|
|
|
public PrimedTnt(Level level, double x, double y, double z, @Nullable LivingEntity owner) {
|
|
@@ -144,6 +181,7 @@ public class PrimedTnt extends Entity implements TraceableEntity {
|
|
if (i <= 0) {
|
|
// CraftBukkit start - Need to reverse the order of the explosion and the entity death so we have a location for the event
|
|
//this.discard();
|
|
+ this.tryToRespawnEntity(); // Sakura - merge cannon entities
|
|
if (!this.level().isClientSide) {
|
|
this.explode();
|
|
}
|
|
@@ -203,6 +241,11 @@ public class PrimedTnt extends Entity implements TraceableEntity {
|
|
}
|
|
|
|
EntityReference.store(this.owner, output, "owner");
|
|
+ // Sakura start - merge cannon entities; save to nbt
|
|
+ if (this.mergeData.count != 1) {
|
|
+ output.putInt("merge_count", this.mergeData.count);
|
|
+ }
|
|
+ // Sakura end - merge cannon entities; save to nbt
|
|
}
|
|
|
|
@Override
|
|
@@ -211,6 +254,7 @@ public class PrimedTnt extends Entity implements TraceableEntity {
|
|
this.setBlockState(input.read("block_state", BlockState.CODEC).orElse(DEFAULT_BLOCK_STATE));
|
|
this.explosionPower = Mth.clamp(input.getFloatOr("explosion_power", 4.0F), 0.0F, 128.0F);
|
|
this.owner = EntityReference.read(input, "owner");
|
|
+ this.mergeData.count = input.getIntOr("merge_count", 1); // Sakura - merge cannon entities; load from nbt
|
|
}
|
|
|
|
@Nullable
|
|
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
|
|
index 2fa0725a2b41517e1589e540999118f5c355e899..19788e29f796efd7b1fe79c398c5532eb99add58 100644
|
|
--- a/net/minecraft/world/level/Level.java
|
|
+++ b/net/minecraft/world/level/Level.java
|
|
@@ -828,6 +828,7 @@ public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, AutoCl
|
|
public final me.samsuik.sakura.listener.LevelTickScheduler levelTickScheduler = new me.samsuik.sakura.listener.LevelTickScheduler();
|
|
public final me.samsuik.sakura.listener.BlockChangeTracker blockChangeTracker = new me.samsuik.sakura.listener.BlockChangeTracker(this);
|
|
// Sakura end - track block changes and tick scheduler
|
|
+ public final me.samsuik.sakura.entity.merge.EntityMergeHandler mergeHandler = new me.samsuik.sakura.entity.merge.EntityMergeHandler(); // Sakura - merge cannon entities
|
|
|
|
protected Level(
|
|
WritableLevelData levelData,
|
|
diff --git a/net/minecraft/world/level/block/BasePressurePlateBlock.java b/net/minecraft/world/level/block/BasePressurePlateBlock.java
|
|
index 42ee3f32fe44c1f0680c994a69201f7bd7792673..96c977df11c660ccb9a9b32e61c865084e3776ce 100644
|
|
--- a/net/minecraft/world/level/block/BasePressurePlateBlock.java
|
|
+++ b/net/minecraft/world/level/block/BasePressurePlateBlock.java
|
|
@@ -92,7 +92,7 @@ public abstract class BasePressurePlateBlock extends Block {
|
|
}
|
|
|
|
private void checkPressed(@Nullable Entity entity, Level level, BlockPos pos, BlockState state, int currentSignal) {
|
|
- int signalStrength = this.getSignalStrength(level, pos);
|
|
+ int signalStrength = this.getSignalStrength(level, pos, currentSignal == 0); // Sakura - merge cannon entities
|
|
boolean flag = currentSignal > 0;
|
|
boolean flag1 = signalStrength > 0;
|
|
|
|
@@ -162,6 +162,12 @@ public abstract class BasePressurePlateBlock extends Block {
|
|
// CraftBukkit end
|
|
}
|
|
|
|
+ // Sakura start - merge cannon entities
|
|
+ protected int getSignalStrength(Level world, BlockPos pos, boolean entityInside) {
|
|
+ return this.getSignalStrength(world, pos);
|
|
+ }
|
|
+ // Sakura end - merge cannon entities
|
|
+
|
|
protected abstract int getSignalStrength(Level level, BlockPos pos);
|
|
|
|
protected abstract int getSignalForState(BlockState state);
|
|
diff --git a/net/minecraft/world/level/block/WeightedPressurePlateBlock.java b/net/minecraft/world/level/block/WeightedPressurePlateBlock.java
|
|
index 5e095919828e89d12f2676b3c544842a81e047a1..e47a5010baea87ebf472ccac9ae98ede7a490b50 100644
|
|
--- a/net/minecraft/world/level/block/WeightedPressurePlateBlock.java
|
|
+++ b/net/minecraft/world/level/block/WeightedPressurePlateBlock.java
|
|
@@ -39,6 +39,11 @@ public class WeightedPressurePlateBlock extends BasePressurePlateBlock {
|
|
|
|
@Override
|
|
protected int getSignalStrength(Level level, BlockPos pos) {
|
|
+ // Sakura start - merge cannon entities
|
|
+ return this.getSignalStrength(level, pos, false);
|
|
+ }
|
|
+ protected final int getSignalStrength(Level level, BlockPos pos, boolean entityInside) {
|
|
+ // Sakura end - merge cannon entities
|
|
// CraftBukkit start
|
|
// int min = Math.min(getEntityCount(level, TOUCH_AABB.move(pos), Entity.class), this.maxWeight);
|
|
int min = 0;
|
|
@@ -54,7 +59,7 @@ public class WeightedPressurePlateBlock extends BasePressurePlateBlock {
|
|
|
|
// We only want to block turning the plate on if all events are cancelled
|
|
if (!cancellable.isCancelled()) {
|
|
- min++;
|
|
+ min += !entityInside && entity instanceof me.samsuik.sakura.entity.merge.MergeableEntity mergeEntity ? mergeEntity.getMergeEntityData().count : 1; // Sakura - merge cannon entities
|
|
}
|
|
}
|
|
// CraftBukkit end
|