Skip to content

Commit

Permalink
Add local redstone implementation API
Browse files Browse the repository at this point in the history
  • Loading branch information
Samsuik committed Nov 29, 2023
1 parent 5a6a5aa commit b8f3546
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,20 @@ index 0000000000000000000000000000000000000000..34a0755da6c471a51fb18a5e139af42d
+}
diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
new file mode 100644
index 0000000000000000000000000000000000000000..4735e5d8dcea4835061b5cada9d601794efdf390
index 0000000000000000000000000000000000000000..ee3057c7969956b9c552ac5ceb2f5e38a30e9cdf
--- /dev/null
+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
@@ -0,0 +1,38 @@
@@ -0,0 +1,27 @@
+package me.samsuik.sakura.local;
+
+import me.samsuik.sakura.physics.PhysicsVersion;
+import org.bukkit.Material;
+import org.bukkit.NamespacedKey;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Supplier;
+
+public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) {
+
+ // ...
+ public static final LocalValueKey<PhysicsVersion> PHYSICS_VERSION = new LocalValueKey<>(
+ new NamespacedKey("sakura", "physics-version"), () -> PhysicsVersion.LATEST
+ );
+
+ public static final LocalValueKey<Map<Material, Map.Entry<Integer, Float>>> DURABLE_MATERIALS = new LocalValueKey<>(
+ new NamespacedKey("sakura", "durable-materials"), HashMap::new
+ );
+
+ @Override
+ public boolean equals(Object o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ Date: Tue, 21 Nov 2023 14:53:27 +0000
Subject: [PATCH] Add physics version API


diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
index ee3057c7969956b9c552ac5ceb2f5e38a30e9cdf..f16ea4550f3fb32bcc39d0fe735849264ce02658 100644
--- a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
@@ -1,5 +1,6 @@
package me.samsuik.sakura.local;

+import me.samsuik.sakura.physics.PhysicsVersion;
import org.bukkit.NamespacedKey;

import java.util.Objects;
@@ -8,6 +9,9 @@ import java.util.function.Supplier;
public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) {

// ...
+ public static final LocalValueKey<PhysicsVersion> PHYSICS_VERSION = new LocalValueKey<>(
+ new NamespacedKey("sakura", "physics-version"), () -> PhysicsVersion.LATEST
+ );

@Override
public boolean equals(Object o) {
diff --git a/src/main/java/me/samsuik/sakura/physics/PhysicsVersion.java b/src/main/java/me/samsuik/sakura/physics/PhysicsVersion.java
new file mode 100644
index 0000000000000000000000000000000000000000..b27a757b6d3d43df589947fa65857011da920529
Expand Down
33 changes: 33 additions & 0 deletions patches/api/0009-Add-durable-material-API.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <[email protected]>
Date: Wed, 29 Nov 2023 22:18:17 +0000
Subject: [PATCH] Add durable material API


diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
index f16ea4550f3fb32bcc39d0fe735849264ce02658..3beb5830d623e72a3f4dec63aedc8b69a6396bf0 100644
--- a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
@@ -1,8 +1,11 @@
package me.samsuik.sakura.local;

import me.samsuik.sakura.physics.PhysicsVersion;
+import org.bukkit.Material;
import org.bukkit.NamespacedKey;

+import java.util.HashMap;
+import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier;

@@ -13,6 +16,10 @@ public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) {
new NamespacedKey("sakura", "physics-version"), () -> PhysicsVersion.LATEST
);

+ public static final LocalValueKey<Map<Material, Map.Entry<Integer, Float>>> DURABLE_MATERIALS = new LocalValueKey<>(
+ new NamespacedKey("sakura", "durable-materials"), HashMap::new
+ );
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
54 changes: 54 additions & 0 deletions patches/api/0010-Add-redstone-implementation-API.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <[email protected]>
Date: Wed, 29 Nov 2023 22:11:36 +0000
Subject: [PATCH] Add redstone implementation API


diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
index 3beb5830d623e72a3f4dec63aedc8b69a6396bf0..1a725c1f349b9b8f86c118e579004d7974f016fd 100644
--- a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
@@ -1,6 +1,7 @@
package me.samsuik.sakura.local;

import me.samsuik.sakura.physics.PhysicsVersion;
+import me.samsuik.sakura.redstone.RedstoneImplementation;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;

@@ -20,6 +21,10 @@ public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) {
new NamespacedKey("sakura", "durable-materials"), HashMap::new
);

+ public static final LocalValueKey<RedstoneImplementation> REDSTONE_IMPLEMENTATION = new LocalValueKey<>(
+ new NamespacedKey("sakura", "redstone-implementation"), () -> RedstoneImplementation.VANILLA
+ );
+
@Override
public boolean equals(Object o) {
if (this == o) return true;
diff --git a/src/main/java/me/samsuik/sakura/redstone/RedstoneImplementation.java b/src/main/java/me/samsuik/sakura/redstone/RedstoneImplementation.java
new file mode 100644
index 0000000000000000000000000000000000000000..f89b5112d98d351435c63b27c64b1a981b8a820f
--- /dev/null
+++ b/src/main/java/me/samsuik/sakura/redstone/RedstoneImplementation.java
@@ -0,0 +1,19 @@
+package me.samsuik.sakura.redstone;
+
+public enum RedstoneImplementation {
+
+ VANILLA("vanilla"),
+ EIGENCRAFT("eigencraft"),
+ ALTERNATE_CURRENT("alternate-current");
+
+ private final String friendlyName;
+
+ RedstoneImplementation(String friendlyName) {
+ this.friendlyName = friendlyName;
+ }
+
+ public String getFriendlyName() {
+ return friendlyName;
+ }
+
+}
16 changes: 13 additions & 3 deletions patches/server/0005-Local-Config-and-Value-Storage-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,20 @@ index 0000000000000000000000000000000000000000..3508755c11cc8f577d27a440f2f4a08d
+}
diff --git a/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java b/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..90f0d417bdc9d27c16cf8500aae9152f7d0406c5
index 0000000000000000000000000000000000000000..fbd877356594f0cf8934452522cef4349801e5d7
--- /dev/null
+++ b/src/main/java/me/samsuik/sakura/local/config/LocalValueConfig.java
@@ -0,0 +1,49 @@
@@ -0,0 +1,59 @@
+package me.samsuik.sakura.local.config;
+
+import io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation;
+import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
+import me.samsuik.sakura.explosion.durable.DurableMaterial;
+import me.samsuik.sakura.local.LocalValueKey;
+import me.samsuik.sakura.local.storage.LocalValueStorage;
+import me.samsuik.sakura.physics.PhysicsVersion;
+import me.samsuik.sakura.utils.objects.Expiry;
+import net.minecraft.world.level.Level;
+import me.samsuik.sakura.physics.PhysicsVersion;
+import net.minecraft.world.level.block.Block;
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
+
Expand All @@ -178,6 +179,7 @@ index 0000000000000000000000000000000000000000..90f0d417bdc9d27c16cf8500aae9152f
+ private final Expiry expiry;
+ public Map<Block, DurableMaterial> durableMaterials;
+ public PhysicsVersion physicsVersion;
+ public RedstoneImplementation redstoneImplementation;
+
+ LocalValueConfig(Expiry expiry) {
+ this.expiry = expiry;
Expand All @@ -189,6 +191,9 @@ index 0000000000000000000000000000000000000000..90f0d417bdc9d27c16cf8500aae9152f
+
+ // physics version
+ this.physicsVersion = level.sakuraConfig().cannons.mechanics.physicsVersion;
+
+ // redstone implementation
+ this.redstoneImplementation = level.paperConfig().misc.redstoneImplementation;
+ }
+
+ void load(LocalValueStorage storage) {
Expand All @@ -201,6 +206,11 @@ index 0000000000000000000000000000000000000000..90f0d417bdc9d27c16cf8500aae9152f
+ if (storage.exists(LocalValueKey.PHYSICS_VERSION)) {
+ this.physicsVersion = storage.value(LocalValueKey.PHYSICS_VERSION);
+ }
+
+ // redstone implementation
+ if (storage.exists(LocalValueKey.REDSTONE_IMPLEMENTATION)) {
+ this.redstoneImplementation = RedstoneImplementation.values()[storage.value(LocalValueKey.REDSTONE_IMPLEMENTATION).ordinal()];
+ }
+ }
+
+ Expiry expiry() {
Expand Down
73 changes: 73 additions & 0 deletions patches/server/0047-Add-redstone-implementation-API.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <[email protected]>
Date: Wed, 29 Nov 2023 22:32:44 +0000
Subject: [PATCH] Add redstone implementation API


diff --git a/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java b/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java
index 7eb617150d278f5b40f097cd402d55fd781e0616..73199366579f8816165b57b1ce7bdc95935b8066 100644
--- a/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/RedStoneWireBlock.java
@@ -262,7 +262,7 @@ public class RedStoneWireBlock extends Block {
* Note: Added 'source' argument so as to help determine direction of information flow
*/
private void updateSurroundingRedstone(Level worldIn, BlockPos pos, BlockState state, BlockPos source) {
- if (worldIn.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.EIGENCRAFT) {
+ if (worldIn.localConfig().config(pos).redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.EIGENCRAFT) { // Sakura
turbo.updateSurroundingRedstone(worldIn, pos, state, source);
return;
}
@@ -286,7 +286,7 @@ public class RedStoneWireBlock extends Block {
int k = worldIn.getBestNeighborSignal(pos1);
this.shouldSignal = true;

- if (worldIn.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.VANILLA) {
+ if (worldIn.localConfig().config(pos1).redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.VANILLA) { // Sakura
// This code is totally redundant to if statements just below the loop.
if (k > 0 && k > j - 1) {
j = k;
@@ -300,7 +300,7 @@ public class RedStoneWireBlock extends Block {
// redstone wire will be set to 'k'. If 'k' is already 15, then nothing inside the
// following loop can affect the power level of the wire. Therefore, the loop is
// skipped if k is already 15.
- if (worldIn.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.VANILLA || k < 15) {
+ if (worldIn.localConfig().config(pos1).redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.VANILLA || k < 15) { // Sakura
for (Direction enumfacing : Direction.Plane.HORIZONTAL) {
BlockPos blockpos = pos1.relative(enumfacing);
boolean flag = blockpos.getX() != pos2.getX() || blockpos.getZ() != pos2.getZ();
@@ -319,7 +319,7 @@ public class RedStoneWireBlock extends Block {
}
}

- if (worldIn.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.VANILLA) {
+ if (worldIn.localConfig().config(pos1).redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.VANILLA) { // Sakura
// The old code would decrement the wire value only by 1 at a time.
if (l > j) {
j = l - 1;
@@ -472,7 +472,7 @@ public class RedStoneWireBlock extends Block {
public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify) {
if (!oldState.is(state.getBlock()) && !world.isClientSide) {
// Paper start - optimize redstone - replace call to updatePowerStrength
- if (world.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) {
+ if (world.localConfig().config(pos).redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) { // Sakura
world.getWireHandler().onWireAdded(pos); // Alternate Current
} else {
this.updateSurroundingRedstone(world, pos, state, null); // vanilla/Eigencraft
@@ -505,7 +505,7 @@ public class RedStoneWireBlock extends Block {
}

// Paper start - optimize redstone - replace call to updatePowerStrength
- if (world.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) {
+ if (world.localConfig().config(pos).redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) { // Sakura
world.getWireHandler().onWireRemoved(pos, state); // Alternate Current
} else {
this.updateSurroundingRedstone(world, pos, state, null); // vanilla/Eigencraft
@@ -546,7 +546,7 @@ public class RedStoneWireBlock extends Block {
if (!world.isClientSide) {
// Paper start - optimize redstone (Alternate Current)
// Alternate Current handles breaking of redstone wires in the WireHandler.
- if (world.paperConfig().misc.redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) {
+ if (world.localConfig().config(pos).redstoneImplementation == io.papermc.paper.configuration.WorldConfiguration.Misc.RedstoneImplementation.ALTERNATE_CURRENT) { // Sakura
world.getWireHandler().onWireUpdated(pos);
} else
// Paper end

0 comments on commit b8f3546

Please sign in to comment.