Generator logic
This commit is contained in:
parent
c8453292b4
commit
b61acffc68
4 changed files with 108 additions and 32 deletions
|
@ -1,8 +1,11 @@
|
|||
package techreborn.client.container;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.inventory.SlotFurnaceFuel;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import reborncore.common.container.RebornContainer;
|
||||
import techreborn.tiles.generator.TileGenerator;
|
||||
|
||||
|
@ -12,6 +15,10 @@ public class ContainerGenerator extends RebornContainer {
|
|||
|
||||
TileGenerator tile;
|
||||
|
||||
public int burnTime = 0;
|
||||
public int totalBurnTime = 0;
|
||||
public int energy;
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
return true;
|
||||
|
@ -45,4 +52,46 @@ public class ContainerGenerator extends RebornContainer {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
for (int i = 0; i < this.crafters.size(); i++) {
|
||||
ICrafting icrafting = (ICrafting) this.crafters.get(i);
|
||||
if (this.burnTime != tile.burnTime) {
|
||||
icrafting.sendProgressBarUpdate(this, 0, tile.burnTime);
|
||||
}
|
||||
if (this.totalBurnTime != tile.totalBurnTime) {
|
||||
icrafting.sendProgressBarUpdate(this, 1, tile.totalBurnTime);
|
||||
}
|
||||
if (this.energy != (int) tile.getEnergy()) {
|
||||
icrafting.sendProgressBarUpdate(this, 2, (int) tile.getEnergy());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCraftGuiOpened(ICrafting crafting) {
|
||||
super.onCraftGuiOpened(crafting);
|
||||
crafting.sendProgressBarUpdate(this, 0, tile.burnTime);
|
||||
crafting.sendProgressBarUpdate(this, 1, tile.totalBurnTime);
|
||||
crafting.sendProgressBarUpdate(this, 2, (int) tile.getEnergy());
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void updateProgressBar(int id, int value) {
|
||||
if (id == 0) {
|
||||
this.burnTime = value;
|
||||
} else if (id == 1) {
|
||||
this.totalBurnTime = value;
|
||||
} else if (id == 2) {
|
||||
this.energy = value;
|
||||
}
|
||||
this.tile.setEnergy(energy);
|
||||
}
|
||||
|
||||
public int getScaledBurnTime(int i) {
|
||||
return (int) (((float) burnTime / (float) totalBurnTime) * i);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package techreborn.client.gui;
|
|||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import techreborn.client.container.ContainerGenerator;
|
||||
|
@ -14,11 +15,14 @@ public class GuiGenerator extends GuiContainer {
|
|||
|
||||
TileGenerator generator;
|
||||
|
||||
ContainerGenerator containerGenerator;
|
||||
|
||||
public GuiGenerator(EntityPlayer player, TileGenerator generator) {
|
||||
super(new ContainerGenerator(generator, player));
|
||||
this.xSize = 176;
|
||||
this.ySize = 167;
|
||||
this.generator = generator;
|
||||
this.containerGenerator = (ContainerGenerator) this.inventorySlots;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,11 +45,19 @@ public class GuiGenerator extends GuiContainer {
|
|||
if (j > 0) {
|
||||
this.drawTexturedModalRect(k + 56, l + 36 + 12 - j, 176, 12 - j, 14, j + 2);
|
||||
}
|
||||
|
||||
if (containerGenerator.burnTime != 0)
|
||||
{
|
||||
j = containerGenerator.getScaledBurnTime(13);
|
||||
this.drawTexturedModalRect(k + 56, l + 36 + 12 - j, 176, 12 - j, 14, j + 1);
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
|
||||
String name = StatCollector.translateToLocal("tile.techreborn.generator.name");
|
||||
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);
|
||||
this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
|
||||
|
||||
this.fontRendererObj.drawString(containerGenerator.energy + "eu", 25, this.ySize- 150, 4210752);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue