mirror of
https://github.com/GTNewHorizons/Baubles-Expanded.git
synced 2026-11-27 23:33:00 +00:00
More work on the API but IIcons are not behaving as expected
This commit is contained in:
1 parent
3773cfdcbe
commit
0a2876d407
20 files changed
+340
-72
No files matched your search
@@ -3,43 +3,57 @@ package baubles.api.expanded;
|
||||
import baubles.api.BaubleType;
|
||||
|
||||
public class BaubleExpandedSlots {
|
||||
|
||||
//The total number of slots that can be added.
|
||||
public static final int slotLimit = 20;
|
||||
|
||||
//All "default" types will have slot backgrounds registered automatically.
|
||||
public static final String ringType = "ring";
|
||||
public static final String amuletType = "amulet";
|
||||
public static final String beltType = "belt";
|
||||
public static final String headType = "head";
|
||||
public static final String bodyType = "body";
|
||||
public static final String charmType = "charm";
|
||||
public static final String gauntletType = "gauntlet";
|
||||
public static final String capeType = "cape";
|
||||
|
||||
public static final String[] defaultTypes = {
|
||||
ringType,
|
||||
amuletType,
|
||||
beltType,
|
||||
headType,
|
||||
bodyType,
|
||||
charmType,
|
||||
gauntletType,
|
||||
capeType
|
||||
};
|
||||
|
||||
private static String[] slots = new String[slotLimit];
|
||||
private static int newSlotsRemaining = slotLimit;
|
||||
|
||||
public static final String ringType = "ring";
|
||||
public static final String amuletType = "amulet";
|
||||
public static final String beltType = "belt";
|
||||
|
||||
static {
|
||||
tryAddSlot(amuletType);
|
||||
tryAddSlot(ringType);
|
||||
tryAddSlot(ringType);
|
||||
tryAddSlot(beltType);
|
||||
|
||||
tryAddSlot(ringType);
|
||||
tryAddSlot(ringType);
|
||||
tryAddSlot(ringType);
|
||||
tryAddSlot(ringType);
|
||||
tryAddSlot(ringType);
|
||||
tryAddSlot(ringType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempts to add a slot, but will not if there are no slots left.
|
||||
*
|
||||
* @param type The type of the slot being added
|
||||
* @return If adding a slot was successful
|
||||
*/
|
||||
public static boolean tryAddSlot(String type) {
|
||||
//TODO: block after GUI init
|
||||
if(newSlotsRemaining >= 1) {
|
||||
slots[slotLimit - newSlotsRemaining] = type;
|
||||
newSlotsRemaining--;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a slot of the specified type if one could be found.
|
||||
*
|
||||
* @param type The type of the slot being removed
|
||||
* @return If removing a slot was successful
|
||||
*/
|
||||
public static boolean tryRemoveSlot(String type) {
|
||||
//TODO: block after GUI init
|
||||
for(int slotToCheck = 0; slotToCheck < slotLimit; slotToCheck++) {
|
||||
if(slots[slotToCheck].equals(type)) {
|
||||
for(int slotToMove = slotToCheck + 1; slotToMove < slotLimit; slotToMove++) {
|
||||
@@ -53,6 +67,13 @@ public class BaubleExpandedSlots {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the currently number of slots matching the specified type.
|
||||
*
|
||||
* @param type The type of slot being counted
|
||||
* @return The current total number of matching slots found
|
||||
*/
|
||||
public static int totalCurrentSlotsOfType(String type) {
|
||||
int total = 0;
|
||||
for(int slotToCheck = 0; slotToCheck < slotLimit; slotToCheck++) {
|
||||
@@ -63,18 +84,36 @@ public class BaubleExpandedSlots {
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of slots that are currently used.
|
||||
*
|
||||
* @return The total number of slots currently used
|
||||
*/
|
||||
public static int getTotalSlots() {
|
||||
return slotLimit - newSlotsRemaining;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the type of the specified slot or null if none or out of range.
|
||||
*
|
||||
* @param slot The slot to check
|
||||
* @return The type in the specified slot or "unknown"
|
||||
*/
|
||||
public static String getSlotType(int slot) {
|
||||
if (slot > 0 & slot < slotLimit) {
|
||||
if (slot >= 0 & slot < slotLimit) {
|
||||
return slots[slot];
|
||||
} else {
|
||||
return null;
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type based on the specified BaubleType.
|
||||
*
|
||||
* @param type The BaubleType get a matching type from
|
||||
* @return The type matching the BaubleType or "unknown"
|
||||
*/
|
||||
public static String getTypeStringFromBaubleType(BaubleType type) {
|
||||
switch(type) {
|
||||
case RING:
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package baubles.api.expanded;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.LoaderState;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
public class BaubleSlotTypeBackgroundIconManager {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static class TypeIIconPair {
|
||||
public IIcon icon;
|
||||
public String type;
|
||||
|
||||
public TypeIIconPair(IIcon icon, String type){
|
||||
this.icon = icon;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static ArrayList<TypeIIconPair> typeIIconPairList = new ArrayList<TypeIIconPair>();
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static IIcon unknownIcon;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static IIcon getBackgroundIconForSlotType(String type) {
|
||||
if(type != null) {
|
||||
for(TypeIIconPair pair : typeIIconPairList) {
|
||||
if(type.equals(pair.type)) {
|
||||
return pair.icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
return unknownIcon;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static boolean doesBackgroundIconForSlotTypeExist(String type) {
|
||||
if(type != null) {
|
||||
for(TypeIIconPair pair : typeIIconPairList) {
|
||||
if(type.equals(pair.type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static boolean tryAddBackgroundIconForSlotType(IIcon icon, String type) {
|
||||
if(icon != null && type != null && !doesBackgroundIconForSlotTypeExist(type)) {
|
||||
typeIIconPairList.add(new TypeIIconPair(icon, type));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void setBakgroundIconForUnknownSlotType(IIcon icon) {
|
||||
if(icon != null) {
|
||||
unknownIcon = icon;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user