Added EquipmentHandler#setEquipment

This commit is contained in:
TheMode 2021-04-10 19:30:25 +02:00
parent ebbfe7868b
commit ea293bd376

View File

@ -20,8 +20,7 @@ public interface EquipmentHandler {
*
* @return the {@link ItemStack} in main hand
*/
@NotNull
ItemStack getItemInMainHand();
@NotNull ItemStack getItemInMainHand();
/**
* Changes the main hand {@link ItemStack}.
@ -35,8 +34,7 @@ public interface EquipmentHandler {
*
* @return the item in off hand
*/
@NotNull
ItemStack getItemInOffHand();
@NotNull ItemStack getItemInOffHand();
/**
* Changes the off hand {@link ItemStack}.
@ -51,8 +49,7 @@ public interface EquipmentHandler {
* @param hand the Hand to get the {@link ItemStack} from
* @return the {@link ItemStack} in {@code hand}
*/
@NotNull
default ItemStack getItemInHand(@NotNull Player.Hand hand) {
default @NotNull ItemStack getItemInHand(@NotNull Player.Hand hand) {
switch (hand) {
case MAIN:
return getItemInMainHand();
@ -85,8 +82,7 @@ public interface EquipmentHandler {
*
* @return the helmet
*/
@NotNull
ItemStack getHelmet();
@NotNull ItemStack getHelmet();
/**
* Changes the helmet.
@ -100,8 +96,7 @@ public interface EquipmentHandler {
*
* @return the chestplate
*/
@NotNull
ItemStack getChestplate();
@NotNull ItemStack getChestplate();
/**
* Changes the chestplate.
@ -115,8 +110,7 @@ public interface EquipmentHandler {
*
* @return the leggings
*/
@NotNull
ItemStack getLeggings();
@NotNull ItemStack getLeggings();
/**
* Changes the leggings.
@ -130,8 +124,7 @@ public interface EquipmentHandler {
*
* @return the boots
*/
@NotNull
ItemStack getBoots();
@NotNull ItemStack getBoots();
/**
* Changes the boots.
@ -146,8 +139,7 @@ public interface EquipmentHandler {
* @param slot the equipment to get the item from
* @return the equipment {@link ItemStack}
*/
@NotNull
default ItemStack getEquipment(@NotNull EntityEquipmentPacket.Slot slot) {
default @NotNull ItemStack getEquipment(@NotNull EntityEquipmentPacket.Slot slot) {
switch (slot) {
case MAIN_HAND:
return getItemInMainHand();
@ -165,6 +157,31 @@ public interface EquipmentHandler {
throw new IllegalStateException("Something weird happened");
}
default void setEquipment(@NotNull EntityEquipmentPacket.Slot slot, @NotNull ItemStack itemStack) {
switch (slot) {
case MAIN_HAND:
setItemInMainHand(itemStack);
break;
case OFF_HAND:
setItemInOffHand(itemStack);
break;
case HELMET:
setHelmet(itemStack);
break;
case CHESTPLATE:
setChestplate(itemStack);
break;
case LEGGINGS:
setLeggings(itemStack);
break;
case BOOTS:
setBoots(itemStack);
break;
default:
throw new IllegalStateException("Something weird happened");
}
}
/**
* Sends a specific equipment to viewers.
*
@ -191,8 +208,7 @@ public interface EquipmentHandler {
* @return the packet with the equipments
* @throws IllegalStateException if 'this' is not an {@link Entity}
*/
@NotNull
default EntityEquipmentPacket getEquipmentsPacket() {
default @NotNull EntityEquipmentPacket getEquipmentsPacket() {
Check.stateCondition(!(this instanceof Entity), "Only accessible for Entity");
final Entity entity = (Entity) this;