added quantumChest

This commit is contained in:
modmuss50 2015-04-11 11:30:16 +01:00
parent 1360258257
commit b41adffa60
13 changed files with 304 additions and 9 deletions

View file

@ -5,10 +5,12 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import techreborn.blocks.BlockQuantumChest;
import techreborn.blocks.BlockQuantumTank;
import techreborn.blocks.BlockThermalGenerator;
import techreborn.client.GuiHandler;
import techreborn.client.TechRebornCreativeTab;
import techreborn.tiles.TileQuantumChest;
import techreborn.tiles.TileQuantumTank;
import techreborn.tiles.TileThermalGenerator;
@ -16,7 +18,8 @@ import techreborn.tiles.TileThermalGenerator;
public class Core {
public static Block thermalGenerator;
public static Block quamtumTank;
public static Block quantumTank;
public static Block quantumChest;
@Mod.Instance
public static Core INSTANCE;
@ -27,10 +30,14 @@ public class Core {
GameRegistry.registerBlock(thermalGenerator, "techreborn.thermalGenerator");
GameRegistry.registerTileEntity(TileThermalGenerator.class, "TileThermalGenerator");
quamtumTank = new BlockQuantumTank().setBlockName("techreborn.quamtumTank").setBlockTextureName("techreborn:quamtumTank").setCreativeTab(TechRebornCreativeTab.instance);
GameRegistry.registerBlock(quamtumTank, "techreborn.quamtumTank");
quantumTank = new BlockQuantumTank().setBlockName("techreborn.quantumTank").setBlockTextureName("techreborn:quantumTank").setCreativeTab(TechRebornCreativeTab.instance);
GameRegistry.registerBlock(quantumTank, "techreborn.quantumTank");
GameRegistry.registerTileEntity(TileQuantumTank.class, "TileQuantumTank");
quantumChest = new BlockQuantumChest().setBlockName("techreborn.quantumChest").setBlockTextureName("techreborn:quantumChest").setCreativeTab(TechRebornCreativeTab.instance);
GameRegistry.registerBlock(quantumChest, "techreborn.quantumChest");
GameRegistry.registerTileEntity(TileQuantumChest.class, "TileQuantumChest");
NetworkRegistry.INSTANCE.registerGuiHandler(INSTANCE, new GuiHandler());
}

View file

@ -0,0 +1,29 @@
package techreborn.blocks;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import techreborn.Core;
import techreborn.client.GuiHandler;
import techreborn.tiles.TileQuantumChest;
public class BlockQuantumChest extends BlockContainer {
public BlockQuantumChest() {
super(Material.piston);
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
return new TileQuantumChest();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
player.openGui(Core.INSTANCE, GuiHandler.quantumChestID, world, x, y, z);
return true;
}
}

View file

@ -26,7 +26,7 @@ public class BlockThermalGenerator extends BlockContainer {
private IIcon other;
public BlockThermalGenerator() {
super(Material.iron);
super(Material.piston);
}
@Override

View file

@ -4,10 +4,13 @@ package techreborn.client;
import cpw.mods.fml.common.network.IGuiHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import techreborn.client.container.ContainerQuantumChest;
import techreborn.client.container.ContainerQuantumTank;
import techreborn.client.container.ContainerThermalGenerator;
import techreborn.client.gui.GuiQuantumChest;
import techreborn.client.gui.GuiQuantumTank;
import techreborn.client.gui.GuiThermalGenerator;
import techreborn.tiles.TileQuantumChest;
import techreborn.tiles.TileQuantumTank;
import techreborn.tiles.TileThermalGenerator;
@ -15,6 +18,7 @@ public class GuiHandler implements IGuiHandler {
public static final int thermalGeneratorID = 0;
public static final int quantumTankID = 1;
public static final int quantumChestID = 2;
@Override
@ -23,6 +27,8 @@ public class GuiHandler implements IGuiHandler {
return new ContainerThermalGenerator((TileThermalGenerator) world.getTileEntity(x, y, z), player);
} else if(ID == quantumTankID){
return new ContainerQuantumTank((TileQuantumTank) world.getTileEntity(x, y, z), player);
} else if(ID == quantumChestID){
return new ContainerQuantumChest((TileQuantumChest) world.getTileEntity(x, y, z), player);
}
return null;
@ -34,6 +40,8 @@ public class GuiHandler implements IGuiHandler {
return new GuiThermalGenerator(player, (TileThermalGenerator)world.getTileEntity(x, y, z));
} else if(ID == quantumTankID){
return new GuiQuantumTank(player, (TileQuantumTank)world.getTileEntity(x, y, z));
} else if(ID == quantumChestID){
return new GuiQuantumChest(player, (TileQuantumChest)world.getTileEntity(x, y, z));
}
return null;
}

View file

@ -0,0 +1,20 @@
package techreborn.client;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class SlotInput extends Slot {
public SlotInput(IInventory par1iInventory, int par2, int par3, int par4) {
super(par1iInventory, par2, par3, par4);
}
public boolean isItemValid(ItemStack par1ItemStack) {
return false;
}
public int getSlotStackLimit() {
return 64;
}
}

View file

@ -13,4 +13,8 @@ public class SlotOutput extends Slot {
public boolean isItemValid(ItemStack par1ItemStack) {
return false;
}
public int getSlotStackLimit() {
return 64;
}
}

View file

@ -0,0 +1,47 @@
package techreborn.client.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import techreborn.client.SlotFake;
import techreborn.client.SlotOutput;
import techreborn.tiles.TileQuantumChest;
public class ContainerQuantumChest extends Container {
public TileQuantumChest tileQuantumChest;
public EntityPlayer player;
public ContainerQuantumChest(TileQuantumChest tileQuantumChest, EntityPlayer player) {
super();
this.tileQuantumChest = tileQuantumChest;
this.player = player;
this.addSlotToContainer(new Slot(tileQuantumChest.inventory, 0, 80, 17));
this.addSlotToContainer(new SlotOutput(tileQuantumChest.inventory, 1, 80, 53));
this.addSlotToContainer(new SlotFake(tileQuantumChest.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;
}
//TODO enable shift-clicking
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
ItemStack stack = null;
return stack;
}
}

View file

@ -0,0 +1,43 @@
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 techreborn.client.container.ContainerQuantumChest;
import techreborn.client.container.ContainerQuantumTank;
import techreborn.tiles.TileQuantumChest;
import techreborn.tiles.TileQuantumTank;
public class GuiQuantumChest extends GuiContainer {
private static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/ThermalGenerator.png");
TileQuantumChest tile;
public GuiQuantumChest(EntityPlayer player, TileQuantumChest tile) {
super(new ContainerQuantumChest(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_)
{
this.fontRendererObj.drawString("Quantum Chest", 8, 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

@ -5,9 +5,7 @@ import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import techreborn.client.container.ContainerQuantumTank;
import techreborn.client.container.ContainerThermalGenerator;
import techreborn.tiles.TileQuantumTank;
import techreborn.tiles.TileThermalGenerator;
public class GuiQuantumTank extends GuiContainer {

View file

@ -0,0 +1,135 @@
package techreborn.tiles;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
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 net.minecraft.tileentity.TileEntity;
import techreborn.util.FluidUtils;
import techreborn.util.Inventory;
public class TileQuantumChest extends TileEntity implements IInventory {
//Slot 0 = Input
//Slot 1 = Output
//Slot 2 = Fake Item
public Inventory inventory = new Inventory(3, "TileQuantumChest", Integer.MAX_VALUE);
public ItemStack storedItem;
@Override
public void updateEntity() {
if(storedItem != null){
setInventorySlotContents(2, new ItemStack(storedItem.getItem()));
} else {
setInventorySlotContents(2, null);
}
if(getStackInSlot(0) != null){
if(storedItem == null){
storedItem = getStackInSlot(0);
setInventorySlotContents(0, null);
} else if (FluidUtils.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 = 64;
setInventorySlotContents(1, itemStack);
storedItem.stackSize -= 64;
} else if(FluidUtils.isItemEqual(getStackInSlot(1), storedItem, true, true)){
int wanted = 64 - getStackInSlot(1).stackSize;
if(storedItem.stackSize >= wanted){
decrStackSize(1, -wanted);
storedItem.stackSize -= wanted;
} else {
decrStackSize(1, -storedItem.stackSize);
storedItem = null;
}
}
}
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 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);
}
}

View file

@ -9,7 +9,10 @@ import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import techreborn.util.FluidUtils;
import techreborn.util.Inventory;
import techreborn.util.Tank;

View file

@ -12,7 +12,6 @@ import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*;
import net.minecraftforge.oredict.OreDictionary;
import techreborn.Core;
import techreborn.util.FluidUtils;
import techreborn.util.Inventory;

View file

@ -1,3 +1,5 @@
itemGroup.techreborn=Tech Reborn
tile.techreborn.thermalGenerator.name=Thermal Generator
tile.techreborn.thermalGenerator.name=Thermal Generator
tile.techreborn.quantumTank.name=Quantum Tank
tile.techreborn.quantumChest.name=Quantum Chest