Convert MatterFabricator

This commit is contained in:
Ourten 2017-01-08 15:22:59 +01:00
parent ad890079ec
commit 665b5f7569
4 changed files with 71 additions and 130 deletions

View file

@ -126,8 +126,13 @@ public class GuiHandler implements IGuiHandler {
return new ContainerImplosionCompressor(
(TileImplosionCompressor) world.getTileEntity(new BlockPos(x, y, z)), player);
} else if (ID == GuiHandler.matterfabID) {
return new ContainerMatterFabricator((TileMatterFabricator) world.getTileEntity(new BlockPos(x, y, z)),
player);
return new ContainerBuilder("matterfabricator").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile((IInventory) world.getTileEntity(new BlockPos(x, y, z))).slot(0, 33, 17)
.slot(1, 33, 35).slot(2, 33, 53).slot(3, 51, 17).slot(4, 51, 35).slot(5, 51, 53)
.outputSlot(6, 116, 35).syncEnergyValue()
.syncIntegerValue(((TileMatterFabricator) world.getTileEntity(new BlockPos(x, y, z)))::getProgress,
((TileMatterFabricator) world.getTileEntity(new BlockPos(x, y, z)))::setProgress)
.addInventory().create();
} else if (ID == GuiHandler.assemblingmachineID) {
return new ContainerBuilder("assemblingmachine").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile((IInventory) world.getTileEntity(new BlockPos(x, y, z))).slot(0, 47, 17)

View file

@ -1,83 +0,0 @@
package techreborn.client.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IContainerListener;
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.tiles.TileMatterFabricator;
public class ContainerMatterFabricator extends RebornContainer {
public int progressTime;
EntityPlayer player;
TileMatterFabricator tile;
public ContainerMatterFabricator(TileMatterFabricator tileMatterfab, EntityPlayer player) {
tile = tileMatterfab;
this.player = player;
// input
this.addSlotToContainer(new BaseSlot(tileMatterfab.inventory, 0, 33, 17));
this.addSlotToContainer(new BaseSlot(tileMatterfab.inventory, 1, 33, 35));
this.addSlotToContainer(new BaseSlot(tileMatterfab.inventory, 2, 33, 53));
this.addSlotToContainer(new BaseSlot(tileMatterfab.inventory, 3, 51, 17));
this.addSlotToContainer(new BaseSlot(tileMatterfab.inventory, 4, 51, 35));
this.addSlotToContainer(new BaseSlot(tileMatterfab.inventory, 5, 51, 53));
// outputs
this.addSlotToContainer(new SlotOutput(tileMatterfab.inventory, 6, 116, 35));
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;
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (int i = 0; i < this.listeners.size(); i++) {
IContainerListener IContainerListener = this.listeners.get(i);
if (this.progressTime != tile.progresstime) {
IContainerListener.sendProgressBarUpdate(this, 0, tile.progresstime);
}
}
}
@Override
public void addListener(IContainerListener crafting) {
super.addListener(crafting);
crafting.sendProgressBarUpdate(this, 0, tile.progresstime);
}
@SideOnly(Side.CLIENT)
@Override
public void updateProgressBar(int id, int value) {
if (id == 0) {
this.progressTime = value;
}
}
public int getProgressScaled(int scale) {
if (progressTime != 0) {
return progressTime * scale / tile.maxProgresstime();
}
return 0;
}
}

View file

@ -5,49 +5,51 @@ 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.ContainerMatterFabricator;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.tiles.TileMatterFabricator;
public class GuiMatterFabricator extends GuiContainer {
private static final ResourceLocation texture = new ResourceLocation("techreborn",
"textures/gui/matterfabricator.png");
"textures/gui/matterfabricator.png");
TileMatterFabricator matterfab;
ContainerMatterFabricator containerMatterFabricator;
public GuiMatterFabricator(EntityPlayer player, TileMatterFabricator tilematterfab) {
super(new ContainerMatterFabricator(tilematterfab, player));
public GuiMatterFabricator(final EntityPlayer player, final TileMatterFabricator tilematterfab) {
super(new ContainerBuilder("matterfabricator").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(tilematterfab).slot(0, 33, 17).slot(1, 33, 35).slot(2, 33, 53).slot(3, 51, 17)
.slot(4, 51, 35).slot(5, 51, 53).outputSlot(6, 116, 35).syncEnergyValue()
.syncIntegerValue(tilematterfab::getProgress, tilematterfab::setProgress).addInventory().create());
this.xSize = 176;
this.ySize = 167;
matterfab = tilematterfab;
containerMatterFabricator = (ContainerMatterFabricator) this.inventorySlots;
this.matterfab = tilematterfab;
}
@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(GuiMatterFabricator.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 = containerMatterFabricator.getProgressScaled(24);
final int j = this.matterfab.getProgressScaled(24);
if (j > 0) {
this.drawTexturedModalRect(k + 79, l + 34, 176, 14, j + 1, 16);
}
}
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
String name = I18n.translateToLocal("tile.techreborn.matterfabricator.name");
@Override
protected void drawGuiContainerForegroundLayer(final int p_146979_1_, final int p_146979_2_) {
final int k = (this.width - this.xSize) / 2;
final int l = (this.height - this.ySize) / 2;
final String name = I18n.translateToLocal("tile.techreborn.matterfabricator.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.fontRendererObj.drawString(containerMatterFabricator.getProgressScaled(100) + "%", 80, 50, 4210752);
this.ySize - 96 + 2, 4210752);
this.fontRendererObj.drawString(this.matterfab.getProgressScaled(100) + "%", 80, 50, 4210752);
}
}

View file

@ -3,12 +3,14 @@ package techreborn.tiles;
import net.minecraft.entity.player.EntityPlayer;
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.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils;
import techreborn.init.ModBlocks;
import techreborn.init.ModItems;
import techreborn.items.ItemParts;
@ -27,17 +29,17 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
}
@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();
}
@ -47,7 +49,7 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.MATTER_FABRICATOR, 1);
}
@ -77,7 +79,7 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
// }
public int maxProgresstime() {
return fabricationRate;
return TileMatterFabricator.fabricationRate;
}
@Override
@ -86,14 +88,14 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
if (!super.world.isRemote) {
for (int i = 0; i < 6; i++) {
ItemStack stack = inventory.getStackInSlot(i);
final ItemStack stack = this.inventory.getStackInSlot(i);
if (this.amplifier < 10000 && stack != ItemStack.EMPTY) {
int amp = (int) ((long) (getValue(stack) / 32));
if (ItemUtils.isItemEqual(stack, inventory.getStackInSlot(i), true, true)) {
if (canUseEnergy(1)) {
useEnergy(1);
final int amp = this.getValue(stack) / 32;
if (ItemUtils.isItemEqual(stack, this.inventory.getStackInSlot(i), true, true)) {
if (this.canUseEnergy(1)) {
this.useEnergy(1);
this.amplifier += amp;
inventory.decrStackSize(i, 1);
this.inventory.decrStackSize(i, 1);
}
}
}
@ -120,27 +122,27 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
}
private boolean spaceForOutput() {
return inventory.getStackInSlot(6) == ItemStack.EMPTY
|| ItemUtils.isItemEqual(inventory.getStackInSlot(6), new ItemStack(ModItems.UU_MATTER), true, true)
&& inventory.getStackInSlot(6).getCount() < 64;
return this.inventory.getStackInSlot(6) == ItemStack.EMPTY
|| ItemUtils.isItemEqual(this.inventory.getStackInSlot(6), new ItemStack(ModItems.UU_MATTER), true, true)
&& this.inventory.getStackInSlot(6).getCount() < 64;
}
private void addOutputProducts() {
if (inventory.getStackInSlot(6) == ItemStack.EMPTY) {
inventory.setInventorySlotContents(6, new ItemStack(ModItems.UU_MATTER));
} else if (ItemUtils.isItemEqual(inventory.getStackInSlot(6), new ItemStack(ModItems.UU_MATTER), true, true)) {
inventory.getStackInSlot(6).setCount(Math.min(64, 1 + inventory.getStackInSlot(6).getCount()));
if (this.inventory.getStackInSlot(6) == ItemStack.EMPTY) {
this.inventory.setInventorySlotContents(6, new ItemStack(ModItems.UU_MATTER));
} else if (ItemUtils.isItemEqual(this.inventory.getStackInSlot(6), new ItemStack(ModItems.UU_MATTER), true, true)) {
this.inventory.getStackInSlot(6).setCount(Math.min(64, 1 + this.inventory.getStackInSlot(6).getCount()));
}
}
public boolean decreaseStoredEnergy(double aEnergy, boolean aIgnoreTooLessEnergy) {
public boolean decreaseStoredEnergy(final double aEnergy, final boolean aIgnoreTooLessEnergy) {
if (this.getEnergy() - aEnergy < 0 && !aIgnoreTooLessEnergy) {
return false;
} else {
setEnergy(this.getEnergy() - aEnergy);
this.setEnergy(this.getEnergy() - aEnergy);
if (this.getEnergy() < 0) {
setEnergy(0);
this.setEnergy(0);
return false;
} else {
return true;
@ -149,7 +151,7 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
}
// TODO ic2
public int getValue(ItemStack itemStack) {
public int getValue(final ItemStack itemStack) {
// int value = getValue(Recipes.matterAmplifier.getOutputFor(itemStack,
// false));
if (itemStack.getItem() == ModItems.PARTS && itemStack.getItemDamage() == ItemParts.getPartByName("scrap").getItemDamage()) {
@ -173,12 +175,12 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
}
@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;
}
@ -199,6 +201,21 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
public int getProgress() {
return this.progresstime;
}
public void setProgress(final int progress) {
this.progresstime = progress;
}
public int getProgressScaled(final int scale) {
if (this.progresstime != 0) {
return this.progresstime * scale / this.maxProgresstime();
}
return 0;
}
}