This commit is contained in:
tterrag1098 committed 2015-07-11 16:00:47 -04:00
commit 8420d79140
3 files changed
+68 -10

No files matched your search

@@ -18,6 +18,7 @@ public abstract class AbstractPoweredTaskEntity extends AbstractPowerConsumerEnt
protected IPoweredTask currentTask = null;
protected IMachineRecipe lastCompletedRecipe;
protected IMachineRecipe cachedNextRecipe;
protected final Random random = new Random();
@@ -205,6 +206,8 @@ public abstract class AbstractPoweredTaskEntity extends AbstractPowerConsumerEnt
listIndex++;
}
}
cachedNextRecipe = null;
}
protected void mergeFluidResult(ResultStack result) {
@@ -257,8 +260,15 @@ public abstract class AbstractPoweredTaskEntity extends AbstractPowerConsumerEnt
return res;
}
protected IMachineRecipe getNextRecipe() {
if (cachedNextRecipe == null) {
cachedNextRecipe = MachineRecipeRegistry.instance.getRecipeForInputs(getMachineName(), getRecipeInputs());
}
return cachedNextRecipe;
}
protected IMachineRecipe canStartNextTask(float chance) {
IMachineRecipe nextRecipe = MachineRecipeRegistry.instance.getRecipeForInputs(getMachineName(), getRecipeInputs());
IMachineRecipe nextRecipe = getNextRecipe();
if(nextRecipe == null) {
return null; // no template
}
@@ -367,4 +377,27 @@ public abstract class AbstractPoweredTaskEntity extends AbstractPowerConsumerEnt
}
}
@Override
public void readCommon(NBTTagCompound nbtRoot) {
super.readCommon(nbtRoot);
cachedNextRecipe = null;
}
@Override
public ItemStack decrStackSize(int fromSlot, int amount) {
ItemStack res = super.decrStackSize(fromSlot, amount);
if(slotDefinition.isInputSlot(fromSlot)) {
cachedNextRecipe = null;
}
return res;
}
@Override
public void setInventorySlotContents(int slot, ItemStack contents) {
super.setInventorySlotContents(slot, contents);
if(slotDefinition.isInputSlot(slot)) {
cachedNextRecipe = null;
}
}
}
@@ -71,7 +71,7 @@ public class TileAlloySmelter extends AbstractPoweredTaskEntity {
return null;
}
IMachineRecipe nextRecipe = MachineRecipeRegistry.instance.getRecipeForInputs(getMachineName(), getRecipeInputs());
IMachineRecipe nextRecipe = getNextRecipe();
if(mode == Mode.ALLOY && nextRecipe instanceof VanillaSmeltingRecipe) {
nextRecipe = null;
}
@@ -44,7 +44,7 @@ public class TileSoulBinder extends AbstractPoweredTaskEntity implements IHaveEx
Capacitors.ENDER_CAPACITOR.capacitor.getMaxEnergyStored(), POWER_PER_TICK_THREE);
private final ExperienceContainer xpCont = new ExperienceContainer(XpUtil.getExperienceForLevel(Config.soulBinderMaxXpLevel));
public TileSoulBinder() {
super(new SlotDefinition(2, 2, 1));
}
@@ -87,21 +87,29 @@ public class TileSoulBinder extends AbstractPoweredTaskEntity implements IHaveEx
}
public boolean needsXP() {
return getXPRequired() > 0;
}
/**
* Computes the required amount of XP to start the current recipe.
* @return 0 if no XP is required, negative when more than required XP is stored.
*/
private int getXPRequired() {
if(currentTask != null) {
return false;
return 0;
}
IMachineRecipe nextRecipe = MachineRecipeRegistry.instance.getRecipeForInputs(getMachineName(), getRecipeInputs());
IMachineRecipe nextRecipe = getNextRecipe();
if(! (nextRecipe instanceof ISoulBinderRecipe)) {
return false;
return 0;
}
return ((ISoulBinderRecipe)nextRecipe).getExperienceRequired() > getContainer().getExperienceTotal();
return ((ISoulBinderRecipe)nextRecipe).getExperienceRequired() - getContainer().getExperienceTotal();
}
public int getCurrentlyRequiredLevel() {
if(currentTask != null) {
return -1;
}
IMachineRecipe nextRecipe = MachineRecipeRegistry.instance.getRecipeForInputs(getMachineName(), getRecipeInputs());
IMachineRecipe nextRecipe = getNextRecipe();
if(! (nextRecipe instanceof ISoulBinderRecipe)) {
return -1;
}
@@ -167,14 +175,31 @@ public class TileSoulBinder extends AbstractPoweredTaskEntity implements IHaveEx
@Override
protected boolean doPull(ForgeDirection dir) {
boolean res = super.doPull(dir);
FluidUtil.doPull(this, dir, Config.fluidConduitExtractRate);
int req = getXPRequired();
if(req > 0) {
FluidUtil.doPull(this, dir, Math.min(XpUtil.experienceToLiquid(req), Config.fluidConduitExtractRate));
}
return res;
}
@Override
protected boolean doPush(ForgeDirection dir) {
boolean res = super.doPush(dir);
FluidUtil.doPush(this, dir, Config.fluidConduitExtractRate);
int maxAmount = Config.fluidConduitExtractRate;
if (currentTask == null) {
IMachineRecipe nextRecipe = getNextRecipe();
if (nextRecipe instanceof ISoulBinderRecipe) {
int excess = getContainer().getExperienceTotal() - ((ISoulBinderRecipe)nextRecipe).getExperienceRequired();
if (excess > 0) {
maxAmount = Math.min(XpUtil.experienceToLiquid(excess), Config.fluidConduitExtractRate);
} else {
maxAmount = 0;
}
}
}
if(maxAmount > 0) {
FluidUtil.doPush(this, dir, maxAmount);
}
return res;
}