This commit is contained in:
Gig 2015-04-24 14:20:09 +01:00
parent 6e0ec1d861
commit 4ac26ac086
137 changed files with 10339 additions and 7322 deletions

View file

@ -11,39 +11,45 @@ public class TileBlastFurnace extends TileMachineBase implements IWrenchable {
public int tickTime;
public BasicSink energy;
public Inventory inventory = new Inventory(3, "TileBlastFurnace", 64);
public Inventory inventory = new Inventory(3, "TileBlastFurnace", 64);
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
{
return false;
}
@Override
public short getFacing() {
public short getFacing()
{
return 0;
}
@Override
public void setFacing(short facing) {
public void setFacing(short facing)
{
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
public boolean wrenchCanRemove(EntityPlayer entityPlayer)
{
return true;
}
@Override
public float getWrenchDropRate() {
public float getWrenchDropRate()
{
return 1.0F;
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
{
return new ItemStack(ModBlocks.BlastFurnace, 1);
}
public boolean isComplete(){
public boolean isComplete()
{
return false;
}

View file

@ -18,334 +18,458 @@ import techreborn.init.ModBlocks;
import techreborn.util.Inventory;
import techreborn.util.ItemUtils;
public class TileCentrifuge extends TileMachineBase implements IInventory, IWrenchable, ISidedInventory {
public class TileCentrifuge extends TileMachineBase implements IInventory,
IWrenchable, ISidedInventory {
public BasicSink energy;
public Inventory inventory = new Inventory(6, "TileCentrifuge", 64);
public BasicSink energy;
public Inventory inventory = new Inventory(6, "TileCentrifuge", 64);
public boolean isRunning;
public int tickTime;
public CentrifugeRecipie currentRecipe;
public boolean hasTakenCells = false;
public boolean hasTakenItem = false;
public boolean isRunning;
public int tickTime;
public CentrifugeRecipie currentRecipe;
public boolean hasTakenCells = false;
public boolean hasTakenItem = false;
public int euTick = ConfigTechReborn.CentrifugeInputTick;
public int euTick = ConfigTechReborn.CentrifugeInputTick;
public TileCentrifuge() {
energy = new BasicSink(this, ConfigTechReborn.CentrifugeCharge, ConfigTechReborn.CentrifugeTier);
}
public TileCentrifuge()
{
energy = new BasicSink(this, ConfigTechReborn.CentrifugeCharge,
ConfigTechReborn.CentrifugeTier);
}
@Override
public void updateEntity() {
super.updateEntity();
energy.updateEntity();
if (!worldObj.isRemote) {
if (isRunning) {
if (ItemUtils.isItemEqual(currentRecipe.getInputItem(), getStackInSlot(0), true, true)) {
if (!hasTakenCells) {
if (getStackInSlot(1) != null && getStackInSlot(1) != null && ItemUtils.isItemEqual(getStackInSlot(1), IC2Items.getItem("cell"), false, false)) {
if (getStackInSlot(1).stackSize >= currentRecipe.getCells()) {
decrStackSize(1, currentRecipe.getCells());
hasTakenCells = true;
}
}
}
if (hasTakenCells && hasTakenItem) {
if (tickTime == currentRecipe.getTickTime()) {
if (areAnyOutputsFull()) {
return;
}
if (areOutputsEmpty()) {
setOutput(1, currentRecipe.getOutput1());
setOutput(2, currentRecipe.getOutput2());
setOutput(3, currentRecipe.getOutput3());
setOutput(4, currentRecipe.getOutput4());
} else if (areOutputsEqual()) {
if (currentRecipe.getOutput1() != null)
increacseItemStack(1, 1);
if (currentRecipe.getOutput2() != null)
increacseItemStack(2, 1);
if (currentRecipe.getOutput3() != null)
increacseItemStack(3, 1);
if (currentRecipe.getOutput4() != null)
increacseItemStack(4, 1);
}
tickTime = 0;
isRunning = false;
hasTakenCells = false;
hasTakenItem = false;
syncWithAll();
return;
}
if (energy.canUseEnergy(euTick)) {
if (getStackInSlot(0) != null && ItemUtils.isItemEqual(getStackInSlot(0), currentRecipe.getInputItem(), true, true)) {
if (energy.useEnergy(5)) {
tickTime++;
}
}
}
}
}
} else {
//sets a new recipe
if (getStackInSlot(0) != null && currentRecipe == null) {
for (CentrifugeRecipie recipie : TechRebornAPI.centrifugeRecipies) {
if (ItemUtils.isItemEqual(recipie.getInputItem(), getStackInSlot(0), true, true)) {
currentRecipe = new CentrifugeRecipie(recipie);
}
}
}
if (!isRunning && currentRecipe != null) {
if (areOutputsEqual() || !areAnyOutputsFull()) {
if (getStackInSlot(0) != null && currentRecipe.getInputItem().stackSize <= getStackInSlot(0).stackSize) {
if (energy.canUseEnergy(euTick)) {
decrStackSize(0, currentRecipe.getInputItem().stackSize);
hasTakenItem = true;
tickTime = 0;
isRunning = true;
}
}
}
}
}
syncWithAll();
}
}
@Override
public void updateEntity()
{
super.updateEntity();
energy.updateEntity();
if (!worldObj.isRemote)
{
if (isRunning)
{
if (ItemUtils.isItemEqual(currentRecipe.getInputItem(),
getStackInSlot(0), true, true))
{
if (!hasTakenCells)
{
if (getStackInSlot(1) != null
&& getStackInSlot(1) != null
&& ItemUtils.isItemEqual(getStackInSlot(1),
IC2Items.getItem("cell"), false, false))
{
if (getStackInSlot(1).stackSize >= currentRecipe
.getCells())
{
decrStackSize(1, currentRecipe.getCells());
hasTakenCells = true;
}
}
}
if (hasTakenCells && hasTakenItem)
{
if (tickTime == currentRecipe.getTickTime())
{
if (areAnyOutputsFull())
{
return;
}
if (areOutputsEmpty())
{
setOutput(1, currentRecipe.getOutput1());
setOutput(2, currentRecipe.getOutput2());
setOutput(3, currentRecipe.getOutput3());
setOutput(4, currentRecipe.getOutput4());
} else if (areOutputsEqual())
{
if (currentRecipe.getOutput1() != null)
increacseItemStack(1, 1);
if (currentRecipe.getOutput2() != null)
increacseItemStack(2, 1);
if (currentRecipe.getOutput3() != null)
increacseItemStack(3, 1);
if (currentRecipe.getOutput4() != null)
increacseItemStack(4, 1);
}
tickTime = 0;
isRunning = false;
hasTakenCells = false;
hasTakenItem = false;
syncWithAll();
return;
}
if (energy.canUseEnergy(euTick))
{
if (getStackInSlot(0) != null
&& ItemUtils.isItemEqual(getStackInSlot(0),
currentRecipe.getInputItem(), true,
true))
{
if (energy.useEnergy(5))
{
tickTime++;
}
}
}
}
}
} else
{
// sets a new recipe
if (getStackInSlot(0) != null && currentRecipe == null)
{
for (CentrifugeRecipie recipie : TechRebornAPI.centrifugeRecipies)
{
if (ItemUtils.isItemEqual(recipie.getInputItem(),
getStackInSlot(0), true, true))
{
currentRecipe = new CentrifugeRecipie(recipie);
}
}
}
if (!isRunning && currentRecipe != null)
{
if (areOutputsEqual() || !areAnyOutputsFull())
{
if (getStackInSlot(0) != null
&& currentRecipe.getInputItem().stackSize <= getStackInSlot(0).stackSize)
{
if (energy.canUseEnergy(euTick))
{
decrStackSize(0,
currentRecipe.getInputItem().stackSize);
hasTakenItem = true;
tickTime = 0;
isRunning = true;
}
}
}
}
}
syncWithAll();
}
}
public boolean areOutputsEqual() {
if (currentRecipe == null) {
return false;
}
boolean boo = false;
if (currentRecipe.getOutput1() != null && ItemUtils.isItemEqual(getOutputItemStack(1), currentRecipe.getOutput1(), false, true)) {
boo = true;
}
if (currentRecipe.getOutput2() != null && ItemUtils.isItemEqual(getOutputItemStack(2), currentRecipe.getOutput2(), false, true)) {
boo = true;
}
if (currentRecipe.getOutput3() != null && ItemUtils.isItemEqual(getOutputItemStack(3), currentRecipe.getOutput3(), false, true)) {
boo = true;
}
if (currentRecipe.getOutput4() != null && ItemUtils.isItemEqual(getOutputItemStack(4), currentRecipe.getOutput4(), false, true)) {
boo = true;
}
return boo;
}
public boolean areOutputsEqual()
{
if (currentRecipe == null)
{
return false;
}
boolean boo = false;
if (currentRecipe.getOutput1() != null
&& ItemUtils.isItemEqual(getOutputItemStack(1),
currentRecipe.getOutput1(), false, true))
{
boo = true;
}
if (currentRecipe.getOutput2() != null
&& ItemUtils.isItemEqual(getOutputItemStack(2),
currentRecipe.getOutput2(), false, true))
{
boo = true;
}
if (currentRecipe.getOutput3() != null
&& ItemUtils.isItemEqual(getOutputItemStack(3),
currentRecipe.getOutput3(), false, true))
{
boo = true;
}
if (currentRecipe.getOutput4() != null
&& ItemUtils.isItemEqual(getOutputItemStack(4),
currentRecipe.getOutput4(), false, true))
{
boo = true;
}
return boo;
}
public boolean areOutputsEmpty() {
return getOutputItemStack(1) == null && getOutputItemStack(2) == null && getOutputItemStack(3) == null && getOutputItemStack(4) == null;
}
public boolean areOutputsEmpty()
{
return getOutputItemStack(1) == null && getOutputItemStack(2) == null
&& getOutputItemStack(3) == null
&& getOutputItemStack(4) == null;
}
public boolean areAnyOutputsFull() {
if (currentRecipe.getOutput1() != null && getOutputItemStack(1) != null && getOutputItemStack(1).stackSize + currentRecipe.getOutput1().stackSize > currentRecipe.getOutput1().getMaxStackSize()) {
return true;
}
if (currentRecipe.getOutput2() != null && getOutputItemStack(2) != null && getOutputItemStack(2).stackSize + currentRecipe.getOutput2().stackSize > currentRecipe.getOutput1().getMaxStackSize()) {
return true;
}
if (currentRecipe.getOutput3() != null && getOutputItemStack(3) != null && getOutputItemStack(3).stackSize + currentRecipe.getOutput3().stackSize > currentRecipe.getOutput1().getMaxStackSize()) {
return true;
}
if (currentRecipe.getOutput4() != null && getOutputItemStack(4) != null && getOutputItemStack(4).stackSize + currentRecipe.getOutput4().stackSize > currentRecipe.getOutput1().getMaxStackSize()) {
return true;
}
return false;
}
public boolean areAnyOutputsFull()
{
if (currentRecipe.getOutput1() != null
&& getOutputItemStack(1) != null
&& getOutputItemStack(1).stackSize
+ currentRecipe.getOutput1().stackSize > currentRecipe
.getOutput1().getMaxStackSize())
{
return true;
}
if (currentRecipe.getOutput2() != null
&& getOutputItemStack(2) != null
&& getOutputItemStack(2).stackSize
+ currentRecipe.getOutput2().stackSize > currentRecipe
.getOutput1().getMaxStackSize())
{
return true;
}
if (currentRecipe.getOutput3() != null
&& getOutputItemStack(3) != null
&& getOutputItemStack(3).stackSize
+ currentRecipe.getOutput3().stackSize > currentRecipe
.getOutput1().getMaxStackSize())
{
return true;
}
if (currentRecipe.getOutput4() != null
&& getOutputItemStack(4) != null
&& getOutputItemStack(4).stackSize
+ currentRecipe.getOutput4().stackSize > currentRecipe
.getOutput1().getMaxStackSize())
{
return true;
}
return false;
}
public ItemStack getOutputItemStack(int slot) {
return getStackInSlot(slot + 1);
}
public ItemStack getOutputItemStack(int slot)
{
return getStackInSlot(slot + 1);
}
public void increacseItemStack(int slot, int amount) {
if (getOutputItemStack(slot) == null) {
return;
}
decrStackSize(slot + 1, -amount);
}
public void increacseItemStack(int slot, int amount)
{
if (getOutputItemStack(slot) == null)
{
return;
}
decrStackSize(slot + 1, -amount);
}
public void setOutput(int slot, ItemStack stack) {
if (stack == null) {
return;
}
setInventorySlotContents(slot + 1, stack);
}
public void setOutput(int slot, ItemStack stack)
{
if (stack == null)
{
return;
}
setInventorySlotContents(slot + 1, stack);
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound);
String recipeName = tagCompound.getString("recipe");
for (CentrifugeRecipie recipie : TechRebornAPI.centrifugeRecipies) {
if (recipie.getInputItem().getUnlocalizedName().equals(recipeName)) {
currentRecipe = new CentrifugeRecipie(recipie);
}
}
isRunning = tagCompound.getBoolean("isRunning");
tickTime = tagCompound.getInteger("tickTime");
hasTakenCells = tagCompound.getBoolean("hasTakenCells");
hasTakenItem = tagCompound.getBoolean("hasTakenItem");
}
@Override
public void readFromNBT(NBTTagCompound tagCompound)
{
super.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound);
String recipeName = tagCompound.getString("recipe");
for (CentrifugeRecipie recipie : TechRebornAPI.centrifugeRecipies)
{
if (recipie.getInputItem().getUnlocalizedName().equals(recipeName))
{
currentRecipe = new CentrifugeRecipie(recipie);
}
}
isRunning = tagCompound.getBoolean("isRunning");
tickTime = tagCompound.getInteger("tickTime");
hasTakenCells = tagCompound.getBoolean("hasTakenCells");
hasTakenItem = tagCompound.getBoolean("hasTakenItem");
}
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound);
writeUpdateToNBT(tagCompound);
}
@Override
public void writeToNBT(NBTTagCompound tagCompound)
{
super.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound);
writeUpdateToNBT(tagCompound);
}
public void writeUpdateToNBT(NBTTagCompound tagCompound) {
if (currentRecipe != null) {
tagCompound.setString("recipe", currentRecipe.getInputItem().getUnlocalizedName());
} else {
tagCompound.setString("recipe", "none");
}
tagCompound.setBoolean("isRunning", isRunning);
tagCompound.setInteger("tickTime", tickTime);
tagCompound.setBoolean("hasTakenCells", hasTakenCells);
tagCompound.setBoolean("hasTakenItem", hasTakenItem);
}
public void writeUpdateToNBT(NBTTagCompound tagCompound)
{
if (currentRecipe != null)
{
tagCompound.setString("recipe", currentRecipe.getInputItem()
.getUnlocalizedName());
} else
{
tagCompound.setString("recipe", "none");
}
tagCompound.setBoolean("isRunning", isRunning);
tagCompound.setInteger("tickTime", tickTime);
tagCompound.setBoolean("hasTakenCells", hasTakenCells);
tagCompound.setBoolean("hasTakenItem", hasTakenItem);
}
@Override
public int getSizeInventory() {
return inventory.getSizeInventory();
}
@Override
public int getSizeInventory()
{
return inventory.getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int p_70301_1_) {
return inventory.getStackInSlot(p_70301_1_);
}
@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 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 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 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 String getInventoryName()
{
return inventory.getInventoryName();
}
@Override
public boolean hasCustomInventoryName() {
return inventory.hasCustomInventoryName();
}
@Override
public boolean hasCustomInventoryName()
{
return inventory.hasCustomInventoryName();
}
@Override
public int getInventoryStackLimit() {
return inventory.getInventoryStackLimit();
}
@Override
public int getInventoryStackLimit()
{
return inventory.getInventoryStackLimit();
}
@Override
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
return inventory.isUseableByPlayer(p_70300_1_);
}
@Override
public boolean isUseableByPlayer(EntityPlayer p_70300_1_)
{
return inventory.isUseableByPlayer(p_70300_1_);
}
@Override
public void openInventory() {
inventory.openInventory();
}
@Override
public void openInventory()
{
inventory.openInventory();
}
@Override
public void closeInventory() {
inventory.closeInventory();
}
@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_);
}
@Override
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_)
{
return inventory.isItemValidForSlot(p_94041_1_, p_94041_2_);
}
@Override
public void invalidate() {
energy.invalidate();
}
@Override
public void invalidate()
{
energy.invalidate();
}
@Override
public void onChunkUnload() {
energy.onChunkUnload();
}
@Override
public void onChunkUnload()
{
energy.onChunkUnload();
}
public Packet getDescriptionPacket() {
NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
}
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 onDataPacket(NetworkManager net,
S35PacketUpdateTileEntity packet)
{
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord,
yCoord, zCoord);
readFromNBT(packet.func_148857_g());
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
return false;
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
{
return false;
}
@Override
public short getFacing() {
return 0;
}
@Override
public short getFacing()
{
return 0;
}
@Override
public void setFacing(short facing) {
}
@Override
public void setFacing(short facing)
{
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
return true;
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer)
{
return true;
}
@Override
public float getWrenchDropRate() {
return 1.0F;
}
@Override
public float getWrenchDropRate()
{
return 1.0F;
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.centrifuge, 1);
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
{
return new ItemStack(ModBlocks.centrifuge, 1);
}
@Override
public int[] getAccessibleSlotsFromSide(int side) {
//Top
if (side == 1) {
return new int[]{0};
}
//Bottom
if (side == 0) {
return new int[]{1};
}
//Not bottom or top
return new int[]{2, 3, 4, 5};
}
@Override
public int[] getAccessibleSlotsFromSide(int side)
{
// Top
if (side == 1)
{
return new int[]
{ 0 };
}
// Bottom
if (side == 0)
{
return new int[]
{ 1 };
}
// Not bottom or top
return new int[]
{ 2, 3, 4, 5 };
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, int side) {
//Bottom
if (side == 0) {
return ItemUtils.isItemEqual(stack, IC2Items.getItem("cell"), false, false);
}
//Not bottom or top
if (side >= 2) {
return false;
}
return true;
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, int side)
{
// Bottom
if (side == 0)
{
return ItemUtils.isItemEqual(stack, IC2Items.getItem("cell"),
false, false);
}
// Not bottom or top
if (side >= 2)
{
return false;
}
return true;
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, int side) {
//Only output slots and sides
return slot >= 2 && side >= 2;
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, int side)
{
// Only output slots and sides
return slot >= 2 && side >= 2;
}
}

