reformat
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package storagecraft.tile;
|
||||
|
||||
public interface ICompareSetting {
|
||||
public interface ICompareSetting
|
||||
{
|
||||
public int getCompare();
|
||||
|
||||
public void setCompare(int compare);
|
||||
|
||||
@@ -2,7 +2,8 @@ package storagecraft.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public interface INetworkTile {
|
||||
public interface INetworkTile
|
||||
{
|
||||
public void fromBytes(ByteBuf buf);
|
||||
|
||||
public void toBytes(ByteBuf buf);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package storagecraft.tile;
|
||||
|
||||
public interface IRedstoneModeSetting {
|
||||
public interface IRedstoneModeSetting
|
||||
{
|
||||
public RedstoneMode getRedstoneMode();
|
||||
|
||||
public void setRedstoneMode(RedstoneMode mode);
|
||||
|
||||
@@ -2,7 +2,8 @@ package storagecraft.tile;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public enum RedstoneMode {
|
||||
public enum RedstoneMode
|
||||
{
|
||||
IGNORE(0),
|
||||
HIGH(1),
|
||||
LOW(2);
|
||||
@@ -11,22 +12,27 @@ public enum RedstoneMode {
|
||||
|
||||
public final int id;
|
||||
|
||||
RedstoneMode(int id) {
|
||||
RedstoneMode(int id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public RedstoneMode next() {
|
||||
public RedstoneMode next()
|
||||
{
|
||||
RedstoneMode next = getById(id + 1);
|
||||
|
||||
if (next == null) {
|
||||
if (next == null)
|
||||
{
|
||||
return getById(0);
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
public boolean isEnabled(World world, int x, int y, int z) {
|
||||
switch (this) {
|
||||
public boolean isEnabled(World world, int x, int y, int z)
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case IGNORE:
|
||||
return true;
|
||||
case HIGH:
|
||||
@@ -38,9 +44,12 @@ public enum RedstoneMode {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static RedstoneMode getById(int id) {
|
||||
for (RedstoneMode control : values()) {
|
||||
if (control.id == id) {
|
||||
public static RedstoneMode getById(int id)
|
||||
{
|
||||
for (RedstoneMode control : values())
|
||||
{
|
||||
if (control.id == id)
|
||||
{
|
||||
return control;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import storagecraft.StorageCraft;
|
||||
import storagecraft.network.MessageTileUpdate;
|
||||
|
||||
public abstract class TileBase extends TileEntity {
|
||||
public abstract class TileBase extends TileEntity
|
||||
{
|
||||
public static final int UPDATE_RANGE = 256;
|
||||
|
||||
private ForgeDirection direction = ForgeDirection.UNKNOWN;
|
||||
@@ -18,13 +19,16 @@ public abstract class TileBase extends TileEntity {
|
||||
protected int ticks;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
ticks++;
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
if (this instanceof INetworkTile) {
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (this instanceof INetworkTile)
|
||||
{
|
||||
TargetPoint target = new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, UPDATE_RANGE);
|
||||
|
||||
StorageCraft.NETWORK.sendToAllAround(new MessageTileUpdate(this), target);
|
||||
@@ -32,30 +36,35 @@ public abstract class TileBase extends TileEntity {
|
||||
}
|
||||
}
|
||||
|
||||
public void setDirection(ForgeDirection direction) {
|
||||
public void setDirection(ForgeDirection direction)
|
||||
{
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
public ForgeDirection getDirection() {
|
||||
public ForgeDirection getDirection()
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
direction = ForgeDirection.getOrientation(nbt.getInteger("Direction"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
nbt.setInteger("Direction", direction.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
|
||||
nbt.setInteger("Direction", direction.ordinal());
|
||||
@@ -64,7 +73,8 @@ public abstract class TileBase extends TileEntity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||
{
|
||||
direction = ForgeDirection.getOrientation(packet.func_148857_g().getInteger("Direction"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,15 +8,19 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import storagecraft.block.BlockCable;
|
||||
|
||||
public class TileCable extends TileBase {
|
||||
public static boolean isCable(World world, int x, int y, int z, ForgeDirection dir) {
|
||||
public class TileCable extends TileBase
|
||||
{
|
||||
public static boolean isCable(World world, int x, int y, int z, ForgeDirection dir)
|
||||
{
|
||||
Block block = world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
|
||||
|
||||
return block instanceof BlockCable;
|
||||
}
|
||||
|
||||
public boolean hasConnection(ForgeDirection dir) {
|
||||
if (!isCable(worldObj, xCoord, yCoord, zCoord, dir)) {
|
||||
public boolean hasConnection(ForgeDirection dir)
|
||||
{
|
||||
if (!isCable(worldObj, xCoord, yCoord, zCoord, dir))
|
||||
{
|
||||
TileEntity tile = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
|
||||
|
||||
return tile instanceof TileMachine || tile instanceof TileController;
|
||||
@@ -25,57 +29,73 @@ public class TileCable extends TileBase {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isPowered() {
|
||||
public boolean isPowered()
|
||||
{
|
||||
return worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
public boolean isSensitiveCable() {
|
||||
public boolean isSensitiveCable()
|
||||
{
|
||||
return worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 1;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
if (isSensitiveCable()) {
|
||||
public boolean isEnabled()
|
||||
{
|
||||
if (isSensitiveCable())
|
||||
{
|
||||
return !isPowered();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addMachines(List<Vec3> visited, List<TileMachine> machines, TileController controller) {
|
||||
for (Vec3 visitedBlock : visited) {
|
||||
if (visitedBlock.xCoord == xCoord && visitedBlock.yCoord == yCoord && visitedBlock.zCoord == zCoord) {
|
||||
public void addMachines(List<Vec3> visited, List<TileMachine> machines, TileController controller)
|
||||
{
|
||||
for (Vec3 visitedBlock : visited)
|
||||
{
|
||||
if (visitedBlock.xCoord == xCoord && visitedBlock.yCoord == yCoord && visitedBlock.zCoord == zCoord)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
visited.add(Vec3.createVectorHelper(xCoord, yCoord, zCoord));
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
int x = xCoord + dir.offsetX;
|
||||
int y = yCoord + dir.offsetY;
|
||||
int z = zCoord + dir.offsetZ;
|
||||
|
||||
boolean found = false;
|
||||
|
||||
for (Vec3 visitedBlock : visited) {
|
||||
if (visitedBlock.xCoord == x && visitedBlock.yCoord == y && visitedBlock.zCoord == z) {
|
||||
for (Vec3 visitedBlock : visited)
|
||||
{
|
||||
if (visitedBlock.xCoord == x && visitedBlock.yCoord == y && visitedBlock.zCoord == z)
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
if (found)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
TileEntity tile = worldObj.getTileEntity(x, y, z);
|
||||
|
||||
if (tile instanceof TileMachine && ((TileMachine) tile).getRedstoneMode().isEnabled(worldObj, x, y, z)) {
|
||||
if (tile instanceof TileMachine && ((TileMachine) tile).getRedstoneMode().isEnabled(worldObj, x, y, z))
|
||||
{
|
||||
machines.add((TileMachine) tile);
|
||||
|
||||
visited.add(Vec3.createVectorHelper(x, y, z));
|
||||
} else if (tile instanceof TileCable && ((TileCable) tile).isEnabled()) {
|
||||
}
|
||||
else if (tile instanceof TileCable && ((TileCable) tile).isEnabled())
|
||||
{
|
||||
((TileCable) tile).addMachines(visited, machines, controller);
|
||||
} else if (tile instanceof TileController && (x != controller.xCoord || y != controller.yCoord || z != controller.zCoord)) {
|
||||
}
|
||||
else if (tile instanceof TileController && (x != controller.xCoord || y != controller.yCoord || z != controller.zCoord))
|
||||
{
|
||||
worldObj.createExplosion(null, x, y, z, 4.5f, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ import storagecraft.storage.IStorageProvider;
|
||||
import storagecraft.storage.StorageItem;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileController extends TileBase implements IEnergyReceiver, INetworkTile, IRedstoneModeSetting {
|
||||
public class TileController extends TileBase implements IEnergyReceiver, INetworkTile, IRedstoneModeSetting
|
||||
{
|
||||
private List<StorageItem> items = new ArrayList<StorageItem>();
|
||||
private List<IStorage> storages = new ArrayList<IStorage>();
|
||||
|
||||
@@ -31,42 +32,56 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
private boolean destroyed = false;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
if (destroyed) {
|
||||
if (destroyed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
if (ticks % 40 == 0) {
|
||||
if (!isActive()) {
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (ticks % 40 == 0)
|
||||
{
|
||||
if (!isActive())
|
||||
{
|
||||
disconnectAll();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
visitedCables.clear();
|
||||
|
||||
List<TileMachine> newMachines = new ArrayList<TileMachine>();
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tile = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
|
||||
|
||||
if (tile instanceof TileCable) {
|
||||
if (tile instanceof TileCable)
|
||||
{
|
||||
TileCable cable = (TileCable) tile;
|
||||
|
||||
if (cable.isEnabled()) {
|
||||
if (cable.isEnabled())
|
||||
{
|
||||
cable.addMachines(visitedCables, newMachines, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (TileMachine machine : machines) {
|
||||
if (!newMachines.contains(machine)) {
|
||||
for (TileMachine machine : machines)
|
||||
{
|
||||
if (!newMachines.contains(machine))
|
||||
{
|
||||
machine.onDisconnected();
|
||||
}
|
||||
}
|
||||
|
||||
for (TileMachine machine : newMachines) {
|
||||
if (!machines.contains(machine)) {
|
||||
for (TileMachine machine : newMachines)
|
||||
{
|
||||
if (!machines.contains(machine))
|
||||
{
|
||||
machine.onConnected(this);
|
||||
}
|
||||
}
|
||||
@@ -75,8 +90,10 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
|
||||
storages.clear();
|
||||
|
||||
for (TileMachine machine : machines) {
|
||||
if (machine instanceof IStorageProvider) {
|
||||
for (TileMachine machine : machines)
|
||||
{
|
||||
if (machine instanceof IStorageProvider)
|
||||
{
|
||||
((IStorageProvider) machine).addStorages(storages);
|
||||
}
|
||||
}
|
||||
@@ -86,67 +103,83 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
|
||||
energyUsage = 10;
|
||||
|
||||
for (TileMachine machine : machines) {
|
||||
for (TileMachine machine : machines)
|
||||
{
|
||||
energyUsage += machine.getEnergyUsage();
|
||||
}
|
||||
}
|
||||
|
||||
energy.extractEnergy(energyUsage, false);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
public void onDestroyed() {
|
||||
public void onDestroyed()
|
||||
{
|
||||
disconnectAll();
|
||||
|
||||
destroyed = true;
|
||||
}
|
||||
|
||||
private void disconnectAll() {
|
||||
for (TileMachine machine : machines) {
|
||||
private void disconnectAll()
|
||||
{
|
||||
for (TileMachine machine : machines)
|
||||
{
|
||||
machine.onDisconnected();
|
||||
}
|
||||
|
||||
machines.clear();
|
||||
}
|
||||
|
||||
public List<TileMachine> getMachines() {
|
||||
public List<TileMachine> getMachines()
|
||||
{
|
||||
return machines;
|
||||
}
|
||||
|
||||
public List<StorageItem> getItems() {
|
||||
public List<StorageItem> getItems()
|
||||
{
|
||||
return items;
|
||||
}
|
||||
|
||||
private void syncItems() {
|
||||
private void syncItems()
|
||||
{
|
||||
items.clear();
|
||||
|
||||
for (IStorage storage : storages) {
|
||||
for (IStorage storage : storages)
|
||||
{
|
||||
storage.addItems(items);
|
||||
}
|
||||
|
||||
combineItems();
|
||||
}
|
||||
|
||||
private void combineItems() {
|
||||
private void combineItems()
|
||||
{
|
||||
List<Integer> markedIndexes = new ArrayList<Integer>();
|
||||
|
||||
for (int i = 0; i < items.size(); ++i) {
|
||||
if (markedIndexes.contains(i)) {
|
||||
for (int i = 0; i < items.size(); ++i)
|
||||
{
|
||||
if (markedIndexes.contains(i))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
StorageItem item = items.get(i);
|
||||
|
||||
for (int j = i + 1; j < items.size(); ++j) {
|
||||
if (markedIndexes.contains(j)) {
|
||||
for (int j = i + 1; j < items.size(); ++j)
|
||||
{
|
||||
if (markedIndexes.contains(j))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
StorageItem other = items.get(j);
|
||||
|
||||
if (item.compareNoQuantity(other)) {
|
||||
if (item.compareNoQuantity(other))
|
||||
{
|
||||
item.setQuantity(item.getQuantity() + other.getQuantity());
|
||||
|
||||
markedIndexes.add(j);
|
||||
@@ -156,25 +189,30 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
|
||||
List<StorageItem> markedItems = new ArrayList<StorageItem>();
|
||||
|
||||
for (int i : markedIndexes) {
|
||||
for (int i : markedIndexes)
|
||||
{
|
||||
markedItems.add(items.get(i));
|
||||
}
|
||||
|
||||
items.removeAll(markedItems);
|
||||
}
|
||||
|
||||
public boolean push(ItemStack stack) {
|
||||
public boolean push(ItemStack stack)
|
||||
{
|
||||
IStorage foundStorage = null;
|
||||
|
||||
for (IStorage storage : storages) {
|
||||
if (storage.canPush(stack)) {
|
||||
for (IStorage storage : storages)
|
||||
{
|
||||
if (storage.canPush(stack))
|
||||
{
|
||||
foundStorage = storage;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundStorage == null) {
|
||||
if (foundStorage == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -185,30 +223,38 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
return true;
|
||||
}
|
||||
|
||||
public ItemStack take(ItemStack stack) {
|
||||
public ItemStack take(ItemStack stack)
|
||||
{
|
||||
return take(stack, InventoryUtils.COMPARE_DAMAGE | InventoryUtils.COMPARE_NBT);
|
||||
}
|
||||
|
||||
public ItemStack take(ItemStack stack, int flags) {
|
||||
public ItemStack take(ItemStack stack, int flags)
|
||||
{
|
||||
int requested = stack.stackSize;
|
||||
int receiving = 0;
|
||||
|
||||
ItemStack newStack = null;
|
||||
|
||||
for (IStorage storage : storages) {
|
||||
for (IStorage storage : storages)
|
||||
{
|
||||
ItemStack took = storage.take(stack, flags);
|
||||
|
||||
if (took != null) {
|
||||
if (newStack == null) {
|
||||
if (took != null)
|
||||
{
|
||||
if (newStack == null)
|
||||
{
|
||||
newStack = took;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
newStack.stackSize += took.stackSize;
|
||||
}
|
||||
|
||||
receiving += took.stackSize;
|
||||
}
|
||||
|
||||
if (requested == receiving) {
|
||||
if (requested == receiving)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -219,18 +265,21 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
energy.readFromNBT(nbt);
|
||||
|
||||
if (nbt.hasKey(RedstoneMode.NBT)) {
|
||||
if (nbt.hasKey(RedstoneMode.NBT))
|
||||
{
|
||||
redstoneMode = RedstoneMode.getById(nbt.getInteger(RedstoneMode.NBT));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
energy.writeToNBT(nbt);
|
||||
@@ -239,60 +288,72 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
||||
{
|
||||
return energy.receiveEnergy(maxReceive, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from) {
|
||||
public int getEnergyStored(ForgeDirection from)
|
||||
{
|
||||
return energy.getEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from) {
|
||||
public int getMaxEnergyStored(ForgeDirection from)
|
||||
{
|
||||
return energy.getMaxEnergyStored();
|
||||
}
|
||||
|
||||
public int getEnergyUsage() {
|
||||
public int getEnergyUsage()
|
||||
{
|
||||
return energyUsage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection from) {
|
||||
public boolean canConnectEnergy(ForgeDirection from)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
public boolean isActive()
|
||||
{
|
||||
return energy.getEnergyStored() >= getEnergyUsage() && redstoneMode.isEnabled(worldObj, xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneMode getRedstoneMode() {
|
||||
public RedstoneMode getRedstoneMode()
|
||||
{
|
||||
return redstoneMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRedstoneMode(RedstoneMode mode) {
|
||||
public void setRedstoneMode(RedstoneMode mode)
|
||||
{
|
||||
this.redstoneMode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
public int getX()
|
||||
{
|
||||
return xCoord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
public int getY()
|
||||
{
|
||||
return yCoord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
public int getZ()
|
||||
{
|
||||
return zCoord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
public void fromBytes(ByteBuf buf)
|
||||
{
|
||||
energy.setEnergyStored(buf.readInt());
|
||||
energyUsage = buf.readInt();
|
||||
|
||||
@@ -302,13 +363,15 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
|
||||
int size = buf.readInt();
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
items.add(new StorageItem(buf));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
buf.writeInt(energy.getEnergyStored());
|
||||
buf.writeInt(energyUsage);
|
||||
|
||||
@@ -316,7 +379,8 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
|
||||
buf.writeInt(items.size());
|
||||
|
||||
for (StorageItem item : items) {
|
||||
for (StorageItem item : items)
|
||||
{
|
||||
item.toBytes(buf, items.indexOf(item));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ import storagecraft.inventory.InventorySimple;
|
||||
import storagecraft.storage.StorageItem;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileDetector extends TileMachine implements IInventory, ISidedInventory, ICompareSetting {
|
||||
public class TileDetector extends TileMachine implements IInventory, ISidedInventory, ICompareSetting
|
||||
{
|
||||
public static final int MODE_UNDER = 0;
|
||||
public static final int MODE_EQUAL = 1;
|
||||
public static final int MODE_ABOVE = 2;
|
||||
@@ -28,30 +29,38 @@ public class TileDetector extends TileMachine implements IInventory, ISidedInven
|
||||
|
||||
private boolean providesPower = false;
|
||||
|
||||
public TileDetector() {
|
||||
public TileDetector()
|
||||
{
|
||||
this.redstoneControlled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyUsage() {
|
||||
public int getEnergyUsage()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMachine() {
|
||||
if (ticks % 5 == 0) {
|
||||
public void updateMachine()
|
||||
{
|
||||
if (ticks % 5 == 0)
|
||||
{
|
||||
ItemStack slot = inventory.getStackInSlot(0);
|
||||
|
||||
boolean lastProvidesPower = providesPower;
|
||||
|
||||
if (slot != null) {
|
||||
if (slot != null)
|
||||
{
|
||||
boolean foundAny = false;
|
||||
|
||||
for (StorageItem item : getController().getItems()) {
|
||||
if (item.compare(slot, compare)) {
|
||||
for (StorageItem item : getController().getItems())
|
||||
{
|
||||
if (item.compare(slot, compare))
|
||||
{
|
||||
foundAny = true;
|
||||
|
||||
switch (mode) {
|
||||
switch (mode)
|
||||
{
|
||||
case MODE_UNDER:
|
||||
providesPower = item.getQuantity() < amount;
|
||||
break;
|
||||
@@ -67,144 +76,181 @@ public class TileDetector extends TileMachine implements IInventory, ISidedInven
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundAny) {
|
||||
if (mode == MODE_UNDER && amount != 0) {
|
||||
if (!foundAny)
|
||||
{
|
||||
if (mode == MODE_UNDER && amount != 0)
|
||||
{
|
||||
providesPower = true;
|
||||
} else if (mode == MODE_EQUAL && amount == 0) {
|
||||
}
|
||||
else if (mode == MODE_EQUAL && amount == 0)
|
||||
{
|
||||
providesPower = true;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
providesPower = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
providesPower = false;
|
||||
}
|
||||
|
||||
if (providesPower != lastProvidesPower) {
|
||||
if (providesPower != lastProvidesPower)
|
||||
{
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, StorageCraftBlocks.DETECTOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean providesPower() {
|
||||
public boolean providesPower()
|
||||
{
|
||||
return providesPower;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCompare() {
|
||||
public int getCompare()
|
||||
{
|
||||
return compare;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompare(int compare) {
|
||||
public void setCompare(int compare)
|
||||
{
|
||||
this.compare = compare;
|
||||
}
|
||||
|
||||
public int getMode() {
|
||||
public int getMode()
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setMode(int mode) {
|
||||
public void setMode(int mode)
|
||||
{
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public int getAmount() {
|
||||
public int getAmount()
|
||||
{
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(int amount) {
|
||||
public void setAmount(int amount)
|
||||
{
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return inventory.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
public ItemStack getStackInSlot(int slot)
|
||||
{
|
||||
return inventory.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
public ItemStack decrStackSize(int slot, int amount)
|
||||
{
|
||||
return inventory.decrStackSize(slot, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
public ItemStack getStackInSlotOnClosing(int slot)
|
||||
{
|
||||
return inventory.getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||
{
|
||||
inventory.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
public String getInventoryName()
|
||||
{
|
||||
return inventory.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return inventory.hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return inventory.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
public boolean isUseableByPlayer(EntityPlayer player)
|
||||
{
|
||||
return inventory.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
public void openInventory()
|
||||
{
|
||||
inventory.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
public void closeInventory()
|
||||
{
|
||||
inventory.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack)
|
||||
{
|
||||
return inventory.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return new int[] {};
|
||||
public int[] getAccessibleSlotsFromSide(int side)
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int slot, ItemStack stack, int side) {
|
||||
public boolean canInsertItem(int slot, ItemStack stack, int side)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slot, ItemStack stack, int side) {
|
||||
public boolean canExtractItem(int slot, ItemStack stack, int side)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
if (nbt.hasKey(NBT_COMPARE)) {
|
||||
if (nbt.hasKey(NBT_COMPARE))
|
||||
{
|
||||
compare = nbt.getInteger(NBT_COMPARE);
|
||||
}
|
||||
|
||||
if (nbt.hasKey(NBT_MODE)) {
|
||||
if (nbt.hasKey(NBT_MODE))
|
||||
{
|
||||
mode = nbt.getInteger(NBT_MODE);
|
||||
}
|
||||
|
||||
if (nbt.hasKey(NBT_AMOUNT)) {
|
||||
if (nbt.hasKey(NBT_AMOUNT))
|
||||
{
|
||||
amount = nbt.getInteger(NBT_AMOUNT);
|
||||
}
|
||||
|
||||
@@ -212,7 +258,8 @@ public class TileDetector extends TileMachine implements IInventory, ISidedInven
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
nbt.setInteger(NBT_COMPARE, compare);
|
||||
@@ -223,7 +270,8 @@ public class TileDetector extends TileMachine implements IInventory, ISidedInven
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
public void fromBytes(ByteBuf buf)
|
||||
{
|
||||
super.fromBytes(buf);
|
||||
|
||||
compare = buf.readInt();
|
||||
@@ -233,7 +281,8 @@ public class TileDetector extends TileMachine implements IInventory, ISidedInven
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
super.toBytes(buf);
|
||||
|
||||
buf.writeInt(compare);
|
||||
|
||||
@@ -11,15 +11,19 @@ import storagecraft.storage.IStorage;
|
||||
import storagecraft.storage.IStorageProvider;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileDrive extends TileMachine implements IInventory, IStorageProvider {
|
||||
public class TileDrive extends TileMachine implements IInventory, IStorageProvider
|
||||
{
|
||||
private InventorySimple inventory = new InventorySimple("drive", 8);
|
||||
|
||||
@Override
|
||||
public int getEnergyUsage() {
|
||||
public int getEnergyUsage()
|
||||
{
|
||||
int base = 5;
|
||||
|
||||
for (int i = 0; i < getSizeInventory(); ++i) {
|
||||
if (getStackInSlot(i) != null) {
|
||||
for (int i = 0; i < getSizeInventory(); ++i)
|
||||
{
|
||||
if (getStackInSlot(i) != null)
|
||||
{
|
||||
base += 2;
|
||||
}
|
||||
}
|
||||
@@ -28,87 +32,105 @@ public class TileDrive extends TileMachine implements IInventory, IStorageProvid
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMachine() {
|
||||
public void updateMachine()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return inventory.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
public ItemStack getStackInSlot(int slot)
|
||||
{
|
||||
return inventory.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
public ItemStack decrStackSize(int slot, int amount)
|
||||
{
|
||||
return inventory.decrStackSize(slot, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
public ItemStack getStackInSlotOnClosing(int slot)
|
||||
{
|
||||
return inventory.getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||
{
|
||||
inventory.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
public String getInventoryName()
|
||||
{
|
||||
return inventory.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return inventory.hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return inventory.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
public boolean isUseableByPlayer(EntityPlayer player)
|
||||
{
|
||||
return inventory.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
public void openInventory()
|
||||
{
|
||||
inventory.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
public void closeInventory()
|
||||
{
|
||||
inventory.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack)
|
||||
{
|
||||
return inventory.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
InventoryUtils.restoreInventory(this, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
InventoryUtils.saveInventory(this, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorages(List<IStorage> storages) {
|
||||
for (int i = 0; i < getSizeInventory(); ++i) {
|
||||
if (getStackInSlot(i) != null) {
|
||||
public void addStorages(List<IStorage> storages)
|
||||
{
|
||||
for (int i = 0; i < getSizeInventory(); ++i)
|
||||
{
|
||||
if (getStackInSlot(i) != null)
|
||||
{
|
||||
storages.add(new CellStorage(getStackInSlot(i)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import storagecraft.inventory.InventorySimple;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileExporter extends TileMachine implements IInventory, ISidedInventory, ICompareSetting {
|
||||
public class TileExporter extends TileMachine implements IInventory, ISidedInventory, ICompareSetting
|
||||
{
|
||||
public static final String NBT_COMPARE = "Compare";
|
||||
|
||||
private InventorySimple inventory = new InventorySimple("exporter", 9);
|
||||
@@ -18,37 +19,48 @@ public class TileExporter extends TileMachine implements IInventory, ISidedInven
|
||||
private int compare = 0;
|
||||
|
||||
@Override
|
||||
public int getEnergyUsage() {
|
||||
public int getEnergyUsage()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMachine() {
|
||||
public void updateMachine()
|
||||
{
|
||||
TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ);
|
||||
|
||||
if (tile instanceof IInventory) {
|
||||
if (tile instanceof IInventory)
|
||||
{
|
||||
IInventory connectedInventory = (IInventory) tile;
|
||||
|
||||
if (ticks % 5 == 0) {
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
||||
if (ticks % 5 == 0)
|
||||
{
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack slot = inventory.getStackInSlot(i);
|
||||
|
||||
if (slot != null) {
|
||||
if (slot != null)
|
||||
{
|
||||
ItemStack toTake = slot.copy();
|
||||
|
||||
toTake.stackSize = 64;
|
||||
|
||||
ItemStack took = getController().take(toTake, compare);
|
||||
|
||||
if (took != null) {
|
||||
if (connectedInventory instanceof ISidedInventory) {
|
||||
if (took != null)
|
||||
{
|
||||
if (connectedInventory instanceof ISidedInventory)
|
||||
{
|
||||
ISidedInventory sided = (ISidedInventory) connectedInventory;
|
||||
|
||||
boolean pushedAny = false;
|
||||
|
||||
for (int si = 0; si < connectedInventory.getSizeInventory(); ++si) {
|
||||
if (sided.canInsertItem(si, took, getDirection().getOpposite().ordinal())) { // @TODO: make more compact
|
||||
if (InventoryUtils.canPushToInventorySlot(connectedInventory, si, took)) {
|
||||
for (int si = 0; si < connectedInventory.getSizeInventory(); ++si)
|
||||
{
|
||||
if (sided.canInsertItem(si, took, getDirection().getOpposite().ordinal()))
|
||||
{ // @TODO: make more compact
|
||||
if (InventoryUtils.canPushToInventorySlot(connectedInventory, si, took))
|
||||
{
|
||||
InventoryUtils.pushToInventorySlot(connectedInventory, si, took);
|
||||
|
||||
pushedAny = true;
|
||||
@@ -58,12 +70,17 @@ public class TileExporter extends TileMachine implements IInventory, ISidedInven
|
||||
}
|
||||
}
|
||||
|
||||
if (!pushedAny) {
|
||||
if (!pushedAny)
|
||||
{
|
||||
getController().push(took);
|
||||
}
|
||||
} else if (InventoryUtils.canPushToInventory(connectedInventory, took)) {
|
||||
}
|
||||
else if (InventoryUtils.canPushToInventory(connectedInventory, took))
|
||||
{
|
||||
InventoryUtils.pushToInventory(connectedInventory, took);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
getController().push(took);
|
||||
}
|
||||
}
|
||||
@@ -74,95 +91,116 @@ public class TileExporter extends TileMachine implements IInventory, ISidedInven
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCompare() {
|
||||
public int getCompare()
|
||||
{
|
||||
return compare;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompare(int compare) {
|
||||
public void setCompare(int compare)
|
||||
{
|
||||
this.compare = compare;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return inventory.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
public ItemStack getStackInSlot(int slot)
|
||||
{
|
||||
return inventory.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
public ItemStack decrStackSize(int slot, int amount)
|
||||
{
|
||||
return inventory.decrStackSize(slot, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
public ItemStack getStackInSlotOnClosing(int slot)
|
||||
{
|
||||
return inventory.getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||
{
|
||||
inventory.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
public String getInventoryName()
|
||||
{
|
||||
return inventory.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return inventory.hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return inventory.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
public boolean isUseableByPlayer(EntityPlayer player)
|
||||
{
|
||||
return inventory.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
public void openInventory()
|
||||
{
|
||||
inventory.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
public void closeInventory()
|
||||
{
|
||||
inventory.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack)
|
||||
{
|
||||
return inventory.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return new int[] {};
|
||||
public int[] getAccessibleSlotsFromSide(int side)
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int slot, ItemStack stack, int side) {
|
||||
public boolean canInsertItem(int slot, ItemStack stack, int side)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slot, ItemStack stack, int side) {
|
||||
public boolean canExtractItem(int slot, ItemStack stack, int side)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
if (nbt.hasKey(NBT_COMPARE)) {
|
||||
if (nbt.hasKey(NBT_COMPARE))
|
||||
{
|
||||
compare = nbt.getInteger(NBT_COMPARE);
|
||||
}
|
||||
|
||||
@@ -170,7 +208,8 @@ public class TileExporter extends TileMachine implements IInventory, ISidedInven
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
nbt.setInteger(NBT_COMPARE, compare);
|
||||
@@ -179,14 +218,16 @@ public class TileExporter extends TileMachine implements IInventory, ISidedInven
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
public void fromBytes(ByteBuf buf)
|
||||
{
|
||||
super.fromBytes(buf);
|
||||
|
||||
compare = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
super.toBytes(buf);
|
||||
|
||||
buf.writeInt(compare);
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package storagecraft.tile;
|
||||
|
||||
public class TileGrid extends TileMachine {
|
||||
public class TileGrid extends TileMachine
|
||||
{
|
||||
@Override
|
||||
public int getEnergyUsage() {
|
||||
public int getEnergyUsage()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMachine() {
|
||||
public void updateMachine()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import storagecraft.inventory.InventorySimple;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileImporter extends TileMachine implements IInventory, ISidedInventory, ICompareSetting {
|
||||
public class TileImporter extends TileMachine implements IInventory, ISidedInventory, ICompareSetting
|
||||
{
|
||||
public static final int MODE_WHITELIST = 0;
|
||||
public static final int MODE_BLACKLIST = 1;
|
||||
|
||||
@@ -25,38 +26,50 @@ public class TileImporter extends TileMachine implements IInventory, ISidedInven
|
||||
private int currentSlot = 0;
|
||||
|
||||
@Override
|
||||
public int getEnergyUsage() {
|
||||
public int getEnergyUsage()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMachine() {
|
||||
public void updateMachine()
|
||||
{
|
||||
TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ);
|
||||
|
||||
if (tile instanceof IInventory) {
|
||||
if (tile instanceof IInventory)
|
||||
{
|
||||
IInventory connectedInventory = (IInventory) tile;
|
||||
|
||||
if (ticks % 5 == 0) {
|
||||
if (ticks % 5 == 0)
|
||||
{
|
||||
ItemStack slot = connectedInventory.getStackInSlot(currentSlot);
|
||||
|
||||
while ((slot = connectedInventory.getStackInSlot(currentSlot)) == null) {
|
||||
while ((slot = connectedInventory.getStackInSlot(currentSlot)) == null)
|
||||
{
|
||||
currentSlot++;
|
||||
|
||||
if (currentSlot > connectedInventory.getSizeInventory() - 1) {
|
||||
if (currentSlot > connectedInventory.getSizeInventory() - 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (slot != null && canImport(slot)) {
|
||||
if (connectedInventory instanceof ISidedInventory) {
|
||||
if (slot != null && canImport(slot))
|
||||
{
|
||||
if (connectedInventory instanceof ISidedInventory)
|
||||
{
|
||||
ISidedInventory sided = (ISidedInventory) connectedInventory;
|
||||
|
||||
if (sided.canExtractItem(currentSlot, slot.copy(), getDirection().getOpposite().ordinal())) {
|
||||
if (getController().push(slot.copy())) {
|
||||
if (sided.canExtractItem(currentSlot, slot.copy(), getDirection().getOpposite().ordinal()))
|
||||
{
|
||||
if (getController().push(slot.copy()))
|
||||
{
|
||||
connectedInventory.setInventorySlotContents(currentSlot, null);
|
||||
}
|
||||
}
|
||||
} else if (getController().push(slot.copy())) {
|
||||
}
|
||||
else if (getController().push(slot.copy()))
|
||||
{
|
||||
connectedInventory.setInventorySlotContents(currentSlot, null);
|
||||
}
|
||||
|
||||
@@ -65,33 +78,42 @@ public class TileImporter extends TileMachine implements IInventory, ISidedInven
|
||||
|
||||
currentSlot++;
|
||||
|
||||
if (currentSlot > connectedInventory.getSizeInventory() - 1) {
|
||||
if (currentSlot > connectedInventory.getSizeInventory() - 1)
|
||||
{
|
||||
currentSlot = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canImport(ItemStack stack) {
|
||||
public boolean canImport(ItemStack stack)
|
||||
{
|
||||
int slots = 0;
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack slot = inventory.getStackInSlot(i);
|
||||
|
||||
if (slot != null) {
|
||||
if (slot != null)
|
||||
{
|
||||
slots++;
|
||||
|
||||
if (InventoryUtils.compareStack(stack, slot, compare)) {
|
||||
if (mode == MODE_WHITELIST) {
|
||||
if (InventoryUtils.compareStack(stack, slot, compare))
|
||||
{
|
||||
if (mode == MODE_WHITELIST)
|
||||
{
|
||||
return true;
|
||||
} else if (mode == MODE_BLACKLIST) {
|
||||
}
|
||||
else if (mode == MODE_BLACKLIST)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == MODE_WHITELIST) {
|
||||
if (mode == MODE_WHITELIST)
|
||||
{
|
||||
return slots == 0;
|
||||
}
|
||||
|
||||
@@ -99,107 +121,131 @@ public class TileImporter extends TileMachine implements IInventory, ISidedInven
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCompare() {
|
||||
public int getCompare()
|
||||
{
|
||||
return compare;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCompare(int compare) {
|
||||
public void setCompare(int compare)
|
||||
{
|
||||
this.compare = compare;
|
||||
}
|
||||
|
||||
public int getMode() {
|
||||
public int getMode()
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
|
||||
public void setMode(int mode) {
|
||||
public void setMode(int mode)
|
||||
{
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return inventory.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
public ItemStack getStackInSlot(int slot)
|
||||
{
|
||||
return inventory.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
public ItemStack decrStackSize(int slot, int amount)
|
||||
{
|
||||
return inventory.decrStackSize(slot, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
public ItemStack getStackInSlotOnClosing(int slot)
|
||||
{
|
||||
return inventory.getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||
{
|
||||
inventory.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
public String getInventoryName()
|
||||
{
|
||||
return inventory.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return inventory.hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return inventory.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
public boolean isUseableByPlayer(EntityPlayer player)
|
||||
{
|
||||
return inventory.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
public void openInventory()
|
||||
{
|
||||
inventory.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
public void closeInventory()
|
||||
{
|
||||
inventory.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack)
|
||||
{
|
||||
return inventory.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return new int[] {};
|
||||
public int[] getAccessibleSlotsFromSide(int side)
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int slot, ItemStack stack, int side) {
|
||||
public boolean canInsertItem(int slot, ItemStack stack, int side)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slot, ItemStack stack, int side) {
|
||||
public boolean canExtractItem(int slot, ItemStack stack, int side)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
if (nbt.hasKey(NBT_COMPARE)) {
|
||||
if (nbt.hasKey(NBT_COMPARE))
|
||||
{
|
||||
compare = nbt.getInteger(NBT_COMPARE);
|
||||
}
|
||||
|
||||
if (nbt.hasKey(NBT_MODE)) {
|
||||
if (nbt.hasKey(NBT_MODE))
|
||||
{
|
||||
mode = nbt.getInteger(NBT_MODE);
|
||||
}
|
||||
|
||||
@@ -207,7 +253,8 @@ public class TileImporter extends TileMachine implements IInventory, ISidedInven
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
nbt.setInteger(NBT_COMPARE, compare);
|
||||
@@ -217,7 +264,8 @@ public class TileImporter extends TileMachine implements IInventory, ISidedInven
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
public void fromBytes(ByteBuf buf)
|
||||
{
|
||||
super.fromBytes(buf);
|
||||
|
||||
compare = buf.readInt();
|
||||
@@ -225,7 +273,8 @@ public class TileImporter extends TileMachine implements IInventory, ISidedInven
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
super.toBytes(buf);
|
||||
|
||||
buf.writeInt(compare);
|
||||
|
||||
@@ -3,7 +3,8 @@ package storagecraft.tile;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public abstract class TileMachine extends TileBase implements INetworkTile, IRedstoneModeSetting {
|
||||
public abstract class TileMachine extends TileBase implements INetworkTile, IRedstoneModeSetting
|
||||
{
|
||||
protected boolean connected = false;
|
||||
protected boolean redstoneControlled = true;
|
||||
|
||||
@@ -13,7 +14,8 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
||||
private int yController;
|
||||
private int zController;
|
||||
|
||||
public void onConnected(TileController controller) {
|
||||
public void onConnected(TileController controller)
|
||||
{
|
||||
this.connected = true;
|
||||
|
||||
this.xController = controller.xCoord;
|
||||
@@ -23,61 +25,74 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
public void onDisconnected() {
|
||||
public void onDisconnected()
|
||||
{
|
||||
this.connected = false;
|
||||
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
if (!worldObj.isRemote && isConnected()) {
|
||||
if (!worldObj.isRemote && isConnected())
|
||||
{
|
||||
updateMachine();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
public boolean isConnected()
|
||||
{
|
||||
return connected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneMode getRedstoneMode() {
|
||||
public RedstoneMode getRedstoneMode()
|
||||
{
|
||||
return redstoneMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRedstoneMode(RedstoneMode mode) {
|
||||
if (redstoneControlled) {
|
||||
public void setRedstoneMode(RedstoneMode mode)
|
||||
{
|
||||
if (redstoneControlled)
|
||||
{
|
||||
this.redstoneMode = mode;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
public int getX()
|
||||
{
|
||||
return xCoord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
public int getY()
|
||||
{
|
||||
return yCoord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
public int getZ()
|
||||
{
|
||||
return zCoord;
|
||||
}
|
||||
|
||||
public TileController getController() {
|
||||
public TileController getController()
|
||||
{
|
||||
return (TileController) worldObj.getTileEntity(xController, yController, zController);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
public void fromBytes(ByteBuf buf)
|
||||
{
|
||||
connected = buf.readBoolean();
|
||||
|
||||
if (connected) {
|
||||
if (connected)
|
||||
{
|
||||
xController = buf.readInt();
|
||||
yController = buf.readInt();
|
||||
zController = buf.readInt();
|
||||
@@ -87,10 +102,12 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
buf.writeBoolean(connected);
|
||||
|
||||
if (connected) {
|
||||
if (connected)
|
||||
{
|
||||
buf.writeInt(xController);
|
||||
buf.writeInt(yController);
|
||||
buf.writeInt(zController);
|
||||
@@ -100,16 +117,19 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
if (nbt.hasKey(RedstoneMode.NBT)) {
|
||||
if (nbt.hasKey(RedstoneMode.NBT))
|
||||
{
|
||||
redstoneMode = RedstoneMode.getById(nbt.getInteger(RedstoneMode.NBT));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
public void writeToNBT(NBTTagCompound nbt)
|
||||
{
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
nbt.setInteger(RedstoneMode.NBT, redstoneMode.id);
|
||||
|
||||
@@ -9,11 +9,14 @@ import storagecraft.storage.IStorageProvider;
|
||||
import storagecraft.storage.StorageItem;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileStorageProxy extends TileMachine implements IStorageProvider, IStorage {
|
||||
public IInventory getInventory() {
|
||||
public class TileStorageProxy extends TileMachine implements IStorageProvider, IStorage
|
||||
{
|
||||
public IInventory getInventory()
|
||||
{
|
||||
TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ);
|
||||
|
||||
if (tile instanceof IInventory) {
|
||||
if (tile instanceof IInventory)
|
||||
{
|
||||
return (IInventory) tile;
|
||||
}
|
||||
|
||||
@@ -21,21 +24,27 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyUsage() {
|
||||
public int getEnergyUsage()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMachine() {
|
||||
public void updateMachine()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItems(List<StorageItem> items) {
|
||||
public void addItems(List<StorageItem> items)
|
||||
{
|
||||
IInventory inventory = getInventory();
|
||||
|
||||
if (inventory != null) {
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
||||
if (inventory.getStackInSlot(i) != null) {
|
||||
if (inventory != null)
|
||||
{
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i)
|
||||
{
|
||||
if (inventory.getStackInSlot(i) != null)
|
||||
{
|
||||
items.add(new StorageItem(inventory.getStackInSlot(i)));
|
||||
}
|
||||
}
|
||||
@@ -43,10 +52,12 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public void push(ItemStack stack) {
|
||||
public void push(ItemStack stack)
|
||||
{
|
||||
IInventory inventory = getInventory();
|
||||
|
||||
if (inventory == null) {
|
||||
if (inventory == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -54,26 +65,32 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack take(ItemStack stack, int flags) {
|
||||
public ItemStack take(ItemStack stack, int flags)
|
||||
{
|
||||
IInventory inventory = getInventory();
|
||||
|
||||
if (inventory == null) {
|
||||
if (inventory == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int quantity = stack.stackSize;
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i)
|
||||
{
|
||||
ItemStack slot = inventory.getStackInSlot(i);
|
||||
|
||||
if (slot != null && InventoryUtils.compareStack(slot, stack, flags)) {
|
||||
if (quantity > slot.stackSize) {
|
||||
if (slot != null && InventoryUtils.compareStack(slot, stack, flags))
|
||||
{
|
||||
if (quantity > slot.stackSize)
|
||||
{
|
||||
quantity = slot.stackSize;
|
||||
}
|
||||
|
||||
slot.stackSize -= quantity;
|
||||
|
||||
if (slot.stackSize == 0) {
|
||||
if (slot.stackSize == 0)
|
||||
{
|
||||
inventory.setInventorySlotContents(i, null);
|
||||
}
|
||||
|
||||
@@ -89,10 +106,12 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPush(ItemStack stack) {
|
||||
public boolean canPush(ItemStack stack)
|
||||
{
|
||||
IInventory inventory = getInventory();
|
||||
|
||||
if (inventory == null) {
|
||||
if (inventory == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -100,7 +119,8 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorages(List<IStorage> storages) {
|
||||
public void addStorages(List<IStorage> storages)
|
||||
{
|
||||
storages.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user