3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-16 03:20:07 +01:00
Paper/patches/server/0934-Add-FluidState-API.patch
Bjarne Koll 77a5779e24
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11197)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
2ec53f49 PR-1050: Fix empty result check for Complex Recipes
10671012 PR-1044: Add CrafterCraftEvent
4d87ffe0 Use correct method in JavaDoc
ae5e5817 SPIGOT-7850: Add API for Bogged shear state
46b6d445 SPIGOT-7837: Support data pack banner patterns
d5d0cefc Fix JavaDoc error
b3c2b83d PR-1036: Add API for InventoryView derivatives
1fe2c75a SPIGOT-7809: Add ShieldMeta

CraftBukkit Changes:
8ee6fd1b8 SPIGOT-7857: Improve ItemMeta block data deserialization
8f26c30c6 SPIGOT-7857: Fix spurious internal NBT tag when deserializing BlockStateMeta
759061b93 SPIGOT-7855: Fire does not spread or burn blocks
00fc9fb64 SPIGOT-7853: AnvilInventory#getRepairCost() always returns 0
7501e2e04 PR-1450: Add CrafterCraftEvent
8c51673e7 SPIGOT-5731: PortalCreateEvent#getEntity returns null for nether portals ignited by flint and steel
d53d0d0b1 PR-1456: Fix inverted logic in CraftCrafterView#setSlotDisabled
682a678c8 SPIGOT-7850: Add API for Bogged shear state
fccf5243a SPIGOT-7837: Support data pack banner patterns
9c3bd4390 PR-1431: Add API for InventoryView derivatives
0cc6acbc4 SPIGOT-7849: Fix FoodComponent serialize with "using-converts-to" using null
2c5474952 Don't rely on tags for CraftItemMetas
20d107e46 SPIGOT-7846: Fix ItemMeta for hanging signs
76f59e315 Remove redundant clone in Dropper InventoryMoveItemEvent
e61a53d25 SPIGOT-7817: Call InventoryMoveItemEvent for Crafters
894682e2d SPIGOT-7839: Remove redundant Java version checks
2c12b2187 SPIGOT-7809: Add ShieldMeta and fix setting shield base colours

Spigot Changes:
fb8fb722 Rebuild patches
34bd42b7 SPIGOT-7835: Fix issue with custom hopper settings
2024-08-09 22:05:50 +02:00