View file

@ -7,43 +7,51 @@ 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 techreborn.init.ModBlocks;
import techreborn.packets.PacketHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class TileMachineBase extends TileEntity {
private int facing;
private int facing;
@Override
public void updateEntity() {
super.updateEntity();
//TODO make this happen less
//syncWithAll();
}
@Override
public void updateEntity()
{
super.updateEntity();
// TODO make this happen less
// syncWithAll();
}
@SideOnly(Side.CLIENT)
public void addWailaInfo(List<String> info) {
@SideOnly(Side.CLIENT)
public void addWailaInfo(List<String> info)
{
}
}
public void syncWithAll() {
if (!worldObj.isRemote) {
PacketHandler.sendPacketToAllPlayers(getDescriptionPacket(), worldObj);
}
}
public void syncWithAll()
{
if (!worldObj.isRemote)
{
PacketHandler.sendPacketToAllPlayers(getDescriptionPacket(),
worldObj);
}
}
public Packet getDescriptionPacket() {
NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
}
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 onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
readFromNBT(packet.func_148857_g());
}
}

View file

@ -1,64 +1,75 @@
package techreborn.tiles;
import techreborn.multiblocks.MultiBlockCasing;
import erogenousbeef.coreTR.multiblock.MultiblockControllerBase;
import erogenousbeef.coreTR.multiblock.MultiblockValidationException;
import erogenousbeef.coreTR.multiblock.rectangular.RectangularMultiblockTileEntityBase;
import techreborn.multiblocks.MultiBlockCasing;
public class TileMachineCasing extends RectangularMultiblockTileEntityBase {
@Override
public boolean canUpdate() {
//No need to update this.
return false;
}
@Override
public boolean canUpdate()
{
// No need to update this.
return false;
}
@Override
public void onMachineActivated() {
@Override
public void onMachineActivated()
{
}
}
@Override
public void onMachineDeactivated() {
@Override
public void onMachineDeactivated()
{
}
}
@Override
public MultiblockControllerBase createNewMultiblock() {
return new MultiBlockCasing(worldObj);
}
@Override
public MultiblockControllerBase createNewMultiblock()
{
return new MultiBlockCasing(worldObj);
}
@Override
public Class<? extends MultiblockControllerBase> getMultiblockControllerType() {
return MultiBlockCasing.class;
}
@Override
public Class<? extends MultiblockControllerBase> getMultiblockControllerType()
{
return MultiBlockCasing.class;
}
@Override
public void isGoodForFrame() throws MultiblockValidationException {
@Override
public void isGoodForFrame() throws MultiblockValidationException
{
}
}
@Override
public void isGoodForSides() throws MultiblockValidationException {
@Override
public void isGoodForSides() throws MultiblockValidationException
{
}
}
@Override
public void isGoodForTop() throws MultiblockValidationException {
@Override
public void isGoodForTop() throws MultiblockValidationException
{
}
}
@Override
public void isGoodForBottom() throws MultiblockValidationException {
@Override
public void isGoodForBottom() throws MultiblockValidationException
{
}
}
@Override
public void isGoodForInterior() throws MultiblockValidationException {
@Override
public void isGoodForInterior() throws MultiblockValidationException
{
}
}
public MultiBlockCasing getMultiblockController() {
return (MultiBlockCasing) super.getMultiblockController();
}
public MultiBlockCasing getMultiblockController()
{
return (MultiBlockCasing) super.getMultiblockController();
}
}

