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-09-15 21:39:53 +02:00
index f662a791e8cb045903a0de29778e5f30892fb766..2bb61084b628582ded44926d7697ee26d0bb1e8e 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-06-14 05:41:44 +02:00
@@ -285,6 +285,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-06-14 05:41:44 +02:00
@@ -706,7 +707,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-07-06 21:19:14 +02:00
@@ -774,6 +775,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-07-06 21:19:14 +02:00
@@ -817,6 +823,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-09-19 16:36:07 +02:00
index 446c319524183d6a1b4d0e6f0613a8db690677da..cbfb07bdf8d5e2e5a462835184be2d47e59d506c 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-09-19 16:36:07 +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-09-19 16:36:07 +02:00
@@ -393,6 +398,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-09-19 16:36:07 +02:00
@@ -435,6 +445,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
}
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-09-21 21:19:02 +02:00
index 2332f40fed84510741e63073aaf0a18aab85303e..516ea1ec9ae5069c3c0e4708f62164a91960b627 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-09-21 21:19:02 +02:00
@@ -1179,4 +1179,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
}