Paper/patches/server/0864-Friction-API.patch

158 lines
7.7 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 f3d201cba18be448a52304a43ec05b109010bb98..38d0def27625f5b7918cc2cebad0d9db2596ff3b 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
2023-12-06 17:21:56 +01:00
@@ -261,6 +261,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() {
2023-12-06 17:21:56 +01:00
@@ -716,7 +717,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) {
2023-12-06 17:21:56 +01:00
@@ -760,6 +761,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);
@@ -802,6 +808,16 @@ public abstract class LivingEntity extends Entity implements Attackable {
2022-11-26 01:23:12 +01:00
absorptionAmount = 0;
}
this.internalSetAbsorptionAmount(absorptionAmount);
+ // 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
2022-11-26 01:23:12 +01:00
// Paper end
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));
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 6b18f23b57c7000dce9726df98a509ee9477f6d2..c34c698d389da29c9cfaa56cb8023e30416a14ba 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
2023-12-06 17:21:56 +01:00
@@ -57,6 +57,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
private int despawnRate = -1; // Paper
+ 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);
2023-12-06 17:21:56 +01:00
@@ -178,7 +179,11 @@ 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
}
2023-12-06 17:21:56 +01:00
@@ -387,6 +392,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);
2023-12-06 17:21:56 +01:00
@@ -421,6 +431,17 @@ public class ItemEntity extends Entity implements TraceableEntity {
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
2023-12-06 17:21:56 +01:00
index b1bbab951ef9a3d2bd98cc54665ba824263542eb..81498941748d646ebe6495f4a7ce6953532144c6 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
Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: cc9aa21a SPIGOT-6399, SPIGOT-7344: Clarify collidable behavior for player entities f23325b6 Add API for per-world simulation distances 26e1774e Add API for per-world view distances 0b541e60 Add PlayerLoginEvent#getRealAddress 5f027d2d PR-949: Add Vector#fromJOML() overloads for read-only vector types CraftBukkit Changes: bcf56171a PR-1321: Clean up some stuff which got missed during previous PRs 7f833a2d1 SPIGOT-7462: Players no longer drop XP after dying near a Sculk Catalyst 752aac669 Implement APIs for per world view and simulation distances 57d7ef433 Preserve empty enchantment tags for glow effect 465ec3fb4 Remove connected check on setScoreboard f90ce621e Use one PermissibleBase for all command blocks 5876cca44 SPIGOT-7550: Fix creation of Arrow instances f03fc3aa3 SPIGOT-7549: ServerTickManager#setTickRate incorrect Precondition 9d7f49b01 SPIGOT-7548: Fix wrong spawn location for experience orb and dropped item Spigot Changes: ed9ba9a4 Drop no longer required patch ignoring -o option 86b5dd6a SPIGOT-7546: Fix hardcoded check for outdated client message aa7cde7a Remove obsolete APIs for per world view and simulation distances 6dff577e Remove obsolete patch preserving empty `ench` tags a3bf95b8 Remove obsolete PlayerLoginEvent#getRealAddress 1b02f5d6 Remove obsolete connected check on setScoreboard patch acf717eb Remove obsolete command block PermissibleBase patch 053fa2a9 Remove redundant patch dealing with null tile entities
2023-12-25 23:51:56 +01:00
index 9de132dc39f2af083b2f60d6344b9a9635c1de83..45ebd9ffc37163e3a11c80c15b41c5aeed2b6983 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
Updated Upstream (Bukkit/CraftBukkit/Spigot) 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: cc9aa21a SPIGOT-6399, SPIGOT-7344: Clarify collidable behavior for player entities f23325b6 Add API for per-world simulation distances 26e1774e Add API for per-world view distances 0b541e60 Add PlayerLoginEvent#getRealAddress 5f027d2d PR-949: Add Vector#fromJOML() overloads for read-only vector types CraftBukkit Changes: bcf56171a PR-1321: Clean up some stuff which got missed during previous PRs 7f833a2d1 SPIGOT-7462: Players no longer drop XP after dying near a Sculk Catalyst 752aac669 Implement APIs for per world view and simulation distances 57d7ef433 Preserve empty enchantment tags for glow effect 465ec3fb4 Remove connected check on setScoreboard f90ce621e Use one PermissibleBase for all command blocks 5876cca44 SPIGOT-7550: Fix creation of Arrow instances f03fc3aa3 SPIGOT-7549: ServerTickManager#setTickRate incorrect Precondition 9d7f49b01 SPIGOT-7548: Fix wrong spawn location for experience orb and dropped item Spigot Changes: ed9ba9a4 Drop no longer required patch ignoring -o option 86b5dd6a SPIGOT-7546: Fix hardcoded check for outdated client message aa7cde7a Remove obsolete APIs for per world view and simulation distances 6dff577e Remove obsolete patch preserving empty `ench` tags a3bf95b8 Remove obsolete PlayerLoginEvent#getRealAddress 1b02f5d6 Remove obsolete connected check on setScoreboard patch acf717eb Remove obsolete command block PermissibleBase patch 053fa2a9 Remove redundant patch dealing with null tile entities
2023-12-25 23:51:56 +01:00
@@ -1083,6 +1083,18 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
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;
+ }
+
@Override
public void knockback(double strength, double directionX, double directionZ) {
Preconditions.checkArgument(strength > 0, "Knockback strength must be > 0");