View file

@ -1,6 +1,9 @@
package techreborn.tiles;
import ic2.api.tile.IWrenchable;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@ -12,220 +15,268 @@ import techreborn.init.ModBlocks;
import techreborn.util.Inventory;
import techreborn.util.ItemUtils;
import java.util.List;
public class TileQuantumChest extends TileMachineBase implements IInventory,
IWrenchable {
// Slot 0 = Input
// Slot 1 = Output
// Slot 2 = Fake Item
public Inventory inventory = new Inventory(3, "TileQuantumChest",
Integer.MAX_VALUE);
public class TileQuantumChest extends TileMachineBase implements IInventory, IWrenchable {
public ItemStack storedItem;
//Slot 0 = Input
//Slot 1 = Output
//Slot 2 = Fake Item
public Inventory inventory = new Inventory(3, "TileQuantumChest", Integer.MAX_VALUE);
@Override
public void updateEntity()
{
if (storedItem != null)
{
ItemStack fakeStack = storedItem.copy();
fakeStack.stackSize = 1;
setInventorySlotContents(2, fakeStack);
} else
{
setInventorySlotContents(2, null);
}
public ItemStack storedItem;
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();
}
@Override
public void updateEntity() {
if (storedItem != null) {
ItemStack fakeStack = storedItem.copy();
fakeStack.stackSize = 1;
setInventorySlotContents(2, fakeStack);
} else {
setInventorySlotContents(2, null);
}
public Packet getDescriptionPacket()
{
NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord,
this.zCoord, 1, nbtTag);
}
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);
}
}
}
@Override
public void onDataPacket(NetworkManager net,
S35PacketUpdateTileEntity packet)
{
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord,
yCoord, zCoord);
readFromNBT(packet.func_148857_g());
}
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();
}
@Override
public void readFromNBT(NBTTagCompound tagCompound)
{
super.readFromNBT(tagCompound);
readFromNBTWithoutCoords(tagCompound);
}
public void readFromNBTWithoutCoords(NBTTagCompound tagCompound)
{
inventory.readFromNBT(tagCompound);
public Packet getDescriptionPacket() {
NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
}
storedItem = null;
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
readFromNBT(packet.func_148857_g());
}
if (tagCompound.hasKey("storedStack"))
{
storedItem = ItemStack
.loadItemStackFromNBT((NBTTagCompound) tagCompound
.getTag("storedStack"));
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
readFromNBTWithoutCoords(tagCompound);
}
if (storedItem != null)
{
storedItem.stackSize = tagCompound.getInteger("storedQuantity");
}
}
public void readFromNBTWithoutCoords(NBTTagCompound tagCompound) {
inventory.readFromNBT(tagCompound);
@Override
public void writeToNBT(NBTTagCompound tagCompound)
{
super.writeToNBT(tagCompound);
writeToNBTWithoutCoords(tagCompound);
}
storedItem = null;
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);
}
if (tagCompound.hasKey("storedStack")) {
storedItem = ItemStack.
loadItemStackFromNBT((NBTTagCompound) tagCompound.getTag("storedStack"));
}
@Override
public int getSizeInventory()
{
return inventory.getSizeInventory();
}
if (storedItem != null) {
storedItem.stackSize = tagCompound.getInteger("storedQuantity");
}
}
@Override
public ItemStack getStackInSlot(int slot)
{
return inventory.getStackInSlot(slot);
}
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
writeToNBTWithoutCoords(tagCompound);
}
@Override
public ItemStack decrStackSize(int slotId, int count)
{
return inventory.decrStackSize(slotId, count);
}
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 ItemStack getStackInSlotOnClosing(int slot)
{
return inventory.getStackInSlotOnClosing(slot);
}
@Override
public int getSizeInventory() {
return inventory.getSizeInventory();
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack)
{
inventory.setInventorySlotContents(slot, stack);
}
@Override
public ItemStack getStackInSlot(int slot) {
return inventory.getStackInSlot(slot);
}
@Override
public String getInventoryName()
{
return inventory.getInventoryName();
}
@Override
public ItemStack decrStackSize(int slotId, int count) {
return inventory.decrStackSize(slotId, count);
}
@Override
public boolean hasCustomInventoryName()
{
return inventory.hasCustomInventoryName();
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
return inventory.getStackInSlotOnClosing(slot);
}
@Override
public int getInventoryStackLimit()
{
return inventory.getInventoryStackLimit();
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
inventory.setInventorySlotContents(slot, stack);
}
@Override
public boolean isUseableByPlayer(EntityPlayer player)
{
return inventory.isUseableByPlayer(player);
}
@Override
public String getInventoryName() {
return inventory.getInventoryName();
}
@Override
public void openInventory()
{
inventory.openInventory();
}
@Override
public boolean hasCustomInventoryName() {
return inventory.hasCustomInventoryName();
}
@Override
public void closeInventory()
{
inventory.closeInventory();
}
@Override
public int getInventoryStackLimit() {
return inventory.getInventoryStackLimit();
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack)
{
return inventory.isItemValidForSlot(slot, stack);
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return inventory.isUseableByPlayer(player);
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
{
return false;
}
@Override
public void openInventory() {
inventory.openInventory();
}
@Override
public short getFacing()
{
return 0;
}
@Override
public void closeInventory() {
inventory.closeInventory();
}
@Override
public void setFacing(short facing)
{
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return inventory.isItemValidForSlot(slot, stack);
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer)
{
return true;
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
return false;
}
@Override
public float getWrenchDropRate()
{
return 1F;
}
@Override
public short getFacing() {
return 0;
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
{
return getDropWithNBT();
}
@Override
public void setFacing(short facing) {
}
public ItemStack getDropWithNBT()
{
NBTTagCompound tileEntity = new NBTTagCompound();
ItemStack dropStack = new ItemStack(ModBlocks.quantumChest, 1);
writeToNBTWithoutCoords(tileEntity);
dropStack.setTagCompound(new NBTTagCompound());
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
return dropStack;
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
return true;
}
@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);
@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.quantumChest, 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

@ -1,6 +1,9 @@
package techreborn.tiles;
import ic2.api.tile.IWrenchable;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@ -18,197 +21,238 @@ import techreborn.util.FluidUtils;
import techreborn.util.Inventory;
import techreborn.util.Tank;
import java.util.List;
public class TileQuantumTank extends TileMachineBase implements IFluidHandler,
IInventory, IWrenchable {
public class TileQuantumTank extends TileMachineBase implements IFluidHandler, IInventory, IWrenchable {
public Tank tank = new Tank("TileQuantumTank", Integer.MAX_VALUE, this);
public Inventory inventory = new Inventory(3, "TileQuantumTank", 64);
public Tank tank = new Tank("TileQuantumTank", Integer.MAX_VALUE, this);
public Inventory inventory = new Inventory(3, "TileQuantumTank", 64);
@Override
public void readFromNBT(NBTTagCompound tagCompound)
{
super.readFromNBT(tagCompound);
readFromNBTWithoutCoords(tagCompound);
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
readFromNBTWithoutCoords(tagCompound);
}
public void readFromNBTWithoutCoords(NBTTagCompound tagCompound)
{
tank.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound);
}
public void readFromNBTWithoutCoords(NBTTagCompound tagCompound) {
tank.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound);
}
@Override
public void writeToNBT(NBTTagCompound tagCompound)
{
super.writeToNBT(tagCompound);
writeToNBTWithoutCoords(tagCompound);
}
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
writeToNBTWithoutCoords(tagCompound);
}
public void writeToNBTWithoutCoords(NBTTagCompound tagCompound)
{
tank.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound);
}
public void writeToNBTWithoutCoords(NBTTagCompound 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());
}
public Packet getDescriptionPacket() {
NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
}
@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);
}
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
readFromNBT(packet.func_148857_g());
}
// IFluidHandler
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{
return tank.fill(resource, doFill);
}
@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);
}
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource,
boolean doDrain)
{
return tank.drain(resource.amount, doDrain);
}
//IFluidHandler
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
return tank.fill(resource, doFill);
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return tank.drain(maxDrain, doDrain);
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
return tank.drain(resource.amount, doDrain);
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid)
{
return tank.getFluid() == null || tank.getFluid().getFluid() == fluid;
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
return tank.drain(maxDrain, doDrain);
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid)
{
return tank.getFluid() == null || tank.getFluid().getFluid() == fluid;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid) {
return tank.getFluid() == null || tank.getFluid().getFluid() == fluid;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return getTankInfo(from);
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) {
return tank.getFluid() == null || tank.getFluid().getFluid() == fluid;
}
// IInventory
@Override
public int getSizeInventory()
{
return inventory.getSizeInventory();
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
return getTankInfo(from);
}
@Override
public ItemStack getStackInSlot(int slot)
{
return inventory.getStackInSlot(slot);
}
//IInventory
@Override
public int getSizeInventory() {
return inventory.getSizeInventory();
}
@Override
public ItemStack decrStackSize(int slotId, int count)
{
return inventory.decrStackSize(slotId, count);
}
@Override
public ItemStack getStackInSlot(int slot) {
return inventory.getStackInSlot(slot);
}
@Override
public ItemStack getStackInSlotOnClosing(int slot)
{
return inventory.getStackInSlotOnClosing(slot);
}
@Override
public ItemStack decrStackSize(int slotId, int count) {
return inventory.decrStackSize(slotId, count);
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack)
{
inventory.setInventorySlotContents(slot, stack);
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
return inventory.getStackInSlotOnClosing(slot);
}
@Override
public String getInventoryName()
{
return inventory.getInventoryName();
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
inventory.setInventorySlotContents(slot, stack);
}
@Override
public boolean hasCustomInventoryName()
{
return inventory.hasCustomInventoryName();
}
@Override
public String getInventoryName() {
return inventory.getInventoryName();
}
@Override
public int getInventoryStackLimit()
{
return inventory.getInventoryStackLimit();
}
@Override
public boolean hasCustomInventoryName() {
return inventory.hasCustomInventoryName();
}
@Override
public boolean isUseableByPlayer(EntityPlayer player)
{
return inventory.isUseableByPlayer(player);
}
@Override
public int getInventoryStackLimit() {
return inventory.getInventoryStackLimit();
}
@Override
public void openInventory()
{
inventory.openInventory();
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return inventory.isUseableByPlayer(player);
}
@Override
public void closeInventory()
{
inventory.closeInventory();
}
@Override
public void openInventory() {
inventory.openInventory();
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack)
{
return inventory.isItemValidForSlot(slot, stack);
}
@Override
public void closeInventory() {
inventory.closeInventory();
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
{
return false;
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return inventory.isItemValidForSlot(slot, stack);
}
@Override
public short getFacing()
{
return 0;
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
return false;
}
@Override
public void setFacing(short facing)
{
}
@Override
public short getFacing() {
return 0;
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer)
{
return true;
}
@Override
public void setFacing(short facing) {
}
@Override
public float getWrenchDropRate()
{
return 1F;
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
return true;
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
{
return getDropWithNBT();
}
@Override
public float getWrenchDropRate() {
return 1F;
}
public ItemStack getDropWithNBT()
{
NBTTagCompound tileEntity = new NBTTagCompound();
ItemStack dropStack = new ItemStack(ModBlocks.quantumTank, 1);
writeToNBTWithoutCoords(tileEntity);
dropStack.setTagCompound(new NBTTagCompound());
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
return dropStack;
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
return getDropWithNBT();
}
public ItemStack getDropWithNBT() {
NBTTagCompound tileEntity = new NBTTagCompound();
ItemStack dropStack = new ItemStack(ModBlocks.quantumTank, 1);
writeToNBTWithoutCoords(tileEntity);
dropStack.setTagCompound(new NBTTagCompound());
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
return dropStack;
}
@Override
public void addWailaInfo(List<String> info) {
super.addWailaInfo(info);
if (tank.getFluid() != null) {
info.add(tank.getFluidAmount() + " of " + tank.getFluidType().getName());
} else {
info.add("Empty");
}
}
@Override
public void addWailaInfo(List<String> info)
{
super.addWailaInfo(info);
if (tank.getFluid() != null)
{
info.add(tank.getFluidAmount() + " of "
+ tank.getFluidType().getName());
} else
{
info.add("Empty");
}
}
}

View file

@ -15,136 +15,174 @@ import techreborn.util.ItemUtils;
//TODO add tick and power bars.
public class TileRollingMachine extends TileMachineBase implements IWrenchable {
public BasicSink energy;
public Inventory inventory = new Inventory(2, "TileRollingMachine", 64);
public final InventoryCrafting craftMatrix = new InventoryCrafting(new RollingTileContainer(), 3, 3);
public BasicSink energy;
public Inventory inventory = new Inventory(2, "TileRollingMachine", 64);
public final InventoryCrafting craftMatrix = new InventoryCrafting(
new RollingTileContainer(), 3, 3);
public boolean isRunning;
public int tickTime;
public int runTime = 250;
public ItemStack currentRecipe;
public boolean isRunning;
public int tickTime;
public int runTime = 250;
public ItemStack currentRecipe;
public int euTick = 5;
public int euTick = 5;
private static class RollingTileContainer extends Container {
private static class RollingTileContainer extends Container {
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
return true;
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer)
{
return true;
}
}
}
public TileRollingMachine() {
energy = new BasicSink(this, 100000, 1);
}
public TileRollingMachine()
{
energy = new BasicSink(this, 100000, 1);
}
@Override
public void updateEntity() {
super.updateEntity();
energy.updateEntity();
if(!worldObj.isRemote){
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, worldObj);
if(currentRecipe != null && canMake()){
if(tickTime >= runTime){
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, worldObj);
if (currentRecipe != null) {
boolean hasCrafted = false;
if(inventory.getStackInSlot(0) == null){
inventory.setInventorySlotContents(0, currentRecipe);
tickTime = 0;
hasCrafted = true;
} else {
if(inventory.getStackInSlot(0).stackSize + currentRecipe.stackSize <= currentRecipe.getMaxStackSize()){
ItemStack stack = inventory.getStackInSlot(0);
stack.stackSize = stack.stackSize + currentRecipe.stackSize;
inventory.setInventorySlotContents(0, stack);
tickTime = 0;
hasCrafted = true;
}
}
if(hasCrafted){
for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
craftMatrix.decrStackSize(i, 1);
}
currentRecipe = null;
}
}
}
}
if(currentRecipe != null) {
if(energy.canUseEnergy(euTick) && tickTime < runTime){
tickTime ++;
}
}
if(currentRecipe == null){
tickTime = 0;
}
} else {
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, worldObj);
if(currentRecipe != null){
inventory.setInventorySlotContents(1, currentRecipe);
} else {
inventory.setInventorySlotContents(1, null);
}
}
}
@Override
public void updateEntity()
{
super.updateEntity();
energy.updateEntity();
if (!worldObj.isRemote)
{
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(
craftMatrix, worldObj);
if (currentRecipe != null && canMake())
{
if (tickTime >= runTime)
{
currentRecipe = RollingMachineRecipe.instance
.findMatchingRecipe(craftMatrix, worldObj);
if (currentRecipe != null)
{
boolean hasCrafted = false;
if (inventory.getStackInSlot(0) == null)
{
inventory
.setInventorySlotContents(0, currentRecipe);
tickTime = 0;
hasCrafted = true;
} else
{
if (inventory.getStackInSlot(0).stackSize
+ currentRecipe.stackSize <= currentRecipe
.getMaxStackSize())
{
ItemStack stack = inventory.getStackInSlot(0);
stack.stackSize = stack.stackSize
+ currentRecipe.stackSize;
inventory.setInventorySlotContents(0, stack);
tickTime = 0;
hasCrafted = true;
}
}
if (hasCrafted)
{
for (int i = 0; i < craftMatrix.getSizeInventory(); i++)
{
craftMatrix.decrStackSize(i, 1);
}
currentRecipe = null;
}
}
}
}
if (currentRecipe != null)
{
if (energy.canUseEnergy(euTick) && tickTime < runTime)
{
tickTime++;
}
}
if (currentRecipe == null)
{
tickTime = 0;
}
} else
{
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(
craftMatrix, worldObj);
if (currentRecipe != null)
{
inventory.setInventorySlotContents(1, currentRecipe);
} else
{
inventory.setInventorySlotContents(1, null);
}
}
}
public boolean canMake() {
if (RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, worldObj) == null){
return false;
}
return true;
}
public boolean canMake()
{
if (RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix,
worldObj) == null)
{
return false;
}
return true;
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
return false;
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
{
return false;
}
@Override
public short getFacing() {
return 0;
}
@Override
public short getFacing()
{
return 0;
}
@Override
public void setFacing(short facing) {
}
@Override
public void setFacing(short facing)
{
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
return true;
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer)
{
return true;
}
@Override
public float getWrenchDropRate() {
return 1.0F;
}
@Override
public float getWrenchDropRate()
{
return 1.0F;
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.RollingMachine, 1);
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
{
return new ItemStack(ModBlocks.RollingMachine, 1);
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound);
ItemUtils.readInvFromNBT(craftMatrix, "Crafting", tagCompound);
isRunning = tagCompound.getBoolean("isRunning");
tickTime = tagCompound.getInteger("tickTime");
}
@Override
public void readFromNBT(NBTTagCompound tagCompound)
{
super.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound);
ItemUtils.readInvFromNBT(craftMatrix, "Crafting", tagCompound);
isRunning = tagCompound.getBoolean("isRunning");
tickTime = tagCompound.getInteger("tickTime");
}
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound);
ItemUtils.writeInvToNBT(craftMatrix, "Crafting", tagCompound);
writeUpdateToNBT(tagCompound);
}
@Override
public void writeToNBT(NBTTagCompound tagCompound)
{
super.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound);
ItemUtils.writeInvToNBT(craftMatrix, "Crafting", tagCompound);
writeUpdateToNBT(tagCompound);
}
public void writeUpdateToNBT(NBTTagCompound tagCompound) {
tagCompound.setBoolean("isRunning", isRunning);
tagCompound.setInteger("tickTime", tickTime);
}
public void writeUpdateToNBT(NBTTagCompound tagCompound)
{
tagCompound.setBoolean("isRunning", isRunning);
tagCompound.setInteger("tickTime", tickTime);
}
}

