Fix more SonarQube warnings.

This commit is contained in:
raoulvdberge
2020-10-17 13:44:19 +02:00
parent fd7cb5d555
commit 7c5534dd3c
21 changed files with 312 additions and 138 deletions

View File

@@ -24,6 +24,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@Mod(RS.ID)
public final class RS {
public static final String ID = "refinedstorage";
public static final String NAME = "Refined Storage";
public static final NetworkHandler NETWORK_HANDLER = new NetworkHandler();
public static final ItemGroup MAIN_GROUP = new MainItemGroup();

View File

@@ -18,10 +18,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
public final class RSItems {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, RS.ID);
@@ -47,17 +44,17 @@ public final class RSItems {
public static final RegistryObject<WirelessCraftingMonitorItem> CREATIVE_WIRELESS_CRAFTING_MONITOR;
public static final RegistryObject<BlockItem> MACHINE_CASING;
public static final Map<ProcessorItem.Type, RegistryObject<ProcessorItem>> PROCESSORS = new HashMap<>();
public static final Map<ProcessorItem.Type, RegistryObject<ProcessorItem>> PROCESSORS = new EnumMap<>(ProcessorItem.Type.class);
public static final Map<ItemStorageType, RegistryObject<StoragePartItem>> ITEM_STORAGE_PARTS = new HashMap<>();
public static final Map<ItemStorageType, RegistryObject<StorageDiskItem>> ITEM_STORAGE_DISKS = new HashMap<>();
public static final Map<ItemStorageType, RegistryObject<StorageBlockItem>> STORAGE_BLOCKS = new HashMap<>();
public static final Map<ItemStorageType, RegistryObject<StoragePartItem>> ITEM_STORAGE_PARTS = new EnumMap<>(ItemStorageType.class);
public static final Map<ItemStorageType, RegistryObject<StorageDiskItem>> ITEM_STORAGE_DISKS = new EnumMap<>(ItemStorageType.class);
public static final Map<ItemStorageType, RegistryObject<StorageBlockItem>> STORAGE_BLOCKS = new EnumMap<>(ItemStorageType.class);
public static final Map<FluidStorageType, RegistryObject<FluidStoragePartItem>> FLUID_STORAGE_PARTS = new HashMap<>();
public static final Map<FluidStorageType, RegistryObject<FluidStorageDiskItem>> FLUID_STORAGE_DISKS = new HashMap<>();
public static final Map<FluidStorageType, RegistryObject<FluidStorageBlockItem>> FLUID_STORAGE_BLOCKS = new HashMap<>();
public static final Map<FluidStorageType, RegistryObject<FluidStoragePartItem>> FLUID_STORAGE_PARTS = new EnumMap<>(FluidStorageType.class);
public static final Map<FluidStorageType, RegistryObject<FluidStorageDiskItem>> FLUID_STORAGE_DISKS = new EnumMap<>(FluidStorageType.class);
public static final Map<FluidStorageType, RegistryObject<FluidStorageBlockItem>> FLUID_STORAGE_BLOCKS = new EnumMap<>(FluidStorageType.class);
public static final Map<UpgradeItem.Type, RegistryObject<UpgradeItem>> UPGRADE_ITEMS = new HashMap<>();
public static final Map<UpgradeItem.Type, RegistryObject<UpgradeItem>> UPGRADE_ITEMS = new EnumMap<>(UpgradeItem.Type.class);
public static final Map<Tags.IOptionalNamedTag<Item>, ColorMap<BlockItem>> COLORED_ITEM_TAGS = new HashMap<>();
@@ -202,6 +199,9 @@ public final class RSItems {
LATE_REGISTRATION.forEach(Runnable::run);
}
private RSItems() {
}
private static <T extends BaseBlock> RegistryObject<BlockItem> registerBlockItemFor(RegistryObject<T> block) {
return ITEMS.register(block.getId().getPath(), () -> new BaseBlockItem(block.get(), new Item.Properties().group(RS.MAIN_GROUP)));
}

View File

@@ -12,7 +12,7 @@ public final class RSKeyBindings {
KeyConflictContext.GUI,
InputMappings.Type.KEYSYM,
GLFW.GLFW_KEY_TAB,
"Refined Storage"
RS.NAME
);
public static final KeyBinding CLEAR_GRID_CRAFTING_MATRIX = new KeyBinding(
@@ -21,34 +21,37 @@ public final class RSKeyBindings {
KeyModifier.CONTROL,
InputMappings.Type.KEYSYM,
GLFW.GLFW_KEY_X,
"Refined Storage"
RS.NAME
);
public static final KeyBinding OPEN_WIRELESS_GRID = new KeyBinding(
"key.refinedstorage.openWirelessGrid",
KeyConflictContext.IN_GAME,
InputMappings.INPUT_INVALID,
"Refined Storage"
RS.NAME
);
public static final KeyBinding OPEN_WIRELESS_FLUID_GRID = new KeyBinding(
"key.refinedstorage.openWirelessFluidGrid",
KeyConflictContext.IN_GAME,
InputMappings.INPUT_INVALID,
"Refined Storage"
RS.NAME
);
public static final KeyBinding OPEN_WIRELESS_CRAFTING_MONITOR = new KeyBinding(
"key.refinedstorage.openWirelessCraftingMonitor",
KeyConflictContext.IN_GAME,
InputMappings.INPUT_INVALID,
"Refined Storage"
RS.NAME
);
public static final KeyBinding OPEN_PORTABLE_GRID = new KeyBinding(
"key.refinedstorage.openPortableGrid",
KeyConflictContext.IN_GAME,
InputMappings.INPUT_INVALID,
"Refined Storage"
RS.NAME
);
}
private RSKeyBindings() {
}
}

View File

@@ -14,6 +14,9 @@ public final class RSLootFunctions {
public static LootFunctionType CRAFTER;
public static LootFunctionType CONTROLLER;
private RSLootFunctions() {
}
public static void register() {
STORAGE_BLOCK = Registry.register(Registry.LOOT_FUNCTION_TYPE, new ResourceLocation(RS.ID, "storage_block"), new LootFunctionType(new StorageBlockLootFunction.Serializer()));
PORTABLE_GRID = Registry.register(Registry.LOOT_FUNCTION_TYPE, new ResourceLocation(RS.ID, "portable_grid"), new LootFunctionType(new PortableGridBlockLootFunction.Serializer()));

View File

@@ -85,4 +85,7 @@ public final class RSTiles {
public static final TileEntityType<CrafterManagerTile> CRAFTER_MANAGER = null;
@ObjectHolder("crafting_monitor")
public static final TileEntityType<CraftingMonitorTile> CRAFTING_MONITOR = null;
private RSTiles() {
}
}

View File

@@ -151,7 +151,7 @@ public interface IRSAPI {
* @param type the type
* @return a set of external storage providers
*/
Set<IExternalStorageProvider> getExternalStorageProviders(StorageType type);
Set<IExternalStorageProvider<?>> getExternalStorageProviders(StorageType type);
/**
* @param world the world

View File

@@ -14,7 +14,7 @@ public interface IStorageDiskRegistry {
* @param id the id of this factory
* @param factory the factory
*/
void add(ResourceLocation id, IStorageDiskFactory factory);
void add(ResourceLocation id, IStorageDiskFactory<?> factory);
/**
* Gets a factory.

View File

@@ -75,7 +75,7 @@ public class API implements IRSAPI {
private final ICraftingGridBehavior craftingGridBehavior = new CraftingGridBehavior();
private final IStorageDiskRegistry storageDiskRegistry = new StorageDiskRegistry();
private final IStorageDiskSync storageDiskSync = new StorageDiskSync();
private final Map<StorageType, TreeSet<IExternalStorageProvider>> externalStorageProviders = new HashMap<>();
private final Map<StorageType, TreeSet<IExternalStorageProvider<?>>> externalStorageProviders = new EnumMap<>(StorageType.class);
private final List<ICraftingPatternRenderHandler> patternRenderHandlers = new LinkedList<>();
public static IRSAPI instance() {
@@ -206,13 +206,13 @@ public class API implements IRSAPI {
}
@Override
public void addExternalStorageProvider(StorageType type, IExternalStorageProvider provider) {
public void addExternalStorageProvider(StorageType type, IExternalStorageProvider<?> provider) {
externalStorageProviders.computeIfAbsent(type, k -> new TreeSet<>((a, b) -> Integer.compare(b.getPriority(), a.getPriority()))).add(provider);
}
@Override
public Set<IExternalStorageProvider> getExternalStorageProviders(StorageType type) {
TreeSet<IExternalStorageProvider> providers = externalStorageProviders.get(type);
public Set<IExternalStorageProvider<?>> getExternalStorageProviders(StorageType type) {
TreeSet<IExternalStorageProvider<?>> providers = externalStorageProviders.get(type);
return providers == null ? Collections.emptySet() : providers;
}

View File

@@ -19,36 +19,23 @@ import javax.annotation.Nullable;
import java.util.List;
public class CraftingPattern implements ICraftingPattern {
private final ICraftingPatternContainer container;
private final ItemStack stack;
private final CraftingPatternContext context;
private final boolean processing;
private final boolean exact;
private final boolean valid;
@Nullable
private final ITextComponent errorMessage;
@Nullable
private final ICraftingRecipe recipe;
private final List<NonNullList<ItemStack>> inputs;
private final NonNullList<ItemStack> outputs;
private final NonNullList<ItemStack> byproducts;
private final List<NonNullList<FluidStack>> fluidInputs;
private final NonNullList<FluidStack> fluidOutputs;
private final CraftingPatternInputs inputs;
private final CraftingPatternOutputs outputs;
@Nullable
private final AllowedTagList allowedTagList;
public CraftingPattern(ICraftingPatternContainer container, ItemStack stack, boolean processing, boolean exact, @Nullable ITextComponent errorMessage, boolean valid, @Nullable ICraftingRecipe recipe, List<NonNullList<ItemStack>> inputs, NonNullList<ItemStack> outputs, NonNullList<ItemStack> byproducts, List<NonNullList<FluidStack>> fluidInputs, NonNullList<FluidStack> fluidOutputs, @Nullable AllowedTagList allowedTagList) {
this.container = container;
this.stack = stack;
public CraftingPattern(CraftingPatternContext context, boolean processing, boolean exact, @Nullable ICraftingRecipe recipe, CraftingPatternInputs inputs, CraftingPatternOutputs outputs, @Nullable AllowedTagList allowedTagList) {
this.context = context;
this.processing = processing;
this.exact = exact;
this.valid = valid;
this.errorMessage = errorMessage;
this.recipe = recipe;
this.inputs = inputs;
this.outputs = outputs;
this.byproducts = byproducts;
this.fluidInputs = fluidInputs;
this.fluidOutputs = fluidOutputs;
this.allowedTagList = allowedTagList;
}
@@ -59,23 +46,23 @@ public class CraftingPattern implements ICraftingPattern {
@Override
public ICraftingPatternContainer getContainer() {
return container;
return context.getContainer();
}
@Override
public ItemStack getStack() {
return stack;
return context.getStack();
}
@Override
public boolean isValid() {
return valid;
return true;
}
@Nullable
@Override
public ITextComponent getErrorMessage() {
return errorMessage;
return null;
}
@Override
@@ -85,12 +72,12 @@ public class CraftingPattern implements ICraftingPattern {
@Override
public List<NonNullList<ItemStack>> getInputs() {
return inputs;
return inputs.getInputs();
}
@Override
public NonNullList<ItemStack> getOutputs() {
return outputs;
return outputs.getOutputs();
}
public ItemStack getOutput(NonNullList<ItemStack> took) {
@@ -98,8 +85,8 @@ public class CraftingPattern implements ICraftingPattern {
throw new IllegalStateException("Cannot get crafting output from processing pattern");
}
if (took.size() != inputs.size()) {
throw new IllegalArgumentException("The items that are taken (" + took.size() + ") should match the inputs for this pattern (" + inputs.size() + ")");
if (took.size() != inputs.getInputs().size()) {
throw new IllegalArgumentException("The items that are taken (" + took.size() + ") should match the inputs for this pattern (" + inputs.getInputs().size() + ")");
}
CraftingInventory inv = new DummyCraftingInventory();
@@ -122,7 +109,7 @@ public class CraftingPattern implements ICraftingPattern {
throw new IllegalStateException("Cannot get byproduct outputs from processing pattern");
}
return byproducts;
return outputs.getByproducts();
}
@Override
@@ -131,8 +118,8 @@ public class CraftingPattern implements ICraftingPattern {
throw new IllegalStateException("Cannot get byproduct outputs from processing pattern");
}
if (took.size() != inputs.size()) {
throw new IllegalArgumentException("The items that are taken (" + took.size() + ") should match the inputs for this pattern (" + inputs.size() + ")");
if (took.size() != inputs.getInputs().size()) {
throw new IllegalArgumentException("The items that are taken (" + took.size() + ") should match the inputs for this pattern (" + inputs.getInputs().size() + ")");
}
CraftingInventory inv = new DummyCraftingInventory();
@@ -155,12 +142,12 @@ public class CraftingPattern implements ICraftingPattern {
@Override
public List<NonNullList<FluidStack>> getFluidInputs() {
return fluidInputs;
return inputs.getFluidInputs();
}
@Override
public NonNullList<FluidStack> getFluidOutputs() {
return fluidOutputs;
return outputs.getFluidOutputs();
}
@Override
@@ -180,62 +167,62 @@ public class CraftingPattern implements ICraftingPattern {
return false;
}
if ((other.getInputs().size() != inputs.size()) ||
(other.getFluidInputs().size() != fluidInputs.size()) ||
(other.getOutputs().size() != outputs.size()) ||
(other.getFluidOutputs().size() != fluidOutputs.size())) {
if ((other.getInputs().size() != inputs.getInputs().size()) ||
(other.getFluidInputs().size() != inputs.getFluidInputs().size()) ||
(other.getOutputs().size() != outputs.getOutputs().size()) ||
(other.getFluidOutputs().size() != outputs.getFluidOutputs().size())) {
return false;
}
if (!processing && other.getByproducts().size() != byproducts.size()) {
if (!processing && other.getByproducts().size() != outputs.getByproducts().size()) {
return false;
}
for (int i = 0; i < inputs.size(); ++i) {
List<ItemStack> inputs = this.inputs.get(i);
List<ItemStack> otherInputs = other.getInputs().get(i);
for (int i = 0; i < inputs.getInputs().size(); ++i) {
List<ItemStack> inputsForSlot = inputs.getInputs().get(i);
List<ItemStack> otherInputsForSlot = other.getInputs().get(i);
if (inputs.size() != otherInputs.size()) {
if (inputsForSlot.size() != otherInputsForSlot.size()) {
return false;
}
for (int j = 0; j < inputs.size(); ++j) {
if (!API.instance().getComparer().isEqual(inputs.get(j), otherInputs.get(j))) {
for (int j = 0; j < inputsForSlot.size(); ++j) {
if (!API.instance().getComparer().isEqual(inputsForSlot.get(j), otherInputsForSlot.get(j))) {
return false;
}
}
}
for (int i = 0; i < fluidInputs.size(); ++i) {
List<FluidStack> inputs = this.fluidInputs.get(i);
List<FluidStack> otherInputs = other.getFluidInputs().get(i);
for (int i = 0; i < inputs.getFluidInputs().size(); ++i) {
List<FluidStack> inputsForSlot = inputs.getFluidInputs().get(i);
List<FluidStack> otherInputsForSlot = other.getFluidInputs().get(i);
if (inputs.size() != otherInputs.size()) {
if (inputsForSlot.size() != otherInputsForSlot.size()) {
return false;
}
for (int j = 0; j < inputs.size(); ++j) {
if (!API.instance().getComparer().isEqual(inputs.get(j), otherInputs.get(j), IComparer.COMPARE_NBT | IComparer.COMPARE_QUANTITY)) {
for (int j = 0; j < inputsForSlot.size(); ++j) {
if (!API.instance().getComparer().isEqual(inputsForSlot.get(j), otherInputsForSlot.get(j), IComparer.COMPARE_NBT | IComparer.COMPARE_QUANTITY)) {
return false;
}
}
}
for (int i = 0; i < outputs.size(); ++i) {
if (!API.instance().getComparer().isEqual(outputs.get(i), other.getOutputs().get(i))) {
for (int i = 0; i < outputs.getOutputs().size(); ++i) {
if (!API.instance().getComparer().isEqual(outputs.getOutputs().get(i), other.getOutputs().get(i))) {
return false;
}
}
for (int i = 0; i < fluidOutputs.size(); ++i) {
if (!API.instance().getComparer().isEqual(fluidOutputs.get(i), other.getFluidOutputs().get(i), IComparer.COMPARE_NBT | IComparer.COMPARE_QUANTITY)) {
for (int i = 0; i < outputs.getFluidOutputs().size(); ++i) {
if (!API.instance().getComparer().isEqual(outputs.getFluidOutputs().get(i), other.getFluidOutputs().get(i), IComparer.COMPARE_NBT | IComparer.COMPARE_QUANTITY)) {
return false;
}
}
if (!processing) {
for (int i = 0; i < byproducts.size(); ++i) {
if (!API.instance().getComparer().isEqual(byproducts.get(i), other.getByproducts().get(i))) {
for (int i = 0; i < outputs.getByproducts().size(); ++i) {
if (!API.instance().getComparer().isEqual(outputs.getByproducts().get(i), other.getByproducts().get(i))) {
return false;
}
}
@@ -251,27 +238,27 @@ public class CraftingPattern implements ICraftingPattern {
result = 31 * result + (processing ? 1 : 0);
result = 31 * result + (exact ? 1 : 0);
for (List<ItemStack> inputs : this.inputs) {
for (ItemStack input : inputs) {
for (List<ItemStack> inputsForSlot : inputs.getInputs()) {
for (ItemStack input : inputsForSlot) {
result = 31 * result + API.instance().getItemStackHashCode(input);
}
}
for (List<FluidStack> inputs : this.fluidInputs) {
for (FluidStack input : inputs) {
for (List<FluidStack> inputsForSlot : inputs.getFluidInputs()) {
for (FluidStack input : inputsForSlot) {
result = 31 * result + API.instance().getFluidStackHashCode(input);
}
}
for (ItemStack output : this.outputs) {
for (ItemStack output : outputs.getOutputs()) {
result = 31 * result + API.instance().getItemStackHashCode(output);
}
for (FluidStack output : this.fluidOutputs) {
for (FluidStack output : outputs.getFluidOutputs()) {
result = 31 * result + API.instance().getFluidStackHashCode(output);
}
for (ItemStack byproduct : this.byproducts) {
for (ItemStack byproduct : outputs.getByproducts()) {
result = 31 * result + API.instance().getItemStackHashCode(byproduct);
}

View File

@@ -0,0 +1,22 @@
package com.refinedmods.refinedstorage.apiimpl.autocrafting;
import com.refinedmods.refinedstorage.api.autocrafting.ICraftingPatternContainer;
import net.minecraft.item.ItemStack;
public class CraftingPatternContext {
private final ICraftingPatternContainer container;
private final ItemStack stack;
public CraftingPatternContext(ICraftingPatternContainer container, ItemStack stack) {
this.container = container;
this.stack = stack;
}
public ICraftingPatternContainer getContainer() {
return container;
}
public ItemStack getStack() {
return stack;
}
}

View File

@@ -1,5 +1,6 @@
package com.refinedmods.refinedstorage.apiimpl.autocrafting;
import com.refinedmods.refinedstorage.api.autocrafting.ICraftingPattern;
import com.refinedmods.refinedstorage.api.autocrafting.ICraftingPatternContainer;
import com.refinedmods.refinedstorage.item.PatternItem;
import net.minecraft.fluid.Fluid;
@@ -12,7 +13,6 @@ import net.minecraft.tags.FluidTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
@@ -23,7 +23,9 @@ import java.util.*;
public class CraftingPatternFactory {
public static final CraftingPatternFactory INSTANCE = new CraftingPatternFactory();
public CraftingPattern create(World world, ICraftingPatternContainer container, ItemStack stack) {
public ICraftingPattern create(World world, ICraftingPatternContainer container, ItemStack stack) {
CraftingPatternContext context = new CraftingPatternContext(container, stack);
boolean processing = PatternItem.isProcessing(stack);
boolean exact = PatternItem.isExact(stack);
AllowedTagList allowedTagList = PatternItem.getAllowedTags(stack);
@@ -34,8 +36,6 @@ public class CraftingPatternFactory {
List<NonNullList<FluidStack>> fluidInputs = new ArrayList<>();
NonNullList<FluidStack> fluidOutputs = NonNullList.create();
ICraftingRecipe recipe = null;
boolean valid = true;
ITextComponent errorMessage = null;
try {
if (processing) {
@@ -76,11 +76,18 @@ public class CraftingPatternFactory {
}
}
} catch (CraftingPatternFactoryException e) {
valid = false;
errorMessage = e.getErrorMessage();
return new InvalidCraftingPattern(context, e.getErrorMessage());
}
return new CraftingPattern(container, stack, processing, exact, errorMessage, valid, recipe, inputs, outputs, byproducts, fluidInputs, fluidOutputs, allowedTagList);
return new CraftingPattern(
context,
processing,
exact,
recipe,
new CraftingPatternInputs(inputs, fluidInputs),
new CraftingPatternOutputs(outputs, byproducts, fluidOutputs),
allowedTagList
);
}
private void fillProcessingInputs(int i, ItemStack stack, List<NonNullList<ItemStack>> inputs, NonNullList<ItemStack> outputs, @Nullable AllowedTagList allowedTagList) throws CraftingPatternFactoryException {

View File

@@ -0,0 +1,25 @@
package com.refinedmods.refinedstorage.apiimpl.autocrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.fluids.FluidStack;
import java.util.List;
public class CraftingPatternInputs {
private final List<NonNullList<ItemStack>> inputs;
private final List<NonNullList<FluidStack>> fluidInputs;
public CraftingPatternInputs(List<NonNullList<ItemStack>> inputs, List<NonNullList<FluidStack>> fluidInputs) {
this.inputs = inputs;
this.fluidInputs = fluidInputs;
}
public List<NonNullList<ItemStack>> getInputs() {
return inputs;
}
public List<NonNullList<FluidStack>> getFluidInputs() {
return fluidInputs;
}
}

View File

@@ -0,0 +1,29 @@
package com.refinedmods.refinedstorage.apiimpl.autocrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.fluids.FluidStack;
public class CraftingPatternOutputs {
private final NonNullList<ItemStack> outputs;
private final NonNullList<ItemStack> byproducts;
private final NonNullList<FluidStack> fluidOutputs;
public CraftingPatternOutputs(NonNullList<ItemStack> outputs, NonNullList<ItemStack> byproducts, NonNullList<FluidStack> fluidOutputs) {
this.outputs = outputs;
this.byproducts = byproducts;
this.fluidOutputs = fluidOutputs;
}
public NonNullList<ItemStack> getOutputs() {
return outputs;
}
public NonNullList<ItemStack> getByproducts() {
return byproducts;
}
public NonNullList<FluidStack> getFluidOutputs() {
return fluidOutputs;
}
}

View File

@@ -0,0 +1,90 @@
package com.refinedmods.refinedstorage.apiimpl.autocrafting;
import com.refinedmods.refinedstorage.api.autocrafting.ICraftingPattern;
import com.refinedmods.refinedstorage.api.autocrafting.ICraftingPatternContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nullable;
import java.util.List;
public class InvalidCraftingPattern implements ICraftingPattern {
private static final String EXCEPTION_MESSAGE = "Crafting pattern is invalid";
private final CraftingPatternContext context;
private final ITextComponent errorMessage;
public InvalidCraftingPattern(CraftingPatternContext context, ITextComponent errorMessage) {
this.context = context;
this.errorMessage = errorMessage;
}
@Override
public ICraftingPatternContainer getContainer() {
return context.getContainer();
}
@Override
public ItemStack getStack() {
return context.getStack();
}
@Override
public boolean isValid() {
return false;
}
@Nullable
@Override
public ITextComponent getErrorMessage() {
return errorMessage;
}
@Override
public boolean isProcessing() {
return false;
}
@Override
public List<NonNullList<ItemStack>> getInputs() {
throw new IllegalStateException(EXCEPTION_MESSAGE);
}
@Override
public NonNullList<ItemStack> getOutputs() {
throw new IllegalStateException(EXCEPTION_MESSAGE);
}
@Override
public ItemStack getOutput(NonNullList<ItemStack> took) {
throw new IllegalStateException(EXCEPTION_MESSAGE);
}
@Override
public NonNullList<ItemStack> getByproducts() {
throw new IllegalStateException(EXCEPTION_MESSAGE);
}
@Override
public NonNullList<ItemStack> getByproducts(NonNullList<ItemStack> took) {
throw new IllegalStateException(EXCEPTION_MESSAGE);
}
@Override
public List<NonNullList<FluidStack>> getFluidInputs() {
throw new IllegalStateException(EXCEPTION_MESSAGE);
}
@Override
public NonNullList<FluidStack> getFluidOutputs() {
throw new IllegalStateException(EXCEPTION_MESSAGE);
}
@Override
public ResourceLocation getCraftingTaskFactoryId() {
throw new IllegalStateException(EXCEPTION_MESSAGE);
}
}

View File

@@ -212,17 +212,17 @@ public class ExternalStorageNetworkNode extends NetworkNode implements IStorageP
if (facing != null) {
if (type == IType.ITEMS) {
for (IExternalStorageProvider<ItemStack> provider : API.instance().getExternalStorageProviders(StorageType.ITEM)) {
for (IExternalStorageProvider<?> provider : API.instance().getExternalStorageProviders(StorageType.ITEM)) {
if (provider.canProvide(facing, getDirection())) {
itemStorages.add(provider.provide(this, getFacingTile(), getDirection()));
itemStorages.add((IExternalStorage<ItemStack>) provider.provide(this, getFacingTile(), getDirection()));
break;
}
}
} else if (type == IType.FLUIDS) {
for (IExternalStorageProvider<FluidStack> provider : API.instance().getExternalStorageProviders(StorageType.FLUID)) {
for (IExternalStorageProvider<?> provider : API.instance().getExternalStorageProviders(StorageType.FLUID)) {
if (provider.canProvide(facing, getDirection())) {
fluidStorages.add(provider.provide(this, getFacingTile(), getDirection()));
fluidStorages.add((IExternalStorage<FluidStack>) provider.provide(this, getFacingTile(), getDirection()));
break;
}

View File

@@ -4,8 +4,8 @@ import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.refinedmods.refinedstorage.api.autocrafting.ICraftingPattern;
import com.refinedmods.refinedstorage.apiimpl.autocrafting.AllowedTagList;
import com.refinedmods.refinedstorage.apiimpl.autocrafting.CraftingPattern;
import com.refinedmods.refinedstorage.item.PatternItem;
import com.refinedmods.refinedstorage.render.Styles;
import net.minecraft.command.CommandSource;
@@ -30,7 +30,7 @@ public class PatternDumpCommand implements Command<CommandSource> {
boolean exact = PatternItem.isExact(stack);
AllowedTagList allowedTagList = PatternItem.getAllowedTags(stack);
CraftingPattern pattern = PatternItem.fromCache(context.getSource().getWorld(), stack);
ICraftingPattern pattern = PatternItem.fromCache(context.getSource().getWorld(), stack);
context.getSource().sendFeedback(new StringTextComponent("Crafting task factory ID: ").setStyle(Styles.YELLOW).append(new StringTextComponent(pattern.getCraftingTaskFactoryId().toString()).setStyle(Styles.WHITE)), false);

View File

@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage.container;
import com.refinedmods.refinedstorage.RSContainers;
import com.refinedmods.refinedstorage.apiimpl.autocrafting.CraftingPattern;
import com.refinedmods.refinedstorage.api.autocrafting.ICraftingPattern;
import com.refinedmods.refinedstorage.apiimpl.network.node.CrafterManagerNetworkNode;
import com.refinedmods.refinedstorage.container.slot.CrafterManagerSlot;
import com.refinedmods.refinedstorage.inventory.item.BaseItemHandler;
@@ -114,7 +114,7 @@ public class CrafterManagerContainer extends BaseContainer {
if (stack.isEmpty()) {
visible = false;
} else {
CraftingPattern pattern = PatternItem.fromCache(crafterManager.getWorld(), stack);
ICraftingPattern pattern = PatternItem.fromCache(crafterManager.getWorld(), stack);
visible = false;

View File

@@ -35,7 +35,7 @@ import java.util.Set;
import java.util.stream.Collectors;
public class PatternItem extends Item implements ICraftingPatternProvider {
private static final Map<ItemStack, CraftingPattern> CACHE = new HashMap<>();
private static final Map<ItemStack, ICraftingPattern> CACHE = new HashMap<>();
private static final String NBT_VERSION = "Version";
private static final String NBT_INPUT_SLOT = "Input_%d";
@@ -52,7 +52,7 @@ public class PatternItem extends Item implements ICraftingPatternProvider {
super(new Item.Properties().group(RS.MAIN_GROUP).setISTER(() -> PatternItemStackTileRenderer::new));
}
public static CraftingPattern fromCache(World world, ItemStack stack) {
public static ICraftingPattern fromCache(World world, ItemStack stack) {
if (!CACHE.containsKey(stack)) {
CACHE.put(stack, CraftingPatternFactory.INSTANCE.create(world, null, stack));
}
@@ -68,14 +68,14 @@ public class PatternItem extends Item implements ICraftingPatternProvider {
return;
}
CraftingPattern pattern = fromCache(world, stack);
ICraftingPattern pattern = fromCache(world, stack);
if (pattern.isValid()) {
if (ContainerScreen.hasShiftDown() || isProcessing(stack)) {
tooltip.add(new TranslationTextComponent("misc.refinedstorage.pattern.inputs").setStyle(Styles.YELLOW));
RenderUtils.addCombinedItemsToTooltip(tooltip, true, pattern.getInputs().stream().map(i -> i.size() > 0 ? i.get(0) : ItemStack.EMPTY).collect(Collectors.toList()));
RenderUtils.addCombinedFluidsToTooltip(tooltip, true, pattern.getFluidInputs().stream().map(i -> i.size() > 0 ? i.get(0) : FluidStack.EMPTY).collect(Collectors.toList()));
RenderUtils.addCombinedItemsToTooltip(tooltip, true, pattern.getInputs().stream().map(i -> !i.isEmpty() ? i.get(0) : ItemStack.EMPTY).collect(Collectors.toList()));
RenderUtils.addCombinedFluidsToTooltip(tooltip, true, pattern.getFluidInputs().stream().map(i -> !i.isEmpty() ? i.get(0) : FluidStack.EMPTY).collect(Collectors.toList()));
tooltip.add(new TranslationTextComponent("misc.refinedstorage.pattern.outputs").setStyle(Styles.YELLOW));
}
@@ -83,30 +83,8 @@ public class PatternItem extends Item implements ICraftingPatternProvider {
RenderUtils.addCombinedItemsToTooltip(tooltip, true, pattern.getOutputs());
RenderUtils.addCombinedFluidsToTooltip(tooltip, true, pattern.getFluidOutputs());
if (pattern.getAllowedTagList() != null) {
for (int i = 0; i < pattern.getAllowedTagList().getAllowedItemTags().size(); ++i) {
Set<ResourceLocation> allowedTags = pattern.getAllowedTagList().getAllowedItemTags().get(i);
for (ResourceLocation tag : allowedTags) {
tooltip.add(new TranslationTextComponent(
"misc.refinedstorage.pattern.allowed_item_tag",
tag.toString(),
pattern.getInputs().get(i).get(0).getDisplayName()
).setStyle(Styles.AQUA));
}
}
for (int i = 0; i < pattern.getAllowedTagList().getAllowedFluidTags().size(); ++i) {
Set<ResourceLocation> allowedTags = pattern.getAllowedTagList().getAllowedFluidTags().get(i);
for (ResourceLocation tag : allowedTags) {
tooltip.add(new TranslationTextComponent(
"misc.refinedstorage.pattern.allowed_fluid_tag",
tag.toString(),
pattern.getFluidInputs().get(i).get(0).getDisplayName()
).setStyle(Styles.AQUA));
}
}
if (pattern instanceof CraftingPattern && ((CraftingPattern) pattern).getAllowedTagList() != null) {
addAllowedTags(tooltip, (CraftingPattern) pattern);
}
if (isExact(stack)) {
@@ -122,6 +100,32 @@ public class PatternItem extends Item implements ICraftingPatternProvider {
}
}
public void addAllowedTags(List<ITextComponent> tooltip, CraftingPattern pattern) {
for (int i = 0; i < pattern.getAllowedTagList().getAllowedItemTags().size(); ++i) {
Set<ResourceLocation> allowedTags = pattern.getAllowedTagList().getAllowedItemTags().get(i);
for (ResourceLocation tag : allowedTags) {
tooltip.add(new TranslationTextComponent(
"misc.refinedstorage.pattern.allowed_item_tag",
tag.toString(),
pattern.getInputs().get(i).get(0).getDisplayName()
).setStyle(Styles.AQUA));
}
}
for (int i = 0; i < pattern.getAllowedTagList().getAllowedFluidTags().size(); ++i) {
Set<ResourceLocation> allowedTags = pattern.getAllowedTagList().getAllowedFluidTags().get(i);
for (ResourceLocation tag : allowedTags) {
tooltip.add(new TranslationTextComponent(
"misc.refinedstorage.pattern.allowed_fluid_tag",
tag.toString(),
pattern.getFluidInputs().get(i).get(0).getDisplayName()
).setStyle(Styles.AQUA));
}
}
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
if (!world.isRemote && player.isCrouching()) {

View File

@@ -1,6 +1,6 @@
package com.refinedmods.refinedstorage.render.color;
import com.refinedmods.refinedstorage.apiimpl.autocrafting.CraftingPattern;
import com.refinedmods.refinedstorage.api.autocrafting.ICraftingPattern;
import com.refinedmods.refinedstorage.item.PatternItem;
import com.refinedmods.refinedstorage.render.model.PatternBakedModel;
import net.minecraft.client.Minecraft;
@@ -10,7 +10,7 @@ import net.minecraft.item.ItemStack;
public class PatternItemColor implements IItemColor {
@Override
public int getColor(ItemStack stack, int tintIndex) {
CraftingPattern pattern = PatternItem.fromCache(Minecraft.getInstance().world, stack);
ICraftingPattern pattern = PatternItem.fromCache(Minecraft.getInstance().world, stack);
if (PatternBakedModel.canDisplayOutput(stack, pattern)) {
int color = Minecraft.getInstance().getItemColors().getColor(pattern.getOutputs().get(0), tintIndex);

View File

@@ -1,9 +1,9 @@
package com.refinedmods.refinedstorage.render.model;
import com.google.common.collect.ImmutableList;
import com.refinedmods.refinedstorage.api.autocrafting.ICraftingPattern;
import com.refinedmods.refinedstorage.api.autocrafting.ICraftingPatternRenderHandler;
import com.refinedmods.refinedstorage.apiimpl.API;
import com.refinedmods.refinedstorage.apiimpl.autocrafting.CraftingPattern;
import com.refinedmods.refinedstorage.item.PatternItem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.model.IBakedModel;
@@ -27,7 +27,7 @@ public class PatternBakedModel extends DelegateBakedModel {
@Override
public IBakedModel func_239290_a_(IBakedModel model, ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity entity) {
if (entity != null) {
CraftingPattern pattern = PatternItem.fromCache(entity.world, stack);
ICraftingPattern pattern = PatternItem.fromCache(entity.world, stack);
if (canDisplayOutput(stack, pattern)) {
ItemStack outputToRender = pattern.getOutputs().get(0);
@@ -46,7 +46,7 @@ public class PatternBakedModel extends DelegateBakedModel {
};
}
public static boolean canDisplayOutput(ItemStack patternStack, CraftingPattern pattern) {
public static boolean canDisplayOutput(ItemStack patternStack, ICraftingPattern pattern) {
if (pattern.isValid() && pattern.getOutputs().size() == 1) {
for (ICraftingPatternRenderHandler renderHandler : API.instance().getPatternRenderHandlers()) {
if (renderHandler.canRenderOutput(patternStack)) {

View File

@@ -1,7 +1,7 @@
package com.refinedmods.refinedstorage.render.tesr;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.refinedmods.refinedstorage.apiimpl.autocrafting.CraftingPattern;
import com.refinedmods.refinedstorage.api.autocrafting.ICraftingPattern;
import com.refinedmods.refinedstorage.item.PatternItem;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
@@ -11,10 +11,10 @@ import net.minecraft.item.ItemStack;
public class PatternItemStackTileRenderer extends ItemStackTileEntityRenderer {
@Override
public void func_239207_a_(ItemStack stack, ItemCameraTransforms.TransformType transformType, MatrixStack matrixStack, IRenderTypeBuffer renderTypeBuffer, int p_239207_5_, int p_239207_6_) {
CraftingPattern pattern = PatternItem.fromCache(null, stack);
ICraftingPattern pattern = PatternItem.fromCache(null, stack);
ItemStack outputStack = pattern.getOutputs().get(0);
outputStack.getItem().getItemStackTileEntityRenderer().func_239207_a_(outputStack, transformType, matrixStack, renderTypeBuffer, p_239207_5_, p_239207_6_);
}
}
}