From bafaa407e4855abcde467779d6b6231c167b6973 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Wed, 30 Oct 2024 17:31:33 +0100 Subject: [PATCH] Add Friction API to minecarts --- patches/api/Friction-API.patch | 13 +++++ patches/server/Friction-API.patch | 89 +++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/patches/api/Friction-API.patch b/patches/api/Friction-API.patch index c8430ff968..45701a3bdd 100644 --- a/patches/api/Friction-API.patch +++ b/patches/api/Friction-API.patch @@ -71,3 +71,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 /** * Gets the height of the living entity's eyes above its Location. +diff --git a/src/main/java/org/bukkit/entity/Minecart.java b/src/main/java/org/bukkit/entity/Minecart.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/entity/Minecart.java ++++ b/src/main/java/org/bukkit/entity/Minecart.java +@@ -0,0 +0,0 @@ import org.jetbrains.annotations.Nullable; + /** + * Represents a minecart entity. + */ +-public interface Minecart extends Vehicle { ++public interface Minecart extends Vehicle, io.papermc.paper.entity.Frictional { // Paper + + /** + * Sets a minecart's damage. diff --git a/patches/server/Friction-API.patch b/patches/server/Friction-API.patch index b8955e1760..0a1663ceb0 100644 --- a/patches/server/Friction-API.patch +++ b/patches/server/Friction-API.patch @@ -109,6 +109,72 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 if (this.getItem().isEmpty()) { this.discard(null); // CraftBukkit - add Bukkit remove cause } +diff --git a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java ++++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java +@@ -0,0 +0,0 @@ public abstract class AbstractMinecart extends VehicleEntity { + private double flyingZ = 0.95; + public double maxSpeed = 0.4D; + // CraftBukkit end ++ public net.kyori.adventure.util.TriState frictionState = net.kyori.adventure.util.TriState.NOT_SET; // Paper - Friction API + + protected AbstractMinecart(EntityType type, Level world) { + super(type, world); +@@ -0,0 +0,0 @@ public abstract class AbstractMinecart extends VehicleEntity { + + this.flipped = nbt.getBoolean("FlippedRotation"); + this.firstTick = nbt.getBoolean("HasTicked"); ++ // Paper start - Friction API ++ if (nbt.contains("Paper.FrictionState")) { ++ String fs = nbt.getString("Paper.FrictionState"); ++ try { ++ frictionState = net.kyori.adventure.util.TriState.valueOf(fs); ++ } catch (Exception ignored) { ++ com.mojang.logging.LogUtils.getLogger().error("Unknown friction state " + fs + " for " + this); ++ } ++ } ++ // Paper end - Friction API + } + + @Override +@@ -0,0 +0,0 @@ public abstract class AbstractMinecart extends VehicleEntity { + + nbt.putBoolean("FlippedRotation", this.flipped); + nbt.putBoolean("HasTicked", this.firstTick); ++ ++ // Paper start - Friction API ++ if (this.frictionState != net.kyori.adventure.util.TriState.NOT_SET) { ++ nbt.putString("Paper.FrictionState", this.frictionState.toString()); ++ } ++ // Paper end - Friction API + } + + @Override +diff --git a/src/main/java/net/minecraft/world/entity/vehicle/NewMinecartBehavior.java b/src/main/java/net/minecraft/world/entity/vehicle/NewMinecartBehavior.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/entity/vehicle/NewMinecartBehavior.java ++++ b/src/main/java/net/minecraft/world/entity/vehicle/NewMinecartBehavior.java +@@ -0,0 +0,0 @@ public class NewMinecartBehavior extends MinecartBehavior { + + @Override + public double getSlowdownFactor() { ++ if (this.minecart.frictionState == net.kyori.adventure.util.TriState.FALSE) return 1; // Paper + return this.minecart.isVehicle() || !this.minecart.slowWhenEmpty ? 0.997D : 0.975D; // CraftBukkit - add !this.slowWhenEmpty + } + +diff --git a/src/main/java/net/minecraft/world/entity/vehicle/OldMinecartBehavior.java b/src/main/java/net/minecraft/world/entity/vehicle/OldMinecartBehavior.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/entity/vehicle/OldMinecartBehavior.java ++++ b/src/main/java/net/minecraft/world/entity/vehicle/OldMinecartBehavior.java +@@ -0,0 +0,0 @@ public class OldMinecartBehavior extends MinecartBehavior { + + @Override + public double getSlowdownFactor() { ++ if (this.minecart.frictionState == net.kyori.adventure.util.TriState.FALSE) return 1; // Paper + return this.minecart.isVehicle() || !this.minecart.slowWhenEmpty ? 0.997D : 0.96D; // CraftBukkit - add !this.slowWhenEmpty + } + } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java @@ -154,3 +220,26 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + // Paper end - friction API } +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java +@@ -0,0 +0,0 @@ public abstract class CraftMinecart extends CraftVehicle implements Minecart { + public int getDisplayBlockOffset() { + return this.getHandle().getDisplayOffset(); + } ++ ++ // Paper start - Friction API ++ @org.jetbrains.annotations.NotNull ++ @Override ++ public net.kyori.adventure.util.TriState getFrictionState() { ++ return this.getHandle().frictionState; ++ } ++ ++ @Override ++ public void setFrictionState(@org.jetbrains.annotations.NotNull net.kyori.adventure.util.TriState state) { ++ java.util.Objects.requireNonNull(state, "state may not be null"); ++ this.getHandle().frictionState = state; ++ } ++ // Paper end - Friction API + }