From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Noah van der Aa 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 a7d74f16d82853f40d5641794dc12a8404359c94..1f41b48964f168532e9f07a4e708e2afb3791c3e 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java +++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java @@ -260,6 +260,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() { @@ -700,7 +701,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) { @@ -744,6 +745,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); @@ -786,6 +792,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 2be70d950be48014c4e9792adfc1d05da5aa6a59..d47b3ac633e7936d30abfda6fc46c2c7412d76fe 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 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(BlockPos.containing(this.getX(), this.getY() - 1.0D, this.getZ())).getBlock().getFriction() * 0.98F; } @@ -360,6 +365,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); @@ -393,6 +403,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 e9946edf568db010e4ccb9fe7755709ed7b8310f..a925b5c490e7129b27370aa57b5fad1cf05530c6 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftItem.java @@ -103,6 +103,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 755ada4b9cbec40bd1d0db2b0ba4ece5933d4e8d..a77f626f79db9a10367bcd51ae946f93fea6ee69 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -1042,6 +1042,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");