2022-11-26 01:23:12 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Noah van der Aa <ndvdaa@gmail.com>
Date: Wed, 15 Sep 2021 20:44:22 +0200
Subject: [PATCH] Friction API
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
2024-10-31 12:44:02 +01:00
index 0e2b5e1dbdf671da0a4edfa77f7fb759732674cb..076c7828fdfa53c7453406beb937700e12b137d2 100644
2022-11-26 01:23:12 +01:00
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
2024-10-27 18:11:15 +01:00
@@ -296,6 +296,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
2022-11-26 01:23:12 +01:00
public boolean bukkitPickUpLoot;
public org.bukkit.craftbukkit.entity.CraftLivingEntity getBukkitLivingEntity() { return (org.bukkit.craftbukkit.entity.CraftLivingEntity) super.getBukkitEntity(); } // Paper
public boolean silentDeath = false; // Paper - mark entity as dying silently for cancellable death event
2024-01-16 12:41:40 +01:00
+ public net.kyori.adventure.util.TriState frictionState = net.kyori.adventure.util.TriState.NOT_SET; // Paper - Friction API
2022-11-26 01:23:12 +01:00
@Override
public float getBukkitYaw() {
2024-10-27 18:11:15 +01:00
@@ -722,7 +723,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
2022-11-26 01:23:12 +01:00
}
public boolean shouldDiscardFriction() {
- return this.discardFriction;
2024-01-16 12:41:40 +01:00
+ return !this.frictionState.toBooleanOrElse(!this.discardFriction); // Paper - Friction API
2022-11-26 01:23:12 +01:00
}
public void setDiscardFriction(boolean noDrag) {
2024-10-27 18:11:15 +01:00
@@ -796,6 +797,11 @@ public abstract class LivingEntity extends Entity implements Attackable {
2022-11-26 01:23:12 +01:00
@Override
public void addAdditionalSaveData(CompoundTag nbt) {
2024-01-16 12:41:40 +01:00
+ // Paper start - Friction API
2022-11-26 01:23:12 +01:00
+ if (this.frictionState != net.kyori.adventure.util.TriState.NOT_SET) {
+ nbt.putString("Paper.FrictionState", this.frictionState.toString());
+ }
2024-01-16 12:41:40 +01:00
+ // Paper end - Friction API
2022-11-26 01:23:12 +01:00
nbt.putFloat("Health", this.getHealth());
nbt.putShort("HurtTime", (short) this.hurtTime);
nbt.putInt("HurtByTimestamp", this.lastHurtByMobTimestamp);
2024-10-27 18:11:15 +01:00
@@ -839,6 +845,16 @@ public abstract class LivingEntity extends Entity implements Attackable {
2022-11-26 01:23:12 +01:00
}
2023-09-22 17:51:48 +02:00
this.internalSetAbsorptionAmount(absorptionAmount);
2024-01-23 14:34:17 +01:00
// Paper end - Check for NaN
2024-01-16 12:41:40 +01:00
+ // Paper start - Friction API
2022-11-26 01:23:12 +01:00
+ if (nbt.contains("Paper.FrictionState")) {
+ String fs = nbt.getString("Paper.FrictionState");
+ try {
+ frictionState = net.kyori.adventure.util.TriState.valueOf(fs);
+ } catch (Exception ignored) {
+ LOGGER.error("Unknown friction state " + fs + " for " + this);
+ }
+ }
2024-01-16 12:41:40 +01:00
+ // Paper end - Friction API
2024-06-14 05:41:44 +02:00
if (nbt.contains("attributes", 9) && this.level() != null && !this.level().isClientSide) {
this.getAttributes().load(nbt.getList("attributes", 10));
2024-01-23 14:34:17 +01:00
}
2022-11-26 01:23:12 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
2024-10-30 14:06:43 +01:00
index d555fd0b200c012f30ed0c0ec09a37b25a737b76..7a6d51020d9c6be33b4c34c0d608559589d5b390 100644
2022-11-26 01:23:12 +01:00
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
2024-06-14 05:41:44 +02:00
@@ -63,6 +63,7 @@ public class ItemEntity extends Entity implements TraceableEntity {
2022-11-26 01:23:12 +01:00
private int lastTick = MinecraftServer.currentTick - 1; // CraftBukkit
2024-01-22 19:01:10 +01:00
public boolean canMobPickup = true; // Paper - Item#canEntityPickup
2024-01-21 12:53:04 +01:00
private int despawnRate = -1; // Paper - Alternative item-despawn-rate
2024-01-16 12:41:40 +01:00
+ public net.kyori.adventure.util.TriState frictionState = net.kyori.adventure.util.TriState.NOT_SET; // Paper - Friction API
2022-11-26 01:23:12 +01:00
public ItemEntity(EntityType<? extends ItemEntity> type, Level world) {
super(type, world);
2024-10-24 00:08:29 +02:00
@@ -186,7 +187,11 @@ public class ItemEntity extends Entity implements TraceableEntity {
this.applyEffectsFromBlocks();
2024-04-24 23:23:56 +02:00
float f = 0.98F;
2022-11-26 01:23:12 +01:00
2023-06-08 10:47:19 +02:00
- if (this.onGround()) {
2024-01-16 12:41:40 +01:00
+ // Paper start - Friction API
2022-11-26 01:23:12 +01:00
+ if (frictionState == net.kyori.adventure.util.TriState.FALSE) {
2024-04-24 23:23:56 +02:00
+ f = 1F;
2023-06-08 10:47:19 +02:00
+ } else if (this.onGround()) {
2024-01-16 12:41:40 +01:00
+ // Paper end - Friction API
2024-04-24 23:23:56 +02:00
f = this.level().getBlockState(this.getBlockPosBelowThatAffectsMyMovement()).getBlock().getFriction() * 0.98F;
2022-11-26 01:23:12 +01:00
}
2024-10-24 00:08:29 +02:00
@@ -409,6 +414,11 @@ public class ItemEntity extends Entity implements TraceableEntity {
2022-11-26 01:23:12 +01:00
@Override
public void addAdditionalSaveData(CompoundTag nbt) {
2024-01-16 12:41:40 +01:00
+ // Paper start - Friction API
2022-11-26 01:23:12 +01:00
+ if (this.frictionState != net.kyori.adventure.util.TriState.NOT_SET) {
+ nbt.putString("Paper.FrictionState", this.frictionState.toString());
+ }
2024-01-16 12:41:40 +01:00
+ // Paper end - Friction API
2022-11-26 01:23:12 +01:00
nbt.putShort("Health", (short) this.health);
nbt.putShort("Age", (short) this.age);
nbt.putShort("PickupDelay", (short) this.pickupDelay);
2024-10-24 00:08:29 +02:00
@@ -451,6 +461,17 @@ public class ItemEntity extends Entity implements TraceableEntity {
2024-04-24 23:23:56 +02:00
this.setItem(ItemStack.EMPTY);
2022-11-26 01:23:12 +01:00
}
2024-01-16 12:41:40 +01:00
+ // Paper start - Friction API
2022-11-26 01:23:12 +01:00
+ 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);
+ }
+ }
2024-01-16 12:41:40 +01:00
+ // Paper end - Friction API
2022-11-26 01:23:12 +01:00
+
2024-04-24 23:23:56 +02:00
if (this.getItem().isEmpty()) {
this.discard(null); // CraftBukkit - add Bukkit remove cause
}
2024-10-30 17:31:33 +01:00
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 d8fcd6d1edec1f31a861fab4b86cbeb15ddc799d..d277f56fef882313d6d21f636fafae2f26630ad7 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/AbstractMinecart.java
@@ -93,6 +93,7 @@ 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);
@@ -552,6 +553,16 @@ 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
@@ -564,6 +575,12 @@ 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 00b0004940339dc105fb95f813bd35b16f7a9fb4..a8718ee94cd6b9a20bd1e9a49d58d39e6f3f2a7a 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/NewMinecartBehavior.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/NewMinecartBehavior.java
@@ -548,6 +548,7 @@ 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 cf871c174091139c8ad1affb84f98fcd74b60dee..23cbafcc12f6e5f5755215a72879a6cab306ad18 100644
--- a/src/main/java/net/minecraft/world/entity/vehicle/OldMinecartBehavior.java
+++ b/src/main/java/net/minecraft/world/entity/vehicle/OldMinecartBehavior.java
@@ -522,6 +522,7 @@ 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
}
}
2022-11-26 01:23:12 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
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:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
index 1a291dd8a287db30e71dcb315599fc4b038764c4..30d62ee4d5cd2ddacb8783b5bbbf475d592b3e02 100644
2022-11-26 01:23:12 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java
2023-10-22 21:12:00 +02:00
@@ -99,6 +99,18 @@ public class CraftItem extends CraftEntity implements Item {
this.getHandle().age = willAge ? 0 : NO_AGE_TIME;
2022-11-26 01:23:12 +01:00
}
+ @org.jetbrains.annotations.NotNull
+ @Override
+ public net.kyori.adventure.util.TriState getFrictionState() {
2023-10-22 21:12:00 +02:00
+ return this.getHandle().frictionState;
2022-11-26 01:23:12 +01:00
+ }
+
+ @Override
+ public void setFrictionState(@org.jetbrains.annotations.NotNull net.kyori.adventure.util.TriState state) {
+ java.util.Objects.requireNonNull(state, "state may not be null");
2023-10-22 21:12:00 +02:00
+ this.getHandle().frictionState = state;
2022-11-26 01:23:12 +01:00
+ }
+
@Override
public int getHealth() {
2023-10-22 21:12:00 +02:00
return this.getHandle().health;
2022-11-26 01:23:12 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
2024-10-24 00:08:29 +02:00
index 1ceaa081231a617bd87331b308c24d9c7a8dcf2b..2fd4a3068d86a37cc18c9203448823c53d590ffb 100644
2022-11-26 01:23:12 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
2024-10-24 00:08:29 +02:00
@@ -1198,4 +1198,17 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
2024-06-14 05:41:44 +02:00
nmsStack.hurtAndBreak(amount, this.getHandle(), slot, true);
2022-11-26 01:23:12 +01:00
}
2024-04-06 21:53:39 +02:00
// Paper end - ItemStack damage API
+ // Paper start - friction API
2022-11-26 01:23:12 +01:00
+ @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;
+ }
2024-04-06 21:53:39 +02:00
+ // Paper end - friction API
}
2024-10-30 17:31:33 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java
index d35c1a10e58932b19c8053c5dacdc25fd7f22e8c..ab9d06a9a4951a5b8aa14d47818a3850433e92b8 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java
@@ -137,4 +137,18 @@ 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
}