Some work no the mass fab

This commit is contained in:
modmuss50 2015-06-22 11:32:30 +01:00
parent a7209f7e79
commit e660463bae

View file

@ -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.Recipes;
import ic2.api.tile.IWrenchable; import ic2.api.tile.IWrenchable;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
@ -11,90 +12,86 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import techreborn.config.ConfigTechReborn; import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks; import techreborn.init.ModBlocks;
import techreborn.init.ModItems;
import techreborn.util.Inventory; 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 class TileMatterFabricator extends TileMachineBase implements IWrenchable, IEnergyTile, IInventory, ISidedInventory {
public static int sMatterFabricationRate = 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 mProgresstime = 0;
public TileMatterFabricator() { public TileMatterFabricator() {
//TODO configs //TODO configs
energy = new BasicSink(this, 1000, energy = new BasicSink(this, 100000,
ConfigTechReborn.CentrifugeTier); ConfigTechReborn.CentrifugeTier);
} }
@Override @Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
{
return false; return false;
} }
@Override @Override
public short getFacing() public short getFacing() {
{
return 0; return 0;
} }
@Override @Override
public void setFacing(short facing) public void setFacing(short facing) {
{
} }
@Override @Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
{ if (entityPlayer.isSneaking()) {
if (entityPlayer.isSneaking())
{
return true; return true;
} }
return false; return false;
} }
@Override @Override
public float getWrenchDropRate() public float getWrenchDropRate() {
{
return 1.0F; return 1.0F;
} }
@Override @Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
{
return new ItemStack(ModBlocks.MatterFabricator, 1); return new ItemStack(ModBlocks.MatterFabricator, 1);
} }
public boolean isComplete() public boolean isComplete() {
{
return false; return false;
} }
@Override @Override
public void readFromNBT(NBTTagCompound tagCompound) public void readFromNBT(NBTTagCompound tagCompound) {
{
super.readFromNBT(tagCompound); super.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound); inventory.readFromNBT(tagCompound);
energy.readFromNBT(tagCompound); energy.readFromNBT(tagCompound);
} }
@Override @Override
public void writeToNBT(NBTTagCompound tagCompound) public void writeToNBT(NBTTagCompound tagCompound) {
{
super.writeToNBT(tagCompound); super.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound); inventory.writeToNBT(tagCompound);
energy.writeToNBT(tagCompound); energy.writeToNBT(tagCompound);
} }
@Override @Override
public void invalidate() public void invalidate() {
{
energy.invalidate(); energy.invalidate();
super.invalidate(); super.invalidate();
} }
@Override @Override
public void onChunkUnload() public void onChunkUnload() {
{
energy.onChunkUnload(); energy.onChunkUnload();
super.onChunkUnload(); super.onChunkUnload();
} }
@ -161,23 +158,95 @@ public class TileMatterFabricator extends TileMachineBase implements IWrenchable
// ISidedInventory // ISidedInventory
@Override @Override
public int[] getAccessibleSlotsFromSide(int side) public int[] getAccessibleSlotsFromSide(int side) {
{
return side == ForgeDirection.DOWN.ordinal() ? new int[]{0, 1, 2, 3, 4, 5, 6} : new int[]{0, 1, 2, 3, 4, 5, 6}; return side == ForgeDirection.DOWN.ordinal() ? new int[]{0, 1, 2, 3, 4, 5, 6} : new int[]{0, 1, 2, 3, 4, 5, 6};
} }
@Override @Override
public boolean canInsertItem(int slotIndex, ItemStack itemStack, int side) public boolean canInsertItem(int slotIndex, ItemStack itemStack, int side) {
{
if (slotIndex == 6) if (slotIndex == 6)
return false; return false;
return isItemValidForSlot(slotIndex, itemStack); return isItemValidForSlot(slotIndex, itemStack);
} }
@Override @Override
public boolean canExtractItem(int slotIndex, ItemStack itemStack, int side) public boolean canExtractItem(int slotIndex, ItemStack itemStack, int side) {
{
return slotIndex == 6; return slotIndex == 6;
} }
public int maxProgresstime() {
return sMatterFabricationRate;
}
@Override
public void updateEntity() {
super.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);
}
}
}
}
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();
}
}
}
}
private boolean spaceForOutput() {
return inventory.getStackInSlot(6) == null || ItemUtils.isItemEqual(inventory.getStackInSlot(6), new ItemStack(ModItems.uuMatter), true, true) && inventory.getStackInSlot(6).stackSize < 64;
}
private void addOutputProducts() {
if (inventory.getStackInSlot(6) == null) {
inventory.setInventorySlotContents(6, new ItemStack(ModItems.uuMatter));
} else if (ItemUtils.isItemEqual(inventory.getStackInSlot(6), new ItemStack(ModItems.uuMatter), true, true)) {
inventory.getStackInSlot(6).stackSize = Math.min(64, 1 + inventory.getStackInSlot(6).stackSize);
}
}
public boolean decreaseStoredEnergy(double aEnergy, boolean aIgnoreTooLessEnergy) {
if (energy.getEnergyStored() - aEnergy < 0 && !aIgnoreTooLessEnergy) {
return false;
} else {
energy.setEnergyStored(energy.getEnergyStored() - aEnergy);
if (energy.getEnergyStored() < 0) {
energy.setEnergyStored(0);
return false;
} else {
return true;
}
}
}
} }