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) ((TileIronFurnace) world.getTileEntity(new BlockPos(x, y, z)))::setTotalBurnTime)
.addInventory().create(); .addInventory().create();
} else if (ID == GuiHandler.recyclerID) { } 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) { } else if (ID == GuiHandler.scrapboxinatorID) {
return new ContainerScrapboxinator((TileScrapboxinator) world.getTileEntity(new BlockPos(x, y, z)), player); return new ContainerScrapboxinator((TileScrapboxinator) world.getTileEntity(new BlockPos(x, y, z)), player);
} else if (ID == GuiHandler.batboxID) { } 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) { public GuiAssemblingMachine(final EntityPlayer player, final TileAssemblingMachine assemblingMachine) {
super(new ContainerBuilder("assemblingmachine").player(player.inventory).inventory(8, 84).hotbar(8, 142) 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) .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) .energySlot(3, 56, 53).upgradeSlot(4, 152, 8).upgradeSlot(5, 152, 26).upgradeSlot(6, 152, 44)
.upgradeSlot(10, 152, 62).syncEnergyValue().syncCrafterValue().addInventory().create()); .upgradeSlot(7, 152, 62).syncEnergyValue().syncCrafterValue().addInventory().create());
this.xSize = 176; this.xSize = 176;
this.ySize = 167; this.ySize = 167;
this.assemblingmachine = assemblingMachine; this.assemblingmachine = assemblingMachine;

View file

@ -19,8 +19,8 @@ public class GuiChemicalReactor extends GuiContainer {
public GuiChemicalReactor(final EntityPlayer player, final TileChemicalReactor tilechemicalReactor) { public GuiChemicalReactor(final EntityPlayer player, final TileChemicalReactor tilechemicalReactor) {
super(new ContainerBuilder("chemicalreactor").player(player.inventory).inventory(8, 84).hotbar(8, 142) 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) .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) .energySlot(3, 8, 51).upgradeSlot(4, 152, 8).upgradeSlot(5, 152, 26).upgradeSlot(6, 152, 44)
.upgradeSlot(10, 152, 62).syncEnergyValue().syncCrafterValue().addInventory().create()); .upgradeSlot(7, 152, 62).syncEnergyValue().syncCrafterValue().addInventory().create());
this.xSize = 176; this.xSize = 176;
this.ySize = 167; this.ySize = 167;
this.chemicalReactor = tilechemicalReactor; this.chemicalReactor = tilechemicalReactor;

View file

