Made the Blood Altar check if it had a null recipe on update while active. (Actual change on line 271)

Potential fix for #1275.
This commit is contained in:
WayofTime 2018-04-20 16:11:05 -04:00
parent 60c8441115
commit c9319477bd
2 changed files with 178 additions and 86 deletions

View file

@ -10,6 +10,7 @@ Version 2.2.9
- Side note: who's bright idea was it to have to wait 15 minutes per crystal growth?
- Added the "Resonance of the Faceted Crystal", which can be used to create your first aspected Will crystal clusters.
- Made it so the Crystallizer no longer generates a random aspected Will crystal cluster.
- Fixed rare crash with the Blood Altar, which only has a chance of occuring on restart.
------------------------------------------------------
Version 2.2.8

View file

@ -30,7 +30,8 @@ import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
import net.minecraftforge.items.ItemHandlerHelper;
public class BloodAltar implements IFluidHandler {
public class BloodAltar implements IFluidHandler
{
public boolean isActive;
protected FluidStack fluidOutput = new FluidStack(BlockLifeEssence.getLifeEssence(), 0);
@ -67,12 +68,15 @@ public class BloodAltar implements IFluidHandler {
private RecipeBloodAltar recipe;
private AltarTier currentTierDisplayed = AltarTier.ONE;
public BloodAltar(TileAltar tileAltar) {
public BloodAltar(TileAltar tileAltar)
{
this.tileAltar = tileAltar;
}
public void readFromNBT(NBTTagCompound tagCompound) {
if (!tagCompound.hasKey(Constants.NBT.EMPTY)) {
public void readFromNBT(NBTTagCompound tagCompound)
{
if (!tagCompound.hasKey(Constants.NBT.EMPTY))
{
FluidStack fluid = FluidStack.loadFluidStackFromNBT(tagCompound);
if (fluid != null)
@ -115,7 +119,8 @@ public class BloodAltar implements IFluidHandler {
currentTierDisplayed = Enums.getIfPresent(AltarTier.class, tagCompound.getString(Constants.NBT.ALTAR_CURRENT_TIER_DISPLAYED)).or(AltarTier.ONE);
}
public void writeToNBT(NBTTagCompound tagCompound) {
public void writeToNBT(NBTTagCompound tagCompound)
{
if (fluid != null)
fluid.writeToNBT(tagCompound);
@ -158,7 +163,8 @@ public class BloodAltar implements IFluidHandler {
tagCompound.setString(Constants.NBT.ALTAR_CURRENT_TIER_DISPLAYED, currentTierDisplayed.name());
}
public void startCycle() {
public void startCycle()
{
if (tileAltar.getWorld() != null)
tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3);
@ -172,11 +178,14 @@ public class BloodAltar implements IFluidHandler {
ItemStack input = tileAltar.getStackInSlot(0);
if (!input.isEmpty()) {
if (!input.isEmpty())
{
// Do recipes
RecipeBloodAltar recipe = BloodMagicAPI.INSTANCE.getRecipeRegistrar().getBloodAltar(input);
if (recipe != null) {
if (recipe.getMinimumTier().ordinal() <= altarTier.ordinal()) {
if (recipe != null)
{
if (recipe.getMinimumTier().ordinal() <= altarTier.ordinal())
{
this.isActive = true;
this.recipe = recipe;
this.liquidRequired = recipe.getSyphon();
@ -185,7 +194,8 @@ public class BloodAltar implements IFluidHandler {
this.canBeFilled = false;
return;
}
} else if (input.getItem() instanceof IBloodOrb) {
} else if (input.getItem() instanceof IBloodOrb)
{
this.isActive = true;
this.canBeFilled = true;
return;
@ -195,7 +205,8 @@ public class BloodAltar implements IFluidHandler {
isActive = false;
}
public void update() {
public void update()
{
World world = tileAltar.getWorld();
BlockPos pos = tileAltar.getPos();
@ -208,14 +219,17 @@ public class BloodAltar implements IFluidHandler {
if (lockdownDuration > 0)
lockdownDuration--;
if (internalCounter % 20 == 0) {
for (EnumFacing facing : EnumFacing.VALUES) {
if (internalCounter % 20 == 0)
{
for (EnumFacing facing : EnumFacing.VALUES)
{
BlockPos newPos = pos.offset(facing);
IBlockState block = world.getBlockState(newPos);
block.getBlock().onNeighborChange(world, newPos, pos);
}
}
if (internalCounter % (Math.max(20 - this.accelerationUpgrades, 1)) == 0) {
if (internalCounter % (Math.max(20 - this.accelerationUpgrades, 1)) == 0)
{
int syphonMax = (int) (20 * this.dislocationMultiplier);
int fluidInputted;
int fluidOutputted;
@ -230,7 +244,8 @@ public class BloodAltar implements IFluidHandler {
tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3);
}
if (internalCounter % this.getChargingFrequency() == 0 && !this.isActive) {
if (internalCounter % this.getChargingFrequency() == 0 && !this.isActive)
{
int chargeInputted = Math.min(chargingRate, this.fluid.amount);
chargeInputted = Math.min(chargeInputted, maxCharge - totalCharge);
totalCharge += chargeInputted;
@ -244,13 +259,21 @@ public class BloodAltar implements IFluidHandler {
updateAltar();
}
private void updateAltar() {
if (!isActive) {
private void updateAltar()
{
if (!isActive)
{
if (cooldownAfterCrafting > 0)
cooldownAfterCrafting--;
return;
}
if (recipe == null)
{
startCycle();
return;
}
ItemStack input = tileAltar.getStackInSlot(0);
if (input.isEmpty())
@ -262,11 +285,13 @@ public class BloodAltar implements IFluidHandler {
if (world.isRemote)
return;
if (!canBeFilled) {
if (!canBeFilled)
{
boolean hasOperated = false;
int stackSize = input.getCount();
if (totalCharge > 0) {
if (totalCharge > 0)
{
int chargeDrained = Math.min(liquidRequired * stackSize - progress, totalCharge);
totalCharge -= chargeDrained;
@ -274,7 +299,8 @@ public class BloodAltar implements IFluidHandler {
hasOperated = true;
}
if (fluid != null && fluid.amount >= 1) {
if (fluid != null && fluid.amount >= 1)
{
int liquidDrained = Math.min((int) (altarTier.ordinal() >= 2 ? consumptionRate * (1 + consumptionMultiplier) : consumptionRate), fluid.amount);
if (liquidDrained > (liquidRequired * stackSize - progress))
@ -285,22 +311,27 @@ public class BloodAltar implements IFluidHandler {
hasOperated = true;
if (internalCounter % 4 == 0 && world instanceof WorldServer) {
if (internalCounter % 4 == 0 && world instanceof WorldServer)
{
WorldServer server = (WorldServer) world;
server.spawnParticle(EnumParticleTypes.REDSTONE, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 1, 0.2, 0, 0.2, 0);
}
} else if (!hasOperated && progress > 0) {
} else if (!hasOperated && progress > 0)
{
progress -= (int) (efficiencyMultiplier * drainRate);
if (internalCounter % 2 == 0 && world instanceof WorldServer) {
if (internalCounter % 2 == 0 && world instanceof WorldServer)
{
WorldServer server = (WorldServer) world;
server.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 1, 0.1, 0, 0.1, 0);
}
}
if (hasOperated) {
if (progress >= liquidRequired * stackSize) {
if (hasOperated)
{
if (progress >= liquidRequired * stackSize)
{
ItemStack result = ItemHandlerHelper.copyStackWithSize(recipe.getOutput(), stackSize);
BloodMagicCraftedEvent.Altar event = new BloodMagicCraftedEvent.Altar(result, input.copy());
@ -308,7 +339,8 @@ public class BloodAltar implements IFluidHandler {
tileAltar.setInventorySlotContents(0, event.getOutput());
progress = 0;
if (world instanceof WorldServer) {
if (world instanceof WorldServer)
{
WorldServer server = (WorldServer) world;
server.spawnParticle(EnumParticleTypes.REDSTONE, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 40, 0.3, 0, 0.3, 0);
}
@ -317,7 +349,8 @@ public class BloodAltar implements IFluidHandler {
this.isActive = false;
}
}
} else {
} else
{
ItemStack contained = tileAltar.getStackInSlot(0);
if (contained.isEmpty() || !(contained.getItem() instanceof IBloodOrb) || !(contained.getItem() instanceof IBindable))
@ -329,13 +362,15 @@ public class BloodAltar implements IFluidHandler {
if (binding == null || orb == null)
return;
if (fluid != null && fluid.amount >= 1) {
if (fluid != null && fluid.amount >= 1)
{
int liquidDrained = Math.min((int) (altarTier.ordinal() >= 2 ? orb.getFillRate() * (1 + consumptionMultiplier) : orb.getFillRate()), fluid.amount);
int drain = NetworkHelper.getSoulNetwork(binding).add(liquidDrained, (int) (orb.getCapacity() * this.orbCapacityMultiplier));
fluid.amount = fluid.amount - drain;
if (drain > 0 && internalCounter % 4 == 0 && world instanceof WorldServer) {
if (drain > 0 && internalCounter % 4 == 0 && world instanceof WorldServer)
{
WorldServer server = (WorldServer) world;
server.spawnParticle(EnumParticleTypes.SPELL_WITCH, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 1, 0, 0, 0, 0.001);
}
@ -345,7 +380,8 @@ public class BloodAltar implements IFluidHandler {
tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3);
}
public void checkTier() {
public void checkTier()
{
AltarTier tier = AltarUtil.getTier(tileAltar.getWorld(), tileAltar.getPos());
this.altarTier = tier;
@ -354,7 +390,8 @@ public class BloodAltar implements IFluidHandler {
if (tier.equals(currentTierDisplayed))
currentTierDisplayed = AltarTier.ONE;
if (tier.equals(AltarTier.ONE)) {
if (tier.equals(AltarTier.ONE))
{
upgrade = null;
isUpgraded = false;
this.consumptionMultiplier = 0;
@ -370,7 +407,8 @@ public class BloodAltar implements IFluidHandler {
this.maxCharge = 0;
this.totalCharge = 0;
return;
} else if (!tier.equals(AltarTier.ONE)) {
} else if (!tier.equals(AltarTier.ONE))
{
this.isUpgraded = true;
this.accelerationUpgrades = upgrade.getLevel(BloodRuneType.ACCELERATION);
this.consumptionMultiplier = (float) (0.20 * upgrade.getLevel(BloodRuneType.SPEED));
@ -400,103 +438,128 @@ public class BloodAltar implements IFluidHandler {
tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3);
}
public int fillMainTank(int amount) {
public int fillMainTank(int amount)
{
int filledAmount = Math.min(capacity - fluid.amount, amount);
fluid.amount += filledAmount;
return filledAmount;
}
public void sacrificialDaggerCall(int amount, boolean isSacrifice) {
if (this.lockdownDuration > 0) {
public void sacrificialDaggerCall(int amount, boolean isSacrifice)
{
if (this.lockdownDuration > 0)
{
int amt = (int) Math.min(bufferCapacity - fluidInput.amount, (isSacrifice ? 1 + sacrificeEfficiencyMultiplier : 1 + selfSacrificeEfficiencyMultiplier) * amount);
fluidInput.amount += amt;
} else {
} else
{
fluid.amount += Math.min(capacity - fluid.amount, (isSacrifice ? 1 + sacrificeEfficiencyMultiplier : 1 + selfSacrificeEfficiencyMultiplier) * amount);
}
}
public void setMainFluid(FluidStack fluid) {
public void setMainFluid(FluidStack fluid)
{
this.fluid = fluid;
}
public void setOutputFluid(FluidStack fluid) {
public void setOutputFluid(FluidStack fluid)
{
this.fluidOutput = fluid;
}
public void setInputFluid(FluidStack fluid) {
public void setInputFluid(FluidStack fluid)
{
this.fluidInput = fluid;
}
public AltarUpgrade getUpgrade() {
public AltarUpgrade getUpgrade()
{
return upgrade;
}
public void setUpgrade(AltarUpgrade upgrade) {
public void setUpgrade(AltarUpgrade upgrade)
{
this.upgrade = upgrade;
}
public int getCapacity() {
public int getCapacity()
{
return capacity;
}
public FluidStack getFluid() {
public FluidStack getFluid()
{
return fluid;
}
public int getFluidAmount() {
public int getFluidAmount()
{
return fluid.amount;
}
public int getCurrentBlood() {
public int getCurrentBlood()
{
return getFluidAmount();
}
public AltarTier getTier() {
public AltarTier getTier()
{
return altarTier;
}
public void setTier(AltarTier tier) {
public void setTier(AltarTier tier)
{
this.altarTier = tier;
}
public int getProgress() {
public int getProgress()
{
return progress;
}
public float getSacrificeMultiplier() {
public float getSacrificeMultiplier()
{
return sacrificeEfficiencyMultiplier;
}
public float getSelfSacrificeMultiplier() {
public float getSelfSacrificeMultiplier()
{
return selfSacrificeEfficiencyMultiplier;
}
public float getOrbMultiplier() {
public float getOrbMultiplier()
{
return orbCapacityMultiplier;
}
public float getDislocationMultiplier() {
public float getDislocationMultiplier()
{
return dislocationMultiplier;
}
public float getConsumptionMultiplier() {
public float getConsumptionMultiplier()
{
return consumptionMultiplier;
}
public float getConsumptionRate() {
public float getConsumptionRate()
{
return consumptionRate;
}
public int getLiquidRequired() {
public int getLiquidRequired()
{
return liquidRequired;
}
public int getBufferCapacity() {
public int getBufferCapacity()
{
return bufferCapacity;
}
public boolean setCurrentTierDisplayed(AltarTier altarTier) {
public boolean setCurrentTierDisplayed(AltarTier altarTier)
{
if (currentTierDisplayed == altarTier)
return false;
else
@ -504,79 +567,99 @@ public class BloodAltar implements IFluidHandler {
return true;
}
public void addToDemonBloodDuration(int dur) {
public void addToDemonBloodDuration(int dur)
{
this.demonBloodDuration += dur;
}
public boolean hasDemonBlood() {
public boolean hasDemonBlood()
{
return this.demonBloodDuration > 0;
}
public void decrementDemonBlood() {
public void decrementDemonBlood()
{
this.demonBloodDuration = Math.max(0, this.demonBloodDuration - 1);
}
public void setActive() {
if (tileAltar.getStackInSlot(0).isEmpty()) {
public void setActive()
{
if (tileAltar.getStackInSlot(0).isEmpty())
{
isActive = false;
}
}
public boolean isActive() {
public boolean isActive()
{
return isActive;
}
public void requestPauseAfterCrafting(int amount) {
if (this.isActive) {
public void requestPauseAfterCrafting(int amount)
{
if (this.isActive)
{
this.cooldownAfterCrafting = amount;
}
}
public int getChargingRate() {
public int getChargingRate()
{
return chargingRate;
}
public int getTotalCharge() {
public int getTotalCharge()
{
return totalCharge;
}
public int getChargingFrequency() {
public int getChargingFrequency()
{
return chargingFrequency == 0 ? 1 : chargingFrequency;
}
@Override
public int fill(FluidStack resource, boolean doFill) {
if (resource == null || resource.getFluid() != BlockLifeEssence.getLifeEssence()) {
public int fill(FluidStack resource, boolean doFill)
{
if (resource == null || resource.getFluid() != BlockLifeEssence.getLifeEssence())
{
return 0;
}
if (!doFill) {
if (fluidInput == null) {
if (!doFill)
{
if (fluidInput == null)
{
return Math.min(bufferCapacity, resource.amount);
}
if (!fluidInput.isFluidEqual(resource)) {
if (!fluidInput.isFluidEqual(resource))
{
return 0;
}
return Math.min(bufferCapacity - fluidInput.amount, resource.amount);
}
if (fluidInput == null) {
if (fluidInput == null)
{
fluidInput = new FluidStack(resource, Math.min(bufferCapacity, resource.amount));
return fluidInput.amount;
}
if (!fluidInput.isFluidEqual(resource)) {
if (!fluidInput.isFluidEqual(resource))
{
return 0;
}
int filled = bufferCapacity - fluidInput.amount;
if (resource.amount < filled) {
if (resource.amount < filled)
{
fluidInput.amount += resource.amount;
filled = resource.amount;
} else {
} else
{
fluidInput.amount = bufferCapacity;
}
@ -584,37 +667,45 @@ public class BloodAltar implements IFluidHandler {
}
@Override
public FluidStack drain(FluidStack resource, boolean doDrain) {
if (resource == null || !resource.isFluidEqual(fluidOutput)) {
public FluidStack drain(FluidStack resource, boolean doDrain)
{
if (resource == null || !resource.isFluidEqual(fluidOutput))
{
return null;
}
return drain(resource.amount, doDrain);
}
@Override
public FluidStack drain(int maxDrain, boolean doDrain) {
if (fluidOutput == null) {
public FluidStack drain(int maxDrain, boolean doDrain)
{
if (fluidOutput == null)
{
return null;
}
int drained = maxDrain;
if (fluidOutput.amount < drained) {
if (fluidOutput.amount < drained)
{
drained = fluidOutput.amount;
}
FluidStack stack = new FluidStack(fluidOutput, drained);
if (doDrain) {
if (doDrain)
{
fluidOutput.amount -= drained;
}
return stack;
}
@Override
public IFluidTankProperties[] getTankProperties() {
return new IFluidTankProperties[]{new FluidTankPropertiesWrapper(new FluidTank(fluid, capacity))};
public IFluidTankProperties[] getTankProperties()
{
return new IFluidTankProperties[] { new FluidTankPropertiesWrapper(new FluidTank(fluid, capacity)) };
}
public AltarTier getCurrentTierDisplayed() {
public AltarTier getCurrentTierDisplayed()
{
return currentTierDisplayed;
}
}