fix BaubleType.UNIVERSAL not working (#6)

This commit is contained in:
Alexdoru authored and GitHub committed 2024-10-01 21:05:57 +02:00
1 parent 46abac47c5
commit 54b672c618
5 files changed
+45 -49

No files matched your search

+14 -14
View File
@@ -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);
}
@@ -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<String> registeredTypes = new ArrayList<String>();
private static final String[] assignedSlots = new String[slotLimit];
private static final ArrayList<String> registeredTypes = new ArrayList<String>();
static {
registeredTypes.add(unknownType);
registeredTypes.add(ringType);
@@ -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);
}
@@ -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;
}
@@ -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() {