GUI rework for Diesel generator
This commit is contained in:
parent
d5a3118801
commit
37d8b8641f
5 changed files with 57 additions and 74 deletions
|
@ -24,55 +24,37 @@
|
|||
|
||||
package techreborn.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
import reborncore.common.powerSystem.PowerSystem;
|
||||
import techreborn.tiles.generator.TileDieselGenerator;
|
||||
|
||||
public class GuiDieselGenerator extends GuiContainer {
|
||||
public class GuiDieselGenerator extends GuiBase {
|
||||
|
||||
TileDieselGenerator tile;
|
||||
|
||||
private static final ResourceLocation texture = new ResourceLocation("techreborn",
|
||||
"textures/gui/diesel_generator.png");
|
||||
|
||||
TileDieselGenerator dieselGenerator;
|
||||
|
||||
public GuiDieselGenerator(final EntityPlayer player, final TileDieselGenerator dieselGenerator) {
|
||||
super(dieselGenerator.createContainer(player));
|
||||
this.xSize = 176;
|
||||
this.ySize = 167;
|
||||
this.dieselGenerator = dieselGenerator;
|
||||
public GuiDieselGenerator(final EntityPlayer player, final TileDieselGenerator tile) {
|
||||
super(player, tile, tile.createContainer(player));
|
||||
this.tile = tile;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(final float p_146976_1_, final int p_146976_2_, final int p_146976_3_) {
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.mc.getTextureManager().bindTexture(GuiDieselGenerator.texture);
|
||||
final int k = (this.width - this.xSize) / 2;
|
||||
final int l = (this.height - this.ySize) / 2;
|
||||
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
|
||||
protected void drawGuiContainerBackgroundLayer(final float f, final int mouseX, final int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
|
||||
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
|
||||
drawSlot(10, 35, layer);
|
||||
drawSlot(10, 55, layer);
|
||||
this.builder.drawJEIButton(this, 150, 4, layer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(final int p_146979_1_, final int p_146979_2_) {
|
||||
final String name = I18n.translateToLocal("techreborn.jei.category.generator.diesel");
|
||||
this.fontRenderer.drawString(name, this.xSize / 2 - this.fontRenderer.getStringWidth(name) / 2, 6,
|
||||
4210752);
|
||||
this.fontRenderer.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8,
|
||||
this.ySize - 96 + 2, 4210752);
|
||||
this.fontRenderer.drawString("Liquid Amount", 10, 20, 16448255);
|
||||
this.fontRenderer.drawString(this.dieselGenerator.tank.getFluidAmount() + "", 10, 30, 16448255);
|
||||
|
||||
this.fontRenderer.drawString("Power Amount", 10, 40, 16448255);
|
||||
this.fontRenderer.drawString(PowerSystem.getLocaliszedPower(this.dieselGenerator.getEnergy()) + "", 10, 50,
|
||||
16448255);
|
||||
protected void drawGuiContainerForegroundLayer(final int mouseX, final int mouseY) {
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND;
|
||||
|
||||
this.builder.drawProgressBar(this, this.tile.getProgressScaled(10), 100, 83, 48, mouseX, mouseY, TRBuilder.ProgressDirection.RIGHT, layer);
|
||||
this.builder.drawMultiEnergyBar(this, 130, 28, (int) this.tile.getEnergy(), (int) this.tile.getMaxPower(), mouseX, mouseY, 0, layer);
|
||||
this.builder.drawTank(this, 29, 25, mouseX, mouseY, this.tile.tank.getFluid(), this.tile.tank.getCapacity(), this.tile.tank.isEmpty(), layer);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
this.renderHoveredToolTip(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -245,7 +245,6 @@ public class TechRebornJeiPlugin extends BlankModPlugin {
|
|||
registry.addRecipeClickArea(GuiBlastFurnace.class, 150, 4, 20, 12, RecipeCategoryUids.BLAST_FURNACE);
|
||||
registry.addRecipeClickArea(GuiChemicalReactor.class, 150, 4, 20, 12, RecipeCategoryUids.CHEMICAL_REACTOR);
|
||||
registry.addRecipeClickArea(GuiIndustrialGrinder.class, 150, 4, 20, 12, RecipeCategoryUids.INDUSTRIAL_GRINDER);
|
||||
|
||||
registry.addRecipeClickArea(GuiIndustrialSawmill.class, 55, 35, 20, 15, RecipeCategoryUids.INDUSTRIAL_SAWMILL);
|
||||
|
||||
//OLD ONES
|
||||
|
@ -264,8 +263,7 @@ public class TechRebornJeiPlugin extends BlankModPlugin {
|
|||
|
||||
registry.addRecipeClickArea(GuiSemifluidGenerator.class, 79, 34, 18, 18,
|
||||
EFluidGenerator.SEMIFLUID.getRecipeID());
|
||||
registry.addRecipeClickArea(GuiDieselGenerator.class, 79, 34, 18, 18,
|
||||
EFluidGenerator.DIESEL.getRecipeID());
|
||||
registry.addRecipeClickArea(GuiDieselGenerator.class, 150, 4, 18, 18, EFluidGenerator.DIESEL.getRecipeID());
|
||||
registry.addRecipeClickArea(GuiGasTurbine.class, 79, 34, 18, 18,
|
||||
EFluidGenerator.GAS.getRecipeID());
|
||||
registry.addRecipeClickArea(GuiThermalGenerator.class, 79, 34, 18, 18,
|
||||
|
|
|
@ -76,7 +76,7 @@ public class FluidGeneratorRecipeWrapper extends BlankRecipeWrapper {
|
|||
|
||||
energyProduced.draw(minecraft, 73, 26);
|
||||
|
||||
minecraft.fontRenderer.drawString(formatter.format(baseRecipe.getEnergyPerMb() * 1000) + " FE", 70, 13,
|
||||
minecraft.fontRenderer.drawString(formatter.format(baseRecipe.getEnergyPerMb() * 1000) + " EU", 70, 13,
|
||||
0x444444);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,11 +47,12 @@ import techreborn.api.generator.GeneratorRecipeHelper;
|
|||
public abstract class TileBaseFluidGenerator extends TilePowerAcceptor implements IToolDrop, IInventoryProvider {
|
||||
|
||||
private final FluidGeneratorRecipeList recipes;
|
||||
|
||||
private final int euTick;
|
||||
|
||||
private FluidGeneratorRecipe currentRecipe;
|
||||
private int ticksSinceLastChange;
|
||||
public final Tank tank;
|
||||
public final Inventory inventory;
|
||||
protected long lastOutput = 0;
|
||||
|
||||
/*
|
||||
* We use this to keep track of fractional millibuckets, allowing us to hit
|
||||
|
@ -62,44 +63,40 @@ public abstract class TileBaseFluidGenerator extends TilePowerAcceptor implement
|
|||
|
||||
public TileBaseFluidGenerator(EFluidGenerator type, String tileName, int tankCapacity, int euTick) {
|
||||
super();
|
||||
|
||||
recipes = GeneratorRecipeHelper.getFluidRecipesForGenerator(type);
|
||||
|
||||
tank = new Tank(tileName, tankCapacity, this);
|
||||
inventory = new Inventory(3, tileName, 64, this);
|
||||
this.euTick = euTick;
|
||||
this.ticksSinceLastChange = 0;
|
||||
}
|
||||
|
||||
protected long lastOutput = 0;
|
||||
private FluidGeneratorRecipe currentRecipe;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
public void update(){
|
||||
this.ticksSinceLastChange++;
|
||||
super.update();
|
||||
|
||||
if (!this.world.isRemote) {
|
||||
if (this.acceptFluid() && FluidUtils.drainContainers(this.tank, this.inventory, 0, 1)
|
||||
|| FluidUtils.fillContainers(this.tank, this.inventory, 0, 1, this.tank.getFluidType()))
|
||||
this.syncWithAll();
|
||||
// Check cells input slot 2 time per second
|
||||
if (this.ticksSinceLastChange >= 10) {
|
||||
if (!this.inventory.getStackInSlot(0).isEmpty()) {
|
||||
FluidUtils.drainContainers(this.tank, this.inventory, 0, 1);
|
||||
FluidUtils.fillContainers(this.tank, this.inventory, 0, 1, this.tank.getFluidType());
|
||||
}
|
||||
this.ticksSinceLastChange = 0;
|
||||
}
|
||||
|
||||
|
||||
if (this.tank.getFluidAmount() > 0) {
|
||||
|
||||
if (this.currentRecipe == null || !this.currentRecipe.getFluid().equals(this.tank.getFluidType()))
|
||||
this.currentRecipe = this.getRecipes().getRecipeForFluid(this.tank.getFluidType()).orElse(null);
|
||||
|
||||
if (this.currentRecipe != null) {
|
||||
final Integer euPerBucket = this.currentRecipe.getEnergyPerMb() * 1000;
|
||||
final float millibucketsPerTick = this.euTick * 1000 / (float) euPerBucket;
|
||||
|
||||
if (this.tryAddingEnergy(this.euTick)) {
|
||||
final Integer euPerBucket = this.currentRecipe.getEnergyPerMb() * 1000;
|
||||
final float millibucketsPerTick = 16000f / (float) euPerBucket;
|
||||
this.pendingWithdraw += millibucketsPerTick;
|
||||
|
||||
final int currentWithdraw = (int) this.pendingWithdraw;
|
||||
|
||||
this.pendingWithdraw -= currentWithdraw;
|
||||
|
||||
this.tank.drain(currentWithdraw, true);
|
||||
|
||||
this.lastOutput = this.world.getTotalWorldTime();
|
||||
}
|
||||
}
|
||||
|
@ -107,12 +104,18 @@ public abstract class TileBaseFluidGenerator extends TilePowerAcceptor implement
|
|||
|
||||
if (!this.world.isRemote) {
|
||||
if (this.world.getTotalWorldTime() - this.lastOutput < 30 && !this.isActive())
|
||||
this.world.setBlockState(this.getPos(),
|
||||
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true));
|
||||
this.world.setBlockState(this.getPos(), this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true));
|
||||
else if (this.world.getTotalWorldTime() - this.lastOutput > 30 && this.isActive())
|
||||
this.world.setBlockState(this.getPos(),
|
||||
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false));
|
||||
this.world.setBlockState(this.getPos(), this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getProgressScaled(final int scale) {
|
||||
if (this.isActive()){
|
||||
return this.ticksSinceLastChange * scale;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected boolean tryAddingEnergy(int amount) {
|
||||
|
|
|
@ -68,8 +68,8 @@ public class TileDieselGenerator extends TileBaseFluidGenerator implements ICont
|
|||
|
||||
@Override
|
||||
public BuiltContainer createContainer(final EntityPlayer player) {
|
||||
return new ContainerBuilder("dieselgenerator").player(player.inventory).inventory(8, 84).hotbar(8, 142)
|
||||
.addInventory().tile(this).slot(0, 80, 17).outputSlot(1, 80, 53).fakeSlot(2, 59, 42).syncEnergyValue()
|
||||
return new ContainerBuilder("dieselgenerator").player(player.inventory).inventory().hotbar()
|
||||
.addInventory().tile(this).slot(0, 10, 35).outputSlot(1, 10, 55).syncEnergyValue()
|
||||
.addInventory().create();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue