Added quamtumTank

This commit is contained in:
modmuss50 2015-04-11 10:37:47 +01:00
parent ce031af8e7
commit 1360258257
9 changed files with 373 additions and 54 deletions

View file

@ -5,15 +5,18 @@ 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.BlockQuantumTank;
import techreborn.blocks.BlockThermalGenerator;
import techreborn.client.GuiHandler;
import techreborn.client.TechRebornCreativeTab;
import techreborn.tiles.TileQuantumTank;
import techreborn.tiles.TileThermalGenerator;
@Mod(modid = "techreborn", name = "TechReborn", version = "@MODVERSION@")
public class Core {
public static Block thermalGenerator;
public static Block quamtumTank;
@Mod.Instance
public static Core INSTANCE;
@ -24,6 +27,10 @@ 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");
GameRegistry.registerTileEntity(TileQuantumTank.class, "TileQuantumTank");
NetworkRegistry.INSTANCE.registerGuiHandler(INSTANCE, new GuiHandler());
}

View file

@ -0,0 +1,28 @@
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.TileQuantumTank;
public class BlockQuantumTank extends BlockContainer {
public BlockQuantumTank() {
super(Material.piston);
}
@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
return new TileQuantumTank();
}
@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.quantumTankID, world, x, y, z);
return true;
}
}

View file

@ -4,18 +4,27 @@ 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.ContainerQuantumTank;
import techreborn.client.container.ContainerThermalGenerator;
import techreborn.client.gui.GuiQuantumTank;
import techreborn.client.gui.GuiThermalGenerator;
import techreborn.tiles.TileQuantumTank;
import techreborn.tiles.TileThermalGenerator;
public class GuiHandler implements IGuiHandler {
public static final int thermalGeneratorID = 0;
public static final int quantumTankID = 1;
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if(ID == thermalGeneratorID){
return new ContainerThermalGenerator((TileThermalGenerator) world.getTileEntity(x, y, z), player);
} else if(ID == quantumTankID){
return new ContainerQuantumTank((TileQuantumTank) world.getTileEntity(x, y, z), player);
}
return null;
}
@ -23,6 +32,8 @@ public class GuiHandler implements IGuiHandler {
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if(ID == thermalGeneratorID){
return new GuiThermalGenerator(player, (TileThermalGenerator)world.getTileEntity(x, y, z));
} else if(ID == quantumTankID){
return new GuiQuantumTank(player, (TileQuantumTank)world.getTileEntity(x, y, z));
}
return null;
}

View file

@ -0,0 +1,43 @@
package techreborn.client.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import techreborn.client.SlotFake;
import techreborn.client.SlotOutput;
import techreborn.tiles.TileQuantumTank;
public class ContainerQuantumTank extends Container {
public TileQuantumTank tileQuantumTank;
public EntityPlayer player;
public ContainerQuantumTank(TileQuantumTank tileQuantumTank, EntityPlayer player) {
super();
this.tileQuantumTank = tileQuantumTank;
this.player = player;
this.addSlotToContainer(new Slot(tileQuantumTank.inventory, 0, 80, 17));
this.addSlotToContainer(new SlotOutput(tileQuantumTank.inventory, 1, 80, 53));
this.addSlotToContainer(new SlotFake(tileQuantumTank.inventory, 2, 59, 42, false, false, 1));
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,41 @@
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.ContainerQuantumTank;
import techreborn.client.container.ContainerThermalGenerator;
import techreborn.tiles.TileQuantumTank;
import techreborn.tiles.TileThermalGenerator;
public class GuiQuantumTank extends GuiContainer {
private static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/ThermalGenerator.png");
TileQuantumTank tile;
public GuiQuantumTank(EntityPlayer player, TileQuantumTank tile) {
super(new ContainerQuantumTank(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 Tank", 8, 6, 4210752);
this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
this.fontRendererObj.drawString("Liquid Amount", 10, 20, 16448255);
this.fontRendererObj.drawString(tile.tank.getFluidAmount() + "", 10, 30, 16448255);
}
}

View file

@ -0,0 +1,151 @@
package techreborn.tiles;
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 net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*;
import techreborn.util.FluidUtils;
import techreborn.util.Inventory;
import techreborn.util.Tank;
public class TileQuantumTank extends TileEntity implements IFluidHandler, IInventory {
public Tank tank = new Tank("TileQuantumTank", 2000000000, this);
public Inventory inventory = new Inventory(3, "TileQuantumTank", 64);
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
tank.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound);
}
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
tank.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound);
}
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 updateEntity() {
super.updateEntity();
FluidUtils.drainContainers(this, inventory, 0, 1);
FluidUtils.fillContainers(this, inventory, 0, 1, tank.getFluidType());
if(tank.getFluidType() != null && getStackInSlot(2) == null){
inventory.setInventorySlotContents(2, new ItemStack(tank.getFluidType().getBlock()));
} else if(tank.getFluidType() == null && getStackInSlot(2) != null){
setInventorySlotContents(2, null);
}
}
//IFluidHandler
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
return tank.fill(resource, doFill);
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
return tank.drain(resource.amount, doDrain);
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
return tank.drain(maxDrain, doDrain);
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid) {
return tank.getFluid() == null || tank.getFluid().getFluid() == fluid;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) {
return tank.getFluid() == null || tank.getFluid().getFluid() == fluid;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
return getTankInfo(from);
}
//IInventory
@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

