Update rolling machine to use new gui system. Work towards #1412

This commit is contained in:
modmuss50 2018-03-29 11:52:57 +01:00
parent 6e1b608113
commit b5ad12a4bb
No known key found for this signature in database
GPG key ID: 773D17BE8BF49C82
4 changed files with 47 additions and 56 deletions

View file

@ -24,67 +24,40 @@
package techreborn.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import techreborn.tiles.TileRollingMachine;
public class GuiRollingMachine extends GuiContainer {
public class GuiRollingMachine extends GuiBase {
public static final ResourceLocation texture = new ResourceLocation("techreborn",
"textures/gui/rolling_machine.png");
TileRollingMachine rollingMachine;
public GuiRollingMachine(final EntityPlayer player, final TileRollingMachine tileRollingmachine) {
super(tileRollingmachine.createContainer(player));
this.xSize = 176;
this.ySize = 167;
super(player, tileRollingmachine, tileRollingmachine.createContainer(player));
this.rollingMachine = tileRollingmachine;
}
@Override
protected void drawGuiContainerBackgroundLayer(final float p_146976_1_, final int p_146976_2_, final int p_146976_3_) {
this.drawDefaultBackground();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(GuiRollingMachine.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;
int j = this.rollingMachine.getBurnTimeRemainingScaled(24);
this.drawTexturedModalRect(k + 91, l + 34, 176, 14, j + 1, 19);
int gridYPos = 22;
this.drawSlot(30, gridYPos, layer); this.drawSlot(48, gridYPos, layer); this.drawSlot(66, gridYPos, layer);
this.drawSlot(30, gridYPos + 18, layer); this.drawSlot(48, gridYPos + 18, layer); this.drawSlot(66, gridYPos + 18, layer);
this.drawSlot(30, gridYPos + 36, layer); this.drawSlot(48, gridYPos + 36, layer); this.drawSlot(66, gridYPos + 36, layer);
j = this.rollingMachine.getEnergyScaled(12);
if (j > 0) {
this.drawTexturedModalRect(k + 7, l + 33 + 12 - j, 176, 12 - j, 14, j + 2);
}
this.drawSlot(8, 70, layer);
this.drawOutputSlot(124, gridYPos + 18, 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.format("tile.techreborn:rolling_machine.name");
this.fontRenderer.drawString(name, this.xSize / 2 - this.fontRenderer.getStringWidth(name) / 2, 6,
4210752);
this.fontRenderer.drawString(I18n.format("container.inventory", new Object[0]), 8,
this.ySize - 96 + 2, 4210752);
}
protected void drawGuiContainerForegroundLayer(final int mouseX, final int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND;
@Override
public void initGui() {
this.buttonList.clear();
final int k = (this.width - this.xSize) / 2;
final int l = (this.height - this.ySize) / 2;
this.buttonList.add(new GuiButton(0, k + 4, l + 4, 20, 20, "R"));
super.initGui();
this.builder.drawProgressBar(this, this.rollingMachine.getProgressScaled(100), 100, 92, 43, mouseX, mouseY, TRBuilder.ProgressDirection.RIGHT, layer);
this.builder.drawMultiEnergyBar(this, 9, 17, (int) this.rollingMachine.getEnergy(), (int) this.rollingMachine.getMaxPower(), mouseX, mouseY, 0, layer);
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
}
}

View file

@ -316,12 +316,12 @@ public class TechRebornJeiPlugin implements IModPlugin {
addRecipeClickArea(GuiDistillationTower.class, 150, 4, 18, 18, RecipeCategoryUids.DISTILLATION_TOWER);
addRecipeClickArea(GuiScrapboxinator.class, 150, 4, 18, 18, RecipeCategoryUids.SCRAPBOX);
addRecipeClickArea(GuiFusionReactor.class, 150, 4, 18, 18, RecipeCategoryUids.FUSION_REACTOR);
addRecipeClickArea(GuiRollingMachine.class, 150, 4, 20, 12, RecipeCategoryUids.ROLLING_MACHINE);
//OLD ONES
addRecipeClickArea(GuiAlloyFurnace.class, 80, 35, 26, 20, RecipeCategoryUids.ALLOY_SMELTER,
VanillaRecipeCategoryUid.FUEL);
addRecipeClickArea(GuiAssemblingMachine.class, 85, 34, 24, 20, RecipeCategoryUids.ASSEMBLING_MACHINE);
addRecipeClickArea(GuiRollingMachine.class, 89, 32, 26, 25, RecipeCategoryUids.ROLLING_MACHINE);
addRecipeClickArea(GuiIronFurnace.class, 78, 36, 24, 16, VanillaRecipeCategoryUid.SMELTING,
VanillaRecipeCategoryUid.FUEL);

View file

@ -30,8 +30,8 @@ import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.IRecipeCategory;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n;
import techreborn.client.gui.GuiRollingMachine;
import techreborn.compat.jei.RecipeCategoryUids;
import techreborn.lib.ModInfo;
@ -47,11 +47,13 @@ public class RollingMachineRecipeCategory implements IRecipeCategory<RollingMach
private final ICraftingGridHelper craftingGridHelper;
private final String title;
public static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/rolling_machine.png");
public RollingMachineRecipeCategory(IGuiHelper guiHelper) {
background = guiHelper.createDrawable(GuiRollingMachine.texture, 29, 16, 116, 54);
background = guiHelper.createDrawable(texture, 29, 16, 116, 54);
title = I18n.translateToLocal("tile.techreborn:rolling_machine.name");
IDrawableStatic progressStatic = guiHelper.createDrawable(GuiRollingMachine.texture, 176, 14, 20, 18);
IDrawableStatic progressStatic = guiHelper.createDrawable(texture, 176, 14, 20, 18);
progress = guiHelper.createAnimatedDrawable(progressStatic, 250, IDrawableAnimated.StartDirection.LEFT, false);
craftingGridHelper = guiHelper.createCraftingGridHelper(INPUT_SLOTS[0], OUTPUT_SLOTS[0]);

View file

@ -224,13 +224,24 @@ public class TileRollingMachine extends TilePowerAcceptor
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("rollingmachine").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this.craftMatrix).slot(0, 30, 17).slot(1, 48, 17).slot(2, 66, 17).slot(3, 30, 35)
.slot(4, 48, 35).slot(5, 66, 35).slot(6, 30, 53).slot(7, 48, 53).slot(8, 66, 53)
.onCraft(inv -> this.inventory.setInventorySlotContents(1,
RollingMachineRecipe.instance.findMatchingRecipe(inv, this.world)))
.addInventory().tile(this).outputSlot(0, 124, 35).energySlot(2, 8, 51).syncEnergyValue()
.syncIntegerValue(this::getBurnTime, this::setBurnTime).addInventory().create(this);
return new ContainerBuilder("rollingmachine").player(player.inventory)
.inventory().hotbar()
.addInventory().tile(this.craftMatrix)
.slot(0, 30, 22).slot(1, 48, 22).slot(2, 66, 22)
.slot(3, 30, 40).slot(4, 48, 40).slot(5, 66, 40)
.slot(6, 30, 58).slot(7, 48, 58).slot(8, 66, 58)
.onCraft(inv -> this.inventory.setInventorySlotContents(1, RollingMachineRecipe.instance.findMatchingRecipe(inv, this.world)))
.addInventory().tile(this)
.outputSlot(0, 124, 40)
.energySlot(2, 8, 70)
.syncEnergyValue().syncIntegerValue(this::getBurnTime, this::setBurnTime).addInventory().create(this);
}
public int getProgressScaled(final int scale) {
if (tickTime != 0 && runTime != 0) {
return tickTime * scale / runTime;
}
return 0;
}
private static class RollingTileContainer extends Container {
@ -241,4 +252,9 @@ public class TileRollingMachine extends TilePowerAcceptor
}
}
@Override
public boolean canBeUpgraded() {
return false;
}
}