Skip to content

Commit

Permalink
Rename merge level NON_STRICT to LENIENT
Browse files Browse the repository at this point in the history
  • Loading branch information
Samsuik committed May 8, 2024
1 parent 2a34b35 commit 22410ee
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 66 deletions.
27 changes: 13 additions & 14 deletions patches/api/0004-Merge-Cannon-Entities.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Subject: [PATCH] Merge Cannon Entities

diff --git a/src/main/java/me/samsuik/sakura/entity/merge/MergeLevel.java b/src/main/java/me/samsuik/sakura/entity/merge/MergeLevel.java
new file mode 100644
index 0000000000000000000000000000000000000000..16e68720eaf2eeedb2ba9bb906c21a16fc818e89
index 0000000000000000000000000000000000000000..506ea3cb8c3b965661a65f9a91903999c1eba309
--- /dev/null
+++ b/src/main/java/me/samsuik/sakura/entity/merge/MergeLevel.java
@@ -0,0 +1,65 @@
@@ -0,0 +1,64 @@
+package me.samsuik.sakura.entity.merge;
+
+import java.util.Locale;
Expand All @@ -20,21 +20,20 @@ index 0000000000000000000000000000000000000000..16e68720eaf2eeedb2ba9bb906c21a16
+ */
+ NONE(-1),
+ /**
+ * Merge entities with the same OOE, properties and position.
+ * This is safe for all use cases and won't cause breakage.
+ * "STRICT" merges entities with the same properties, position, momentum and OOE.
+ * This is considered safe to use, and will not break cannon mechanics.
+ */
+ STRICT(1),
+ /**
+ * Merge entities with the same properties and position.
+ * If the entities are known to have merged in the past
+ * this will be able to merge them together regardless of OOE.
+ * "LENIENT" merges entities aggressively by tracking the entities that have
+ * previously merged. This is a hybrid of "SPAWN" and "STRICT" merging, with the
+ * visuals of "STRICT" merging and better merging potential of "SPAWN" merging.
+ */
+ NON_STRICT(2),
+ LENIENT(2),
+ /**
+ * This will make sure of Non-Strict as a base, once the cannon
+ * has past the "on spawn" merge threshold it will be deemed safe
+ * for on spawn merging. This will merge all entities together on
+ * spawn that have merged together in the past.
+ * "SPAWN" merges entities one gametick after they have spawned. Merging is
+ * only possible after it has been established that the entity is safe to
+ * merge by collecting information on the entities that merge together over time.
+ */
+ SPAWN(3);
+
Expand Down Expand Up @@ -95,7 +94,7 @@ index 0000000000000000000000000000000000000000..c241a3a359cad1d7c2cdb690649e0cac
+ void setStacked(int stacked);
+}
diff --git a/src/main/java/org/bukkit/entity/FallingBlock.java b/src/main/java/org/bukkit/entity/FallingBlock.java
index 95e75f5a4ccdedd3b26f8639f37de9450ed63d6b..be52a64e73e7880c6a28d8a6912923973b7cb13b 100644
index 7904c716a3b0869ebf2f9b416536c59121a539a8..2479453b96a75fda2c307261f84c91034e73000d 100644
--- a/src/main/java/org/bukkit/entity/FallingBlock.java
+++ b/src/main/java/org/bukkit/entity/FallingBlock.java
@@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull;
Expand All @@ -108,7 +107,7 @@ index 95e75f5a4ccdedd3b26f8639f37de9450ed63d6b..be52a64e73e7880c6a28d8a691292397
/**
* Get the Material of the falling block
diff --git a/src/main/java/org/bukkit/entity/TNTPrimed.java b/src/main/java/org/bukkit/entity/TNTPrimed.java
index 0813bd913c8fdb2001963ce3e82c07c2af105418..0bc227b6ba953c778ac950ec40f99276c77e880c 100644
index 87e717c9ea61b0cbf536bc62fa829ddcfae5ad8c..ba84b3cbbd3358b16b21a18baa9c1812733fc144 100644
--- a/src/main/java/org/bukkit/entity/TNTPrimed.java
+++ b/src/main/java/org/bukkit/entity/TNTPrimed.java
@@ -6,7 +6,7 @@ import org.jetbrains.annotations.Nullable;
Expand Down
51 changes: 47 additions & 4 deletions patches/server/0003-Sakura-Configuration-Files.patch
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,10 @@ index 0000000000000000000000000000000000000000..5296d4e0a1041932e36562f42fbf3e1d
+}
diff --git a/src/main/java/me/samsuik/sakura/configuration/SakuraConfigurations.java b/src/main/java/me/samsuik/sakura/configuration/SakuraConfigurations.java
new file mode 100644
index 0000000000000000000000000000000000000000..04dc81634277d05894076a2cafde60ca35e1886e
index 0000000000000000000000000000000000000000..f8770f97e3ad6c2746bc436b2b2c895cecd43996
--- /dev/null
+++ b/src/main/java/me/samsuik/sakura/configuration/SakuraConfigurations.java
@@ -0,0 +1,251 @@
@@ -0,0 +1,253 @@
+package me.samsuik.sakura.configuration;
+
+import com.google.common.collect.Table;
Expand All @@ -417,6 +417,7 @@ index 0000000000000000000000000000000000000000..04dc81634277d05894076a2cafde60ca
+import it.unimi.dsi.fastutil.objects.Reference2LongOpenHashMap;
+import me.samsuik.sakura.configuration.transformation.world.V3_RenameKnockback;
+import me.samsuik.sakura.configuration.transformation.world.V2_VerticalKnockbackUseDefault;
+import me.samsuik.sakura.configuration.transformation.world.V4_RenameNonStrictMergeLevel;
+import net.minecraft.core.RegistryAccess;
+import net.minecraft.core.registries.Registries;
+import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -579,6 +580,7 @@ index 0000000000000000000000000000000000000000..04dc81634277d05894076a2cafde60ca
+ final ConfigurationTransformation.VersionedBuilder versionedBuilder = Transformations.versionedBuilder();
+ V2_VerticalKnockbackUseDefault.apply(versionedBuilder);
+ V3_RenameKnockback.apply(versionedBuilder);
+ V4_RenameNonStrictMergeLevel.apply(versionedBuilder);
+ // ADD FUTURE VERSIONED TRANSFORMS TO versionedBuilder HERE
+ versionedBuilder.build().apply(node);
+ }
Expand Down Expand Up @@ -645,7 +647,7 @@ index 0000000000000000000000000000000000000000..04dc81634277d05894076a2cafde60ca
+}
diff --git a/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java b/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java
new file mode 100644
index 0000000000000000000000000000000000000000..a019905f4fb7ec8743136ca406584dbcc73801f5
index 0000000000000000000000000000000000000000..0d015331a5143a0e45c4576e1ba51e50b2d46d87
--- /dev/null
+++ b/src/main/java/me/samsuik/sakura/configuration/WorldConfiguration.java
@@ -0,0 +1,199 @@
Expand Down Expand Up @@ -680,7 +682,7 @@ index 0000000000000000000000000000000000000000..a019905f4fb7ec8743136ca406584dbc
+public class WorldConfiguration extends ConfigurationPart {
+
+ private static final Logger LOGGER = LogUtils.getClassLogger();
+ static final int CURRENT_VERSION = 3; // (when you change the version, change the comment, so it conflicts on rebases): rename filter bad nbt from spawn eggs
+ static final int CURRENT_VERSION = 4; // (when you change the version, change the comment, so it conflicts on rebases): rename filter bad nbt from spawn eggs
+
+ private transient final ResourceLocation worldKey;
+ WorldConfiguration(ResourceLocation worldKey) {
Expand Down Expand Up @@ -918,6 +920,47 @@ index 0000000000000000000000000000000000000000..efba1f83cb079d0e75904adc439b715d
+ builder.addVersion(VERSION, transformationBuilder.build());
+ }
+}
diff --git a/src/main/java/me/samsuik/sakura/configuration/transformation/world/V4_RenameNonStrictMergeLevel.java b/src/main/java/me/samsuik/sakura/configuration/transformation/world/V4_RenameNonStrictMergeLevel.java
new file mode 100644
index 0000000000000000000000000000000000000000..198eb5f030ec5def4d93dec51dde352261654bb5
--- /dev/null
+++ b/src/main/java/me/samsuik/sakura/configuration/transformation/world/V4_RenameNonStrictMergeLevel.java
@@ -0,0 +1,35 @@
+package me.samsuik.sakura.configuration.transformation.world;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.spongepowered.configurate.ConfigurateException;
+import org.spongepowered.configurate.ConfigurationNode;
+import org.spongepowered.configurate.NodePath;
+import org.spongepowered.configurate.transformation.ConfigurationTransformation;
+import org.spongepowered.configurate.transformation.TransformAction;
+
+import java.util.Locale;
+
+import static org.spongepowered.configurate.NodePath.path;
+
+public final class V4_RenameNonStrictMergeLevel implements TransformAction {
+ private static final int VERSION = 4;
+ private static final String OLD_LEVEL_NAME = "NON_STRICT";
+ private static final String NEW_LEVEL_NAME = "LENIENT";
+ private static final NodePath PATH = path("cannons", "merge-level");
+ private static final V4_RenameNonStrictMergeLevel INSTANCE = new V4_RenameNonStrictMergeLevel();
+
+ private V4_RenameNonStrictMergeLevel() {}
+
+ public static void apply(ConfigurationTransformation.VersionedBuilder builder) {
+ builder.addVersion(VERSION, ConfigurationTransformation.builder().addAction(PATH, INSTANCE).build());
+ }
+
+ @Override
+ public Object @Nullable [] visitPath(NodePath path, ConfigurationNode value) throws ConfigurateException {
+ String level = value.getString();
+ if (level != null && OLD_LEVEL_NAME.equals(level.toUpperCase(Locale.ENGLISH))) {
+ value.set(NEW_LEVEL_NAME);
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/me/samsuik/sakura/explosion/durable/DurableMaterial.java b/src/main/java/me/samsuik/sakura/explosion/durable/DurableMaterial.java
new file mode 100644
index 0000000000000000000000000000000000000000..4024f9738e039ffffd560a07a2210f758879d3c0
Expand Down
35 changes: 17 additions & 18 deletions patches/server/0018-Merge-Cannon-Entities.patch
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ index 55e0be135ec084ee7ebe6bc7bb9323519e0cd864..51fa57e8b9d5c9ee563ec3608a437c69
this.guardEntityTick(this::tickNonPassenger, entity);
gameprofilerfiller.pop();
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index e657b5f88195f1db2cb9a9a97f255ff23992cadd..a81dde7251255aa0966498c1c8449492dae537a9 100644
index e657b5f88195f1db2cb9a9a97f255ff23992cadd..5e155cdf66701f96dd0b831603c714b5a47d74c0 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -603,6 +603,117 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@@ -603,6 +603,116 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
return to.entityState() != null && to.entityState().isCurrentState(this);
}
// Sakura end - store entity data/state
Expand Down Expand Up @@ -264,31 +264,30 @@ index e657b5f88195f1db2cb9a9a97f255ff23992cadd..a81dde7251255aa0966498c1c8449492
+ }
+
+ public final boolean tryMergeInto(@Nullable Entity entity) {
+ if (mergeLevel.atLeast(me.samsuik.sakura.entity.merge.MergeLevel.NON_STRICT) && tickCount == 0) {
+ if (mergeLevel.atLeast(me.samsuik.sakura.entity.merge.MergeLevel.LENIENT) && tickCount == 0) {
+ originData = level.mergeHistory.retrievePositions(this);
+ }
+
+ Entity mergeEntity = null;
+
+ if (entity == null || entity.getType() != getType()) {
+ // first entity in the tick loop, we have to let it into this method so that we can retrieve the originData
+ return false;
+ return false; // First entity
+ } else if (mergeLevel.atLeast(me.samsuik.sakura.entity.merge.MergeLevel.SPAWN) && entity.isSafeToSpawnMerge(this)) {
+ // On spawn merging, this merges entities immediately upon spawning after
+ // it is considered "safe". We try to make sure it is safe by only retaining
+ // positions that do not change when we're collecting information.
+ // "SPAWN" merges entities one gametick after they have spawned. Merging is
+ // only possible after it has been established that the entity is safe to
+ // merge by collecting information on the entities that merge together over time.
+ mergeEntity = entity;
+ } else {
+ // Strict, simple merging
+ // This merges entities that are in the exact same state and sequential.
+ // Sane for most use cases but as it is merging entities plugins may misbehave.
+ // "STRICT" merges entities with the same properties, position, momentum and OOE.
+ // This is considered safe to use, and will not break cannon mechanics.
+ if (mergeLevel.atLeast(me.samsuik.sakura.entity.merge.MergeLevel.STRICT) && compareState(entity)) {
+ mergeEntity = entity;
+ }
+
+ // Non strict merging algorithm uses information collected after entities die
+ // to be able to perform more aggressive merging by already knowing the OOE.
+ if (mergeLevel.atLeast(me.samsuik.sakura.entity.merge.MergeLevel.NON_STRICT) && mergeEntity == null && originData != null) {
+ // "LENIENT" merges entities aggressively by tracking the entities that have
+ // previously merged. This is a hybrid of "SPAWN" and "STRICT" merging, with the
+ // visuals of "STRICT" merging and better merging potential of "SPAWN" merging.
+ if (mergeLevel.atLeast(me.samsuik.sakura.entity.merge.MergeLevel.LENIENT) && mergeEntity == null && originData != null) {
+ mergeEntity = originData.findFirstEntityInSamePosition(this);
+ }
+ }
Expand Down Expand Up @@ -330,15 +329,15 @@ index e657b5f88195f1db2cb9a9a97f255ff23992cadd..a81dde7251255aa0966498c1c8449492

public Entity(EntityType<?> type, Level world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
@@ -651,6 +762,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@@ -651,6 +761,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
this.getEntityData().registrationLocked = true; // Spigot
this.setPos(0.0D, 0.0D, 0.0D);
this.eyeHeight = this.getEyeHeight(net.minecraft.world.entity.Pose.STANDING, this.dimensions);
+ this.mergeLevel = level.sakuraConfig().cannons.mergeLevel; // Sakura
}

public boolean isColliding(BlockPos pos, BlockState state) {
@@ -2533,6 +2645,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@@ -2533,6 +2644,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
nbttagcompound.putBoolean("Paper.FreezeLock", true);
}
// Paper end
Expand All @@ -350,7 +349,7 @@ index e657b5f88195f1db2cb9a9a97f255ff23992cadd..a81dde7251255aa0966498c1c8449492
return nbttagcompound;
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
@@ -2680,6 +2797,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@@ -2680,6 +2796,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
freezeLocked = nbt.getBoolean("Paper.FreezeLock");
}
// Paper end
Expand All @@ -362,7 +361,7 @@ index e657b5f88195f1db2cb9a9a97f255ff23992cadd..a81dde7251255aa0966498c1c8449492

} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
@@ -4889,6 +5011,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@@ -4889,6 +5010,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
// Paper end - rewrite chunk system
CraftEventFactory.callEntityRemoveEvent(this, cause);
// CraftBukkit end
Expand Down
8 changes: 4 additions & 4 deletions patches/server/0022-Optimise-Fast-Movement.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Optimise Fast Movement


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index a81dde7251255aa0966498c1c8449492dae537a9..08a5558679da5602f05f2f052cb841d008d866cc 100644
index 5e155cdf66701f96dd0b831603c714b5a47d74c0..f6ce2eea92bbea846ec62c7406d19cb3423d0d8d 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1236,6 +1236,95 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@@ -1235,6 +1235,95 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
}
// Paper end - detailed watchdog information

Expand Down Expand Up @@ -104,7 +104,7 @@ index a81dde7251255aa0966498c1c8449492dae537a9..08a5558679da5602f05f2f052cb841d0
public void move(MoverType movementType, Vec3 movement) {
final Vec3 originalMovement = movement; // Paper - Expose pre-collision velocity
// Paper start - detailed watchdog information
@@ -1614,6 +1703,95 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@@ -1613,6 +1702,95 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
return offsetFactor;
}

Expand Down Expand Up @@ -214,7 +214,7 @@ index 99a0bec7eb5be527b41248b365b037a5e42a3270..16a8b667f50700a85f1c14f3a7ed3098
if (this.level().paperConfig().fixes.fallingBlockHeightNerf.test(v -> this.getY() > v)) {
if (this.dropItem && this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
diff --git a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
index 30c3e31148d23998ce9007691c30d1d518a2b86d..491dab62dda6e24bda5b01364a2adbf51ad74ef6 100644
index 8acef487b0579febb3497cc88b23c4fc74492571..9acbc8d5a0c25d7613bfc0c21757ca563954cc0a 100644
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
@@ -96,7 +96,7 @@ public class PrimedTnt extends Entity implements TraceableEntity {
Expand Down
6 changes: 3 additions & 3 deletions patches/server/0024-isPushedByFluid-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ Subject: [PATCH] isPushedByFluid API


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 08a5558679da5602f05f2f052cb841d008d866cc..24dcf92c85d4453564d3ca51687a59497d8182fe 100644
index f6ce2eea92bbea846ec62c7406d19cb3423d0d8d..09f38e36e89cb75a45bf88c9779960fed9183930 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -714,6 +714,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@@ -713,6 +713,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
}
}
// Sakura end - cannon entity merging
+ public boolean pushedByFluid = true; // Sakura - entity pushed by fluid api

public Entity(EntityType<?> type, Level world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
@@ -4252,7 +4253,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@@ -4251,7 +4252,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
}

public boolean isPushedByFluid() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Optimise TNT fluid state and pushing


diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 24dcf92c85d4453564d3ca51687a59497d8182fe..e3b6ef30a3c983e7e9b6bd83bc7baa600b16d850 100644
index 09f38e36e89cb75a45bf88c9779960fed9183930..a4dc4154550bb4bd30d3e548f145cff5c693dc18 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2199,7 +2199,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
@@ -2198,7 +2198,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
return this.isInWater() || flag;
}

Expand All @@ -18,7 +18,7 @@ index 24dcf92c85d4453564d3ca51687a59497d8182fe..e3b6ef30a3c983e7e9b6bd83bc7baa60

if (entity instanceof Boat) {
diff --git a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
index 403cfb14dff46a405a1476f6806020e9a2c9a941..b4b509bcdd470ff21bbe6e0c3f58848c168bc120 100644
index 37c719bd4baf3c38e3e89728e3f9a413743c2241..76ac9d119933b0558b28eff3bee7c96f92c5c642 100644
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
@@ -94,6 +94,19 @@ public class PrimedTnt extends Entity implements TraceableEntity {
Expand Down
Loading

0 comments on commit 22410ee

Please sign in to comment.