Files
Mekanism-Community-Edition/src/main/java/mekanism/api/infuse/InfuseRegistry.java
T
Richard Freimer d19f1cd7eb Transporter performance improvements (#5488)
* Improve performance of predicted insert. Don't copy stacks nearly as often

* Cache what stack is in the slots and update comments

* Cleanup up pathfinder code some

* Clean up a bit more mainly TileComponentEjector

* Fix crash caused by an earlier commit

* Minor cleanup

* Minor cleanup

* Slightly clean up TileEntityBin and fix creative bin auto eject lowering item count

* Partially cleanup getpaths, and prep work for better handling of AcceptorData with mulitple TransitResponses

* Scratch previous attempted idea of combining responses

* Use EnumMap instead of HashMap for keeping track of side data for Ejector and prep for an eventual change to TransitResponse of inserting into more than one slot at a time if the stack would be best split among multiple

* Change some more HashMaps to EnumMaps

* Make it easier to read component ejector for gas and fluids

* Inline getStacksToDest so that it can bail even earlier in cases when destination is full

* Don't create a copy of the stack if it won't be inserted AND also fix having broken inserting across multiple slots

* Replace a bunch of other HashMap instances with EnumMap where possible

* Make a couple sets more generic

* Use Int2ObjectMap for int based cache & tidy clamping

* ensure EnumMap doesnt throw NPE

* FastUtil map changes
2019-05-28 09:31:33 -04:00

111 lines
3.3 KiB
Java

package mekanism.api.infuse;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.ItemHandlerHelper;
/**
* Use this class to add a new object that registers as an infuse object.
*
* @author AidanBrady
*/
public class InfuseRegistry {
/**
* The (private) map of ItemStacks and their related InfuseObjects.
*/
private static Map<ItemStack, InfuseObject> infuseObjects = new HashMap<>();
/**
* The (private) map of infuse names and their corresponding InfuseTypes.
*/
private static Map<String, InfuseType> infuseTypes = new HashMap<>();
/**
* Registers an InfuseType into the registry. Call this in PreInit!
*
* @param infuse InfuseType to register
*/
public static void registerInfuseType(InfuseType infuse) {
if (infuseTypes.containsKey(infuse.name)) {
return;
}
infuseTypes.put(infuse.name, infuse);
}
/**
* Gets an InfuseType from it's name, or null if it doesn't exist.
*
* @param name - the name of the InfuseType to get
*
* @return the name's corresponding InfuseType
*/
public static InfuseType get(String name) {
if (name.equals("null")) {
return null;
}
return infuseTypes.get(name);
}
/**
* Whether or not the registry contains a correspondent InfuseType to a name.
*
* @param name - the name to check
*
* @return if the name has a coorespondent InfuseType
*/
public static boolean contains(String name) {
return get(name) != null;
}
/**
* Registers a block or item that serves as an infuse object. An infuse object will store a certain type and amount of infuse, and will deliver this amount to the
* Metallurgic Infuser's buffer of infuse. The item's stack size will be decremented when it is placed in the Metallurgic Infuser's infuse slot, and the machine can
* accept the type and amount of infuse stored in the object.
*
* @param itemStack - stack the infuse object is linked to -- stack size is ignored
* @param infuseObject - the infuse object with the type and amount data
*/
public static void registerInfuseObject(ItemStack itemStack, InfuseObject infuseObject) {
if (getObject(itemStack) != null) {
return;
}
infuseObjects.put(itemStack, infuseObject);
}
/**
* Gets the InfuseObject data from an ItemStack.
*
* @param itemStack - the ItemStack to check
*
* @return the ItemStack's InfuseObject
*/
public static InfuseObject getObject(ItemStack itemStack) {
for (Entry<ItemStack, InfuseObject> obj : infuseObjects.entrySet()) {
if (ItemHandlerHelper.canItemStacksStack(obj.getKey(), itemStack)) {
return obj.getValue();
}
}
return null;
}
/**
* Gets the private map for InfuseObjects.
*
* @return private InfuseObject map
*/
public static Map<ItemStack, InfuseObject> getObjectMap() {
return infuseObjects;
}
/**
* Gets the private map for InfuseTypes.
*
* @return private InfuseType map
*/
public static Map<String, InfuseType> getInfuseMap() {
return infuseTypes;
}
}