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-06-13 17:45:43 +02:00
index 947bccb93f2a5baa6236e1da1a7ec0b27c072a14..337c43f08465cb84227ca02b99f972b47a9186f5 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-04-24 23:23:56 +02:00
@@ -273,6 +273,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-04-24 23:23:56 +02:00
@@ -738,7 +739,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-04-24 23:23:56 +02:00
@@ -799,6 +800,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-04-24 23:23:56 +02:00
@@ -842,6 +848,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
2023-06-08 10:47:19 +02:00
if (nbt.contains("Attributes", 9) && this.level() != null && !this.level().isClientSide) {
2022-11-26 01:23:12 +01:00
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-04-24 23:23:56 +02:00
index b392fda26982517cbc2c04156897184275ce69e5..8fd3845c4965843be9c37498760d93f1ebdff541 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-04-24 23:23:56 +02:00
@@ -62,6 +62,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-04-24 23:23:56 +02:00
@@ -185,7 +186,11 @@ public class ItemEntity extends Entity implements TraceableEntity {
2022-11-26 01:23:12 +01:00
this.move(MoverType.SELF, this.getDeltaMovement());
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-04-24 23:23:56 +02:00
@@ -394,6 +399,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-04-24 23:23:56 +02:00
@@ -436,6 +446,17 @@ public class ItemEntity extends Entity implements TraceableEntity {
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
}
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-06-10 08:24:52 +02:00
index 6cf60ff71e398dbf6110f94a00e9bb973916a7f8..112d54e1789d30ef89b34f53a60b0124538d3cda 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-05-30 22:31:45 +02:00
@@ -1147,4 +1147,18 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
2024-06-10 08:24:52 +02:00
nmsStack.hurtAndBreakWithoutChecks(amount, this.getHandle(), slot);
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
}