reformat
This commit is contained in:
@@ -14,8 +14,10 @@ import net.minecraft.item.Item;
|
|||||||
import storagecraft.proxy.CommonProxy;
|
import storagecraft.proxy.CommonProxy;
|
||||||
|
|
||||||
@Mod(modid = StorageCraft.ID, version = StorageCraft.VERSION)
|
@Mod(modid = StorageCraft.ID, version = StorageCraft.VERSION)
|
||||||
public class StorageCraft {
|
public class StorageCraft
|
||||||
public static final class GUI {
|
{
|
||||||
|
public static final class GUI
|
||||||
|
{
|
||||||
public static final int CONTROLLER = 0;
|
public static final int CONTROLLER = 0;
|
||||||
public static final int GRID = 1;
|
public static final int GRID = 1;
|
||||||
public static final int DRIVE = 2;
|
public static final int DRIVE = 2;
|
||||||
@@ -28,9 +30,11 @@ public class StorageCraft {
|
|||||||
public static final String ID = "storagecraft";
|
public static final String ID = "storagecraft";
|
||||||
public static final String VERSION = "1.0";
|
public static final String VERSION = "1.0";
|
||||||
public static final SimpleNetworkWrapper NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(ID);
|
public static final SimpleNetworkWrapper NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(ID);
|
||||||
public static final CreativeTabs TAB = new CreativeTabs(ID) {
|
public static final CreativeTabs TAB = new CreativeTabs(ID)
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public Item getTabIconItem() {
|
public Item getTabIconItem()
|
||||||
|
{
|
||||||
return Item.getItemFromBlock(StorageCraftBlocks.CONTROLLER);
|
return Item.getItemFromBlock(StorageCraftBlocks.CONTROLLER);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -40,17 +44,20 @@ public class StorageCraft {
|
|||||||
public static StorageCraft INSTANCE;
|
public static StorageCraft INSTANCE;
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent e) {
|
public void preInit(FMLPreInitializationEvent e)
|
||||||
|
{
|
||||||
PROXY.preInit(e);
|
PROXY.preInit(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void init(FMLInitializationEvent e) {
|
public void init(FMLInitializationEvent e)
|
||||||
|
{
|
||||||
PROXY.init(e);
|
PROXY.init(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void postInit(FMLPostInitializationEvent e) {
|
public void postInit(FMLPostInitializationEvent e)
|
||||||
|
{
|
||||||
PROXY.postInit(e);
|
PROXY.postInit(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,8 @@ import storagecraft.block.BlockGrid;
|
|||||||
import storagecraft.block.BlockImporter;
|
import storagecraft.block.BlockImporter;
|
||||||
import storagecraft.block.BlockStorageProxy;
|
import storagecraft.block.BlockStorageProxy;
|
||||||
|
|
||||||
public class StorageCraftBlocks {
|
public class StorageCraftBlocks
|
||||||
|
{
|
||||||
public static final BlockController CONTROLLER = new BlockController();
|
public static final BlockController CONTROLLER = new BlockController();
|
||||||
public static final BlockCable CABLE = new BlockCable();
|
public static final BlockCable CABLE = new BlockCable();
|
||||||
public static final BlockGrid GRID = new BlockGrid();
|
public static final BlockGrid GRID = new BlockGrid();
|
||||||
|
@@ -2,6 +2,7 @@ package storagecraft;
|
|||||||
|
|
||||||
import storagecraft.item.ItemStorageCell;
|
import storagecraft.item.ItemStorageCell;
|
||||||
|
|
||||||
public class StorageCraftItems {
|
public class StorageCraftItems
|
||||||
|
{
|
||||||
public static final ItemStorageCell STORAGE_CELL = new ItemStorageCell();
|
public static final ItemStorageCell STORAGE_CELL = new ItemStorageCell();
|
||||||
}
|
}
|
||||||
|
@@ -13,10 +13,12 @@ import storagecraft.StorageCraft;
|
|||||||
import storagecraft.tile.TileBase;
|
import storagecraft.tile.TileBase;
|
||||||
import storagecraft.util.InventoryUtils;
|
import storagecraft.util.InventoryUtils;
|
||||||
|
|
||||||
public abstract class BlockBase extends Block {
|
public abstract class BlockBase extends Block
|
||||||
|
{
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public BlockBase(String name) {
|
public BlockBase(String name)
|
||||||
|
{
|
||||||
super(Material.rock);
|
super(Material.rock);
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -26,20 +28,24 @@ public abstract class BlockBase extends Block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUnlocalizedName() {
|
public String getUnlocalizedName()
|
||||||
|
{
|
||||||
return "block." + StorageCraft.ID + ":" + name;
|
return "block." + StorageCraft.ID + ":" + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis) {
|
public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis)
|
||||||
|
{
|
||||||
TileEntity tile = world.getTileEntity(x, y, z);
|
TileEntity tile = world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
if (tile instanceof TileBase) {
|
if (tile instanceof TileBase)
|
||||||
|
{
|
||||||
ForgeDirection dir = ((TileBase) tile).getDirection();
|
ForgeDirection dir = ((TileBase) tile).getDirection();
|
||||||
|
|
||||||
int newDir = dir.ordinal() + 1;
|
int newDir = dir.ordinal() + 1;
|
||||||
|
|
||||||
if (newDir > ForgeDirection.VALID_DIRECTIONS.length - 1) {
|
if (newDir > ForgeDirection.VALID_DIRECTIONS.length - 1)
|
||||||
|
{
|
||||||
newDir = 0;
|
newDir = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,26 +60,31 @@ public abstract class BlockBase extends Block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int damageDropped(int meta) {
|
public int damageDropped(int meta)
|
||||||
|
{
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack) {
|
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack)
|
||||||
|
{
|
||||||
super.onBlockPlacedBy(world, x, y, z, entityLiving, itemStack);
|
super.onBlockPlacedBy(world, x, y, z, entityLiving, itemStack);
|
||||||
|
|
||||||
TileEntity tile = world.getTileEntity(x, y, z);
|
TileEntity tile = world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
if (tile instanceof TileBase) {
|
if (tile instanceof TileBase)
|
||||||
|
{
|
||||||
((TileBase) tile).setDirection(ForgeDirection.getOrientation(BlockPistonBase.determineOrientation(world, x, y, z, entityLiving)));
|
((TileBase) tile).setDirection(ForgeDirection.getOrientation(BlockPistonBase.determineOrientation(world, x, y, z, entityLiving)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockPreDestroy(World world, int x, int y, int z, int meta) {
|
public void onBlockPreDestroy(World world, int x, int y, int z, int meta)
|
||||||
|
{
|
||||||
TileEntity tile = world.getTileEntity(x, y, z);
|
TileEntity tile = world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
if (tile instanceof IInventory) {
|
if (tile instanceof IInventory)
|
||||||
|
{
|
||||||
InventoryUtils.dropInventory(world, (IInventory) tile, x, y, z);
|
InventoryUtils.dropInventory(world, (IInventory) tile, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,35 +9,43 @@ import net.minecraft.tileentity.TileEntity;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import storagecraft.tile.TileCable;
|
import storagecraft.tile.TileCable;
|
||||||
|
|
||||||
public class BlockCable extends BlockBase implements ITileEntityProvider {
|
public class BlockCable extends BlockBase implements ITileEntityProvider
|
||||||
public BlockCable() {
|
{
|
||||||
|
public BlockCable()
|
||||||
|
{
|
||||||
super("cable");
|
super("cable");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world, int meta) {
|
public TileEntity createNewTileEntity(World world, int meta)
|
||||||
|
{
|
||||||
return new TileCable();
|
return new TileCable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getSubBlocks(Item item, CreativeTabs tab, List subItems) {
|
public void getSubBlocks(Item item, CreativeTabs tab, List subItems)
|
||||||
for (int i = 0; i < 2; i++) {
|
{
|
||||||
|
for (int i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
subItems.add(new ItemStack(item, 1, i));
|
subItems.add(new ItemStack(item, 1, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRenderType() {
|
public int getRenderType()
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOpaqueCube() {
|
public boolean isOpaqueCube()
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean renderAsNormalBlock() {
|
public boolean renderAsNormalBlock()
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,22 +10,27 @@ import net.minecraft.world.World;
|
|||||||
import storagecraft.StorageCraft;
|
import storagecraft.StorageCraft;
|
||||||
import storagecraft.tile.TileController;
|
import storagecraft.tile.TileController;
|
||||||
|
|
||||||
public class BlockController extends BlockBase implements ITileEntityProvider {
|
public class BlockController extends BlockBase implements ITileEntityProvider
|
||||||
|
{
|
||||||
private IIcon sideIcon;
|
private IIcon sideIcon;
|
||||||
private IIcon[] icons = new IIcon[6];
|
private IIcon[] icons = new IIcon[6];
|
||||||
|
|
||||||
public BlockController() {
|
public BlockController()
|
||||||
|
{
|
||||||
super("controller");
|
super("controller");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world, int meta) {
|
public TileEntity createNewTileEntity(World world, int meta)
|
||||||
|
{
|
||||||
return new TileController();
|
return new TileController();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
|
||||||
if (!world.isRemote) {
|
{
|
||||||
|
if (!world.isRemote)
|
||||||
|
{
|
||||||
player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.CONTROLLER, world, x, y, z);
|
player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.CONTROLLER, world, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,15 +38,18 @@ public class BlockController extends BlockBase implements ITileEntityProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockPreDestroy(World world, int x, int y, int z, int meta) {
|
public void onBlockPreDestroy(World world, int x, int y, int z, int meta)
|
||||||
|
{
|
||||||
((TileController) world.getTileEntity(x, y, z)).onDestroyed();
|
((TileController) world.getTileEntity(x, y, z)).onDestroyed();
|
||||||
|
|
||||||
super.onBlockPreDestroy(world, x, y, z, meta);
|
super.onBlockPreDestroy(world, x, y, z, meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerBlockIcons(IIconRegister register) {
|
public void registerBlockIcons(IIconRegister register)
|
||||||
for (int i = 0; i <= 5; ++i) {
|
{
|
||||||
|
for (int i = 0; i <= 5; ++i)
|
||||||
|
{
|
||||||
icons[i] = register.registerIcon("storagecraft:controller" + i);
|
icons[i] = register.registerIcon("storagecraft:controller" + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,8 +57,10 @@ public class BlockController extends BlockBase implements ITileEntityProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)
|
||||||
if (side == 0 || side == 1) {
|
{
|
||||||
|
if (side == 0 || side == 1)
|
||||||
|
{
|
||||||
return sideIcon;
|
return sideIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,8 +70,10 @@ public class BlockController extends BlockBase implements ITileEntityProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIcon(int side, int meta) {
|
public IIcon getIcon(int side, int meta)
|
||||||
if (side == 0 || side == 1) {
|
{
|
||||||
|
if (side == 0 || side == 1)
|
||||||
|
{
|
||||||
return sideIcon;
|
return sideIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,17 +10,21 @@ import net.minecraft.world.World;
|
|||||||
import storagecraft.StorageCraft;
|
import storagecraft.StorageCraft;
|
||||||
import storagecraft.tile.TileDetector;
|
import storagecraft.tile.TileDetector;
|
||||||
|
|
||||||
public class BlockDetector extends BlockBase implements ITileEntityProvider {
|
public class BlockDetector extends BlockBase implements ITileEntityProvider
|
||||||
|
{
|
||||||
private IIcon frontIcon;
|
private IIcon frontIcon;
|
||||||
private IIcon sideIcon;
|
private IIcon sideIcon;
|
||||||
|
|
||||||
public BlockDetector() {
|
public BlockDetector()
|
||||||
|
{
|
||||||
super("detector");
|
super("detector");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
|
||||||
if (!world.isRemote) {
|
{
|
||||||
|
if (!world.isRemote)
|
||||||
|
{
|
||||||
player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.DETECTOR, world, x, y, z);
|
player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.DETECTOR, world, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,38 +32,45 @@ public class BlockDetector extends BlockBase implements ITileEntityProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world, int meta) {
|
public TileEntity createNewTileEntity(World world, int meta)
|
||||||
|
{
|
||||||
return new TileDetector();
|
return new TileDetector();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side) {
|
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side)
|
||||||
|
{
|
||||||
return isProvidingStrongPower(world, x, y, z, side);
|
return isProvidingStrongPower(world, x, y, z, side);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int side) {
|
public int isProvidingStrongPower(IBlockAccess world, int x, int y, int z, int side)
|
||||||
|
{
|
||||||
TileDetector detector = (TileDetector) world.getTileEntity(x, y, z);
|
TileDetector detector = (TileDetector) world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
return detector.providesPower() ? 15 : 0;
|
return detector.providesPower() ? 15 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canProvidePower() {
|
public boolean canProvidePower()
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerBlockIcons(IIconRegister register) {
|
public void registerBlockIcons(IIconRegister register)
|
||||||
|
{
|
||||||
frontIcon = register.registerIcon("storagecraft:detector");
|
frontIcon = register.registerIcon("storagecraft:detector");
|
||||||
sideIcon = register.registerIcon("storagecraft:generic");
|
sideIcon = register.registerIcon("storagecraft:generic");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)
|
||||||
|
{
|
||||||
TileDetector tile = (TileDetector) world.getTileEntity(x, y, z);
|
TileDetector tile = (TileDetector) world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
if (side == tile.getDirection().ordinal()) {
|
if (side == tile.getDirection().ordinal())
|
||||||
|
{
|
||||||
return frontIcon;
|
return frontIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,8 +78,10 @@ public class BlockDetector extends BlockBase implements ITileEntityProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIcon(int side, int meta) {
|
public IIcon getIcon(int side, int meta)
|
||||||
if (side == 3) {
|
{
|
||||||
|
if (side == 3)
|
||||||
|
{
|
||||||
return frontIcon;
|
return frontIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,17 +10,21 @@ import net.minecraft.world.World;
|
|||||||
import storagecraft.StorageCraft;
|
import storagecraft.StorageCraft;
|
||||||
import storagecraft.tile.TileDrive;
|
import storagecraft.tile.TileDrive;
|
||||||
|
|
||||||
public class BlockDrive extends BlockBase implements ITileEntityProvider {
|
public class BlockDrive extends BlockBase implements ITileEntityProvider
|
||||||
|
{
|
||||||
private IIcon frontIcon;
|
private IIcon frontIcon;
|
||||||
private IIcon sideIcon;
|
private IIcon sideIcon;
|
||||||
|
|
||||||
public BlockDrive() {
|
public BlockDrive()
|
||||||
|
{
|
||||||
super("drive");
|
super("drive");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
|
||||||
if (!world.isRemote) {
|
{
|
||||||
|
if (!world.isRemote)
|
||||||
|
{
|
||||||
player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.DRIVE, world, x, y, z);
|
player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.DRIVE, world, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,21 +32,25 @@ public class BlockDrive extends BlockBase implements ITileEntityProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world, int meta) {
|
public TileEntity createNewTileEntity(World world, int meta)
|
||||||
|
{
|
||||||
return new TileDrive();
|
return new TileDrive();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerBlockIcons(IIconRegister register) {
|
public void registerBlockIcons(IIconRegister register)
|
||||||
|
{
|
||||||
frontIcon = register.registerIcon("storagecraft:drive");
|
frontIcon = register.registerIcon("storagecraft:drive");
|
||||||
sideIcon = register.registerIcon("storagecraft:generic");
|
sideIcon = register.registerIcon("storagecraft:generic");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)
|
||||||
|
{
|
||||||
TileDrive tile = (TileDrive) world.getTileEntity(x, y, z);
|
TileDrive tile = (TileDrive) world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
if (side == tile.getDirection().ordinal()) {
|
if (side == tile.getDirection().ordinal())
|
||||||
|
{
|
||||||
return frontIcon;
|
return frontIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,8 +58,10 @@ public class BlockDrive extends BlockBase implements ITileEntityProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIcon(int side, int meta) {
|
public IIcon getIcon(int side, int meta)
|
||||||
if (side == 3) {
|
{
|
||||||
|
if (side == 3)
|
||||||
|
{
|
||||||
return frontIcon;
|
return frontIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,22 +10,27 @@ import net.minecraft.world.World;
|
|||||||
import storagecraft.StorageCraft;
|
import storagecraft.StorageCraft;
|
||||||
import storagecraft.tile.TileExporter;
|
import storagecraft.tile.TileExporter;
|
||||||
|
|
||||||
public class BlockExporter extends BlockBase implements ITileEntityProvider {
|
public class BlockExporter extends BlockBase implements ITileEntityProvider
|
||||||
|
{
|
||||||
private IIcon frontIcon;
|
private IIcon frontIcon;
|
||||||
private IIcon sideIcon;
|
private IIcon sideIcon;
|
||||||
|
|
||||||
public BlockExporter() {
|
public BlockExporter()
|
||||||
|
{
|
||||||
super("exporter");
|
super("exporter");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world, int meta) {
|
public TileEntity createNewTileEntity(World world, int meta)
|
||||||
|
{
|
||||||
return new TileExporter();
|
return new TileExporter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
|
||||||
if (!world.isRemote) {
|
{
|
||||||
|
if (!world.isRemote)
|
||||||
|
{
|
||||||
player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.EXPORTER, world, x, y, z);
|
player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.EXPORTER, world, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,16 +38,19 @@ public class BlockExporter extends BlockBase implements ITileEntityProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerBlockIcons(IIconRegister register) {
|
public void registerBlockIcons(IIconRegister register)
|
||||||
|
{
|
||||||
frontIcon = register.registerIcon("storagecraft:exporter");
|
frontIcon = register.registerIcon("storagecraft:exporter");
|
||||||
sideIcon = register.registerIcon("storagecraft:generic");
|
sideIcon = register.registerIcon("storagecraft:generic");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)
|
||||||
|
{
|
||||||
TileExporter tile = (TileExporter) world.getTileEntity(x, y, z);
|
TileExporter tile = (TileExporter) world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
if (side == tile.getDirection().ordinal()) {
|
if (side == tile.getDirection().ordinal())
|
||||||
|
{
|
||||||
return frontIcon;
|
return frontIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,8 +58,10 @@ public class BlockExporter extends BlockBase implements ITileEntityProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIcon(int side, int meta) {
|
public IIcon getIcon(int side, int meta)
|
||||||
if (side == 3) {
|
{
|
||||||
|
if (side == 3)
|
||||||
|
{
|
||||||
return frontIcon;
|
return frontIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,23 +10,28 @@ import net.minecraft.world.World;
|
|||||||
import storagecraft.StorageCraft;
|
import storagecraft.StorageCraft;
|
||||||
import storagecraft.tile.TileGrid;
|
import storagecraft.tile.TileGrid;
|
||||||
|
|
||||||
public class BlockGrid extends BlockBase implements ITileEntityProvider {
|
public class BlockGrid extends BlockBase implements ITileEntityProvider
|
||||||
|
{
|
||||||
private IIcon sideIcon;
|
private IIcon sideIcon;
|
||||||
private IIcon connectedIcon;
|
private IIcon connectedIcon;
|
||||||
private IIcon disconnectedIcon;
|
private IIcon disconnectedIcon;
|
||||||
|
|
||||||
public BlockGrid() {
|
public BlockGrid()
|
||||||
|
{
|
||||||
super("grid");
|
super("grid");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world, int meta) {
|
public TileEntity createNewTileEntity(World world, int meta)
|
||||||
|
{
|
||||||
return new TileGrid();
|
return new TileGrid();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
|
||||||
if (!world.isRemote) {
|
{
|
||||||
|
if (!world.isRemote)
|
||||||
|
{
|
||||||
player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.GRID, world, x, y, z);
|
player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.GRID, world, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,17 +39,20 @@ public class BlockGrid extends BlockBase implements ITileEntityProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerBlockIcons(IIconRegister register) {
|
public void registerBlockIcons(IIconRegister register)
|
||||||
|
{
|
||||||
connectedIcon = register.registerIcon("storagecraft:gridConnected");
|
connectedIcon = register.registerIcon("storagecraft:gridConnected");
|
||||||
disconnectedIcon = register.registerIcon("storagecraft:gridDisconnected");
|
disconnectedIcon = register.registerIcon("storagecraft:gridDisconnected");
|
||||||
sideIcon = register.registerIcon("storagecraft:generic");
|
sideIcon = register.registerIcon("storagecraft:generic");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)
|
||||||
|
{
|
||||||
TileGrid tile = (TileGrid) world.getTileEntity(x, y, z);
|
TileGrid tile = (TileGrid) world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
if (side == tile.getDirection().ordinal()) {
|
if (side == tile.getDirection().ordinal())
|
||||||
|
{
|
||||||
return tile.isConnected() ? connectedIcon : disconnectedIcon;
|
return tile.isConnected() ? connectedIcon : disconnectedIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,8 +60,10 @@ public class BlockGrid extends BlockBase implements ITileEntityProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIcon(int side, int damage) {
|
public IIcon getIcon(int side, int damage)
|
||||||
if (side == 3) {
|
{
|
||||||
|
if (side == 3)
|
||||||
|
{
|
||||||
return disconnectedIcon;
|
return disconnectedIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,22 +10,27 @@ import net.minecraft.world.World;
|
|||||||
import storagecraft.StorageCraft;
|
import storagecraft.StorageCraft;
|
||||||
import storagecraft.tile.TileImporter;
|
import storagecraft.tile.TileImporter;
|
||||||
|
|
||||||
public class BlockImporter extends BlockBase implements ITileEntityProvider {
|
public class BlockImporter extends BlockBase implements ITileEntityProvider
|
||||||
|
{
|
||||||
private IIcon frontIcon;
|
private IIcon frontIcon;
|
||||||
private IIcon sideIcon;
|
private IIcon sideIcon;
|
||||||
|
|
||||||
public BlockImporter() {
|
public BlockImporter()
|
||||||
|
{
|
||||||
super("importer");
|
super("importer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world, int meta) {
|
public TileEntity createNewTileEntity(World world, int meta)
|
||||||
|
{
|
||||||
return new TileImporter();
|
return new TileImporter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
|
||||||
if (!world.isRemote) {
|
{
|
||||||
|
if (!world.isRemote)
|
||||||
|
{
|
||||||
player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.IMPORTER, world, x, y, z);
|
player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.IMPORTER, world, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,16 +38,19 @@ public class BlockImporter extends BlockBase implements ITileEntityProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerBlockIcons(IIconRegister register) {
|
public void registerBlockIcons(IIconRegister register)
|
||||||
|
{
|
||||||
frontIcon = register.registerIcon("storagecraft:importer");
|
frontIcon = register.registerIcon("storagecraft:importer");
|
||||||
sideIcon = register.registerIcon("storagecraft:generic");
|
sideIcon = register.registerIcon("storagecraft:generic");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)
|
||||||
|
{
|
||||||
TileImporter tile = (TileImporter) world.getTileEntity(x, y, z);
|
TileImporter tile = (TileImporter) world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
if (side == tile.getDirection().ordinal()) {
|
if (side == tile.getDirection().ordinal())
|
||||||
|
{
|
||||||
return frontIcon;
|
return frontIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,8 +58,10 @@ public class BlockImporter extends BlockBase implements ITileEntityProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIcon(int side, int meta) {
|
public IIcon getIcon(int side, int meta)
|
||||||
if (side == 3) {
|
{
|
||||||
|
if (side == 3)
|
||||||
|
{
|
||||||
return frontIcon;
|
return frontIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,22 +10,27 @@ import net.minecraft.world.World;
|
|||||||
import storagecraft.StorageCraft;
|
import storagecraft.StorageCraft;
|
||||||
import storagecraft.tile.TileStorageProxy;
|
import storagecraft.tile.TileStorageProxy;
|
||||||
|
|
||||||
public class BlockStorageProxy extends BlockBase implements ITileEntityProvider {
|
public class BlockStorageProxy extends BlockBase implements ITileEntityProvider
|
||||||
|
{
|
||||||
private IIcon frontIcon;
|
private IIcon frontIcon;
|
||||||
private IIcon sideIcon;
|
private IIcon sideIcon;
|
||||||
|
|
||||||
public BlockStorageProxy() {
|
public BlockStorageProxy()
|
||||||
|
{
|
||||||
super("storageProxy");
|
super("storageProxy");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World world, int meta) {
|
public TileEntity createNewTileEntity(World world, int meta)
|
||||||
|
{
|
||||||
return new TileStorageProxy();
|
return new TileStorageProxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
|
||||||
if (!world.isRemote) {
|
{
|
||||||
|
if (!world.isRemote)
|
||||||
|
{
|
||||||
player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.STORAGE_PROXY, world, x, y, z);
|
player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.STORAGE_PROXY, world, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,16 +38,19 @@ public class BlockStorageProxy extends BlockBase implements ITileEntityProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerBlockIcons(IIconRegister register) {
|
public void registerBlockIcons(IIconRegister register)
|
||||||
|
{
|
||||||
frontIcon = register.registerIcon("storagecraft:storageProxy");
|
frontIcon = register.registerIcon("storagecraft:storageProxy");
|
||||||
sideIcon = register.registerIcon("storagecraft:generic");
|
sideIcon = register.registerIcon("storagecraft:generic");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side)
|
||||||
|
{
|
||||||
TileStorageProxy tile = (TileStorageProxy) world.getTileEntity(x, y, z);
|
TileStorageProxy tile = (TileStorageProxy) world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
if (side == tile.getDirection().ordinal()) {
|
if (side == tile.getDirection().ordinal())
|
||||||
|
{
|
||||||
return frontIcon;
|
return frontIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,8 +58,10 @@ public class BlockStorageProxy extends BlockBase implements ITileEntityProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIcon(int side, int meta) {
|
public IIcon getIcon(int side, int meta)
|
||||||
if (side == 3) {
|
{
|
||||||
|
if (side == 3)
|
||||||
|
{
|
||||||
return frontIcon;
|
return frontIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,28 +6,35 @@ import net.minecraft.inventory.Slot;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import storagecraft.container.slot.SlotSpecimen;
|
import storagecraft.container.slot.SlotSpecimen;
|
||||||
|
|
||||||
public abstract class ContainerBase extends Container {
|
public abstract class ContainerBase extends Container
|
||||||
|
{
|
||||||
private EntityPlayer player;
|
private EntityPlayer player;
|
||||||
|
|
||||||
public ContainerBase(EntityPlayer player) {
|
public ContainerBase(EntityPlayer player)
|
||||||
|
{
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityPlayer getPlayer() {
|
public EntityPlayer getPlayer()
|
||||||
|
{
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addPlayerInventory(int xInventory, int yInventory) {
|
protected void addPlayerInventory(int xInventory, int yInventory)
|
||||||
|
{
|
||||||
int id = 0;
|
int id = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++)
|
||||||
|
{
|
||||||
addSlotToContainer(new Slot(player.inventory, id, xInventory + i * 18, yInventory + 4 + (3 * 18)));
|
addSlotToContainer(new Slot(player.inventory, id, xInventory + i * 18, yInventory + 4 + (3 * 18)));
|
||||||
|
|
||||||
id++;
|
id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int y = 0; y < 3; y++) {
|
for (int y = 0; y < 3; y++)
|
||||||
for (int x = 0; x < 9; x++) {
|
{
|
||||||
|
for (int x = 0; x < 9; x++)
|
||||||
|
{
|
||||||
addSlotToContainer(new Slot(player.inventory, id, xInventory + x * 18, yInventory + y * 18));
|
addSlotToContainer(new Slot(player.inventory, id, xInventory + x * 18, yInventory + y * 18));
|
||||||
|
|
||||||
id++;
|
id++;
|
||||||
@@ -36,13 +43,18 @@ public abstract class ContainerBase extends Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack slotClick(int id, int clickedButton, int mode, EntityPlayer player) {
|
public ItemStack slotClick(int id, int clickedButton, int mode, EntityPlayer player)
|
||||||
|
{
|
||||||
Slot slot = id >= 0 ? getSlot(id) : null;
|
Slot slot = id >= 0 ? getSlot(id) : null;
|
||||||
|
|
||||||
if (slot instanceof SlotSpecimen) {
|
if (slot instanceof SlotSpecimen)
|
||||||
if (clickedButton == 2) {
|
{
|
||||||
|
if (clickedButton == 2)
|
||||||
|
{
|
||||||
slot.putStack(null);
|
slot.putStack(null);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
slot.putStack(player.inventory.getItemStack() == null ? null : player.inventory.getItemStack().copy());
|
slot.putStack(player.inventory.getItemStack() == null ? null : player.inventory.getItemStack().copy());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,12 +65,14 @@ public abstract class ContainerBase extends Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
|
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInteractWith(EntityPlayer player) {
|
public boolean canInteractWith(EntityPlayer player)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,8 +2,10 @@ package storagecraft.container;
|
|||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
|
||||||
public class ContainerController extends ContainerBase {
|
public class ContainerController extends ContainerBase
|
||||||
public ContainerController(EntityPlayer player) {
|
{
|
||||||
|
public ContainerController(EntityPlayer player)
|
||||||
|
{
|
||||||
super(player);
|
super(player);
|
||||||
|
|
||||||
addPlayerInventory(8, 108);
|
addPlayerInventory(8, 108);
|
||||||
|
@@ -4,8 +4,10 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||||||
import storagecraft.container.slot.SlotSpecimen;
|
import storagecraft.container.slot.SlotSpecimen;
|
||||||
import storagecraft.tile.TileDetector;
|
import storagecraft.tile.TileDetector;
|
||||||
|
|
||||||
public class ContainerDetector extends ContainerBase {
|
public class ContainerDetector extends ContainerBase
|
||||||
public ContainerDetector(EntityPlayer player, TileDetector detector) {
|
{
|
||||||
|
public ContainerDetector(EntityPlayer player, TileDetector detector)
|
||||||
|
{
|
||||||
super(player);
|
super(player);
|
||||||
|
|
||||||
addSlotToContainer(new SlotSpecimen(detector, 0, 107, 20));
|
addSlotToContainer(new SlotSpecimen(detector, 0, 107, 20));
|
||||||
|
@@ -5,8 +5,10 @@ import storagecraft.StorageCraftItems;
|
|||||||
import storagecraft.container.slot.SlotItemFilter;
|
import storagecraft.container.slot.SlotItemFilter;
|
||||||
import storagecraft.tile.TileDrive;
|
import storagecraft.tile.TileDrive;
|
||||||
|
|
||||||
public class ContainerDrive extends ContainerBase {
|
public class ContainerDrive extends ContainerBase
|
||||||
public ContainerDrive(EntityPlayer player, TileDrive drive) {
|
{
|
||||||
|
public ContainerDrive(EntityPlayer player, TileDrive drive)
|
||||||
|
{
|
||||||
super(player);
|
super(player);
|
||||||
|
|
||||||
addPlayerInventory(8, 108);
|
addPlayerInventory(8, 108);
|
||||||
@@ -14,13 +16,17 @@ public class ContainerDrive extends ContainerBase {
|
|||||||
int x = 71;
|
int x = 71;
|
||||||
int y = 20;
|
int y = 20;
|
||||||
|
|
||||||
for (int i = 0; i < 8; ++i) {
|
for (int i = 0; i < 8; ++i)
|
||||||
|
{
|
||||||
addSlotToContainer(new SlotItemFilter(drive, i, x, y, StorageCraftItems.STORAGE_CELL));
|
addSlotToContainer(new SlotItemFilter(drive, i, x, y, StorageCraftItems.STORAGE_CELL));
|
||||||
|
|
||||||
if ((i + 1) % 2 == 0) {
|
if ((i + 1) % 2 == 0)
|
||||||
|
{
|
||||||
x = 71;
|
x = 71;
|
||||||
y += 18;
|
y += 18;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
x += 18;
|
x += 18;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,11 +4,14 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||||||
import storagecraft.container.slot.SlotSpecimen;
|
import storagecraft.container.slot.SlotSpecimen;
|
||||||
import storagecraft.tile.TileExporter;
|
import storagecraft.tile.TileExporter;
|
||||||
|
|
||||||
public class ContainerExporter extends ContainerBase {
|
public class ContainerExporter extends ContainerBase
|
||||||
public ContainerExporter(EntityPlayer player, TileExporter exporter) {
|
{
|
||||||
|
public ContainerExporter(EntityPlayer player, TileExporter exporter)
|
||||||
|
{
|
||||||
super(player);
|
super(player);
|
||||||
|
|
||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i)
|
||||||
|
{
|
||||||
addSlotToContainer(new SlotSpecimen(exporter, i, 8 + (18 * i), 20));
|
addSlotToContainer(new SlotSpecimen(exporter, i, 8 + (18 * i), 20));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,8 +2,10 @@ package storagecraft.container;
|
|||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
|
||||||
public class ContainerGrid extends ContainerBase {
|
public class ContainerGrid extends ContainerBase
|
||||||
public ContainerGrid(EntityPlayer player) {
|
{
|
||||||
|
public ContainerGrid(EntityPlayer player)
|
||||||
|
{
|
||||||
super(player);
|
super(player);
|
||||||
|
|
||||||
addPlayerInventory(8, 108);
|
addPlayerInventory(8, 108);
|
||||||
|
@@ -4,11 +4,14 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||||||
import storagecraft.container.slot.SlotSpecimen;
|
import storagecraft.container.slot.SlotSpecimen;
|
||||||
import storagecraft.tile.TileImporter;
|
import storagecraft.tile.TileImporter;
|
||||||
|
|
||||||
public class ContainerImporter extends ContainerBase {
|
public class ContainerImporter extends ContainerBase
|
||||||
public ContainerImporter(EntityPlayer player, TileImporter importer) {
|
{
|
||||||
|
public ContainerImporter(EntityPlayer player, TileImporter importer)
|
||||||
|
{
|
||||||
super(player);
|
super(player);
|
||||||
|
|
||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i)
|
||||||
|
{
|
||||||
addSlotToContainer(new SlotSpecimen(importer, i, 8 + (18 * i), 20));
|
addSlotToContainer(new SlotSpecimen(importer, i, 8 + (18 * i), 20));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,8 +2,10 @@ package storagecraft.container;
|
|||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
|
||||||
public class ContainerStorageProxy extends ContainerBase {
|
public class ContainerStorageProxy extends ContainerBase
|
||||||
public ContainerStorageProxy(EntityPlayer player) {
|
{
|
||||||
|
public ContainerStorageProxy(EntityPlayer player)
|
||||||
|
{
|
||||||
super(player);
|
super(player);
|
||||||
|
|
||||||
addPlayerInventory(8, 50);
|
addPlayerInventory(8, 50);
|
||||||
|
@@ -5,17 +5,20 @@ import net.minecraft.inventory.Slot;
|
|||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public class SlotItemFilter extends Slot {
|
public class SlotItemFilter extends Slot
|
||||||
|
{
|
||||||
private Item item;
|
private Item item;
|
||||||
|
|
||||||
public SlotItemFilter(IInventory inventory, int id, int x, int y, Item item) {
|
public SlotItemFilter(IInventory inventory, int id, int x, int y, Item item)
|
||||||
|
{
|
||||||
super(inventory, id, x, y);
|
super(inventory, id, x, y);
|
||||||
|
|
||||||
this.item = item;
|
this.item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValid(ItemStack item) {
|
public boolean isItemValid(ItemStack item)
|
||||||
|
{
|
||||||
return item.getItem() == this.item;
|
return item.getItem() == this.item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,24 +5,30 @@ import net.minecraft.inventory.IInventory;
|
|||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public class SlotSpecimen extends Slot {
|
public class SlotSpecimen extends Slot
|
||||||
public SlotSpecimen(IInventory inventory, int id, int x, int y) {
|
{
|
||||||
|
public SlotSpecimen(IInventory inventory, int id, int x, int y)
|
||||||
|
{
|
||||||
super(inventory, id, x, y);
|
super(inventory, id, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canTakeStack(EntityPlayer player) {
|
public boolean canTakeStack(EntityPlayer player)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValid(ItemStack stack) {
|
public boolean isItemValid(ItemStack stack)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putStack(ItemStack stack) {
|
public void putStack(ItemStack stack)
|
||||||
if (stack != null) {
|
{
|
||||||
|
if (stack != null)
|
||||||
|
{
|
||||||
stack.stackSize = 1;
|
stack.stackSize = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,7 +16,8 @@ import org.lwjgl.opengl.GL12;
|
|||||||
import storagecraft.StorageCraft;
|
import storagecraft.StorageCraft;
|
||||||
import storagecraft.gui.sidebutton.SideButton;
|
import storagecraft.gui.sidebutton.SideButton;
|
||||||
|
|
||||||
public abstract class GuiBase extends GuiContainer {
|
public abstract class GuiBase extends GuiContainer
|
||||||
|
{
|
||||||
public static final int SIDE_BUTTON_WIDTH = 20;
|
public static final int SIDE_BUTTON_WIDTH = 20;
|
||||||
public static final int SIDE_BUTTON_HEIGHT = 20;
|
public static final int SIDE_BUTTON_HEIGHT = 20;
|
||||||
|
|
||||||
@@ -25,7 +26,8 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
private int lastButtonId = 0;
|
private int lastButtonId = 0;
|
||||||
private int lastSideButtonY = 6;
|
private int lastSideButtonY = 6;
|
||||||
|
|
||||||
public GuiBase(Container container, int w, int h) {
|
public GuiBase(Container container, int w, int h)
|
||||||
|
{
|
||||||
super(container);
|
super(container);
|
||||||
|
|
||||||
this.xSize = w;
|
this.xSize = w;
|
||||||
@@ -33,37 +35,43 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initGui() {
|
public void initGui()
|
||||||
|
{
|
||||||
super.initGui();
|
super.initGui();
|
||||||
|
|
||||||
init(guiLeft, guiTop);
|
init(guiLeft, guiTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateScreen() {
|
public void updateScreen()
|
||||||
|
{
|
||||||
super.updateScreen();
|
super.updateScreen();
|
||||||
|
|
||||||
update(guiLeft, guiTop);
|
update(guiLeft, guiTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) {
|
protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY)
|
||||||
|
{
|
||||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
|
||||||
drawBackground(guiLeft, guiTop, mouseX, mouseY);
|
drawBackground(guiLeft, guiTop, mouseX, mouseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
|
||||||
|
{
|
||||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||||
|
|
||||||
mouseX -= guiLeft;
|
mouseX -= guiLeft;
|
||||||
mouseY -= guiTop;
|
mouseY -= guiTop;
|
||||||
|
|
||||||
for (SideButton sideButton : sideButtons) {
|
for (SideButton sideButton : sideButtons)
|
||||||
|
{
|
||||||
sideButton.draw(this, sideButton.getX() + 2, sideButton.getY() + 1);
|
sideButton.draw(this, sideButton.getX() + 2, sideButton.getY() + 1);
|
||||||
|
|
||||||
if (inBounds(sideButton.getX(), sideButton.getY(), SIDE_BUTTON_WIDTH, SIDE_BUTTON_HEIGHT, mouseX, mouseY)) {
|
if (inBounds(sideButton.getX(), sideButton.getY(), SIDE_BUTTON_WIDTH, SIDE_BUTTON_HEIGHT, mouseX, mouseY))
|
||||||
|
{
|
||||||
drawTooltip(mouseX, mouseY, sideButton.getTooltip(this));
|
drawTooltip(mouseX, mouseY, sideButton.getTooltip(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,21 +80,26 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void actionPerformed(GuiButton button) {
|
protected void actionPerformed(GuiButton button)
|
||||||
|
{
|
||||||
super.actionPerformed(button);
|
super.actionPerformed(button);
|
||||||
|
|
||||||
for (SideButton sideButton : sideButtons) {
|
for (SideButton sideButton : sideButtons)
|
||||||
if (sideButton.getId() == button.id) {
|
{
|
||||||
|
if (sideButton.getId() == button.id)
|
||||||
|
{
|
||||||
sideButton.actionPerformed();
|
sideButton.actionPerformed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiButton addButton(int x, int y, int w, int h) {
|
public GuiButton addButton(int x, int y, int w, int h)
|
||||||
|
{
|
||||||
return addButton(x, y, w, h, "");
|
return addButton(x, y, w, h, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiButton addButton(int x, int y, int w, int h, String text) {
|
public GuiButton addButton(int x, int y, int w, int h, String text)
|
||||||
|
{
|
||||||
GuiButton button = new GuiButton(lastButtonId++, x, y, w, h, text);
|
GuiButton button = new GuiButton(lastButtonId++, x, y, w, h, text);
|
||||||
|
|
||||||
buttonList.add(button);
|
buttonList.add(button);
|
||||||
@@ -94,7 +107,8 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSideButton(SideButton button) {
|
public void addSideButton(SideButton button)
|
||||||
|
{
|
||||||
button.setX(xSize - 1);
|
button.setX(xSize - 1);
|
||||||
button.setY(lastSideButtonY);
|
button.setY(lastSideButtonY);
|
||||||
button.setId(addButton(guiLeft + button.getX(), guiTop + button.getY(), SIDE_BUTTON_WIDTH, SIDE_BUTTON_HEIGHT).id);
|
button.setId(addButton(guiLeft + button.getX(), guiTop + button.getY(), SIDE_BUTTON_WIDTH, SIDE_BUTTON_HEIGHT).id);
|
||||||
@@ -104,23 +118,28 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
sideButtons.add(button);
|
sideButtons.add(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean inBounds(int x, int y, int w, int h, int ox, int oy) {
|
public boolean inBounds(int x, int y, int w, int h, int ox, int oy)
|
||||||
|
{
|
||||||
return ox >= x && ox <= x + w && oy >= y && oy <= y + h;
|
return ox >= x && ox <= x + w && oy >= y && oy <= y + h;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bindTexture(String file) {
|
public void bindTexture(String file)
|
||||||
|
{
|
||||||
bindTexture(StorageCraft.ID, file);
|
bindTexture(StorageCraft.ID, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bindTexture(String base, String file) {
|
public void bindTexture(String base, String file)
|
||||||
|
{
|
||||||
mc.getTextureManager().bindTexture(new ResourceLocation(base, "textures/" + file));
|
mc.getTextureManager().bindTexture(new ResourceLocation(base, "textures/" + file));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawItem(int x, int y, ItemStack stack) {
|
public void drawItem(int x, int y, ItemStack stack)
|
||||||
|
{
|
||||||
drawItem(x, y, stack, false);
|
drawItem(x, y, stack, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawItem(int x, int y, ItemStack stack, boolean withOverlay) {
|
public void drawItem(int x, int y, ItemStack stack, boolean withOverlay)
|
||||||
|
{
|
||||||
zLevel = 100;
|
zLevel = 100;
|
||||||
itemRender.zLevel = 100;
|
itemRender.zLevel = 100;
|
||||||
|
|
||||||
@@ -134,7 +153,8 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
|
|
||||||
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, stack, x, y);
|
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, stack, x, y);
|
||||||
|
|
||||||
if (withOverlay) {
|
if (withOverlay)
|
||||||
|
{
|
||||||
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, stack, x, y);
|
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, stack, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,16 +164,19 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
zLevel = 0;
|
zLevel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawString(int x, int y, String message) {
|
public void drawString(int x, int y, String message)
|
||||||
|
{
|
||||||
drawString(x, y, message, 4210752);
|
drawString(x, y, message, 4210752);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawString(int x, int y, String message, int color) {
|
public void drawString(int x, int y, String message, int color)
|
||||||
|
{
|
||||||
fontRendererObj.drawString(message, x, y, color);
|
fontRendererObj.drawString(message, x, y, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/AppliedEnergistics/Applied-Energistics-2/blob/master/src/main/java/appeng/client/gui/AEBaseGui.java
|
// https://github.com/AppliedEnergistics/Applied-Energistics-2/blob/master/src/main/java/appeng/client/gui/AEBaseGui.java
|
||||||
public void drawTooltip(int x, int y, String message) {
|
public void drawTooltip(int x, int y, String message)
|
||||||
|
{
|
||||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||||
|
|
||||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||||
@@ -165,15 +188,18 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
|
|
||||||
String[] lines = message.split("\n");
|
String[] lines = message.split("\n");
|
||||||
|
|
||||||
if (lines.length > 0) {
|
if (lines.length > 0)
|
||||||
|
{
|
||||||
int var5 = 0;
|
int var5 = 0;
|
||||||
int var6;
|
int var6;
|
||||||
int var7;
|
int var7;
|
||||||
|
|
||||||
for (var6 = 0; var6 < lines.length; ++var6) {
|
for (var6 = 0; var6 < lines.length; ++var6)
|
||||||
|
{
|
||||||
var7 = this.fontRendererObj.getStringWidth(lines[var6]);
|
var7 = this.fontRendererObj.getStringWidth(lines[var6]);
|
||||||
|
|
||||||
if (var7 > var5) {
|
if (var7 > var5)
|
||||||
|
{
|
||||||
var5 = var7;
|
var5 = var7;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,11 +208,13 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
var7 = y - 12;
|
var7 = y - 12;
|
||||||
int var9 = 8;
|
int var9 = 8;
|
||||||
|
|
||||||
if (lines.length > 1) {
|
if (lines.length > 1)
|
||||||
|
{
|
||||||
var9 += 2 + (lines.length - 1) * 10;
|
var9 += 2 + (lines.length - 1) * 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.guiTop + var7 + var9 + 6 > this.height) {
|
if (this.guiTop + var7 + var9 + 6 > this.height)
|
||||||
|
{
|
||||||
var7 = this.height - var9 - this.guiTop - 6;
|
var7 = this.height - var9 - this.guiTop - 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,18 +237,23 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11);
|
drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11);
|
||||||
drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12);
|
drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12);
|
||||||
|
|
||||||
for (int var13 = 0; var13 < lines.length; ++var13) {
|
for (int var13 = 0; var13 < lines.length; ++var13)
|
||||||
|
{
|
||||||
String var14 = lines[var13];
|
String var14 = lines[var13];
|
||||||
|
|
||||||
if (var13 == 0) {
|
if (var13 == 0)
|
||||||
|
{
|
||||||
var14 = '\u00a7' + Integer.toHexString(15) + var14;
|
var14 = '\u00a7' + Integer.toHexString(15) + var14;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
var14 = "\u00a77" + var14;
|
var14 = "\u00a77" + var14;
|
||||||
}
|
}
|
||||||
|
|
||||||
fontRendererObj.drawStringWithShadow(var14, var6, var7, -1);
|
fontRendererObj.drawStringWithShadow(var14, var6, var7, -1);
|
||||||
|
|
||||||
if (var13 == 0) {
|
if (var13 == 0)
|
||||||
|
{
|
||||||
var7 += 2;
|
var7 += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,13 +267,18 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
GL11.glPopAttrib();
|
GL11.glPopAttrib();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawTooltip(int x, int y, ItemStack stack) {
|
public void drawTooltip(int x, int y, ItemStack stack)
|
||||||
|
{
|
||||||
List list = stack.getTooltip(mc.thePlayer, mc.gameSettings.advancedItemTooltips);
|
List list = stack.getTooltip(mc.thePlayer, mc.gameSettings.advancedItemTooltips);
|
||||||
|
|
||||||
for (int i = 0; i < list.size(); ++i) {
|
for (int i = 0; i < list.size(); ++i)
|
||||||
if (i == 0) {
|
{
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
list.set(i, stack.getRarity().rarityColor + (String) list.get(i));
|
list.set(i, stack.getRarity().rarityColor + (String) list.get(i));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
list.set(i, EnumChatFormatting.GRAY + (String) list.get(i));
|
list.set(i, EnumChatFormatting.GRAY + (String) list.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,7 +286,8 @@ public abstract class GuiBase extends GuiContainer {
|
|||||||
drawTooltip(x, y, Joiner.on("\n").join(list));
|
drawTooltip(x, y, Joiner.on("\n").join(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String t(String name, Object... format) {
|
public String t(String name, Object... format)
|
||||||
|
{
|
||||||
return StatCollector.translateToLocalFormatted(name, format);
|
return StatCollector.translateToLocalFormatted(name, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,26 +4,31 @@ import storagecraft.container.ContainerController;
|
|||||||
import storagecraft.gui.sidebutton.SideButtonRedstoneMode;
|
import storagecraft.gui.sidebutton.SideButtonRedstoneMode;
|
||||||
import storagecraft.tile.TileController;
|
import storagecraft.tile.TileController;
|
||||||
|
|
||||||
public class GuiController extends GuiBase {
|
public class GuiController extends GuiBase
|
||||||
|
{
|
||||||
private TileController controller;
|
private TileController controller;
|
||||||
|
|
||||||
public GuiController(ContainerController container, TileController controller) {
|
public GuiController(ContainerController container, TileController controller)
|
||||||
|
{
|
||||||
super(container, 176, 190);
|
super(container, 176, 190);
|
||||||
|
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(int x, int y) {
|
public void init(int x, int y)
|
||||||
|
{
|
||||||
addSideButton(new SideButtonRedstoneMode(controller));
|
addSideButton(new SideButtonRedstoneMode(controller));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(int x, int y) {
|
public void update(int x, int y)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawBackground(int x, int y, int mouseX, int mouseY) {
|
public void drawBackground(int x, int y, int mouseX, int mouseY)
|
||||||
|
{
|
||||||
bindTexture("gui/controller.png");
|
bindTexture("gui/controller.png");
|
||||||
|
|
||||||
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
||||||
@@ -39,7 +44,8 @@ public class GuiController extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawForeground(int mouseX, int mouseY) {
|
public void drawForeground(int mouseX, int mouseY)
|
||||||
|
{
|
||||||
drawString(7, 7, t("gui.storagecraft:controller"));
|
drawString(7, 7, t("gui.storagecraft:controller"));
|
||||||
drawString(7, 96, t("container.inventory"));
|
drawString(7, 96, t("container.inventory"));
|
||||||
|
|
||||||
|
@@ -10,19 +10,22 @@ import storagecraft.network.MessageDetectorAmountUpdate;
|
|||||||
import storagecraft.tile.TileDetector;
|
import storagecraft.tile.TileDetector;
|
||||||
import storagecraft.util.InventoryUtils;
|
import storagecraft.util.InventoryUtils;
|
||||||
|
|
||||||
public class GuiDetector extends GuiBase {
|
public class GuiDetector extends GuiBase
|
||||||
|
{
|
||||||
private TileDetector detector;
|
private TileDetector detector;
|
||||||
|
|
||||||
private GuiTextField amountField;
|
private GuiTextField amountField;
|
||||||
|
|
||||||
public GuiDetector(ContainerDetector container, TileDetector detector) {
|
public GuiDetector(ContainerDetector container, TileDetector detector)
|
||||||
|
{
|
||||||
super(container, 176, 137);
|
super(container, 176, 137);
|
||||||
|
|
||||||
this.detector = detector;
|
this.detector = detector;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(int x, int y) {
|
public void init(int x, int y)
|
||||||
|
{
|
||||||
addSideButton(new SideButtonCompare(detector, InventoryUtils.COMPARE_DAMAGE));
|
addSideButton(new SideButtonCompare(detector, InventoryUtils.COMPARE_DAMAGE));
|
||||||
addSideButton(new SideButtonCompare(detector, InventoryUtils.COMPARE_NBT));
|
addSideButton(new SideButtonCompare(detector, InventoryUtils.COMPARE_NBT));
|
||||||
|
|
||||||
@@ -38,11 +41,13 @@ public class GuiDetector extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(int x, int y) {
|
public void update(int x, int y)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawBackground(int x, int y, int mouseX, int mouseY) {
|
public void drawBackground(int x, int y, int mouseX, int mouseY)
|
||||||
|
{
|
||||||
bindTexture("gui/detector.png");
|
bindTexture("gui/detector.png");
|
||||||
|
|
||||||
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
||||||
@@ -51,20 +56,26 @@ public class GuiDetector extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawForeground(int mouseX, int mouseY) {
|
public void drawForeground(int mouseX, int mouseY)
|
||||||
|
{
|
||||||
drawString(7, 7, t("gui.storagecraft:detector"));
|
drawString(7, 7, t("gui.storagecraft:detector"));
|
||||||
drawString(7, 43, t("container.inventory"));
|
drawString(7, 43, t("container.inventory"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void keyTyped(char character, int keyCode) {
|
protected void keyTyped(char character, int keyCode)
|
||||||
if (!checkHotbarKeys(keyCode) && amountField.textboxKeyTyped(character, keyCode)) {
|
{
|
||||||
|
if (!checkHotbarKeys(keyCode) && amountField.textboxKeyTyped(character, keyCode))
|
||||||
|
{
|
||||||
Integer result = Ints.tryParse(amountField.getText());
|
Integer result = Ints.tryParse(amountField.getText());
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null)
|
||||||
|
{
|
||||||
StorageCraft.NETWORK.sendToServer(new MessageDetectorAmountUpdate(detector, result));
|
StorageCraft.NETWORK.sendToServer(new MessageDetectorAmountUpdate(detector, result));
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
super.keyTyped(character, keyCode);
|
super.keyTyped(character, keyCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,33 +4,39 @@ import storagecraft.container.ContainerDrive;
|
|||||||
import storagecraft.gui.sidebutton.SideButtonRedstoneMode;
|
import storagecraft.gui.sidebutton.SideButtonRedstoneMode;
|
||||||
import storagecraft.tile.TileDrive;
|
import storagecraft.tile.TileDrive;
|
||||||
|
|
||||||
public class GuiDrive extends GuiBase {
|
public class GuiDrive extends GuiBase
|
||||||
|
{
|
||||||
private TileDrive drive;
|
private TileDrive drive;
|
||||||
|
|
||||||
public GuiDrive(ContainerDrive container, TileDrive drive) {
|
public GuiDrive(ContainerDrive container, TileDrive drive)
|
||||||
|
{
|
||||||
super(container, 176, 190);
|
super(container, 176, 190);
|
||||||
|
|
||||||
this.drive = drive;
|
this.drive = drive;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(int x, int y) {
|
public void init(int x, int y)
|
||||||
|
{
|
||||||
addSideButton(new SideButtonRedstoneMode(drive));
|
addSideButton(new SideButtonRedstoneMode(drive));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(int x, int y) {
|
public void update(int x, int y)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawBackground(int x, int y, int mouseX, int mouseY) {
|
public void drawBackground(int x, int y, int mouseX, int mouseY)
|
||||||
|
{
|
||||||
bindTexture("gui/drive.png");
|
bindTexture("gui/drive.png");
|
||||||
|
|
||||||
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawForeground(int mouseX, int mouseY) {
|
public void drawForeground(int mouseX, int mouseY)
|
||||||
|
{
|
||||||
drawString(7, 7, t("gui.storagecraft:drive"));
|
drawString(7, 7, t("gui.storagecraft:drive"));
|
||||||
drawString(7, 96, t("container.inventory"));
|
drawString(7, 96, t("container.inventory"));
|
||||||
}
|
}
|
||||||
|
@@ -6,17 +6,20 @@ import storagecraft.gui.sidebutton.SideButtonRedstoneMode;
|
|||||||
import storagecraft.tile.TileExporter;
|
import storagecraft.tile.TileExporter;
|
||||||
import storagecraft.util.InventoryUtils;
|
import storagecraft.util.InventoryUtils;
|
||||||
|
|
||||||
public class GuiExporter extends GuiBase {
|
public class GuiExporter extends GuiBase
|
||||||
|
{
|
||||||
private TileExporter exporter;
|
private TileExporter exporter;
|
||||||
|
|
||||||
public GuiExporter(ContainerExporter container, TileExporter exporter) {
|
public GuiExporter(ContainerExporter container, TileExporter exporter)
|
||||||
|
{
|
||||||
super(container, 176, 137);
|
super(container, 176, 137);
|
||||||
|
|
||||||
this.exporter = exporter;
|
this.exporter = exporter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(int x, int y) {
|
public void init(int x, int y)
|
||||||
|
{
|
||||||
addSideButton(new SideButtonRedstoneMode(exporter));
|
addSideButton(new SideButtonRedstoneMode(exporter));
|
||||||
|
|
||||||
addSideButton(new SideButtonCompare(exporter, InventoryUtils.COMPARE_DAMAGE));
|
addSideButton(new SideButtonCompare(exporter, InventoryUtils.COMPARE_DAMAGE));
|
||||||
@@ -24,18 +27,21 @@ public class GuiExporter extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(int x, int y) {
|
public void update(int x, int y)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawBackground(int x, int y, int mouseX, int mouseY) {
|
public void drawBackground(int x, int y, int mouseX, int mouseY)
|
||||||
|
{
|
||||||
bindTexture("gui/exporter.png");
|
bindTexture("gui/exporter.png");
|
||||||
|
|
||||||
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawForeground(int mouseX, int mouseY) {
|
public void drawForeground(int mouseX, int mouseY)
|
||||||
|
{
|
||||||
drawString(7, 7, t("gui.storagecraft:exporter"));
|
drawString(7, 7, t("gui.storagecraft:exporter"));
|
||||||
drawString(7, 43, t("container.inventory"));
|
drawString(7, 43, t("container.inventory"));
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,8 @@ import storagecraft.storage.StorageItem;
|
|||||||
import storagecraft.tile.TileController;
|
import storagecraft.tile.TileController;
|
||||||
import storagecraft.tile.TileGrid;
|
import storagecraft.tile.TileGrid;
|
||||||
|
|
||||||
public class GuiGrid extends GuiBase {
|
public class GuiGrid extends GuiBase
|
||||||
|
{
|
||||||
public static final int SORTING_DIRECTION_ASCENDING = 0;
|
public static final int SORTING_DIRECTION_ASCENDING = 0;
|
||||||
public static final int SORTING_DIRECTION_DESCENDING = 1;
|
public static final int SORTING_DIRECTION_DESCENDING = 1;
|
||||||
|
|
||||||
@@ -39,7 +40,8 @@ public class GuiGrid extends GuiBase {
|
|||||||
|
|
||||||
private int offset;
|
private int offset;
|
||||||
|
|
||||||
public GuiGrid(ContainerGrid container, TileGrid grid) {
|
public GuiGrid(ContainerGrid container, TileGrid grid)
|
||||||
|
{
|
||||||
super(container, 176, 190);
|
super(container, 176, 190);
|
||||||
|
|
||||||
this.container = container;
|
this.container = container;
|
||||||
@@ -47,7 +49,8 @@ public class GuiGrid extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(int x, int y) {
|
public void init(int x, int y)
|
||||||
|
{
|
||||||
addSideButton(new SideButtonRedstoneMode(grid));
|
addSideButton(new SideButtonRedstoneMode(grid));
|
||||||
|
|
||||||
addSideButton(new SideButtonGridSortingDirection());
|
addSideButton(new SideButtonGridSortingDirection());
|
||||||
@@ -62,22 +65,27 @@ public class GuiGrid extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(int x, int y) {
|
public void update(int x, int y)
|
||||||
|
{
|
||||||
int wheel = Mouse.getDWheel();
|
int wheel = Mouse.getDWheel();
|
||||||
|
|
||||||
wheel = Math.max(Math.min(-wheel, 1), -1);
|
wheel = Math.max(Math.min(-wheel, 1), -1);
|
||||||
|
|
||||||
if (canScroll(wheel)) {
|
if (canScroll(wheel))
|
||||||
|
{
|
||||||
offset += wheel;
|
offset += wheel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (offset > getMaxOffset()) {
|
if (offset > getMaxOffset())
|
||||||
|
{
|
||||||
offset = getMaxOffset();
|
offset = getMaxOffset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getMaxOffset() {
|
private int getMaxOffset()
|
||||||
if (!grid.isConnected()) {
|
{
|
||||||
|
if (!grid.isConnected())
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,24 +94,29 @@ public class GuiGrid extends GuiBase {
|
|||||||
return max < 0 ? 0 : max;
|
return max < 0 ? 0 : max;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canScroll(int delta) {
|
private boolean canScroll(int delta)
|
||||||
if (offset + delta < 0) {
|
{
|
||||||
|
if (offset + delta < 0)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return offset + delta <= getMaxOffset();
|
return offset + delta <= getMaxOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isHoveringOverValidSlot() {
|
private boolean isHoveringOverValidSlot()
|
||||||
|
{
|
||||||
return grid.isConnected() && isHoveringOverSlot() && hoveringSlotId < getItems().size();
|
return grid.isConnected() && isHoveringOverSlot() && hoveringSlotId < getItems().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isHoveringOverSlot() {
|
private boolean isHoveringOverSlot()
|
||||||
|
{
|
||||||
return hoveringSlotId >= 0;
|
return hoveringSlotId >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawBackground(int x, int y, int mouseX, int mouseY) {
|
public void drawBackground(int x, int y, int mouseX, int mouseY)
|
||||||
|
{
|
||||||
bindTexture("gui/grid.png");
|
bindTexture("gui/grid.png");
|
||||||
|
|
||||||
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
||||||
@@ -112,7 +125,8 @@ public class GuiGrid extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawForeground(int mouseX, int mouseY) {
|
public void drawForeground(int mouseX, int mouseY)
|
||||||
|
{
|
||||||
drawString(7, 7, t("gui.storagecraft:grid"));
|
drawString(7, 7, t("gui.storagecraft:grid"));
|
||||||
drawString(7, 96, t("container.inventory"));
|
drawString(7, 96, t("container.inventory"));
|
||||||
|
|
||||||
@@ -125,15 +139,19 @@ public class GuiGrid extends GuiBase {
|
|||||||
|
|
||||||
int slot = offset * 9;
|
int slot = offset * 9;
|
||||||
|
|
||||||
for (int i = 0; i < 9 * 4; ++i) {
|
for (int i = 0; i < 9 * 4; ++i)
|
||||||
if (slot < items.size()) {
|
{
|
||||||
|
if (slot < items.size())
|
||||||
|
{
|
||||||
drawItem(x, y, items.get(slot).toItemStack(), true);
|
drawItem(x, y, items.get(slot).toItemStack(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inBounds(x, y, 16, 16, mouseX, mouseY) || !grid.isConnected()) {
|
if (inBounds(x, y, 16, 16, mouseX, mouseY) || !grid.isConnected())
|
||||||
|
{
|
||||||
hoveringSlotId = slot;
|
hoveringSlotId = slot;
|
||||||
|
|
||||||
if (slot < items.size()) {
|
if (slot < items.size())
|
||||||
|
{
|
||||||
// We need to use the ID, because if we filter, the client-side index will change
|
// We need to use the ID, because if we filter, the client-side index will change
|
||||||
// while the serverside's index will still be the same.
|
// while the serverside's index will still be the same.
|
||||||
hoveringId = items.get(slot).getId();
|
hoveringId = items.get(slot).getId();
|
||||||
@@ -150,44 +168,55 @@ public class GuiGrid extends GuiBase {
|
|||||||
|
|
||||||
x += 18;
|
x += 18;
|
||||||
|
|
||||||
if ((i + 1) % 9 == 0) {
|
if ((i + 1) % 9 == 0)
|
||||||
|
{
|
||||||
x = 8;
|
x = 8;
|
||||||
y += 18;
|
y += 18;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isHoveringOverValidSlot()) {
|
if (isHoveringOverValidSlot())
|
||||||
|
{
|
||||||
drawTooltip(mouseX, mouseY, items.get(hoveringSlotId).toItemStack());
|
drawTooltip(mouseX, mouseY, items.get(hoveringSlotId).toItemStack());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StorageItem> getItems() {
|
public List<StorageItem> getItems()
|
||||||
|
{
|
||||||
List<StorageItem> items = new ArrayList<StorageItem>();
|
List<StorageItem> items = new ArrayList<StorageItem>();
|
||||||
|
|
||||||
if (!grid.isConnected()) {
|
if (!grid.isConnected())
|
||||||
|
{
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
items.addAll(grid.getController().getItems());
|
items.addAll(grid.getController().getItems());
|
||||||
|
|
||||||
if (!searchField.getText().trim().isEmpty()) {
|
if (!searchField.getText().trim().isEmpty())
|
||||||
|
{
|
||||||
Iterator<StorageItem> t = items.iterator();
|
Iterator<StorageItem> t = items.iterator();
|
||||||
|
|
||||||
while (t.hasNext()) {
|
while (t.hasNext())
|
||||||
|
{
|
||||||
StorageItem item = t.next();
|
StorageItem item = t.next();
|
||||||
|
|
||||||
if (!item.toItemStack().getDisplayName().toLowerCase().contains(searchField.getText().toLowerCase())) {
|
if (!item.toItemStack().getDisplayName().toLowerCase().contains(searchField.getText().toLowerCase()))
|
||||||
|
{
|
||||||
t.remove();
|
t.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (SORTING_TYPE) {
|
switch (SORTING_TYPE)
|
||||||
|
{
|
||||||
case SORTING_TYPE_COUNT:
|
case SORTING_TYPE_COUNT:
|
||||||
items.sort(new Comparator<StorageItem>() {
|
items.sort(new Comparator<StorageItem>()
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public int compare(StorageItem o1, StorageItem o2) {
|
public int compare(StorageItem o1, StorageItem o2)
|
||||||
switch (SORTING_DIRECTION) {
|
{
|
||||||
|
switch (SORTING_DIRECTION)
|
||||||
|
{
|
||||||
case SORTING_DIRECTION_ASCENDING:
|
case SORTING_DIRECTION_ASCENDING:
|
||||||
return Integer.valueOf(o2.getQuantity()).compareTo(o1.getQuantity());
|
return Integer.valueOf(o2.getQuantity()).compareTo(o1.getQuantity());
|
||||||
case SORTING_DIRECTION_DESCENDING:
|
case SORTING_DIRECTION_DESCENDING:
|
||||||
@@ -200,10 +229,13 @@ public class GuiGrid extends GuiBase {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case SORTING_TYPE_NAME:
|
case SORTING_TYPE_NAME:
|
||||||
items.sort(new Comparator<StorageItem>() {
|
items.sort(new Comparator<StorageItem>()
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public int compare(StorageItem o1, StorageItem o2) {
|
public int compare(StorageItem o1, StorageItem o2)
|
||||||
switch (SORTING_DIRECTION) {
|
{
|
||||||
|
switch (SORTING_DIRECTION)
|
||||||
|
{
|
||||||
case SORTING_DIRECTION_ASCENDING:
|
case SORTING_DIRECTION_ASCENDING:
|
||||||
return o2.toItemStack().getDisplayName().compareTo(o1.toItemStack().getDisplayName());
|
return o2.toItemStack().getDisplayName().compareTo(o1.toItemStack().getDisplayName());
|
||||||
case SORTING_DIRECTION_DESCENDING:
|
case SORTING_DIRECTION_DESCENDING:
|
||||||
@@ -221,22 +253,32 @@ public class GuiGrid extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(int mouseX, int mouseY, int clickedButton) {
|
public void mouseClicked(int mouseX, int mouseY, int clickedButton)
|
||||||
|
{
|
||||||
super.mouseClicked(mouseX, mouseY, clickedButton);
|
super.mouseClicked(mouseX, mouseY, clickedButton);
|
||||||
|
|
||||||
if (grid.isConnected()) {
|
if (grid.isConnected())
|
||||||
|
{
|
||||||
TileController controller = grid.getController();
|
TileController controller = grid.getController();
|
||||||
|
|
||||||
if (isHoveringOverSlot() && container.getPlayer().inventory.getItemStack() != null) {
|
if (isHoveringOverSlot() && container.getPlayer().inventory.getItemStack() != null)
|
||||||
|
{
|
||||||
StorageCraft.NETWORK.sendToServer(new MessageStoragePush(controller.xCoord, controller.yCoord, controller.zCoord, -1, clickedButton == 1));
|
StorageCraft.NETWORK.sendToServer(new MessageStoragePush(controller.xCoord, controller.yCoord, controller.zCoord, -1, clickedButton == 1));
|
||||||
} else if (isHoveringOverValidSlot() && container.getPlayer().inventory.getItemStack() == null) {
|
}
|
||||||
|
else if (isHoveringOverValidSlot() && container.getPlayer().inventory.getItemStack() == null)
|
||||||
|
{
|
||||||
StorageCraft.NETWORK.sendToServer(new MessageStoragePull(controller.xCoord, controller.yCoord, controller.zCoord, hoveringId, clickedButton == 1, Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)));
|
StorageCraft.NETWORK.sendToServer(new MessageStoragePull(controller.xCoord, controller.yCoord, controller.zCoord, hoveringId, clickedButton == 1, Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)));
|
||||||
} else {
|
}
|
||||||
for (int i = 0; i < container.inventorySlots.size(); ++i) {
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < container.inventorySlots.size(); ++i)
|
||||||
|
{
|
||||||
Slot slot = (Slot) container.inventorySlots.get(i);
|
Slot slot = (Slot) container.inventorySlots.get(i);
|
||||||
|
|
||||||
if (inBounds(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX - guiLeft, mouseY - guiTop)) {
|
if (inBounds(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, mouseX - guiLeft, mouseY - guiTop))
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
{
|
||||||
|
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
|
||||||
|
{
|
||||||
StorageCraft.NETWORK.sendToServer(new MessageStoragePush(controller.xCoord, controller.yCoord, controller.zCoord, slot.slotNumber, clickedButton == 1));
|
StorageCraft.NETWORK.sendToServer(new MessageStoragePush(controller.xCoord, controller.yCoord, controller.zCoord, slot.slotNumber, clickedButton == 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,9 +288,13 @@ public class GuiGrid extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void keyTyped(char character, int keyCode) {
|
protected void keyTyped(char character, int keyCode)
|
||||||
if (!checkHotbarKeys(keyCode) && searchField.textboxKeyTyped(character, keyCode)) {
|
{
|
||||||
} else {
|
if (!checkHotbarKeys(keyCode) && searchField.textboxKeyTyped(character, keyCode))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
super.keyTyped(character, keyCode);
|
super.keyTyped(character, keyCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,9 +21,12 @@ import storagecraft.tile.TileGrid;
|
|||||||
import storagecraft.tile.TileImporter;
|
import storagecraft.tile.TileImporter;
|
||||||
import storagecraft.tile.TileStorageProxy;
|
import storagecraft.tile.TileStorageProxy;
|
||||||
|
|
||||||
public class GuiHandler implements IGuiHandler {
|
public class GuiHandler implements IGuiHandler
|
||||||
private Container getContainer(int ID, EntityPlayer player, TileEntity tile) {
|
{
|
||||||
switch (ID) {
|
private Container getContainer(int ID, EntityPlayer player, TileEntity tile)
|
||||||
|
{
|
||||||
|
switch (ID)
|
||||||
|
{
|
||||||
case StorageCraft.GUI.CONTROLLER:
|
case StorageCraft.GUI.CONTROLLER:
|
||||||
return new ContainerController(player);
|
return new ContainerController(player);
|
||||||
case StorageCraft.GUI.GRID:
|
case StorageCraft.GUI.GRID:
|
||||||
@@ -44,15 +47,18 @@ public class GuiHandler implements IGuiHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
||||||
|
{
|
||||||
return getContainer(ID, player, world.getTileEntity(x, y, z));
|
return getContainer(ID, player, world.getTileEntity(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
|
||||||
|
{
|
||||||
TileEntity tile = world.getTileEntity(x, y, z);
|
TileEntity tile = world.getTileEntity(x, y, z);
|
||||||
|
|
||||||
switch (ID) {
|
switch (ID)
|
||||||
|
{
|
||||||
case StorageCraft.GUI.CONTROLLER:
|
case StorageCraft.GUI.CONTROLLER:
|
||||||
return new GuiController((ContainerController) getContainer(ID, player, tile), (TileController) tile);
|
return new GuiController((ContainerController) getContainer(ID, player, tile), (TileController) tile);
|
||||||
case StorageCraft.GUI.GRID:
|
case StorageCraft.GUI.GRID:
|
||||||
|
@@ -7,17 +7,20 @@ import storagecraft.gui.sidebutton.SideButtonRedstoneMode;
|
|||||||
import storagecraft.tile.TileImporter;
|
import storagecraft.tile.TileImporter;
|
||||||
import storagecraft.util.InventoryUtils;
|
import storagecraft.util.InventoryUtils;
|
||||||
|
|
||||||
public class GuiImporter extends GuiBase {
|
public class GuiImporter extends GuiBase
|
||||||
|
{
|
||||||
private TileImporter importer;
|
private TileImporter importer;
|
||||||
|
|
||||||
public GuiImporter(ContainerImporter container, TileImporter importer) {
|
public GuiImporter(ContainerImporter container, TileImporter importer)
|
||||||
|
{
|
||||||
super(container, 176, 137);
|
super(container, 176, 137);
|
||||||
|
|
||||||
this.importer = importer;
|
this.importer = importer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(int x, int y) {
|
public void init(int x, int y)
|
||||||
|
{
|
||||||
addSideButton(new SideButtonRedstoneMode(importer));
|
addSideButton(new SideButtonRedstoneMode(importer));
|
||||||
|
|
||||||
addSideButton(new SideButtonCompare(importer, InventoryUtils.COMPARE_DAMAGE));
|
addSideButton(new SideButtonCompare(importer, InventoryUtils.COMPARE_DAMAGE));
|
||||||
@@ -27,18 +30,21 @@ public class GuiImporter extends GuiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(int x, int y) {
|
public void update(int x, int y)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawBackground(int x, int y, int mouseX, int mouseY) {
|
public void drawBackground(int x, int y, int mouseX, int mouseY)
|
||||||
|
{
|
||||||
bindTexture("gui/importer.png");
|
bindTexture("gui/importer.png");
|
||||||
|
|
||||||
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawForeground(int mouseX, int mouseY) {
|
public void drawForeground(int mouseX, int mouseY)
|
||||||
|
{
|
||||||
drawString(7, 7, t("gui.storagecraft:importer"));
|
drawString(7, 7, t("gui.storagecraft:importer"));
|
||||||
drawString(7, 43, t("container.inventory"));
|
drawString(7, 43, t("container.inventory"));
|
||||||
}
|
}
|
||||||
|
@@ -4,33 +4,39 @@ import storagecraft.container.ContainerStorageProxy;
|
|||||||
import storagecraft.gui.sidebutton.SideButtonRedstoneMode;
|
import storagecraft.gui.sidebutton.SideButtonRedstoneMode;
|
||||||
import storagecraft.tile.TileStorageProxy;
|
import storagecraft.tile.TileStorageProxy;
|
||||||
|
|
||||||
public class GuiStorageProxy extends GuiBase {
|
public class GuiStorageProxy extends GuiBase
|
||||||
|
{
|
||||||
private TileStorageProxy storageProxy;
|
private TileStorageProxy storageProxy;
|
||||||
|
|
||||||
public GuiStorageProxy(ContainerStorageProxy container, TileStorageProxy storageProxy) {
|
public GuiStorageProxy(ContainerStorageProxy container, TileStorageProxy storageProxy)
|
||||||
|
{
|
||||||
super(container, 176, 131);
|
super(container, 176, 131);
|
||||||
|
|
||||||
this.storageProxy = storageProxy;
|
this.storageProxy = storageProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(int x, int y) {
|
public void init(int x, int y)
|
||||||
|
{
|
||||||
addSideButton(new SideButtonRedstoneMode(storageProxy));
|
addSideButton(new SideButtonRedstoneMode(storageProxy));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(int x, int y) {
|
public void update(int x, int y)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawBackground(int x, int y, int mouseX, int mouseY) {
|
public void drawBackground(int x, int y, int mouseX, int mouseY)
|
||||||
|
{
|
||||||
bindTexture("gui/storageProxy.png");
|
bindTexture("gui/storageProxy.png");
|
||||||
|
|
||||||
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawForeground(int mouseX, int mouseY) {
|
public void drawForeground(int mouseX, int mouseY)
|
||||||
|
{
|
||||||
drawString(7, 7, t("gui.storagecraft:storageProxy"));
|
drawString(7, 7, t("gui.storagecraft:storageProxy"));
|
||||||
drawString(7, 39, t("container.inventory"));
|
drawString(7, 39, t("container.inventory"));
|
||||||
}
|
}
|
||||||
|
@@ -2,32 +2,39 @@ package storagecraft.gui.sidebutton;
|
|||||||
|
|
||||||
import storagecraft.gui.GuiBase;
|
import storagecraft.gui.GuiBase;
|
||||||
|
|
||||||
public abstract class SideButton {
|
public abstract class SideButton
|
||||||
|
{
|
||||||
private int id;
|
private int id;
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
|
|
||||||
public int getId() {
|
public int getId()
|
||||||
|
{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(int id) {
|
public void setId(int id)
|
||||||
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getX() {
|
public int getX()
|
||||||
|
{
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setX(int x) {
|
public void setX(int x)
|
||||||
|
{
|
||||||
this.x = x;
|
this.x = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getY() {
|
public int getY()
|
||||||
|
{
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setY(int y) {
|
public void setY(int y)
|
||||||
|
{
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,24 +6,30 @@ import storagecraft.gui.GuiBase;
|
|||||||
import storagecraft.network.MessageCompareUpdate;
|
import storagecraft.network.MessageCompareUpdate;
|
||||||
import storagecraft.tile.ICompareSetting;
|
import storagecraft.tile.ICompareSetting;
|
||||||
|
|
||||||
public class SideButtonCompare extends SideButton {
|
public class SideButtonCompare extends SideButton
|
||||||
|
{
|
||||||
private ICompareSetting setting;
|
private ICompareSetting setting;
|
||||||
private int mask;
|
private int mask;
|
||||||
|
|
||||||
public SideButtonCompare(ICompareSetting setting, int mask) {
|
public SideButtonCompare(ICompareSetting setting, int mask)
|
||||||
|
{
|
||||||
this.setting = setting;
|
this.setting = setting;
|
||||||
this.mask = mask;
|
this.mask = mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTooltip(GuiBase gui) {
|
public String getTooltip(GuiBase gui)
|
||||||
|
{
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
builder.append(EnumChatFormatting.YELLOW).append(gui.t("sidebutton.storagecraft:compare." + mask)).append(EnumChatFormatting.RESET).append("\n");
|
builder.append(EnumChatFormatting.YELLOW).append(gui.t("sidebutton.storagecraft:compare." + mask)).append(EnumChatFormatting.RESET).append("\n");
|
||||||
|
|
||||||
if ((setting.getCompare() & mask) == mask) {
|
if ((setting.getCompare() & mask) == mask)
|
||||||
|
{
|
||||||
builder.append(gui.t("misc.storagecraft:yes"));
|
builder.append(gui.t("misc.storagecraft:yes"));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
builder.append(gui.t("misc.storagecraft:no"));
|
builder.append(gui.t("misc.storagecraft:no"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,11 +37,13 @@ public class SideButtonCompare extends SideButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(GuiBase gui, int x, int y) {
|
public void draw(GuiBase gui, int x, int y)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed() {
|
public void actionPerformed()
|
||||||
|
{
|
||||||
StorageCraft.NETWORK.sendToServer(new MessageCompareUpdate(setting, setting.getCompare() ^ mask));
|
StorageCraft.NETWORK.sendToServer(new MessageCompareUpdate(setting, setting.getCompare() ^ mask));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,15 +6,18 @@ import storagecraft.gui.GuiBase;
|
|||||||
import storagecraft.network.MessageDetectorModeUpdate;
|
import storagecraft.network.MessageDetectorModeUpdate;
|
||||||
import storagecraft.tile.TileDetector;
|
import storagecraft.tile.TileDetector;
|
||||||
|
|
||||||
public class SideButtonDetectorMode extends SideButton {
|
public class SideButtonDetectorMode extends SideButton
|
||||||
|
{
|
||||||
private TileDetector detector;
|
private TileDetector detector;
|
||||||
|
|
||||||
public SideButtonDetectorMode(TileDetector detector) {
|
public SideButtonDetectorMode(TileDetector detector)
|
||||||
|
{
|
||||||
this.detector = detector;
|
this.detector = detector;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTooltip(GuiBase gui) {
|
public String getTooltip(GuiBase gui)
|
||||||
|
{
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
builder.append(EnumChatFormatting.GREEN).append(gui.t("sidebutton.storagecraft:detector.mode")).append(EnumChatFormatting.RESET).append("\n");
|
builder.append(EnumChatFormatting.GREEN).append(gui.t("sidebutton.storagecraft:detector.mode")).append(EnumChatFormatting.RESET).append("\n");
|
||||||
@@ -25,11 +28,13 @@ public class SideButtonDetectorMode extends SideButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(GuiBase gui, int x, int y) {
|
public void draw(GuiBase gui, int x, int y)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed() {
|
public void actionPerformed()
|
||||||
|
{
|
||||||
StorageCraft.NETWORK.sendToServer(new MessageDetectorModeUpdate(detector));
|
StorageCraft.NETWORK.sendToServer(new MessageDetectorModeUpdate(detector));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,9 +4,11 @@ import net.minecraft.util.EnumChatFormatting;
|
|||||||
import storagecraft.gui.GuiBase;
|
import storagecraft.gui.GuiBase;
|
||||||
import storagecraft.gui.GuiGrid;
|
import storagecraft.gui.GuiGrid;
|
||||||
|
|
||||||
public class SideButtonGridSortingDirection extends SideButton {
|
public class SideButtonGridSortingDirection extends SideButton
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public String getTooltip(GuiBase gui) {
|
public String getTooltip(GuiBase gui)
|
||||||
|
{
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
builder.append(EnumChatFormatting.YELLOW).append(gui.t("sidebutton.storagecraft:sorting.direction")).append(EnumChatFormatting.RESET).append("\n");
|
builder.append(EnumChatFormatting.YELLOW).append(gui.t("sidebutton.storagecraft:sorting.direction")).append(EnumChatFormatting.RESET).append("\n");
|
||||||
@@ -17,11 +19,13 @@ public class SideButtonGridSortingDirection extends SideButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(GuiBase gui, int x, int y) {
|
public void draw(GuiBase gui, int x, int y)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed() {
|
public void actionPerformed()
|
||||||
|
{
|
||||||
GuiGrid.SORTING_DIRECTION = GuiGrid.SORTING_DIRECTION == GuiGrid.SORTING_DIRECTION_ASCENDING ? GuiGrid.SORTING_DIRECTION_DESCENDING : GuiGrid.SORTING_DIRECTION_ASCENDING;
|
GuiGrid.SORTING_DIRECTION = GuiGrid.SORTING_DIRECTION == GuiGrid.SORTING_DIRECTION_ASCENDING ? GuiGrid.SORTING_DIRECTION_DESCENDING : GuiGrid.SORTING_DIRECTION_ASCENDING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,9 +4,11 @@ import net.minecraft.util.EnumChatFormatting;
|
|||||||
import storagecraft.gui.GuiBase;
|
import storagecraft.gui.GuiBase;
|
||||||
import storagecraft.gui.GuiGrid;
|
import storagecraft.gui.GuiGrid;
|
||||||
|
|
||||||
public class SideButtonGridSortingType extends SideButton {
|
public class SideButtonGridSortingType extends SideButton
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public String getTooltip(GuiBase gui) {
|
public String getTooltip(GuiBase gui)
|
||||||
|
{
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
builder.append(EnumChatFormatting.YELLOW).append(gui.t("sidebutton.storagecraft:sorting.type")).append(EnumChatFormatting.RESET).append("\n");
|
builder.append(EnumChatFormatting.YELLOW).append(gui.t("sidebutton.storagecraft:sorting.type")).append(EnumChatFormatting.RESET).append("\n");
|
||||||
@@ -17,11 +19,13 @@ public class SideButtonGridSortingType extends SideButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(GuiBase gui, int x, int y) {
|
public void draw(GuiBase gui, int x, int y)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed() {
|
public void actionPerformed()
|
||||||
|
{
|
||||||
GuiGrid.SORTING_TYPE = GuiGrid.SORTING_TYPE == GuiGrid.SORTING_TYPE_COUNT ? GuiGrid.SORTING_TYPE_NAME : GuiGrid.SORTING_TYPE_COUNT;
|
GuiGrid.SORTING_TYPE = GuiGrid.SORTING_TYPE == GuiGrid.SORTING_TYPE_COUNT ? GuiGrid.SORTING_TYPE_NAME : GuiGrid.SORTING_TYPE_COUNT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,15 +6,18 @@ import storagecraft.gui.GuiBase;
|
|||||||
import storagecraft.network.MessageImporterModeUpdate;
|
import storagecraft.network.MessageImporterModeUpdate;
|
||||||
import storagecraft.tile.TileImporter;
|
import storagecraft.tile.TileImporter;
|
||||||
|
|
||||||
public class SideButtonImporterMode extends SideButton {
|
public class SideButtonImporterMode extends SideButton
|
||||||
|
{
|
||||||
private TileImporter importer;
|
private TileImporter importer;
|
||||||
|
|
||||||
public SideButtonImporterMode(TileImporter importer) {
|
public SideButtonImporterMode(TileImporter importer)
|
||||||
|
{
|
||||||
this.importer = importer;
|
this.importer = importer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTooltip(GuiBase gui) {
|
public String getTooltip(GuiBase gui)
|
||||||
|
{
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
builder.append(EnumChatFormatting.GREEN).append(gui.t("sidebutton.storagecraft:importer.mode")).append(EnumChatFormatting.RESET).append("\n");
|
builder.append(EnumChatFormatting.GREEN).append(gui.t("sidebutton.storagecraft:importer.mode")).append(EnumChatFormatting.RESET).append("\n");
|
||||||
@@ -25,11 +28,13 @@ public class SideButtonImporterMode extends SideButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(GuiBase gui, int x, int y) {
|
public void draw(GuiBase gui, int x, int y)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed() {
|
public void actionPerformed()
|
||||||
|
{
|
||||||
StorageCraft.NETWORK.sendToServer(new MessageImporterModeUpdate(importer));
|
StorageCraft.NETWORK.sendToServer(new MessageImporterModeUpdate(importer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,15 +8,18 @@ import storagecraft.gui.GuiBase;
|
|||||||
import storagecraft.network.MessageRedstoneModeUpdate;
|
import storagecraft.network.MessageRedstoneModeUpdate;
|
||||||
import storagecraft.tile.IRedstoneModeSetting;
|
import storagecraft.tile.IRedstoneModeSetting;
|
||||||
|
|
||||||
public class SideButtonRedstoneMode extends SideButton {
|
public class SideButtonRedstoneMode extends SideButton
|
||||||
|
{
|
||||||
private IRedstoneModeSetting setting;
|
private IRedstoneModeSetting setting;
|
||||||
|
|
||||||
public SideButtonRedstoneMode(IRedstoneModeSetting setting) {
|
public SideButtonRedstoneMode(IRedstoneModeSetting setting)
|
||||||
|
{
|
||||||
this.setting = setting;
|
this.setting = setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTooltip(GuiBase gui) {
|
public String getTooltip(GuiBase gui)
|
||||||
|
{
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
builder.append(EnumChatFormatting.RED).append(gui.t("sidebutton.storagecraft:redstoneMode")).append(EnumChatFormatting.RESET).append("\n");
|
builder.append(EnumChatFormatting.RED).append(gui.t("sidebutton.storagecraft:redstoneMode")).append(EnumChatFormatting.RESET).append("\n");
|
||||||
@@ -27,12 +30,14 @@ public class SideButtonRedstoneMode extends SideButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(GuiBase gui, int x, int y) {
|
public void draw(GuiBase gui, int x, int y)
|
||||||
|
{
|
||||||
gui.drawItem(x, y, new ItemStack(Items.redstone, 1));
|
gui.drawItem(x, y, new ItemStack(Items.redstone, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed() {
|
public void actionPerformed()
|
||||||
|
{
|
||||||
StorageCraft.NETWORK.sendToServer(new MessageRedstoneModeUpdate(setting));
|
StorageCraft.NETWORK.sendToServer(new MessageRedstoneModeUpdate(setting));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,38 +4,48 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public class InventorySimple implements IInventory {
|
public class InventorySimple implements IInventory
|
||||||
|
{
|
||||||
private ItemStack[] inventory;
|
private ItemStack[] inventory;
|
||||||
private int size;
|
private int size;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public InventorySimple(String name, int size) {
|
public InventorySimple(String name, int size)
|
||||||
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
this.inventory = new ItemStack[size];
|
this.inventory = new ItemStack[size];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSizeInventory() {
|
public int getSizeInventory()
|
||||||
|
{
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStackInSlot(int slotIndex) {
|
public ItemStack getStackInSlot(int slotIndex)
|
||||||
|
{
|
||||||
return inventory[slotIndex];
|
return inventory[slotIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack decrStackSize(int slot, int amount) {
|
public ItemStack decrStackSize(int slot, int amount)
|
||||||
|
{
|
||||||
ItemStack stack = getStackInSlot(slot);
|
ItemStack stack = getStackInSlot(slot);
|
||||||
|
|
||||||
if (stack != null) {
|
if (stack != null)
|
||||||
if (stack.stackSize <= amount) {
|
{
|
||||||
|
if (stack.stackSize <= amount)
|
||||||
|
{
|
||||||
setInventorySlotContents(slot, null);
|
setInventorySlotContents(slot, null);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
stack = stack.splitStack(amount);
|
stack = stack.splitStack(amount);
|
||||||
|
|
||||||
if (stack.stackSize == 0) {
|
if (stack.stackSize == 0)
|
||||||
|
{
|
||||||
setInventorySlotContents(slot, null);
|
setInventorySlotContents(slot, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,10 +55,12 @@ public class InventorySimple implements IInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
public ItemStack getStackInSlotOnClosing(int slot)
|
||||||
|
{
|
||||||
ItemStack stack = getStackInSlot(slot);
|
ItemStack stack = getStackInSlot(slot);
|
||||||
|
|
||||||
if (stack != null) {
|
if (stack != null)
|
||||||
|
{
|
||||||
setInventorySlotContents(slot, null);
|
setInventorySlotContents(slot, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,8 +68,10 @@ public class InventorySimple implements IInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||||
if (stack != null && stack.stackSize > getInventoryStackLimit()) {
|
{
|
||||||
|
if (stack != null && stack.stackSize > getInventoryStackLimit())
|
||||||
|
{
|
||||||
stack.stackSize = getInventoryStackLimit();
|
stack.stackSize = getInventoryStackLimit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,39 +79,47 @@ public class InventorySimple implements IInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInventoryName() {
|
public String getInventoryName()
|
||||||
|
{
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCustomInventoryName() {
|
public boolean hasCustomInventoryName()
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInventoryStackLimit() {
|
public int getInventoryStackLimit()
|
||||||
|
{
|
||||||
return 64;
|
return 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
public boolean isUseableByPlayer(EntityPlayer player)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openInventory() {
|
public void openInventory()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeInventory() {
|
public void closeInventory()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
public boolean isItemValidForSlot(int slot, ItemStack stack)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void markDirty() {
|
public void markDirty()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,10 +4,12 @@ import net.minecraft.item.Item;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import storagecraft.StorageCraft;
|
import storagecraft.StorageCraft;
|
||||||
|
|
||||||
public abstract class ItemBase extends Item {
|
public abstract class ItemBase extends Item
|
||||||
|
{
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public ItemBase(String name) {
|
public ItemBase(String name)
|
||||||
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
setCreativeTab(StorageCraft.TAB);
|
setCreativeTab(StorageCraft.TAB);
|
||||||
@@ -15,13 +17,16 @@ public abstract class ItemBase extends Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUnlocalizedName() {
|
public String getUnlocalizedName()
|
||||||
|
{
|
||||||
return "item." + StorageCraft.ID + ":" + name;
|
return "item." + StorageCraft.ID + ":" + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUnlocalizedName(ItemStack stack) {
|
public String getUnlocalizedName(ItemStack stack)
|
||||||
if (getHasSubtypes()) {
|
{
|
||||||
|
if (getHasSubtypes())
|
||||||
|
{
|
||||||
return getUnlocalizedName() + "." + stack.getItemDamage();
|
return getUnlocalizedName() + "." + stack.getItemDamage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,13 +4,16 @@ import net.minecraft.block.Block;
|
|||||||
import net.minecraft.item.ItemBlockWithMetadata;
|
import net.minecraft.item.ItemBlockWithMetadata;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public abstract class ItemBlockBase extends ItemBlockWithMetadata {
|
public abstract class ItemBlockBase extends ItemBlockWithMetadata
|
||||||
public ItemBlockBase(Block block) {
|
{
|
||||||
|
public ItemBlockBase(Block block)
|
||||||
|
{
|
||||||
super(block, block);
|
super(block, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUnlocalizedName(ItemStack stack) {
|
public String getUnlocalizedName(ItemStack stack)
|
||||||
|
{
|
||||||
return getUnlocalizedName() + "." + stack.getItemDamage();
|
return getUnlocalizedName() + "." + stack.getItemDamage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,8 +2,10 @@ package storagecraft.item;
|
|||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
|
||||||
public class ItemBlockCable extends ItemBlockBase {
|
public class ItemBlockCable extends ItemBlockBase
|
||||||
public ItemBlockCable(Block block) {
|
{
|
||||||
|
public ItemBlockCable(Block block)
|
||||||
|
{
|
||||||
super(block);
|
super(block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,10 +13,12 @@ import net.minecraft.util.StatCollector;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import storagecraft.storage.CellStorage;
|
import storagecraft.storage.CellStorage;
|
||||||
|
|
||||||
public class ItemStorageCell extends ItemBase {
|
public class ItemStorageCell extends ItemBase
|
||||||
|
{
|
||||||
private IIcon[] icons = new IIcon[5];
|
private IIcon[] icons = new IIcon[5];
|
||||||
|
|
||||||
public ItemStorageCell() {
|
public ItemStorageCell()
|
||||||
|
{
|
||||||
super("storageCell");
|
super("storageCell");
|
||||||
|
|
||||||
setMaxStackSize(1);
|
setMaxStackSize(1);
|
||||||
@@ -25,41 +27,52 @@ public class ItemStorageCell extends ItemBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getSubItems(Item item, CreativeTabs tab, List list) {
|
public void getSubItems(Item item, CreativeTabs tab, List list)
|
||||||
for (int i = 0; i < 5; ++i) {
|
{
|
||||||
|
for (int i = 0; i < 5; ++i)
|
||||||
|
{
|
||||||
list.add(initNBT(new ItemStack(item, 1, i)));
|
list.add(initNBT(new ItemStack(item, 1, i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInformation(ItemStack cell, EntityPlayer player, List list, boolean b) {
|
public void addInformation(ItemStack cell, EntityPlayer player, List list, boolean b)
|
||||||
if (getCapacity(cell) == -1) {
|
{
|
||||||
|
if (getCapacity(cell) == -1)
|
||||||
|
{
|
||||||
list.add(String.format(StatCollector.translateToLocal("misc.storagecraft:storageCellStored"), getStored(cell)));
|
list.add(String.format(StatCollector.translateToLocal("misc.storagecraft:storageCellStored"), getStored(cell)));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
list.add(String.format(StatCollector.translateToLocal("misc.storagecraft:storageCellStoredWithCapacity"), getStored(cell), getCapacity(cell)));
|
list.add(String.format(StatCollector.translateToLocal("misc.storagecraft:storageCellStoredWithCapacity"), getStored(cell), getCapacity(cell)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
|
public void onCreated(ItemStack stack, World world, EntityPlayer player)
|
||||||
|
{
|
||||||
super.onCreated(stack, world, player);
|
super.onCreated(stack, world, player);
|
||||||
|
|
||||||
initNBT(stack);
|
initNBT(stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerIcons(IIconRegister register) {
|
public void registerIcons(IIconRegister register)
|
||||||
for (int i = 0; i < 5; ++i) {
|
{
|
||||||
|
for (int i = 0; i < 5; ++i)
|
||||||
|
{
|
||||||
icons[i] = register.registerIcon("storagecraft:storageCell" + i);
|
icons[i] = register.registerIcon("storagecraft:storageCell" + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIcon getIconFromDamage(int damage) {
|
public IIcon getIconFromDamage(int damage)
|
||||||
|
{
|
||||||
return icons[damage];
|
return icons[damage];
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack initNBT(ItemStack cell) {
|
private ItemStack initNBT(ItemStack cell)
|
||||||
|
{
|
||||||
cell.stackTagCompound = new NBTTagCompound();
|
cell.stackTagCompound = new NBTTagCompound();
|
||||||
cell.stackTagCompound.setTag(CellStorage.NBT_ITEMS, new NBTTagList());
|
cell.stackTagCompound.setTag(CellStorage.NBT_ITEMS, new NBTTagList());
|
||||||
cell.stackTagCompound.setInteger(CellStorage.NBT_STORED, 0);
|
cell.stackTagCompound.setInteger(CellStorage.NBT_STORED, 0);
|
||||||
@@ -67,12 +80,15 @@ public class ItemStorageCell extends ItemBase {
|
|||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getStored(ItemStack cell) {
|
public static int getStored(ItemStack cell)
|
||||||
|
{
|
||||||
return cell.stackTagCompound.getInteger(CellStorage.NBT_STORED);
|
return cell.stackTagCompound.getInteger(CellStorage.NBT_STORED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getCapacity(ItemStack cell) {
|
public static int getCapacity(ItemStack cell)
|
||||||
switch (cell.getItemDamage()) {
|
{
|
||||||
|
switch (cell.getItemDamage())
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return 1000;
|
return 1000;
|
||||||
case 1:
|
case 1:
|
||||||
|
@@ -8,16 +8,19 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
|||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import storagecraft.tile.ICompareSetting;
|
import storagecraft.tile.ICompareSetting;
|
||||||
|
|
||||||
public class MessageCompareUpdate implements IMessage, IMessageHandler<MessageCompareUpdate, IMessage> {
|
public class MessageCompareUpdate implements IMessage, IMessageHandler<MessageCompareUpdate, IMessage>
|
||||||
|
{
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
private int z;
|
private int z;
|
||||||
private int compare;
|
private int compare;
|
||||||
|
|
||||||
public MessageCompareUpdate() {
|
public MessageCompareUpdate()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageCompareUpdate(ICompareSetting setting, int compare) {
|
public MessageCompareUpdate(ICompareSetting setting, int compare)
|
||||||
|
{
|
||||||
this.x = setting.getX();
|
this.x = setting.getX();
|
||||||
this.y = setting.getY();
|
this.y = setting.getY();
|
||||||
this.z = setting.getZ();
|
this.z = setting.getZ();
|
||||||
@@ -25,7 +28,8 @@ public class MessageCompareUpdate implements IMessage, IMessageHandler<MessageCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
x = buf.readInt();
|
x = buf.readInt();
|
||||||
y = buf.readInt();
|
y = buf.readInt();
|
||||||
z = buf.readInt();
|
z = buf.readInt();
|
||||||
@@ -33,7 +37,8 @@ public class MessageCompareUpdate implements IMessage, IMessageHandler<MessageCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
buf.writeInt(x);
|
buf.writeInt(x);
|
||||||
buf.writeInt(y);
|
buf.writeInt(y);
|
||||||
buf.writeInt(z);
|
buf.writeInt(z);
|
||||||
@@ -41,12 +46,14 @@ public class MessageCompareUpdate implements IMessage, IMessageHandler<MessageCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMessage onMessage(MessageCompareUpdate message, MessageContext context) {
|
public IMessage onMessage(MessageCompareUpdate message, MessageContext context)
|
||||||
|
{
|
||||||
EntityPlayerMP player = context.getServerHandler().playerEntity;
|
EntityPlayerMP player = context.getServerHandler().playerEntity;
|
||||||
|
|
||||||
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||||
|
|
||||||
if (tile instanceof ICompareSetting) {
|
if (tile instanceof ICompareSetting)
|
||||||
|
{
|
||||||
((ICompareSetting) tile).setCompare(message.compare);
|
((ICompareSetting) tile).setCompare(message.compare);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,16 +8,19 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
|||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import storagecraft.tile.TileDetector;
|
import storagecraft.tile.TileDetector;
|
||||||
|
|
||||||
public class MessageDetectorAmountUpdate implements IMessage, IMessageHandler<MessageDetectorAmountUpdate, IMessage> {
|
public class MessageDetectorAmountUpdate implements IMessage, IMessageHandler<MessageDetectorAmountUpdate, IMessage>
|
||||||
|
{
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
private int z;
|
private int z;
|
||||||
private int amount;
|
private int amount;
|
||||||
|
|
||||||
public MessageDetectorAmountUpdate() {
|
public MessageDetectorAmountUpdate()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageDetectorAmountUpdate(TileDetector detector, int amount) {
|
public MessageDetectorAmountUpdate(TileDetector detector, int amount)
|
||||||
|
{
|
||||||
this.x = detector.xCoord;
|
this.x = detector.xCoord;
|
||||||
this.y = detector.yCoord;
|
this.y = detector.yCoord;
|
||||||
this.z = detector.zCoord;
|
this.z = detector.zCoord;
|
||||||
@@ -25,7 +28,8 @@ public class MessageDetectorAmountUpdate implements IMessage, IMessageHandler<Me
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
x = buf.readInt();
|
x = buf.readInt();
|
||||||
y = buf.readInt();
|
y = buf.readInt();
|
||||||
z = buf.readInt();
|
z = buf.readInt();
|
||||||
@@ -33,7 +37,8 @@ public class MessageDetectorAmountUpdate implements IMessage, IMessageHandler<Me
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
buf.writeInt(x);
|
buf.writeInt(x);
|
||||||
buf.writeInt(y);
|
buf.writeInt(y);
|
||||||
buf.writeInt(z);
|
buf.writeInt(z);
|
||||||
@@ -41,12 +46,14 @@ public class MessageDetectorAmountUpdate implements IMessage, IMessageHandler<Me
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMessage onMessage(MessageDetectorAmountUpdate message, MessageContext context) {
|
public IMessage onMessage(MessageDetectorAmountUpdate message, MessageContext context)
|
||||||
|
{
|
||||||
EntityPlayerMP player = context.getServerHandler().playerEntity;
|
EntityPlayerMP player = context.getServerHandler().playerEntity;
|
||||||
|
|
||||||
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||||
|
|
||||||
if (tile instanceof TileDetector && message.amount >= 0) {
|
if (tile instanceof TileDetector && message.amount >= 0)
|
||||||
|
{
|
||||||
((TileDetector) tile).setAmount(message.amount);
|
((TileDetector) tile).setAmount(message.amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,44 +8,52 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
|||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import storagecraft.tile.TileDetector;
|
import storagecraft.tile.TileDetector;
|
||||||
|
|
||||||
public class MessageDetectorModeUpdate implements IMessage, IMessageHandler<MessageDetectorModeUpdate, IMessage> {
|
public class MessageDetectorModeUpdate implements IMessage, IMessageHandler<MessageDetectorModeUpdate, IMessage>
|
||||||
|
{
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
private int z;
|
private int z;
|
||||||
|
|
||||||
public MessageDetectorModeUpdate() {
|
public MessageDetectorModeUpdate()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageDetectorModeUpdate(TileDetector detector) {
|
public MessageDetectorModeUpdate(TileDetector detector)
|
||||||
|
{
|
||||||
this.x = detector.xCoord;
|
this.x = detector.xCoord;
|
||||||
this.y = detector.yCoord;
|
this.y = detector.yCoord;
|
||||||
this.z = detector.zCoord;
|
this.z = detector.zCoord;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
x = buf.readInt();
|
x = buf.readInt();
|
||||||
y = buf.readInt();
|
y = buf.readInt();
|
||||||
z = buf.readInt();
|
z = buf.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
buf.writeInt(x);
|
buf.writeInt(x);
|
||||||
buf.writeInt(y);
|
buf.writeInt(y);
|
||||||
buf.writeInt(z);
|
buf.writeInt(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMessage onMessage(MessageDetectorModeUpdate message, MessageContext context) {
|
public IMessage onMessage(MessageDetectorModeUpdate message, MessageContext context)
|
||||||
|
{
|
||||||
EntityPlayerMP player = context.getServerHandler().playerEntity;
|
EntityPlayerMP player = context.getServerHandler().playerEntity;
|
||||||
|
|
||||||
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||||
|
|
||||||
if (tile instanceof TileDetector) {
|
if (tile instanceof TileDetector)
|
||||||
|
{
|
||||||
TileDetector detector = (TileDetector) tile;
|
TileDetector detector = (TileDetector) tile;
|
||||||
|
|
||||||
switch (detector.getMode()) {
|
switch (detector.getMode())
|
||||||
|
{
|
||||||
case TileDetector.MODE_UNDER:
|
case TileDetector.MODE_UNDER:
|
||||||
detector.setMode(TileDetector.MODE_EQUAL);
|
detector.setMode(TileDetector.MODE_EQUAL);
|
||||||
break;
|
break;
|
||||||
|
@@ -8,41 +8,48 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
|||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import storagecraft.tile.TileImporter;
|
import storagecraft.tile.TileImporter;
|
||||||
|
|
||||||
public class MessageImporterModeUpdate implements IMessage, IMessageHandler<MessageImporterModeUpdate, IMessage> {
|
public class MessageImporterModeUpdate implements IMessage, IMessageHandler<MessageImporterModeUpdate, IMessage>
|
||||||
|
{
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
private int z;
|
private int z;
|
||||||
|
|
||||||
public MessageImporterModeUpdate() {
|
public MessageImporterModeUpdate()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageImporterModeUpdate(TileImporter importer) {
|
public MessageImporterModeUpdate(TileImporter importer)
|
||||||
|
{
|
||||||
this.x = importer.xCoord;
|
this.x = importer.xCoord;
|
||||||
this.y = importer.yCoord;
|
this.y = importer.yCoord;
|
||||||
this.z = importer.zCoord;
|
this.z = importer.zCoord;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
x = buf.readInt();
|
x = buf.readInt();
|
||||||
y = buf.readInt();
|
y = buf.readInt();
|
||||||
z = buf.readInt();
|
z = buf.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
buf.writeInt(x);
|
buf.writeInt(x);
|
||||||
buf.writeInt(y);
|
buf.writeInt(y);
|
||||||
buf.writeInt(z);
|
buf.writeInt(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMessage onMessage(MessageImporterModeUpdate message, MessageContext context) {
|
public IMessage onMessage(MessageImporterModeUpdate message, MessageContext context)
|
||||||
|
{
|
||||||
EntityPlayerMP player = context.getServerHandler().playerEntity;
|
EntityPlayerMP player = context.getServerHandler().playerEntity;
|
||||||
|
|
||||||
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||||
|
|
||||||
if (tile instanceof TileImporter) {
|
if (tile instanceof TileImporter)
|
||||||
|
{
|
||||||
TileImporter importer = (TileImporter) tile;
|
TileImporter importer = (TileImporter) tile;
|
||||||
|
|
||||||
importer.setMode(importer.getMode() == TileImporter.MODE_WHITELIST ? TileImporter.MODE_BLACKLIST : TileImporter.MODE_WHITELIST);
|
importer.setMode(importer.getMode() == TileImporter.MODE_WHITELIST ? TileImporter.MODE_BLACKLIST : TileImporter.MODE_WHITELIST);
|
||||||
|
@@ -8,41 +8,48 @@ import net.minecraft.entity.player.EntityPlayerMP;
|
|||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import storagecraft.tile.IRedstoneModeSetting;
|
import storagecraft.tile.IRedstoneModeSetting;
|
||||||
|
|
||||||
public class MessageRedstoneModeUpdate implements IMessage, IMessageHandler<MessageRedstoneModeUpdate, IMessage> {
|
public class MessageRedstoneModeUpdate implements IMessage, IMessageHandler<MessageRedstoneModeUpdate, IMessage>
|
||||||
|
{
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
private int z;
|
private int z;
|
||||||
|
|
||||||
public MessageRedstoneModeUpdate() {
|
public MessageRedstoneModeUpdate()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageRedstoneModeUpdate(IRedstoneModeSetting setting) {
|
public MessageRedstoneModeUpdate(IRedstoneModeSetting setting)
|
||||||
|
{
|
||||||
this.x = setting.getX();
|
this.x = setting.getX();
|
||||||
this.y = setting.getY();
|
this.y = setting.getY();
|
||||||
this.z = setting.getZ();
|
this.z = setting.getZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
x = buf.readInt();
|
x = buf.readInt();
|
||||||
y = buf.readInt();
|
y = buf.readInt();
|
||||||
z = buf.readInt();
|
z = buf.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
buf.writeInt(x);
|
buf.writeInt(x);
|
||||||
buf.writeInt(y);
|
buf.writeInt(y);
|
||||||
buf.writeInt(z);
|
buf.writeInt(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMessage onMessage(MessageRedstoneModeUpdate message, MessageContext context) {
|
public IMessage onMessage(MessageRedstoneModeUpdate message, MessageContext context)
|
||||||
|
{
|
||||||
EntityPlayerMP player = context.getServerHandler().playerEntity;
|
EntityPlayerMP player = context.getServerHandler().playerEntity;
|
||||||
|
|
||||||
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||||
|
|
||||||
if (tile instanceof IRedstoneModeSetting) {
|
if (tile instanceof IRedstoneModeSetting)
|
||||||
|
{
|
||||||
IRedstoneModeSetting setting = (IRedstoneModeSetting) tile;
|
IRedstoneModeSetting setting = (IRedstoneModeSetting) tile;
|
||||||
|
|
||||||
setting.setRedstoneMode(setting.getRedstoneMode().next());
|
setting.setRedstoneMode(setting.getRedstoneMode().next());
|
||||||
|
@@ -10,7 +10,8 @@ import net.minecraft.tileentity.TileEntity;
|
|||||||
import storagecraft.storage.StorageItem;
|
import storagecraft.storage.StorageItem;
|
||||||
import storagecraft.tile.TileController;
|
import storagecraft.tile.TileController;
|
||||||
|
|
||||||
public class MessageStoragePull implements IMessage, IMessageHandler<MessageStoragePull, IMessage> {
|
public class MessageStoragePull implements IMessage, IMessageHandler<MessageStoragePull, IMessage>
|
||||||
|
{
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
private int z;
|
private int z;
|
||||||
@@ -18,10 +19,12 @@ public class MessageStoragePull implements IMessage, IMessageHandler<MessageStor
|
|||||||
private boolean half;
|
private boolean half;
|
||||||
private boolean shift;
|
private boolean shift;
|
||||||
|
|
||||||
public MessageStoragePull() {
|
public MessageStoragePull()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageStoragePull(int x, int y, int z, int id, boolean half, boolean shift) {
|
public MessageStoragePull(int x, int y, int z, int id, boolean half, boolean shift)
|
||||||
|
{
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
@@ -31,7 +34,8 @@ public class MessageStoragePull implements IMessage, IMessageHandler<MessageStor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
x = buf.readInt();
|
x = buf.readInt();
|
||||||
y = buf.readInt();
|
y = buf.readInt();
|
||||||
z = buf.readInt();
|
z = buf.readInt();
|
||||||
@@ -41,7 +45,8 @@ public class MessageStoragePull implements IMessage, IMessageHandler<MessageStor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
buf.writeInt(x);
|
buf.writeInt(x);
|
||||||
buf.writeInt(y);
|
buf.writeInt(y);
|
||||||
buf.writeInt(z);
|
buf.writeInt(z);
|
||||||
@@ -51,35 +56,45 @@ public class MessageStoragePull implements IMessage, IMessageHandler<MessageStor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMessage onMessage(MessageStoragePull message, MessageContext context) {
|
public IMessage onMessage(MessageStoragePull message, MessageContext context)
|
||||||
|
{
|
||||||
EntityPlayerMP player = context.getServerHandler().playerEntity;
|
EntityPlayerMP player = context.getServerHandler().playerEntity;
|
||||||
|
|
||||||
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||||
|
|
||||||
if (tile instanceof TileController) {
|
if (tile instanceof TileController)
|
||||||
|
{
|
||||||
TileController controller = (TileController) tile;
|
TileController controller = (TileController) tile;
|
||||||
|
|
||||||
if (message.id < controller.getItems().size()) {
|
if (message.id < controller.getItems().size())
|
||||||
|
{
|
||||||
StorageItem item = controller.getItems().get(message.id);
|
StorageItem item = controller.getItems().get(message.id);
|
||||||
|
|
||||||
int quantity = 64;
|
int quantity = 64;
|
||||||
|
|
||||||
if (message.half && item.getQuantity() > 1) {
|
if (message.half && item.getQuantity() > 1)
|
||||||
|
{
|
||||||
quantity = item.getQuantity() / 2;
|
quantity = item.getQuantity() / 2;
|
||||||
|
|
||||||
if (quantity > 64) {
|
if (quantity > 64)
|
||||||
|
{
|
||||||
quantity = 64;
|
quantity = 64;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack took = controller.take(item.copy(quantity).toItemStack());
|
ItemStack took = controller.take(item.copy(quantity).toItemStack());
|
||||||
|
|
||||||
if (took != null) {
|
if (took != null)
|
||||||
if (message.shift) {
|
{
|
||||||
if (!player.inventory.addItemStackToInventory(took.copy())) {
|
if (message.shift)
|
||||||
|
{
|
||||||
|
if (!player.inventory.addItemStackToInventory(took.copy()))
|
||||||
|
{
|
||||||
controller.push(took);
|
controller.push(took);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
player.inventory.setItemStack(took);
|
player.inventory.setItemStack(took);
|
||||||
player.updateHeldItem();
|
player.updateHeldItem();
|
||||||
}
|
}
|
||||||
|
@@ -9,17 +9,20 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import storagecraft.tile.TileController;
|
import storagecraft.tile.TileController;
|
||||||
|
|
||||||
public class MessageStoragePush implements IMessage, IMessageHandler<MessageStoragePush, IMessage> {
|
public class MessageStoragePush implements IMessage, IMessageHandler<MessageStoragePush, IMessage>
|
||||||
|
{
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
private int z;
|
private int z;
|
||||||
private int slot;
|
private int slot;
|
||||||
private boolean one;
|
private boolean one;
|
||||||
|
|
||||||
public MessageStoragePush() {
|
public MessageStoragePush()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageStoragePush(int x, int y, int z, int slot, boolean one) {
|
public MessageStoragePush(int x, int y, int z, int slot, boolean one)
|
||||||
|
{
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
@@ -28,7 +31,8 @@ public class MessageStoragePush implements IMessage, IMessageHandler<MessageStor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
x = buf.readInt();
|
x = buf.readInt();
|
||||||
y = buf.readInt();
|
y = buf.readInt();
|
||||||
z = buf.readInt();
|
z = buf.readInt();
|
||||||
@@ -37,7 +41,8 @@ public class MessageStoragePush implements IMessage, IMessageHandler<MessageStor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
buf.writeInt(x);
|
buf.writeInt(x);
|
||||||
buf.writeInt(y);
|
buf.writeInt(y);
|
||||||
buf.writeInt(z);
|
buf.writeInt(z);
|
||||||
@@ -46,43 +51,58 @@ public class MessageStoragePush implements IMessage, IMessageHandler<MessageStor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMessage onMessage(MessageStoragePush message, MessageContext context) {
|
public IMessage onMessage(MessageStoragePush message, MessageContext context)
|
||||||
|
{
|
||||||
EntityPlayerMP player = context.getServerHandler().playerEntity;
|
EntityPlayerMP player = context.getServerHandler().playerEntity;
|
||||||
|
|
||||||
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||||
|
|
||||||
if (tile instanceof TileController) {
|
if (tile instanceof TileController)
|
||||||
|
{
|
||||||
TileController controller = (TileController) tile;
|
TileController controller = (TileController) tile;
|
||||||
|
|
||||||
ItemStack stack;
|
ItemStack stack;
|
||||||
|
|
||||||
if (message.slot == -1) {
|
if (message.slot == -1)
|
||||||
|
{
|
||||||
stack = player.inventory.getItemStack().copy();
|
stack = player.inventory.getItemStack().copy();
|
||||||
|
|
||||||
if (message.one) {
|
if (message.one)
|
||||||
|
{
|
||||||
stack.stackSize = 1;
|
stack.stackSize = 1;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
stack = player.inventory.getStackInSlot(message.slot);
|
stack = player.inventory.getStackInSlot(message.slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack != null) {
|
if (stack != null)
|
||||||
|
{
|
||||||
boolean success = controller.push(stack);
|
boolean success = controller.push(stack);
|
||||||
|
|
||||||
if (success) {
|
if (success)
|
||||||
if (message.slot == -1) {
|
{
|
||||||
if (message.one) {
|
if (message.slot == -1)
|
||||||
|
{
|
||||||
|
if (message.one)
|
||||||
|
{
|
||||||
player.inventory.getItemStack().stackSize--;
|
player.inventory.getItemStack().stackSize--;
|
||||||
|
|
||||||
if (player.inventory.getItemStack().stackSize == 0) {
|
if (player.inventory.getItemStack().stackSize == 0)
|
||||||
|
{
|
||||||
player.inventory.setItemStack(null);
|
player.inventory.setItemStack(null);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
player.inventory.setItemStack(null);
|
player.inventory.setItemStack(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
player.updateHeldItem();
|
player.updateHeldItem();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
player.inventory.setInventorySlotContents(message.slot, null);
|
player.inventory.setInventorySlotContents(message.slot, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,47 +8,56 @@ import net.minecraft.client.Minecraft;
|
|||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import storagecraft.tile.INetworkTile;
|
import storagecraft.tile.INetworkTile;
|
||||||
|
|
||||||
public class MessageTileUpdate implements IMessage, IMessageHandler<MessageTileUpdate, IMessage> {
|
public class MessageTileUpdate implements IMessage, IMessageHandler<MessageTileUpdate, IMessage>
|
||||||
|
{
|
||||||
private TileEntity tile;
|
private TileEntity tile;
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
private int z;
|
private int z;
|
||||||
|
|
||||||
public MessageTileUpdate() {
|
public MessageTileUpdate()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageTileUpdate(TileEntity tile) {
|
public MessageTileUpdate(TileEntity tile)
|
||||||
|
{
|
||||||
this.tile = tile;
|
this.tile = tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
x = buf.readInt();
|
x = buf.readInt();
|
||||||
y = buf.readInt();
|
y = buf.readInt();
|
||||||
z = buf.readInt();
|
z = buf.readInt();
|
||||||
|
|
||||||
if (Minecraft.getMinecraft().theWorld != null) {
|
if (Minecraft.getMinecraft().theWorld != null)
|
||||||
|
{
|
||||||
tile = Minecraft.getMinecraft().theWorld.getTileEntity(x, y, z);
|
tile = Minecraft.getMinecraft().theWorld.getTileEntity(x, y, z);
|
||||||
|
|
||||||
if (tile instanceof INetworkTile) {
|
if (tile instanceof INetworkTile)
|
||||||
|
{
|
||||||
((INetworkTile) tile).fromBytes(buf);
|
((INetworkTile) tile).fromBytes(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
buf.writeInt(tile.xCoord);
|
buf.writeInt(tile.xCoord);
|
||||||
buf.writeInt(tile.yCoord);
|
buf.writeInt(tile.yCoord);
|
||||||
buf.writeInt(tile.zCoord);
|
buf.writeInt(tile.zCoord);
|
||||||
|
|
||||||
if (tile instanceof INetworkTile) {
|
if (tile instanceof INetworkTile)
|
||||||
|
{
|
||||||
((INetworkTile) tile).toBytes(buf);
|
((INetworkTile) tile).toBytes(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMessage onMessage(MessageTileUpdate message, MessageContext ctx) {
|
public IMessage onMessage(MessageTileUpdate message, MessageContext ctx)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,9 +9,11 @@ import storagecraft.render.BlockCableRenderer;
|
|||||||
import storagecraft.render.ItemCableRenderer;
|
import storagecraft.render.ItemCableRenderer;
|
||||||
import storagecraft.tile.TileCable;
|
import storagecraft.tile.TileCable;
|
||||||
|
|
||||||
public class ClientProxy extends CommonProxy {
|
public class ClientProxy extends CommonProxy
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public void preInit(FMLPreInitializationEvent e) {
|
public void preInit(FMLPreInitializationEvent e)
|
||||||
|
{
|
||||||
super.preInit(e);
|
super.preInit(e);
|
||||||
|
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer(TileCable.class, new BlockCableRenderer());
|
ClientRegistry.bindTileEntitySpecialRenderer(TileCable.class, new BlockCableRenderer());
|
||||||
|
@@ -28,8 +28,10 @@ import storagecraft.tile.TileGrid;
|
|||||||
import storagecraft.tile.TileImporter;
|
import storagecraft.tile.TileImporter;
|
||||||
import storagecraft.tile.TileStorageProxy;
|
import storagecraft.tile.TileStorageProxy;
|
||||||
|
|
||||||
public class CommonProxy {
|
public class CommonProxy
|
||||||
public void preInit(FMLPreInitializationEvent e) {
|
{
|
||||||
|
public void preInit(FMLPreInitializationEvent e)
|
||||||
|
{
|
||||||
StorageCraft.NETWORK.registerMessage(MessageTileUpdate.class, MessageTileUpdate.class, 0, Side.CLIENT);
|
StorageCraft.NETWORK.registerMessage(MessageTileUpdate.class, MessageTileUpdate.class, 0, Side.CLIENT);
|
||||||
StorageCraft.NETWORK.registerMessage(MessageRedstoneModeUpdate.class, MessageRedstoneModeUpdate.class, 1, Side.SERVER);
|
StorageCraft.NETWORK.registerMessage(MessageRedstoneModeUpdate.class, MessageRedstoneModeUpdate.class, 1, Side.SERVER);
|
||||||
StorageCraft.NETWORK.registerMessage(MessageStoragePush.class, MessageStoragePush.class, 2, Side.SERVER);
|
StorageCraft.NETWORK.registerMessage(MessageStoragePush.class, MessageStoragePush.class, 2, Side.SERVER);
|
||||||
@@ -62,9 +64,11 @@ public class CommonProxy {
|
|||||||
GameRegistry.registerItem(StorageCraftItems.STORAGE_CELL, "storageCell");
|
GameRegistry.registerItem(StorageCraftItems.STORAGE_CELL, "storageCell");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(FMLInitializationEvent e) {
|
public void init(FMLInitializationEvent e)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void postInit(FMLPostInitializationEvent e) {
|
public void postInit(FMLPostInitializationEvent e)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
package storagecraft.proxy;
|
package storagecraft.proxy;
|
||||||
|
|
||||||
public class ServerProxy extends CommonProxy {
|
public class ServerProxy extends CommonProxy
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
@@ -6,11 +6,13 @@ import org.lwjgl.opengl.GL11;
|
|||||||
import storagecraft.render.model.CableModel;
|
import storagecraft.render.model.CableModel;
|
||||||
import storagecraft.tile.TileCable;
|
import storagecraft.tile.TileCable;
|
||||||
|
|
||||||
public class BlockCableRenderer extends TileEntitySpecialRenderer {
|
public class BlockCableRenderer extends TileEntitySpecialRenderer
|
||||||
|
{
|
||||||
public static final CableModel CABLE_MODEL = new CableModel();
|
public static final CableModel CABLE_MODEL = new CableModel();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float scale) {
|
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float scale)
|
||||||
|
{
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
GL11.glTranslatef((float) x, (float) y, (float) z);
|
GL11.glTranslatef((float) x, (float) y, (float) z);
|
||||||
|
|
||||||
|
@@ -5,21 +5,25 @@ import net.minecraftforge.client.IItemRenderer;
|
|||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
import storagecraft.render.model.CableModel;
|
import storagecraft.render.model.CableModel;
|
||||||
|
|
||||||
public class ItemCableRenderer implements IItemRenderer {
|
public class ItemCableRenderer implements IItemRenderer
|
||||||
|
{
|
||||||
public static final CableModel CABLE_MODEL = new CableModel();
|
public static final CableModel CABLE_MODEL = new CableModel();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
public boolean handleRenderType(ItemStack item, ItemRenderType type)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
|
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
|
public void renderItem(ItemRenderType type, ItemStack item, Object... data)
|
||||||
|
{
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
|
|
||||||
CABLE_MODEL.render(item, 0.0625F);
|
CABLE_MODEL.render(item, 0.0625F);
|
||||||
|
@@ -8,7 +8,8 @@ import net.minecraft.util.ResourceLocation;
|
|||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
import storagecraft.tile.TileCable;
|
import storagecraft.tile.TileCable;
|
||||||
|
|
||||||
public class CableModel extends ModelBase {
|
public class CableModel extends ModelBase
|
||||||
|
{
|
||||||
public static final ResourceLocation CABLE_RESOURCE = new ResourceLocation("storagecraft:textures/blocks/cable.png");
|
public static final ResourceLocation CABLE_RESOURCE = new ResourceLocation("storagecraft:textures/blocks/cable.png");
|
||||||
public static final ResourceLocation CABLE_UNPOWERED_RESOURCE = new ResourceLocation("storagecraft:textures/blocks/cableUnpowered.png");
|
public static final ResourceLocation CABLE_UNPOWERED_RESOURCE = new ResourceLocation("storagecraft:textures/blocks/cableUnpowered.png");
|
||||||
public static final ResourceLocation CABLE_POWERED_RESOURCE = new ResourceLocation("storagecraft:textures/blocks/cablePowered.png");
|
public static final ResourceLocation CABLE_POWERED_RESOURCE = new ResourceLocation("storagecraft:textures/blocks/cablePowered.png");
|
||||||
@@ -21,7 +22,8 @@ public class CableModel extends ModelBase {
|
|||||||
private ModelRenderer south;
|
private ModelRenderer south;
|
||||||
private ModelRenderer west;
|
private ModelRenderer west;
|
||||||
|
|
||||||
public CableModel() {
|
public CableModel()
|
||||||
|
{
|
||||||
core = new ModelRenderer(this, 0, 0);
|
core = new ModelRenderer(this, 0, 0);
|
||||||
core.addBox(6F, 6F, 6F, 4, 4, 4);
|
core.addBox(6F, 6F, 6F, 4, 4, 4);
|
||||||
core.setTextureSize(16, 16);
|
core.setTextureSize(16, 16);
|
||||||
@@ -51,16 +53,21 @@ public class CableModel extends ModelBase {
|
|||||||
west.setTextureSize(16, 16);
|
west.setTextureSize(16, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(ItemStack cable, float x) {
|
public void render(ItemStack cable, float x)
|
||||||
if (cable.getItemDamage() == 1) {
|
{
|
||||||
|
if (cable.getItemDamage() == 1)
|
||||||
|
{
|
||||||
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_UNPOWERED_RESOURCE);
|
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_UNPOWERED_RESOURCE);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_RESOURCE);
|
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_RESOURCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.render(x);
|
core.render(x);
|
||||||
|
|
||||||
if (cable.getItemDamage() == 1) {
|
if (cable.getItemDamage() == 1)
|
||||||
|
{
|
||||||
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_RESOURCE);
|
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_RESOURCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,44 +75,58 @@ public class CableModel extends ModelBase {
|
|||||||
south.render(x);
|
south.render(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(TileCable cable, float x) {
|
public void render(TileCable cable, float x)
|
||||||
if (cable.isSensitiveCable()) {
|
{
|
||||||
if (cable.isPowered()) {
|
if (cable.isSensitiveCable())
|
||||||
|
{
|
||||||
|
if (cable.isPowered())
|
||||||
|
{
|
||||||
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_POWERED_RESOURCE);
|
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_POWERED_RESOURCE);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_UNPOWERED_RESOURCE);
|
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_UNPOWERED_RESOURCE);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_RESOURCE);
|
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_RESOURCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.render(x);
|
core.render(x);
|
||||||
|
|
||||||
if (cable.isSensitiveCable()) {
|
if (cable.isSensitiveCable())
|
||||||
|
{
|
||||||
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_RESOURCE);
|
Minecraft.getMinecraft().renderEngine.bindTexture(CABLE_RESOURCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cable.hasConnection(ForgeDirection.UP)) {
|
if (cable.hasConnection(ForgeDirection.UP))
|
||||||
|
{
|
||||||
up.render(x);
|
up.render(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cable.hasConnection(ForgeDirection.DOWN)) {
|
if (cable.hasConnection(ForgeDirection.DOWN))
|
||||||
|
{
|
||||||
down.render(x);
|
down.render(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cable.hasConnection(ForgeDirection.NORTH)) {
|
if (cable.hasConnection(ForgeDirection.NORTH))
|
||||||
|
{
|
||||||
north.render(x);
|
north.render(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cable.hasConnection(ForgeDirection.EAST)) {
|
if (cable.hasConnection(ForgeDirection.EAST))
|
||||||
|
{
|
||||||
east.render(x);
|
east.render(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cable.hasConnection(ForgeDirection.SOUTH)) {
|
if (cable.hasConnection(ForgeDirection.SOUTH))
|
||||||
|
{
|
||||||
south.render(x);
|
south.render(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cable.hasConnection(ForgeDirection.WEST)) {
|
if (cable.hasConnection(ForgeDirection.WEST))
|
||||||
|
{
|
||||||
west.render(x);
|
west.render(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,8 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import storagecraft.item.ItemStorageCell;
|
import storagecraft.item.ItemStorageCell;
|
||||||
|
|
||||||
public class CellStorage implements IStorage {
|
public class CellStorage implements IStorage
|
||||||
|
{
|
||||||
public static final String NBT_ITEMS = "Items";
|
public static final String NBT_ITEMS = "Items";
|
||||||
public static final String NBT_STORED = "Stored";
|
public static final String NBT_STORED = "Stored";
|
||||||
|
|
||||||
@@ -18,31 +19,37 @@ public class CellStorage implements IStorage {
|
|||||||
|
|
||||||
private ItemStack cell;
|
private ItemStack cell;
|
||||||
|
|
||||||
public CellStorage(ItemStack cell) {
|
public CellStorage(ItemStack cell)
|
||||||
|
{
|
||||||
this.cell = cell;
|
this.cell = cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addItems(List<StorageItem> items) {
|
public void addItems(List<StorageItem> items)
|
||||||
|
{
|
||||||
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
||||||
|
|
||||||
for (int i = 0; i < list.tagCount(); ++i) {
|
for (int i = 0; i < list.tagCount(); ++i)
|
||||||
|
{
|
||||||
items.add(createItemFromNBT(list.getCompoundTagAt(i)));
|
items.add(createItemFromNBT(list.getCompoundTagAt(i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void push(ItemStack stack) {
|
public void push(ItemStack stack)
|
||||||
|
{
|
||||||
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
||||||
|
|
||||||
cell.stackTagCompound.setInteger(NBT_STORED, ItemStorageCell.getStored(cell) + stack.stackSize);
|
cell.stackTagCompound.setInteger(NBT_STORED, ItemStorageCell.getStored(cell) + stack.stackSize);
|
||||||
|
|
||||||
for (int i = 0; i < list.tagCount(); ++i) {
|
for (int i = 0; i < list.tagCount(); ++i)
|
||||||
|
{
|
||||||
NBTTagCompound tag = list.getCompoundTagAt(i);
|
NBTTagCompound tag = list.getCompoundTagAt(i);
|
||||||
|
|
||||||
StorageItem item = createItemFromNBT(tag);
|
StorageItem item = createItemFromNBT(tag);
|
||||||
|
|
||||||
if (item.compareNoQuantity(stack)) {
|
if (item.compareNoQuantity(stack))
|
||||||
|
{
|
||||||
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity() + stack.stackSize);
|
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity() + stack.stackSize);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -55,7 +62,8 @@ public class CellStorage implements IStorage {
|
|||||||
tag.setInteger(NBT_ITEM_QUANTITY, stack.stackSize);
|
tag.setInteger(NBT_ITEM_QUANTITY, stack.stackSize);
|
||||||
tag.setInteger(NBT_ITEM_DAMAGE, stack.getItemDamage());
|
tag.setInteger(NBT_ITEM_DAMAGE, stack.getItemDamage());
|
||||||
|
|
||||||
if (stack.stackTagCompound != null) {
|
if (stack.stackTagCompound != null)
|
||||||
|
{
|
||||||
tag.setTag(NBT_ITEM_NBT, stack.stackTagCompound);
|
tag.setTag(NBT_ITEM_NBT, stack.stackTagCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,24 +71,29 @@ public class CellStorage implements IStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack take(ItemStack stack, int flags) {
|
public ItemStack take(ItemStack stack, int flags)
|
||||||
|
{
|
||||||
int quantity = stack.stackSize;
|
int quantity = stack.stackSize;
|
||||||
|
|
||||||
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
NBTTagList list = (NBTTagList) cell.stackTagCompound.getTag(NBT_ITEMS);
|
||||||
|
|
||||||
for (int i = 0; i < list.tagCount(); ++i) {
|
for (int i = 0; i < list.tagCount(); ++i)
|
||||||
|
{
|
||||||
NBTTagCompound tag = list.getCompoundTagAt(i);
|
NBTTagCompound tag = list.getCompoundTagAt(i);
|
||||||
|
|
||||||
StorageItem item = createItemFromNBT(tag);
|
StorageItem item = createItemFromNBT(tag);
|
||||||
|
|
||||||
if (item.compare(stack, flags)) {
|
if (item.compare(stack, flags))
|
||||||
if (quantity > item.getQuantity()) {
|
{
|
||||||
|
if (quantity > item.getQuantity())
|
||||||
|
{
|
||||||
quantity = item.getQuantity();
|
quantity = item.getQuantity();
|
||||||
}
|
}
|
||||||
|
|
||||||
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity() - quantity);
|
tag.setInteger(NBT_ITEM_QUANTITY, item.getQuantity() - quantity);
|
||||||
|
|
||||||
if (item.getQuantity() - quantity == 0) {
|
if (item.getQuantity() - quantity == 0)
|
||||||
|
{
|
||||||
list.removeTag(i);
|
list.removeTag(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,15 +111,18 @@ public class CellStorage implements IStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPush(ItemStack stack) {
|
public boolean canPush(ItemStack stack)
|
||||||
if (ItemStorageCell.getCapacity(cell) == -1) {
|
{
|
||||||
|
if (ItemStorageCell.getCapacity(cell) == -1)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (ItemStorageCell.getStored(cell) + stack.stackSize) <= ItemStorageCell.getCapacity(cell);
|
return (ItemStorageCell.getStored(cell) + stack.stackSize) <= ItemStorageCell.getCapacity(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StorageItem createItemFromNBT(NBTTagCompound tag) {
|
private StorageItem createItemFromNBT(NBTTagCompound tag)
|
||||||
|
{
|
||||||
return new StorageItem(Item.getItemById(tag.getInteger(NBT_ITEM_TYPE)), tag.getInteger(NBT_ITEM_QUANTITY), tag.getInteger(NBT_ITEM_DAMAGE), tag.hasKey(NBT_ITEM_NBT) ? ((NBTTagCompound) tag.getTag(NBT_ITEM_NBT)) : null);
|
return new StorageItem(Item.getItemById(tag.getInteger(NBT_ITEM_TYPE)), tag.getInteger(NBT_ITEM_QUANTITY), tag.getInteger(NBT_ITEM_DAMAGE), tag.hasKey(NBT_ITEM_NBT) ? ((NBTTagCompound) tag.getTag(NBT_ITEM_NBT)) : null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,8 @@ package storagecraft.storage;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public interface IStorage {
|
public interface IStorage
|
||||||
|
{
|
||||||
public void addItems(List<StorageItem> items);
|
public void addItems(List<StorageItem> items);
|
||||||
|
|
||||||
public void push(ItemStack stack);
|
public void push(ItemStack stack);
|
||||||
|
@@ -2,6 +2,7 @@ package storagecraft.storage;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface IStorageProvider {
|
public interface IStorageProvider
|
||||||
|
{
|
||||||
public void addStorages(List<IStorage> storages);
|
public void addStorages(List<IStorage> storages);
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,8 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import storagecraft.util.InventoryUtils;
|
import storagecraft.util.InventoryUtils;
|
||||||
|
|
||||||
public class StorageItem {
|
public class StorageItem
|
||||||
|
{
|
||||||
private Item type;
|
private Item type;
|
||||||
private int quantity;
|
private int quantity;
|
||||||
private int damage;
|
private int damage;
|
||||||
@@ -17,7 +18,8 @@ public class StorageItem {
|
|||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
public StorageItem(ByteBuf buf) {
|
public StorageItem(ByteBuf buf)
|
||||||
|
{
|
||||||
this.id = buf.readInt();
|
this.id = buf.readInt();
|
||||||
this.type = Item.getItemById(buf.readInt());
|
this.type = Item.getItemById(buf.readInt());
|
||||||
this.quantity = buf.readInt();
|
this.quantity = buf.readInt();
|
||||||
@@ -25,77 +27,93 @@ public class StorageItem {
|
|||||||
this.tag = buf.readBoolean() ? ByteBufUtils.readTag(buf) : null;
|
this.tag = buf.readBoolean() ? ByteBufUtils.readTag(buf) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorageItem(Item type, int quantity, int damage, NBTTagCompound tag) {
|
public StorageItem(Item type, int quantity, int damage, NBTTagCompound tag)
|
||||||
|
{
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.quantity = quantity;
|
this.quantity = quantity;
|
||||||
this.damage = damage;
|
this.damage = damage;
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorageItem(Item type, int quantity, int damage, NBTTagCompound tag, int id) {
|
public StorageItem(Item type, int quantity, int damage, NBTTagCompound tag, int id)
|
||||||
|
{
|
||||||
this(type, quantity, damage, tag);
|
this(type, quantity, damage, tag);
|
||||||
|
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorageItem(ItemStack stack) {
|
public StorageItem(ItemStack stack)
|
||||||
|
{
|
||||||
this(stack.getItem(), stack.stackSize, stack.getItemDamage(), stack.stackTagCompound);
|
this(stack.getItem(), stack.stackSize, stack.getItemDamage(), stack.stackTagCompound);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toBytes(ByteBuf buf, int id) {
|
public void toBytes(ByteBuf buf, int id)
|
||||||
|
{
|
||||||
buf.writeInt(id);
|
buf.writeInt(id);
|
||||||
buf.writeInt(Item.getIdFromItem(type));
|
buf.writeInt(Item.getIdFromItem(type));
|
||||||
buf.writeInt(quantity);
|
buf.writeInt(quantity);
|
||||||
buf.writeInt(damage);
|
buf.writeInt(damage);
|
||||||
buf.writeBoolean(tag != null);
|
buf.writeBoolean(tag != null);
|
||||||
|
|
||||||
if (tag != null) {
|
if (tag != null)
|
||||||
|
{
|
||||||
ByteBufUtils.writeTag(buf, tag);
|
ByteBufUtils.writeTag(buf, tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item getType() {
|
public Item getType()
|
||||||
|
{
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getQuantity() {
|
public int getQuantity()
|
||||||
|
{
|
||||||
return quantity;
|
return quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQuantity(int quantity) {
|
public void setQuantity(int quantity)
|
||||||
|
{
|
||||||
this.quantity = quantity;
|
this.quantity = quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDamage() {
|
public int getDamage()
|
||||||
|
{
|
||||||
return damage;
|
return damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDamage(int damage) {
|
public void setDamage(int damage)
|
||||||
|
{
|
||||||
this.damage = damage;
|
this.damage = damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTTagCompound getTag() {
|
public NBTTagCompound getTag()
|
||||||
|
{
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTag(NBTTagCompound tag) {
|
public void setTag(NBTTagCompound tag)
|
||||||
|
{
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public int getId() {
|
public int getId()
|
||||||
|
{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorageItem copy() {
|
public StorageItem copy()
|
||||||
|
{
|
||||||
return copy(quantity);
|
return copy(quantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StorageItem copy(int newQuantity) {
|
public StorageItem copy(int newQuantity)
|
||||||
|
{
|
||||||
return new StorageItem(type, newQuantity, damage, tag);
|
return new StorageItem(type, newQuantity, damage, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack toItemStack() {
|
public ItemStack toItemStack()
|
||||||
|
{
|
||||||
ItemStack stack = new ItemStack(type, quantity, damage);
|
ItemStack stack = new ItemStack(type, quantity, damage);
|
||||||
|
|
||||||
stack.stackTagCompound = tag;
|
stack.stackTagCompound = tag;
|
||||||
@@ -103,21 +121,28 @@ public class StorageItem {
|
|||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean compare(StorageItem other, int flags) {
|
public boolean compare(StorageItem other, int flags)
|
||||||
if ((flags & InventoryUtils.COMPARE_DAMAGE) == InventoryUtils.COMPARE_DAMAGE) {
|
{
|
||||||
if (damage != other.getDamage()) {
|
if ((flags & InventoryUtils.COMPARE_DAMAGE) == InventoryUtils.COMPARE_DAMAGE)
|
||||||
|
{
|
||||||
|
if (damage != other.getDamage())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & InventoryUtils.COMPARE_NBT) == InventoryUtils.COMPARE_NBT) {
|
if ((flags & InventoryUtils.COMPARE_NBT) == InventoryUtils.COMPARE_NBT)
|
||||||
if (tag != null && !tag.equals(other.getTag())) {
|
{
|
||||||
|
if (tag != null && !tag.equals(other.getTag()))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & InventoryUtils.COMPARE_QUANTITY) == InventoryUtils.COMPARE_QUANTITY) {
|
if ((flags & InventoryUtils.COMPARE_QUANTITY) == InventoryUtils.COMPARE_QUANTITY)
|
||||||
if (quantity != other.getQuantity()) {
|
{
|
||||||
|
if (quantity != other.getQuantity())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -125,21 +150,28 @@ public class StorageItem {
|
|||||||
return type == other.getType();
|
return type == other.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean compare(ItemStack stack, int flags) {
|
public boolean compare(ItemStack stack, int flags)
|
||||||
if ((flags & InventoryUtils.COMPARE_DAMAGE) == InventoryUtils.COMPARE_DAMAGE) {
|
{
|
||||||
if (damage != stack.getItemDamage()) {
|
if ((flags & InventoryUtils.COMPARE_DAMAGE) == InventoryUtils.COMPARE_DAMAGE)
|
||||||
|
{
|
||||||
|
if (damage != stack.getItemDamage())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & InventoryUtils.COMPARE_NBT) == InventoryUtils.COMPARE_NBT) {
|
if ((flags & InventoryUtils.COMPARE_NBT) == InventoryUtils.COMPARE_NBT)
|
||||||
if (tag != null && !tag.equals(stack.stackTagCompound)) {
|
{
|
||||||
|
if (tag != null && !tag.equals(stack.stackTagCompound))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & InventoryUtils.COMPARE_QUANTITY) == InventoryUtils.COMPARE_QUANTITY) {
|
if ((flags & InventoryUtils.COMPARE_QUANTITY) == InventoryUtils.COMPARE_QUANTITY)
|
||||||
if (quantity != stack.stackSize) {
|
{
|
||||||
|
if (quantity != stack.stackSize)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,11 +179,13 @@ public class StorageItem {
|
|||||||
return type == stack.getItem();
|
return type == stack.getItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean compareNoQuantity(StorageItem other) {
|
public boolean compareNoQuantity(StorageItem other)
|
||||||
|
{
|
||||||
return compare(other, InventoryUtils.COMPARE_NBT | InventoryUtils.COMPARE_DAMAGE);
|
return compare(other, InventoryUtils.COMPARE_NBT | InventoryUtils.COMPARE_DAMAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean compareNoQuantity(ItemStack stack) {
|
public boolean compareNoQuantity(ItemStack stack)
|
||||||
|
{
|
||||||
return compare(stack, InventoryUtils.COMPARE_NBT | InventoryUtils.COMPARE_DAMAGE);
|
return compare(stack, InventoryUtils.COMPARE_NBT | InventoryUtils.COMPARE_DAMAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package storagecraft.tile;
|
package storagecraft.tile;
|
||||||
|
|
||||||
public interface ICompareSetting {
|
public interface ICompareSetting
|
||||||
|
{
|
||||||
public int getCompare();
|
public int getCompare();
|
||||||
|
|
||||||
public void setCompare(int compare);
|
public void setCompare(int compare);
|
||||||
|
@@ -2,7 +2,8 @@ package storagecraft.tile;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
public interface INetworkTile {
|
public interface INetworkTile
|
||||||
|
{
|
||||||
public void fromBytes(ByteBuf buf);
|
public void fromBytes(ByteBuf buf);
|
||||||
|
|
||||||
public void toBytes(ByteBuf buf);
|
public void toBytes(ByteBuf buf);
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package storagecraft.tile;
|
package storagecraft.tile;
|
||||||
|
|
||||||
public interface IRedstoneModeSetting {
|
public interface IRedstoneModeSetting
|
||||||
|
{
|
||||||
public RedstoneMode getRedstoneMode();
|
public RedstoneMode getRedstoneMode();
|
||||||
|
|
||||||
public void setRedstoneMode(RedstoneMode mode);
|
public void setRedstoneMode(RedstoneMode mode);
|
||||||
|
@@ -2,7 +2,8 @@ package storagecraft.tile;
|
|||||||
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public enum RedstoneMode {
|
public enum RedstoneMode
|
||||||
|
{
|
||||||
IGNORE(0),
|
IGNORE(0),
|
||||||
HIGH(1),
|
HIGH(1),
|
||||||
LOW(2);
|
LOW(2);
|
||||||
@@ -11,22 +12,27 @@ public enum RedstoneMode {
|
|||||||
|
|
||||||
public final int id;
|
public final int id;
|
||||||
|
|
||||||
RedstoneMode(int id) {
|
RedstoneMode(int id)
|
||||||
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RedstoneMode next() {
|
public RedstoneMode next()
|
||||||
|
{
|
||||||
RedstoneMode next = getById(id + 1);
|
RedstoneMode next = getById(id + 1);
|
||||||
|
|
||||||
if (next == null) {
|
if (next == null)
|
||||||
|
{
|
||||||
return getById(0);
|
return getById(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled(World world, int x, int y, int z) {
|
public boolean isEnabled(World world, int x, int y, int z)
|
||||||
switch (this) {
|
{
|
||||||
|
switch (this)
|
||||||
|
{
|
||||||
case IGNORE:
|
case IGNORE:
|
||||||
return true;
|
return true;
|
||||||
case HIGH:
|
case HIGH:
|
||||||
@@ -38,9 +44,12 @@ public enum RedstoneMode {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RedstoneMode getById(int id) {
|
public static RedstoneMode getById(int id)
|
||||||
for (RedstoneMode control : values()) {
|
{
|
||||||
if (control.id == id) {
|
for (RedstoneMode control : values())
|
||||||
|
{
|
||||||
|
if (control.id == id)
|
||||||
|
{
|
||||||
return control;
|
return control;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,8 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||||||
import storagecraft.StorageCraft;
|
import storagecraft.StorageCraft;
|
||||||
import storagecraft.network.MessageTileUpdate;
|
import storagecraft.network.MessageTileUpdate;
|
||||||
|
|
||||||
public abstract class TileBase extends TileEntity {
|
public abstract class TileBase extends TileEntity
|
||||||
|
{
|
||||||
public static final int UPDATE_RANGE = 256;
|
public static final int UPDATE_RANGE = 256;
|
||||||
|
|
||||||
private ForgeDirection direction = ForgeDirection.UNKNOWN;
|
private ForgeDirection direction = ForgeDirection.UNKNOWN;
|
||||||
@@ -18,13 +19,16 @@ public abstract class TileBase extends TileEntity {
|
|||||||
protected int ticks;
|
protected int ticks;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity()
|
||||||
|
{
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
|
|
||||||
ticks++;
|
ticks++;
|
||||||
|
|
||||||
if (!worldObj.isRemote) {
|
if (!worldObj.isRemote)
|
||||||
if (this instanceof INetworkTile) {
|
{
|
||||||
|
if (this instanceof INetworkTile)
|
||||||
|
{
|
||||||
TargetPoint target = new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, UPDATE_RANGE);
|
TargetPoint target = new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, UPDATE_RANGE);
|
||||||
|
|
||||||
StorageCraft.NETWORK.sendToAllAround(new MessageTileUpdate(this), target);
|
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;
|
this.direction = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ForgeDirection getDirection() {
|
public ForgeDirection getDirection()
|
||||||
|
{
|
||||||
return direction;
|
return direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
public void readFromNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
direction = ForgeDirection.getOrientation(nbt.getInteger("Direction"));
|
direction = ForgeDirection.getOrientation(nbt.getInteger("Direction"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
public void writeToNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
nbt.setInteger("Direction", direction.ordinal());
|
nbt.setInteger("Direction", direction.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Packet getDescriptionPacket() {
|
public Packet getDescriptionPacket()
|
||||||
|
{
|
||||||
NBTTagCompound nbt = new NBTTagCompound();
|
NBTTagCompound nbt = new NBTTagCompound();
|
||||||
|
|
||||||
nbt.setInteger("Direction", direction.ordinal());
|
nbt.setInteger("Direction", direction.ordinal());
|
||||||
@@ -64,7 +73,8 @@ public abstract class TileBase extends TileEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
|
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
|
||||||
|
{
|
||||||
direction = ForgeDirection.getOrientation(packet.func_148857_g().getInteger("Direction"));
|
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 net.minecraftforge.common.util.ForgeDirection;
|
||||||
import storagecraft.block.BlockCable;
|
import storagecraft.block.BlockCable;
|
||||||
|
|
||||||
public class TileCable extends TileBase {
|
public class TileCable extends TileBase
|
||||||
public static boolean isCable(World world, int x, int y, int z, ForgeDirection dir) {
|
{
|
||||||
|
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);
|
Block block = world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
|
||||||
|
|
||||||
return block instanceof BlockCable;
|
return block instanceof BlockCable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasConnection(ForgeDirection dir) {
|
public boolean hasConnection(ForgeDirection dir)
|
||||||
if (!isCable(worldObj, xCoord, yCoord, zCoord, dir)) {
|
{
|
||||||
|
if (!isCable(worldObj, xCoord, yCoord, zCoord, dir))
|
||||||
|
{
|
||||||
TileEntity tile = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
|
TileEntity tile = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
|
||||||
|
|
||||||
return tile instanceof TileMachine || tile instanceof TileController;
|
return tile instanceof TileMachine || tile instanceof TileController;
|
||||||
@@ -25,57 +29,73 @@ public class TileCable extends TileBase {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPowered() {
|
public boolean isPowered()
|
||||||
|
{
|
||||||
return worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
|
return worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSensitiveCable() {
|
public boolean isSensitiveCable()
|
||||||
|
{
|
||||||
return worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 1;
|
return worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled()
|
||||||
if (isSensitiveCable()) {
|
{
|
||||||
|
if (isSensitiveCable())
|
||||||
|
{
|
||||||
return !isPowered();
|
return !isPowered();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMachines(List<Vec3> visited, List<TileMachine> machines, TileController controller) {
|
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) {
|
for (Vec3 visitedBlock : visited)
|
||||||
|
{
|
||||||
|
if (visitedBlock.xCoord == xCoord && visitedBlock.yCoord == yCoord && visitedBlock.zCoord == zCoord)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
visited.add(Vec3.createVectorHelper(xCoord, yCoord, zCoord));
|
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 x = xCoord + dir.offsetX;
|
||||||
int y = yCoord + dir.offsetY;
|
int y = yCoord + dir.offsetY;
|
||||||
int z = zCoord + dir.offsetZ;
|
int z = zCoord + dir.offsetZ;
|
||||||
|
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
|
||||||
for (Vec3 visitedBlock : visited) {
|
for (Vec3 visitedBlock : visited)
|
||||||
if (visitedBlock.xCoord == x && visitedBlock.yCoord == y && visitedBlock.zCoord == z) {
|
{
|
||||||
|
if (visitedBlock.xCoord == x && visitedBlock.yCoord == y && visitedBlock.zCoord == z)
|
||||||
|
{
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
TileEntity tile = worldObj.getTileEntity(x, y, z);
|
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);
|
machines.add((TileMachine) tile);
|
||||||
|
|
||||||
visited.add(Vec3.createVectorHelper(x, y, z));
|
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);
|
((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);
|
worldObj.createExplosion(null, x, y, z, 4.5f, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,8 @@ import storagecraft.storage.IStorageProvider;
|
|||||||
import storagecraft.storage.StorageItem;
|
import storagecraft.storage.StorageItem;
|
||||||
import storagecraft.util.InventoryUtils;
|
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<StorageItem> items = new ArrayList<StorageItem>();
|
||||||
private List<IStorage> storages = new ArrayList<IStorage>();
|
private List<IStorage> storages = new ArrayList<IStorage>();
|
||||||
|
|
||||||
@@ -31,42 +32,56 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
private boolean destroyed = false;
|
private boolean destroyed = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity()
|
||||||
|
{
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
|
|
||||||
if (destroyed) {
|
if (destroyed)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!worldObj.isRemote) {
|
if (!worldObj.isRemote)
|
||||||
if (ticks % 40 == 0) {
|
{
|
||||||
if (!isActive()) {
|
if (ticks % 40 == 0)
|
||||||
|
{
|
||||||
|
if (!isActive())
|
||||||
|
{
|
||||||
disconnectAll();
|
disconnectAll();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
visitedCables.clear();
|
visitedCables.clear();
|
||||||
|
|
||||||
List<TileMachine> newMachines = new ArrayList<TileMachine>();
|
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);
|
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;
|
TileCable cable = (TileCable) tile;
|
||||||
|
|
||||||
if (cable.isEnabled()) {
|
if (cable.isEnabled())
|
||||||
|
{
|
||||||
cable.addMachines(visitedCables, newMachines, this);
|
cable.addMachines(visitedCables, newMachines, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (TileMachine machine : machines) {
|
for (TileMachine machine : machines)
|
||||||
if (!newMachines.contains(machine)) {
|
{
|
||||||
|
if (!newMachines.contains(machine))
|
||||||
|
{
|
||||||
machine.onDisconnected();
|
machine.onDisconnected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (TileMachine machine : newMachines) {
|
for (TileMachine machine : newMachines)
|
||||||
if (!machines.contains(machine)) {
|
{
|
||||||
|
if (!machines.contains(machine))
|
||||||
|
{
|
||||||
machine.onConnected(this);
|
machine.onConnected(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,8 +90,10 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
|
|
||||||
storages.clear();
|
storages.clear();
|
||||||
|
|
||||||
for (TileMachine machine : machines) {
|
for (TileMachine machine : machines)
|
||||||
if (machine instanceof IStorageProvider) {
|
{
|
||||||
|
if (machine instanceof IStorageProvider)
|
||||||
|
{
|
||||||
((IStorageProvider) machine).addStorages(storages);
|
((IStorageProvider) machine).addStorages(storages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,67 +103,83 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
|
|
||||||
energyUsage = 10;
|
energyUsage = 10;
|
||||||
|
|
||||||
for (TileMachine machine : machines) {
|
for (TileMachine machine : machines)
|
||||||
|
{
|
||||||
energyUsage += machine.getEnergyUsage();
|
energyUsage += machine.getEnergyUsage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
energy.extractEnergy(energyUsage, false);
|
energy.extractEnergy(energyUsage, false);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDestroyed() {
|
public void onDestroyed()
|
||||||
|
{
|
||||||
disconnectAll();
|
disconnectAll();
|
||||||
|
|
||||||
destroyed = true;
|
destroyed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disconnectAll() {
|
private void disconnectAll()
|
||||||
for (TileMachine machine : machines) {
|
{
|
||||||
|
for (TileMachine machine : machines)
|
||||||
|
{
|
||||||
machine.onDisconnected();
|
machine.onDisconnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
machines.clear();
|
machines.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TileMachine> getMachines() {
|
public List<TileMachine> getMachines()
|
||||||
|
{
|
||||||
return machines;
|
return machines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StorageItem> getItems() {
|
public List<StorageItem> getItems()
|
||||||
|
{
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void syncItems() {
|
private void syncItems()
|
||||||
|
{
|
||||||
items.clear();
|
items.clear();
|
||||||
|
|
||||||
for (IStorage storage : storages) {
|
for (IStorage storage : storages)
|
||||||
|
{
|
||||||
storage.addItems(items);
|
storage.addItems(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
combineItems();
|
combineItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void combineItems() {
|
private void combineItems()
|
||||||
|
{
|
||||||
List<Integer> markedIndexes = new ArrayList<Integer>();
|
List<Integer> markedIndexes = new ArrayList<Integer>();
|
||||||
|
|
||||||
for (int i = 0; i < items.size(); ++i) {
|
for (int i = 0; i < items.size(); ++i)
|
||||||
if (markedIndexes.contains(i)) {
|
{
|
||||||
|
if (markedIndexes.contains(i))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageItem item = items.get(i);
|
StorageItem item = items.get(i);
|
||||||
|
|
||||||
for (int j = i + 1; j < items.size(); ++j) {
|
for (int j = i + 1; j < items.size(); ++j)
|
||||||
if (markedIndexes.contains(j)) {
|
{
|
||||||
|
if (markedIndexes.contains(j))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageItem other = items.get(j);
|
StorageItem other = items.get(j);
|
||||||
|
|
||||||
if (item.compareNoQuantity(other)) {
|
if (item.compareNoQuantity(other))
|
||||||
|
{
|
||||||
item.setQuantity(item.getQuantity() + other.getQuantity());
|
item.setQuantity(item.getQuantity() + other.getQuantity());
|
||||||
|
|
||||||
markedIndexes.add(j);
|
markedIndexes.add(j);
|
||||||
@@ -156,25 +189,30 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
|
|
||||||
List<StorageItem> markedItems = new ArrayList<StorageItem>();
|
List<StorageItem> markedItems = new ArrayList<StorageItem>();
|
||||||
|
|
||||||
for (int i : markedIndexes) {
|
for (int i : markedIndexes)
|
||||||
|
{
|
||||||
markedItems.add(items.get(i));
|
markedItems.add(items.get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
items.removeAll(markedItems);
|
items.removeAll(markedItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean push(ItemStack stack) {
|
public boolean push(ItemStack stack)
|
||||||
|
{
|
||||||
IStorage foundStorage = null;
|
IStorage foundStorage = null;
|
||||||
|
|
||||||
for (IStorage storage : storages) {
|
for (IStorage storage : storages)
|
||||||
if (storage.canPush(stack)) {
|
{
|
||||||
|
if (storage.canPush(stack))
|
||||||
|
{
|
||||||
foundStorage = storage;
|
foundStorage = storage;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundStorage == null) {
|
if (foundStorage == null)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,30 +223,38 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack take(ItemStack stack) {
|
public ItemStack take(ItemStack stack)
|
||||||
|
{
|
||||||
return take(stack, InventoryUtils.COMPARE_DAMAGE | InventoryUtils.COMPARE_NBT);
|
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 requested = stack.stackSize;
|
||||||
int receiving = 0;
|
int receiving = 0;
|
||||||
|
|
||||||
ItemStack newStack = null;
|
ItemStack newStack = null;
|
||||||
|
|
||||||
for (IStorage storage : storages) {
|
for (IStorage storage : storages)
|
||||||
|
{
|
||||||
ItemStack took = storage.take(stack, flags);
|
ItemStack took = storage.take(stack, flags);
|
||||||
|
|
||||||
if (took != null) {
|
if (took != null)
|
||||||
if (newStack == null) {
|
{
|
||||||
|
if (newStack == null)
|
||||||
|
{
|
||||||
newStack = took;
|
newStack = took;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
newStack.stackSize += took.stackSize;
|
newStack.stackSize += took.stackSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
receiving += took.stackSize;
|
receiving += took.stackSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requested == receiving) {
|
if (requested == receiving)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,18 +265,21 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
public void readFromNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
energy.readFromNBT(nbt);
|
energy.readFromNBT(nbt);
|
||||||
|
|
||||||
if (nbt.hasKey(RedstoneMode.NBT)) {
|
if (nbt.hasKey(RedstoneMode.NBT))
|
||||||
|
{
|
||||||
redstoneMode = RedstoneMode.getById(nbt.getInteger(RedstoneMode.NBT));
|
redstoneMode = RedstoneMode.getById(nbt.getInteger(RedstoneMode.NBT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
public void writeToNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
energy.writeToNBT(nbt);
|
energy.writeToNBT(nbt);
|
||||||
@@ -239,60 +288,72 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
||||||
|
{
|
||||||
return energy.receiveEnergy(maxReceive, simulate);
|
return energy.receiveEnergy(maxReceive, simulate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyStored(ForgeDirection from) {
|
public int getEnergyStored(ForgeDirection from)
|
||||||
|
{
|
||||||
return energy.getEnergyStored();
|
return energy.getEnergyStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxEnergyStored(ForgeDirection from) {
|
public int getMaxEnergyStored(ForgeDirection from)
|
||||||
|
{
|
||||||
return energy.getMaxEnergyStored();
|
return energy.getMaxEnergyStored();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage()
|
||||||
|
{
|
||||||
return energyUsage;
|
return energyUsage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canConnectEnergy(ForgeDirection from) {
|
public boolean canConnectEnergy(ForgeDirection from)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isActive() {
|
public boolean isActive()
|
||||||
|
{
|
||||||
return energy.getEnergyStored() >= getEnergyUsage() && redstoneMode.isEnabled(worldObj, xCoord, yCoord, zCoord);
|
return energy.getEnergyStored() >= getEnergyUsage() && redstoneMode.isEnabled(worldObj, xCoord, yCoord, zCoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RedstoneMode getRedstoneMode() {
|
public RedstoneMode getRedstoneMode()
|
||||||
|
{
|
||||||
return redstoneMode;
|
return redstoneMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setRedstoneMode(RedstoneMode mode) {
|
public void setRedstoneMode(RedstoneMode mode)
|
||||||
|
{
|
||||||
this.redstoneMode = mode;
|
this.redstoneMode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getX() {
|
public int getX()
|
||||||
|
{
|
||||||
return xCoord;
|
return xCoord;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getY() {
|
public int getY()
|
||||||
|
{
|
||||||
return yCoord;
|
return yCoord;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getZ() {
|
public int getZ()
|
||||||
|
{
|
||||||
return zCoord;
|
return zCoord;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
energy.setEnergyStored(buf.readInt());
|
energy.setEnergyStored(buf.readInt());
|
||||||
energyUsage = buf.readInt();
|
energyUsage = buf.readInt();
|
||||||
|
|
||||||
@@ -302,13 +363,15 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
|
|
||||||
int size = buf.readInt();
|
int size = buf.readInt();
|
||||||
|
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i)
|
||||||
|
{
|
||||||
items.add(new StorageItem(buf));
|
items.add(new StorageItem(buf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
buf.writeInt(energy.getEnergyStored());
|
buf.writeInt(energy.getEnergyStored());
|
||||||
buf.writeInt(energyUsage);
|
buf.writeInt(energyUsage);
|
||||||
|
|
||||||
@@ -316,7 +379,8 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
|||||||
|
|
||||||
buf.writeInt(items.size());
|
buf.writeInt(items.size());
|
||||||
|
|
||||||
for (StorageItem item : items) {
|
for (StorageItem item : items)
|
||||||
|
{
|
||||||
item.toBytes(buf, items.indexOf(item));
|
item.toBytes(buf, items.indexOf(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,8 @@ import storagecraft.inventory.InventorySimple;
|
|||||||
import storagecraft.storage.StorageItem;
|
import storagecraft.storage.StorageItem;
|
||||||
import storagecraft.util.InventoryUtils;
|
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_UNDER = 0;
|
||||||
public static final int MODE_EQUAL = 1;
|
public static final int MODE_EQUAL = 1;
|
||||||
public static final int MODE_ABOVE = 2;
|
public static final int MODE_ABOVE = 2;
|
||||||
@@ -28,30 +29,38 @@ public class TileDetector extends TileMachine implements IInventory, ISidedInven
|
|||||||
|
|
||||||
private boolean providesPower = false;
|
private boolean providesPower = false;
|
||||||
|
|
||||||
public TileDetector() {
|
public TileDetector()
|
||||||
|
{
|
||||||
this.redstoneControlled = false;
|
this.redstoneControlled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage()
|
||||||
|
{
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMachine() {
|
public void updateMachine()
|
||||||
if (ticks % 5 == 0) {
|
{
|
||||||
|
if (ticks % 5 == 0)
|
||||||
|
{
|
||||||
ItemStack slot = inventory.getStackInSlot(0);
|
ItemStack slot = inventory.getStackInSlot(0);
|
||||||
|
|
||||||
boolean lastProvidesPower = providesPower;
|
boolean lastProvidesPower = providesPower;
|
||||||
|
|
||||||
if (slot != null) {
|
if (slot != null)
|
||||||
|
{
|
||||||
boolean foundAny = false;
|
boolean foundAny = false;
|
||||||
|
|
||||||
for (StorageItem item : getController().getItems()) {
|
for (StorageItem item : getController().getItems())
|
||||||
if (item.compare(slot, compare)) {
|
{
|
||||||
|
if (item.compare(slot, compare))
|
||||||
|
{
|
||||||
foundAny = true;
|
foundAny = true;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode)
|
||||||
|
{
|
||||||
case MODE_UNDER:
|
case MODE_UNDER:
|
||||||
providesPower = item.getQuantity() < amount;
|
providesPower = item.getQuantity() < amount;
|
||||||
break;
|
break;
|
||||||
@@ -67,144 +76,181 @@ public class TileDetector extends TileMachine implements IInventory, ISidedInven
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!foundAny) {
|
if (!foundAny)
|
||||||
if (mode == MODE_UNDER && amount != 0) {
|
{
|
||||||
|
if (mode == MODE_UNDER && amount != 0)
|
||||||
|
{
|
||||||
providesPower = true;
|
providesPower = true;
|
||||||
} else if (mode == MODE_EQUAL && amount == 0) {
|
}
|
||||||
|
else if (mode == MODE_EQUAL && amount == 0)
|
||||||
|
{
|
||||||
providesPower = true;
|
providesPower = true;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
providesPower = false;
|
providesPower = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
providesPower = false;
|
providesPower = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (providesPower != lastProvidesPower) {
|
if (providesPower != lastProvidesPower)
|
||||||
|
{
|
||||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||||
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, StorageCraftBlocks.DETECTOR);
|
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, StorageCraftBlocks.DETECTOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean providesPower() {
|
public boolean providesPower()
|
||||||
|
{
|
||||||
return providesPower;
|
return providesPower;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCompare() {
|
public int getCompare()
|
||||||
|
{
|
||||||
return compare;
|
return compare;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCompare(int compare) {
|
public void setCompare(int compare)
|
||||||
|
{
|
||||||
this.compare = compare;
|
this.compare = compare;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMode() {
|
public int getMode()
|
||||||
|
{
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMode(int mode) {
|
public void setMode(int mode)
|
||||||
|
{
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAmount() {
|
public int getAmount()
|
||||||
|
{
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAmount(int amount) {
|
public void setAmount(int amount)
|
||||||
|
{
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSizeInventory() {
|
public int getSizeInventory()
|
||||||
|
{
|
||||||
return inventory.getSizeInventory();
|
return inventory.getSizeInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStackInSlot(int slot) {
|
public ItemStack getStackInSlot(int slot)
|
||||||
|
{
|
||||||
return inventory.getStackInSlot(slot);
|
return inventory.getStackInSlot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack decrStackSize(int slot, int amount) {
|
public ItemStack decrStackSize(int slot, int amount)
|
||||||
|
{
|
||||||
return inventory.decrStackSize(slot, amount);
|
return inventory.decrStackSize(slot, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
public ItemStack getStackInSlotOnClosing(int slot)
|
||||||
|
{
|
||||||
return inventory.getStackInSlotOnClosing(slot);
|
return inventory.getStackInSlotOnClosing(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||||
|
{
|
||||||
inventory.setInventorySlotContents(slot, stack);
|
inventory.setInventorySlotContents(slot, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInventoryName() {
|
public String getInventoryName()
|
||||||
|
{
|
||||||
return inventory.getInventoryName();
|
return inventory.getInventoryName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCustomInventoryName() {
|
public boolean hasCustomInventoryName()
|
||||||
|
{
|
||||||
return inventory.hasCustomInventoryName();
|
return inventory.hasCustomInventoryName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInventoryStackLimit() {
|
public int getInventoryStackLimit()
|
||||||
|
{
|
||||||
return inventory.getInventoryStackLimit();
|
return inventory.getInventoryStackLimit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
public boolean isUseableByPlayer(EntityPlayer player)
|
||||||
|
{
|
||||||
return inventory.isUseableByPlayer(player);
|
return inventory.isUseableByPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openInventory() {
|
public void openInventory()
|
||||||
|
{
|
||||||
inventory.openInventory();
|
inventory.openInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeInventory() {
|
public void closeInventory()
|
||||||
|
{
|
||||||
inventory.closeInventory();
|
inventory.closeInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
public boolean isItemValidForSlot(int slot, ItemStack stack)
|
||||||
|
{
|
||||||
return inventory.isItemValidForSlot(slot, stack);
|
return inventory.isItemValidForSlot(slot, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getAccessibleSlotsFromSide(int side) {
|
public int[] getAccessibleSlotsFromSide(int side)
|
||||||
return new int[] {};
|
{
|
||||||
|
return new int[]
|
||||||
|
{
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsertItem(int slot, ItemStack stack, int side) {
|
public boolean canInsertItem(int slot, ItemStack stack, int side)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtractItem(int slot, ItemStack stack, int side) {
|
public boolean canExtractItem(int slot, ItemStack stack, int side)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
public void readFromNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
if (nbt.hasKey(NBT_COMPARE)) {
|
if (nbt.hasKey(NBT_COMPARE))
|
||||||
|
{
|
||||||
compare = nbt.getInteger(NBT_COMPARE);
|
compare = nbt.getInteger(NBT_COMPARE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nbt.hasKey(NBT_MODE)) {
|
if (nbt.hasKey(NBT_MODE))
|
||||||
|
{
|
||||||
mode = nbt.getInteger(NBT_MODE);
|
mode = nbt.getInteger(NBT_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nbt.hasKey(NBT_AMOUNT)) {
|
if (nbt.hasKey(NBT_AMOUNT))
|
||||||
|
{
|
||||||
amount = nbt.getInteger(NBT_AMOUNT);
|
amount = nbt.getInteger(NBT_AMOUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +258,8 @@ public class TileDetector extends TileMachine implements IInventory, ISidedInven
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
public void writeToNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
nbt.setInteger(NBT_COMPARE, compare);
|
nbt.setInteger(NBT_COMPARE, compare);
|
||||||
@@ -223,7 +270,8 @@ public class TileDetector extends TileMachine implements IInventory, ISidedInven
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
super.fromBytes(buf);
|
super.fromBytes(buf);
|
||||||
|
|
||||||
compare = buf.readInt();
|
compare = buf.readInt();
|
||||||
@@ -233,7 +281,8 @@ public class TileDetector extends TileMachine implements IInventory, ISidedInven
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
super.toBytes(buf);
|
super.toBytes(buf);
|
||||||
|
|
||||||
buf.writeInt(compare);
|
buf.writeInt(compare);
|
||||||
|
@@ -11,15 +11,19 @@ import storagecraft.storage.IStorage;
|
|||||||
import storagecraft.storage.IStorageProvider;
|
import storagecraft.storage.IStorageProvider;
|
||||||
import storagecraft.util.InventoryUtils;
|
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);
|
private InventorySimple inventory = new InventorySimple("drive", 8);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage()
|
||||||
|
{
|
||||||
int base = 5;
|
int base = 5;
|
||||||
|
|
||||||
for (int i = 0; i < getSizeInventory(); ++i) {
|
for (int i = 0; i < getSizeInventory(); ++i)
|
||||||
if (getStackInSlot(i) != null) {
|
{
|
||||||
|
if (getStackInSlot(i) != null)
|
||||||
|
{
|
||||||
base += 2;
|
base += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,87 +32,105 @@ public class TileDrive extends TileMachine implements IInventory, IStorageProvid
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMachine() {
|
public void updateMachine()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSizeInventory() {
|
public int getSizeInventory()
|
||||||
|
{
|
||||||
return inventory.getSizeInventory();
|
return inventory.getSizeInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStackInSlot(int slot) {
|
public ItemStack getStackInSlot(int slot)
|
||||||
|
{
|
||||||
return inventory.getStackInSlot(slot);
|
return inventory.getStackInSlot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack decrStackSize(int slot, int amount) {
|
public ItemStack decrStackSize(int slot, int amount)
|
||||||
|
{
|
||||||
return inventory.decrStackSize(slot, amount);
|
return inventory.decrStackSize(slot, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
public ItemStack getStackInSlotOnClosing(int slot)
|
||||||
|
{
|
||||||
return inventory.getStackInSlotOnClosing(slot);
|
return inventory.getStackInSlotOnClosing(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||||
|
{
|
||||||
inventory.setInventorySlotContents(slot, stack);
|
inventory.setInventorySlotContents(slot, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInventoryName() {
|
public String getInventoryName()
|
||||||
|
{
|
||||||
return inventory.getInventoryName();
|
return inventory.getInventoryName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCustomInventoryName() {
|
public boolean hasCustomInventoryName()
|
||||||
|
{
|
||||||
return inventory.hasCustomInventoryName();
|
return inventory.hasCustomInventoryName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInventoryStackLimit() {
|
public int getInventoryStackLimit()
|
||||||
|
{
|
||||||
return inventory.getInventoryStackLimit();
|
return inventory.getInventoryStackLimit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
public boolean isUseableByPlayer(EntityPlayer player)
|
||||||
|
{
|
||||||
return inventory.isUseableByPlayer(player);
|
return inventory.isUseableByPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openInventory() {
|
public void openInventory()
|
||||||
|
{
|
||||||
inventory.openInventory();
|
inventory.openInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeInventory() {
|
public void closeInventory()
|
||||||
|
{
|
||||||
inventory.closeInventory();
|
inventory.closeInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
public boolean isItemValidForSlot(int slot, ItemStack stack)
|
||||||
|
{
|
||||||
return inventory.isItemValidForSlot(slot, stack);
|
return inventory.isItemValidForSlot(slot, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
public void readFromNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
InventoryUtils.restoreInventory(this, nbt);
|
InventoryUtils.restoreInventory(this, nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
public void writeToNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
InventoryUtils.saveInventory(this, nbt);
|
InventoryUtils.saveInventory(this, nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addStorages(List<IStorage> storages) {
|
public void addStorages(List<IStorage> storages)
|
||||||
for (int i = 0; i < getSizeInventory(); ++i) {
|
{
|
||||||
if (getStackInSlot(i) != null) {
|
for (int i = 0; i < getSizeInventory(); ++i)
|
||||||
|
{
|
||||||
|
if (getStackInSlot(i) != null)
|
||||||
|
{
|
||||||
storages.add(new CellStorage(getStackInSlot(i)));
|
storages.add(new CellStorage(getStackInSlot(i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,8 @@ import net.minecraft.tileentity.TileEntity;
|
|||||||
import storagecraft.inventory.InventorySimple;
|
import storagecraft.inventory.InventorySimple;
|
||||||
import storagecraft.util.InventoryUtils;
|
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";
|
public static final String NBT_COMPARE = "Compare";
|
||||||
|
|
||||||
private InventorySimple inventory = new InventorySimple("exporter", 9);
|
private InventorySimple inventory = new InventorySimple("exporter", 9);
|
||||||
@@ -18,37 +19,48 @@ public class TileExporter extends TileMachine implements IInventory, ISidedInven
|
|||||||
private int compare = 0;
|
private int compare = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage()
|
||||||
|
{
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMachine() {
|
public void updateMachine()
|
||||||
|
{
|
||||||
TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ);
|
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;
|
IInventory connectedInventory = (IInventory) tile;
|
||||||
|
|
||||||
if (ticks % 5 == 0) {
|
if (ticks % 5 == 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);
|
||||||
|
|
||||||
if (slot != null) {
|
if (slot != null)
|
||||||
|
{
|
||||||
ItemStack toTake = slot.copy();
|
ItemStack toTake = slot.copy();
|
||||||
|
|
||||||
toTake.stackSize = 64;
|
toTake.stackSize = 64;
|
||||||
|
|
||||||
ItemStack took = getController().take(toTake, compare);
|
ItemStack took = getController().take(toTake, compare);
|
||||||
|
|
||||||
if (took != null) {
|
if (took != null)
|
||||||
if (connectedInventory instanceof ISidedInventory) {
|
{
|
||||||
|
if (connectedInventory instanceof ISidedInventory)
|
||||||
|
{
|
||||||
ISidedInventory sided = (ISidedInventory) connectedInventory;
|
ISidedInventory sided = (ISidedInventory) connectedInventory;
|
||||||
|
|
||||||
boolean pushedAny = false;
|
boolean pushedAny = false;
|
||||||
|
|
||||||
for (int si = 0; si < connectedInventory.getSizeInventory(); ++si) {
|
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)) {
|
if (sided.canInsertItem(si, took, getDirection().getOpposite().ordinal()))
|
||||||
|
{ // @TODO: make more compact
|
||||||
|
if (InventoryUtils.canPushToInventorySlot(connectedInventory, si, took))
|
||||||
|
{
|
||||||
InventoryUtils.pushToInventorySlot(connectedInventory, si, took);
|
InventoryUtils.pushToInventorySlot(connectedInventory, si, took);
|
||||||
|
|
||||||
pushedAny = true;
|
pushedAny = true;
|
||||||
@@ -58,12 +70,17 @@ public class TileExporter extends TileMachine implements IInventory, ISidedInven
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pushedAny) {
|
if (!pushedAny)
|
||||||
|
{
|
||||||
getController().push(took);
|
getController().push(took);
|
||||||
}
|
}
|
||||||
} else if (InventoryUtils.canPushToInventory(connectedInventory, took)) {
|
}
|
||||||
|
else if (InventoryUtils.canPushToInventory(connectedInventory, took))
|
||||||
|
{
|
||||||
InventoryUtils.pushToInventory(connectedInventory, took);
|
InventoryUtils.pushToInventory(connectedInventory, took);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
getController().push(took);
|
getController().push(took);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,95 +91,116 @@ public class TileExporter extends TileMachine implements IInventory, ISidedInven
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCompare() {
|
public int getCompare()
|
||||||
|
{
|
||||||
return compare;
|
return compare;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCompare(int compare) {
|
public void setCompare(int compare)
|
||||||
|
{
|
||||||
this.compare = compare;
|
this.compare = compare;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSizeInventory() {
|
public int getSizeInventory()
|
||||||
|
{
|
||||||
return inventory.getSizeInventory();
|
return inventory.getSizeInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStackInSlot(int slot) {
|
public ItemStack getStackInSlot(int slot)
|
||||||
|
{
|
||||||
return inventory.getStackInSlot(slot);
|
return inventory.getStackInSlot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack decrStackSize(int slot, int amount) {
|
public ItemStack decrStackSize(int slot, int amount)
|
||||||
|
{
|
||||||
return inventory.decrStackSize(slot, amount);
|
return inventory.decrStackSize(slot, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
public ItemStack getStackInSlotOnClosing(int slot)
|
||||||
|
{
|
||||||
return inventory.getStackInSlotOnClosing(slot);
|
return inventory.getStackInSlotOnClosing(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||||
|
{
|
||||||
inventory.setInventorySlotContents(slot, stack);
|
inventory.setInventorySlotContents(slot, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInventoryName() {
|
public String getInventoryName()
|
||||||
|
{
|
||||||
return inventory.getInventoryName();
|
return inventory.getInventoryName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCustomInventoryName() {
|
public boolean hasCustomInventoryName()
|
||||||
|
{
|
||||||
return inventory.hasCustomInventoryName();
|
return inventory.hasCustomInventoryName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInventoryStackLimit() {
|
public int getInventoryStackLimit()
|
||||||
|
{
|
||||||
return inventory.getInventoryStackLimit();
|
return inventory.getInventoryStackLimit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
public boolean isUseableByPlayer(EntityPlayer player)
|
||||||
|
{
|
||||||
return inventory.isUseableByPlayer(player);
|
return inventory.isUseableByPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openInventory() {
|
public void openInventory()
|
||||||
|
{
|
||||||
inventory.openInventory();
|
inventory.openInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeInventory() {
|
public void closeInventory()
|
||||||
|
{
|
||||||
inventory.closeInventory();
|
inventory.closeInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
public boolean isItemValidForSlot(int slot, ItemStack stack)
|
||||||
|
{
|
||||||
return inventory.isItemValidForSlot(slot, stack);
|
return inventory.isItemValidForSlot(slot, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getAccessibleSlotsFromSide(int side) {
|
public int[] getAccessibleSlotsFromSide(int side)
|
||||||
return new int[] {};
|
{
|
||||||
|
return new int[]
|
||||||
|
{
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsertItem(int slot, ItemStack stack, int side) {
|
public boolean canInsertItem(int slot, ItemStack stack, int side)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtractItem(int slot, ItemStack stack, int side) {
|
public boolean canExtractItem(int slot, ItemStack stack, int side)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
public void readFromNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
if (nbt.hasKey(NBT_COMPARE)) {
|
if (nbt.hasKey(NBT_COMPARE))
|
||||||
|
{
|
||||||
compare = nbt.getInteger(NBT_COMPARE);
|
compare = nbt.getInteger(NBT_COMPARE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +208,8 @@ public class TileExporter extends TileMachine implements IInventory, ISidedInven
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
public void writeToNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
nbt.setInteger(NBT_COMPARE, compare);
|
nbt.setInteger(NBT_COMPARE, compare);
|
||||||
@@ -179,14 +218,16 @@ public class TileExporter extends TileMachine implements IInventory, ISidedInven
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
super.fromBytes(buf);
|
super.fromBytes(buf);
|
||||||
|
|
||||||
compare = buf.readInt();
|
compare = buf.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
super.toBytes(buf);
|
super.toBytes(buf);
|
||||||
|
|
||||||
buf.writeInt(compare);
|
buf.writeInt(compare);
|
||||||
|
@@ -1,12 +1,15 @@
|
|||||||
package storagecraft.tile;
|
package storagecraft.tile;
|
||||||
|
|
||||||
public class TileGrid extends TileMachine {
|
public class TileGrid extends TileMachine
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage()
|
||||||
|
{
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMachine() {
|
public void updateMachine()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,8 @@ import net.minecraft.tileentity.TileEntity;
|
|||||||
import storagecraft.inventory.InventorySimple;
|
import storagecraft.inventory.InventorySimple;
|
||||||
import storagecraft.util.InventoryUtils;
|
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_WHITELIST = 0;
|
||||||
public static final int MODE_BLACKLIST = 1;
|
public static final int MODE_BLACKLIST = 1;
|
||||||
|
|
||||||
@@ -25,38 +26,50 @@ public class TileImporter extends TileMachine implements IInventory, ISidedInven
|
|||||||
private int currentSlot = 0;
|
private int currentSlot = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage()
|
||||||
|
{
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMachine() {
|
public void updateMachine()
|
||||||
|
{
|
||||||
TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ);
|
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;
|
IInventory connectedInventory = (IInventory) tile;
|
||||||
|
|
||||||
if (ticks % 5 == 0) {
|
if (ticks % 5 == 0)
|
||||||
|
{
|
||||||
ItemStack slot = connectedInventory.getStackInSlot(currentSlot);
|
ItemStack slot = connectedInventory.getStackInSlot(currentSlot);
|
||||||
|
|
||||||
while ((slot = connectedInventory.getStackInSlot(currentSlot)) == null) {
|
while ((slot = connectedInventory.getStackInSlot(currentSlot)) == null)
|
||||||
|
{
|
||||||
currentSlot++;
|
currentSlot++;
|
||||||
|
|
||||||
if (currentSlot > connectedInventory.getSizeInventory() - 1) {
|
if (currentSlot > connectedInventory.getSizeInventory() - 1)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slot != null && canImport(slot)) {
|
if (slot != null && canImport(slot))
|
||||||
if (connectedInventory instanceof ISidedInventory) {
|
{
|
||||||
|
if (connectedInventory instanceof ISidedInventory)
|
||||||
|
{
|
||||||
ISidedInventory sided = (ISidedInventory) connectedInventory;
|
ISidedInventory sided = (ISidedInventory) connectedInventory;
|
||||||
|
|
||||||
if (sided.canExtractItem(currentSlot, slot.copy(), getDirection().getOpposite().ordinal())) {
|
if (sided.canExtractItem(currentSlot, slot.copy(), getDirection().getOpposite().ordinal()))
|
||||||
if (getController().push(slot.copy())) {
|
{
|
||||||
|
if (getController().push(slot.copy()))
|
||||||
|
{
|
||||||
connectedInventory.setInventorySlotContents(currentSlot, null);
|
connectedInventory.setInventorySlotContents(currentSlot, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (getController().push(slot.copy())) {
|
}
|
||||||
|
else if (getController().push(slot.copy()))
|
||||||
|
{
|
||||||
connectedInventory.setInventorySlotContents(currentSlot, null);
|
connectedInventory.setInventorySlotContents(currentSlot, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,33 +78,42 @@ public class TileImporter extends TileMachine implements IInventory, ISidedInven
|
|||||||
|
|
||||||
currentSlot++;
|
currentSlot++;
|
||||||
|
|
||||||
if (currentSlot > connectedInventory.getSizeInventory() - 1) {
|
if (currentSlot > connectedInventory.getSizeInventory() - 1)
|
||||||
|
{
|
||||||
currentSlot = 0;
|
currentSlot = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canImport(ItemStack stack) {
|
public boolean canImport(ItemStack stack)
|
||||||
|
{
|
||||||
int slots = 0;
|
int slots = 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);
|
||||||
|
|
||||||
if (slot != null) {
|
if (slot != null)
|
||||||
|
{
|
||||||
slots++;
|
slots++;
|
||||||
|
|
||||||
if (InventoryUtils.compareStack(stack, slot, compare)) {
|
if (InventoryUtils.compareStack(stack, slot, compare))
|
||||||
if (mode == MODE_WHITELIST) {
|
{
|
||||||
|
if (mode == MODE_WHITELIST)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
} else if (mode == MODE_BLACKLIST) {
|
}
|
||||||
|
else if (mode == MODE_BLACKLIST)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == MODE_WHITELIST) {
|
if (mode == MODE_WHITELIST)
|
||||||
|
{
|
||||||
return slots == 0;
|
return slots == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,107 +121,131 @@ public class TileImporter extends TileMachine implements IInventory, ISidedInven
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCompare() {
|
public int getCompare()
|
||||||
|
{
|
||||||
return compare;
|
return compare;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCompare(int compare) {
|
public void setCompare(int compare)
|
||||||
|
{
|
||||||
this.compare = compare;
|
this.compare = compare;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMode() {
|
public int getMode()
|
||||||
|
{
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMode(int mode) {
|
public void setMode(int mode)
|
||||||
|
{
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSizeInventory() {
|
public int getSizeInventory()
|
||||||
|
{
|
||||||
return inventory.getSizeInventory();
|
return inventory.getSizeInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStackInSlot(int slot) {
|
public ItemStack getStackInSlot(int slot)
|
||||||
|
{
|
||||||
return inventory.getStackInSlot(slot);
|
return inventory.getStackInSlot(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack decrStackSize(int slot, int amount) {
|
public ItemStack decrStackSize(int slot, int amount)
|
||||||
|
{
|
||||||
return inventory.decrStackSize(slot, amount);
|
return inventory.decrStackSize(slot, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
public ItemStack getStackInSlotOnClosing(int slot)
|
||||||
|
{
|
||||||
return inventory.getStackInSlotOnClosing(slot);
|
return inventory.getStackInSlotOnClosing(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||||
|
{
|
||||||
inventory.setInventorySlotContents(slot, stack);
|
inventory.setInventorySlotContents(slot, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getInventoryName() {
|
public String getInventoryName()
|
||||||
|
{
|
||||||
return inventory.getInventoryName();
|
return inventory.getInventoryName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCustomInventoryName() {
|
public boolean hasCustomInventoryName()
|
||||||
|
{
|
||||||
return inventory.hasCustomInventoryName();
|
return inventory.hasCustomInventoryName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getInventoryStackLimit() {
|
public int getInventoryStackLimit()
|
||||||
|
{
|
||||||
return inventory.getInventoryStackLimit();
|
return inventory.getInventoryStackLimit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
public boolean isUseableByPlayer(EntityPlayer player)
|
||||||
|
{
|
||||||
return inventory.isUseableByPlayer(player);
|
return inventory.isUseableByPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void openInventory() {
|
public void openInventory()
|
||||||
|
{
|
||||||
inventory.openInventory();
|
inventory.openInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeInventory() {
|
public void closeInventory()
|
||||||
|
{
|
||||||
inventory.closeInventory();
|
inventory.closeInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
public boolean isItemValidForSlot(int slot, ItemStack stack)
|
||||||
|
{
|
||||||
return inventory.isItemValidForSlot(slot, stack);
|
return inventory.isItemValidForSlot(slot, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getAccessibleSlotsFromSide(int side) {
|
public int[] getAccessibleSlotsFromSide(int side)
|
||||||
return new int[] {};
|
{
|
||||||
|
return new int[]
|
||||||
|
{
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsertItem(int slot, ItemStack stack, int side) {
|
public boolean canInsertItem(int slot, ItemStack stack, int side)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExtractItem(int slot, ItemStack stack, int side) {
|
public boolean canExtractItem(int slot, ItemStack stack, int side)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
public void readFromNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
if (nbt.hasKey(NBT_COMPARE)) {
|
if (nbt.hasKey(NBT_COMPARE))
|
||||||
|
{
|
||||||
compare = nbt.getInteger(NBT_COMPARE);
|
compare = nbt.getInteger(NBT_COMPARE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nbt.hasKey(NBT_MODE)) {
|
if (nbt.hasKey(NBT_MODE))
|
||||||
|
{
|
||||||
mode = nbt.getInteger(NBT_MODE);
|
mode = nbt.getInteger(NBT_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +253,8 @@ public class TileImporter extends TileMachine implements IInventory, ISidedInven
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
public void writeToNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
nbt.setInteger(NBT_COMPARE, compare);
|
nbt.setInteger(NBT_COMPARE, compare);
|
||||||
@@ -217,7 +264,8 @@ public class TileImporter extends TileMachine implements IInventory, ISidedInven
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
super.fromBytes(buf);
|
super.fromBytes(buf);
|
||||||
|
|
||||||
compare = buf.readInt();
|
compare = buf.readInt();
|
||||||
@@ -225,7 +273,8 @@ public class TileImporter extends TileMachine implements IInventory, ISidedInven
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
super.toBytes(buf);
|
super.toBytes(buf);
|
||||||
|
|
||||||
buf.writeInt(compare);
|
buf.writeInt(compare);
|
||||||
|
@@ -3,7 +3,8 @@ package storagecraft.tile;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
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 connected = false;
|
||||||
protected boolean redstoneControlled = true;
|
protected boolean redstoneControlled = true;
|
||||||
|
|
||||||
@@ -13,7 +14,8 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
private int yController;
|
private int yController;
|
||||||
private int zController;
|
private int zController;
|
||||||
|
|
||||||
public void onConnected(TileController controller) {
|
public void onConnected(TileController controller)
|
||||||
|
{
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
|
|
||||||
this.xController = controller.xCoord;
|
this.xController = controller.xCoord;
|
||||||
@@ -23,61 +25,74 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDisconnected() {
|
public void onDisconnected()
|
||||||
|
{
|
||||||
this.connected = false;
|
this.connected = false;
|
||||||
|
|
||||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity()
|
||||||
|
{
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
|
|
||||||
if (!worldObj.isRemote && isConnected()) {
|
if (!worldObj.isRemote && isConnected())
|
||||||
|
{
|
||||||
updateMachine();
|
updateMachine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isConnected() {
|
public boolean isConnected()
|
||||||
|
{
|
||||||
return connected;
|
return connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RedstoneMode getRedstoneMode() {
|
public RedstoneMode getRedstoneMode()
|
||||||
|
{
|
||||||
return redstoneMode;
|
return redstoneMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setRedstoneMode(RedstoneMode mode) {
|
public void setRedstoneMode(RedstoneMode mode)
|
||||||
if (redstoneControlled) {
|
{
|
||||||
|
if (redstoneControlled)
|
||||||
|
{
|
||||||
this.redstoneMode = mode;
|
this.redstoneMode = mode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getX() {
|
public int getX()
|
||||||
|
{
|
||||||
return xCoord;
|
return xCoord;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getY() {
|
public int getY()
|
||||||
|
{
|
||||||
return yCoord;
|
return yCoord;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getZ() {
|
public int getZ()
|
||||||
|
{
|
||||||
return zCoord;
|
return zCoord;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TileController getController() {
|
public TileController getController()
|
||||||
|
{
|
||||||
return (TileController) worldObj.getTileEntity(xController, yController, zController);
|
return (TileController) worldObj.getTileEntity(xController, yController, zController);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf) {
|
public void fromBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
connected = buf.readBoolean();
|
connected = buf.readBoolean();
|
||||||
|
|
||||||
if (connected) {
|
if (connected)
|
||||||
|
{
|
||||||
xController = buf.readInt();
|
xController = buf.readInt();
|
||||||
yController = buf.readInt();
|
yController = buf.readInt();
|
||||||
zController = buf.readInt();
|
zController = buf.readInt();
|
||||||
@@ -87,10 +102,12 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf) {
|
public void toBytes(ByteBuf buf)
|
||||||
|
{
|
||||||
buf.writeBoolean(connected);
|
buf.writeBoolean(connected);
|
||||||
|
|
||||||
if (connected) {
|
if (connected)
|
||||||
|
{
|
||||||
buf.writeInt(xController);
|
buf.writeInt(xController);
|
||||||
buf.writeInt(yController);
|
buf.writeInt(yController);
|
||||||
buf.writeInt(zController);
|
buf.writeInt(zController);
|
||||||
@@ -100,16 +117,19 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbt) {
|
public void readFromNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
super.readFromNBT(nbt);
|
super.readFromNBT(nbt);
|
||||||
|
|
||||||
if (nbt.hasKey(RedstoneMode.NBT)) {
|
if (nbt.hasKey(RedstoneMode.NBT))
|
||||||
|
{
|
||||||
redstoneMode = RedstoneMode.getById(nbt.getInteger(RedstoneMode.NBT));
|
redstoneMode = RedstoneMode.getById(nbt.getInteger(RedstoneMode.NBT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound nbt) {
|
public void writeToNBT(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
super.writeToNBT(nbt);
|
super.writeToNBT(nbt);
|
||||||
|
|
||||||
nbt.setInteger(RedstoneMode.NBT, redstoneMode.id);
|
nbt.setInteger(RedstoneMode.NBT, redstoneMode.id);
|
||||||
|
@@ -9,11 +9,14 @@ import storagecraft.storage.IStorageProvider;
|
|||||||
import storagecraft.storage.StorageItem;
|
import storagecraft.storage.StorageItem;
|
||||||
import storagecraft.util.InventoryUtils;
|
import storagecraft.util.InventoryUtils;
|
||||||
|
|
||||||
public class TileStorageProxy extends TileMachine implements IStorageProvider, IStorage {
|
public class TileStorageProxy extends TileMachine implements IStorageProvider, IStorage
|
||||||
public IInventory getInventory() {
|
{
|
||||||
|
public IInventory getInventory()
|
||||||
|
{
|
||||||
TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ);
|
TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ);
|
||||||
|
|
||||||
if (tile instanceof IInventory) {
|
if (tile instanceof IInventory)
|
||||||
|
{
|
||||||
return (IInventory) tile;
|
return (IInventory) tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,21 +24,27 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage()
|
||||||
|
{
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMachine() {
|
public void updateMachine()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addItems(List<StorageItem> items) {
|
public void addItems(List<StorageItem> items)
|
||||||
|
{
|
||||||
IInventory inventory = getInventory();
|
IInventory inventory = getInventory();
|
||||||
|
|
||||||
if (inventory != null) {
|
if (inventory != null)
|
||||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
{
|
||||||
if (inventory.getStackInSlot(i) != null) {
|
for (int i = 0; i < inventory.getSizeInventory(); ++i)
|
||||||
|
{
|
||||||
|
if (inventory.getStackInSlot(i) != null)
|
||||||
|
{
|
||||||
items.add(new StorageItem(inventory.getStackInSlot(i)));
|
items.add(new StorageItem(inventory.getStackInSlot(i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,10 +52,12 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void push(ItemStack stack) {
|
public void push(ItemStack stack)
|
||||||
|
{
|
||||||
IInventory inventory = getInventory();
|
IInventory inventory = getInventory();
|
||||||
|
|
||||||
if (inventory == null) {
|
if (inventory == null)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,26 +65,32 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack take(ItemStack stack, int flags) {
|
public ItemStack take(ItemStack stack, int flags)
|
||||||
|
{
|
||||||
IInventory inventory = getInventory();
|
IInventory inventory = getInventory();
|
||||||
|
|
||||||
if (inventory == null) {
|
if (inventory == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int quantity = stack.stackSize;
|
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);
|
ItemStack slot = inventory.getStackInSlot(i);
|
||||||
|
|
||||||
if (slot != null && InventoryUtils.compareStack(slot, stack, flags)) {
|
if (slot != null && InventoryUtils.compareStack(slot, stack, flags))
|
||||||
if (quantity > slot.stackSize) {
|
{
|
||||||
|
if (quantity > slot.stackSize)
|
||||||
|
{
|
||||||
quantity = slot.stackSize;
|
quantity = slot.stackSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
slot.stackSize -= quantity;
|
slot.stackSize -= quantity;
|
||||||
|
|
||||||
if (slot.stackSize == 0) {
|
if (slot.stackSize == 0)
|
||||||
|
{
|
||||||
inventory.setInventorySlotContents(i, null);
|
inventory.setInventorySlotContents(i, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,10 +106,12 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPush(ItemStack stack) {
|
public boolean canPush(ItemStack stack)
|
||||||
|
{
|
||||||
IInventory inventory = getInventory();
|
IInventory inventory = getInventory();
|
||||||
|
|
||||||
if (inventory == null) {
|
if (inventory == null)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +119,8 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addStorages(List<IStorage> storages) {
|
public void addStorages(List<IStorage> storages)
|
||||||
|
{
|
||||||
storages.add(this);
|
storages.add(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,8 @@ import net.minecraft.nbt.NBTTagList;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.Constants;
|
import net.minecraftforge.common.util.Constants;
|
||||||
|
|
||||||
public class InventoryUtils {
|
public class InventoryUtils
|
||||||
|
{
|
||||||
public static final String NBT_INVENTORY = "Inventory";
|
public static final String NBT_INVENTORY = "Inventory";
|
||||||
public static final String NBT_SLOT = "Slot";
|
public static final String NBT_SLOT = "Slot";
|
||||||
|
|
||||||
@@ -17,11 +18,14 @@ public class InventoryUtils {
|
|||||||
public static final int COMPARE_NBT = 2;
|
public static final int COMPARE_NBT = 2;
|
||||||
public static final int COMPARE_QUANTITY = 4;
|
public static final int COMPARE_QUANTITY = 4;
|
||||||
|
|
||||||
public static void saveInventory(IInventory inventory, NBTTagCompound nbt) {
|
public static void saveInventory(IInventory inventory, NBTTagCompound nbt)
|
||||||
|
{
|
||||||
NBTTagList tagList = new NBTTagList();
|
NBTTagList tagList = new NBTTagList();
|
||||||
|
|
||||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||||
if (inventory.getStackInSlot(i) != null) {
|
{
|
||||||
|
if (inventory.getStackInSlot(i) != null)
|
||||||
|
{
|
||||||
NBTTagCompound compoundTag = new NBTTagCompound();
|
NBTTagCompound compoundTag = new NBTTagCompound();
|
||||||
|
|
||||||
compoundTag.setInteger(NBT_SLOT, i);
|
compoundTag.setInteger(NBT_SLOT, i);
|
||||||
@@ -35,11 +39,14 @@ public class InventoryUtils {
|
|||||||
nbt.setTag(NBT_INVENTORY, tagList);
|
nbt.setTag(NBT_INVENTORY, tagList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void restoreInventory(IInventory inventory, NBTTagCompound nbt) {
|
public static void restoreInventory(IInventory inventory, NBTTagCompound nbt)
|
||||||
if (nbt.hasKey(NBT_INVENTORY)) {
|
{
|
||||||
|
if (nbt.hasKey(NBT_INVENTORY))
|
||||||
|
{
|
||||||
NBTTagList tagList = nbt.getTagList(NBT_INVENTORY, Constants.NBT.TAG_COMPOUND);
|
NBTTagList tagList = nbt.getTagList(NBT_INVENTORY, Constants.NBT.TAG_COMPOUND);
|
||||||
|
|
||||||
for (int i = 0; i < tagList.tagCount(); i++) {
|
for (int i = 0; i < tagList.tagCount(); i++)
|
||||||
|
{
|
||||||
int slot = tagList.getCompoundTagAt(i).getInteger(NBT_SLOT);
|
int slot = tagList.getCompoundTagAt(i).getInteger(NBT_SLOT);
|
||||||
|
|
||||||
ItemStack stack = ItemStack.loadItemStackFromNBT(tagList.getCompoundTagAt(i));
|
ItemStack stack = ItemStack.loadItemStackFromNBT(tagList.getCompoundTagAt(i));
|
||||||
@@ -50,13 +57,16 @@ public class InventoryUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/cpw/ironchest/blob/master/src/main/java/cpw/mods/ironchest/BlockIronChest.java#L200
|
// https://github.com/cpw/ironchest/blob/master/src/main/java/cpw/mods/ironchest/BlockIronChest.java#L200
|
||||||
public static void dropInventory(World world, IInventory inventory, int x, int y, int z) {
|
public static void dropInventory(World world, IInventory inventory, int x, int y, int z)
|
||||||
|
{
|
||||||
Random random = world.rand;
|
Random random = world.rand;
|
||||||
|
|
||||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
for (int i = 0; i < inventory.getSizeInventory(); ++i)
|
||||||
|
{
|
||||||
ItemStack stack = inventory.getStackInSlot(i);
|
ItemStack stack = inventory.getStackInSlot(i);
|
||||||
|
|
||||||
if (stack == null) {
|
if (stack == null)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,10 +74,12 @@ public class InventoryUtils {
|
|||||||
float yo = random.nextFloat() * 0.8F + 0.1F;
|
float yo = random.nextFloat() * 0.8F + 0.1F;
|
||||||
float zo = random.nextFloat() * 0.8F + 0.1F;
|
float zo = random.nextFloat() * 0.8F + 0.1F;
|
||||||
|
|
||||||
while (stack.stackSize > 0) {
|
while (stack.stackSize > 0)
|
||||||
|
{
|
||||||
int amount = random.nextInt(21) + 10;
|
int amount = random.nextInt(21) + 10;
|
||||||
|
|
||||||
if (amount > stack.stackSize) {
|
if (amount > stack.stackSize)
|
||||||
|
{
|
||||||
amount = stack.stackSize;
|
amount = stack.stackSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +91,8 @@ public class InventoryUtils {
|
|||||||
entity.motionY = (float) random.nextGaussian() * 0.05F + 0.2F;
|
entity.motionY = (float) random.nextGaussian() * 0.05F + 0.2F;
|
||||||
entity.motionZ = (float) random.nextGaussian() * 0.05F;
|
entity.motionZ = (float) random.nextGaussian() * 0.05F;
|
||||||
|
|
||||||
if (stack.hasTagCompound()) {
|
if (stack.hasTagCompound())
|
||||||
|
{
|
||||||
entity.getEntityItem().setTagCompound((NBTTagCompound) stack.getTagCompound().copy());
|
entity.getEntityItem().setTagCompound((NBTTagCompound) stack.getTagCompound().copy());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,44 +101,57 @@ public class InventoryUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void pushToInventorySlot(IInventory inventory, int i, ItemStack stack) {
|
public static void pushToInventorySlot(IInventory inventory, int i, ItemStack stack)
|
||||||
|
{
|
||||||
ItemStack slot = inventory.getStackInSlot(i);
|
ItemStack slot = inventory.getStackInSlot(i);
|
||||||
|
|
||||||
if (slot == null) {
|
if (slot == null)
|
||||||
|
{
|
||||||
inventory.setInventorySlotContents(i, stack);
|
inventory.setInventorySlotContents(i, stack);
|
||||||
} else if (compareStackNoQuantity(slot, stack)) {
|
}
|
||||||
|
else if (compareStackNoQuantity(slot, stack))
|
||||||
|
{
|
||||||
slot.stackSize += stack.stackSize;
|
slot.stackSize += stack.stackSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canPushToInventorySlot(IInventory inventory, int i, ItemStack stack) {
|
public static boolean canPushToInventorySlot(IInventory inventory, int i, ItemStack stack)
|
||||||
|
{
|
||||||
ItemStack slot = inventory.getStackInSlot(i);
|
ItemStack slot = inventory.getStackInSlot(i);
|
||||||
|
|
||||||
if (slot == null) {
|
if (slot == null)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!compareStackNoQuantity(slot, stack)) {
|
if (!compareStackNoQuantity(slot, stack))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return slot.stackSize + stack.stackSize < slot.getMaxStackSize();
|
return slot.stackSize + stack.stackSize < slot.getMaxStackSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void pushToInventory(IInventory inventory, ItemStack stack) {
|
public static void pushToInventory(IInventory inventory, ItemStack stack)
|
||||||
|
{
|
||||||
int toGo = stack.stackSize;
|
int toGo = stack.stackSize;
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
if (slot == null) {
|
if (slot == null)
|
||||||
|
{
|
||||||
inventory.setInventorySlotContents(i, stack);
|
inventory.setInventorySlotContents(i, stack);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else if (compareStackNoQuantity(slot, stack)) {
|
}
|
||||||
|
else if (compareStackNoQuantity(slot, stack))
|
||||||
|
{
|
||||||
int toAdd = toGo;
|
int toAdd = toGo;
|
||||||
|
|
||||||
if (slot.stackSize + toAdd > slot.getMaxStackSize()) {
|
if (slot.stackSize + toAdd > slot.getMaxStackSize())
|
||||||
|
{
|
||||||
toAdd = slot.getMaxStackSize() - slot.stackSize;
|
toAdd = slot.getMaxStackSize() - slot.stackSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,31 +159,39 @@ public class InventoryUtils {
|
|||||||
|
|
||||||
toGo -= toAdd;
|
toGo -= toAdd;
|
||||||
|
|
||||||
if (toGo == 0) {
|
if (toGo == 0)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canPushToInventory(IInventory inventory, ItemStack stack) {
|
public static boolean canPushToInventory(IInventory inventory, ItemStack stack)
|
||||||
|
{
|
||||||
int toGo = stack.stackSize;
|
int toGo = stack.stackSize;
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
if (slot == null) {
|
if (slot == null)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
} else if (compareStackNoQuantity(slot, stack)) {
|
}
|
||||||
|
else if (compareStackNoQuantity(slot, stack))
|
||||||
|
{
|
||||||
int toAdd = toGo;
|
int toAdd = toGo;
|
||||||
|
|
||||||
if (slot.stackSize + toAdd > slot.getMaxStackSize()) {
|
if (slot.stackSize + toAdd > slot.getMaxStackSize())
|
||||||
|
{
|
||||||
toAdd = slot.getMaxStackSize() - slot.stackSize;
|
toAdd = slot.getMaxStackSize() - slot.stackSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
toGo -= toAdd;
|
toGo -= toAdd;
|
||||||
|
|
||||||
if (toGo == 0) {
|
if (toGo == 0)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,25 +200,33 @@ public class InventoryUtils {
|
|||||||
return toGo == 0;
|
return toGo == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean compareStack(ItemStack first, ItemStack second) {
|
public static boolean compareStack(ItemStack first, ItemStack second)
|
||||||
|
{
|
||||||
return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE | COMPARE_QUANTITY);
|
return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE | COMPARE_QUANTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean compareStack(ItemStack first, ItemStack second, int flags) {
|
public static boolean compareStack(ItemStack first, ItemStack second, int flags)
|
||||||
if ((flags & COMPARE_DAMAGE) == COMPARE_DAMAGE) {
|
{
|
||||||
if (first.getItemDamage() != second.getItemDamage()) {
|
if ((flags & COMPARE_DAMAGE) == COMPARE_DAMAGE)
|
||||||
|
{
|
||||||
|
if (first.getItemDamage() != second.getItemDamage())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & COMPARE_NBT) == COMPARE_NBT) {
|
if ((flags & COMPARE_NBT) == COMPARE_NBT)
|
||||||
if (first.stackTagCompound != null && !first.stackTagCompound.equals(second.stackTagCompound)) {
|
{
|
||||||
|
if (first.stackTagCompound != null && !first.stackTagCompound.equals(second.stackTagCompound))
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & COMPARE_QUANTITY) == COMPARE_QUANTITY) {
|
if ((flags & COMPARE_QUANTITY) == COMPARE_QUANTITY)
|
||||||
if (first.stackSize != second.stackSize) {
|
{
|
||||||
|
if (first.stackSize != second.stackSize)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,7 +234,8 @@ public class InventoryUtils {
|
|||||||
return first.getItem() == second.getItem();
|
return first.getItem() == second.getItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean compareStackNoQuantity(ItemStack first, ItemStack second) {
|
public static boolean compareStackNoQuantity(ItemStack first, ItemStack second)
|
||||||
|
{
|
||||||
return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE);
|
return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user