mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
assemfac functionality
This commit is contained in:
parent
aa385f2a21
commit
c28d268a57
@ -1,8 +1,16 @@
|
||||
package com.hbm.tileentity.machine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.inventory.RecipesCommon.AStack;
|
||||
import com.hbm.inventory.recipes.AssemblerRecipes;
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.lib.Library;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
import com.hbm.util.InventoryUtil;
|
||||
|
||||
import api.hbm.energy.IEnergyUser;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
|
||||
public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBase implements IEnergyUser {
|
||||
@ -11,6 +19,9 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
public int[] progress;
|
||||
public int[] maxProgress;
|
||||
public boolean isProgressing;
|
||||
|
||||
int consumption = 100;
|
||||
int speed = 100;
|
||||
|
||||
public TileEntityMachineAssemblerBase(int scount) {
|
||||
super(scount);
|
||||
@ -21,6 +32,115 @@ public abstract class TileEntityMachineAssemblerBase extends TileEntityMachineBa
|
||||
maxProgress = new int[count];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
int count = this.getRecipeCount();
|
||||
|
||||
this.isProgressing = false;
|
||||
this.power = Library.chargeTEFromItems(slots, 0, power, this.getMaxPower());
|
||||
|
||||
for(int i = 0; i < count; i++) {
|
||||
//loadItems(i);
|
||||
//unloadItems(i);
|
||||
}
|
||||
|
||||
if(worldObj.getTotalWorldTime() % 10 == 0) {
|
||||
|
||||
/*for(FluidTank tank : this.outTanks()) {
|
||||
if(tank.getTankType() != Fluids.NONE && tank.getFill() > 0) {
|
||||
this.fillFluidInit(tank.getTankType());
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
for(int i = 0; i < count; i++) {
|
||||
if(!canProcess(i)) {
|
||||
this.progress[i] = 0;
|
||||
} else {
|
||||
isProgressing = true;
|
||||
process(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean canProcess(int index) {
|
||||
|
||||
int template = getTemplateIndex(index);
|
||||
|
||||
if(slots[template] == null || slots[template].getItem() != ModItems.assembly_template)
|
||||
return false;
|
||||
|
||||
List<AStack> recipe = AssemblerRecipes.getRecipeFromTempate(slots[template]);
|
||||
ItemStack output = AssemblerRecipes.getOutputFromTempate(slots[template]);
|
||||
|
||||
if(recipe == null)
|
||||
return false;
|
||||
|
||||
if(this.power < this.consumption) return false;
|
||||
if(!hasRequiredItems(recipe, index)) return false;
|
||||
if(!hasSpaceForItems(output, index)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean hasRequiredItems(List<AStack> recipe, int index) {
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
return InventoryUtil.doesArrayHaveIngredients(slots, indices[0], indices[1], recipe.toArray(new AStack[0]));
|
||||
}
|
||||
|
||||
private boolean hasSpaceForItems(ItemStack recipe, int index) {
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
return InventoryUtil.doesArrayHaveSpace(slots, indices[2], indices[2], new ItemStack[] { recipe });
|
||||
}
|
||||
|
||||
protected void process(int index) {
|
||||
|
||||
this.power -= this.consumption;
|
||||
this.progress[index]++;
|
||||
|
||||
if(slots[0] != null && slots[0].getItem() == ModItems.meteorite_sword_alloyed)
|
||||
slots[0] = new ItemStack(ModItems.meteorite_sword_machined); //fisfndmoivndlmgindgifgjfdnblfm
|
||||
|
||||
int template = getTemplateIndex(index);
|
||||
|
||||
List<AStack> recipe = AssemblerRecipes.getRecipeFromTempate(slots[template]);
|
||||
ItemStack output = AssemblerRecipes.getOutputFromTempate(slots[template]);
|
||||
int time = AssemblerRecipes.time.get(output);
|
||||
|
||||
this.maxProgress[index] = time * this.speed / 100;
|
||||
|
||||
if(this.progress[index] >= this.maxProgress[index]) {
|
||||
consumeItems(recipe, index);
|
||||
produceItems(output, index);
|
||||
this.progress[index] = 0;
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
private void consumeItems(List<AStack> recipe, int index) {
|
||||
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
|
||||
for(AStack in : recipe) {
|
||||
if(in != null)
|
||||
InventoryUtil.tryConsumeAStack(slots, indices[0], indices[1], in);
|
||||
}
|
||||
}
|
||||
|
||||
private void produceItems(ItemStack out, int index) {
|
||||
|
||||
int[] indices = getSlotIndicesFromIndex(index);
|
||||
|
||||
if(out != null) {
|
||||
InventoryUtil.tryAddItemToInventory(slots, indices[2], indices[2], out.copy());
|
||||
}
|
||||
}
|
||||
|
||||
public abstract int getRecipeCount();
|
||||
public abstract int getTemplateIndex(int index);
|
||||
|
||||
|
||||
@ -3,7 +3,6 @@ package com.hbm.tileentity.machine;
|
||||
import java.util.Random;
|
||||
|
||||
import com.hbm.blocks.BlockDummyable;
|
||||
import com.hbm.tileentity.TileEntityMachineBase;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
@ -30,10 +29,16 @@ public class TileEntityMachineAssemfac extends TileEntityMachineAssemblerBase {
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if(worldObj.isRemote) {
|
||||
for(AssemblerArm arm : arms) {
|
||||
arm.updateArm();
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
} else {
|
||||
|
||||
if(isProgressing) {
|
||||
for(AssemblerArm arm : arms) {
|
||||
arm.updateArm();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,6 +197,7 @@ public abstract class TileEntityMachineChemplantBase extends TileEntityMachineBa
|
||||
InventoryUtil.tryAddItemToInventory(slots, indices[2], indices[3], out.copy());
|
||||
}
|
||||
}
|
||||
|
||||
private void loadItems(int index) {
|
||||
|
||||
int template = getTemplateIndex(index);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user