9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-22 16:29:16 +00:00
Files
SakuraMC/patches/server/0015-Store-Entity-Data-State.patch
Samsuik 8491db8c0a Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@9aea240 Properly lookup plugin classes when looked up by spark
PaperMC/Paper@7e91a2c Update the bundled spark version
PaperMC/Paper@3a47518 Deprecate more Timings things for removal (#11126)
PaperMC/Paper@aa36ae6 Fix EntityUnleashEvent cancellation on distance cause (#11131)
PaperMC/Paper@73a863b Fix horse inventories indices (#11139)
PaperMC/Paper@5512af7 [ci skip] remove timings from issue templates (#11127)
PaperMC/Paper@5a5035b Fix a couple of ItemMeta related NPEs (#11149)
PaperMC/Paper@e1462a9 Bump MCUtils#asyncExecutor core size
PaperMC/Paper@645a677 Make max interaction range configurable (#11164)
PaperMC/Paper@66165f7 Fix PickupStatus getting reset (#11154)
PaperMC/Paper@dcbd99d Fix Owen's typos (#11179)
PaperMC/Paper@f82bea6 Add argument for FinePosition to brig API (#11094)
PaperMC/Paper@694b120 Remove Entity tracker field
PaperMC/Paper@f774787 Copy missed changes to chunk system from Folia
PaperMC/Paper@50bdfc3 Null check tracker in Entity#resendPossiblyDesyncedEntityData
PaperMC/Paper@3234b20 Do not allow chunk unloading outside of the regular tick loop
PaperMC/Paper@0246a9d Add mob bucket items to item id to entity map in DataConverter
PaperMC/Paper@438863c Shutdown L4J cordially if the server stops before it's even started (#11172)
PaperMC/Paper@100d75a Don't entirely die just because a plugin jar was bad
PaperMC/Paper@227544c Move TickThread changes from Moonrise patch to MCUtils
PaperMC/Paper@67d414a Allow plugin aliases to override vanilla commands (#11186)
PaperMC/Paper@58c7ea3 Preserve command node when re-registering modern commands through old API (#11184)
PaperMC/Paper@0a1be9a Make loadChunksForMoveAsync use new chunk system load calls
PaperMC/Paper@df3b654 ConcurrentUtil: Fix concurrent long map resize chain pull function
PaperMC/Paper@5a5c3a4 Remove chunk unload trace debug
PaperMC/Paper@7e44684 Fix wrong assumption about locale being null in the login phase (#11204)
PaperMC/Paper@042f15f [ci skip] chore: fix incorrect commit hash in PR builds (#11198)
PaperMC/Paper@4e6a2a1 Check for block type in SculkSensorBlock#canActivate
2024-08-09 20:10:59 +01:00

96 lines
4.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <40902469+Samsuik@users.noreply.github.com>
Date: Wed, 16 Aug 2023 22:34:49 +0100
Subject: [PATCH] Store Entity Data/State
diff --git a/src/main/java/me/samsuik/sakura/entity/EntityState.java b/src/main/java/me/samsuik/sakura/entity/EntityState.java
new file mode 100644
index 0000000000000000000000000000000000000000..c9f2c5ae57878283e8c8bc3847fe63b98f4e8d10
--- /dev/null
+++ b/src/main/java/me/samsuik/sakura/entity/EntityState.java
@@ -0,0 +1,41 @@
+package me.samsuik.sakura.entity;
+
+import net.minecraft.core.BlockPos;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.phys.AABB;
+import net.minecraft.world.phys.Vec3;
+
+import java.util.Optional;
+
+public record EntityState(Vec3 position, Vec3 momentum, AABB bb, Vec3 stuckSpeed, Optional<BlockPos> supportingPos, boolean onGround, float fallDistance) {
+
+ public static EntityState of(Entity entity) {
+ return new EntityState(entity.position(), entity.getDeltaMovement(), entity.getBoundingBox(), entity.stuckSpeedMultiplier(), entity.mainSupportingBlockPos, entity.onGround(), entity.fallDistance);
+ }
+
+ public void apply(Entity entity) {
+ entity.setPos(position);
+ entity.setDeltaMovement(momentum);
+ entity.setBoundingBox(bb);
+ // null here is only safe for our use case (tnt and sand)
+ //noinspection DataFlowIssue
+ entity.makeStuckInBlock(null, stuckSpeed);
+ entity.onGround = onGround;
+ entity.mainSupportingBlockPos = supportingPos;
+ entity.fallDistance = fallDistance;
+ }
+
+ public void position(Entity entity) {
+ entity.setPos(position);
+ entity.setBoundingBox(bb);
+ }
+
+ public boolean isCurrentState(Entity entity) {
+ return entity.position().equals(position)
+ && entity.getDeltaMovement().equals(momentum);
+ // 1.14+ versions seem to correct morphed bounding boxes after a gametick.
+ // If there are any related issues uncomment this line of code.
+ // && entity.getBoundingBox().equals(bb);
+ }
+
+}
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index f375728a95465bbcbb8581cb43e48fc0e6966858..4435e0cd1370f3720102734ac3647674d5f46730 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -567,6 +567,25 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return flags;
}
// Sakura end - load chunks on movement
+ // Sakura start - store entity data/state
+ private me.samsuik.sakura.entity.EntityState entityState = null;
+
+ public final Vec3 stuckSpeedMultiplier() {
+ return this.stuckSpeedMultiplier;
+ }
+
+ public final void storeEntityState() {
+ this.entityState = me.samsuik.sakura.entity.EntityState.of(this);
+ }
+
+ public final me.samsuik.sakura.entity.EntityState entityState() {
+ return this.entityState;
+ }
+
+ public final boolean compareState(Entity to) {
+ return to.entityState() != null && to.entityState().isCurrentState(this);
+ }
+ // Sakura end - store entity data/state
public Entity(EntityType<?> type, Level world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 5886f44fdc605d3b814566808d8477e09df2fd3b..7384c7f81e0f9bfe05c05561a1ec87f3fa17f010 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -1431,6 +1431,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl
public <T extends Entity> void guardEntityTick(Consumer<T> tickConsumer, T entity) {
try {
+ entity.storeEntityState(); // Sakura - store entity data/state
tickConsumer.accept(entity);
} catch (Throwable throwable) {
if (throwable instanceof ThreadDeath) throw throwable; // Paper