From 06204eb7d9c986c04f163f4cedfaa131a493182b Mon Sep 17 00:00:00 2001 From: Logan Date: Wed, 27 Aug 2025 10:52:13 -0500 Subject: [PATCH] feat: attribute modifiers now included in scale --- .../packets/wrapper/PlayerScaleWrapper.java | 5 ++++- .../nms/v1_20_R4/NMSPacketChannel.java | 14 +++++++++++++- .../nms/v1_21_R1/NMSPacketChannel.java | 14 +++++++++++++- .../nms/v1_21_R2/NMSPacketChannel.java | 14 +++++++++++++- .../nms/v1_21_R3/NMSPacketChannel.java | 14 +++++++++++++- .../nms/v1_21_R4/NMSPacketChannel.java | 14 +++++++++++++- .../nms/v1_21_R5/NMSPacketChannel.java | 14 +++++++++++++- 7 files changed, 82 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/me/lojosho/hibiscuscommons/packets/wrapper/PlayerScaleWrapper.java b/common/src/main/java/me/lojosho/hibiscuscommons/packets/wrapper/PlayerScaleWrapper.java index 19801ca..3fc5060 100644 --- a/common/src/main/java/me/lojosho/hibiscuscommons/packets/wrapper/PlayerScaleWrapper.java +++ b/common/src/main/java/me/lojosho/hibiscuscommons/packets/wrapper/PlayerScaleWrapper.java @@ -8,9 +8,12 @@ public class PlayerScaleWrapper { private final int entityId; @Getter private final double scale; + @Getter + private final double base; - public PlayerScaleWrapper(int entityId, double scale) { + public PlayerScaleWrapper(int entityId, double base, double scale) { this.entityId = entityId; this.scale = scale; + this.base = base; } } diff --git a/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSPacketChannel.java b/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSPacketChannel.java index d7212cd..c21c433 100644 --- a/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSPacketChannel.java +++ b/v1_20_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_20_R4/NMSPacketChannel.java @@ -13,6 +13,7 @@ import me.lojosho.hibiscuscommons.util.MessagesUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.*; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.inventory.ClickType; import net.minecraft.world.item.ItemStack; @@ -183,7 +184,18 @@ public class NMSPacketChannel extends ChannelDuplexHandler { } AtomicReference action = new AtomicReference<>(PacketAction.NOTHING); - PlayerScaleWrapper wrapper = new PlayerScaleWrapper(packet.getEntityId(), nmsScaleAttribute.base()); + + final double base = nmsScaleAttribute.base(); + double total = base; + + for (AttributeModifier modifier : nmsScaleAttribute.modifiers()) { + switch (modifier.operation()) { + case ADD_VALUE -> total += modifier.amount(); + case ADD_MULTIPLIED_BASE -> total += modifier.amount() * nmsScaleAttribute.base(); + case ADD_MULTIPLIED_TOTAL -> total += modifier.amount() * total; + } + } + PlayerScaleWrapper wrapper = new PlayerScaleWrapper(packet.getEntityId(), base, total); SubPlugins.getSubPlugins().forEach(plugin -> { PacketAction pluginAction = plugin.getPacketInterface().readPlayerScale(player, wrapper); diff --git a/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSPacketChannel.java b/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSPacketChannel.java index a9ef1d6..a8f7642 100644 --- a/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSPacketChannel.java +++ b/v1_21_R1/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R1/NMSPacketChannel.java @@ -13,6 +13,7 @@ import me.lojosho.hibiscuscommons.util.MessagesUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.*; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.inventory.ClickType; import net.minecraft.world.item.ItemStack; @@ -183,7 +184,18 @@ public class NMSPacketChannel extends ChannelDuplexHandler { } AtomicReference action = new AtomicReference<>(PacketAction.NOTHING); - PlayerScaleWrapper wrapper = new PlayerScaleWrapper(packet.getEntityId(), nmsScaleAttribute.base()); + + final double base = nmsScaleAttribute.base(); + double total = base; + + for (AttributeModifier modifier : nmsScaleAttribute.modifiers()) { + switch (modifier.operation()) { + case ADD_VALUE -> total += modifier.amount(); + case ADD_MULTIPLIED_BASE -> total += modifier.amount() * nmsScaleAttribute.base(); + case ADD_MULTIPLIED_TOTAL -> total += modifier.amount() * total; + } + } + PlayerScaleWrapper wrapper = new PlayerScaleWrapper(packet.getEntityId(), base, total); SubPlugins.getSubPlugins().forEach(plugin -> { PacketAction pluginAction = plugin.getPacketInterface().readPlayerScale(player, wrapper); diff --git a/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSPacketChannel.java b/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSPacketChannel.java index c16efab..18f9922 100644 --- a/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSPacketChannel.java +++ b/v1_21_R2/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R2/NMSPacketChannel.java @@ -13,6 +13,7 @@ import me.lojosho.hibiscuscommons.util.MessagesUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.*; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.inventory.ClickType; import net.minecraft.world.item.ItemStack; @@ -183,7 +184,18 @@ public class NMSPacketChannel extends ChannelDuplexHandler { } AtomicReference action = new AtomicReference<>(PacketAction.NOTHING); - PlayerScaleWrapper wrapper = new PlayerScaleWrapper(packet.getEntityId(), nmsScaleAttribute.base()); + + final double base = nmsScaleAttribute.base(); + double total = base; + + for (AttributeModifier modifier : nmsScaleAttribute.modifiers()) { + switch (modifier.operation()) { + case ADD_VALUE -> total += modifier.amount(); + case ADD_MULTIPLIED_BASE -> total += modifier.amount() * nmsScaleAttribute.base(); + case ADD_MULTIPLIED_TOTAL -> total += modifier.amount() * total; + } + } + PlayerScaleWrapper wrapper = new PlayerScaleWrapper(packet.getEntityId(), base, total); SubPlugins.getSubPlugins().forEach(plugin -> { PacketAction pluginAction = plugin.getPacketInterface().readPlayerScale(player, wrapper); diff --git a/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSPacketChannel.java b/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSPacketChannel.java index 6c65023..1371a6e 100644 --- a/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSPacketChannel.java +++ b/v1_21_R3/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R3/NMSPacketChannel.java @@ -13,6 +13,7 @@ import me.lojosho.hibiscuscommons.util.MessagesUtil; import net.minecraft.core.NonNullList; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.*; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.inventory.ClickType; import net.minecraft.world.item.ItemStack; @@ -183,7 +184,18 @@ public class NMSPacketChannel extends ChannelDuplexHandler { } AtomicReference action = new AtomicReference<>(PacketAction.NOTHING); - PlayerScaleWrapper wrapper = new PlayerScaleWrapper(packet.getEntityId(), nmsScaleAttribute.base()); + + final double base = nmsScaleAttribute.base(); + double total = base; + + for (AttributeModifier modifier : nmsScaleAttribute.modifiers()) { + switch (modifier.operation()) { + case ADD_VALUE -> total += modifier.amount(); + case ADD_MULTIPLIED_BASE -> total += modifier.amount() * nmsScaleAttribute.base(); + case ADD_MULTIPLIED_TOTAL -> total += modifier.amount() * total; + } + } + PlayerScaleWrapper wrapper = new PlayerScaleWrapper(packet.getEntityId(), base, total); SubPlugins.getSubPlugins().forEach(plugin -> { PacketAction pluginAction = plugin.getPacketInterface().readPlayerScale(player, wrapper); diff --git a/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSPacketChannel.java b/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSPacketChannel.java index 5eaa547..b1863b7 100644 --- a/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSPacketChannel.java +++ b/v1_21_R4/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R4/NMSPacketChannel.java @@ -12,6 +12,7 @@ import me.lojosho.hibiscuscommons.plugins.SubPlugins; import me.lojosho.hibiscuscommons.util.MessagesUtil; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.*; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.inventory.ClickType; import net.minecraft.world.item.ItemStack; @@ -182,7 +183,18 @@ public class NMSPacketChannel extends ChannelDuplexHandler { } AtomicReference action = new AtomicReference<>(PacketAction.NOTHING); - PlayerScaleWrapper wrapper = new PlayerScaleWrapper(packet.getEntityId(), nmsScaleAttribute.base()); + + final double base = nmsScaleAttribute.base(); + double total = base; + + for (AttributeModifier modifier : nmsScaleAttribute.modifiers()) { + switch (modifier.operation()) { + case ADD_VALUE -> total += modifier.amount(); + case ADD_MULTIPLIED_BASE -> total += modifier.amount() * nmsScaleAttribute.base(); + case ADD_MULTIPLIED_TOTAL -> total += modifier.amount() * total; + } + } + PlayerScaleWrapper wrapper = new PlayerScaleWrapper(packet.getEntityId(), base, total); SubPlugins.getSubPlugins().forEach(plugin -> { PacketAction pluginAction = plugin.getPacketInterface().readPlayerScale(player, wrapper); diff --git a/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPacketChannel.java b/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPacketChannel.java index c7fbf36..e561d86 100644 --- a/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPacketChannel.java +++ b/v1_21_R5/src/main/java/me/lojosho/hibiscuscommons/nms/v1_21_R5/NMSPacketChannel.java @@ -12,6 +12,7 @@ import me.lojosho.hibiscuscommons.plugins.SubPlugins; import me.lojosho.hibiscuscommons.util.MessagesUtil; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.*; +import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.inventory.ClickType; import net.minecraft.world.item.ItemStack; @@ -182,7 +183,18 @@ public class NMSPacketChannel extends ChannelDuplexHandler { } AtomicReference action = new AtomicReference<>(PacketAction.NOTHING); - PlayerScaleWrapper wrapper = new PlayerScaleWrapper(packet.getEntityId(), nmsScaleAttribute.base()); + + final double base = nmsScaleAttribute.base(); + double total = base; + + for (AttributeModifier modifier : nmsScaleAttribute.modifiers()) { + switch (modifier.operation()) { + case ADD_VALUE -> total += modifier.amount(); + case ADD_MULTIPLIED_BASE -> total += modifier.amount() * nmsScaleAttribute.base(); + case ADD_MULTIPLIED_TOTAL -> total += modifier.amount() * total; + } + } + PlayerScaleWrapper wrapper = new PlayerScaleWrapper(packet.getEntityId(), base, total); SubPlugins.getSubPlugins().forEach(plugin -> { PacketAction pluginAction = plugin.getPacketInterface().readPlayerScale(player, wrapper);