Convert BlastFurnace

This commit is contained in:
Ourten 2017-01-08 15:45:05 +01:00
parent 665b5f7569
commit ea98e4a8a0
4 changed files with 147 additions and 200 deletions

View file

@ -106,7 +106,12 @@ public class GuiHandler implements IGuiHandler {
((TileRollingMachine) world.getTileEntity(new BlockPos(x, y, z)))::setBurnTime)
.addInventory().create();
} else if (ID == GuiHandler.blastFurnaceID) {
return new ContainerBlastFurnace((TileBlastFurnace) world.getTileEntity(new BlockPos(x, y, z)), player);
return new ContainerBuilder("blastfurnace").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile((IInventory) world.getTileEntity(new BlockPos(x, y, z))).slot(0, 40, 25)
.slot(1, 40, 43).outputSlot(2, 100, 35).outputSlot(3, 118, 35).syncEnergyValue().syncCrafterValue()
.syncIntegerValue(((TileBlastFurnace) world.getTileEntity(new BlockPos(x, y, z)))::getHeat,
((TileBlastFurnace) world.getTileEntity(new BlockPos(x, y, z)))::setHeat)
.addInventory().create();
} else if (ID == GuiHandler.alloySmelterID) {
return new ContainerBuilder("alloysmelter").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile((IInventory) world.getTileEntity(new BlockPos(x, y, z)))

View file

@ -1,74 +0,0 @@
package techreborn.client.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IContainerListener;
import reborncore.client.gui.slots.BaseSlot;
import reborncore.client.gui.slots.SlotOutput;
import techreborn.tiles.multiblock.TileBlastFurnace;
public class ContainerBlastFurnace extends ContainerCrafting {
public int heat;
public int tickTime;
EntityPlayer player;
TileBlastFurnace tile;
public ContainerBlastFurnace(TileBlastFurnace tileblastfurnace, EntityPlayer player) {
super(tileblastfurnace.crafter);
tile = tileblastfurnace;
this.player = player;
// input
this.addSlotToContainer(new BaseSlot(tileblastfurnace.inventory, 0, 40, 25));// Input
// 1
this.addSlotToContainer(new BaseSlot(tileblastfurnace.inventory, 1, 40, 43));// Input
// 2
// outputs
this.addSlotToContainer(new SlotOutput(tileblastfurnace.inventory, 2, 100, 35));// Output
// 1
this.addSlotToContainer(new SlotOutput(tileblastfurnace.inventory, 3, 118, 35));// Output
// 2
int i;
for (i = 0; i < 3; ++i) {
for (int j = 0; j < 9; ++j) {
this.addSlotToContainer(new BaseSlot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (i = 0; i < 9; ++i) {
this.addSlotToContainer(new BaseSlot(player.inventory, i, 8 + i * 18, 142));
}
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return true;
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (int i = 0; i < this.listeners.size(); i++) {
IContainerListener IContainerListener = this.listeners.get(i);
if (this.heat != tile.getHeat()) {
IContainerListener.sendProgressBarUpdate(this, 10, tile.getHeat());
}
}
}
@Override
public void addListener(IContainerListener crafting) {
super.addListener(crafting);
crafting.sendProgressBarUpdate(this, 10, tile.getHeat());
}
@Override
public void updateProgressBar(int id, int value) {
if (id == 10) {
this.heat = value;
}
super.updateProgressBar(id, value);
}
}

View file

@ -9,13 +9,15 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.translation.I18n;
import reborncore.client.gui.GuiUtil;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.multiblock.MultiblockRenderEvent;
import reborncore.client.multiblock.MultiblockSet;
import reborncore.common.misc.Location;
import reborncore.common.multiblock.CoordTriplet;
import techreborn.client.container.ContainerBlastFurnace;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import techreborn.proxies.ClientProxy;
import techreborn.tiles.multiblock.TileBlastFurnace;
@ -25,35 +27,36 @@ import java.io.IOException;
public class GuiBlastFurnace extends GuiContainer {
public static final ResourceLocation texture = new ResourceLocation("techreborn",
"textures/gui/industrial_blast_furnace.png");
"textures/gui/industrial_blast_furnace.png");
TileBlastFurnace blastfurnace;
ContainerBlastFurnace containerBlastFurnace;
boolean hasMultiBlock;
public GuiBlastFurnace(EntityPlayer player, TileBlastFurnace tileblastfurnace) {
super(new ContainerBlastFurnace(tileblastfurnace, player));
public GuiBlastFurnace(final EntityPlayer player, final TileBlastFurnace tileblastfurnace) {
super(new ContainerBuilder("blastfurnace").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(tileblastfurnace).slot(0, 40, 25).slot(1, 40, 43).outputSlot(2, 100, 35)
.outputSlot(3, 118, 35).syncEnergyValue().syncCrafterValue()
.syncIntegerValue(tileblastfurnace::getHeat, tileblastfurnace::setHeat).addInventory().create());
this.xSize = 176;
this.ySize = 167;
blastfurnace = tileblastfurnace;
this.containerBlastFurnace = (ContainerBlastFurnace) this.inventorySlots;
this.blastfurnace = tileblastfurnace;
}
@Override
public void initGui() {
hasMultiBlock = containerBlastFurnace.heat != 0;
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
GuiButton button = new GuiButton(212, k + 4, l + 6, 20, 20, "");
buttonList.add(button);
this.hasMultiBlock = this.blastfurnace.getCachedHeat() != 0;
final int k = (this.width - this.xSize) / 2;
final int l = (this.height - this.ySize) / 2;
final GuiButton button = new GuiButton(212, k + 4, l + 6, 20, 20, "");
this.buttonList.add(button);
super.initGui();
CoordTriplet coordinates = new CoordTriplet(
blastfurnace.getPos().getX() - (EnumFacing.getFront(blastfurnace.getFacingInt()).getFrontOffsetX() * 2),
blastfurnace.getPos().getY() - 1, blastfurnace.getPos().getZ()
- (EnumFacing.getFront(blastfurnace.getFacingInt()).getFrontOffsetZ() * 2));
if (coordinates.equals(ClientProxy.multiblockRenderEvent.anchor) && blastfurnace.getHeat() != 0) {
final CoordTriplet coordinates = new CoordTriplet(
this.blastfurnace.getPos().getX() - EnumFacing.getFront(this.blastfurnace.getFacingInt()).getFrontOffsetX() * 2,
this.blastfurnace.getPos().getY() - 1, this.blastfurnace.getPos().getZ()
- EnumFacing.getFront(this.blastfurnace.getFacingInt()).getFrontOffsetZ() * 2);
if (coordinates.equals(MultiblockRenderEvent.anchor) && this.blastfurnace.getHeat() != 0) {
ClientProxy.multiblockRenderEvent.setMultiblock(null);
button.displayString = "B";
} else {
@ -62,100 +65,101 @@ public class GuiBlastFurnace extends GuiContainer {
}
@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
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(texture);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.mc.getTextureManager().bindTexture(GuiBlastFurnace.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);
if (containerBlastFurnace.heat == 0) {
if (this.blastfurnace.getCachedHeat() == 0) {
GuiUtil.drawTooltipBox(k + 30, l + 50 + 12 - 0, 114, 10);
this.fontRendererObj.drawString(I18n.translateToLocal("techreborn.message.missingmultiblock"), k + 38,
l + 52 + 12 - 0, -1);
l + 52 + 12 - 0, -1);
}
int j = 0;
this.mc.getTextureManager().bindTexture(texture);
j = blastfurnace.getProgressScaled(24);
this.mc.getTextureManager().bindTexture(GuiBlastFurnace.texture);
j = this.blastfurnace.getProgressScaled(24);
if (j > 0) {
this.drawTexturedModalRect(k + 64, l + 37, 176, 14, j + 1, 16);
}
j = blastfurnace.getEnergyScaled(12);
j = this.blastfurnace.getEnergyScaled(12);
if (j > 0) {
this.drawTexturedModalRect(k + 9, l + 36 + 12 - j, 176, 12 - j, 14, j + 2);
}
}
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
@Override
protected void drawGuiContainerForegroundLayer(final int p_146979_1_, final int p_146979_2_) {
super.drawGuiContainerForegroundLayer(p_146979_1_, p_146979_2_);
String name = I18n.translateToLocal("tile.techreborn.blastfurnace.name");
final String name = I18n.translateToLocal("tile.techreborn.blastfurnace.name");
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6,
4210752);
if (containerBlastFurnace.heat != 0) {
this.fontRendererObj.drawString("Current Heat: " + containerBlastFurnace.heat, 40, 60, 4210752);
4210752);
if (this.blastfurnace.getCachedHeat() != 0) {
this.fontRendererObj.drawString("Current Heat: " + this.blastfurnace.getCachedHeat(), 40, 60, 4210752);
}
this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8,
this.ySize - 96 + 2, 4210752);
this.ySize - 96 + 2, 4210752);
}
@Override
public void actionPerformed(GuiButton button) throws IOException {
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.
Multiblock multiblock = new Multiblock();
addComponent(0, 0, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(1, 0, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(0, 0, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(-1, 0, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(0, 0, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(-1, 0, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(-1, 0, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(1, 0, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(1, 0, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
final Multiblock multiblock = new Multiblock();
this.addComponent(0, 0, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(1, 0, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(0, 0, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(-1, 0, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(0, 0, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(-1, 0, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(-1, 0, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(1, 0, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(1, 0, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(1, 1, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(0, 1, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(-1, 1, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(0, 1, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(-1, 1, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(-1, 1, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(1, 1, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(1, 1, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(1, 1, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(0, 1, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(-1, 1, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(0, 1, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(-1, 1, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(-1, 1, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(1, 1, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(1, 1, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(1, 2, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(0, 2, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(-1, 2, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(0, 2, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(-1, 2, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(-1, 2, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(1, 2, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(1, 2, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(1, 2, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(0, 2, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(-1, 2, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(0, 2, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(-1, 2, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(-1, 2, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(1, 2, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(1, 2, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(0, 3, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(1, 3, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(0, 3, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(-1, 3, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(0, 3, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(-1, 3, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(-1, 3, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(1, 3, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
addComponent(1, 3, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(0, 3, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(1, 3, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(0, 3, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(-1, 3, 0, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(0, 3, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(-1, 3, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(-1, 3, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(1, 3, -1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
this.addComponent(1, 3, 1, ModBlocks.MACHINE_CASINGS.getDefaultState(), multiblock);
MultiblockSet set = new MultiblockSet(multiblock);
final MultiblockSet set = new MultiblockSet(multiblock);
ClientProxy.multiblockRenderEvent.setMultiblock(set);
ClientProxy.multiblockRenderEvent.parent = new Location(blastfurnace.getPos().getX(),
blastfurnace.getPos().getY(), blastfurnace.getPos().getZ(), blastfurnace.getWorld());
ClientProxy.multiblockRenderEvent.parent = new Location(this.blastfurnace.getPos().getX(),
this.blastfurnace.getPos().getY(), this.blastfurnace.getPos().getZ(), this.blastfurnace.getWorld());
MultiblockRenderEvent.anchor = new BlockPos(
blastfurnace.getPos().getX()
- (EnumFacing.getFront(blastfurnace.getFacingInt()).getFrontOffsetX() * 2),
blastfurnace.getPos().getY() - 1, blastfurnace.getPos().getZ()
- (EnumFacing.getFront(blastfurnace.getFacingInt()).getFrontOffsetZ() * 2));
this.blastfurnace.getPos().getX()
- EnumFacing.getFront(this.blastfurnace.getFacingInt()).getFrontOffsetX() * 2,
this.blastfurnace.getPos().getY() - 1, this.blastfurnace.getPos().getZ()
- EnumFacing.getFront(this.blastfurnace.getFacingInt()).getFrontOffsetZ() * 2);
}
button.displayString = "A";
} else {
@ -165,7 +169,7 @@ public class GuiBlastFurnace extends GuiContainer {
}
}
public void addComponent(int x, int y, int z, IBlockState blockState, Multiblock multiblock) {
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);
}