This commit is contained in:
Raoul Van den Berge
2016-05-05 13:46:58 +02:00
parent 31c8e301e6
commit 0c43fc1533
10 changed files with 96 additions and 97 deletions

View File

@@ -7,7 +7,6 @@ import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n; import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.fml.client.config.GuiCheckBox;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import refinedstorage.RefinedStorage; import refinedstorage.RefinedStorage;
import refinedstorage.gui.sidebutton.SideButton; import refinedstorage.gui.sidebutton.SideButton;
@@ -116,10 +115,6 @@ public abstract class GuiBase extends GuiContainer {
return addButton(new GuiButton(lastButtonId++, x, y, w, h, text)); return addButton(new GuiButton(lastButtonId++, x, y, w, h, text));
} }
public GuiButton addCheckBox(int x, int y, String text) {
return addButton(new GuiCheckBox(lastButtonId++, x, y, text, false));
}
public GuiButton addButton(GuiButton button) { public GuiButton addButton(GuiButton button) {
buttonList.add(button); buttonList.add(button);

View File

@@ -106,11 +106,11 @@ public class InventorySimple implements IInventory {
} }
@Override @Override
public void openInventory(EntityPlayer playerIn) { public void openInventory(EntityPlayer player) {
} }
@Override @Override
public void closeInventory(EntityPlayer playerIn) { public void closeInventory(EntityPlayer player) {
} }
@Override @Override

View File

@@ -32,7 +32,7 @@ public class MachineSearcher {
if (machine.getRedstoneMode().isEnabled(controller.getWorld(), tile.getPos())) { if (machine.getRedstoneMode().isEnabled(controller.getWorld(), tile.getPos())) {
machines.add(machine); machines.add(machine);
} else if (machine instanceof TileRelay) { } else if (machine instanceof TileRelay) {
// if the relay is disabled we can't search any further // If the relay is disabled we can't search any further
return; return;
} }
} }

View File

