update Implosion Compressor to GuiBase

This commit is contained in:
alexpic57 2017-09-07 23:59:46 +02:00
parent aa2df32222
commit e4b5d3378a
4 changed files with 116 additions and 59 deletions

View file

@ -24,69 +24,119 @@
package techreborn.client.gui;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.translation.I18n;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.multiblock.MultiblockRenderEvent;
import reborncore.client.multiblock.MultiblockSet;
import reborncore.common.misc.Location;
import techreborn.Core;
import techreborn.client.gui.widget.GuiButtonHologram;
import techreborn.init.ModBlocks;
import techreborn.proxies.ClientProxy;
import techreborn.tiles.multiblock.TileImplosionCompressor;
public class GuiImplosionCompressor extends GuiContainer {
import java.io.IOException;
public static final ResourceLocation texture = new ResourceLocation("techreborn",
"textures/gui/implosion_compressor.png");
public class GuiImplosionCompressor extends GuiBase {
TileImplosionCompressor compressor;
TileImplosionCompressor tile;
public GuiImplosionCompressor(final EntityPlayer player, final TileImplosionCompressor compressor) {
super(compressor.createContainer(player));
this.xSize = 176;
this.ySize = 167;
this.compressor = compressor;
public GuiImplosionCompressor(final EntityPlayer player, final TileImplosionCompressor tile) {
super(player, tile, tile.createContainer(player));
this.tile = tile;
}
@Override
public void initGui() {
super.initGui();
ClientProxy.multiblockRenderEvent.setMultiblock(null);
}
@Override
protected void drawGuiContainerBackgroundLayer(final float p_146976_1_, final int p_146976_2_, final int p_146976_3_) {
this.drawDefaultBackground();
protected void drawGuiContainerBackgroundLayer(final float f, final int mouseX, final int mouseY) {
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(GuiImplosionCompressor.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);
final GuiBase.Layer layer = Layer.BACKGROUND;
if (!this.compressor.getMutliBlock()) {
// GuiDraw.drawTooltipBox(k + 30, l + 50 + 12 - 0, 114, 10);
this.fontRenderer.drawString(I18n.format("techreborn.message.missingmultiblock"), k + 38, l + 52 + 12, -1);
}
drawSlot(50, 27, layer);
drawSlot(50,47,layer);
drawSlot(92,36,layer);
drawSlot(110,36,layer);
this.mc.getTextureManager().bindTexture(GuiImplosionCompressor.texture);
int j = this.compressor.getProgressScaled(24);
if (j > 0) {
this.drawTexturedModalRect(k + 61, l + 37, 176, 14, j + 1, 16);
}
if(tile.getMutliBlock()) {
builder.drawHologramButton(this, 6, 4, mouseX, mouseY, layer);
}
j = this.compressor.getEnergyScaled(12);
if (j > 0) {
this.drawTexturedModalRect(k + 14, l + 36 + 12 - j, 176, 12 - j, 14, j + 2);
}
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:implosion_compressor.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 = Layer.FOREGROUND;
this.builder.drawProgressBar(this, this.tile.getProgressScaled(100), 100, 71, 40, mouseX, mouseY, TRBuilder.ProgressDirection.RIGHT, layer);
this.builder.drawMultiEnergyBar(this, 9, 19, (int) this.tile.getEnergy(), (int) this.tile.getMaxPower(), mouseX, mouseY, 0, layer);
if(tile.getMutliBlock()){
addHologramButton(6, 4, 212, layer);
} else {
builder.drawMultiblockMissingBar(this, layer);
addHologramButton(76, 56, 212, layer);
builder.drawHologramButton(this, 76, 56, mouseX, mouseY, layer);
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
}
public void addHologramButton(int x, int y, int id, Layer layer) {
if (id == 0)
buttonList.clear();
int factorX = 0;
int factorY = 0;
if (layer == Layer.BACKGROUND) {
factorX = guiLeft;
factorY = guiTop;
}
buttonList.add(new GuiButtonHologram(id, x + factorX, y + factorY, this, layer));
}
@Override
public void actionPerformed(final GuiButton button) throws IOException {
super.actionPerformed(button);
if (button.id == 212) {
if (ClientProxy.multiblockRenderEvent.currentMultiblock == null) {
{
// This code here makes a basic multiblock and then sets to the selected one.
final Multiblock multiblock = new Multiblock();
for(int x = -1; x <= 1; x++) {
for(int y = -4; y <= -2; y++) {
for(int z = -1; z <= 1; z++) {
if(!((x == 0) && (y == -3) && (z == 0))) {
this.addComponent(x, y, z, ModBlocks.MACHINE_CASINGS.getStateFromMeta(1), multiblock);
}
}
}
}
final MultiblockSet set = new MultiblockSet(multiblock);
ClientProxy.multiblockRenderEvent.setMultiblock(set);
ClientProxy.multiblockRenderEvent.parent = new Location(this.tile.getPos().getX(), this.tile.getPos().getY(), this.tile.getPos().getZ(), this.tile.getWorld());
MultiblockRenderEvent.anchor = new BlockPos(this.tile.getPos().getX(), this.tile.getPos().getY(), this.tile.getPos().getZ());
}
} else {
ClientProxy.multiblockRenderEvent.setMultiblock(null);
}
}
}
public void addComponent(final int x, final int y, final int z, final IBlockState blockState, final Multiblock multiblock) {
multiblock.addComponent(new BlockPos(x, y, z), blockState);
}
}

View file

@ -29,6 +29,8 @@ import mezz.jei.api.gui.*;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.BlankRecipeCategory;
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.GuiImplosionCompressor;
import techreborn.compat.jei.RecipeCategoryUids;
@ -38,18 +40,15 @@ import techreborn.lib.ModInfo;
import javax.annotation.Nonnull;
public class ImplosionCompressorRecipeCategory extends BlankRecipeCategory<ImplosionCompressorRecipeWrapper> {
public static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/jei.png");
private static final int[] INPUT_SLOTS = { 0, 1 };
private static final int[] OUTPUT_SLOTS = { 2, 3 };
private final IDrawable background;
private final IDrawable electricity;
private final String title;
public ImplosionCompressorRecipeCategory(IGuiHelper guiHelper) {
background = guiHelper.createDrawable(GuiImplosionCompressor.texture, 16, 25, 116, 36);
IDrawableStatic electricityDrawable = guiHelper.createDrawable(GuiImplosionCompressor.texture, 176, 0, 14, 14);
electricity = guiHelper.createAnimatedDrawable(electricityDrawable, 300, IDrawableAnimated.StartDirection.TOP,
true);
background = guiHelper.createDrawable(texture, 0, 95, 120, 42);
title = I18n.translateToLocal("tile.techreborn:implosion_compressor.name");
}
@ -76,12 +75,6 @@ public class ImplosionCompressorRecipeCategory extends BlankRecipeCategory<Implo
return background;
}
@Override
public void drawExtras(Minecraft minecraft) {
super.drawExtras(minecraft);
electricity.draw(minecraft, 0, 12);
}
@Override
public void setRecipe(
@Nonnull
@ -91,11 +84,11 @@ public class ImplosionCompressorRecipeCategory extends BlankRecipeCategory<Implo
@Nonnull
IIngredients ingredients) {
IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks();
guiItemStacks.init(INPUT_SLOTS[0], true, 20, 0);
guiItemStacks.init(INPUT_SLOTS[1], true, 20, 18);
guiItemStacks.init(INPUT_SLOTS[0], true, 21, 2);
guiItemStacks.init(INPUT_SLOTS[1], true, 21, 22);
guiItemStacks.init(OUTPUT_SLOTS[0], false, 76, 9);
guiItemStacks.init(OUTPUT_SLOTS[1], false, 94, 9);
guiItemStacks.init(OUTPUT_SLOTS[0], false, 63, 11);
guiItemStacks.init(OUTPUT_SLOTS[1], false, 81, 11);
RecipeUtil.setRecipeItems(recipeLayout, ingredients, INPUT_SLOTS, OUTPUT_SLOTS, null, null);
}

View file

@ -31,6 +31,7 @@ import mezz.jei.api.gui.IDrawableStatic;
import net.minecraft.client.Minecraft;
import techreborn.api.recipe.machines.ImplosionCompressorRecipe;
import techreborn.client.gui.GuiImplosionCompressor;
import techreborn.client.gui.TRBuilder;
import techreborn.compat.jei.BaseRecipeWrapper;
import javax.annotation.Nonnull;
@ -45,7 +46,7 @@ public class ImplosionCompressorRecipeWrapper extends BaseRecipeWrapper<Implosio
ImplosionCompressorRecipe baseRecipe) {
super(baseRecipe);
IGuiHelper guiHelper = jeiHelpers.getGuiHelper();
IDrawableStatic progressStatic = guiHelper.createDrawable(GuiImplosionCompressor.texture, 176, 14, 21, 11);
IDrawableStatic progressStatic = guiHelper.createDrawable(TRBuilder.GUI_SHEET, 100, 151, 16, 10);
this.progress = guiHelper.createAnimatedDrawable(progressStatic, baseRecipe.tickTime(),
IDrawableAnimated.StartDirection.LEFT, false);
}
@ -53,10 +54,10 @@ public class ImplosionCompressorRecipeWrapper extends BaseRecipeWrapper<Implosio
@Override
public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) {
super.drawInfo(minecraft, recipeWidth, recipeHeight, mouseX, mouseY);
progress.draw(minecraft, 44, 13);
progress.draw(minecraft, 43, 16);
int x = -45;
int y = 4;
int x = -35;
int y = 13;
int lineHeight = minecraft.fontRenderer.FONT_HEIGHT;
minecraft.fontRenderer.drawString("Time: " + baseRecipe.tickTime / 20 + " s", x, y, 0x444444);

View file

@ -25,6 +25,8 @@
package techreborn.tiles.multiblock;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
@ -40,10 +42,12 @@ import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import techreborn.tiles.TileRollingMachine;
public class TileImplosionCompressor extends TilePowerAcceptor
implements IToolDrop, IInventoryProvider, IRecipeCrafterProvider, IContainerProvider {
public final InventoryCrafting craftMatrix = new InventoryCrafting(new ImplosionCompressorTileContainer(), 3, 3);
public Inventory inventory = new Inventory(4, "TileImplosionCompressor", 64, this);
public MultiblockChecker multiblockChecker;
public RecipeCrafter crafter;
@ -153,9 +157,18 @@ public class TileImplosionCompressor extends TilePowerAcceptor
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("implosioncompressor").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).slot(0, 37, 26).slot(1, 37, 44).outputSlot(2, 93, 35).outputSlot(3, 111, 35)
return new ContainerBuilder("implosioncompressor").player(player.inventory).inventory().hotbar()
.addInventory().tile(this).slot(0, 50, 27).slot(1, 50, 47).outputSlot(2, 92, 36).outputSlot(3, 110, 36)
.syncEnergyValue().syncCrafterValue().addInventory().create();
}
private static class ImplosionCompressorTileContainer extends Container {
@Override
public boolean canInteractWith(final EntityPlayer entityplayer) {
return true;
}
}
}