@ -14,6 +14,7 @@ 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;
import techreborn.util.Tank;
@ -124,7 +125,7 @@ public class TileThermalGenerator extends TileEntity implements IWrenchable, IFl
@Override
public void updateEntity() {
super.updateEntity();
drainContainers(this, inventory, 0, 1);
FluidUtils.drainContainers(this, inventory, 0, 1);
energySource.updateEntity();
if(tank.getFluidAmount() > 0 && energySource.getCapacity() - energySource.getEnergyStored() >= euTick){
tank.drain(1, true);
@ -135,59 +136,6 @@ public class TileThermalGenerator extends TileEntity implements IWrenchable, IFl
} else if(tank.getFluidType() == null && getStackInSlot(2) != null){
setInventorySlotContents(2, null);
}
}
public static boolean drainContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot) {
ItemStack input = inv.getStackInSlot(inputSlot);
ItemStack output = inv.getStackInSlot(outputSlot);
if (input != null) {
FluidStack fluidInContainer = getFluidStackInContainer(input);
ItemStack emptyItem = input.getItem().getContainerItem(input);
if (fluidInContainer != null && (emptyItem == null || output == null || (output.stackSize < output.getMaxStackSize() && isItemEqual(output, emptyItem, true, true)))) {
int used = fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, false);
if (used >= fluidInContainer.amount) {
fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, true);
if (emptyItem != null)
if (output == null)
inv.setInventorySlotContents(outputSlot, emptyItem);
else
output.stackSize++;
inv.decrStackSize(inputSlot, 1);
return true;
}
}
}
return false;
}
public static FluidStack getFluidStackInContainer(ItemStack stack) {
return FluidContainerRegistry.getFluidForFilledItem(stack);
}
public static boolean isItemEqual(final ItemStack a, final ItemStack b, final boolean matchDamage, final boolean matchNBT) {
if (a == null || b == null)
return false;
if (a.getItem() != b.getItem())
return false;
if (matchNBT && !ItemStack.areItemStackTagsEqual(a, b))
return false;
if (matchDamage && a.getHasSubtypes()) {
if (isWildcard(a) || isWildcard(b))
return true;
if (a.getItemDamage() != b.getItemDamage())
return false;
}
return true;
}
public static boolean isWildcard(ItemStack stack) {
return isWildcard(stack.getItemDamage());
}
public static boolean isWildcard(int damage) {
return damage == -1 || damage == OreDictionary.WILDCARD_VALUE;
}
@Override

View file

@ -0,0 +1,90 @@
package techreborn.util;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.oredict.OreDictionary;
public class FluidUtils {
public static boolean drainContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot) {
ItemStack input = inv.getStackInSlot(inputSlot);
ItemStack output = inv.getStackInSlot(outputSlot);
if (input != null) {
FluidStack fluidInContainer = getFluidStackInContainer(input);
ItemStack emptyItem = input.getItem().getContainerItem(input);
if (fluidInContainer != null && (emptyItem == null || output == null || (output.stackSize < output.getMaxStackSize() && isItemEqual(output, emptyItem, true, true)))) {
int used = fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, false);
if (used >= fluidInContainer.amount) {
fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, true);
if (emptyItem != null)
if (output == null)
inv.setInventorySlotContents(outputSlot, emptyItem);
else
output.stackSize++;
inv.decrStackSize(inputSlot, 1);
return true;
}
}
}
return false;
}
public static boolean fillContainers(IFluidHandler fluidHandler, IInventory inv, int inputSlot, int outputSlot, Fluid fluidToFill) {
ItemStack input = inv.getStackInSlot(inputSlot);
ItemStack output = inv.getStackInSlot(outputSlot);
ItemStack filled = getFilledContainer(fluidToFill, input);
if (filled != null && (output == null || (output.stackSize < output.getMaxStackSize() && isItemEqual(filled, output, true, true)))) {
FluidStack fluidInContainer = getFluidStackInContainer(filled);
FluidStack drain = fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, false);
if (drain != null && drain.amount == fluidInContainer.amount) {
fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, true);
if (output == null)
inv.setInventorySlotContents(outputSlot, filled);
else
output.stackSize++;
inv.decrStackSize(inputSlot, 1);
return true;
}
}
return false;
}
public static FluidStack getFluidStackInContainer(ItemStack stack) {
return FluidContainerRegistry.getFluidForFilledItem(stack);
}
public static ItemStack getFilledContainer(Fluid fluid, ItemStack empty) {
if (fluid == null || empty == null) return null;
return FluidContainerRegistry.fillFluidContainer(new FluidStack(fluid, Integer.MAX_VALUE), empty);
}
public static boolean isItemEqual(final ItemStack a, final ItemStack b, final boolean matchDamage, final boolean matchNBT) {
if (a == null || b == null)
return false;
if (a.getItem() != b.getItem())
return false;
if (matchNBT && !ItemStack.areItemStackTagsEqual(a, b))
return false;
if (matchDamage && a.getHasSubtypes()) {
if (isWildcard(a) || isWildcard(b))
return true;
if (a.getItemDamage() != b.getItemDamage())
return false;
}
return true;
}
public static boolean isWildcard(ItemStack stack) {
return isWildcard(stack.getItemDamage());
}
public static boolean isWildcard(int damage) {
return damage == -1 || damage == OreDictionary.WILDCARD_VALUE;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 16 KiB