Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Universal Bauble Type (can go into any slot) #4

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/baubles/api/BaubleType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public enum BaubleType {
RING,
AMULET,
BELT
BELT,
UNIVERSAL
}
68 changes: 36 additions & 32 deletions src/main/java/baubles/api/expanded/BaubleExpandedSlots.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class BaubleExpandedSlots {
public static final String ringType = "ring";
public static final String amuletType = "amulet";
public static final String beltType = "belt";
public static final String universalType = "universal";
public static final String headType = "head";
public static final String bodyType = "body";
public static final String charmType = "charm";
Expand All @@ -36,7 +37,7 @@ public class BaubleExpandedSlots {
/**
* Registers a type and returns true if the type could be or has been registered.
* Types can only be registered while the loader state is pre-initialization.
*
*
* @param type The type to register.
* @return If a type was registered or had been registered previously.
*/
Expand All @@ -57,10 +58,10 @@ public static boolean tryRegisterType(String type) {
/**
* Returns false if the type is unregistered or unknown, the minimum number of
* assigned slots cannot be met, or the loader state is not pre-initialization.
*
*
* @param type The type of the slot to evaluate and possibly assign.
* @param minimumOfType The minimum slots of type to be assigned.
*
*
* @return If the total assigned slots of the specified type equals or is more than the minimum.
*/
public static boolean tryAssignSlotsUpToMinimum(String type, int minimumOfType) {
Expand Down Expand Up @@ -91,10 +92,10 @@ public static boolean tryAssignSlotsUpToMinimum(String type, int minimumOfType)
/**
* Returns false if the type is unregistered or unknown, or the
* loader state is not pre-initialization.
*
*
* @param type The type of the slot to evaluate and possibly unassign.
* @param maximumOfType The maximum slots of type to be left assigned.
*
*
* @return If the total assigned slots of the specified type equals or is less than the maximum.
*/
public static boolean tryUnassignSlotsDownToMaximum(String type, int maximumOfType) {
Expand Down Expand Up @@ -130,9 +131,9 @@ public static boolean tryUnassignSlotsDownToMaximum(String type, int maximumOfTy
* Returns if a slot was assigned successfully.
* Does not assign a type to a slot if the type is unregistered, no slots
* are free, or the loader state is not pre-initialization.
*
*
* @param type The type to attempt assigning to a slot.
*
*
* @return If assigning a type to a slot was successful or not.
*/
public static boolean tryAssignSlotOfType(String type) {
Expand All @@ -148,9 +149,9 @@ public static boolean tryAssignSlotOfType(String type) {
/**
* Unassigns the last slot of the specified type if one can be found
* and the loader state is pre-initialization.
*
*
* @param type The type of the slot to be unassigned.
*
*
* @return If unassigning a slot was successful or not.
*/
public static boolean tryUnassignSlotOfType(String type) {
Expand All @@ -171,9 +172,9 @@ public static boolean tryUnassignSlotOfType(String type) {

/**
* Returns the current number of slots with a matching type.
*
*
* @param type The type of slot being counted.
*
*
* @return The current total slots with a matching type assigned.
*/
public static int totalCurrentlyAssignedSlotsOfType(String type) {
Expand All @@ -191,9 +192,9 @@ public static int totalCurrentlyAssignedSlotsOfType(String type) {
/**
* Returns an array of slot indexes that have the specified type assigned.
* Do not treat results from this as final until postinit or later.
*
*
* @param type The type of slot being checked.
*
*
* @return an array of slot indexes with the specified type.
*/
public static int[] getIndexesOfAssignedSlotsOfType(String type) {
Expand All @@ -211,9 +212,9 @@ public static int[] getIndexesOfAssignedSlotsOfType(String type) {

/**
* Returns if the type is registered or not.
*
*
* @param type The type to check the registration of.
*
*
* @return If the type is registered or not.
*/
public static boolean isTypeRegistered(String type) {
Expand All @@ -222,7 +223,7 @@ public static boolean isTypeRegistered(String type) {

/**
* Returns the number of bauble slots that are currently used.
*
*
* @return The number of bauble slots currently used.
*/
public static int slotsCurrentlyUsed() {
Expand All @@ -231,7 +232,7 @@ public static int slotsCurrentlyUsed() {

/**
* Returns the number of bauble slots that are currently unused.
*
*
* @return The number of bauble slots currently unused.
*/
public static int slotsCurrentlyUnused() {
Expand All @@ -240,7 +241,7 @@ public static int slotsCurrentlyUnused() {

/**
* Returns the type of the specified slot, "unknown" if out of range.
*
*
* @param slot The slot to check
* @return The type of the specified slot or unknown.
*/
Expand All @@ -255,7 +256,7 @@ public static String getSlotType(int slot) {
/**
* Returns the index of a certain type in the registeredType array
* or -1 if it cannot be found.
*
*
* @param type The type to get the index of
* @return Index of a type or negative one
*/
Expand All @@ -266,7 +267,7 @@ public static int getIndexOfTypeInRegisteredTypes(String type) {
/**
* Returns the currently registered bauble types.
* If pre-initialization is done this list is effectively final.
*
*
* @return The currently registered bauble types.
*/
public static ArrayList<String> getCurrentlyRegisteredTypes() {
Expand All @@ -276,7 +277,7 @@ public static ArrayList<String> getCurrentlyRegisteredTypes() {
/**
* Returns the current slot assignments as a string array.
* If initialization is done this list is effectively final.
*
*
* @return The current contents of the slots array.
*/
public static String[] getCurrentSlotAssignments() {
Expand All @@ -285,24 +286,26 @@ public static String[] getCurrentSlotAssignments() {

/**
* Returns a type based on the specified BaubleType.
*
*
* @param type The BaubleType to get a matching type from.
*
*
* @return The type matching the BaubleType or unknown.
*/
public static String getTypeFromBaubleType(BaubleType type) {
if(type == null) {
return invalidType;
}
switch(type) {
case RING:
return ringType;
case AMULET:
return amuletType;
case BELT:
return beltType;
default:
return unknownType;
case RING:
return ringType;
case AMULET:
return amuletType;
case BELT:
return beltType;
case UNIVERSAL:
return universalType;
default:
return unknownType;
}
}

Expand All @@ -312,7 +315,7 @@ public static String getTypeFromBaubleType(BaubleType type) {
* Any entry that would go over slotLimit is ignored.
* If an array is shorter than slotLimit all remaining slots are set to unknown.
* Invalid slot types are set to unknown.
*
*
* @param overrideSlots The array to override assigned slots with.
*/
public static void overrideSlots(String[] overrideSlots) {
Expand All @@ -337,6 +340,7 @@ public static void overrideSlots(String[] overrideSlots) {
registeredTypes.add(ringType);
registeredTypes.add(amuletType);
registeredTypes.add(beltType);
registeredTypes.add(universalType);
registeredTypes.add(headType);
registeredTypes.add(bodyType);
registeredTypes.add(charmType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
types = new String[] {BaubleExpandedSlots.getTypeFromBaubleType(((IBauble)item).getBaubleType(returnStack))};
}
for(String type : types) {
if(type.equals(BaubleExpandedSlots.getSlotType(baubleSlot - 4)) && !mergeItemStack(originalStack, baubleSlot, baubleSlot + 1, false)) {
if((type.equals(BaubleExpandedSlots.universalType) || type.equals(BaubleExpandedSlots.getSlotType(baubleSlot - 4))) && !mergeItemStack(originalStack, baubleSlot, baubleSlot + 1, false)) {
returnStack = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public boolean isItemValidForSlot(int slot, ItemStack stack) {
}

for(String type : types) {
if(type.equals(slotType)) {
if(type.equals(BaubleExpandedSlots.universalType) || type.equals(slotType)) {
return true;
}
}
Expand Down