Convert Scrapboxinator

This commit is contained in:
Ourten 2017-01-08 12:05:57 +01:00
parent 3c40e25b6a
commit 619ddb14b8
5 changed files with 41 additions and 98 deletions

View file

@ -12,6 +12,7 @@ import reborncore.common.container.RebornContainer;
import techreborn.client.container.*;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.client.gui.*;
import techreborn.init.ModItems;
import techreborn.manual.GuiManual;
import techreborn.tiles.*;
import techreborn.tiles.fusionReactor.TileEntityFusionController;
@ -197,7 +198,14 @@ public class GuiHandler implements IGuiHandler {
((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);
return new ContainerBuilder("scrapboxinator").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile((IInventory) world.getTileEntity(new BlockPos(x, y, z)))
.filterSlot(0, 56, 34, stack -> stack.getItem() == ModItems.SCRAP_BOX).outputSlot(1, 116, 34)
.upgradeSlot(2, 152, 8).upgradeSlot(3, 152, 26).upgradeSlot(4, 152, 44).upgradeSlot(5, 152, 62)
.syncEnergyValue()
.syncIntegerValue(((TileScrapboxinator) world.getTileEntity(new BlockPos(x, y, z)))::getProgress,
((TileScrapboxinator) world.getTileEntity(new BlockPos(x, y, z)))::setProgress)
.addInventory().create();
} else if (ID == GuiHandler.batboxID) {
return new ContainerBuilder("batbox").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile((IInventory) world.getTileEntity(new BlockPos(x, y, z))).energySlot(0, 80, 17)

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.TileScrapboxinator;
public class ContainerScrapboxinator extends RebornContainer {
public int connectionStatus;
EntityPlayer player;
TileScrapboxinator tile;
public ContainerScrapboxinator(TileScrapboxinator tileScrapboxinator, EntityPlayer player) {
super();
tile = tileScrapboxinator;
this.player = player;
// input
this.addSlotToContainer(new SlotScrapbox(tileScrapboxinator.inventory, 0, 56, 34));
this.addSlotToContainer(new SlotOutput(tileScrapboxinator.inventory, 1, 116, 34));
// upgrades
this.addSlotToContainer(new SlotUpgrade(tileScrapboxinator.inventory, 2, 152, 8));
this.addSlotToContainer(new SlotUpgrade(tileScrapboxinator.inventory, 3, 152, 26));
this.addSlotToContainer(new SlotUpgrade(tileScrapboxinator.inventory, 4, 152, 44));
this.addSlotToContainer(new SlotUpgrade(tileScrapboxinator.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

@ -1,21 +0,0 @@
package techreborn.client.container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import reborncore.client.gui.slots.BaseSlot;
import techreborn.init.ModItems;
public class SlotScrapbox extends BaseSlot {
public SlotScrapbox(IInventory par1iInventory, int par2, int par3, int par4) {
super(par1iInventory, par2, par3, par4);
}
public boolean isItemValid(ItemStack par1ItemStack) {
return par1ItemStack.getItem() == ModItems.SCRAP_BOX;
}
public int getSlotStackLimit() {
return 64;
}
}

View file

@ -5,6 +5,7 @@ import org.apache.commons.lang3.tuple.Pair;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.SlotFurnaceFuel;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
@ -22,6 +23,7 @@ import techreborn.utils.upgrade.IMachineUpgrade;
import java.util.function.IntConsumer;
import java.util.function.IntSupplier;
import java.util.function.Predicate;
public class ContainerTileInventoryBuilder {
@ -50,6 +52,12 @@ public class ContainerTileInventoryBuilder {
return this;
}
public ContainerTileInventoryBuilder filterSlot(final int index, final int x, final int y,
final Predicate<ItemStack> filter) {
this.parent.slots.add(new FilteredSlot(this.tile, index, x, y).setFilter(filter));
return this;
}
@SuppressWarnings("null")
public ContainerTileInventoryBuilder energySlot(final int index, final int x, final int y) {
this.parent.slots.add(new FilteredSlot(this.tile, index, x, y)
@ -121,7 +129,7 @@ public class ContainerTileInventoryBuilder {
(currentNeededTicks) -> ((IRecipeCrafterProvider) this.tile)
.getRecipeCrafter().currentNeededTicks = currentNeededTicks);
Core.logHelper
.error(this.tile + " is not an instance of IRecipeCrafterProvider! Craft progress cannot be synced.");
.error(this.tile + " is not an instance of IRecipeCrafterProvider! Craft progress cannot be synced.");
return this;
}

View file

@ -5,52 +5,58 @@ import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import techreborn.client.container.ContainerScrapboxinator;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModItems;
import techreborn.tiles.TileScrapboxinator;
public class GuiScrapboxinator extends GuiContainer {
public static final ResourceLocation texture = new ResourceLocation("techreborn",
"textures/gui/scrapboxinator.png");
"textures/gui/scrapboxinator.png");
TileScrapboxinator tile;
ContainerScrapboxinator containerScrapboxinator;
public GuiScrapboxinator(EntityPlayer player, TileScrapboxinator tileScrapboxinator) {
super(new ContainerScrapboxinator(tileScrapboxinator, player));
public GuiScrapboxinator(final EntityPlayer player, final TileScrapboxinator scrapboxinator) {
super(new ContainerBuilder("scrapboxinator").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(scrapboxinator)
.filterSlot(0, 56, 34, stack -> stack.getItem() == ModItems.SCRAP_BOX).outputSlot(1, 116, 34)
.upgradeSlot(2, 152, 8).upgradeSlot(3, 152, 26).upgradeSlot(4, 152, 44).upgradeSlot(5, 152, 62)
.syncEnergyValue().syncIntegerValue(scrapboxinator::getProgress, scrapboxinator::setProgress)
.addInventory().create());
this.xSize = 176;
this.ySize = 167;
tile = tileScrapboxinator;
containerScrapboxinator = (ContainerScrapboxinator) this.inventorySlots;
this.tile = scrapboxinator;
}
@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(GuiScrapboxinator.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 = tile.gaugeProgressScaled(24);
j = this.tile.gaugeProgressScaled(24);
// System.out.println(compressor.gaugeProgressScaled(10));
if (j > 0) {
this.drawTexturedModalRect(k + 78, l + 35, 176, 14, j + 1, 16);
}
j = tile.getEnergyScaled(12);
j = this.tile.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 = net.minecraft.util.text.translation.I18n.translateToLocal("tile.techreborn.scrapboxinator.name");
@Override
protected void drawGuiContainerForegroundLayer(final int p_146979_1_, final int p_146979_2_) {
final String name = net.minecraft.util.text.translation.I18n.translateToLocal("tile.techreborn.scrapboxinator.name");
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6,
4210752);
4210752);
this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2,
4210752);
4210752);
}
}