Fixed the centrifuge, still needs some testing.

This commit is contained in:
Modmuss50 2015-04-14 08:35:44 +01:00
parent 4746968a04
commit f49b8c27c2
2 changed files with 47 additions and 32 deletions

View file

@ -1,6 +1,7 @@
package techreborn.client.container; package techreborn.client.container;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import techreborn.client.SlotOutput; import techreborn.client.SlotOutput;
import techreborn.tiles.TileCentrifuge; import techreborn.tiles.TileCentrifuge;
@ -11,6 +12,8 @@ public class ContainerCentrifuge extends TechRebornContainer {
TileCentrifuge tile; TileCentrifuge tile;
public int tickTime;
public ContainerCentrifuge(TileCentrifuge tileCentrifuge, EntityPlayer player){ public ContainerCentrifuge(TileCentrifuge tileCentrifuge, EntityPlayer player){
tile = tileCentrifuge; tile = tileCentrifuge;
this.player = player; this.player = player;
@ -42,4 +45,24 @@ public class ContainerCentrifuge extends TechRebornContainer {
public boolean canInteractWith(EntityPlayer player) { public boolean canInteractWith(EntityPlayer player) {
return true; return true;
} }
@Override
public void addCraftingToCrafters(ICrafting crafting) {
super.addCraftingToCrafters(crafting);
crafting.sendProgressBarUpdate(this, 0, tile.tickTime);
}
/**
* Looks for changes made in the container, sends them to every listener.
*/
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (int i = 0; i < this.crafters.size(); ++i) {
ICrafting icrafting = (ICrafting)this.crafters.get(i);
if (this.tickTime != this.tile.tickTime) {
icrafting.sendProgressBarUpdate(this, 0, this.tile.tickTime);
}
}
this.tickTime = this.tile.tickTime;
}
} }

View file

@ -10,7 +10,6 @@ import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity; 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.packets.PacketHandler;
import techreborn.util.Inventory; import techreborn.util.Inventory;
import techreborn.util.ItemUtils; import techreborn.util.ItemUtils;
@ -78,7 +77,6 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
if(getStackInSlot(0) != null && ItemUtils.isItemEqual(getStackInSlot(0), currentRecipe.getInputItem(), true, true)){ if(getStackInSlot(0) != null && ItemUtils.isItemEqual(getStackInSlot(0), currentRecipe.getInputItem(), true, true)){
if(energy.useEnergy(5)){ if(energy.useEnergy(5)){
tickTime ++; tickTime ++;
syncWithAll();
} }
} }
} }
@ -94,36 +92,40 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
} }
} }
if(!isRunning && currentRecipe != null){ if(!isRunning && currentRecipe != null){
if(areOutputsEqual() || areOutputsEmpty() && !areAnyOutputsFull()){ if(areOutputsEqual() || !areAnyOutputsFull()){
if(getStackInSlot(0) != null && currentRecipe.getInputItem().stackSize <= getStackInSlot(0).stackSize){ if(getStackInSlot(0) != null && currentRecipe.getInputItem().stackSize <= getStackInSlot(0).stackSize){
if(energy.canUseEnergy(euTick)){ if(energy.canUseEnergy(euTick)){
decrStackSize(0, currentRecipe.getInputItem().stackSize); decrStackSize(0, currentRecipe.getInputItem().stackSize);
hasTakenItem = true; hasTakenItem = true;
tickTime = 0; tickTime = 0;
isRunning = true; isRunning = true;
}
}
}
}
}
syncWithAll(); syncWithAll();
} }
} }
}
}
}
}
}
public boolean areOutputsEqual(){ public boolean areOutputsEqual(){
if(currentRecipe == null){ if(currentRecipe == null){
return false; return false;
} }
if(ItemUtils.isItemEqual(getOutputItemStack(1), currentRecipe.getOutput1(), false, true)){ boolean boo = false;
if(ItemUtils.isItemEqual(getOutputItemStack(2), currentRecipe.getOutput2(), false, true)){ if(currentRecipe.getOutput1() != null && ItemUtils.isItemEqual(getOutputItemStack(1), currentRecipe.getOutput1(), false, true)){
if(ItemUtils.isItemEqual(getOutputItemStack(3), currentRecipe.getOutput3(), false, true)){ boo = true;
if(ItemUtils.isItemEqual(getOutputItemStack(4), currentRecipe.getOutput4(), false, true)){
return 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 false; return boo;
} }
public boolean areOutputsEmpty(){ public boolean areOutputsEmpty(){
@ -151,6 +153,12 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
} }
public void increacseItemStack(int slot, int amount) { public void increacseItemStack(int slot, int amount) {
if(getOutputItemStack(slot) == null){
return;
}
if(getOutputItemStack(slot).getItem() == null){
return;
}
decrStackSize(slot + 1, -amount); decrStackSize(slot + 1, -amount);
} }
@ -158,6 +166,9 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
if(stack == null){ if(stack == null){
return; return;
} }
if(stack.getItem() == null){
return;
}
setInventorySlotContents(slot + 1, stack); setInventorySlotContents(slot + 1, stack);
} }
@ -243,7 +254,6 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
@Override @Override
public void openInventory() { public void openInventory() {
syncAllWithAll();
inventory.openInventory(); inventory.openInventory();
} }
@ -273,24 +283,6 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
} }
public Packet getDescriptionPacketWithOutInv() {
NBTTagCompound nbtTag = new NBTTagCompound();
writeUpdateToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
}
public void syncWithAll() {
if (!worldObj.isRemote) {
PacketHandler.sendPacketToAllPlayers(getDescriptionPacketWithOutInv(), worldObj);
}
}
public void syncAllWithAll() {
if (!worldObj.isRemote) {
PacketHandler.sendPacketToAllPlayers(getDescriptionPacket(), worldObj);
}
}
@Override @Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord); worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);