mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-19 15:09:26 +00:00
Merge pull request #19 from OakLoaf/feat/scale
Added support for scale packet
This commit is contained in:
@@ -83,6 +83,8 @@ public interface NMSPackets {
|
|||||||
|
|
||||||
void sendEntityDestroyPacket(IntList entityIds, List<Player> sendTo);
|
void sendEntityDestroyPacket(IntList entityIds, List<Player> sendTo);
|
||||||
|
|
||||||
|
void sendEntityScalePacket(int entityId, double scale, List<Player> sendTo);
|
||||||
|
|
||||||
void sendItemDisplayMetadata(int entityId,
|
void sendItemDisplayMetadata(int entityId,
|
||||||
Vector3f translation,
|
Vector3f translation,
|
||||||
Vector3f scale,
|
Vector3f scale,
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ public interface PacketInterface {
|
|||||||
// Override
|
// Override
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default PacketAction readPlayerScale(@NotNull Player player, @NotNull PlayerScaleWrapper wrapper) {
|
||||||
|
return PacketAction.NOTHING;
|
||||||
|
// Override
|
||||||
|
}
|
||||||
|
|
||||||
default PacketAction readEntityHandle(@NotNull Player player, @NotNull PlayerInteractWrapper wrapper) {
|
default PacketAction readEntityHandle(@NotNull Player player, @NotNull PlayerInteractWrapper wrapper) {
|
||||||
return PacketAction.NOTHING;
|
return PacketAction.NOTHING;
|
||||||
// Override
|
// Override
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package me.lojosho.hibiscuscommons.packets.wrapper;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public class PlayerScaleWrapper {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final int entityId;
|
||||||
|
@Getter
|
||||||
|
private final double scale;
|
||||||
|
|
||||||
|
public PlayerScaleWrapper(int entityId, double scale) {
|
||||||
|
this.entityId = entityId;
|
||||||
|
this.scale = scale;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,6 +26,8 @@ import net.minecraft.server.level.ServerLevel;
|
|||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.level.GameType;
|
import net.minecraft.world.level.GameType;
|
||||||
@@ -328,6 +330,18 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
for (Player p : sendTo) sendPacket(p, packet);
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEntityScalePacket(int entityId, double scale, List<Player> sendTo) {
|
||||||
|
AttributeInstance attribute = new AttributeInstance(
|
||||||
|
Attributes.SCALE,
|
||||||
|
(ignored) -> {}
|
||||||
|
);
|
||||||
|
attribute.setBaseValue(scale);
|
||||||
|
|
||||||
|
ClientboundUpdateAttributesPacket packet = new ClientboundUpdateAttributesPacket(entityId, List.of(attribute));
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendItemDisplayMetadata(int entityId,
|
public void sendItemDisplayMetadata(int entityId,
|
||||||
Vector3f translation,
|
Vector3f translation,
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import net.minecraft.server.level.ServerLevel;
|
|||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.level.GameType;
|
import net.minecraft.world.level.GameType;
|
||||||
@@ -327,6 +329,18 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
for (Player p : sendTo) sendPacket(p, packet);
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEntityScalePacket(int entityId, double scale, List<Player> sendTo) {
|
||||||
|
AttributeInstance attribute = new AttributeInstance(
|
||||||
|
Attributes.SCALE,
|
||||||
|
(ignored) -> {}
|
||||||
|
);
|
||||||
|
attribute.setBaseValue(scale);
|
||||||
|
|
||||||
|
ClientboundUpdateAttributesPacket packet = new ClientboundUpdateAttributesPacket(entityId, List.of(attribute));
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendItemDisplayMetadata(int entityId,
|
public void sendItemDisplayMetadata(int entityId,
|
||||||
Vector3f translation,
|
Vector3f translation,
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import net.minecraft.server.level.ServerPlayer;
|
|||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
import net.minecraft.world.entity.PositionMoveRotation;
|
import net.minecraft.world.entity.PositionMoveRotation;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.level.GameType;
|
import net.minecraft.world.level.GameType;
|
||||||
@@ -330,6 +332,18 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
for (Player p : sendTo) sendPacket(p, packet);
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEntityScalePacket(int entityId, double scale, List<Player> sendTo) {
|
||||||
|
AttributeInstance attribute = new AttributeInstance(
|
||||||
|
Attributes.SCALE,
|
||||||
|
(ignored) -> {}
|
||||||
|
);
|
||||||
|
attribute.setBaseValue(scale);
|
||||||
|
|
||||||
|
ClientboundUpdateAttributesPacket packet = new ClientboundUpdateAttributesPacket(entityId, List.of(attribute));
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendItemDisplayMetadata(int entityId,
|
public void sendItemDisplayMetadata(int entityId,
|
||||||
Vector3f translation,
|
Vector3f translation,
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import net.minecraft.server.level.ServerPlayer;
|
|||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
import net.minecraft.world.entity.PositionMoveRotation;
|
import net.minecraft.world.entity.PositionMoveRotation;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.level.GameType;
|
import net.minecraft.world.level.GameType;
|
||||||
@@ -334,6 +336,18 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
for (Player p : sendTo) sendPacket(p, packet);
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEntityScalePacket(int entityId, double scale, List<Player> sendTo) {
|
||||||
|
AttributeInstance attribute = new AttributeInstance(
|
||||||
|
Attributes.SCALE,
|
||||||
|
(ignored) -> {}
|
||||||
|
);
|
||||||
|
attribute.setBaseValue(scale);
|
||||||
|
|
||||||
|
ClientboundUpdateAttributesPacket packet = new ClientboundUpdateAttributesPacket(entityId, List.of(attribute));
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendItemDisplayMetadata(int entityId,
|
public void sendItemDisplayMetadata(int entityId,
|
||||||
Vector3f translation,
|
Vector3f translation,
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ import net.minecraft.server.level.ServerPlayer;
|
|||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
import net.minecraft.world.entity.PositionMoveRotation;
|
import net.minecraft.world.entity.PositionMoveRotation;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.level.GameType;
|
import net.minecraft.world.level.GameType;
|
||||||
@@ -335,6 +337,18 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
for (Player p : sendTo) sendPacket(p, packet);
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEntityScalePacket(int entityId, double scale, List<Player> sendTo) {
|
||||||
|
AttributeInstance attribute = new AttributeInstance(
|
||||||
|
Attributes.SCALE,
|
||||||
|
(ignored) -> {}
|
||||||
|
);
|
||||||
|
attribute.setBaseValue(scale);
|
||||||
|
|
||||||
|
ClientboundUpdateAttributesPacket packet = new ClientboundUpdateAttributesPacket(entityId, List.of(attribute));
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendItemDisplayMetadata(int entityId,
|
public void sendItemDisplayMetadata(int entityId,
|
||||||
Vector3f translation,
|
Vector3f translation,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import me.lojosho.hibiscuscommons.plugins.SubPlugins;
|
|||||||
import me.lojosho.hibiscuscommons.util.MessagesUtil;
|
import me.lojosho.hibiscuscommons.util.MessagesUtil;
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.*;
|
import net.minecraft.network.protocol.game.*;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||||
import net.minecraft.world.inventory.ClickType;
|
import net.minecraft.world.inventory.ClickType;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||||
@@ -45,6 +46,7 @@ public class NMSPacketChannel extends ChannelDuplexHandler {
|
|||||||
case ClientboundContainerSetSlotPacket setSlotPacket -> msg = handleSlotChange(setSlotPacket);
|
case ClientboundContainerSetSlotPacket setSlotPacket -> msg = handleSlotChange(setSlotPacket);
|
||||||
case ClientboundSetEquipmentPacket equipmentPacket -> msg = handlePlayerEquipment(equipmentPacket);
|
case ClientboundSetEquipmentPacket equipmentPacket -> msg = handlePlayerEquipment(equipmentPacket);
|
||||||
case ClientboundSetPassengersPacket passengerPacket -> msg = handlePassengerSet(passengerPacket);
|
case ClientboundSetPassengersPacket passengerPacket -> msg = handlePassengerSet(passengerPacket);
|
||||||
|
case ClientboundUpdateAttributesPacket attributesPacket -> msg = handleScaleChange(attributesPacket);
|
||||||
default -> {}
|
default -> {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,6 +170,30 @@ public class NMSPacketChannel extends ChannelDuplexHandler {
|
|||||||
return (Packet<?>) NMSHandlers.getHandler().getPacketHandler().createMountPacket(ownerId, passengers.stream().mapToInt(Integer::intValue).toArray());
|
return (Packet<?>) NMSHandlers.getHandler().getPacketHandler().createMountPacket(ownerId, passengers.stream().mapToInt(Integer::intValue).toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Packet<?> handleScaleChange(@NotNull ClientboundUpdateAttributesPacket packet) {
|
||||||
|
final List<ClientboundUpdateAttributesPacket.AttributeSnapshot> nmsAttributes = packet.getValues();
|
||||||
|
final ClientboundUpdateAttributesPacket.AttributeSnapshot nmsScaleAttribute = nmsAttributes.stream()
|
||||||
|
.filter(attribute -> attribute.attribute().equals(Attributes.SCALE))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (nmsScaleAttribute == null) {
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
AtomicReference<PacketAction> action = new AtomicReference<>(PacketAction.NOTHING);
|
||||||
|
PlayerScaleWrapper wrapper = new PlayerScaleWrapper(packet.getEntityId(), nmsScaleAttribute.base());
|
||||||
|
|
||||||
|
SubPlugins.getSubPlugins().forEach(plugin -> {
|
||||||
|
PacketAction pluginAction = plugin.getPacketInterface().readPlayerScale(player, wrapper);
|
||||||
|
if (pluginAction != PacketAction.NOTHING) action.set(pluginAction);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (action.get() == PacketAction.CANCELLED) return null;
|
||||||
|
if (action.get() == PacketAction.NOTHING) return packet;
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||||
if (!(msg instanceof Packet packet)) {
|
if (!(msg instanceof Packet packet)) {
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ import net.minecraft.server.level.ServerPlayer;
|
|||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EquipmentSlot;
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
import net.minecraft.world.entity.PositionMoveRotation;
|
import net.minecraft.world.entity.PositionMoveRotation;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||||
import net.minecraft.world.entity.decoration.ArmorStand;
|
import net.minecraft.world.entity.decoration.ArmorStand;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.level.GameType;
|
import net.minecraft.world.level.GameType;
|
||||||
@@ -339,6 +341,18 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
|||||||
for (Player p : sendTo) sendPacket(p, packet);
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendEntityScalePacket(int entityId, double scale, List<Player> sendTo) {
|
||||||
|
AttributeInstance attribute = new AttributeInstance(
|
||||||
|
Attributes.SCALE,
|
||||||
|
(ignored) -> {}
|
||||||
|
);
|
||||||
|
attribute.setBaseValue(scale);
|
||||||
|
|
||||||
|
ClientboundUpdateAttributesPacket packet = new ClientboundUpdateAttributesPacket(entityId, List.of(attribute));
|
||||||
|
for (Player p : sendTo) sendPacket(p, packet);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendItemDisplayMetadata(int entityId,
|
public void sendItemDisplayMetadata(int entityId,
|
||||||
Vector3f translation,
|
Vector3f translation,
|
||||||
|
|||||||
Reference in New Issue
Block a user