Fixed the centrifuge, still needs some testing.
This commit is contained in:
parent
4746968a04
commit
f49b8c27c2
2 changed files with 47 additions and 32 deletions
|
@ -1,6 +1,7 @@
|
|||
package techreborn.client.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import techreborn.client.SlotOutput;
|
||||
import techreborn.tiles.TileCentrifuge;
|
||||
|
@ -11,6 +12,8 @@ public class ContainerCentrifuge extends TechRebornContainer {
|
|||
|
||||
TileCentrifuge tile;
|
||||
|
||||
public int tickTime;
|
||||
|
||||
public ContainerCentrifuge(TileCentrifuge tileCentrifuge, EntityPlayer player){
|
||||
tile = tileCentrifuge;
|
||||
this.player = player;
|
||||
|
@ -42,4 +45,24 @@ public class ContainerCentrifuge extends TechRebornContainer {
|
|||
public boolean canInteractWith(EntityPlayer player) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import net.minecraft.network.Packet;
|
|||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import techreborn.api.CentrifugeRecipie;
|
||||
import techreborn.api.TechRebornAPI;
|
||||
import techreborn.packets.PacketHandler;
|
||||
import techreborn.util.Inventory;
|
||||
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(energy.useEnergy(5)){
|
||||
tickTime ++;
|
||||
syncWithAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,19 +92,19 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
|
|||
}
|
||||
}
|
||||
if(!isRunning && currentRecipe != null){
|
||||
if(areOutputsEqual() || areOutputsEmpty() && !areAnyOutputsFull()){
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
syncWithAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,16 +112,20 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
|
|||
if(currentRecipe == null){
|
||||
return false;
|
||||
}
|
||||
if(ItemUtils.isItemEqual(getOutputItemStack(1), currentRecipe.getOutput1(), false, true)){
|
||||
if(ItemUtils.isItemEqual(getOutputItemStack(2), currentRecipe.getOutput2(), false, true)){
|
||||
if(ItemUtils.isItemEqual(getOutputItemStack(3), currentRecipe.getOutput3(), false, true)){
|
||||
if(ItemUtils.isItemEqual(getOutputItemStack(4), currentRecipe.getOutput4(), false, true)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean boo = false;
|
||||
if(currentRecipe.getOutput1() != null && ItemUtils.isItemEqual(getOutputItemStack(1), currentRecipe.getOutput1(), false, true)){
|
||||
boo = true;
|
||||
}
|
||||
return false;
|
||||
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(){
|
||||
|
@ -151,6 +153,12 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
|
|||
}
|
||||
|
||||
public void increacseItemStack(int slot, int amount) {
|
||||
if(getOutputItemStack(slot) == null){
|
||||
return;
|
||||
}
|
||||
if(getOutputItemStack(slot).getItem() == null){
|
||||
return;
|
||||
}
|
||||
decrStackSize(slot + 1, -amount);
|
||||
}
|
||||
|
||||
|
@ -158,6 +166,9 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
|
|||
if(stack == null){
|
||||
return;
|
||||
}
|
||||
if(stack.getItem() == null){
|
||||
return;
|
||||
}
|
||||
setInventorySlotContents(slot + 1, stack);
|
||||
}
|
||||
|
||||
|
@ -243,7 +254,6 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
|
|||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
syncAllWithAll();
|
||||
inventory.openInventory();
|
||||
}
|
||||
|
||||
|
@ -273,24 +283,6 @@ public class TileCentrifuge extends TileMachineBase implements IInventory {
|
|||
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
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
|
||||
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
|
||||
|
|
Loading…
Reference in a new issue