add whitelist / blacklist to importer and fix some code
This commit is contained in:
31
src/main/java/storagecraft/tile/ImporterMode.java
Normal file
31
src/main/java/storagecraft/tile/ImporterMode.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package storagecraft.tile;
|
||||
|
||||
public enum ImporterMode {
|
||||
WHITELIST(0), BLACKLIST(1);
|
||||
|
||||
public final int id;
|
||||
|
||||
ImporterMode(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public ImporterMode next() {
|
||||
ImporterMode next = getById(id + 1);
|
||||
|
||||
if (next == null) {
|
||||
return getById(0);
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
public static ImporterMode getById(int id) {
|
||||
for (ImporterMode mode : values()) {
|
||||
if (mode.id == id) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,16 @@ public enum RedstoneMode {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public RedstoneMode next() {
|
||||
RedstoneMode next = getById(id + 1);
|
||||
|
||||
if (next == null) {
|
||||
return getById(0);
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
public static RedstoneMode getById(int id) {
|
||||
for (RedstoneMode control : values()) {
|
||||
if (control.id == id) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import storagecraft.network.MessageTileUpdate;
|
||||
public class TileBase extends TileEntity {
|
||||
public static final int UPDATE_RANGE = 64;
|
||||
|
||||
private ForgeDirection direction;
|
||||
private ForgeDirection direction = ForgeDirection.UNKNOWN;
|
||||
|
||||
protected int ticks;
|
||||
|
||||
|
||||
@@ -11,10 +11,12 @@ import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileImporter extends TileMachine implements IInventory {
|
||||
public static final String NBT_COMPARE_FLAGS = "CompareFlags";
|
||||
public static final String NBT_MODE = "Mode";
|
||||
|
||||
private InventorySimple inventory = new InventorySimple("importer", 9);
|
||||
|
||||
private int compareFlags = InventoryUtils.COMPARE_NBT | InventoryUtils.COMPARE_DAMAGE;
|
||||
private int compareFlags = 0;
|
||||
private ImporterMode mode = ImporterMode.WHITELIST;
|
||||
|
||||
private int currentSlot = 0;
|
||||
|
||||
@@ -67,12 +69,20 @@ public class TileImporter extends TileMachine implements IInventory {
|
||||
slots++;
|
||||
|
||||
if (InventoryUtils.compareStack(stack, slot, compareFlags)) {
|
||||
return true;
|
||||
if (mode == ImporterMode.WHITELIST) {
|
||||
return true;
|
||||
} else if (mode == ImporterMode.BLACKLIST) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return slots == 0;
|
||||
if (mode == ImporterMode.WHITELIST) {
|
||||
return slots == 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getCompareFlags() {
|
||||
@@ -83,6 +93,14 @@ public class TileImporter extends TileMachine implements IInventory {
|
||||
this.compareFlags = flags;
|
||||
}
|
||||
|
||||
public ImporterMode getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setMode(ImporterMode mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inventory.getSizeInventory();
|
||||
@@ -151,6 +169,10 @@ public class TileImporter extends TileMachine implements IInventory {
|
||||
compareFlags = nbt.getInteger(NBT_COMPARE_FLAGS);
|
||||
}
|
||||
|
||||
if (nbt.hasKey(NBT_MODE)) {
|
||||
mode = ImporterMode.getById(nbt.getInteger(NBT_MODE));
|
||||
}
|
||||
|
||||
InventoryUtils.restoreInventory(this, nbt);
|
||||
}
|
||||
|
||||
@@ -159,6 +181,7 @@ public class TileImporter extends TileMachine implements IInventory {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
nbt.setInteger(NBT_COMPARE_FLAGS, compareFlags);
|
||||
nbt.setInteger(NBT_MODE, mode.id);
|
||||
|
||||
InventoryUtils.saveInventory(this, nbt);
|
||||
}
|
||||
@@ -168,6 +191,7 @@ public class TileImporter extends TileMachine implements IInventory {
|
||||
super.fromBytes(buf);
|
||||
|
||||
compareFlags = buf.readInt();
|
||||
mode = ImporterMode.getById(buf.readInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,5 +199,6 @@ public class TileImporter extends TileMachine implements IInventory {
|
||||
super.toBytes(buf);
|
||||
|
||||
buf.writeInt(compareFlags);
|
||||
buf.writeInt(mode.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public abstract class TileMachine extends TileBase implements INetworkTile {
|
||||
|
||||
protected boolean connected = false;
|
||||
|
||||
private RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
||||
private RedstoneMode redstoneMode = RedstoneMode.LOW;
|
||||
|
||||
private int xController;
|
||||
private int yController;
|
||||
|
||||
Reference in New Issue
Block a user