Added Digital Chest, Computer Monitor

This commit is contained in:
joflashstudios 2015-06-06 22:11:13 -04:00
parent 65bd203791
commit 7cfaac1f61
10 changed files with 539 additions and 1 deletions

View file

@ -0,0 +1,68 @@
package techreborn.blocks;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import techreborn.Core;
import techreborn.client.GuiHandler;
import techreborn.tiles.TileDigitalChest;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockDigitalChest extends BlockMachineBase {
@SideOnly(Side.CLIENT)
private IIcon iconFront;
@SideOnly(Side.CLIENT)
private IIcon iconTop;
@SideOnly(Side.CLIENT)
private IIcon iconBottom;
public BlockDigitalChest()
{
super(Material.rock);
setBlockName("techreborn.DigitalChest");
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_)
{
return new TileDigitalChest();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z,
EntityPlayer player, int side, float hitX, float hitY, float hitZ)
{
if (!player.isSneaking())
player.openGui(Core.INSTANCE, GuiHandler.digitalChestID, world, x,
y, z);
return true;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister icon)
{
this.blockIcon = icon.registerIcon("techreborn:machine/machine_side");
this.iconFront = icon.registerIcon("techreborn:machine/quantum_chest");
this.iconTop = icon.registerIcon("techreborn:machine/quantum_top");
this.iconBottom = icon.registerIcon("techreborn:machine/machine_bottom");
}
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata)
{
return metadata == 0 && side == 3 ? this.iconFront
: side == 1 ? this.iconTop :
side == 0 ? this.iconBottom: (side == 0 ? this.iconTop
: (side == metadata ? this.iconFront : this.blockIcon));
}
}

View file

