Allow whitelist / blacklist and filters on destructors
This commit is contained in:
@@ -1,28 +1,15 @@
|
|||||||
package refinedstorage.container;
|
package refinedstorage.container;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import refinedstorage.container.slot.SlotSpecimenItemBlock;
|
||||||
import net.minecraft.item.ItemBlock;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import refinedstorage.container.slot.SlotSpecimen;
|
|
||||||
import refinedstorage.tile.TileConstructor;
|
import refinedstorage.tile.TileConstructor;
|
||||||
|
|
||||||
public class ContainerConstructor extends ContainerBase {
|
public class ContainerConstructor extends ContainerBase {
|
||||||
class SlotConstructor extends SlotSpecimen {
|
|
||||||
public SlotConstructor(IInventory inventory, int id, int x, int y) {
|
|
||||||
super(inventory, id, x, y, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isItemValid(ItemStack stack) {
|
|
||||||
return stack.getItem() instanceof ItemBlock;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContainerConstructor(EntityPlayer player, TileConstructor constructor) {
|
public ContainerConstructor(EntityPlayer player, TileConstructor constructor) {
|
||||||
super(player);
|
super(player);
|
||||||
|
|
||||||
addSlotToContainer(new SlotConstructor(constructor.getInventory(), 0, 80, 20));
|
addSlotToContainer(new SlotSpecimenItemBlock(constructor.getInventory(), 0, 80, 20));
|
||||||
|
|
||||||
addPlayerInventory(8, 55);
|
addPlayerInventory(8, 55);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
package refinedstorage.container;
|
package refinedstorage.container;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import refinedstorage.container.slot.SlotSpecimenItemBlock;
|
||||||
|
import refinedstorage.tile.TileDestructor;
|
||||||
|
|
||||||
public class ContainerDestructor extends ContainerBase {
|
public class ContainerDestructor extends ContainerBase {
|
||||||
public ContainerDestructor(EntityPlayer player) {
|
public ContainerDestructor(EntityPlayer player, TileDestructor destructor) {
|
||||||
super(player);
|
super(player);
|
||||||
|
|
||||||
addPlayerInventory(8, 50);
|
for (int i = 0; i < 9; ++i) {
|
||||||
|
addSlotToContainer(new SlotSpecimenItemBlock(destructor.getInventory(), i, 8 + (18 * i), 20));
|
||||||
|
}
|
||||||
|
|
||||||
|
addPlayerInventory(8, 55);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/main/java/refinedstorage/container/slot/SlotSpecimenItemBlock.java
Executable file
16
src/main/java/refinedstorage/container/slot/SlotSpecimenItemBlock.java
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
package refinedstorage.container.slot;
|
||||||
|
|
||||||
|
import net.minecraft.inventory.IInventory;
|
||||||
|
import net.minecraft.item.ItemBlock;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
public class SlotSpecimenItemBlock extends SlotSpecimen {
|
||||||
|
public SlotSpecimenItemBlock(IInventory inventory, int id, int x, int y) {
|
||||||
|
super(inventory, id, x, y, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isItemValid(ItemStack stack) {
|
||||||
|
return stack.getItem() instanceof ItemBlock;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
package refinedstorage.gui;
|
package refinedstorage.gui;
|
||||||
|
|
||||||
import refinedstorage.container.ContainerDestructor;
|
import refinedstorage.container.ContainerDestructor;
|
||||||
|
import refinedstorage.gui.sidebutton.SideButtonCompare;
|
||||||
|
import refinedstorage.gui.sidebutton.SideButtonMode;
|
||||||
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
||||||
import refinedstorage.tile.TileDestructor;
|
import refinedstorage.tile.TileDestructor;
|
||||||
|
import refinedstorage.util.InventoryUtils;
|
||||||
|
|
||||||
public class GuiDestructor extends GuiBase {
|
public class GuiDestructor extends GuiBase {
|
||||||
private TileDestructor destructor;
|
private TileDestructor destructor;
|
||||||
|
|
||||||
public GuiDestructor(ContainerDestructor container, TileDestructor destructor) {
|
public GuiDestructor(ContainerDestructor container, TileDestructor destructor) {
|
||||||
super(container, 176, 131);
|
super(container, 176, 137);
|
||||||
|
|
||||||
this.destructor = destructor;
|
this.destructor = destructor;
|
||||||
}
|
}
|
||||||
@@ -16,6 +19,11 @@ public class GuiDestructor extends GuiBase {
|
|||||||
@Override
|
@Override
|
||||||
public void init(int x, int y) {
|
public void init(int x, int y) {
|
||||||
addSideButton(new SideButtonRedstoneMode(destructor));
|
addSideButton(new SideButtonRedstoneMode(destructor));
|
||||||
|
|
||||||
|
addSideButton(new SideButtonMode(destructor));
|
||||||
|
|
||||||
|
addSideButton(new SideButtonCompare(destructor, InventoryUtils.COMPARE_DAMAGE));
|
||||||
|
addSideButton(new SideButtonCompare(destructor, InventoryUtils.COMPARE_NBT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -32,6 +40,6 @@ public class GuiDestructor extends GuiBase {
|
|||||||
@Override
|
@Override
|
||||||
public void drawForeground(int mouseX, int mouseY) {
|
public void drawForeground(int mouseX, int mouseY) {
|
||||||
drawString(7, 7, t("gui.refinedstorage:destructor"));
|
drawString(7, 7, t("gui.refinedstorage:destructor"));
|
||||||
drawString(7, 39, t("container.inventory"));
|
drawString(7, 43, t("container.inventory"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class GuiHandler implements IGuiHandler {
|
|||||||
case RefinedStorageGui.WIRELESS_TRANSMITTER:
|
case RefinedStorageGui.WIRELESS_TRANSMITTER:
|
||||||
return new ContainerWirelessTransmitter(player, (TileWirelessTransmitter) tile);
|
return new ContainerWirelessTransmitter(player, (TileWirelessTransmitter) tile);
|
||||||
case RefinedStorageGui.DESTRUCTOR:
|
case RefinedStorageGui.DESTRUCTOR:
|
||||||
return new ContainerDestructor(player);
|
return new ContainerDestructor(player, (TileDestructor) tile);
|
||||||
case RefinedStorageGui.CONSTRUCTOR:
|
case RefinedStorageGui.CONSTRUCTOR:
|
||||||
return new ContainerConstructor(player, (TileConstructor) tile);
|
return new ContainerConstructor(player, (TileConstructor) tile);
|
||||||
case RefinedStorageGui.STORAGE:
|
case RefinedStorageGui.STORAGE:
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import refinedstorage.tile.settings.ICompareSetting;
|
|||||||
import refinedstorage.util.InventoryUtils;
|
import refinedstorage.util.InventoryUtils;
|
||||||
|
|
||||||
public class TileConstructor extends TileMachine implements ICompareSetting {
|
public class TileConstructor extends TileMachine implements ICompareSetting {
|
||||||
|
public static final int SPEED = 10;
|
||||||
|
|
||||||
public static final String NBT_COMPARE = "Compare";
|
public static final String NBT_COMPARE = "Compare";
|
||||||
|
|
||||||
private InventorySimple inventory = new InventorySimple("constructor", 1, this);
|
private InventorySimple inventory = new InventorySimple("constructor", 1, this);
|
||||||
@@ -24,7 +26,7 @@ public class TileConstructor extends TileMachine implements ICompareSetting {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMachine() {
|
public void updateMachine() {
|
||||||
if (ticks % 10 == 0) {
|
if (ticks % SPEED == 0) {
|
||||||
BlockPos front = pos.offset(getDirection());
|
BlockPos front = pos.offset(getDirection());
|
||||||
|
|
||||||
if ((worldObj.isAirBlock(front) || worldObj.getBlockState(front).getBlock().getMaterial(worldObj.getBlockState(front)).isLiquid()) && inventory.getStackInSlot(0) != null) {
|
if ((worldObj.isAirBlock(front) || worldObj.getBlockState(front).getBlock().getMaterial(worldObj.getBlockState(front)).isLiquid()) && inventory.getStackInSlot(0) != null) {
|
||||||
|
|||||||
@@ -1,14 +1,31 @@
|
|||||||
package refinedstorage.tile;
|
package refinedstorage.tile;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import refinedstorage.inventory.InventorySimple;
|
||||||
|
import refinedstorage.tile.settings.ICompareSetting;
|
||||||
|
import refinedstorage.tile.settings.IModeSetting;
|
||||||
|
import refinedstorage.tile.settings.ModeSettingUtils;
|
||||||
import refinedstorage.util.InventoryUtils;
|
import refinedstorage.util.InventoryUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TileDestructor extends TileMachine {
|
public class TileDestructor extends TileMachine implements ICompareSetting, IModeSetting {
|
||||||
|
public static final String NBT_COMPARE = "Compare";
|
||||||
|
public static final String NBT_MODE = "Mode";
|
||||||
|
|
||||||
|
public static final int SPEED = 10;
|
||||||
|
|
||||||
|
private InventorySimple inventory = new InventorySimple("destructor", 9, this);
|
||||||
|
|
||||||
|
private int compare = 0;
|
||||||
|
private int mode = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage() {
|
||||||
return 1;
|
return 1;
|
||||||
@@ -16,23 +33,106 @@ public class TileDestructor extends TileMachine {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMachine() {
|
public void updateMachine() {
|
||||||
if (ticks % 10 == 0) {
|
if (ticks % SPEED == 0) {
|
||||||
BlockPos front = pos.offset(getDirection());
|
BlockPos front = pos.offset(getDirection());
|
||||||
|
|
||||||
IBlockState frontBlockState = worldObj.getBlockState(front);
|
IBlockState frontBlockState = worldObj.getBlockState(front);
|
||||||
Block frontBlock = frontBlockState.getBlock();
|
Block frontBlock = frontBlockState.getBlock();
|
||||||
|
|
||||||
if (!frontBlock.isAir(frontBlockState, worldObj, front)) {
|
if (!frontBlock.isAir(frontBlockState, worldObj, front)) {
|
||||||
List<ItemStack> drops = frontBlock.getDrops(worldObj, front, worldObj.getBlockState(front), 0);
|
if (ModeSettingUtils.doesNotViolateMode(inventory, this, compare, new ItemStack(frontBlock, 1, frontBlock.getMetaFromState(frontBlockState)))) {
|
||||||
|
List<ItemStack> drops = frontBlock.getDrops(worldObj, front, frontBlockState, 0);
|
||||||
|
|
||||||
worldObj.setBlockToAir(front);
|
worldObj.setBlockToAir(front);
|
||||||
|
|
||||||
for (ItemStack drop : drops) {
|
for (ItemStack drop : drops) {
|
||||||
if (!getController().push(drop)) {
|
if (!getController().push(drop)) {
|
||||||
InventoryUtils.dropStack(worldObj, drop, front.getX(), front.getY(), front.getZ());
|
InventoryUtils.dropStack(worldObj, drop, front.getX(), front.getY(), front.getZ());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCompare() {
|
||||||
|
return compare;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCompare(int compare) {
|
||||||
|
markDirty();
|
||||||
|
|
||||||
|
this.compare = compare;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWhitelist() {
|
||||||
|
return mode == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBlacklist() {
|
||||||
|
return mode == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setToWhitelist() {
|
||||||
|
markDirty();
|
||||||
|
|
||||||
|
this.mode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setToBlacklist() {
|
||||||
|
markDirty();
|
||||||
|
|
||||||
|
this.mode = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromNBT(NBTTagCompound nbt) {
|
||||||
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
|
if (nbt.hasKey(NBT_COMPARE)) {
|
||||||
|
compare = nbt.getInteger(NBT_COMPARE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nbt.hasKey(NBT_MODE)) {
|
||||||
|
mode = nbt.getInteger(NBT_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
InventoryUtils.restoreInventory(inventory, 0, nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToNBT(NBTTagCompound nbt) {
|
||||||
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
|
nbt.setInteger(NBT_COMPARE, compare);
|
||||||
|
nbt.setInteger(NBT_MODE, mode);
|
||||||
|
|
||||||
|
InventoryUtils.saveInventory(inventory, 0, nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
super.fromBytes(buf);
|
||||||
|
|
||||||
|
compare = buf.readInt();
|
||||||
|
mode = buf.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
super.toBytes(buf);
|
||||||
|
|
||||||
|
buf.writeInt(compare);
|
||||||
|
buf.writeInt(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IInventory getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.8 KiB |
Reference in New Issue
Block a user