mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-16 10:14:39 +00:00
Improve backpack API and add backpack config blacklists
This commit is contained in:
1 parent
f6feca096f
commit
94f751d78a
18 files changed
+627
-376
No files matched your search
@@ -15,33 +15,108 @@ import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.api.storage.EnumBackpackType;
|
||||
import forestry.api.storage.IBackpackDefinition;
|
||||
import forestry.api.storage.IBackpackFilter;
|
||||
import forestry.api.storage.IBackpackFilterConfigurable;
|
||||
import forestry.api.storage.IBackpackInterface;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.storage.items.ItemBackpack;
|
||||
import forestry.storage.items.ItemBackpackNaturalist;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class BackpackInterface implements IBackpackInterface {
|
||||
/**
|
||||
* Only use this if you know what you are doing. Prefer backpackInterface.
|
||||
*/
|
||||
public final Map<String, IBackpackDefinition> definitions = new HashMap<>();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBackpackDefinition getBackpack(@Nonnull String uid) {
|
||||
return definitions.get(uid);
|
||||
private final Map<String, IBackpackDefinition> definitions = new HashMap<>();
|
||||
private final Multimap<String, String> backpackAcceptedItems = HashMultimap.create();
|
||||
|
||||
public Multimap<String, String> getBackpackAcceptedItems() {
|
||||
return backpackAcceptedItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBackpack(@Nonnull String uid, @Nonnull IBackpackDefinition definition) {
|
||||
definitions.put(uid, definition);
|
||||
public void addItemToForestryBackpack(@Nullable String backpackUid, @Nullable ItemStack itemStack) {
|
||||
if (backpackUid == null) {
|
||||
throw new NullPointerException("backpackUid must not be null");
|
||||
}
|
||||
if (itemStack == null) {
|
||||
throw new NullPointerException("itemStack must not be null");
|
||||
}
|
||||
if (itemStack.getItem() == null) {
|
||||
throw new NullPointerException("itemStack.getItem() must not be null");
|
||||
}
|
||||
|
||||
String stringForItemStack = ItemStackUtil.getStringForItemStack(itemStack);
|
||||
backpackAcceptedItems.put(backpackUid, stringForItemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerBackpackDefinition(@Nullable String backpackUid, @Nullable IBackpackDefinition definition) {
|
||||
if (backpackUid == null) {
|
||||
throw new NullPointerException("backpackUid must not be null");
|
||||
}
|
||||
if (definition == null) {
|
||||
throw new NullPointerException("definition must not be null");
|
||||
}
|
||||
definitions.put(backpackUid, definition);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBackpackDefinition getBackpackDefinition(@Nullable String backpackUid) {
|
||||
if (backpackUid == null) {
|
||||
throw new NullPointerException("backpackUid must not be null");
|
||||
}
|
||||
return definitions.get(backpackUid);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Item createBackpack(@Nonnull IBackpackDefinition definition, @Nonnull EnumBackpackType type) {
|
||||
public Item createBackpack(@Nullable String backpackUid, @Nullable EnumBackpackType type) {
|
||||
if (backpackUid == null) {
|
||||
throw new NullPointerException("backpackUid must not be null");
|
||||
}
|
||||
if (type == null) {
|
||||
throw new NullPointerException("type must not be null");
|
||||
}
|
||||
if (type == EnumBackpackType.NATURALIST) {
|
||||
throw new IllegalArgumentException("type must not be NATURALIST. Use createNaturalistBackpack instead.");
|
||||
}
|
||||
|
||||
IBackpackDefinition definition = definitions.get(backpackUid);
|
||||
if (definition == null) {
|
||||
throw new IllegalArgumentException("No backpack definition was registered for UID: " + backpackUid);
|
||||
}
|
||||
return new ItemBackpack(definition, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item createNaturalistBackpack(@Nullable String backpackUid, @Nullable ISpeciesRoot speciesRoot) {
|
||||
if (backpackUid == null) {
|
||||
throw new NullPointerException("backpackUid must not be null");
|
||||
}
|
||||
if (speciesRoot == null) {
|
||||
throw new NullPointerException("speciesRoot must not be null");
|
||||
}
|
||||
|
||||
IBackpackDefinition definition = definitions.get(backpackUid);
|
||||
if (definition == null) {
|
||||
throw new IllegalArgumentException("No backpack definition was registered for UID: " + backpackUid);
|
||||
}
|
||||
return new ItemBackpackNaturalist(speciesRoot, definition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBackpackFilterConfigurable createBackpackFilter() {
|
||||
return new BackpackFilter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBackpackFilter createNaturalistBackpackFilter(String speciesRootUid) {
|
||||
return new BackpackFilterNaturalist(speciesRootUid);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user