TechReborn/src/main/java/techreborn/client/container/ContainerRollingMachine.java

119 lines
3.8 KiB
Java
Raw Normal View History

2015-04-14 01:12:24 +02:00
package techreborn.client.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
2015-04-15 18:27:05 +02:00
import net.minecraft.inventory.IInventory;
2015-04-14 01:12:24 +02:00
import net.minecraft.inventory.Slot;
2015-04-15 18:27:05 +02:00
import net.minecraft.item.ItemStack;
2015-11-08 13:15:45 +01:00
import reborncore.client.gui.SlotFake;
import reborncore.client.gui.SlotOutput;
import reborncore.common.container.RebornContainer;
2015-04-15 18:27:05 +02:00
import techreborn.api.RollingMachineRecipe;
2015-04-15 17:23:12 +02:00
import techreborn.tiles.TileRollingMachine;
2015-04-14 01:12:24 +02:00
2015-11-08 13:15:45 +01:00
public class ContainerRollingMachine extends RebornContainer {
2015-04-15 17:23:12 +02:00
EntityPlayer player;
TileRollingMachine tile;
2015-04-24 15:20:09 +02:00
public ContainerRollingMachine(TileRollingMachine tileRollingmachine,
EntityPlayer player) {
tile = tileRollingmachine;
this.player = player;
2015-04-24 15:20:09 +02:00
for (int l = 0; l < 3; l++) {
for (int k1 = 0; k1 < 3; k1++) {
this.addSlotToContainer(new Slot(
tileRollingmachine.craftMatrix, k1 + l * 3,
30 + k1 * 18, 17 + l * 18));
}
}
2015-04-24 15:20:09 +02:00
// output
this.addSlotToContainer(new SlotOutput(tileRollingmachine.inventory, 0,
124, 35));
2015-04-24 15:20:09 +02:00
// fakeOutput
this.addSlotToContainer(new SlotFake(tileRollingmachine.inventory, 1,
124, 10, false, false, 1));
2015-04-24 15:20:09 +02:00
int i;
2015-04-24 15:20:09 +02:00
for (i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
this.addSlotToContainer(new Slot(player.inventory, j + i * 9
+ 9, 8 + j * 18, 84 + i * 18));
}
}
2015-04-24 15:20:09 +02:00
for (i = 0; i < 9; ++i) {
this.addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18,
142));
}
}
2015-04-24 15:20:09 +02:00
@Override
public boolean canInteractWith(EntityPlayer player) {
return true;
}
2015-04-24 15:20:09 +02:00
@Override
public final void onCraftMatrixChanged(IInventory inv) {
ItemStack output = RollingMachineRecipe.instance.findMatchingRecipe(
tile.craftMatrix, tile.getWorldObj());
tile.inventory.setInventorySlotContents(1, output);
}
2015-04-15 18:27:05 +02:00
int currentItemBurnTime;
int burnTime;
int energy;
@Override
public void addCraftingToCrafters(ICrafting crafting) {
super.addCraftingToCrafters(crafting);
crafting.sendProgressBarUpdate(this, 0, tile.runTime);
crafting.sendProgressBarUpdate(this, 1, tile.tickTime);
crafting.sendProgressBarUpdate(this, 2, (int) tile.getEnergy());
}
@Override
public void detectAndSendChanges() {
for (int i = 0; i < this.crafters.size(); i++) {
ICrafting crafting = (ICrafting) this.crafters.get(i);
if (this.currentItemBurnTime != tile.runTime) {
crafting.sendProgressBarUpdate(this, 0, tile.runTime);
}
if (this.burnTime != tile.tickTime) {
crafting.sendProgressBarUpdate(this, 1, tile.tickTime);
}
2015-11-08 13:15:45 +01:00
if (this.energy != (int) tile.getEnergy()) {
crafting.sendProgressBarUpdate(this, 2, (int) tile.getEnergy());
}
}
super.detectAndSendChanges();
}
@Override
public void updateProgressBar(int id, int value) {
super.updateProgressBar(id, value);
2015-11-08 13:15:45 +01:00
if (id == 0) {
this.currentItemBurnTime = value;
2015-11-08 13:15:45 +01:00
} else if (id == 1) {
this.burnTime = value;
2015-11-08 13:15:45 +01:00
} else if (id == 2) {
this.energy = value;
}
this.tile.runTime = this.currentItemBurnTime;
this.tile.tickTime = this.burnTime;
this.tile.setEnergy(this.energy);
}
2015-11-08 13:15:45 +01:00
public int getBurnTimeRemainingScaled(int scale) {
if (burnTime == 0 || this.currentItemBurnTime == 0) {
return 0;
}
return this.burnTime * scale / this.currentItemBurnTime;
}
2015-04-14 01:12:24 +02:00
}