aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0902-Friction-API.patch
blob: 45b7a1422ee38b7c6c125c5b4e7b131b13c285fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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
index e59738a15c3db0d11bb7007af160aa1845cafd28..6e955e940ab95c5be22a8fb331b3c61347a77f92 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -263,6 +263,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
     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
+    public net.kyori.adventure.util.TriState frictionState = net.kyori.adventure.util.TriState.NOT_SET; // Paper
 
     @Override
     public float getBukkitYaw() {
@@ -718,7 +719,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
     }
 
     public boolean shouldDiscardFriction() {
-        return this.discardFriction;
+        return !this.frictionState.toBooleanOrElse(!this.discardFriction); // Paper
     }
 
     public void setDiscardFriction(boolean noDrag) {
@@ -762,6 +763,11 @@ public abstract class LivingEntity extends Entity implements Attackable {
 
     @Override
     public void addAdditionalSaveData(CompoundTag nbt) {
+        // Paper start
+        if (this.frictionState != net.kyori.adventure.util.TriState.NOT_SET) {
+            nbt.putString("Paper.FrictionState", this.frictionState.toString());
+        }
+        // Paper end
         nbt.putFloat("Health", this.getHealth());
         nbt.putShort("HurtTime", (short) this.hurtTime);
         nbt.putInt("HurtByTimestamp", this.lastHurtByMobTimestamp);
@@ -804,6 +810,15 @@ public abstract class LivingEntity extends Entity implements Attackable {
             absorptionAmount = 0;
         }
         this.setAbsorptionAmount(absorptionAmount);
+
+        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);
+            }
+        }
         // Paper end
         if (nbt.contains("Attributes", 9) && this.level() != null && !this.level().isClientSide) {
             this.getAttributes().load(nbt.getList("Attributes", 10));
diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
index 00ecef0ba7530ff2533fa9d5eaa8489da8796ead..3d41dbe0285f8fec8adae1e93010cf464df9b08c 100644
--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java
@@ -54,6 +54,7 @@ public class ItemEntity extends Entity implements TraceableEntity {
     private int lastTick = MinecraftServer.currentTick - 1; // CraftBukkit
     public boolean canMobPickup = true; // Paper
     private int despawnRate = -1; // Paper
+    public net.kyori.adventure.util.TriState frictionState = net.kyori.adventure.util.TriState.NOT_SET; // Paper
 
     public ItemEntity(EntityType<? extends ItemEntity> type, Level world) {
         super(type, world);
@@ -159,7 +160,11 @@ public class ItemEntity extends Entity implements TraceableEntity {
                 this.move(MoverType.SELF, this.getDeltaMovement());
                 float f1 = 0.98F;
 
-                if (this.onGround()) {
+                // Paper start
+                if (frictionState == net.kyori.adventure.util.TriState.FALSE) {
+                    f1 = 1F;
+                } else if (this.onGround()) {
+                    // Paper end
                     f1 = this.level().getBlockState(this.getBlockPosBelowThatAffectsMyMovement()).getBlock().getFriction() * 0.98F;
                 }
 
@@ -364,6 +369,11 @@ public class ItemEntity extends Entity implements TraceableEntity {
 
     @Override
     public void addAdditionalSaveData(CompoundTag nbt) {
+        // Paper start
+        if (this.frictionState != net.kyori.adventure.util.TriState.NOT_SET) {
+            nbt.putString("Paper.FrictionState", this.frictionState.toString());
+        }
+        // Paper end
         nbt.putShort("Health", (short) this.health);
         nbt.putShort("Age", (short) this.age);
         nbt.putShort("PickupDelay", (short) this.pickupDelay);
@@ -397,6 +407,17 @@ public class ItemEntity extends Entity implements TraceableEntity {
             this.thrower = nbt.getUUID("Thrower");
         }
 
+        // Paper start
+        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
+
         CompoundTag nbttagcompound1 = nbt.getCompound("Item");
 
         this.setItem(ItemStack.of(nbttagcompound1));
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java
index d160db37a3b7ef44b6de8fef209eeccef46c3a95..5e83fabb20bc2b0668cbf48530053ca1bb9092f3 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java
@@ -102,6 +102,18 @@ public class CraftItem extends CraftEntity implements Item {
         item.age = willAge ? 0 : NO_AGE_TIME;
      }
 
+     @org.jetbrains.annotations.NotNull
+     @Override
+     public net.kyori.adventure.util.TriState getFrictionState() {
+        return this.item.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.item.frictionState = state;
+     }
+
     @Override
     public int getHealth() {
         return item.health;
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index c2ef57029bea0ebd161c917adbfa3b1297b6806e..eb61197da44a84a60cd59bb518079e4c202e1188 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -1035,6 +1035,18 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
         });
     }
 
+    @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;
+    }
+
     @Override
     public void knockback(double strength, double directionX, double directionZ) {
         Preconditions.checkArgument(strength > 0, "Knockback strength must be > 0");