Paper/patches/unapplied/server/0827-Friction-API.patch

163 lines
8.1 KiB
Diff
Raw Normal View History

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
index b19b5b8678ce2fb912b703382ae79f5755e025e7..084d988ec3dcdae54a10309d34d335ca4f37b7b0 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
@@ -262,6 +262,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
+ 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() {
@@ -717,7 +718,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
2022-11-26 01:23:12 +01:00
}
public boolean shouldDiscardFriction() {
- return this.discardFriction;
+ return !this.frictionState.toBooleanOrElse(!this.discardFriction); // Paper - Friction API
2022-11-26 01:23:12 +01:00
}
public void setDiscardFriction(boolean noDrag) {
@@ -768,6 +769,11 @@ public abstract class LivingEntity extends Entity implements Attackable {
2022-11-26 01:23:12 +01:00
@Override
public void addAdditionalSaveData(CompoundTag nbt) {
+ // 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());
+ }
+ // 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);
@@ -811,6 +817,16 @@ public abstract class LivingEntity extends Entity implements Attackable {
2022-11-26 01:23:12 +01:00
}
this.internalSetAbsorptionAmount(absorptionAmount);
// Paper end - Check for NaN
+ // 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);
+ }
+ }
+ // 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));
}
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
index d0dac3dc89b9bb645a1d8498802fb8c6bff6a78e..29ce703a79f7893ac990ad80e0f1c1cf63546e6c 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
@@ -58,6 +58,7 @@ public class ItemEntity extends Entity implements TraceableEntity {
2022-11-26 01:23:12 +01:00
private int lastTick = MinecraftServer.currentTick - 1; // CraftBukkit
public boolean canMobPickup = true; // Paper - Item#canEntityPickup
private int despawnRate = -1; // Paper - Alternative item-despawn-rate
+ 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);
@@ -179,11 +180,15 @@ public class ItemEntity extends Entity implements TraceableEntity {
2022-11-26 01:23:12 +01:00
this.move(MoverType.SELF, this.getDeltaMovement());
float f1 = 0.98F;
2023-06-08 10:47:19 +02:00
- if (this.onGround()) {
+ // Paper start - Friction API
2022-11-26 01:23:12 +01:00
+ if (frictionState == net.kyori.adventure.util.TriState.FALSE) {
+ f1 = 1F;
2023-06-08 10:47:19 +02:00
+ } else if (this.onGround()) {
+ // Paper end - Friction API
2023-06-08 10:47:19 +02:00
f1 = this.level().getBlockState(this.getBlockPosBelowThatAffectsMyMovement()).getBlock().getFriction() * 0.98F;
2022-11-26 01:23:12 +01:00
}
- this.setDeltaMovement(this.getDeltaMovement().multiply((double) f1, 0.98D, (double) f1));
+ this.setDeltaMovement(this.getDeltaMovement().multiply((double) f1, frictionState == net.kyori.adventure.util.TriState.FALSE ? 1D : 0.98D, (double) f1)); // Paper - Friction API
if (this.onGround()) {
Vec3 vec3d1 = this.getDeltaMovement();
@@ -388,6 +393,11 @@ public class ItemEntity extends Entity implements TraceableEntity {
2022-11-26 01:23:12 +01:00
@Override
public void addAdditionalSaveData(CompoundTag nbt) {
+ // 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());
+ }
+ // 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);
@@ -422,6 +432,17 @@ public class ItemEntity extends Entity implements TraceableEntity {
2023-12-06 17:21:56 +01:00
this.cachedThrower = null;
2022-11-26 01:23:12 +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);
+ }
+ }
+ // Paper end - Friction API
2022-11-26 01:23:12 +01:00
+
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 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
@@ -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() {
+ 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");
+ this.getHandle().frictionState = state;
2022-11-26 01:23:12 +01:00
+ }
+
@Override
public int getHealth() {
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-04-06 23:44:27 +02:00
index 711eb84fee6c46341928a765970defa47e1fe0c3..b0c03854ee9936b1dac9cbf89e9977d978712d56 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-04-06 23:44:27 +02:00
@@ -1177,4 +1177,18 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
2022-11-26 01:23:12 +01:00
});
}
Updated Upstream (Bukkit/CraftBukkit) (#10379) Updated Upstream (Bukkit/CraftBukkit) 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: f02baa38 PR-988: Add World#getIntersectingChunks(BoundingBox) 9321d665 Move getItemInUse up to LivingEntity 819eef73 PR-959: Add access to current item's remaining ticks c4fdadb0 SPIGOT-7601: Add AbstractArrow#getItem be8261ca Add support for Java 22 26119676 PR-979: Add more translation keys 66753362 PR-985: Correct book maximum pages and characters per page documentation c8be92fa PR-980: Improve getArmorContents() documentation f1120ee2 PR-983: Expose riptide velocity to PlayerRiptideEvent CraftBukkit Changes: dfaa89bbe PR-1369: Add World#getIntersectingChunks(BoundingBox) 51bbab2b9 Move getItemInUse up to LivingEntity 668e09602 PR-1331: Add access to current item's remaining ticks a639406d1 SPIGOT-7601: Add AbstractArrow#getItem 0398930fc SPIGOT-7602: Allow opening in-world horse and related inventories ffd15611c SPIGOT-7608: Allow empty lists to morph to any PDT list 2188dcfa9 Add support for Java 22 45d6a609f SPIGOT-7604: Revert "SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime" 06d915943 SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime ca3bc3707 PR-1361: Add more translation keys 366c3ca80 SPIGOT-7600: EntityChangeBlockEvent is not fired for frog eggs 06d0f9ba8 SPIGOT-7593: Fix sapling growth physics / client-side updates 45c2608e4 PR-1366: Expose riptide velocity to PlayerRiptideEvent 29b6bb79b SPIGOT-7587: Remove fixes for now-resolved MC-142590 and MC-109346
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;
+ }
Updated Upstream (Bukkit/CraftBukkit) (#10379) Updated Upstream (Bukkit/CraftBukkit) 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: f02baa38 PR-988: Add World#getIntersectingChunks(BoundingBox) 9321d665 Move getItemInUse up to LivingEntity 819eef73 PR-959: Add access to current item's remaining ticks c4fdadb0 SPIGOT-7601: Add AbstractArrow#getItem be8261ca Add support for Java 22 26119676 PR-979: Add more translation keys 66753362 PR-985: Correct book maximum pages and characters per page documentation c8be92fa PR-980: Improve getArmorContents() documentation f1120ee2 PR-983: Expose riptide velocity to PlayerRiptideEvent CraftBukkit Changes: dfaa89bbe PR-1369: Add World#getIntersectingChunks(BoundingBox) 51bbab2b9 Move getItemInUse up to LivingEntity 668e09602 PR-1331: Add access to current item's remaining ticks a639406d1 SPIGOT-7601: Add AbstractArrow#getItem 0398930fc SPIGOT-7602: Allow opening in-world horse and related inventories ffd15611c SPIGOT-7608: Allow empty lists to morph to any PDT list 2188dcfa9 Add support for Java 22 45d6a609f SPIGOT-7604: Revert "SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime" 06d915943 SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime ca3bc3707 PR-1361: Add more translation keys 366c3ca80 SPIGOT-7600: EntityChangeBlockEvent is not fired for frog eggs 06d0f9ba8 SPIGOT-7593: Fix sapling growth physics / client-side updates 45c2608e4 PR-1366: Expose riptide velocity to PlayerRiptideEvent 29b6bb79b SPIGOT-7587: Remove fixes for now-resolved MC-142590 and MC-109346
2024-04-06 21:53:39 +02:00
+ // Paper end - friction API
}