diff --git a/src/main/java/baubles/api/IBauble.java b/src/main/java/baubles/api/IBauble.java index 69885b8..0e6e7c4 100644 --- a/src/main/java/baubles/api/IBauble.java +++ b/src/main/java/baubles/api/IBauble.java @@ -4,42 +4,42 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; /** - * + * * This interface should be extended by items that can be worn in bauble slots - * + * * @author Azanor */ public interface IBauble { - + /** - * This method returns the type of bauble this is. + * This method returns the type of bauble this is. * Type is used to determine the slots it can go into. */ - public BaubleType getBaubleType(ItemStack itemstack); - + BaubleType getBaubleType(ItemStack itemstack); + /** * This method is called once per tick if the bauble is being worn by a player */ - public void onWornTick(ItemStack itemstack, EntityLivingBase player); - + void onWornTick(ItemStack itemstack, EntityLivingBase player); + /** * This method is called when the bauble is equipped by a player */ - public void onEquipped(ItemStack itemstack, EntityLivingBase player); - + void onEquipped(ItemStack itemstack, EntityLivingBase player); + /** * This method is called when the bauble is unequipped by a player */ - public void onUnequipped(ItemStack itemstack, EntityLivingBase player); + void onUnequipped(ItemStack itemstack, EntityLivingBase player); /** * can this bauble be placed in a bauble slot */ - public boolean canEquip(ItemStack itemstack, EntityLivingBase player); - + boolean canEquip(ItemStack itemstack, EntityLivingBase player); + /** * Can this bauble be removed from a bauble slot */ - public boolean canUnequip(ItemStack itemstack, EntityLivingBase player); + boolean canUnequip(ItemStack itemstack, EntityLivingBase player); } diff --git a/src/main/java/baubles/api/expanded/BaubleExpandedSlots.java b/src/main/java/baubles/api/expanded/BaubleExpandedSlots.java index d66f22d..0efe585 100644 --- a/src/main/java/baubles/api/expanded/BaubleExpandedSlots.java +++ b/src/main/java/baubles/api/expanded/BaubleExpandedSlots.java @@ -198,7 +198,7 @@ public class BaubleExpandedSlots { * @return an array of slot indexes with the specified type. */ public static int[] getIndexesOfAssignedSlotsOfType(String type) { - int slotIndexes[] = new int[0]; + int[] slotIndexes = new int[0]; if(isTypeRegistered(type)) { for(int slotToCheck = 0; slotToCheck < slotLimit; slotToCheck++) { if(assignedSlots[slotToCheck].equals(type)) { @@ -295,18 +295,13 @@ public class BaubleExpandedSlots { if(type == null) { return invalidType; } - switch(type) { - case RING: - return ringType; - case AMULET: - return amuletType; - case BELT: - return beltType; - case UNIVERSAL: - return universalType; - default: - return unknownType; - } + return switch (type) { + case RING -> ringType; + case AMULET -> amuletType; + case BELT -> beltType; + case UNIVERSAL -> universalType; + default -> unknownType; + }; } /** @@ -333,8 +328,8 @@ public class BaubleExpandedSlots { } private static int newSlotsRemaining; - private static String[] assignedSlots = new String[slotLimit]; - private static ArrayList registeredTypes = new ArrayList(); + private static final String[] assignedSlots = new String[slotLimit]; + private static final ArrayList registeredTypes = new ArrayList(); static { registeredTypes.add(unknownType); registeredTypes.add(ringType); diff --git a/src/main/java/baubles/api/expanded/IBaubleExpanded.java b/src/main/java/baubles/api/expanded/IBaubleExpanded.java index b258002..826c620 100644 --- a/src/main/java/baubles/api/expanded/IBaubleExpanded.java +++ b/src/main/java/baubles/api/expanded/IBaubleExpanded.java @@ -6,16 +6,16 @@ import net.minecraft.item.ItemStack; /** * This interface should be extended by items that can be worn in bauble slots. * Supports all original and several expanded slot types. - * + * * @author jss2a98aj */ public interface IBaubleExpanded extends IBauble { - + /** * This method returns the types of bauble slots this item can go into. * getBaubleType is generally ignored when using IBaubleExpanded, so it can return null unless you want backwards compatibility with official bauble builds. * Pre-registered slot types can be found in BaubleExpandedSlots, but it is possible to add more during pre-initialization. */ - public String[] getBaubleTypes (ItemStack itemstack); + String[] getBaubleTypes (ItemStack itemstack); } diff --git a/src/main/java/baubles/common/container/ContainerPlayerExpanded.java b/src/main/java/baubles/common/container/ContainerPlayerExpanded.java index 122c05c..4a102ac 100644 --- a/src/main/java/baubles/common/container/ContainerPlayerExpanded.java +++ b/src/main/java/baubles/common/container/ContainerPlayerExpanded.java @@ -103,7 +103,7 @@ public class ContainerPlayerExpanded extends Container { if(!mergeItemStack(originalStack, armorSlot, armorSlot + 1, false)) { returnStack = null; } - } else if(returnStack != null && slotIndex >= 4 + visibleBaubleSlots && item instanceof IBauble && ((IBauble)item).canEquip(returnStack, thePlayer)) { + } else if(slotIndex >= 4 + visibleBaubleSlots && item instanceof IBauble && ((IBauble) item).canEquip(returnStack, thePlayer)) { for(int baubleSlot = 4; baubleSlot < 4 + visibleBaubleSlots; baubleSlot++) { if(returnStack == null) { break; @@ -122,15 +122,15 @@ public class ContainerPlayerExpanded extends Container { } } } - } else if(returnStack != null && slotIndex >= 4 + visibleBaubleSlots && slotIndex < 31 + visibleBaubleSlots) { + } else if(slotIndex >= 4 + visibleBaubleSlots && slotIndex < 31 + visibleBaubleSlots) { if(!mergeItemStack(originalStack, 31 + visibleBaubleSlots, 40 + visibleBaubleSlots, false)) { returnStack = null; } - } else if(returnStack != null && slotIndex >= 31 + visibleBaubleSlots && slotIndex < 40 + visibleBaubleSlots) { + } else if(slotIndex >= 31 + visibleBaubleSlots && slotIndex < 40 + visibleBaubleSlots) { if(!mergeItemStack(originalStack, 4 + visibleBaubleSlots, 31 + visibleBaubleSlots, false)) { returnStack = null; } - } else if(returnStack != null && !mergeItemStack(originalStack, 4 + visibleBaubleSlots, 40 + visibleBaubleSlots, false, slot)) { + } else if(!mergeItemStack(originalStack, 4 + visibleBaubleSlots, 40 + visibleBaubleSlots, false, slot)) { returnStack = null; } diff --git a/src/main/java/baubles/common/container/SlotBauble.java b/src/main/java/baubles/common/container/SlotBauble.java index c211b3b..68a2f57 100644 --- a/src/main/java/baubles/common/container/SlotBauble.java +++ b/src/main/java/baubles/common/container/SlotBauble.java @@ -25,7 +25,7 @@ public class SlotBauble extends Slot { slotType = BaubleExpandedSlots.getTypeFromBaubleType(legacyType); } - + public SlotBauble(IInventory inventory, String type, int slot, int x, int y) { super(inventory, slot, x, y); if(type == null) { @@ -49,18 +49,19 @@ public class SlotBauble extends Slot { return false; } - String[] types; - if(item instanceof IBaubleExpanded) { - types = ((IBaubleExpanded)item).getBaubleTypes(stack); - } else { - types = new String[] {BaubleExpandedSlots.getTypeFromBaubleType(((IBauble)item).getBaubleType(stack))}; - } + String[] types; + if(item instanceof IBaubleExpanded) { + types = ((IBaubleExpanded)item).getBaubleTypes(stack); + } else { + BaubleType legacyType = ((IBauble)item).getBaubleType(stack); + types = new String[] {BaubleExpandedSlots.getTypeFromBaubleType(legacyType)}; + } - for(String type : types) { - if(type.equals(slotType)) { - return true; - } - } + for(String type : types) { + if(type.equals(BaubleExpandedSlots.universalType) || type.equals(slotType)) { + return true; + } + } return false; } @@ -75,7 +76,7 @@ public class SlotBauble extends Slot { public int getSlotStackLimit() { return 1; } - + @Override @SideOnly(Side.CLIENT) public IIcon getBackgroundIconIndex() {