@ -5,47 +5,51 @@ 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.ContainerRecycler;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.tiles.teir1.TileRecycler; import techreborn.tiles.teir1.TileRecycler;
public class GuiRecycler extends GuiContainer { public class GuiRecycler 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");
TileRecycler compressor; TileRecycler recycler;
ContainerRecycler containerGrinder;
public GuiRecycler(EntityPlayer player, TileRecycler tilegrinder) { public GuiRecycler(final EntityPlayer player, final TileRecycler recycler) {
super(new ContainerRecycler(tilegrinder, player)); 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.xSize = 176;
this.ySize = 167; this.ySize = 167;
compressor = tilegrinder; this.recycler = recycler;
containerGrinder = (ContainerRecycler) 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(GuiRecycler.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 = compressor.gaugeProgressScaled(24); j = this.recycler.gaugeProgressScaled(24);
if (j > 0) { if (j > 0) {
this.drawTexturedModalRect(k + 78, l + 35, 176, 14, j + 1, 16); this.drawTexturedModalRect(k + 78, l + 35, 176, 14, j + 1, 16);
} }
j = compressor.getEnergyScaled(12); j = this.recycler.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.recycler.name"); 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, 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,

View file

@ -5,12 +5,14 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
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;
import techreborn.items.ItemParts; import techreborn.items.ItemParts;
@ -30,107 +32,107 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv
super(1); super(1);
} }
public int gaugeProgressScaled(int scale) { public int gaugeProgressScaled(final int scale) {
return (progress * scale) / time; return this.progress * scale / this.time;
} }
@Override @Override
public void updateEntity() { public void updateEntity() {
if (world.isRemote) { if (this.world.isRemote) {
return; return;
} }
boolean burning = isBurning(); final boolean burning = this.isBurning();
boolean updateInventory = false; boolean updateInventory = false;
if (getEnergy() <= cost && canRecycle()) { if (this.getEnergy() <= this.cost && this.canRecycle()) {
if (getEnergy() > cost) { if (this.getEnergy() > this.cost) {
updateInventory = true; updateInventory = true;
} }
} }
if (isBurning() && canRecycle()) { if (this.isBurning() && this.canRecycle()) {
updateState(); this.updateState();
progress++; this.progress++;
if (progress >= time) { if (this.progress >= this.time) {
progress = 0; this.progress = 0;
recycleItems(); this.recycleItems();
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 recycleItems() { public void recycleItems() {
if (this.canRecycle()) { if (this.canRecycle()) {
ItemStack itemstack = ItemParts.getPartByName("scrap"); final ItemStack itemstack = ItemParts.getPartByName("scrap");
int randomchance = world.rand.nextInt(chance); final int randomchance = this.world.rand.nextInt(this.chance);
if (getStackInSlot(output) == ItemStack.EMPTY) { if (this.getStackInSlot(this.output) == ItemStack.EMPTY) {
useEnergy(cost); this.useEnergy(this.cost);
if (randomchance == 1) { if (randomchance == 1) {
setInventorySlotContents(output, itemstack.copy()); this.setInventorySlotContents(this.output, itemstack.copy());
} }
} else if (getStackInSlot(output).isItemEqual(itemstack)) { } else if (this.getStackInSlot(this.output).isItemEqual(itemstack)) {
useEnergy(cost); this.useEnergy(this.cost);
if (randomchance == 1) { if (randomchance == 1) {
getStackInSlot(output).setCount(itemstack.getCount()); this.getStackInSlot(this.output).setCount(itemstack.getCount());
} }
} }
if (getStackInSlot(input1).getCount() > 1) { if (this.getStackInSlot(this.input1).getCount() > 1) {
useEnergy(cost); this.useEnergy(this.cost);
this.decrStackSize(input1, 1); this.decrStackSize(this.input1, 1);
} else { } else {
useEnergy(cost); this.useEnergy(this.cost);
setInventorySlotContents(input1, ItemStack.EMPTY); this.setInventorySlotContents(this.input1, ItemStack.EMPTY);
} }
} }
} }
public boolean canRecycle() { public boolean canRecycle() {
return getStackInSlot(input1) != null && hasSlotGotSpace(output); return this.getStackInSlot(this.input1) != null && this.hasSlotGotSpace(this.output);
} }
public boolean hasSlotGotSpace(int slot) { public boolean hasSlotGotSpace(final int slot) {
if (getStackInSlot(slot) == ItemStack.EMPTY) { if (this.getStackInSlot(slot) == ItemStack.EMPTY) {
return true; return true;
} else if (getStackInSlot(slot).getCount() < getStackInSlot(slot).getMaxStackSize()) { } else if (this.getStackInSlot(slot).getCount() < this.getStackInSlot(slot).getMaxStackSize()) {
return true; return true;
} }
return true; return true;
} }
public boolean isBurning() { public boolean isBurning() {
return getEnergy() > cost; return this.getEnergy() > this.cost;
} }
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();
} }
@ -140,7 +142,7 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv
} }
@Override @Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) { public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.RECYCLER, 1); return new ItemStack(ModBlocks.RECYCLER, 1);
} }
@ -150,34 +152,34 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv
// ISidedInventory // ISidedInventory
@Override @Override
public int[] getSlotsForFace(EnumFacing side) { public int[] getSlotsForFace(final EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { output } : new int[] { input1 }; return side == EnumFacing.DOWN ? new int[] { this.output } : new int[] { this.input1 };
} }
@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 == output) if (slotIndex == this.output)
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 == output; return slotIndex == this.output;
} }
@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;
} }
@ -198,6 +200,14 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv
@Override @Override
public Inventory getInventory() { public Inventory getInventory() {
return inventory; return this.inventory;
}
public int getProgress() {
return this.progress;
}
public void setProgress(final int progress) {
this.progress = progress;
} }
} }