@@ -10,15 +10,17 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import refinedstorage.container.ContainerConstructor; import refinedstorage.container.ContainerConstructor;
import refinedstorage.inventory.InventorySimple; import refinedstorage.inventory.InventorySimple;
import refinedstorage.item.ItemUpgrade;
import refinedstorage.tile.autocrafting.CraftingPattern; import refinedstorage.tile.autocrafting.CraftingPattern;
import refinedstorage.tile.config.ICompareConfig; import refinedstorage.tile.config.ICompareConfig;
import refinedstorage.util.InventoryUtils; import refinedstorage.util.InventoryUtils;
import refinedstorage.util.UpgradeUtils;
public class TileConstructor extends TileMachine implements ICompareConfig { public class TileConstructor extends TileMachine implements ICompareConfig {
public static final int BASE_SPEED = 20;
public static final String NBT_COMPARE = "Compare"; public static final String NBT_COMPARE = "Compare";
public static final int BASE_SPEED = 20;
private InventorySimple inventory = new InventorySimple("constructor", 1, this); private InventorySimple inventory = new InventorySimple("constructor", 1, this);
private InventorySimple upgradesInventory = new InventorySimple("upgrades", 4, this); private InventorySimple upgradesInventory = new InventorySimple("upgrades", 4, this);
@@ -31,18 +33,18 @@ public class TileConstructor extends TileMachine implements ICompareConfig {
@Override @Override
public void updateMachine() { public void updateMachine() {
if (ticks % TileInterface.getSpeed(upgradesInventory, BASE_SPEED) == 0 && inventory.getStackInSlot(0) != null) { if (ticks % UpgradeUtils.getSpeed(upgradesInventory, BASE_SPEED, 4) == 0 && inventory.getStackInSlot(0) != null) {
BlockPos front = pos.offset(getDirection()); BlockPos front = pos.offset(getDirection());
Block tryingToPlace = ((ItemBlock) inventory.getStackInSlot(0).getItem()).getBlock(); Block block = ((ItemBlock) inventory.getStackInSlot(0).getItem()).getBlock();
if (tryingToPlace.canPlaceBlockAt(worldObj, front)) { if (block.canPlaceBlockAt(worldObj, front)) {
ItemStack took = controller.take(inventory.getStackInSlot(0).copy(), compare); ItemStack took = controller.take(inventory.getStackInSlot(0).copy(), compare);
if (took != null) { if (took != null) {
worldObj.setBlockState(front, tryingToPlace.getStateFromMeta(took.getItemDamage()), 1 | 2); worldObj.setBlockState(front, block.getStateFromMeta(took.getItemDamage()), 1 | 2);
} else if (TileInterface.hasCrafting(upgradesInventory)) { } else if (UpgradeUtils.hasUpgrade(upgradesInventory, ItemUpgrade.TYPE_CRAFTING)) {
CraftingPattern pattern = controller.getPattern(inventory.getStackInSlot(0).copy(), compare); CraftingPattern pattern = controller.getPattern(inventory.getStackInSlot(0), compare);
if (pattern != null && !controller.hasCraftingTask(pattern, compare)) { if (pattern != null && !controller.hasCraftingTask(pattern, compare)) {
controller.addCraftingTask(pattern); controller.addCraftingTask(pattern);

View File

@@ -28,7 +28,8 @@ import refinedstorage.network.MessageWirelessGridItems;
import refinedstorage.storage.IStorage; import refinedstorage.storage.IStorage;
import refinedstorage.storage.IStorageProvider; import refinedstorage.storage.IStorageProvider;
import refinedstorage.storage.ItemGroup; import refinedstorage.storage.ItemGroup;
import refinedstorage.tile.autocrafting.*; import refinedstorage.tile.autocrafting.CraftingPattern;
import refinedstorage.tile.autocrafting.TileCrafter;
import refinedstorage.tile.autocrafting.task.BasicCraftingTask; import refinedstorage.tile.autocrafting.task.BasicCraftingTask;
import refinedstorage.tile.autocrafting.task.ICraftingTask; import refinedstorage.tile.autocrafting.task.ICraftingTask;
import refinedstorage.tile.autocrafting.task.ProcessingCraftingTask; import refinedstorage.tile.autocrafting.task.ProcessingCraftingTask;
@@ -362,38 +363,31 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
} }
public boolean push(ItemStack stack) { public boolean push(ItemStack stack) {
IStorage foundStorage = null;
for (IStorage storage : storages) { for (IStorage storage : storages) {
if (storage.canPush(stack)) { if (storage.canPush(stack)) {
foundStorage = storage; storage.push(stack);
break; syncItems();
}
}
if (foundStorage == null) { // Notify processing tasks that we got an item
return false; // A processing task accepts itemstacks of 1 item, so give it like that
} for (int i = 0; i < stack.stackSize; ++i) {
for (ICraftingTask task : craftingTasks) {
foundStorage.push(stack); if (task instanceof ProcessingCraftingTask) {
if (((ProcessingCraftingTask) task).onInserted(stack)) {
syncItems(); break;
}
// processing tasks accept 1-per }
for (int i = 0; i < stack.stackSize; ++i) {
for (ICraftingTask task : craftingTasks) {
if (task instanceof ProcessingCraftingTask) {
if (((ProcessingCraftingTask) task).onInserted(stack)) {
break;
} }
} }
markDirty();
return true;
} }
} }
markDirty(); return false;
return true;
} }
public ItemStack take(ItemStack stack) { public ItemStack take(ItemStack stack) {
@@ -727,20 +721,19 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
int quantityPerRequest = 0; int quantityPerRequest = 0;
CraftingPattern pattern = getPattern(requested); CraftingPattern pattern = getPattern(requested);
for (ItemStack output : pattern.getOutputs()) { if (pattern != null) {
if (InventoryUtils.compareStackNoQuantity(requested, output)) { for (ItemStack output : pattern.getOutputs()) {
quantityPerRequest = output.stackSize; if (InventoryUtils.compareStackNoQuantity(requested, output)) {
break; quantityPerRequest = output.stackSize;
}
}
while (quantity > 0) { break;
if (pattern != null) { }
}
while (quantity > 0) {
addCraftingTask(pattern); addCraftingTask(pattern);
quantity -= quantityPerRequest; quantity -= quantityPerRequest;
} else {
break;
} }
} }
} }

View File

@@ -15,6 +15,7 @@ import refinedstorage.tile.config.ICompareConfig;
import refinedstorage.tile.config.IModeConfig; import refinedstorage.tile.config.IModeConfig;
import refinedstorage.tile.config.ModeConfigUtils; import refinedstorage.tile.config.ModeConfigUtils;
import refinedstorage.util.InventoryUtils; import refinedstorage.util.InventoryUtils;
import refinedstorage.util.UpgradeUtils;
import java.util.List; import java.util.List;
@@ -37,7 +38,7 @@ public class TileDestructor extends TileMachine implements ICompareConfig, IMode
@Override @Override
public void updateMachine() { public void updateMachine() {
if (ticks % TileInterface.getSpeed(upgradesInventory, BASE_SPEED) == 0) { if (ticks % UpgradeUtils.getSpeed(upgradesInventory, BASE_SPEED, 4) == 0) {
BlockPos front = pos.offset(getDirection()); BlockPos front = pos.offset(getDirection());
IBlockState frontBlockState = worldObj.getBlockState(front); IBlockState frontBlockState = worldObj.getBlockState(front);

View File

@@ -9,9 +9,11 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityHopper; import net.minecraft.tileentity.TileEntityHopper;
import refinedstorage.container.ContainerExporter; import refinedstorage.container.ContainerExporter;
import refinedstorage.inventory.InventorySimple; import refinedstorage.inventory.InventorySimple;
import refinedstorage.item.ItemUpgrade;
import refinedstorage.tile.autocrafting.CraftingPattern; import refinedstorage.tile.autocrafting.CraftingPattern;
import refinedstorage.tile.config.ICompareConfig; import refinedstorage.tile.config.ICompareConfig;
import refinedstorage.util.InventoryUtils; import refinedstorage.util.InventoryUtils;
import refinedstorage.util.UpgradeUtils;
public class TileExporter extends TileMachine implements ICompareConfig { public class TileExporter extends TileMachine implements ICompareConfig {
public static final String NBT_COMPARE = "Compare"; public static final String NBT_COMPARE = "Compare";
@@ -33,7 +35,7 @@ public class TileExporter extends TileMachine implements ICompareConfig {
if (connectedTile instanceof IInventory) { if (connectedTile instanceof IInventory) {
IInventory connectedInventory = (IInventory) connectedTile; IInventory connectedInventory = (IInventory) connectedTile;
if (ticks % TileInterface.getSpeed(upgradesInventory) == 0) { if (ticks % UpgradeUtils.getSpeed(upgradesInventory) == 0) {
for (int i = 0; i < inventory.getSizeInventory(); ++i) { for (int i = 0; i < inventory.getSizeInventory(); ++i) {
ItemStack slot = inventory.getStackInSlot(i); ItemStack slot = inventory.getStackInSlot(i);
@@ -49,7 +51,7 @@ public class TileExporter extends TileMachine implements ICompareConfig {
if (remaining != null) { if (remaining != null) {
controller.push(remaining); controller.push(remaining);
} }
} else if (TileInterface.hasCrafting(upgradesInventory)) { } else if (UpgradeUtils.hasUpgrade(upgradesInventory, ItemUpgrade.TYPE_CRAFTING)) {
CraftingPattern pattern = controller.getPattern(slot, compare); CraftingPattern pattern = controller.getPattern(slot, compare);
if (pattern != null && !controller.hasCraftingTask(pattern, compare)) { if (pattern != null && !controller.hasCraftingTask(pattern, compare)) {

View File

@@ -12,6 +12,7 @@ import refinedstorage.inventory.InventorySimple;
import refinedstorage.tile.config.ICompareConfig; import refinedstorage.tile.config.ICompareConfig;
import refinedstorage.tile.config.IModeConfig; import refinedstorage.tile.config.IModeConfig;
import refinedstorage.util.InventoryUtils; import refinedstorage.util.InventoryUtils;
import refinedstorage.util.UpgradeUtils;
public class TileImporter extends TileMachine implements ICompareConfig, IModeConfig { public class TileImporter extends TileMachine implements ICompareConfig, IModeConfig {
public static final String NBT_COMPARE = "Compare"; public static final String NBT_COMPARE = "Compare";
@@ -51,7 +52,7 @@ public class TileImporter extends TileMachine implements ICompareConfig, IModeCo
if (stack == null) { if (stack == null) {
currentSlot++; currentSlot++;
} else { } else {
if (ticks % TileInterface.getSpeed(upgradesInventory) == 0) { if (ticks % UpgradeUtils.getSpeed(upgradesInventory) == 0) {
ItemStack toTake = stack.copy(); ItemStack toTake = stack.copy();
toTake.stackSize = 1; toTake.stackSize = 1;
@@ -61,7 +62,7 @@ public class TileImporter extends TileMachine implements ICompareConfig, IModeCo
sided.markDirty(); sided.markDirty();
} }
} else { } else {
// if we can't import and/or extract, move on (otherwise we stay on the same slot forever) // If we can't import and/or extract, move on (otherwise we stay on the same slot forever)
currentSlot++; currentSlot++;
} }
} }
@@ -77,7 +78,7 @@ public class TileImporter extends TileMachine implements ICompareConfig, IModeCo
ItemStack stack = inventory.getStackInSlot(currentSlot); ItemStack stack = inventory.getStackInSlot(currentSlot);
if (stack != null) { if (stack != null) {
if (ticks % TileInterface.getSpeed(upgradesInventory) == 0) { if (ticks % UpgradeUtils.getSpeed(upgradesInventory) == 0) {
ItemStack toTake = stack.copy(); ItemStack toTake = stack.copy();
toTake.stackSize = 1; toTake.stackSize = 1;

View File

@@ -15,6 +15,7 @@ import refinedstorage.item.ItemUpgrade;
import refinedstorage.tile.autocrafting.CraftingPattern; import refinedstorage.tile.autocrafting.CraftingPattern;
import refinedstorage.tile.config.ICompareConfig; import refinedstorage.tile.config.ICompareConfig;
import refinedstorage.util.InventoryUtils; import refinedstorage.util.InventoryUtils;
import refinedstorage.util.UpgradeUtils;
public class TileInterface extends TileMachine implements ICompareConfig, ISidedInventory { public class TileInterface extends TileMachine implements ICompareConfig, ISidedInventory {
public static final String NBT_COMPARE = "Compare"; public static final String NBT_COMPARE = "Compare";
@@ -38,32 +39,6 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided
return 4; return 4;
} }
public static int getSpeed(InventorySimple upgradesInventory) {
return getSpeed(upgradesInventory, 9);
}
public static int getSpeed(InventorySimple upgradesInventory, int baseSpeed) {
int upgrades = 0;
for (int i = 0; i < upgradesInventory.getSizeInventory(); ++i) {
if (upgradesInventory.getStackInSlot(i) != null && upgradesInventory.getStackInSlot(i).getMetadata() == ItemUpgrade.TYPE_SPEED) {
upgrades++;
}
}
return baseSpeed - (upgrades * 2);
}
public static boolean hasCrafting(InventorySimple upgradesInventory) {
for (int i = 0; i < upgradesInventory.getSizeInventory(); ++i) {
if (upgradesInventory.getStackInSlot(i) != null && upgradesInventory.getStackInSlot(i).getMetadata() == ItemUpgrade.TYPE_CRAFTING) {
return true;
}
}
return false;
}
@Override @Override
public void updateMachine() { public void updateMachine() {
if (currentSlot > 8) { if (currentSlot > 8) {
@@ -75,7 +50,7 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided
if (slot == null) { if (slot == null) {
currentSlot++; currentSlot++;
} else { } else {
if (ticks % getSpeed(upgradesInventory) == 0) { if (ticks % UpgradeUtils.getSpeed(upgradesInventory) == 0) {
ItemStack toPush = slot.copy(); ItemStack toPush = slot.copy();
toPush.stackSize = 1; toPush.stackSize = 1;
@@ -123,10 +98,10 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided
} }
} }
if (hasCrafting(upgradesInventory)) { if (UpgradeUtils.hasUpgrade(upgradesInventory, ItemUpgrade.TYPE_CRAFTING)) {
CraftingPattern pattern = controller.getPattern(wanted, compare); CraftingPattern pattern = controller.getPattern(wanted, compare);
if (pattern != null && took == null || took.stackSize != needed) { if (pattern != null && (took == null || took.stackSize != needed)) {
int tasksToCreate = needed - controller.getCraftingTaskCount(pattern, compare); int tasksToCreate = needed - controller.getCraftingTaskCount(pattern, compare);
for (int j = 0; j < tasksToCreate; ++j) { for (int j = 0; j < tasksToCreate; ++j) {
@@ -144,6 +119,18 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided
} }
} }
@Override
public int getCompare() {
return compare;
}
@Override
public void setCompare(int compare) {
markDirty();
this.compare = compare;
}
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
@@ -293,16 +280,4 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided
public IInventory getDroppedInventory() { public IInventory getDroppedInventory() {
return upgradesInventory; return upgradesInventory;
} }
@Override
public int getCompare() {
return compare;
}
@Override
public void setCompare(int compare) {
markDirty();
this.compare = compare;
}
} }

View File

@@ -0,0 +1,30 @@
package refinedstorage.util;
import refinedstorage.inventory.InventorySimple;
import refinedstorage.item.ItemUpgrade;
public class UpgradeUtils {
public static int getSpeed(InventorySimple upgrades) {
return getSpeed(upgrades, 9, 2);
}
public static int getSpeed(InventorySimple inventory, int speed, int speedIncrease) {
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
if (inventory.getStackInSlot(i) != null && inventory.getStackInSlot(i).getMetadata() == ItemUpgrade.TYPE_SPEED) {
speed -= speedIncrease;
}
}
return speed;
}
public static boolean hasUpgrade(InventorySimple inventory, int type) {
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
if (inventory.getStackInSlot(i) != null && inventory.getStackInSlot(i).getMetadata() == type) {
return true;
}
}
return false;
}
}