Finishing off for tonight.
This commit is contained in:
parent
da25ed6add
commit
700012697e
6 changed files with 375 additions and 9 deletions
|
@ -27,7 +27,7 @@ if (ENV.BUILD_NUMBER) {
|
|||
}
|
||||
|
||||
minecraft {
|
||||
version = "1.7.10-10.13.3.1358-1.7.10"
|
||||
version = "1.7.10-10.13.2.1351-1.7.10"
|
||||
replace "@MODVERSION@", project.version
|
||||
replaceIn "Core.java"
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@ public class ContainerThermalGenerator extends Container {
|
|||
this.tileThermalGenerator = tileThermalGenerator;
|
||||
this.player = player;
|
||||
|
||||
this.addSlotToContainer(new Slot(player.inventory, 40, 80, 17));
|
||||
this.addSlotToContainer(new SlotOutput(player.inventory, 41, 80, 53));
|
||||
this.addSlotToContainer(new SlotFake(player.inventory, 42, 59, 42, false, false, 1));
|
||||
this.addSlotToContainer(new Slot(tileThermalGenerator.inventory, 0, 80, 17));
|
||||
this.addSlotToContainer(new SlotOutput(tileThermalGenerator.inventory, 1, 80, 53));
|
||||
this.addSlotToContainer(new SlotFake(tileThermalGenerator.inventory, 2, 59, 42, false, false, 1));
|
||||
|
||||
int i;
|
||||
|
||||
|
@ -26,13 +26,13 @@ public class ContainerThermalGenerator extends Container {
|
|||
{
|
||||
for (int j = 0; j < 9; ++j)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(player.inventory , j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
|
||||
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));
|
||||
this.addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18, 142));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,10 +11,13 @@ public class GuiThermalGenerator extends GuiContainer {
|
|||
|
||||
private static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/ThermalGenerator.png");
|
||||
|
||||
TileThermalGenerator tile;
|
||||
|
||||
public GuiThermalGenerator(EntityPlayer player, TileThermalGenerator tile) {
|
||||
super(new ContainerThermalGenerator(tile, player));
|
||||
this.xSize = 176;
|
||||
this .ySize = 167;
|
||||
this.ySize = 167;
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,6 +33,6 @@ public class GuiThermalGenerator extends GuiContainer {
|
|||
this.fontRendererObj.drawString("Thermal Generator", 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("0", 10, 30, 16448255);
|
||||
this.fontRendererObj.drawString(tile.tank.getFluidAmount() + "", 10, 30, 16448255);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,24 @@ 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 net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.*;
|
||||
import techreborn.Core;
|
||||
import techreborn.util.Inventory;
|
||||
import techreborn.util.Tank;
|
||||
|
||||
public class TileThermalGenerator extends TileEntity implements IWrenchable, IFluidHandler, IInventory {
|
||||
|
||||
public Tank tank = new Tank("TileThermalGenerator", FluidContainerRegistry.BUCKET_VOLUME * 16, this);
|
||||
public Inventory inventory = new Inventory(3, "TileThermalGenerator", 64);
|
||||
|
||||
public class TileThermalGenerator extends TileEntity implements IWrenchable {
|
||||
@Override
|
||||
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
|
||||
return false;
|
||||
|
@ -36,4 +49,143 @@ public class TileThermalGenerator extends TileEntity implements IWrenchable {
|
|||
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
||||
return new ItemStack(Core.thermalGenerator, 1);
|
||||
}
|
||||
|
||||
@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) {
|
||||
if (fluid != null) {
|
||||
if (FluidRegistry.getFluidName(fluid.getID()).contentEquals("lava")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@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();
|
||||
if(tank.getFluidAmount() != 0){
|
||||
setInventorySlotContents(2, new ItemStack(tank.getFluidType().getBlock(), 1));
|
||||
}
|
||||
// if(getStackInSlot(0) != null && getStackInSlot(0).getItem() instanceof IFluidContainerItem){
|
||||
// FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(getStackInSlot(0));
|
||||
// // TODO
|
||||
// if (liquid != null) {
|
||||
// int qty = fill(ForgeDirection.UNKNOWN, liquid, true);
|
||||
//
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inventory.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int p_70301_1_) {
|
||||
return inventory.getStackInSlot(p_70301_1_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int p_70298_1_, int p_70298_2_) {
|
||||
return inventory.decrStackSize(p_70298_1_, p_70298_2_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
|
||||
return inventory.getStackInSlotOnClosing(p_70304_1_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_) {
|
||||
inventory.setInventorySlotContents(p_70299_1_, p_70299_2_);
|
||||
}
|
||||
|
||||
@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 p_70300_1_) {
|
||||
return inventory.isUseableByPlayer(p_70300_1_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
inventory.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
inventory.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
|
||||
return inventory.isItemValidForSlot(p_94041_1_, p_94041_2_);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
158
src/main/java/techreborn/util/Inventory.java
Normal file
158
src/main/java/techreborn/util/Inventory.java
Normal file
|
@ -0,0 +1,158 @@
|
|||
package techreborn.util;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
public class Inventory implements IInventory {
|
||||
|
||||
private final ItemStack[] contents;
|
||||
private final String name;
|
||||
private final int stackLimit;
|
||||
private TileEntity tile = new TileEntity();
|
||||
|
||||
public Inventory(int size, String invName, int invStackLimit) {
|
||||
contents = new ItemStack[size];
|
||||
name = invName;
|
||||
stackLimit = invStackLimit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return contents.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slotId) {
|
||||
return contents[slotId];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slotId, int count) {
|
||||
if (slotId < contents.length && contents[slotId] != null) {
|
||||
if (contents[slotId].stackSize > count) {
|
||||
ItemStack result = contents[slotId].splitStack(count);
|
||||
markDirty();
|
||||
return result;
|
||||
}
|
||||
ItemStack stack = contents[slotId];
|
||||
setInventorySlotContents(slotId, null);
|
||||
return stack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slotId, ItemStack itemstack) {
|
||||
if (slotId >= contents.length) {
|
||||
return;
|
||||
}
|
||||
contents[slotId] = itemstack;
|
||||
|
||||
if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) {
|
||||
itemstack.stackSize = this.getInventoryStackLimit();
|
||||
}
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return stackLimit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
}
|
||||
|
||||
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
readFromNBT(data, "Items");
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data, String tag) {
|
||||
NBTTagList nbttaglist = data.getTagList(tag, Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
for (int j = 0; j < nbttaglist.tagCount(); ++j) {
|
||||
NBTTagCompound slot = nbttaglist.getCompoundTagAt(j);
|
||||
int index;
|
||||
if (slot.hasKey("index")) {
|
||||
index = slot.getInteger("index");
|
||||
} else {
|
||||
index = slot.getByte("Slot");
|
||||
}
|
||||
if (index >= 0 && index < contents.length) {
|
||||
setInventorySlotContents(index, ItemStack.loadItemStackFromNBT(slot));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
writeToNBT(data, "Items");
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data, String tag) {
|
||||
NBTTagList slots = new NBTTagList();
|
||||
for (byte index = 0; index < contents.length; ++index) {
|
||||
if (contents[index] != null && contents[index].stackSize > 0) {
|
||||
NBTTagCompound slot = new NBTTagCompound();
|
||||
slots.appendTag(slot);
|
||||
slot.setByte("Slot", index);
|
||||
contents[index].writeToNBT(slot);
|
||||
}
|
||||
}
|
||||
data.setTag(tag, slots);
|
||||
}
|
||||
|
||||
public void setTile(TileEntity tileEntity) {
|
||||
tile = tileEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slotId) {
|
||||
if (this.contents[slotId] == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack stackToTake = this.contents[slotId];
|
||||
setInventorySlotContents(slotId, null);
|
||||
return stackToTake;
|
||||
}
|
||||
|
||||
public ItemStack[] getStacks() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty() {
|
||||
tile.markDirty();
|
||||
}
|
||||
}
|
53
src/main/java/techreborn/util/Tank.java
Normal file
53
src/main/java/techreborn/util/Tank.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
package techreborn.util;
|
||||
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
public class Tank extends FluidTank {
|
||||
|
||||
|
||||
private final String name;
|
||||
|
||||
public Tank(String name, int capacity, TileEntity tile) {
|
||||
super(capacity);
|
||||
this.name = name;
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return getFluid() == null || getFluid().amount <= 0;
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return getFluid() != null && getFluid().amount >= getCapacity();
|
||||
}
|
||||
|
||||
public Fluid getFluidType() {
|
||||
return getFluid() != null ? getFluid().getFluid() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
NBTTagCompound tankData = new NBTTagCompound();
|
||||
super.writeToNBT(tankData);
|
||||
nbt.setTag(name, tankData);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final FluidTank readFromNBT(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(name)) {
|
||||
// allow to read empty tanks
|
||||
setFluid(null);
|
||||
|
||||
NBTTagCompound tankData = nbt.getCompoundTag(name);
|
||||
super.readFromNBT(tankData);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue