rewritten matter fab
Take 3 should be good :)
This commit is contained in:
parent
6d99b28e7d
commit
74a9ace574
3 changed files with 89 additions and 44 deletions
|
@ -1,6 +1,9 @@
|
||||||
package techreborn.client.container;
|
package techreborn.client.container;
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.ICrafting;
|
||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
import techreborn.client.SlotOutput;
|
import techreborn.client.SlotOutput;
|
||||||
import techreborn.tiles.TileMatterFabricator;
|
import techreborn.tiles.TileMatterFabricator;
|
||||||
|
@ -11,7 +14,7 @@ public class ContainerMatterFabricator extends TechRebornContainer{
|
||||||
|
|
||||||
TileMatterFabricator tile;
|
TileMatterFabricator tile;
|
||||||
|
|
||||||
public int tickTime;
|
public int progressTime;
|
||||||
|
|
||||||
public ContainerMatterFabricator(TileMatterFabricator tileMatterfab,
|
public ContainerMatterFabricator(TileMatterFabricator tileMatterfab,
|
||||||
EntityPlayer player)
|
EntityPlayer player)
|
||||||
|
@ -55,4 +58,36 @@ public class ContainerMatterFabricator extends TechRebornContainer{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void detectAndSendChanges() {
|
||||||
|
super.detectAndSendChanges();
|
||||||
|
for (int i = 0; i < this.crafters.size(); i++) {
|
||||||
|
ICrafting icrafting = (ICrafting) this.crafters.get(i);
|
||||||
|
if (this.progressTime != tile.progresstime) {
|
||||||
|
icrafting.sendProgressBarUpdate(this, 0, tile.progresstime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addCraftingToCrafters(ICrafting crafting) {
|
||||||
|
super.addCraftingToCrafters(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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,15 @@ public class GuiMatterFabricator extends GuiContainer{
|
||||||
|
|
||||||
TileMatterFabricator matterfab;
|
TileMatterFabricator matterfab;
|
||||||
|
|
||||||
|
ContainerMatterFabricator containerMatterFabricator;
|
||||||
|
|
||||||
public GuiMatterFabricator(EntityPlayer player, TileMatterFabricator tilematterfab)
|
public GuiMatterFabricator(EntityPlayer player, TileMatterFabricator tilematterfab)
|
||||||
{
|
{
|
||||||
super(new ContainerMatterFabricator(tilematterfab, player));
|
super(new ContainerMatterFabricator(tilematterfab, player));
|
||||||
this.xSize = 176;
|
this.xSize = 176;
|
||||||
this.ySize = 167;
|
this.ySize = 167;
|
||||||
matterfab = tilematterfab;
|
matterfab = tilematterfab;
|
||||||
|
containerMatterFabricator = (ContainerMatterFabricator) this.inventorySlots;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -32,6 +34,11 @@ public class GuiMatterFabricator extends GuiContainer{
|
||||||
int k = (this.width - this.xSize) / 2;
|
int k = (this.width - this.xSize) / 2;
|
||||||
int l = (this.height - this.ySize) / 2;
|
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 = containerMatterFabricator.getProgressScaled(24);
|
||||||
|
if(j > 0) {
|
||||||
|
this.drawTexturedModalRect(k + 79, l + 34, 176, 14, j + 1, 16);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void drawGuiContainerForegroundLayer(int p_146979_1_,
|
protected void drawGuiContainerForegroundLayer(int p_146979_1_,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package techreborn.tiles;
|
||||||
|
|
||||||
import ic2.api.energy.prefab.BasicSink;
|
import ic2.api.energy.prefab.BasicSink;
|
||||||
import ic2.api.energy.tile.IEnergyTile;
|
import ic2.api.energy.tile.IEnergyTile;
|
||||||
|
import ic2.api.recipe.RecipeOutput;
|
||||||
import ic2.api.recipe.Recipes;
|
import ic2.api.recipe.Recipes;
|
||||||
import ic2.api.tile.IWrenchable;
|
import ic2.api.tile.IWrenchable;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
@ -10,28 +11,23 @@ import net.minecraft.inventory.ISidedInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
import techreborn.config.ConfigTechReborn;
|
|
||||||
import techreborn.init.ModBlocks;
|
import techreborn.init.ModBlocks;
|
||||||
import techreborn.init.ModItems;
|
import techreborn.init.ModItems;
|
||||||
import techreborn.util.Inventory;
|
import techreborn.util.Inventory;
|
||||||
import techreborn.util.ItemUtils;
|
import techreborn.util.ItemUtils;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
public class TileMatterFabricator extends TileMachineBase implements IWrenchable, IEnergyTile, IInventory, ISidedInventory {
|
public class TileMatterFabricator extends TileMachineBase implements IWrenchable, IEnergyTile, IInventory, ISidedInventory {
|
||||||
|
|
||||||
public static int sMatterFabricationRate = 166666;
|
public static int fabricationRate = 166666;
|
||||||
public int tickTime;
|
public int tickTime;
|
||||||
public BasicSink energy;
|
public BasicSink energy;
|
||||||
public Inventory inventory = new Inventory(7, "TileMatterFabricator", 64);
|
public Inventory inventory = new Inventory(7, "TileMatterFabricator", 64);
|
||||||
private int mAmplifier = 0;
|
private int amplifier = 0;
|
||||||
private int mProgresstime = 0;
|
public int progresstime = 0;
|
||||||
|
|
||||||
public TileMatterFabricator() {
|
public TileMatterFabricator() {
|
||||||
//TODO configs
|
//TODO configs
|
||||||
energy = new BasicSink(this, 100000,
|
energy = new BasicSink(this, 10000000, 6);
|
||||||
ConfigTechReborn.CentrifugeTier);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -175,48 +171,43 @@ public class TileMatterFabricator extends TileMachineBase implements IWrenchable
|
||||||
}
|
}
|
||||||
|
|
||||||
public int maxProgresstime() {
|
public int maxProgresstime() {
|
||||||
return sMatterFabricationRate;
|
return fabricationRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
|
energy.updateEntity();
|
||||||
|
|
||||||
if (!super.worldObj.isRemote) {
|
if (!super.worldObj.isRemote) {
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
if (this.energy.getEnergyStored() > 0 && !super.worldObj.isBlockIndirectlyGettingPowered(super.xCoord, super.yCoord, super.zCoord)) {
|
ItemStack stack = inventory.getStackInSlot(i);
|
||||||
Iterator tIterator = Recipes.matterAmplifier.getRecipes().entrySet().iterator();
|
if (this.amplifier < 100000 && stack != null) {
|
||||||
|
int amp = (int) ((long) (getValue(stack) * (long) this.maxProgresstime() / 166666L));
|
||||||
while (this.mAmplifier < 100000 && tIterator.hasNext()) {
|
if (ItemUtils.isItemEqual(stack, inventory.getStackInSlot(i), true, true)) {
|
||||||
Entry tEntry = (Entry) tIterator.next();
|
this.amplifier += amp;
|
||||||
ItemStack tStack = (ItemStack) tEntry.getKey();
|
|
||||||
int tValue = (int) ((long) ((Integer) tEntry.getValue()).intValue() * (long) this.maxProgresstime() / 166666L);
|
|
||||||
if (tValue > 0) {
|
|
||||||
for (int i = 0; this.mAmplifier < 100000 && i < 5; ++i) {
|
|
||||||
if (inventory.getStackInSlot(i) != null && ItemUtils.isItemEqual(inventory.getStackInSlot(i), tStack, true, false)) {
|
|
||||||
this.mAmplifier += tValue;
|
|
||||||
inventory.decrStackSize(i, 1);
|
inventory.decrStackSize(i, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (this.mAmplifier > 0) {
|
if (this.amplifier > 0) {
|
||||||
if (this.mAmplifier > this.energy.getEnergyStored()) {
|
if (this.amplifier > this.energy.getEnergyStored()) {
|
||||||
this.mProgresstime += this.energy.getEnergyStored();
|
this.progresstime += this.energy.getEnergyStored();
|
||||||
this.mAmplifier -= this.energy.getEnergyStored();
|
this.amplifier -= this.energy.getEnergyStored();
|
||||||
this.decreaseStoredEnergy(this.energy.getEnergyStored(), true);
|
this.decreaseStoredEnergy(this.energy.getEnergyStored(), true);
|
||||||
} else {
|
} else {
|
||||||
this.mProgresstime += this.mAmplifier;
|
this.progresstime += this.amplifier;
|
||||||
this.decreaseStoredEnergy(this.mAmplifier, true);
|
this.decreaseStoredEnergy(this.amplifier, true);
|
||||||
this.mAmplifier = 0;
|
this.amplifier = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.mProgresstime > this.maxProgresstime() && this.spaceForOutput()) {
|
if (this.progresstime > this.maxProgresstime() && this.spaceForOutput()) {
|
||||||
this.mProgresstime -= this.maxProgresstime();
|
this.progresstime -= this.maxProgresstime();
|
||||||
this.addOutputProducts();
|
this.addOutputProducts();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -249,4 +240,16 @@ public class TileMatterFabricator extends TileMachineBase implements IWrenchable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getValue(ItemStack itemStack) {
|
||||||
|
int value = getValue(Recipes.matterAmplifier.getOutputFor(itemStack, false));
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Integer getValue(RecipeOutput output) {
|
||||||
|
if (output != null && output.metadata != null) {
|
||||||
|
return output.metadata.getInteger("amplification");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue