mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-22 00:09:20 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@b4f04ff Add Plugin#getDataPath (#11080) PaperMC/Paper@05e5865 Add ItemType#getItemRarity (#11049) PaperMC/Paper@aa929d6 Call PlayerLaunchProjectileEvent for wind charge (#10911) PaperMC/Paper@8b23018 Avoid collision shapes outside world border in findFreePosition PaperMC/Paper@3b45454 Port random ticking optimisation from Moonrise PaperMC/Paper@77fcb29 Apply incremental player/level saving patch PaperMC/Paper@9fd7710 Apply automatic regionfile header recalculation patch PaperMC/Paper@b57b24d Do not try to stop main thread during watchdog shutdown PaperMC/Paper@2cd8c46 Add OMINOUS_ITEM_SPAWNER SpawnReason (#10897) PaperMC/Paper@ef96a69 Fire EntityChangeBlockEvent for weaving potion effect (#11087) PaperMC/Paper@a6ceda1 distinguish between null and empty map in API (#10829) PaperMC/Paper@506f165 Don't store removed components in multiple places (#11091) PaperMC/Paper@ceeb8c1 Disable timings by default (#11095) PaperMC/Paper@05ed6a6 Fix priority scheduling logic PaperMC/Paper@967f98a Optimise chunk tick checking during chunk tick PaperMC/Paper@00b949f Remove Moonrise utils to MCUtils, remove duplicated/unused utils PaperMC/Paper@4efd24b Remove unused chunk system hooks in MCUtils PaperMC/Paper@b653276 Finish chunk tick iteration optimisation port from Moonrise PaperMC/Paper@2df5bba Log throwable when failing to save chunk/poi/entity data PaperMC/Paper@44c3dd0 fix exact choice shapeless recipes (#10973) PaperMC/Paper@dd11ef8 Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11102) PaperMC/Paper@3c8a7fe Re-add missing chunk event calls (#11104) PaperMC/Paper@a8db527 Even more cleanup of mcutil patch PaperMC/Paper@d08e8d1 Add total time to done message (#11109) PaperMC/Paper@2a39276 Add CrafterCraftEvent (#11082) PaperMC/Paper@75af62b Split rewriting flag into `paper.disableOldApiSupport` and `paper.disablePluginRemapping` (#11108) PaperMC/Paper@7ea4039 Fixup startup time log message PaperMC/Paper@e71c1df Call PlayerChunkUnloadEvent PaperMC/Paper@968bdeb Make CraftComplexRecipe extend CraftingRecipe (#11114) PaperMC/Paper@f1f01a1 Adjust done message again (#11118)
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..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 8306bf3943e65fdff93d76b0c97f0f1d8d0db6d3..49ae460ba5b871f085d67a0c4abdc0e7096ca3e1 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -568,6 +568,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..dd8e5c0a6197158b376e8de8930f660fc4771e54 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 state
|
|
tickConsumer.accept(entity);
|
|
} catch (Throwable throwable) {
|
|
if (throwable instanceof ThreadDeath) throw throwable; // Paper
|