209 Zeilen
8.4 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: vicisacat <victor.branchu@gmail.com>
Date: Fri, 17 Nov 2023 20:22:43 +0100
Subject: [PATCH] Add FluidState API
diff --git a/src/main/java/io/papermc/paper/block/fluid/PaperFluidData.java b/src/main/java/io/papermc/paper/block/fluid/PaperFluidData.java
new file mode 100644
index 0000000000000000000000000000000000000000..479bc32241ebadf8bbc1080b601f61391ad37fa4
--- /dev/null
+++ b/src/main/java/io/papermc/paper/block/fluid/PaperFluidData.java
@@ -0,0 +1,110 @@
+package io.papermc.paper.block.fluid;
+
+import com.google.common.base.Preconditions;
+import io.papermc.paper.block.fluid.type.PaperFallingFluidData;
+import io.papermc.paper.block.fluid.type.PaperFlowingFluidData;
+import io.papermc.paper.util.MCUtil;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+import net.minecraft.world.level.material.FluidState;
+import net.minecraft.world.level.material.LavaFluid;
+import net.minecraft.world.level.material.WaterFluid;
+import org.bukkit.Fluid;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.CraftFluid;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.util.CraftVector;
+import org.bukkit.util.Vector;
+import org.jetbrains.annotations.NotNull;
+
+public class PaperFluidData implements FluidData {
+
+ private final FluidState state;
+
+ protected PaperFluidData(final FluidState state) {
+ this.state = state;
+ }
+
+ /**
+ * Provides the internal server representation of this fluid data.
+ * @return the fluid state.
+ */
+ public FluidState getState() {
+ return this.state;
+ }
+
+ @Override
+ public final @NotNull Fluid getFluidType() {
+ return CraftFluid.minecraftToBukkit(this.state.getType());
+ }
+
+ @Override
+ public @NotNull PaperFluidData clone() {
+ try {
+ return (PaperFluidData) super.clone();
+ } catch (final CloneNotSupportedException ex) {
+ throw new AssertionError("Clone not supported", ex);
+ }
+ }
+
+ @Override
+ public @NotNull Vector computeFlowDirection(final Location location) {
+ Preconditions.checkArgument(location.getWorld() != null, "Cannot compute flow direction on world-less location");
+ return CraftVector.toBukkit(this.state.getFlow(
+ ((CraftWorld) location.getWorld()).getHandle(),
+ MCUtil.toBlockPosition(location)
+ ));
+ }
+
+ @Override
+ public int getLevel() {
+ return this.state.getAmount();
+ }
+
+ @Override
+ public float computeHeight(@NotNull final Location location) {
+ Preconditions.checkArgument(location.getWorld() != null, "Cannot compute height on world-less location");
+ return this.state.getHeight(((CraftWorld) location.getWorld()).getHandle(), MCUtil.toBlockPos(location));
+ }
+
+ @Override
+ public boolean isSource() {
+ return this.state.isSource();
+ }
+
+ @Override
+ public int hashCode() {
+ return this.state.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return obj instanceof final PaperFluidData paperFluidData && this.state.equals(paperFluidData.state);
+ }
+
+ @Override
+ public String toString() {
+ return "PaperFluidData{" + this.state + "}";
+ }
+
+ /* Registry */
+ private static final Map<Class<? extends net.minecraft.world.level.material.Fluid>, Function<FluidState, PaperFluidData>> MAP = new HashMap<>();
+ static {
+ //<editor-fold desc="PaperFluidData Registration" defaultstate="collapsed">
+ register(LavaFluid.Source.class, PaperFallingFluidData::new);
+ register(WaterFluid.Source.class, PaperFallingFluidData::new);
+ register(LavaFluid.Flowing.class, PaperFlowingFluidData::new);
+ register(WaterFluid.Flowing.class, PaperFlowingFluidData::new);
+ //</editor-fold>
+ }
+
+ static void register(final Class<? extends net.minecraft.world.level.material.Fluid> fluid, final Function<FluidState, PaperFluidData> creator) {
+ Preconditions.checkState(MAP.put(fluid, creator) == null, "Duplicate mapping %s->%s", fluid, creator);
+ MAP.put(fluid, creator);
+ }
+
+ public static PaperFluidData createData(final FluidState state) {
+ return MAP.getOrDefault(state.getType().getClass(), PaperFluidData::new).apply(state);
+ }
+}
diff --git a/src/main/java/io/papermc/paper/block/fluid/package-info.java b/src/main/java/io/papermc/paper/block/fluid/package-info.java
new file mode 100644
index 0000000000000000000000000000000000000000..cfabb814ebd281aab299c6c655266ff357e08806
--- /dev/null
+++ b/src/main/java/io/papermc/paper/block/fluid/package-info.java
@@ -0,0 +1,5 @@
+@DefaultQualifier(NonNull.class)
+package io.papermc.paper.block.fluid;
+
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.framework.qual.DefaultQualifier;
diff --git a/src/main/java/io/papermc/paper/block/fluid/type/PaperFallingFluidData.java b/src/main/java/io/papermc/paper/block/fluid/type/PaperFallingFluidData.java
new file mode 100644
index 0000000000000000000000000000000000000000..655dbd83ff4e632f1168b75e9b402b05aa9d8edf
--- /dev/null
+++ b/src/main/java/io/papermc/paper/block/fluid/type/PaperFallingFluidData.java
@@ -0,0 +1,18 @@
+
+package io.papermc.paper.block.fluid.type;
+
+import io.papermc.paper.block.fluid.PaperFluidData;
+import net.minecraft.world.level.material.FlowingFluid;
+import net.minecraft.world.level.material.FluidState;
+
+public class PaperFallingFluidData extends PaperFluidData implements FallingFluidData {
+
+ public PaperFallingFluidData(final FluidState state) {
+ super(state);
+ }
+
+ @Override
+ public boolean isFalling() {
+ return this.getState().getValue(FlowingFluid.FALLING);
+ }
+}
diff --git a/src/main/java/io/papermc/paper/block/fluid/type/PaperFlowingFluidData.java b/src/main/java/io/papermc/paper/block/fluid/type/PaperFlowingFluidData.java
new file mode 100644
index 0000000000000000000000000000000000000000..c0c2805cb045cdd835b402776a6923fe2ecc2a99
--- /dev/null
+++ b/src/main/java/io/papermc/paper/block/fluid/type/PaperFlowingFluidData.java
@@ -0,0 +1,11 @@
+package io.papermc.paper.block.fluid.type;
+
+import net.minecraft.world.level.material.FluidState;
+
+public class PaperFlowingFluidData extends PaperFallingFluidData implements FlowingFluidData {
+
+ public PaperFlowingFluidData(final FluidState state) {
+ super(state);
+ }
+
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
index a14d3e6c43b94c543790571b13808713444a239f..284234fcdd15c4c7a4567c7c887d47bf0b7967f4 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
@@ -108,6 +108,13 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
return CraftBlock.at(this.getHandle(), new BlockPos(x, y, z)).getState();
}
+ // Paper start - FluidState API
+ @Override
+ public io.papermc.paper.block.fluid.FluidData getFluidData(final int x, final int y, final int z) {
+ return io.papermc.paper.block.fluid.PaperFluidData.createData(getHandle().getFluidState(new BlockPos(x, y, z)));
+ }
+ // Paper end
+
@Override
public BlockData getBlockData(Location location) {
return this.getBlockData(location.getBlockX(), location.getBlockY(), location.getBlockZ());
diff --git a/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java b/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java
index eaa9ba70b0b80d86eb376a0641420093a7c9dfdb..25598df0bb0d4347b2c17b6ec0afbfe4ecf808b9 100644
--- a/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java
+++ b/src/main/java/org/bukkit/craftbukkit/generator/CraftLimitedRegion.java
@@ -303,4 +303,11 @@ public class CraftLimitedRegion extends CraftRegionAccessor implements LimitedRe
return centerChunkZ;
}
// Paper end - Add more LimitedRegion API
+ // Paper start - Fluid API
+ @Override
+ public io.papermc.paper.block.fluid.FluidData getFluidData(int x, int y, int z) {
+ Preconditions.checkArgument(this.isInRegion(x, y, z), "Coordinates %s, %s, %s are not in the region", x, y, z);
+ return super.getFluidData(x, y, z);
+ }
+ // Paper end
}