mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-21 07:49:29 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@c0a3d51 Start update, apply API patches PaperMC/Paper@172c7dc Work PaperMC/Paper@ab9a3db More work PaperMC/Paper@c60e47f More more work PaperMC/Paper@bd55e32 More more more work PaperMC/Paper@5265287 More more more more work PaperMC/Paper@4601dc9 Some fixes, start updating CustomModelData API PaperMC/Paper@2331dad Even more work PaperMC/Paper@dc74c6f moonrise PaperMC/Paper@d7d2f88 Apply remaining patches, fix API PaperMC/Paper@f863bb7 Update generated classes PaperMC/Paper@71a4ef8 Set java launcher for api generate task PaperMC/Paper@b8aeecb Compilation fixes PaperMC/Paper@6c35392 Tests succeed (by removing one) PaperMC/Paper@b0603da Fix jd gson version, move back mc util diff PaperMC/Paper@e2dd1d5 Add back post_teleport chunk ticket PaperMC/Paper@7045b2a Update DataConverter PaperMC/Paper@65633e3 Update Moonrise
96 lines
4.1 KiB
Diff
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..aeb5f128b369753cb20b7310fa382ddf2b6e8f0f
|
|
--- /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.level.block.Blocks;
|
|
+import net.minecraft.world.phys.AABB;
|
|
+import net.minecraft.world.phys.Vec3;
|
|
+import org.jspecify.annotations.NullMarked;
|
|
+
|
|
+import java.util.Optional;
|
|
+
|
|
+@NullMarked
|
|
+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(this.position);
|
|
+ entity.setDeltaMovement(this.momentum);
|
|
+ entity.setBoundingBox(this.bb);
|
|
+ entity.makeStuckInBlock(Blocks.AIR.defaultBlockState(), this.stuckSpeed);
|
|
+ entity.onGround = this.onGround;
|
|
+ entity.mainSupportingBlockPos = this.supportingPos;
|
|
+ entity.fallDistance = this.fallDistance;
|
|
+ }
|
|
+
|
|
+ public void applyEntityPosition(Entity entity) {
|
|
+ entity.setPos(this.position);
|
|
+ entity.setBoundingBox(this.bb);
|
|
+ }
|
|
+
|
|
+ public boolean comparePositionAndMotion(Entity entity) {
|
|
+ return entity.position().equals(this.position)
|
|
+ && entity.getDeltaMovement().equals(this.momentum);
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index 384b64cfbc2fef49fa22baf1f640ea8f440093cd..316ab62995a7804cf85a2cb986b22e15cd22b01c 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -586,6 +586,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().comparePositionAndMotion(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 13e8ac95daa115720a2b1f52ad33d124351cbd6d..c69c04451c61bcc32e539baae160f05e3418841f 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
|
@@ -1500,6 +1500,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
|