Add speed upgrade to destructor
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
package refinedstorage.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.container.slot.IItemValidator;
|
||||
import refinedstorage.container.slot.SlotFiltered;
|
||||
import refinedstorage.container.slot.SlotSpecimenItemBlock;
|
||||
import refinedstorage.item.ItemUpgrade;
|
||||
import refinedstorage.tile.TileDestructor;
|
||||
|
||||
public class ContainerDestructor extends ContainerBase {
|
||||
@@ -12,6 +17,15 @@ public class ContainerDestructor extends ContainerBase {
|
||||
addSlotToContainer(new SlotSpecimenItemBlock(destructor.getInventory(), i, 8 + (18 * i), 20));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
addSlotToContainer(new SlotFiltered(destructor.getUpgradesInventory(), i, 187, 6 + (i * 18), new IItemValidator() {
|
||||
@Override
|
||||
public boolean isValid(ItemStack stack) {
|
||||
return stack.getItem() == RefinedStorageItems.UPGRADE && stack.getMetadata() == ItemUpgrade.TYPE_SPEED;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
addPlayerInventory(8, 55);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public class GuiDestructor extends GuiBase {
|
||||
private TileDestructor destructor;
|
||||
|
||||
public GuiDestructor(ContainerDestructor container, TileDestructor destructor) {
|
||||
super(container, 176, 137);
|
||||
super(container, 211, 137);
|
||||
|
||||
this.destructor = destructor;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import refinedstorage.tile.config.ICompareConfig;
|
||||
import refinedstorage.util.InventoryUtils;
|
||||
|
||||
public class TileConstructor extends TileMachine implements ICompareConfig {
|
||||
public static final int SPEED = 10;
|
||||
public static final int BASE_SPEED = 20;
|
||||
|
||||
public static final String NBT_COMPARE = "Compare";
|
||||
|
||||
@@ -31,7 +31,7 @@ public class TileConstructor extends TileMachine implements ICompareConfig {
|
||||
|
||||
@Override
|
||||
public void updateMachine() {
|
||||
if (ticks % TileInterface.getSpeed(upgradesInventory) == 0 && inventory.getStackInSlot(0) != null) {
|
||||
if (ticks % TileInterface.getSpeed(upgradesInventory, BASE_SPEED) == 0 && inventory.getStackInSlot(0) != null) {
|
||||
BlockPos front = pos.offset(getDirection());
|
||||
|
||||
Block tryingToPlace = ((ItemBlock) inventory.getStackInSlot(0).getItem()).getBlock();
|
||||
@@ -42,10 +42,10 @@ public class TileConstructor extends TileMachine implements ICompareConfig {
|
||||
if (took != null) {
|
||||
worldObj.setBlockState(front, tryingToPlace.getStateFromMeta(took.getItemDamage()), 1 | 2);
|
||||
} else if (TileInterface.hasCrafting(upgradesInventory)) {
|
||||
CraftingPattern pattern = controller.getPatternForItem(inventory.getStackInSlot(0).copy(), compare);
|
||||
CraftingPattern pattern = controller.getPattern(inventory.getStackInSlot(0).copy(), compare);
|
||||
|
||||
if (pattern != null && !controller.hasCraftingTaskWithPattern(pattern, compare)) {
|
||||
controller.addCraftingTaskForPattern(pattern);
|
||||
if (pattern != null && !controller.hasCraftingTask(pattern, compare)) {
|
||||
controller.addCraftingTask(pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +260,15 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
craftingTasksToAdd.add(task);
|
||||
}
|
||||
|
||||
public int getAmountOfCraftingTasksWithPattern(CraftingPattern pattern, int flags) {
|
||||
public void addCraftingTask(CraftingPattern pattern) {
|
||||
if (pattern.isProcessing()) {
|
||||
addCraftingTask(new ProcessingCraftingTask(pattern));
|
||||
} else {
|
||||
addCraftingTask(new BasicCraftingTask(pattern));
|
||||
}
|
||||
}
|
||||
|
||||
public int getCraftingTaskCount(CraftingPattern pattern, int flags) {
|
||||
int amount = 0;
|
||||
|
||||
for (int i = 0; i < craftingTasks.size(); ++i) {
|
||||
@@ -272,31 +280,23 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
return amount;
|
||||
}
|
||||
|
||||
public boolean hasCraftingTaskWithPattern(CraftingPattern pattern, int flags) {
|
||||
return getAmountOfCraftingTasksWithPattern(pattern, flags) > 0;
|
||||
}
|
||||
|
||||
public void addCraftingTaskForPattern(CraftingPattern pattern) {
|
||||
if (pattern.isProcessing()) {
|
||||
addCraftingTask(new ProcessingCraftingTask(pattern));
|
||||
} else {
|
||||
addCraftingTask(new BasicCraftingTask(pattern));
|
||||
}
|
||||
public boolean hasCraftingTask(CraftingPattern pattern, int flags) {
|
||||
return getCraftingTaskCount(pattern, flags) > 0;
|
||||
}
|
||||
|
||||
public List<CraftingPattern> getPatterns() {
|
||||
return patterns;
|
||||
}
|
||||
|
||||
public CraftingPattern getPatternForItem(ItemStack stack) {
|
||||
return getPatternForItem(stack, InventoryUtils.COMPARE_DAMAGE | InventoryUtils.COMPARE_NBT);
|
||||
public CraftingPattern getPattern(ItemStack pattern) {
|
||||
return getPattern(pattern, InventoryUtils.COMPARE_DAMAGE | InventoryUtils.COMPARE_NBT);
|
||||
}
|
||||
|
||||
public CraftingPattern getPatternForItem(ItemStack stack, int flags) {
|
||||
for (CraftingPattern pattern : getPatterns()) {
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
if (InventoryUtils.compareStack(output, stack, flags)) {
|
||||
return pattern;
|
||||
public CraftingPattern getPattern(ItemStack pattern, int flags) {
|
||||
for (CraftingPattern craftingPattern : getPatterns()) {
|
||||
for (ItemStack output : craftingPattern.getOutputs()) {
|
||||
if (InventoryUtils.compareStack(output, pattern, flags)) {
|
||||
return craftingPattern;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -725,7 +725,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
if (id >= 0 && id < itemGroups.size() && quantity > 0) {
|
||||
ItemStack requested = itemGroups.get(id).toItemStack();
|
||||
int quantityPerRequest = 0;
|
||||
CraftingPattern pattern = getPatternForItem(requested);
|
||||
CraftingPattern pattern = getPattern(requested);
|
||||
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
if (InventoryUtils.compareStackNoQuantity(requested, output)) {
|
||||
@@ -736,7 +736,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
|
||||
while (quantity > 0) {
|
||||
if (pattern != null) {
|
||||
addCraftingTaskForPattern(pattern);
|
||||
addCraftingTask(pattern);
|
||||
|
||||
quantity -= quantityPerRequest;
|
||||
} else {
|
||||
|
||||
@@ -22,9 +22,10 @@ public class TileDestructor extends TileMachine implements ICompareConfig, IMode
|
||||
public static final String NBT_COMPARE = "Compare";
|
||||
public static final String NBT_MODE = "Mode";
|
||||
|
||||
public static final int SPEED = 10;
|
||||
public static final int BASE_SPEED = 20;
|
||||
|
||||
private InventorySimple inventory = new InventorySimple("destructor", 9, this);
|
||||
private InventorySimple upgradesInventory = new InventorySimple("upgrades", 4, this);
|
||||
|
||||
private int compare = 0;
|
||||
private int mode = 0;
|
||||
@@ -36,7 +37,7 @@ public class TileDestructor extends TileMachine implements ICompareConfig, IMode
|
||||
|
||||
@Override
|
||||
public void updateMachine() {
|
||||
if (ticks % SPEED == 0) {
|
||||
if (ticks % TileInterface.getSpeed(upgradesInventory, BASE_SPEED) == 0) {
|
||||
BlockPos front = pos.offset(getDirection());
|
||||
|
||||
IBlockState frontBlockState = worldObj.getBlockState(front);
|
||||
@@ -108,6 +109,7 @@ public class TileDestructor extends TileMachine implements ICompareConfig, IMode
|
||||
}
|
||||
|
||||
InventoryUtils.restoreInventory(inventory, 0, nbt);
|
||||
InventoryUtils.restoreInventory(upgradesInventory, 1, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,6 +120,7 @@ public class TileDestructor extends TileMachine implements ICompareConfig, IMode
|
||||
nbt.setInteger(NBT_MODE, mode);
|
||||
|
||||
InventoryUtils.saveInventory(inventory, 0, nbt);
|
||||
InventoryUtils.saveInventory(upgradesInventory, 1, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,6 +143,10 @@ public class TileDestructor extends TileMachine implements ICompareConfig, IMode
|
||||
return ContainerDestructor.class;
|
||||
}
|
||||
|
||||
public InventorySimple getUpgradesInventory() {
|
||||
return upgradesInventory;
|
||||
}
|
||||
|
||||
public IInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@@ -50,10 +50,10 @@ public class TileExporter extends TileMachine implements ICompareConfig {
|
||||
controller.push(remaining);
|
||||
}
|
||||
} else if (TileInterface.hasCrafting(upgradesInventory)) {
|
||||
CraftingPattern pattern = controller.getPatternForItem(slot, compare);
|
||||
CraftingPattern pattern = controller.getPattern(slot, compare);
|
||||
|
||||
if (pattern != null && !controller.hasCraftingTaskWithPattern(pattern, compare)) {
|
||||
controller.addCraftingTaskForPattern(pattern);
|
||||
if (pattern != null && !controller.hasCraftingTask(pattern, compare)) {
|
||||
controller.addCraftingTask(pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,10 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -47,7 +51,7 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided
|
||||
}
|
||||
}
|
||||
|
||||
return 9 - (upgrades * 2);
|
||||
return baseSpeed - (upgrades * 2);
|
||||
}
|
||||
|
||||
public static boolean hasCrafting(InventorySimple upgradesInventory) {
|
||||
@@ -86,7 +90,7 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided
|
||||
ItemStack got = inventory.getStackInSlot(i + 9);
|
||||
|
||||
if (wanted != null) {
|
||||
boolean ok = false;
|
||||
boolean mayTake = false;
|
||||
|
||||
if (got != null) {
|
||||
if (!InventoryUtils.compareStack(wanted, got, compare)) {
|
||||
@@ -94,13 +98,13 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided
|
||||
inventory.setInventorySlotContents(i + 9, null);
|
||||
}
|
||||
} else {
|
||||
ok = true;
|
||||
mayTake = true;
|
||||
}
|
||||
} else {
|
||||
ok = true;
|
||||
mayTake = true;
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
if (mayTake) {
|
||||
got = inventory.getStackInSlot(i + 9);
|
||||
|
||||
int needed = got == null ? wanted.stackSize : wanted.stackSize - got.stackSize;
|
||||
@@ -120,13 +124,13 @@ public class TileInterface extends TileMachine implements ICompareConfig, ISided
|
||||
}
|
||||
|
||||
if (hasCrafting(upgradesInventory)) {
|
||||
CraftingPattern pattern = controller.getPatternForItem(wanted, compare);
|
||||
CraftingPattern pattern = controller.getPattern(wanted, compare);
|
||||
|
||||
if (pattern != null && took == null || took.stackSize != needed) {
|
||||
int tasksToCreate = needed - controller.getAmountOfCraftingTasksWithPattern(pattern, compare);
|
||||
int tasksToCreate = needed - controller.getCraftingTaskCount(pattern, compare);
|
||||
|
||||
for (int j = 0; j < tasksToCreate; ++j) {
|
||||
controller.addCraftingTaskForPattern(pattern);
|
||||
controller.addCraftingTask(pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ public class BasicCraftingTask implements ICraftingTask {
|
||||
if (took != null) {
|
||||
satisfied[i] = true;
|
||||
} else if (!childTasks[i]) {
|
||||
CraftingPattern pattern = controller.getPatternForItem(input);
|
||||
CraftingPattern pattern = controller.getPattern(input);
|
||||
|
||||
if (pattern != null) {
|
||||
controller.addCraftingTaskForPattern(pattern);
|
||||
controller.addCraftingTask(pattern);
|
||||
|
||||
childTasks[i] = true;
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.9 KiB |
Reference in New Issue
Block a user