Make controller consume pattern container API

This commit is contained in:
Raoul Van den Berge
2016-08-30 23:51:45 +02:00
parent e270743aeb
commit cf06a707b0
5 changed files with 24 additions and 18 deletions

View File

@@ -2,7 +2,6 @@ package refinedstorage.api.autocrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
/** /**
@@ -15,11 +14,6 @@ public interface ICraftingPattern {
*/ */
ICraftingPatternContainer getContainer(World world); ICraftingPatternContainer getContainer(World world);
/**
* @return The position of the container where the pattern is in
*/
BlockPos getContainerPosition();
/** /**
* @return The inputs * @return The inputs
*/ */
@@ -40,6 +34,10 @@ public interface ICraftingPattern {
*/ */
String getId(); String getId();
/**
* @param requested The item requested
* @return The quantity returned per request
*/
int getQuantityPerRequest(ItemStack requested); int getQuantityPerRequest(ItemStack requested);
/** /**

View File

@@ -1,5 +1,6 @@
package refinedstorage.api.autocrafting; package refinedstorage.api.autocrafting;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
/** /**
@@ -17,4 +18,14 @@ public interface ICraftingPatternContainer {
* @return The {@link IItemHandler} that this container is facing * @return The {@link IItemHandler} that this container is facing
*/ */
IItemHandler getConnectedItems(); IItemHandler getConnectedItems();
/**
* @return The patterns stored in this container
*/
IItemHandler getPatterns();
/**
* @return The position of this container
*/
BlockPos getPosition();
} }

View File

@@ -10,6 +10,7 @@ import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.autocrafting.ICraftingPatternContainer; import refinedstorage.api.autocrafting.ICraftingPatternContainer;
import refinedstorage.api.storage.CompareUtils; import refinedstorage.api.storage.CompareUtils;
import refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactoryNormal; import refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactoryNormal;
import refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactoryProcessing;
import refinedstorage.item.ItemPattern; import refinedstorage.item.ItemPattern;
import refinedstorage.tile.TileCrafter; import refinedstorage.tile.TileCrafter;
@@ -46,11 +47,6 @@ public class CraftingPattern implements ICraftingPattern {
return crafter; return crafter;
} }
@Override
public BlockPos getContainerPosition() {
return crafterPos;
}
@Override @Override
public ItemStack[] getInputs() { public ItemStack[] getInputs() {
return inputs; return inputs;
@@ -68,7 +64,7 @@ public class CraftingPattern implements ICraftingPattern {
@Override @Override
public String getId() { public String getId() {
return processing ? "processing" : CraftingTaskFactoryNormal.ID; return processing ? CraftingTaskFactoryProcessing.ID : CraftingTaskFactoryNormal.ID;
} }
@Override @Override

View File

@@ -463,15 +463,15 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
patterns.clear(); patterns.clear();
for (INetworkNode node : nodeGraph.all()) { for (INetworkNode node : nodeGraph.all()) {
if (node instanceof TileCrafter && node.canUpdate()) { if (node instanceof ICraftingPatternContainer && node.canUpdate()) {
TileCrafter crafter = (TileCrafter) node; ICraftingPatternContainer container = (ICraftingPatternContainer) node;
for (int i = 0; i < crafter.getPatterns().getSlots(); ++i) { for (int i = 0; i < container.getPatterns().getSlots(); ++i) {
ItemStack pattern = crafter.getPatterns().getStackInSlot(i); ItemStack pattern = container.getPatterns().getStackInSlot(i);
if (pattern != null && ItemPattern.isValid(pattern)) { if (pattern != null && ItemPattern.isValid(pattern)) {
patterns.add(new CraftingPattern( patterns.add(new CraftingPattern(
crafter.getPos(), container.getPosition(),
ItemPattern.isProcessing(pattern), ItemPattern.isProcessing(pattern),
ItemPattern.getInputs(pattern), ItemPattern.getInputs(pattern),
ItemPattern.getOutputs(pattern), ItemPattern.getOutputs(pattern),

View File

@@ -50,7 +50,7 @@ public class TileCrafter extends TileNode implements ICraftingPatternContainer {
public void onConnectionChange(INetworkMaster network, boolean state) { public void onConnectionChange(INetworkMaster network, boolean state) {
if (!state) { if (!state) {
network.getCraftingTasks().stream() network.getCraftingTasks().stream()
.filter(task -> task.getPattern().getContainerPosition().equals(pos)) .filter(task -> task.getPattern().getContainer(worldObj).getPosition().equals(pos))
.forEach(network::cancelCraftingTask); .forEach(network::cancelCraftingTask);
} }
@@ -85,6 +85,7 @@ public class TileCrafter extends TileNode implements ICraftingPatternContainer {
return getItemHandler(getFacingTile(), getDirection().getOpposite()); return getItemHandler(getFacingTile(), getDirection().getOpposite());
} }
@Override
public IItemHandler getPatterns() { public IItemHandler getPatterns() {
return patterns; return patterns;
} }