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