mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-31 21:48:08 +01:00
Moved EquipmentSlot out of equipment packet
This commit is contained in:
parent
19e22d03ce
commit
29b0f5448d
49
src/main/java/net/minestom/server/entity/EquipmentSlot.java
Normal file
49
src/main/java/net/minestom/server/entity/EquipmentSlot.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package net.minestom.server.entity;
|
||||||
|
|
||||||
|
import net.minestom.server.event.item.ArmorEquipEvent;
|
||||||
|
import net.minestom.server.item.attribute.AttributeSlot;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public enum EquipmentSlot {
|
||||||
|
MAIN_HAND,
|
||||||
|
OFF_HAND,
|
||||||
|
BOOTS,
|
||||||
|
LEGGINGS,
|
||||||
|
CHESTPLATE,
|
||||||
|
HELMET;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static EquipmentSlot fromArmorSlot(ArmorEquipEvent.ArmorSlot armorSlot) {
|
||||||
|
switch (armorSlot) {
|
||||||
|
case HELMET:
|
||||||
|
return HELMET;
|
||||||
|
case CHESTPLATE:
|
||||||
|
return CHESTPLATE;
|
||||||
|
case LEGGINGS:
|
||||||
|
return LEGGINGS;
|
||||||
|
case BOOTS:
|
||||||
|
return BOOTS;
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Something weird happened");
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static EquipmentSlot fromAttributeSlot(AttributeSlot attributeSlot) {
|
||||||
|
switch (attributeSlot) {
|
||||||
|
case MAINHAND:
|
||||||
|
return MAIN_HAND;
|
||||||
|
case OFFHAND:
|
||||||
|
return OFF_HAND;
|
||||||
|
case FEET:
|
||||||
|
return BOOTS;
|
||||||
|
case LEGS:
|
||||||
|
return LEGGINGS;
|
||||||
|
case CHEST:
|
||||||
|
return CHESTPLATE;
|
||||||
|
case HEAD:
|
||||||
|
return HELMET;
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Something weird happened");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -128,7 +128,7 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void setItemInMainHand(@NotNull ItemStack itemStack) {
|
public void setItemInMainHand(@NotNull ItemStack itemStack) {
|
||||||
this.mainHandItem = itemStack;
|
this.mainHandItem = itemStack;
|
||||||
syncEquipment(EntityEquipmentPacket.Slot.MAIN_HAND);
|
syncEquipment(EquipmentSlot.MAIN_HAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -140,7 +140,7 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void setItemInOffHand(@NotNull ItemStack itemStack) {
|
public void setItemInOffHand(@NotNull ItemStack itemStack) {
|
||||||
this.offHandItem = itemStack;
|
this.offHandItem = itemStack;
|
||||||
syncEquipment(EntityEquipmentPacket.Slot.OFF_HAND);
|
syncEquipment(EquipmentSlot.OFF_HAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -152,7 +152,7 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void setHelmet(@NotNull ItemStack itemStack) {
|
public void setHelmet(@NotNull ItemStack itemStack) {
|
||||||
this.helmet = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.HELMET);
|
this.helmet = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.HELMET);
|
||||||
syncEquipment(EntityEquipmentPacket.Slot.HELMET);
|
syncEquipment(EquipmentSlot.HELMET);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -164,7 +164,7 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void setChestplate(@NotNull ItemStack itemStack) {
|
public void setChestplate(@NotNull ItemStack itemStack) {
|
||||||
this.chestplate = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.CHESTPLATE);
|
this.chestplate = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.CHESTPLATE);
|
||||||
syncEquipment(EntityEquipmentPacket.Slot.CHESTPLATE);
|
syncEquipment(EquipmentSlot.CHESTPLATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -176,7 +176,7 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void setLeggings(@NotNull ItemStack itemStack) {
|
public void setLeggings(@NotNull ItemStack itemStack) {
|
||||||
this.leggings = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.LEGGINGS);
|
this.leggings = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.LEGGINGS);
|
||||||
syncEquipment(EntityEquipmentPacket.Slot.LEGGINGS);
|
syncEquipment(EquipmentSlot.LEGGINGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -188,7 +188,7 @@ public class LivingEntity extends Entity implements EquipmentHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void setBoots(@NotNull ItemStack itemStack) {
|
public void setBoots(@NotNull ItemStack itemStack) {
|
||||||
this.boots = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.BOOTS);
|
this.boots = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.BOOTS);
|
||||||
syncEquipment(EntityEquipmentPacket.Slot.BOOTS);
|
syncEquipment(EquipmentSlot.BOOTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack getEquipmentItem(@NotNull ItemStack itemStack, @NotNull ArmorEquipEvent.ArmorSlot armorSlot) {
|
private ItemStack getEquipmentItem(@NotNull ItemStack itemStack, @NotNull ArmorEquipEvent.ArmorSlot armorSlot) {
|
||||||
|
@ -2256,7 +2256,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
*/
|
*/
|
||||||
public void refreshHeldSlot(byte slot) {
|
public void refreshHeldSlot(byte slot) {
|
||||||
this.heldSlot = slot;
|
this.heldSlot = slot;
|
||||||
syncEquipment(EntityEquipmentPacket.Slot.MAIN_HAND);
|
syncEquipment(EquipmentSlot.MAIN_HAND);
|
||||||
|
|
||||||
refreshEating(null);
|
refreshEating(null);
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
package net.minestom.server.entity.type.decoration;
|
package net.minestom.server.entity.type.decoration;
|
||||||
|
|
||||||
import net.minestom.server.entity.EntityType;
|
import net.minestom.server.entity.*;
|
||||||
import net.minestom.server.entity.Metadata;
|
|
||||||
import net.minestom.server.entity.ObjectEntity;
|
|
||||||
import net.minestom.server.entity.Player;
|
|
||||||
import net.minestom.server.event.item.ArmorEquipEvent;
|
import net.minestom.server.event.item.ArmorEquipEvent;
|
||||||
import net.minestom.server.inventory.EquipmentHandler;
|
import net.minestom.server.inventory.EquipmentHandler;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import net.minestom.server.network.packet.server.play.EntityEquipmentPacket;
|
|
||||||
import net.minestom.server.utils.Position;
|
import net.minestom.server.utils.Position;
|
||||||
import net.minestom.server.utils.Vector;
|
import net.minestom.server.utils.Vector;
|
||||||
import net.minestom.server.utils.binary.BitmaskUtil;
|
import net.minestom.server.utils.binary.BitmaskUtil;
|
||||||
@ -74,7 +70,7 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void setItemInMainHand(@NotNull ItemStack itemStack) {
|
public void setItemInMainHand(@NotNull ItemStack itemStack) {
|
||||||
this.mainHandItem = itemStack;
|
this.mainHandItem = itemStack;
|
||||||
syncEquipment(EntityEquipmentPacket.Slot.MAIN_HAND);
|
syncEquipment(EquipmentSlot.MAIN_HAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -86,7 +82,7 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void setItemInOffHand(@NotNull ItemStack itemStack) {
|
public void setItemInOffHand(@NotNull ItemStack itemStack) {
|
||||||
this.offHandItem = itemStack;
|
this.offHandItem = itemStack;
|
||||||
syncEquipment(EntityEquipmentPacket.Slot.OFF_HAND);
|
syncEquipment(EquipmentSlot.OFF_HAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -98,7 +94,7 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void setHelmet(@NotNull ItemStack itemStack) {
|
public void setHelmet(@NotNull ItemStack itemStack) {
|
||||||
this.helmet = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.HELMET);
|
this.helmet = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.HELMET);
|
||||||
syncEquipment(EntityEquipmentPacket.Slot.HELMET);
|
syncEquipment(EquipmentSlot.HELMET);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -110,7 +106,7 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void setChestplate(@NotNull ItemStack itemStack) {
|
public void setChestplate(@NotNull ItemStack itemStack) {
|
||||||
this.chestplate = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.CHESTPLATE);
|
this.chestplate = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.CHESTPLATE);
|
||||||
syncEquipment(EntityEquipmentPacket.Slot.CHESTPLATE);
|
syncEquipment(EquipmentSlot.CHESTPLATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -122,7 +118,7 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void setLeggings(@NotNull ItemStack itemStack) {
|
public void setLeggings(@NotNull ItemStack itemStack) {
|
||||||
this.leggings = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.LEGGINGS);
|
this.leggings = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.LEGGINGS);
|
||||||
syncEquipment(EntityEquipmentPacket.Slot.LEGGINGS);
|
syncEquipment(EquipmentSlot.LEGGINGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -134,7 +130,7 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void setBoots(@NotNull ItemStack itemStack) {
|
public void setBoots(@NotNull ItemStack itemStack) {
|
||||||
this.boots = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.BOOTS);
|
this.boots = getEquipmentItem(itemStack, ArmorEquipEvent.ArmorSlot.BOOTS);
|
||||||
syncEquipment(EntityEquipmentPacket.Slot.BOOTS);
|
syncEquipment(EquipmentSlot.BOOTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSmall() {
|
public boolean isSmall() {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.minestom.server.inventory;
|
package net.minestom.server.inventory;
|
||||||
|
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
|
import net.minestom.server.entity.EquipmentSlot;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import net.minestom.server.network.packet.server.play.EntityEquipmentPacket;
|
import net.minestom.server.network.packet.server.play.EntityEquipmentPacket;
|
||||||
@ -139,7 +140,7 @@ public interface EquipmentHandler {
|
|||||||
* @param slot the equipment to get the item from
|
* @param slot the equipment to get the item from
|
||||||
* @return the equipment {@link ItemStack}
|
* @return the equipment {@link ItemStack}
|
||||||
*/
|
*/
|
||||||
default @NotNull ItemStack getEquipment(@NotNull EntityEquipmentPacket.Slot slot) {
|
default @NotNull ItemStack getEquipment(@NotNull EquipmentSlot slot) {
|
||||||
switch (slot) {
|
switch (slot) {
|
||||||
case MAIN_HAND:
|
case MAIN_HAND:
|
||||||
return getItemInMainHand();
|
return getItemInMainHand();
|
||||||
@ -157,7 +158,7 @@ public interface EquipmentHandler {
|
|||||||
throw new IllegalStateException("Something weird happened");
|
throw new IllegalStateException("Something weird happened");
|
||||||
}
|
}
|
||||||
|
|
||||||
default void setEquipment(@NotNull EntityEquipmentPacket.Slot slot, @NotNull ItemStack itemStack) {
|
default void setEquipment(@NotNull EquipmentSlot slot, @NotNull ItemStack itemStack) {
|
||||||
switch (slot) {
|
switch (slot) {
|
||||||
case MAIN_HAND:
|
case MAIN_HAND:
|
||||||
setItemInMainHand(itemStack);
|
setItemInMainHand(itemStack);
|
||||||
@ -187,7 +188,7 @@ public interface EquipmentHandler {
|
|||||||
*
|
*
|
||||||
* @param slot the slot of the equipment
|
* @param slot the slot of the equipment
|
||||||
*/
|
*/
|
||||||
default void syncEquipment(@NotNull EntityEquipmentPacket.Slot slot) {
|
default void syncEquipment(@NotNull EquipmentSlot slot) {
|
||||||
Check.stateCondition(!(this instanceof Entity), "Only accessible for Entity");
|
Check.stateCondition(!(this instanceof Entity), "Only accessible for Entity");
|
||||||
|
|
||||||
Entity entity = (Entity) this;
|
Entity entity = (Entity) this;
|
||||||
@ -196,7 +197,7 @@ public interface EquipmentHandler {
|
|||||||
|
|
||||||
EntityEquipmentPacket entityEquipmentPacket = new EntityEquipmentPacket();
|
EntityEquipmentPacket entityEquipmentPacket = new EntityEquipmentPacket();
|
||||||
entityEquipmentPacket.entityId = entity.getEntityId();
|
entityEquipmentPacket.entityId = entity.getEntityId();
|
||||||
entityEquipmentPacket.slots = new EntityEquipmentPacket.Slot[]{slot};
|
entityEquipmentPacket.slots = new EquipmentSlot[]{slot};
|
||||||
entityEquipmentPacket.itemStacks = new ItemStack[]{itemStack};
|
entityEquipmentPacket.itemStacks = new ItemStack[]{itemStack};
|
||||||
|
|
||||||
entity.sendPacketToViewers(entityEquipmentPacket);
|
entity.sendPacketToViewers(entityEquipmentPacket);
|
||||||
@ -213,12 +214,12 @@ public interface EquipmentHandler {
|
|||||||
|
|
||||||
final Entity entity = (Entity) this;
|
final Entity entity = (Entity) this;
|
||||||
|
|
||||||
final EntityEquipmentPacket.Slot[] slots = EntityEquipmentPacket.Slot.values();
|
final EquipmentSlot[] slots = EquipmentSlot.values();
|
||||||
|
|
||||||
List<ItemStack> itemStacks = new ArrayList<>(slots.length);
|
List<ItemStack> itemStacks = new ArrayList<>(slots.length);
|
||||||
|
|
||||||
// Fill items
|
// Fill items
|
||||||
for (EntityEquipmentPacket.Slot slot : slots) {
|
for (EquipmentSlot slot : slots) {
|
||||||
final ItemStack equipment = getEquipment(slot);
|
final ItemStack equipment = getEquipment(slot);
|
||||||
itemStacks.add(equipment);
|
itemStacks.add(equipment);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package net.minestom.server.inventory;
|
package net.minestom.server.inventory;
|
||||||
|
|
||||||
|
import net.minestom.server.entity.EquipmentSlot;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.event.item.ArmorEquipEvent;
|
import net.minestom.server.event.item.ArmorEquipEvent;
|
||||||
import net.minestom.server.inventory.click.ClickType;
|
import net.minestom.server.inventory.click.ClickType;
|
||||||
import net.minestom.server.inventory.click.InventoryClickResult;
|
import net.minestom.server.inventory.click.InventoryClickResult;
|
||||||
import net.minestom.server.inventory.condition.InventoryCondition;
|
import net.minestom.server.inventory.condition.InventoryCondition;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import net.minestom.server.network.packet.server.play.EntityEquipmentPacket;
|
|
||||||
import net.minestom.server.network.packet.server.play.SetSlotPacket;
|
import net.minestom.server.network.packet.server.play.SetSlotPacket;
|
||||||
import net.minestom.server.network.packet.server.play.WindowItemsPacket;
|
import net.minestom.server.network.packet.server.play.WindowItemsPacket;
|
||||||
import net.minestom.server.utils.MathUtils;
|
import net.minestom.server.utils.MathUtils;
|
||||||
@ -170,12 +170,12 @@ public class PlayerInventory extends AbstractInventory implements EquipmentHandl
|
|||||||
"The slot {0} does not exist for player", slot);
|
"The slot {0} does not exist for player", slot);
|
||||||
Check.notNull(itemStack, "The ItemStack cannot be null, you can set air instead");
|
Check.notNull(itemStack, "The ItemStack cannot be null, you can set air instead");
|
||||||
|
|
||||||
EntityEquipmentPacket.Slot equipmentSlot;
|
EquipmentSlot equipmentSlot;
|
||||||
|
|
||||||
if (slot == player.getHeldSlot()) {
|
if (slot == player.getHeldSlot()) {
|
||||||
equipmentSlot = EntityEquipmentPacket.Slot.MAIN_HAND;
|
equipmentSlot = EquipmentSlot.MAIN_HAND;
|
||||||
} else if (slot == OFFHAND_SLOT) {
|
} else if (slot == OFFHAND_SLOT) {
|
||||||
equipmentSlot = EntityEquipmentPacket.Slot.OFF_HAND;
|
equipmentSlot = EquipmentSlot.OFF_HAND;
|
||||||
} else {
|
} else {
|
||||||
ArmorEquipEvent armorEquipEvent = null;
|
ArmorEquipEvent armorEquipEvent = null;
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ public class PlayerInventory extends AbstractInventory implements EquipmentHandl
|
|||||||
|
|
||||||
if (armorEquipEvent != null) {
|
if (armorEquipEvent != null) {
|
||||||
ArmorEquipEvent.ArmorSlot armorSlot = armorEquipEvent.getArmorSlot();
|
ArmorEquipEvent.ArmorSlot armorSlot = armorEquipEvent.getArmorSlot();
|
||||||
equipmentSlot = EntityEquipmentPacket.Slot.fromArmorSlot(armorSlot);
|
equipmentSlot = EquipmentSlot.fromArmorSlot(armorSlot);
|
||||||
player.callEvent(ArmorEquipEvent.class, armorEquipEvent);
|
player.callEvent(ArmorEquipEvent.class, armorEquipEvent);
|
||||||
itemStack = armorEquipEvent.getArmorItem();
|
itemStack = armorEquipEvent.getArmorItem();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package net.minestom.server.network.packet.server.play;
|
package net.minestom.server.network.packet.server.play;
|
||||||
|
|
||||||
import net.minestom.server.event.item.ArmorEquipEvent;
|
import net.minestom.server.entity.EquipmentSlot;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import net.minestom.server.network.packet.server.ServerPacket;
|
import net.minestom.server.network.packet.server.ServerPacket;
|
||||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||||
@ -14,7 +14,7 @@ import java.util.List;
|
|||||||
public class EntityEquipmentPacket implements ServerPacket {
|
public class EntityEquipmentPacket implements ServerPacket {
|
||||||
|
|
||||||
public int entityId;
|
public int entityId;
|
||||||
public Slot[] slots;
|
public EquipmentSlot[] slots;
|
||||||
public ItemStack[] itemStacks;
|
public ItemStack[] itemStacks;
|
||||||
|
|
||||||
public EntityEquipmentPacket() {
|
public EntityEquipmentPacket() {
|
||||||
@ -33,7 +33,7 @@ public class EntityEquipmentPacket implements ServerPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < slots.length; i++) {
|
for (int i = 0; i < slots.length; i++) {
|
||||||
final Slot slot = slots[i];
|
final EquipmentSlot slot = slots[i];
|
||||||
final ItemStack itemStack = itemStacks[i];
|
final ItemStack itemStack = itemStacks[i];
|
||||||
final boolean last = i == slots.length - 1;
|
final boolean last = i == slots.length - 1;
|
||||||
|
|
||||||
@ -52,17 +52,17 @@ public class EntityEquipmentPacket implements ServerPacket {
|
|||||||
entityId = reader.readVarInt();
|
entityId = reader.readVarInt();
|
||||||
|
|
||||||
boolean hasRemaining = true;
|
boolean hasRemaining = true;
|
||||||
List<Slot> slots = new LinkedList<>();
|
List<EquipmentSlot> slots = new LinkedList<>();
|
||||||
List<ItemStack> stacks = new LinkedList<>();
|
List<ItemStack> stacks = new LinkedList<>();
|
||||||
while (hasRemaining) {
|
while (hasRemaining) {
|
||||||
byte slotEnum = reader.readByte();
|
byte slotEnum = reader.readByte();
|
||||||
hasRemaining = (slotEnum & 0x80) == 0x80;
|
hasRemaining = (slotEnum & 0x80) == 0x80;
|
||||||
|
|
||||||
slots.add(Slot.values()[slotEnum & 0x7F]);
|
slots.add(EquipmentSlot.values()[slotEnum & 0x7F]);
|
||||||
stacks.add(reader.readItemStack());
|
stacks.add(reader.readItemStack());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.slots = slots.toArray(new Slot[0]);
|
this.slots = slots.toArray(new EquipmentSlot[0]);
|
||||||
this.itemStacks = stacks.toArray(new ItemStack[0]);
|
this.itemStacks = stacks.toArray(new ItemStack[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,29 +71,4 @@ public class EntityEquipmentPacket implements ServerPacket {
|
|||||||
return ServerPacketIdentifier.ENTITY_EQUIPMENT;
|
return ServerPacketIdentifier.ENTITY_EQUIPMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Slot {
|
|
||||||
MAIN_HAND,
|
|
||||||
OFF_HAND,
|
|
||||||
BOOTS,
|
|
||||||
LEGGINGS,
|
|
||||||
CHESTPLATE,
|
|
||||||
HELMET;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static Slot fromArmorSlot(ArmorEquipEvent.ArmorSlot armorSlot) {
|
|
||||||
switch (armorSlot) {
|
|
||||||
case HELMET:
|
|
||||||
return HELMET;
|
|
||||||
case CHESTPLATE:
|
|
||||||
return CHESTPLATE;
|
|
||||||
case LEGGINGS:
|
|
||||||
return LEGGINGS;
|
|
||||||
case BOOTS:
|
|
||||||
return BOOTS;
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("Something weird happened");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package readwritepackets;
|
|||||||
|
|
||||||
import com.google.common.reflect.ClassPath;
|
import com.google.common.reflect.ClassPath;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.entity.EquipmentSlot;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import net.minestom.server.network.packet.client.ClientPacket;
|
import net.minestom.server.network.packet.client.ClientPacket;
|
||||||
import net.minestom.server.network.packet.server.ServerPacket;
|
import net.minestom.server.network.packet.server.ServerPacket;
|
||||||
@ -67,7 +68,7 @@ public class ReadWritePackets {
|
|||||||
// requires at least one slot and one item
|
// requires at least one slot and one item
|
||||||
EntityEquipmentPacket p = new EntityEquipmentPacket();
|
EntityEquipmentPacket p = new EntityEquipmentPacket();
|
||||||
p.itemStacks = new ItemStack[]{ItemStack.AIR};
|
p.itemStacks = new ItemStack[]{ItemStack.AIR};
|
||||||
p.slots = new EntityEquipmentPacket.Slot[]{EntityEquipmentPacket.Slot.MAIN_HAND};
|
p.slots = new EquipmentSlot[]{EquipmentSlot.MAIN_HAND};
|
||||||
packet = (T) p;
|
packet = (T) p;
|
||||||
} else {
|
} else {
|
||||||
packet = (T) constructor.newInstance();
|
packet = (T) constructor.newInstance();
|
||||||
|
Loading…
Reference in New Issue
Block a user