Convert ElectricFurnace

This commit is contained in:
Ourten 2017-01-07 22:11:54 +01:00
parent af524f169f
commit 1df2c84e16
5 changed files with 92 additions and 127 deletions

View file

@ -149,8 +149,13 @@ public class GuiHandler implements IGuiHandler {
} else if (ID == GuiHandler.compressorID) { } else if (ID == GuiHandler.compressorID) {
return new ContainerCompressor((TileCompressor) world.getTileEntity(new BlockPos(x, y, z)), player); return new ContainerCompressor((TileCompressor) world.getTileEntity(new BlockPos(x, y, z)), player);
} else if (ID == GuiHandler.electricFurnaceID) { } else if (ID == GuiHandler.electricFurnaceID) {
return new ContainerElectricFurnace((TileElectricFurnace) world.getTileEntity(new BlockPos(x, y, z)), return new ContainerBuilder().player(player.inventory).inventory(8, 84).hotbar(8, 142).addInventory()
player); .tile((IInventory) world.getTileEntity(new BlockPos(x, y, z))).slot(0, 56, 34)
.outputSlot(1, 116, 34).upgradeSlot(2, 152, 8).upgradeSlot(3, 152, 26).upgradeSlot(4, 152, 44)
.upgradeSlot(5, 152, 62).syncEnergyValue()
.syncIntegerValue(((TileElectricFurnace) world.getTileEntity(new BlockPos(x, y, z)))::getBurnTime,
((TileElectricFurnace) world.getTileEntity(new BlockPos(x, y, z)))::setBurnTime)
.addInventory().create();
} else if (ID == GuiHandler.ironFurnace) { } else if (ID == GuiHandler.ironFurnace) {
return new ContainerBuilder().player(player.inventory).inventory(8, 84).hotbar(8, 142).addInventory() return new ContainerBuilder().player(player.inventory).inventory(8, 84).hotbar(8, 142).addInventory()
.tile((IInventory) world.getTileEntity(new BlockPos(x, y, z))).slot(0, 56, 17) .tile((IInventory) world.getTileEntity(new BlockPos(x, y, z))).slot(0, 56, 17)

View file

@ -1,59 +0,0 @@
package techreborn.client.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.client.gui.slots.BaseSlot;
import reborncore.client.gui.slots.SlotOutput;
import reborncore.common.container.RebornContainer;
import techreborn.api.gui.SlotUpgrade;
import techreborn.tiles.teir1.TileElectricFurnace;
public class ContainerElectricFurnace extends RebornContainer {
public int connectionStatus;
EntityPlayer player;
TileElectricFurnace tile;
public ContainerElectricFurnace(TileElectricFurnace tileGrinder, EntityPlayer player) {
super();
tile = tileGrinder;
this.player = player;
// input
this.addSlotToContainer(new BaseSlot(tileGrinder.inventory, 0, 56, 34));
this.addSlotToContainer(new SlotOutput(tileGrinder.inventory, 1, 116, 34));
// upgrades
this.addSlotToContainer(new SlotUpgrade(tileGrinder.inventory, 2, 152, 8));
this.addSlotToContainer(new SlotUpgrade(tileGrinder.inventory, 3, 152, 26));
this.addSlotToContainer(new SlotUpgrade(tileGrinder.inventory, 4, 152, 44));
this.addSlotToContainer(new SlotUpgrade(tileGrinder.inventory, 5, 152, 62));
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 p_75145_1_) {
return true;
}
@SideOnly(Side.CLIENT)
@Override
public void updateProgressBar(int id, int value) {
if (id == 10) {
this.connectionStatus = value;
}
}
}

View file

@ -17,6 +17,7 @@ import reborncore.common.powerSystem.TilePowerAcceptor;
import techreborn.Core; import techreborn.Core;
import techreborn.client.container.builder.slot.FilteredSlot; import techreborn.client.container.builder.slot.FilteredSlot;
import techreborn.utils.upgrade.IMachineUpgrade;
import java.util.function.IntConsumer; import java.util.function.IntConsumer;
import java.util.function.IntSupplier; import java.util.function.IntSupplier;
@ -69,6 +70,12 @@ public class ContainerTileInventoryBuilder {
return this; return this;
} }
public ContainerTileInventoryBuilder upgradeSlot(final int index, final int x, final int y) {
this.parent.slots.add(new FilteredSlot(this.tile, index, x, y)
.setFilter(stack -> stack.getItem() instanceof IMachineUpgrade));
return this;
}
/** /**
* *
* @param supplier * @param supplier

View file

@ -5,7 +5,8 @@ import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n; import net.minecraft.util.text.translation.I18n;
import techreborn.client.container.ContainerElectricFurnace;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.tiles.teir1.TileElectricFurnace; import techreborn.tiles.teir1.TileElectricFurnace;
public class GuiElectricFurnace extends GuiContainer { public class GuiElectricFurnace extends GuiContainer {
@ -13,43 +14,44 @@ public class GuiElectricFurnace extends GuiContainer {
public static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/compressor.png"); public static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/compressor.png");
TileElectricFurnace furnace; TileElectricFurnace furnace;
ContainerElectricFurnace containerGrinder;
public GuiElectricFurnace(EntityPlayer player, TileElectricFurnace tilegrinder) { public GuiElectricFurnace(final EntityPlayer player, final TileElectricFurnace furnace) {
super(new ContainerElectricFurnace(tilegrinder, player)); super(new ContainerBuilder().player(player.inventory).inventory(8, 84).hotbar(8, 142).addInventory()
.tile(furnace).slot(0, 56, 34).outputSlot(1, 116, 34).upgradeSlot(2, 152, 8).upgradeSlot(3, 152, 26)
.upgradeSlot(4, 152, 44).upgradeSlot(5, 152, 62).syncEnergyValue()
.syncIntegerValue(furnace::getBurnTime, furnace::setBurnTime).addInventory().create());
this.xSize = 176; this.xSize = 176;
this.ySize = 167; this.ySize = 167;
furnace = tilegrinder; this.furnace = furnace;
containerGrinder = (ContainerElectricFurnace) this.inventorySlots;
} }
@Override @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); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(texture); this.mc.getTextureManager().bindTexture(GuiElectricFurnace.texture);
int k = (this.width - this.xSize) / 2; final int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2; final int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
int j = 0; int j = 0;
j = furnace.gaugeProgressScaled(24); j = this.furnace.gaugeProgressScaled(24);
if (j > 0) { if (j > 0) {
this.drawTexturedModalRect(k + 78, l + 34, 176, 14, j + 1, 16); this.drawTexturedModalRect(k + 78, l + 34, 176, 14, j + 1, 16);
} }
j = furnace.getEnergyScaled(12); j = this.furnace.getEnergyScaled(12);
if (j > 0) { if (j > 0) {
this.drawTexturedModalRect(k + 24, l + 36 + 12 - j, 176, 12 - j, 14, j + 2); this.drawTexturedModalRect(k + 24, l + 36 + 12 - j, 176, 12 - j, 14, j + 2);
} }
} }
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) { @Override
String name = I18n.translateToLocal("tile.techreborn.electricfurnace.name"); protected void drawGuiContainerForegroundLayer(final int p_146979_1_, final int p_146979_2_) {
final String name = I18n.translateToLocal("tile.techreborn.electricfurnace.name");
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6,
4210752); 4210752);
this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8, this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8,
this.ySize - 96 + 2, 4210752); this.ySize - 96 + 2, 4210752);
} }
} }

View file

@ -6,12 +6,14 @@ import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import reborncore.api.power.EnumPowerTier; import reborncore.api.power.EnumPowerTier;
import reborncore.api.tile.IInventoryProvider; import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable; import reborncore.common.IWrenchable;
import reborncore.common.blocks.BlockMachineBase; import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory; import reborncore.common.util.Inventory;
import techreborn.init.ModBlocks; import techreborn.init.ModBlocks;
public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, ISidedInventory { public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, ISidedInventory {
@ -31,78 +33,78 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl
super(1); super(1);
} }
public int gaugeProgressScaled(int scale) { public int gaugeProgressScaled(final int scale) {
return (progress * scale) / fuelScale; return this.progress * scale / this.fuelScale;
} }
@Override @Override
public void update() { public void update() {
super.update(); super.update();
boolean burning = isBurning(); final boolean burning = this.isBurning();
boolean updateInventory = false; boolean updateInventory = false;
if (isBurning() && canSmelt()) { if (this.isBurning() && this.canSmelt()) {
updateState(); this.updateState();
progress++; this.progress++;
if (progress % 10 == 0) { if (this.progress % 10 == 0) {
useEnergy(cost); this.useEnergy(this.cost);
} }
if (progress >= fuelScale) { if (this.progress >= this.fuelScale) {
progress = 0; this.progress = 0;
cookItems(); this.cookItems();
updateInventory = true; updateInventory = true;
} }
} else { } else {
progress = 0; this.progress = 0;
updateState(); this.updateState();
} }
if (burning != isBurning()) { if (burning != this.isBurning()) {
updateInventory = true; updateInventory = true;
} }
if (updateInventory) { if (updateInventory) {
markDirty(); this.markDirty();
} }
} }
public void cookItems() { public void cookItems() {
if (this.canSmelt()) { if (this.canSmelt()) {
ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1)); final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.getStackInSlot(this.input1));
if (getStackInSlot(output) == ItemStack.EMPTY) { if (this.getStackInSlot(this.output) == ItemStack.EMPTY) {
setInventorySlotContents(output, itemstack.copy()); this.setInventorySlotContents(this.output, itemstack.copy());
} else if (getStackInSlot(output).isItemEqual(itemstack)) { } else if (this.getStackInSlot(this.output).isItemEqual(itemstack)) {
getStackInSlot(output).grow(itemstack.getCount()); this.getStackInSlot(this.output).grow(itemstack.getCount());
} }
if (getStackInSlot(input1).getCount() > 1) { if (this.getStackInSlot(this.input1).getCount() > 1) {
this.decrStackSize(input1, 1); this.decrStackSize(this.input1, 1);
} else { } else {
setInventorySlotContents(input1, ItemStack.EMPTY); this.setInventorySlotContents(this.input1, ItemStack.EMPTY);
} }
} }
} }
public boolean canSmelt() { public boolean canSmelt() {
if (getStackInSlot(input1) == ItemStack.EMPTY) { if (this.getStackInSlot(this.input1) == ItemStack.EMPTY) {
return false; return false;
} else { } else {
ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1)); final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.getStackInSlot(this.input1));
if (itemstack == ItemStack.EMPTY) if (itemstack == ItemStack.EMPTY)
return false; return false;
if (getStackInSlot(output) == ItemStack.EMPTY) if (this.getStackInSlot(this.output) == ItemStack.EMPTY)
return true; return true;
if (!getStackInSlot(output).isItemEqual(itemstack)) if (!this.getStackInSlot(this.output).isItemEqual(itemstack))
return false; return false;
int result = getStackInSlot(output).getCount() + itemstack.getCount(); final int result = this.getStackInSlot(this.output).getCount() + itemstack.getCount();
return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize()); return result <= this.getInventoryStackLimit() && result <= itemstack.getMaxStackSize();
} }
} }
public boolean isBurning() { public boolean isBurning() {
return getEnergy() > cost; return this.getEnergy() > this.cost;
} }
public ItemStack getResultFor(ItemStack stack) { public ItemStack getResultFor(final ItemStack stack) {
ItemStack result = FurnaceRecipes.instance().getSmeltingResult(stack); final ItemStack result = FurnaceRecipes.instance().getSmeltingResult(stack);
if (result != ItemStack.EMPTY) { if (result != ItemStack.EMPTY) {
return result.copy(); return result.copy();
} }
@ -110,26 +112,26 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl
} }
public void updateState() { public void updateState() {
IBlockState BlockStateContainer = world.getBlockState(pos); final IBlockState BlockStateContainer = this.world.getBlockState(this.pos);
if (BlockStateContainer.getBlock() instanceof BlockMachineBase) { if (BlockStateContainer.getBlock() instanceof BlockMachineBase) {
BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock(); final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != progress > 0) if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != this.progress > 0)
blockMachineBase.setActive(progress > 0, world, pos); blockMachineBase.setActive(this.progress > 0, this.world, this.pos);
} }
} }
@Override @Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) { public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) {
return false; return false;
} }
@Override @Override
public EnumFacing getFacing() { public EnumFacing getFacing() {
return getFacingEnum(); return this.getFacingEnum();
} }
@Override @Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) { public boolean wrenchCanRemove(final EntityPlayer entityPlayer) {
return entityPlayer.isSneaking(); return entityPlayer.isSneaking();
} }
@ -139,7 +141,7 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl
} }
@Override @Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) { public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.ELECTRIC_FURNACE, 1); return new ItemStack(ModBlocks.ELECTRIC_FURNACE, 1);
} }
@ -149,34 +151,34 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl
// ISidedInventory // ISidedInventory
@Override @Override
public int[] getSlotsForFace(EnumFacing side) { public int[] getSlotsForFace(final EnumFacing side) {
return side == EnumFacing.DOWN ? SLOTS_BOTTOM : (side == EnumFacing.UP ? SLOTS_TOP : SLOTS_SIDES); return side == EnumFacing.DOWN ? TileElectricFurnace.SLOTS_BOTTOM : side == EnumFacing.UP ? TileElectricFurnace.SLOTS_TOP : TileElectricFurnace.SLOTS_SIDES;
} }
@Override @Override
public boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side) { public boolean canInsertItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
if (slotIndex == 2) if (slotIndex == 2)
return false; return false;
return isItemValidForSlot(slotIndex, itemStack); return this.isItemValidForSlot(slotIndex, itemStack);
} }
@Override @Override
public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side) { public boolean canExtractItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
return slotIndex == 1; return slotIndex == 1;
} }
@Override @Override
public double getMaxPower() { public double getMaxPower() {
return capacity; return this.capacity;
} }
@Override @Override
public boolean canAcceptEnergy(EnumFacing direction) { public boolean canAcceptEnergy(final EnumFacing direction) {
return true; return true;
} }
@Override @Override
public boolean canProvideEnergy(EnumFacing direction) { public boolean canProvideEnergy(final EnumFacing direction) {
return false; return false;
} }
@ -197,6 +199,14 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl
@Override @Override
public Inventory getInventory() { public Inventory getInventory() {
return inventory; return this.inventory;
}
public int getBurnTime() {
return this.progress;
}
public void setBurnTime(final int burnTime) {
this.progress = burnTime;
} }
} }