wireless grid

This commit is contained in:
Raoul Van den Berge
2015-12-22 18:13:41 +01:00
parent 1dfe250ddc
commit 22c036141c
6 changed files with 145 additions and 1 deletions

View File

@@ -1,8 +1,10 @@
package storagecraft;
import storagecraft.item.ItemStorageCell;
import storagecraft.item.ItemWirelessGrid;
public class StorageCraftItems
{
public static final ItemStorageCell STORAGE_CELL = new ItemStorageCell();
public static final ItemWirelessGrid WIRELESS_GRID = new ItemWirelessGrid();
}

View File

@@ -0,0 +1,135 @@
package storagecraft.item;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import storagecraft.StorageCraft;
import storagecraft.tile.TileGrid;
public class ItemWirelessGrid extends ItemBase
{
public static final String NBT_GRID_X = "GridX";
public static final String NBT_GRID_Y = "GridY";
public static final String NBT_GRID_Z = "GridZ";
private IIcon iconConnected;
private IIcon iconDisconnected;
public ItemWirelessGrid()
{
super("wirelessGrid");
setMaxStackSize(1);
}
@Override
public void registerIcons(IIconRegister register)
{
iconConnected = register.registerIcon("storagecraft:wirelessGridConnected");
iconDisconnected = register.registerIcon("storagecraft:wirelessGridDisconnected");
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote)
{
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileGrid)
{
stack.stackTagCompound = new NBTTagCompound();
stack.stackTagCompound.setInteger(NBT_GRID_X, x);
stack.stackTagCompound.setInteger(NBT_GRID_Y, y);
stack.stackTagCompound.setInteger(NBT_GRID_Z, z);
player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocalFormatted("misc.storagecraft:wirelessGrid.set", x, y, z)));
return true;
}
}
return super.onItemUseFirst(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
if (!world.isRemote)
{
if (isValid(stack))
{
if (isInRange(stack, player))
{
int x = getX(stack);
int y = getY(stack);
int z = getZ(stack);
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileGrid)
{
player.openGui(StorageCraft.INSTANCE, StorageCraft.GUI.GRID, world, x, y, z);
}
else
{
player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocal("misc.storagecraft:wirelessGrid.notFound")));
}
}
else
{
player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocal("misc.storagecraft:wirelessGrid.outOfRange")));
}
}
else
{
player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocal("misc.storagecraft:wirelessGrid.notSet")));
}
}
return stack;
}
public int getX(ItemStack stack)
{
return stack.stackTagCompound.getInteger(NBT_GRID_X);
}
public int getY(ItemStack stack)
{
return stack.stackTagCompound.getInteger(NBT_GRID_Y);
}
public int getZ(ItemStack stack)
{
return stack.stackTagCompound.getInteger(NBT_GRID_Z);
}
public boolean isInRange(ItemStack stack, EntityPlayer player)
{
return (int) Math.sqrt(Math.pow(getX(stack) - player.posX, 2) + Math.pow(getY(stack) - player.posY, 2) + Math.pow(getZ(stack) - player.posZ, 2)) < 64;
}
public boolean isValid(ItemStack stack)
{
return stack.stackTagCompound != null && stack.stackTagCompound.hasKey(NBT_GRID_X) && stack.stackTagCompound.hasKey(NBT_GRID_Y) && stack.stackTagCompound.hasKey(NBT_GRID_Z);
}
@Override
public IIcon getIcon(ItemStack stack, int pass)
{
return getIconIndex(stack);
}
@Override
public IIcon getIconIndex(ItemStack stack)
{
return isValid(stack) ? iconConnected : iconDisconnected;
}
}

View File

@@ -65,6 +65,7 @@ public class CommonProxy
GameRegistry.registerBlock(StorageCraftBlocks.DETECTOR, "detector");
GameRegistry.registerItem(StorageCraftItems.STORAGE_CELL, "storageCell");
GameRegistry.registerItem(StorageCraftItems.WIRELESS_GRID, "wirelessGrid");
}
public void init(FMLInitializationEvent e)

View File

@@ -14,6 +14,11 @@ misc.storagecraft:energyUsage=Usage: %d RF/t
misc.storagecraft:storageCellStored=Stored: %d
misc.storagecraft:storageCellStoredWithCapacity=Stored: %d / %d
misc.storagecraft:wirelessGrid.set=Grid set at %d, %d, %d.
misc.storagecraft:wirelessGrid.notFound=Grid not found.
misc.storagecraft:wirelessGrid.notSet=Grid not set yet.
misc.storagecraft:wirelessGrid.outOfRange=Grid is out of range.
sidebutton.storagecraft:compare.1=Compare Damage
sidebutton.storagecraft:compare.2=Compare NBT
@@ -58,3 +63,4 @@ item.storagecraft:storageCell.1.name=4k Storage Cell
item.storagecraft:storageCell.2.name=16k Storage Cell
item.storagecraft:storageCell.3.name=64k Storage Cell
item.storagecraft:storageCell.4.name=Creative Storage Cell
item.storagecraft:wirelessGrid.name=Wireless Grid

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 B