Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/patches/server/1041-Add-FluidState-API.patch
Jake Potrebic bd38e0318a
Updated Upstream (Bukkit/CraftBukkit) (#10379)
Updated Upstream (Bukkit/CraftBukkit)

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:
f02baa38 PR-988: Add World#getIntersectingChunks(BoundingBox)
9321d665 Move getItemInUse up to LivingEntity
819eef73 PR-959: Add access to current item's remaining ticks
c4fdadb0 SPIGOT-7601: Add AbstractArrow#getItem
be8261ca Add support for Java 22
26119676 PR-979: Add more translation keys
66753362 PR-985: Correct book maximum pages and characters per page documentation
c8be92fa PR-980: Improve getArmorContents() documentation
f1120ee2 PR-983: Expose riptide velocity to PlayerRiptideEvent

CraftBukkit Changes:
dfaa89bbe PR-1369: Add World#getIntersectingChunks(BoundingBox)
51bbab2b9 Move getItemInUse up to LivingEntity
668e09602 PR-1331: Add access to current item's remaining ticks
a639406d1 SPIGOT-7601: Add AbstractArrow#getItem
0398930fc SPIGOT-7602: Allow opening in-world horse and related inventories
ffd15611c SPIGOT-7608: Allow empty lists to morph to any PDT list
2188dcfa9 Add support for Java 22
45d6a609f SPIGOT-7604: Revert "SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime"
06d915943 SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime
ca3bc3707 PR-1361: Add more translation keys
366c3ca80 SPIGOT-7600: EntityChangeBlockEvent is not fired for frog eggs
06d0f9ba8 SPIGOT-7593: Fix sapling growth physics / client-side updates
45c2608e4 PR-1366: Expose riptide velocity to PlayerRiptideEvent
29b6bb79b SPIGOT-7587: Remove fixes for now-resolved MC-142590 and MC-109346
2024-04-06 12:53:39 -07: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 7c7dbd030ada8d2fab494b6a125664ddc3955639..35f7de6b50d3adae7bdd0da5f779f0a466d25522 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
@@ -107,6 +107,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 ca9bb98ccfc3863c2ba538953470ab9e2b8a2f29..a2edef9739bad941f8e581da126bbfeac7cab5d8 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
}