@ -21,6 +21,7 @@ import techreborn.client.container.ContainerMatterFabricator;
import techreborn.client.container.ContainerPlateCuttingMachine;
import techreborn.client.container.ContainerQuantumChest;
import techreborn.client.container.ContainerQuantumTank;
import techreborn.client.container.ContainerDigitalChest;
import techreborn.client.container.ContainerRollingMachine;
import techreborn.client.container.ContainerThermalGenerator;
import techreborn.client.container.ContainerSemifluidGenerator;
@ -43,6 +44,7 @@ import techreborn.client.gui.GuiMatterFabricator;
import techreborn.client.gui.GuiPlateCuttingMachine;
import techreborn.client.gui.GuiQuantumChest;
import techreborn.client.gui.GuiQuantumTank;
import techreborn.client.gui.GuiDigitalChest;
import techreborn.client.gui.GuiRollingMachine;
import techreborn.client.gui.GuiThermalGenerator;
import techreborn.client.gui.GuiSemifluidGenerator;
@ -76,6 +78,7 @@ public class GuiHandler implements IGuiHandler {
public static final int chemicalReactorID = 20;
public static final int semifluidGeneratorID = 21;
public static final int gasTurbineID = 22;
public static final int digitalChestID = 23;
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
@ -97,6 +100,10 @@ public class GuiHandler implements IGuiHandler {
{
return new ContainerQuantumTank(
(TileQuantumTank) world.getTileEntity(x, y, z), player);
} else if (ID == digitalChestID)
{
return new ContainerDigitalChest(
(TileDigitalChest) world.getTileEntity(x, y, z), player);
} else if (ID == quantumChestID)
{
return new ContainerQuantumChest(
@ -197,6 +204,10 @@ public class GuiHandler implements IGuiHandler {
{
return new GuiQuantumTank(player,
(TileQuantumTank) world.getTileEntity(x, y, z));
} else if (ID == digitalChestID)
{
return new GuiDigitalChest(player,
(TileDigitalChest) world.getTileEntity(x, y, z));
} else if (ID == quantumChestID)
{
return new GuiQuantumChest(player,

View file

@ -0,0 +1,50 @@
package techreborn.client.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import techreborn.client.SlotFake;
import techreborn.client.SlotOutput;
import techreborn.tiles.TileDigitalChest;
public class ContainerDigitalChest extends TechRebornContainer {
public TileDigitalChest tileDigitalChest;
public EntityPlayer player;
public ContainerDigitalChest(TileDigitalChest tileDigitalChest,
EntityPlayer player)
{
super();
this.tileDigitalChest = tileDigitalChest;
this.player = player;
this.addSlotToContainer(new Slot(tileDigitalChest.inventory, 0, 80, 17));
this.addSlotToContainer(new SlotOutput(tileDigitalChest.inventory, 1,
80, 53));
this.addSlotToContainer(new SlotFake(tileDigitalChest.inventory, 2, 59,
42, false, false, Integer.MAX_VALUE));
int i;
for (i = 0; i < 3; ++i)
{
for (int j = 0; j < 9; ++j)
{
this.addSlotToContainer(new Slot(player.inventory, j + i * 9
+ 9, 8 + j * 18, 84 + i * 18));
}
}
for (i = 0; i < 9; ++i)
{
this.addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18,
142));
}
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
return true;
}
}

View file

@ -0,0 +1,49 @@
package techreborn.client.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import techreborn.client.container.ContainerDigitalChest;
import techreborn.tiles.TileDigitalChest;
public class GuiDigitalChest extends GuiContainer {
private static final ResourceLocation texture = new ResourceLocation(
"techreborn", "textures/gui/ThermalGenerator.png");
TileDigitalChest tile;
public GuiDigitalChest(EntityPlayer player, TileDigitalChest tile)
{
super(new ContainerDigitalChest(tile, player));
this.xSize = 176;
this.ySize = 167;
this.tile = tile;
}
@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_,
int p_146976_2_, int p_146976_3_)
{
this.mc.getTextureManager().bindTexture(texture);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
}
protected void drawGuiContainerForegroundLayer(int p_146979_1_,
int p_146979_2_)
{
String name = StatCollector.translateToLocal("tile.techreborn.digitalChest.name");
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);
this.fontRendererObj.drawString(
I18n.format("container.inventory", new Object[0]), 8,
this.ySize - 96 + 2, 4210752);
this.fontRendererObj.drawString("Amount", 10, 20, 16448255);
if (tile.storedItem != null)
this.fontRendererObj.drawString(tile.storedItem.stackSize + "", 10,
30, 16448255);
}
}

View file

@ -57,6 +57,7 @@ import techreborn.tiles.TileMachineCasing;
import techreborn.tiles.TileMatterFabricator;
import techreborn.tiles.TilePlateCuttingMachine;
import techreborn.tiles.TileQuantumChest;
import techreborn.tiles.TileDigitalChest;
import techreborn.tiles.TileQuantumTank;
import techreborn.tiles.TileRollingMachine;
import techreborn.tiles.TileThermalGenerator;
@ -70,6 +71,7 @@ public class ModBlocks {
public static Block thermalGenerator;
public static Block quantumTank;
public static Block quantumChest;
public static Block digitalChest;
public static Block centrifuge;
public static Block RollingMachine;
public static Block MachineCasing;
@ -126,6 +128,10 @@ public class ModBlocks {
quantumChest = new BlockQuantumChest();
GameRegistry.registerBlock(quantumChest, ItemBlockQuantumChest.class, "techreborn.quantumChest");
GameRegistry.registerTileEntity(TileQuantumChest.class, "TileQuantumChestTR");
digitalChest = new BlockDigitalChest();
GameRegistry.registerBlock(digitalChest, ItemBlockDigitalChest.class, "techreborn.digitalChest");
GameRegistry.registerTileEntity(TileDigitalChest.class, "TileDigitalChestTR");
centrifuge = new BlockCentrifuge();
GameRegistry.registerBlock(centrifuge, "techreborn.centrifuge");

View file

@ -0,0 +1,61 @@
package techreborn.itemblocks;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import techreborn.init.ModBlocks;
import techreborn.tiles.TileDigitalChest;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemBlockDigitalChest extends ItemBlock {
public ItemBlockDigitalChest(Block p_i45328_1_)
{
super(p_i45328_1_);
}
@SuppressWarnings(
{ "rawtypes", "unchecked" })
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list,
boolean par4)
{
if (stack != null && stack.hasTagCompound())
{
if (stack.getTagCompound().getCompoundTag("tileEntity") != null)
list.add(stack.getTagCompound().getCompoundTag("tileEntity")
.getInteger("storedQuantity")
+ " items");
}
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player,
World world, int x, int y, int z, int side, float hitX, float hitY,
float hitZ, int metadata)
{
if (!world.setBlock(x, y, z, ModBlocks.digitalChest, metadata, 3))
{
return false;
}
if (world.getBlock(x, y, z) == ModBlocks.digitalChest)
{
world.getBlock(x, y, z).onBlockPlacedBy(world, x, y, z, player,
stack);
world.getBlock(x, y, z).onPostBlockPlaced(world, x, y, z, metadata);
}
if (stack != null && stack.hasTagCompound())
{
((TileDigitalChest) world.getTileEntity(x, y, z))
.readFromNBTWithoutCoords(stack.getTagCompound()
.getCompoundTag("tileEntity"));
}
return true;
}
}

View file

@ -20,7 +20,7 @@ public class ItemParts extends Item {
"bronzeGear", "ironGear", "titaniumGear", "steelGear", "tungstensteelGear",
"laserFocus", "ductTape", "lazuriteChunk", "iridiumAlloyIngot", "rockCutterBlade", "superconductor",
"thoriumCell", "doubleThoriumCell", "quadThoriumCell", "plutoniumCell", "doublePlutoniumCell",
"quadPlutoniumCell", "destructoPack", "iridiumNeutronReflector", "massHoleDevice" };
"quadPlutoniumCell", "destructoPack", "iridiumNeutronReflector", "massHoleDevice", "computerMonitor" };
private IIcon[] textures;

View file

@ -0,0 +1,291 @@
package techreborn.tiles;
import ic2.api.tile.IWrenchable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import techreborn.init.ModBlocks;
import techreborn.util.Inventory;
import techreborn.util.ItemUtils;
import java.util.List;
public class TileDigitalChest extends TileMachineBase implements IInventory,
IWrenchable {
// Slot 0 = Input
// Slot 1 = Output
// Slot 2 = Fake Item
//TODO use long so we can have 9,223,372,036,854,775,807 items instead of 2,147,483,647
int storage = 32767;
public Inventory inventory = new Inventory(3, "TileDigitalChest",
storage);
public ItemStack storedItem;
@Override
public void updateEntity()
{
if(!worldObj.isRemote){
if (storedItem != null)
{
ItemStack fakeStack = storedItem.copy();
fakeStack.stackSize = 1;
setInventorySlotContents(2, fakeStack);
} else
{
setInventorySlotContents(2, null);
}
if (getStackInSlot(0) != null)
{
if (storedItem == null)
{
storedItem = getStackInSlot(0);
setInventorySlotContents(0, null);
} else if (ItemUtils.isItemEqual(storedItem, getStackInSlot(0),
true, true))
{
if (storedItem.stackSize <= Integer.MAX_VALUE
- getStackInSlot(0).stackSize)
{
storedItem.stackSize += getStackInSlot(0).stackSize;
decrStackSize(0, getStackInSlot(0).stackSize);
}
}
}
if (storedItem != null && getStackInSlot(1) == null)
{
ItemStack itemStack = storedItem.copy();
itemStack.stackSize = itemStack.getMaxStackSize();
setInventorySlotContents(1, itemStack);
storedItem.stackSize -= itemStack.getMaxStackSize();
} else if (ItemUtils.isItemEqual(getStackInSlot(1), storedItem, true,
true))
{
int wanted = getStackInSlot(1).getMaxStackSize()
- getStackInSlot(1).stackSize;
if (storedItem.stackSize >= wanted)
{
decrStackSize(1, -wanted);
storedItem.stackSize -= wanted;
} else
{
decrStackSize(1, -storedItem.stackSize);
storedItem = null;
}
}
}
syncWithAll();
}
public Packet getDescriptionPacket()
{
NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord,
this.zCoord, 1, nbtTag);
}
@Override
public void onDataPacket(NetworkManager net,
S35PacketUpdateTileEntity packet)
{
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord,
yCoord, zCoord);
readFromNBT(packet.func_148857_g());
}
@Override
public void readFromNBT(NBTTagCompound tagCompound)
{
super.readFromNBT(tagCompound);
readFromNBTWithoutCoords(tagCompound);
}
public void readFromNBTWithoutCoords(NBTTagCompound tagCompound)
{
inventory.readFromNBT(tagCompound);
storedItem = null;
if (tagCompound.hasKey("storedStack"))
{
storedItem = ItemStack
.loadItemStackFromNBT((NBTTagCompound) tagCompound
.getTag("storedStack"));
}
if (storedItem != null)
{
storedItem.stackSize = tagCompound.getInteger("storedQuantity");
}
}
@Override
public void writeToNBT(NBTTagCompound tagCompound)
{
super.writeToNBT(tagCompound);
writeToNBTWithoutCoords(tagCompound);
}
public void writeToNBTWithoutCoords(NBTTagCompound tagCompound)
{
inventory.writeToNBT(tagCompound);
if (storedItem != null)
{
tagCompound.setTag("storedStack",
storedItem.writeToNBT(new NBTTagCompound()));
tagCompound.setInteger("storedQuantity", storedItem.stackSize);
} else
tagCompound.setInteger("storedQuantity", 0);
}
@Override
public int getSizeInventory()
{
return inventory.getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int slot)
{
return inventory.getStackInSlot(slot);
}
@Override
public ItemStack decrStackSize(int slotId, int count)
{
return inventory.decrStackSize(slotId, count);
}
@Override
public ItemStack getStackInSlotOnClosing(int slot)
{
return inventory.getStackInSlotOnClosing(slot);
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack)
{
inventory.setInventorySlotContents(slot, stack);
}
@Override
public String getInventoryName()
{
return inventory.getInventoryName();
}
@Override
public boolean hasCustomInventoryName()
{
return inventory.hasCustomInventoryName();
}
@Override
public int getInventoryStackLimit()
{
return inventory.getInventoryStackLimit();
}
@Override
public boolean isUseableByPlayer(EntityPlayer player)
{
return inventory.isUseableByPlayer(player);
}
@Override
public void openInventory()
{
inventory.openInventory();
}
@Override
public void closeInventory()
{
inventory.closeInventory();
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack)
{
return inventory.isItemValidForSlot(slot, stack);
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
{
return false;
}
@Override
public short getFacing()
{
return 0;
}
@Override
public void setFacing(short facing)
{
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer)
{
if (entityPlayer.isSneaking())
{
return true;
}
return false;
}
@Override
public float getWrenchDropRate()
{
return 1F;
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
{
return getDropWithNBT();
}
public ItemStack getDropWithNBT()
{
NBTTagCompound tileEntity = new NBTTagCompound();
ItemStack dropStack = new ItemStack(ModBlocks.digitalChest, 1);
writeToNBTWithoutCoords(tileEntity);
dropStack.setTagCompound(new NBTTagCompound());
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
return dropStack;
}
@Override
public void addWailaInfo(List<String> info)
{
super.addWailaInfo(info);
int size = 0;
String name = "of nothing";
if (storedItem != null)
{
name = storedItem.getDisplayName();
size += storedItem.stackSize;
}
if (getStackInSlot(1) != null)
{
name = getStackInSlot(1).getDisplayName();
size += getStackInSlot(1).stackSize;
}
info.add(size + " " + name);
}
}

View file

@ -6,6 +6,7 @@ tile.techreborn.industrialBlock.name=Industrial
tile.techreborn.thermalGenerator.name=Thermal Generator
tile.techreborn.quantumTank.name=Quantum Tank
tile.techreborn.quantumChest.name=Quantum Chest
tile.techreborn.digitalChest.name=Digital Chest
tile.techreborn.centrifuge.name=Centrifuge
tile.techreborn.rollingmachine.name=Rolling machine
tile.techreborn.machineCasing.standard.name=Standard Machine Casing
@ -636,6 +637,7 @@ item.techreborn.part.quadPlutoniumCell.name=Quad Fuel Rod (Plutonium)
item.techreborn.part.destructoPack.name=Destructopack
item.techreborn.part.iridiumNeutronReflector.name=Iridium Neutron Reflector
item.techreborn.part.massHoleDevice.name=Mass Hole Device
item.techreborn.part.computerMonitor.name=Computer Monitor
#Tools

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B