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;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import techreborn.client.SlotOutput;
|
||||
import techreborn.tiles.TileMatterFabricator;
|
||||
|
@ -11,7 +14,7 @@ public class ContainerMatterFabricator extends TechRebornContainer{
|
|||
|
||||
TileMatterFabricator tile;
|
||||
|
||||
public int tickTime;
|
||||
public int progressTime;
|
||||
|
||||
public ContainerMatterFabricator(TileMatterFabricator tileMatterfab,
|
||||
EntityPlayer player)
|
||||
|
@ -55,4 +58,36 @@ public class ContainerMatterFabricator extends TechRebornContainer{
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ public class GuiMatterFabricator extends GuiContainer{
|
|||
"techreborn", "textures/gui/matterfabricator.png");
|
||||
|
||||
TileMatterFabricator matterfab;
|
||||
|
||||
ContainerMatterFabricator containerMatterFabricator;
|
||||
|
||||
public GuiMatterFabricator(EntityPlayer player, TileMatterFabricator tilematterfab)
|
||||
{
|
||||
|
@ -21,7 +23,7 @@ public class GuiMatterFabricator extends GuiContainer{
|
|||
this.xSize = 176;
|
||||
this.ySize = 167;
|
||||
matterfab = tilematterfab;
|
||||
|
||||
containerMatterFabricator = (ContainerMatterFabricator) this.inventorySlots;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,6 +34,11 @@ public class GuiMatterFabricator extends GuiContainer{
|
|||
int k = (this.width - this.xSize) / 2;
|
||||
int l = (this.height - this.ySize) / 2;
|
||||
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_,
|
||||
|
|
|
@ -2,6 +2,7 @@ package techreborn.tiles;
|
|||
|
||||
import ic2.api.energy.prefab.BasicSink;
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
import ic2.api.recipe.RecipeOutput;
|
||||
import ic2.api.recipe.Recipes;
|
||||
import ic2.api.tile.IWrenchable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -10,28 +11,23 @@ import net.minecraft.inventory.ISidedInventory;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.init.ModBlocks;
|
||||
import techreborn.init.ModItems;
|
||||
import techreborn.util.Inventory;
|
||||
import techreborn.util.ItemUtils;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class TileMatterFabricator extends TileMachineBase implements IWrenchable, IEnergyTile, IInventory, ISidedInventory {
|
||||
|
||||
public static int sMatterFabricationRate = 166666;
|
||||
public static int fabricationRate = 166666;
|
||||
public int tickTime;
|
||||
public BasicSink energy;
|
||||
public Inventory inventory = new Inventory(7, "TileMatterFabricator", 64);
|
||||
private int mAmplifier = 0;
|
||||
private int mProgresstime = 0;
|
||||
private int amplifier = 0;
|
||||
public int progresstime = 0;
|
||||
|
||||
public TileMatterFabricator() {
|
||||
//TODO configs
|
||||
energy = new BasicSink(this, 100000,
|
||||
ConfigTechReborn.CentrifugeTier);
|
||||
energy = new BasicSink(this, 10000000, 6);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -175,48 +171,43 @@ public class TileMatterFabricator extends TileMachineBase implements IWrenchable
|
|||
}
|
||||
|
||||
public int maxProgresstime() {
|
||||
return sMatterFabricationRate;
|
||||
return fabricationRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
energy.updateEntity();
|
||||
|
||||
if (!super.worldObj.isRemote) {
|
||||
|
||||
if (this.energy.getEnergyStored() > 0 && !super.worldObj.isBlockIndirectlyGettingPowered(super.xCoord, super.yCoord, super.zCoord)) {
|
||||
Iterator tIterator = Recipes.matterAmplifier.getRecipes().entrySet().iterator();
|
||||
|
||||
while (this.mAmplifier < 100000 && tIterator.hasNext()) {
|
||||
Entry tEntry = (Entry) tIterator.next();
|
||||
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);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ItemStack stack = inventory.getStackInSlot(i);
|
||||
if (this.amplifier < 100000 && stack != null) {
|
||||
int amp = (int) ((long) (getValue(stack) * (long) this.maxProgresstime() / 166666L));
|
||||
if (ItemUtils.isItemEqual(stack, inventory.getStackInSlot(i), true, true)) {
|
||||
this.amplifier += amp;
|
||||
inventory.decrStackSize(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.mAmplifier > 0) {
|
||||
if (this.mAmplifier > this.energy.getEnergyStored()) {
|
||||
this.mProgresstime += this.energy.getEnergyStored();
|
||||
this.mAmplifier -= this.energy.getEnergyStored();
|
||||
this.decreaseStoredEnergy(this.energy.getEnergyStored(), true);
|
||||
} else {
|
||||
this.mProgresstime += this.mAmplifier;
|
||||
this.decreaseStoredEnergy(this.mAmplifier, true);
|
||||
this.mAmplifier = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.mProgresstime > this.maxProgresstime() && this.spaceForOutput()) {
|
||||
this.mProgresstime -= this.maxProgresstime();
|
||||
this.addOutputProducts();
|
||||
}
|
||||
}
|
||||
|
||||
if (this.amplifier > 0) {
|
||||
if (this.amplifier > this.energy.getEnergyStored()) {
|
||||
this.progresstime += this.energy.getEnergyStored();
|
||||
this.amplifier -= this.energy.getEnergyStored();
|
||||
this.decreaseStoredEnergy(this.energy.getEnergyStored(), true);
|
||||
} else {
|
||||
this.progresstime += this.amplifier;
|
||||
this.decreaseStoredEnergy(this.amplifier, true);
|
||||
this.amplifier = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.progresstime > this.maxProgresstime() && this.spaceForOutput()) {
|
||||
this.progresstime -= this.maxProgresstime();
|
||||
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
Reference in a new issue