Convert recycler + Fix slot indexes

This commit is contained in:
Ourten 2017-01-08 02:41:50 +01:00
parent d77ed99e8a
commit b9444b5ce5
6 changed files with 95 additions and 133 deletions

View file

@ -189,7 +189,13 @@ public class GuiHandler implements IGuiHandler {
((TileIronFurnace) world.getTileEntity(new BlockPos(x, y, z)))::setTotalBurnTime)
.addInventory().create();
} else if (ID == GuiHandler.recyclerID) {
return new ContainerRecycler((TileRecycler) world.getTileEntity(new BlockPos(x, y, z)), player);
return new ContainerBuilder("recycler").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile((IInventory) world.getTileEntity(new BlockPos(x, y, z))).slot(0, 56, 34)
.slot(1, 116, 34).upgradeSlot(2, 152, 8).upgradeSlot(3, 152, 26).upgradeSlot(4, 152, 44)
.upgradeSlot(5, 152, 62).syncEnergyValue()
.syncIntegerValue(((TileRecycler) world.getTileEntity(new BlockPos(x, y, z)))::getProgress,
((TileRecycler) world.getTileEntity(new BlockPos(x, y, z)))::setProgress)
.addInventory().create();
} else if (ID == GuiHandler.scrapboxinatorID) {
return new ContainerScrapboxinator((TileScrapboxinator) world.getTileEntity(new BlockPos(x, y, z)), player);
} else if (ID == GuiHandler.batboxID) {

View file

@ -1,58 +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.TileRecycler;
public class ContainerRecycler extends RebornContainer {
public int connectionStatus;
EntityPlayer player;
TileRecycler tile;
public ContainerRecycler(TileRecycler 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

@ -19,8 +19,8 @@ public class GuiAssemblingMachine extends GuiContainer {
public GuiAssemblingMachine(final EntityPlayer player, final TileAssemblingMachine assemblingMachine) {
super(new ContainerBuilder("assemblingmachine").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(assemblingMachine).slot(0, 47, 17).slot(1, 65, 17).outputSlot(2, 116, 35)
.energySlot(6, 56, 53).upgradeSlot(7, 152, 8).upgradeSlot(8, 152, 26).upgradeSlot(9, 152, 44)
.upgradeSlot(10, 152, 62).syncEnergyValue().syncCrafterValue().addInventory().create());
.energySlot(3, 56, 53).upgradeSlot(4, 152, 8).upgradeSlot(5, 152, 26).upgradeSlot(6, 152, 44)
.upgradeSlot(7, 152, 62).syncEnergyValue().syncCrafterValue().addInventory().create());
this.xSize = 176;
this.ySize = 167;
this.assemblingmachine = assemblingMachine;

View file

@ -19,8 +19,8 @@ public class GuiChemicalReactor extends GuiContainer {
public GuiChemicalReactor(final EntityPlayer player, final TileChemicalReactor tilechemicalReactor) {
super(new ContainerBuilder("chemicalreactor").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(tilechemicalReactor).slot(0, 70, 21).slot(1, 90, 21).outputSlot(2, 80, 51)
.energySlot(6, 8, 51).upgradeSlot(7, 152, 8).upgradeSlot(8, 152, 26).upgradeSlot(9, 152, 44)
.upgradeSlot(10, 152, 62).syncEnergyValue().syncCrafterValue().addInventory().create());
.energySlot(3, 8, 51).upgradeSlot(4, 152, 8).upgradeSlot(5, 152, 26).upgradeSlot(6, 152, 44)
.upgradeSlot(7, 152, 62).syncEnergyValue().syncCrafterValue().addInventory().create());
this.xSize = 176;
this.ySize = 167;
this.chemicalReactor = tilechemicalReactor;

View file

@ -5,50 +5,54 @@ 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 techreborn.client.container.ContainerRecycler;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.tiles.teir1.TileRecycler;
public class GuiRecycler extends GuiContainer {
public static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/compressor.png");
TileRecycler compressor;
ContainerRecycler containerGrinder;
TileRecycler recycler;
public GuiRecycler(EntityPlayer player, TileRecycler tilegrinder) {
super(new ContainerRecycler(tilegrinder, player));
public GuiRecycler(final EntityPlayer player, final TileRecycler recycler) {
super(new ContainerBuilder("recycler").player(player.inventory).inventory(8, 84).hotbar(8, 142).addInventory()
.tile(recycler).slot(0, 56, 34).slot(1, 116, 34).upgradeSlot(2, 152, 8).upgradeSlot(3, 152, 26)
.upgradeSlot(4, 152, 44).upgradeSlot(5, 152, 62).syncEnergyValue()
.syncIntegerValue(recycler::getProgress, recycler::setProgress).addInventory().create());
this.xSize = 176;
this.ySize = 167;
compressor = tilegrinder;
containerGrinder = (ContainerRecycler) this.inventorySlots;
this.recycler = recycler;
}
@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(GuiRecycler.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);
int j = 0;
j = compressor.gaugeProgressScaled(24);
j = this.recycler.gaugeProgressScaled(24);
if (j > 0) {
this.drawTexturedModalRect(k + 78, l + 35, 176, 14, j + 1, 16);
}
j = compressor.getEnergyScaled(12);
j = this.recycler.getEnergyScaled(12);
if (j > 0) {
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_) {
String name = I18n.translateToLocal("tile.techreborn.recycler.name");
@Override
protected void drawGuiContainerForegroundLayer(final int p_146979_1_, final int p_146979_2_) {
final String name = I18n.translateToLocal("tile.techreborn.recycler.name");
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.ySize - 96 + 2, 4210752);
this.ySize - 96 + 2, 4210752);
}
}

View file

@ -5,12 +5,14 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import techreborn.init.ModBlocks;
import techreborn.items.ItemParts;
@ -30,107 +32,107 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv
super(1);
}
public int gaugeProgressScaled(int scale) {
return (progress * scale) / time;
public int gaugeProgressScaled(final int scale) {
return this.progress * scale / this.time;
}
@Override
public void updateEntity() {
if (world.isRemote) {
if (this.world.isRemote) {
return;
}
boolean burning = isBurning();
final boolean burning = this.isBurning();
boolean updateInventory = false;
if (getEnergy() <= cost && canRecycle()) {
if (getEnergy() > cost) {
if (this.getEnergy() <= this.cost && this.canRecycle()) {
if (this.getEnergy() > this.cost) {
updateInventory = true;
}
}
if (isBurning() && canRecycle()) {
updateState();
if (this.isBurning() && this.canRecycle()) {
this.updateState();
progress++;
if (progress >= time) {
progress = 0;
recycleItems();
this.progress++;
if (this.progress >= this.time) {
this.progress = 0;
this.recycleItems();
updateInventory = true;
}
} else {
progress = 0;
updateState();
this.progress = 0;
this.updateState();
}
if (burning != isBurning()) {
if (burning != this.isBurning()) {
updateInventory = true;
}
if (updateInventory) {
markDirty();
this.markDirty();
}
}
public void recycleItems() {
if (this.canRecycle()) {
ItemStack itemstack = ItemParts.getPartByName("scrap");
int randomchance = world.rand.nextInt(chance);
final ItemStack itemstack = ItemParts.getPartByName("scrap");
final int randomchance = this.world.rand.nextInt(this.chance);
if (getStackInSlot(output) == ItemStack.EMPTY) {
useEnergy(cost);
if (this.getStackInSlot(this.output) == ItemStack.EMPTY) {
this.useEnergy(this.cost);
if (randomchance == 1) {
setInventorySlotContents(output, itemstack.copy());
this.setInventorySlotContents(this.output, itemstack.copy());
}
} else if (getStackInSlot(output).isItemEqual(itemstack)) {
useEnergy(cost);
} else if (this.getStackInSlot(this.output).isItemEqual(itemstack)) {
this.useEnergy(this.cost);
if (randomchance == 1) {
getStackInSlot(output).setCount(itemstack.getCount());
this.getStackInSlot(this.output).setCount(itemstack.getCount());
}
}
if (getStackInSlot(input1).getCount() > 1) {
useEnergy(cost);
this.decrStackSize(input1, 1);
if (this.getStackInSlot(this.input1).getCount() > 1) {
this.useEnergy(this.cost);
this.decrStackSize(this.input1, 1);
} else {
useEnergy(cost);
setInventorySlotContents(input1, ItemStack.EMPTY);
this.useEnergy(this.cost);
this.setInventorySlotContents(this.input1, ItemStack.EMPTY);
}
}
}
public boolean canRecycle() {
return getStackInSlot(input1) != null && hasSlotGotSpace(output);
return this.getStackInSlot(this.input1) != null && this.hasSlotGotSpace(this.output);
}
public boolean hasSlotGotSpace(int slot) {
if (getStackInSlot(slot) == ItemStack.EMPTY) {
public boolean hasSlotGotSpace(final int slot) {
if (this.getStackInSlot(slot) == ItemStack.EMPTY) {
return true;
} else if (getStackInSlot(slot).getCount() < getStackInSlot(slot).getMaxStackSize()) {
} else if (this.getStackInSlot(slot).getCount() < this.getStackInSlot(slot).getMaxStackSize()) {
return true;
}
return true;
}
public boolean isBurning() {
return getEnergy() > cost;
return this.getEnergy() > this.cost;
}
public void updateState() {
IBlockState BlockStateContainer = world.getBlockState(pos);
final IBlockState BlockStateContainer = this.world.getBlockState(this.pos);
if (BlockStateContainer.getBlock() instanceof BlockMachineBase) {
BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != progress > 0)
blockMachineBase.setActive(progress > 0, world, pos);
final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != this.progress > 0)
blockMachineBase.setActive(this.progress > 0, this.world, this.pos);
}
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) {
return false;
}
@Override
public EnumFacing getFacing() {
return getFacingEnum();
return this.getFacingEnum();
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
public boolean wrenchCanRemove(final EntityPlayer entityPlayer) {
return entityPlayer.isSneaking();
}
@ -140,7 +142,7 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.RECYCLER, 1);
}
@ -150,34 +152,34 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv
// ISidedInventory
@Override
public int[] getSlotsForFace(EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { output } : new int[] { input1 };
public int[] getSlotsForFace(final EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { this.output } : new int[] { this.input1 };
}
@Override
public boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
if (slotIndex == output)
public boolean canInsertItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
if (slotIndex == this.output)
return false;
return isItemValidForSlot(slotIndex, itemStack);
return this.isItemValidForSlot(slotIndex, itemStack);
}
@Override
public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
return slotIndex == output;
public boolean canExtractItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
return slotIndex == this.output;
}
@Override
public double getMaxPower() {
return capacity;
return this.capacity;
}
@Override
public boolean canAcceptEnergy(EnumFacing direction) {
public boolean canAcceptEnergy(final EnumFacing direction) {
return true;
}
@Override
public boolean canProvideEnergy(EnumFacing direction) {
public boolean canProvideEnergy(final EnumFacing direction) {
return false;
}
@ -198,6 +200,14 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
public int getProgress() {
return this.progress;
}
public void setProgress(final int progress) {
this.progress = progress;
}
}