Renames and formatting fixes

This commit is contained in:
Raoul Van den Berge
2016-10-23 15:02:02 +02:00
parent 72de12142a
commit 1b9b081a95
14 changed files with 98 additions and 71 deletions

View File

@@ -20,6 +20,9 @@ public interface ICraftingPatternContainer {
*/
IItemHandler getFacingInventory();
/**
* @return the tile that this container is facing
*/
TileEntity getFacingTile();
/**

View File

@@ -25,7 +25,7 @@ public interface ICraftingStep {
List<ItemStack> getToInsert();
/**
* Check if the processing can start
* Check if the processing can start.
*
* @param items a list to compare the needed {@link ItemStack} inputs against
* @param fluids a list to compare the needed {@link net.minecraftforge.fluids.FluidStack} inputs against (eg. a bucket, machine insert)
@@ -33,14 +33,19 @@ public interface ICraftingStep {
*/
boolean canStartProcessing(IItemStackList items, IFluidStackList fluids);
/**
* When called, this step will be marked as started processing.
*/
void setStartedProcessing();
/**
* @return whether this step has started processing
*/
boolean hasStartedProcessing();
/**
* Execute this step
* Any items to be added to the network should be inserting into these queues
* and they'll be managed by the {@link ICraftingTask}
* Execute this step.
* Any items to be added to the network should be inserting into these queues and they'll be managed by the {@link ICraftingTask}.
*
* @param toInsertItems a queue of items to be inserted into the network
* @param toInsertFluids a queue of fluids to be inserted into the network

View File

@@ -53,14 +53,14 @@ public class API implements IRSAPI {
return craftingTaskRegistry;
}
@Nonnull
@Override
@Nonnull
public ICraftingMonitorElementRegistry getCraftingMonitorElementRegistry() {
return craftingMonitorElementRegistry;
}
@Nonnull
@Override
@Nonnull
public ICraftingPreviewElementRegistry getCraftingPreviewElementRegistry() {
return craftingPreviewElementRegistry;
}
@@ -71,14 +71,14 @@ public class API implements IRSAPI {
return new ItemStackList();
}
@Nonnull
@Override
@Nonnull
public IFluidStackList createFluidStackList() {
return new FluidStackList();
}
@Nonnull
@Override
@Nonnull
public ICraftingMonitorElementList createCraftingMonitorElementList() {
return new CraftingMonitorElementList();
}

View File

@@ -65,8 +65,10 @@ public class CraftingMonitorElementFluidRender implements ICraftingMonitorElemen
public boolean merge(ICraftingMonitorElement element) {
if (element.getId().equals(getId()) && elementHashCode() == element.elementHashCode()) {
this.stack.amount += ((CraftingMonitorElementFluidRender) element).stack.amount;
return true;
}
return false;
}

View File

@@ -68,8 +68,10 @@ public class CraftingMonitorElementItemRender implements ICraftingMonitorElement
public boolean merge(ICraftingMonitorElement element) {
if (element.getId().equals(getId()) && elementHashCode() == element.elementHashCode()) {
this.quantity += ((CraftingMonitorElementItemRender) element).quantity;
return true;
}
return false;
}

View File

@@ -17,15 +17,19 @@ public class CraftingMonitorElementList implements ICraftingMonitorElementList {
@Override
public void add(ICraftingMonitorElement element) {
Map<Integer, ICraftingMonitorElement> currentElements = currentLists.get(element.getId());
if (currentElements == null) {
currentElements = new HashMap<>();
}
ICraftingMonitorElement exitingElement = currentElements.get(element.elementHashCode());
if (exitingElement == null) {
exitingElement = element;
} else {
exitingElement.merge(element);
}
currentElements.put(exitingElement.elementHashCode(), exitingElement);
currentLists.put(exitingElement.getId(), currentElements);
}
@@ -41,6 +45,7 @@ public class CraftingMonitorElementList implements ICraftingMonitorElementList {
if (!currentLists.isEmpty()) {
commit();
}
return elements;
}
}

View File

@@ -3,14 +3,14 @@ package com.raoulvdberge.refinedstorage.apiimpl.autocrafting.registry;
import com.raoulvdberge.refinedstorage.RSUtils;
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPattern;
import com.raoulvdberge.refinedstorage.api.autocrafting.registry.ICraftingTaskFactory;
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask;
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingStep;
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask;
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
import com.raoulvdberge.refinedstorage.api.util.IFluidStackList;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.CraftCraftingStep;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.CraftingStep;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.CraftingStepCraft;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.CraftingStepProcess;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.CraftingTask;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.AbstractCraftingStep;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.ProcessCraftingStep;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@@ -32,28 +32,26 @@ public class CraftingTaskFactory implements ICraftingTaskFactory {
@Nonnull
public ICraftingTask create(World world, INetworkMaster network, @Nullable ItemStack stack, ICraftingPattern pattern, int quantity, @Nullable NBTTagCompound tag) {
if (tag != null) {
NBTTagList toProcessList = tag.getTagList(CraftingTask.NBT_TO_PROCESS, Constants.NBT.TAG_COMPOUND);
NBTTagList stepsList = tag.getTagList(CraftingTask.NBT_STEPS, Constants.NBT.TAG_COMPOUND);
List<ICraftingStep> toProcess = new ArrayList<>();
List<ICraftingStep> steps = new ArrayList<>();
for (int i = 0; i < toProcessList.tagCount(); ++i) {
NBTTagCompound compound = toProcessList.getCompoundTagAt(i);
AbstractCraftingStep abstractCraftingStep;
switch (compound.getString(AbstractCraftingStep.NBT_CRAFTING_STEP_TYPE))
{
case CraftCraftingStep.ID:
abstractCraftingStep = new CraftCraftingStep(network);
for (int i = 0; i < stepsList.tagCount(); ++i) {
NBTTagCompound stepTag = stepsList.getCompoundTagAt(i);
CraftingStep step = null;
switch (stepTag.getString(CraftingStep.NBT_CRAFTING_STEP_TYPE)) {
case CraftingStepCraft.ID:
step = new CraftingStepCraft(network);
break;
case ProcessCraftingStep.ID:
abstractCraftingStep = new ProcessCraftingStep(network);
break;
default:
abstractCraftingStep = null;
case CraftingStepProcess.ID:
step = new CraftingStepProcess(network);
break;
}
if (abstractCraftingStep != null && abstractCraftingStep.readFromNBT(compound)) {
toProcess.add(abstractCraftingStep);
if (step != null && step.readFromNBT(stepTag)) {
steps.add(step);
}
}
@@ -85,7 +83,7 @@ public class CraftingTaskFactory implements ICraftingTaskFactory {
}
}
return new CraftingTask(network, stack, pattern, quantity, toProcess, toInsert, toTakeFluids, tookFluids, toInsertFluids);
return new CraftingTask(network, stack, pattern, quantity, steps, toInsert, toTakeFluids, tookFluids, toInsertFluids);
}
return new CraftingTask(network, stack, pattern, quantity);

View File

@@ -10,14 +10,19 @@ import com.raoulvdberge.refinedstorage.api.util.IFluidStackList;
import com.raoulvdberge.refinedstorage.api.util.IItemStackList;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
public abstract class AbstractCraftingStep implements ICraftingStep {
;
public abstract class CraftingStep implements ICraftingStep {
public static final String NBT_CRAFTING_STEP_TYPE = "CraftingStepType";
private static final String NBT_SATISFIED = "Satisfied_%d";
private static final String NBT_PATTERN = "Pattern";
@@ -29,13 +34,13 @@ public abstract class AbstractCraftingStep implements ICraftingStep {
protected Map<Integer, Integer> satisfied;
protected boolean startedProcessing;
public AbstractCraftingStep(INetworkMaster network, ICraftingPattern pattern) {
public CraftingStep(INetworkMaster network, ICraftingPattern pattern) {
this.network = network;
this.pattern = pattern;
this.satisfied = new HashMap<>(getPattern().getOutputs().size());
}
public AbstractCraftingStep(INetworkMaster network) {
public CraftingStep(INetworkMaster network) {
this.network = network;
}

View File

@@ -14,14 +14,14 @@ import net.minecraftforge.items.ItemHandlerHelper;
import java.util.Deque;
public class CraftCraftingStep extends AbstractCraftingStep {
public static final String ID = "CraftCraftingStep";
public class CraftingStepCraft extends CraftingStep {
public static final String ID = "craft";
public CraftCraftingStep(INetworkMaster network, ICraftingPattern pattern) {
public CraftingStepCraft(INetworkMaster network, ICraftingPattern pattern) {
super(network, pattern);
}
public CraftCraftingStep(INetworkMaster network) {
public CraftingStepCraft(INetworkMaster network) {
super(network);
}

View File

@@ -11,20 +11,20 @@ import net.minecraftforge.items.ItemHandlerHelper;
import java.util.Deque;
public class ProcessCraftingStep extends AbstractCraftingStep {
public static final String ID = "ProcessCraftingStep";
public class CraftingStepProcess extends CraftingStep {
public static final String ID = "process";
public ProcessCraftingStep(INetworkMaster network, ICraftingPattern pattern) {
public CraftingStepProcess(INetworkMaster network, ICraftingPattern pattern) {
super(network, pattern);
}
public ProcessCraftingStep(INetworkMaster network) {
public CraftingStepProcess(INetworkMaster network) {
super(network);
}
@Override
public void execute(Deque<ItemStack> toInsertItems, Deque<FluidStack> toInsertFluids) {
// TODO fluid handling
// @TODO: fluid handling
IItemHandler inventory = getPattern().getContainer().getFacingInventory();
for (ItemStack insertStack : getToInsert()) {
ItemStack tookStack = network.extractItem(insertStack, insertStack.stackSize, CraftingTask.DEFAULT_COMPARE | (getPattern().isOredict() ? IComparer.COMPARE_OREDICT : 0));
@@ -35,6 +35,7 @@ public class ProcessCraftingStep extends AbstractCraftingStep {
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
tag.setString(NBT_CRAFTING_STEP_TYPE, ID);
return super.writeToNBT(tag);
}
}

View File

@@ -6,8 +6,8 @@ import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingPatternContaine
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElement;
import com.raoulvdberge.refinedstorage.api.autocrafting.craftingmonitor.ICraftingMonitorElementList;
import com.raoulvdberge.refinedstorage.api.autocrafting.preview.ICraftingPreviewElement;
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask;
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingStep;
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask;
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
import com.raoulvdberge.refinedstorage.api.util.IComparer;
import com.raoulvdberge.refinedstorage.api.util.IFluidStackList;
@@ -32,7 +32,7 @@ import java.util.stream.Collectors;
public class CraftingTask implements ICraftingTask {
protected static final int DEFAULT_COMPARE = IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT;
public static final String NBT_TO_PROCESS = "ToProcess";
public static final String NBT_STEPS = "Steps";
public static final String NBT_TO_TAKE_FLUIDS = "ToTakeFluids";
public static final String NBT_TO_INSERT_ITEMS = "ToInsertItems";
public static final String NBT_TO_INSERT_FLUIDS = "ToInsertFluids";
@@ -76,7 +76,9 @@ public class CraftingTask implements ICraftingTask {
IItemStackList toInsert = API.instance().createItemStackList();
toCraft.add(ItemHandlerHelper.copyStackWithSize(requested, quantity));
int quantity = this.quantity;
while (quantity > 0 && !recurseFound) {
calculate(networkList, pattern, toInsert);
quantity -= pattern.getQuantityPerRequest(requested);
@@ -147,9 +149,9 @@ public class CraftingTask implements ICraftingTask {
}
if (pattern.isProcessing()) {
steps.add(new ProcessCraftingStep(network, pattern));
steps.add(new CraftingStepProcess(network, pattern));
} else {
steps.add(new CraftCraftingStep(network, pattern));
steps.add(new CraftingStepCraft(network, pattern));
}
if (missing.isEmpty()) {
@@ -250,7 +252,11 @@ public class CraftingTask implements ICraftingTask {
for (ICraftingStep step : steps) {
ICraftingPatternContainer container = step.getPattern().getContainer();
Integer timesUsed = usedContainers.get(container);
if (timesUsed == null) timesUsed = 0;
if (timesUsed == null) {
timesUsed = 0;
}
if (timesUsed++ <= container.getSpeedUpdateCount()) {
if (!step.hasStartedProcessing() && step.canStartProcessing(network.getItemStorageCache().getList(), tookFluids) && canProcess(step)) {
step.setStartedProcessing();
@@ -261,13 +267,13 @@ public class CraftingTask implements ICraftingTask {
}
}
// We need to copy the size cause we'll readd unadded stacks to the queue
// We need to copy the size cause we'll re-add unadded stacks to the queue
int times = toInsertItems.size();
for (int i = 0; i < times; i++)
{
for (int i = 0; i < times; i++) {
ItemStack insert = toInsertItems.poll();
if (insert != null) {
ItemStack remainder = network.insertItem(insert, insert.stackSize, false);
if (remainder != null) {
toInsertItems.add(remainder);
}
@@ -333,7 +339,7 @@ public class CraftingTask implements ICraftingTask {
processablesList.appendTag(processable.writeToNBT(new NBTTagCompound()));
}
tag.setTag(NBT_TO_PROCESS, processablesList);
tag.setTag(NBT_STEPS, processablesList);
NBTTagList toInsertItemsList = new NBTTagList();
@@ -373,13 +379,13 @@ public class CraftingTask implements ICraftingTask {
elements.directAdd(new CraftingMonitorElementText("gui.refinedstorage:crafting_monitor.items_inserting", 16));
toInsertItems.stream()
.map(stack -> new CraftingMonitorElementItemRender(
-1,
stack,
stack.stackSize,
32
))
.forEach(elements::add);
.map(stack -> new CraftingMonitorElementItemRender(
-1,
stack,
stack.stackSize,
32
))
.forEach(elements::add);
elements.commit();
}
@@ -391,10 +397,10 @@ public class CraftingTask implements ICraftingTask {
for (ICraftingStep processable : steps.stream().filter(s -> !s.getPattern().isProcessing()).collect(Collectors.toList())) {
for (int i = 0; i < processable.getPattern().getOutputs().size(); ++i) {
elements.add(new CraftingMonitorElementItemRender(
-1,
processable.getPattern().getOutputs().get(i),
processable.getPattern().getOutputs().get(i).stackSize,
32
-1,
processable.getPattern().getOutputs().get(i),
processable.getPattern().getOutputs().get(i).stackSize,
32
));
}
}
@@ -408,10 +414,10 @@ public class CraftingTask implements ICraftingTask {
for (ICraftingStep processable : steps.stream().filter(s -> s.getPattern().isProcessing()).collect(Collectors.toList())) {
for (int i = 0; i < processable.getPattern().getOutputs().size(); ++i) {
ICraftingMonitorElement element = new CraftingMonitorElementItemRender(
-1,
processable.getPattern().getOutputs().get(i),
processable.getPattern().getOutputs().get(i).stackSize,
32
-1,
processable.getPattern().getOutputs().get(i),
processable.getPattern().getOutputs().get(i).stackSize,
32
);
if (processable.getPattern().getContainer().getFacingTile() == null) {

View File

@@ -3,7 +3,6 @@ package com.raoulvdberge.refinedstorage.apiimpl.util;
import com.google.common.collect.ArrayListMultimap;
import com.raoulvdberge.refinedstorage.api.util.IFluidStackList;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
@@ -81,6 +80,7 @@ public class FluidStackList implements IFluidStackList {
List<FluidStack> toRemove = stacks.values().stream()
.filter(stack -> stack.amount <= 0)
.collect(Collectors.toList());
toRemove.forEach(stack -> stacks.remove(stack.getFluid(), stack));
}

View File

@@ -25,7 +25,7 @@ public class ItemStackList implements IItemStackList {
} else {
otherStack.stackSize += stack.stackSize;
}
return;
}
}
@@ -54,7 +54,7 @@ public class ItemStackList implements IItemStackList {
@Override
@Nullable
public ItemStack get(@Nonnull ItemStack stack, int flags) {
// When the oreDict flag is set all stacks need to be checked not just the ones matching the Item
// When the oredict flag is set all stacks need to be checked not just the ones matching the item
for (ItemStack otherStack : (flags & IComparer.COMPARE_OREDICT) == IComparer.COMPARE_OREDICT ? stacks.values() : stacks.get(stack.getItem())) {
if (API.instance().getComparer().isEqual(otherStack, stack, flags)) {
return otherStack;
@@ -86,6 +86,7 @@ public class ItemStackList implements IItemStackList {
List<ItemStack> toRemove = stacks.values().stream()
.filter(stack -> stack.stackSize <= 0)
.collect(Collectors.toList());
toRemove.forEach(stack -> stacks.remove(stack.getItem(), stack));
}

View File

@@ -18,7 +18,6 @@ public class SideButtonAccessType extends SideButton {
@Override
protected void drawButtonIcon(int x, int y) {
// @TODO
}
@Override