View file

@ -11,201 +11,253 @@ 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.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import techreborn.util.FluidUtils;
import techreborn.util.Inventory;
import techreborn.util.Tank;
public class TileThermalGenerator extends TileEntity implements IWrenchable, IFluidHandler, IInventory {
public class TileThermalGenerator extends TileEntity implements IWrenchable,
IFluidHandler, IInventory {
public Tank tank = new Tank("TileThermalGenerator", FluidContainerRegistry.BUCKET_VOLUME * 10, this);
public Inventory inventory = new Inventory(3, "TileThermalGenerator", 64);
public BasicSource energySource;
public static final int euTick = ConfigTechReborn.ThermalGenertaorOutput;
public Tank tank = new Tank("TileThermalGenerator",
FluidContainerRegistry.BUCKET_VOLUME * 10, this);
public Inventory inventory = new Inventory(3, "TileThermalGenerator", 64);
public BasicSource energySource;
public static final int euTick = ConfigTechReborn.ThermalGenertaorOutput;
public TileThermalGenerator() {
this.energySource = new BasicSource(this, ConfigTechReborn.ThermalGeneratorCharge, ConfigTechReborn.ThermalGeneratorTier);
}
public TileThermalGenerator()
{
this.energySource = new BasicSource(this,
ConfigTechReborn.ThermalGeneratorCharge,
ConfigTechReborn.ThermalGeneratorTier);
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
return false;
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side)
{
return false;
}
@Override
public short getFacing() {
return 0;
}
@Override
public short getFacing()
{
return 0;
}
@Override
public void setFacing(short facing) {
}
@Override
public void setFacing(short facing)
{
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
return true;
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer)
{
return true;
}
@Override
public float getWrenchDropRate() {
return 1.0F;
}
@Override
public float getWrenchDropRate()
{
return 1.0F;
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.thermalGenerator, 1);
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
{
return new ItemStack(ModBlocks.thermalGenerator, 1);
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
return tank.fill(resource, doFill);
}
@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, 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 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 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 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 FluidTankInfo[] getTankInfo(ForgeDirection from)
{
return getTankInfo(from);
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
tank.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound);
energySource.readFromNBT(tagCompound);
}
@Override
public void readFromNBT(NBTTagCompound tagCompound)
{
super.readFromNBT(tagCompound);
tank.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound);
energySource.readFromNBT(tagCompound);
}
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
tank.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound);
energySource.writeToNBT(tagCompound);
}
@Override
public void writeToNBT(NBTTagCompound tagCompound)
{
super.writeToNBT(tagCompound);
tank.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound);
energySource.writeToNBT(tagCompound);
}
public Packet getDescriptionPacket() {
NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
}
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 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);
energySource.updateEntity();
if (tank.getFluidAmount() > 0 && energySource.getCapacity() - energySource.getEnergyStored() >= euTick) {
tank.drain(1, true);
energySource.addEnergy(euTick);
}
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);
}
}
@Override
public void updateEntity()
{
super.updateEntity();
FluidUtils.drainContainers(this, inventory, 0, 1);
energySource.updateEntity();
if (tank.getFluidAmount() > 0
&& energySource.getCapacity() - energySource.getEnergyStored() >= euTick)
{
tank.drain(1, true);
energySource.addEnergy(euTick);
}
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);
}
}
@Override
public int getSizeInventory() {
return inventory.getSizeInventory();
}
@Override
public int getSizeInventory()
{
return inventory.getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int p_70301_1_) {
return inventory.getStackInSlot(p_70301_1_);
}
@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 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 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 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 String getInventoryName()
{
return inventory.getInventoryName();
}
@Override
public boolean hasCustomInventoryName() {
return inventory.hasCustomInventoryName();
}
@Override
public boolean hasCustomInventoryName()
{
return inventory.hasCustomInventoryName();
}
@Override
public int getInventoryStackLimit() {
return inventory.getInventoryStackLimit();
}
@Override
public int getInventoryStackLimit()
{
return inventory.getInventoryStackLimit();
}
@Override
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
return inventory.isUseableByPlayer(p_70300_1_);
}
@Override
public boolean isUseableByPlayer(EntityPlayer p_70300_1_)
{
return inventory.isUseableByPlayer(p_70300_1_);
}
@Override
public void openInventory() {
inventory.openInventory();
}
@Override
public void openInventory()
{
inventory.openInventory();
}
@Override
public void closeInventory() {
inventory.closeInventory();
}
@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_);
}
@Override
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_)
{
return inventory.isItemValidForSlot(p_94041_1_, p_94041_2_);
}
@Override
public void onChunkUnload() {
energySource.onChunkUnload();
}
@Override
public void onChunkUnload()
{
energySource.onChunkUnload();
}
@Override
public void invalidate() {
energySource.invalidate();
super.invalidate();
}
@Override
public void invalidate()
{
energySource.invalidate();
super.invalidate();
}
}