Made it work, need to figure out the ic2 cells, for now it uses resin
This commit is contained in:
parent
1824e0bf36
commit
822879a6b6
4 changed files with 123 additions and 61 deletions
|
@ -11,10 +11,13 @@ public class GuiCentrifuge extends GuiContainer {
|
||||||
|
|
||||||
private static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/centrifuge.png");
|
private static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/centrifuge.png");
|
||||||
|
|
||||||
|
TileCentrifuge centrifuge;
|
||||||
|
|
||||||
public GuiCentrifuge(EntityPlayer player, TileCentrifuge tileCentrifuge) {
|
public GuiCentrifuge(EntityPlayer player, TileCentrifuge tileCentrifuge) {
|
||||||
super(new ContainerCentrifuge(tileCentrifuge, player));
|
super(new ContainerCentrifuge(tileCentrifuge, player));
|
||||||
this.xSize = 176;
|
this.xSize = 176;
|
||||||
this.ySize = 167;
|
this.ySize = 167;
|
||||||
|
centrifuge = tileCentrifuge;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,5 +32,6 @@ public class GuiCentrifuge extends GuiContainer {
|
||||||
{
|
{
|
||||||
this.fontRendererObj.drawString("Centrifuge", 110, 6, 4210752);
|
this.fontRendererObj.drawString("Centrifuge", 110, 6, 4210752);
|
||||||
this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
|
this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
|
||||||
|
this.fontRendererObj.drawString(centrifuge.tickTime + " " + centrifuge.isRunning, 110, this.ySize - 96 + 2, 4210752);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,9 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.network.NetworkManager;
|
||||||
|
import net.minecraft.network.Packet;
|
||||||
|
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||||
import techreborn.api.CentrifugeRecipie;
|
import techreborn.api.CentrifugeRecipie;
|
||||||
import techreborn.api.TechRebornAPI;
|
import techreborn.api.TechRebornAPI;
|
||||||
import techreborn.util.Inventory;
|
import techreborn.util.Inventory;
|
||||||
|
@ -33,71 +36,85 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
energy.updateEntity();
|
energy.updateEntity();
|
||||||
if(isRunning){
|
if(!worldObj.isRemote){
|
||||||
if(ItemUtils.isItemEqual(currentRecipe.getInputItem(), getStackInSlot(0), true, true)){
|
if(isRunning){
|
||||||
if(!hasTakenCells){
|
if(ItemUtils.isItemEqual(currentRecipe.getInputItem(), getStackInSlot(0), true, true)){
|
||||||
if(getStackInSlot(1) != null && ItemUtils.isItemEqual(getStackInSlot(1), IC2Items.getItem("resin"), true, true)){
|
if(!hasTakenCells){
|
||||||
if(getStackInSlot(1).stackSize >= currentRecipe.getCells()){
|
if(getStackInSlot(1) != null && ItemUtils.isItemEqual(getStackInSlot(1), IC2Items.getItem("resin"), true, true)){
|
||||||
decrStackSize(1, currentRecipe.getCells());
|
if(getStackInSlot(1).stackSize >= currentRecipe.getCells()){
|
||||||
hasTakenCells = true;
|
decrStackSize(1, currentRecipe.getCells());
|
||||||
|
hasTakenCells = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(hasTakenCells && hasTakenItem){
|
||||||
|
if(tickTime == currentRecipe.getTickTime()) {
|
||||||
|
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 ++;
|
||||||
|
syncWithAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(hasTakenCells && hasTakenItem){
|
} else {
|
||||||
if(tickTime == currentRecipe.getTickTime()) {
|
//sets a new recipe
|
||||||
if(areOutputsEqual() || areOutputsEmpty()){
|
if(getStackInSlot(0) != null && currentRecipe == null){
|
||||||
setOutput(1, currentRecipe.getOutput1());
|
for(CentrifugeRecipie recipie: TechRebornAPI.centrifugeRecipies){
|
||||||
setOutput(2, currentRecipe.getOutput2());
|
if(ItemUtils.isItemEqual(recipie.getInputItem(), getStackInSlot(0), true, true)){
|
||||||
setOutput(3, currentRecipe.getOutput3());
|
currentRecipe = new CentrifugeRecipie(recipie);
|
||||||
setOutput(4, currentRecipe.getOutput4());
|
}
|
||||||
tickTime = 0;
|
|
||||||
isRunning = false;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(energy.canUseEnergy(euTick)){
|
|
||||||
if(getStackInSlot(0) != null && ItemUtils.isItemEqual(getStackInSlot(0), currentRecipe.getInputItem(), true, true)){
|
|
||||||
if(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(!isRunning && currentRecipe != null){
|
if(areOutputsEqual() || areOutputsEmpty()){
|
||||||
if(areOutputsEqual() || areOutputsEmpty()){
|
if(getStackInSlot(0) != null && currentRecipe.getInputItem().stackSize <= getStackInSlot(0).stackSize){
|
||||||
|
if(energy.canUseEnergy(euTick)){
|
||||||
if(currentRecipe.getInputItem().stackSize <= getStackInSlot(0).stackSize){
|
decrStackSize(0, currentRecipe.getInputItem().stackSize);
|
||||||
if(energy.canUseEnergy(euTick)){
|
hasTakenItem = true;
|
||||||
decrStackSize(0, currentRecipe.getInputItem().stackSize);
|
tickTime = 0;
|
||||||
hasTakenItem = true;
|
isRunning = true;
|
||||||
tickTime = 0;
|
syncWithAll();
|
||||||
isRunning = true;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println(hasTakenItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean areOutputsEqual(){
|
public boolean areOutputsEqual(){
|
||||||
if(currentRecipe == null){
|
if(currentRecipe == null){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(ItemUtils.isItemEqual(getOutputItemStack(1), currentRecipe.getOutput1(), true, true)){
|
if(ItemUtils.isItemEqual(getOutputItemStack(1), currentRecipe.getOutput1(), false, true)){
|
||||||
if(ItemUtils.isItemEqual(getOutputItemStack(2), currentRecipe.getOutput2(), true, true)){
|
if(ItemUtils.isItemEqual(getOutputItemStack(2), currentRecipe.getOutput2(), false, true)){
|
||||||
if(ItemUtils.isItemEqual(getOutputItemStack(3), currentRecipe.getOutput3(), true, true)){
|
if(ItemUtils.isItemEqual(getOutputItemStack(3), currentRecipe.getOutput3(), false, true)){
|
||||||
if(ItemUtils.isItemEqual(getOutputItemStack(4), currentRecipe.getOutput4(), true, true)){
|
if(ItemUtils.isItemEqual(getOutputItemStack(4), currentRecipe.getOutput4(), false, true)){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,12 +127,18 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
|
||||||
return getOutputItemStack(1) == null && getOutputItemStack(2) == null && getOutputItemStack(3) == null && getOutputItemStack(4) == null;
|
return getOutputItemStack(1) == null && getOutputItemStack(2) == null && getOutputItemStack(3) == null && getOutputItemStack(4) == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ItemStack getOutputItemStack(int slot){
|
public ItemStack getOutputItemStack(int slot){
|
||||||
return getStackInSlot(slot + 1);
|
return getStackInSlot(slot + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void increacseItemStack(int slot, int amount) {
|
||||||
|
decrStackSize(slot + 1, -amount);
|
||||||
|
}
|
||||||
|
|
||||||
public void setOutput(int slot, ItemStack stack){
|
public void setOutput(int slot, ItemStack stack){
|
||||||
|
if(stack == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
setInventorySlotContents(slot + 1, stack);
|
setInventorySlotContents(slot + 1, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,12 +146,27 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
|
||||||
public void readFromNBT(NBTTagCompound tagCompound) {
|
public void readFromNBT(NBTTagCompound tagCompound) {
|
||||||
super.readFromNBT(tagCompound);
|
super.readFromNBT(tagCompound);
|
||||||
inventory.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
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound tagCompound) {
|
public void writeToNBT(NBTTagCompound tagCompound) {
|
||||||
super.writeToNBT(tagCompound);
|
super.writeToNBT(tagCompound);
|
||||||
inventory.writeToNBT(tagCompound);
|
inventory.writeToNBT(tagCompound);
|
||||||
|
tagCompound.setString("recipe", currentRecipe.getInputItem().getUnlocalizedName());
|
||||||
|
tagCompound.setBoolean("isRunning", isRunning);
|
||||||
|
tagCompound.setInteger("tickTime", tickTime);
|
||||||
|
tagCompound.setBoolean("hasTakenCells", hasTakenCells);
|
||||||
|
tagCompound.setBoolean("hasTakenItem", hasTakenItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -201,12 +239,15 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
|
||||||
energy.onChunkUnload();
|
energy.onChunkUnload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean useEnergy(double amount) {
|
public Packet getDescriptionPacket() {
|
||||||
if(energy.canUseEnergy(amount)) {
|
NBTTagCompound nbtTag = new NBTTagCompound();
|
||||||
energy.setEnergyStored(energy.getEnergyStored() - amount);
|
writeToNBT(nbtTag);
|
||||||
return true;
|
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
|
||||||
} else {
|
}
|
||||||
return false;
|
|
||||||
}
|
@Override
|
||||||
|
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
|
||||||
|
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
|
||||||
|
readFromNBT(packet.func_148857_g());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package techreborn.tiles;
|
package techreborn.tiles;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import techreborn.packets.PacketHandler;
|
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
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.packets.PacketHandler;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class TileMachineBase extends TileEntity {
|
public class TileMachineBase extends TileEntity {
|
||||||
|
|
||||||
|
@ -26,4 +30,16 @@ public class TileMachineBase extends TileEntity {
|
||||||
PacketHandler.sendPacketToAllPlayers(getDescriptionPacket(), worldObj);
|
PacketHandler.sendPacketToAllPlayers(getDescriptionPacket(), worldObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ public class TileQuantumChest extends TileMachineBase implements IInventory ,IWr
|
||||||
storedItem = null;
|
storedItem = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
syncWithAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue