mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-20 07:19:33 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@dc3ef2a Fix vanilla components not being translated (#9893) PaperMC/Paper@7e15d97 Remove no longer needed diff from adventure patch PaperMC/Paper@f1820dc Fix incorrect border collision detection PaperMC/Paper@de04cbc Updated Upstream (Bukkit/CraftBukkit) (#10034) PaperMC/Paper@ff26d54 send sound and particle packets immediately even if off main (#10033) PaperMC/Paper@e3140fb hotfix spawning item/xp in wrong spot PaperMC/Paper@0b95298 Make worldborder collisions consistent with Vanilla PaperMC/Paper@47b2c18 Don't fire the drop event on player deaths (#10046) PaperMC/Paper@8c007d9 properly read and store sus effect duration (#10050) PaperMC/Paper@5385b21 [ci skip] Make test results viewable in-browser and downloadable (#10055) PaperMC/Paper@086ca61 Fix world border edge collision (#10053) PaperMC/Paper@45e01a2 Use correct max stack size in crafter (#10057) PaperMC/Paper@d11a588 Remove duplicate code in chunk tick iteration (#10056) PaperMC/Paper@b4c9e7e add missing Experimental annotations (#10012)
105 lines
4.4 KiB
Diff
105 lines
4.4 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 d69dfd44a9ff3ee6861042fa8f5a64c2031815cd..70ca40c87c161d96a3661066386f2560d0aeca6d 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -550,6 +550,34 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
return flags;
|
|
}
|
|
// Sakura end
|
|
+ // Sakura start - entity state (from start of tick)
|
|
+ private @Nullable me.samsuik.sakura.entity.EntityState entityState = null;
|
|
+
|
|
+ public Vec3 stuckSpeedMultiplier() {
|
|
+ return stuckSpeedMultiplier;
|
|
+ }
|
|
+
|
|
+ public void storeEntityState() {
|
|
+ entityState = me.samsuik.sakura.entity.EntityState.of(this);
|
|
+ }
|
|
+
|
|
+ public @Nullable me.samsuik.sakura.entity.EntityState entityState() {
|
|
+ return entityState;
|
|
+ }
|
|
+
|
|
+ public boolean compareState(Entity to) {
|
|
+ return to.entityState() != null && to.entityState().isCurrentState(this);
|
|
+ }
|
|
+
|
|
+ public long getPackedOrigin() {
|
|
+ var v = getOriginVector();
|
|
+ if (v == null) return Long.MIN_VALUE;
|
|
+ // Note: vector#getBlockN may not be 100% exact
|
|
+ // If there's any future issues at let's say 0.999999...
|
|
+ // giving an incorrect position change it to Mth instead.
|
|
+ return BlockPos.asLong(v.getBlockX(), v.getBlockY(), v.getBlockZ());
|
|
+ }
|
|
+ // Sakura end
|
|
|
|
public boolean isLegacyTrackingEntity = false;
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
|
|
index 9ef1d77dd87793577223402808ff7a6baad42ee4..862a56ce8de55bdca99af24fcf3909e820a0598e 100644
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
|
@@ -1343,6 +1343,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
|
|
|
public <T extends Entity> void guardEntityTick(Consumer<T> tickConsumer, T entity) {
|
|
try {
|
|
+ entity.storeEntityState(); // Sakura - store entity state
|
|
tickConsumer.accept(entity);
|
|
MinecraftServer.getServer().executeMidTickTasks(); // Paper - execute chunk tasks mid tick
|
|
} catch (Throwable throwable) {
|