2015-11-02 20:39:44 +00:00
|
|
|
package WayofTime.bloodmagic.tile;
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2015-11-03 02:30:28 +00:00
|
|
|
import WayofTime.bloodmagic.altar.BloodAltar;
|
2015-11-02 20:39:44 +00:00
|
|
|
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
2015-11-03 18:00:40 +00:00
|
|
|
import WayofTime.bloodmagic.api.ItemStackWrapper;
|
2015-11-03 16:09:16 +00:00
|
|
|
import WayofTime.bloodmagic.api.NBTHolder;
|
2015-11-03 02:30:28 +00:00
|
|
|
import WayofTime.bloodmagic.api.altar.AltarRecipe;
|
2015-11-02 20:39:44 +00:00
|
|
|
import WayofTime.bloodmagic.api.altar.AltarUpgrade;
|
2015-11-03 02:30:28 +00:00
|
|
|
import WayofTime.bloodmagic.api.altar.EnumAltarTier;
|
2015-11-03 15:34:11 +00:00
|
|
|
import WayofTime.bloodmagic.api.altar.IBloodAltar;
|
2015-11-03 02:30:28 +00:00
|
|
|
import WayofTime.bloodmagic.api.registry.AltarRecipeRegistry;
|
2015-11-03 15:34:11 +00:00
|
|
|
import WayofTime.bloodmagic.block.BlockLifeEssence;
|
2015-11-03 16:31:34 +00:00
|
|
|
import com.google.common.base.Enums;
|
2015-11-03 15:34:11 +00:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-10-30 03:22:14 +00:00
|
|
|
import net.minecraft.server.gui.IUpdatePlayerListBox;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraftforge.fluids.*;
|
|
|
|
|
2015-11-03 15:34:11 +00:00
|
|
|
public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlayerListBox, IFluidTank, IFluidHandler {
|
2015-11-03 16:09:16 +00:00
|
|
|
|
|
|
|
private EnumAltarTier altarTier = EnumAltarTier.ONE;
|
2015-10-30 03:22:14 +00:00
|
|
|
private AltarUpgrade upgrade = new AltarUpgrade();
|
2015-11-03 16:09:16 +00:00
|
|
|
private int capacity = FluidContainerRegistry.BUCKET_VOLUME * 10;
|
|
|
|
|
2015-11-02 20:39:44 +00:00
|
|
|
private FluidStack fluid = new FluidStack(BloodMagicAPI.getLifeEssence(), 0);
|
2015-11-03 15:34:11 +00:00
|
|
|
protected FluidStack fluidOutput = new FluidStack(BlockLifeEssence.getLifeEssence(), 0);
|
|
|
|
protected FluidStack fluidInput = new FluidStack(BlockLifeEssence.getLifeEssence(), 0);
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2015-11-03 15:34:11 +00:00
|
|
|
private int liquidRequired; //mB
|
|
|
|
private boolean canBeFilled;
|
|
|
|
private int consumptionRate;
|
|
|
|
private int drainRate;
|
|
|
|
private float consumptionMultiplier;
|
|
|
|
private float efficiencyMultiplier;
|
|
|
|
private float sacrificeEfficiencyMultiplier;
|
|
|
|
private float selfSacrificeEfficiencyMultiplier;
|
2015-11-03 16:09:16 +00:00
|
|
|
private float capacityMultiplier = 1;
|
2015-11-03 15:34:11 +00:00
|
|
|
private float orbCapacityMultiplier;
|
|
|
|
private float dislocationMultiplier;
|
|
|
|
private int accelerationUpgrades;
|
|
|
|
private boolean isUpgraded;
|
|
|
|
private boolean isResultBlock;
|
2015-11-03 16:09:16 +00:00
|
|
|
private int bufferCapacity = FluidContainerRegistry.BUCKET_VOLUME;
|
2015-11-03 15:34:11 +00:00
|
|
|
private int progress;
|
|
|
|
|
|
|
|
public boolean isActive;
|
|
|
|
|
|
|
|
private int lockdownDuration;
|
|
|
|
private int demonBloodDuration;
|
|
|
|
|
|
|
|
private int cooldownAfterCrafting = 500;
|
|
|
|
|
|
|
|
public TileAltar() {
|
2015-10-30 03:22:14 +00:00
|
|
|
super(1, "altar");
|
2015-11-03 15:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-03 16:09:16 +00:00
|
|
|
public void readFromNBT(NBTTagCompound tagCompound) {
|
|
|
|
super.readFromNBT(tagCompound);
|
2015-11-03 15:34:11 +00:00
|
|
|
|
2015-11-03 16:09:16 +00:00
|
|
|
if (!tagCompound.hasKey("Empty")) {
|
|
|
|
FluidStack fluid = FluidStack.loadFluidStackFromNBT(tagCompound);
|
2015-11-03 15:34:11 +00:00
|
|
|
|
2015-11-03 16:09:16 +00:00
|
|
|
if (fluid != null)
|
2015-11-03 15:34:11 +00:00
|
|
|
setMainFluid(fluid);
|
|
|
|
|
2015-11-03 16:09:16 +00:00
|
|
|
FluidStack fluidOut = new FluidStack(BloodMagicAPI.getLifeEssence(), tagCompound.getInteger("outputAmount"));
|
|
|
|
setOutputFluid(fluidOut);
|
2015-11-03 15:34:11 +00:00
|
|
|
|
2015-11-03 16:09:16 +00:00
|
|
|
FluidStack fluidIn = new FluidStack(BloodMagicAPI.getLifeEssence(), tagCompound.getInteger("inputAmount"));
|
|
|
|
setInputFluid(fluidIn);
|
2015-11-03 15:34:11 +00:00
|
|
|
}
|
|
|
|
|
2015-11-03 18:00:40 +00:00
|
|
|
altarTier = Enums.getIfPresent(EnumAltarTier.class, tagCompound.getString(NBTHolder.NBT_ALTAR_TIER)).or(EnumAltarTier.ONE);
|
2015-11-03 16:09:16 +00:00
|
|
|
isActive = tagCompound.getBoolean(NBTHolder.NBT_ALTAR_ACTIVE);
|
|
|
|
liquidRequired = tagCompound.getInteger(NBTHolder.NBT_ALTAR_LIQUID_REQ);
|
|
|
|
canBeFilled = tagCompound.getBoolean(NBTHolder.NBT_ALTAR_FILLABLE);
|
|
|
|
isUpgraded = tagCompound.getBoolean("isUpgraded");
|
|
|
|
consumptionRate = tagCompound.getInteger("consumptionRate");
|
|
|
|
drainRate = tagCompound.getInteger("drainRate");
|
|
|
|
consumptionMultiplier = tagCompound.getFloat("consumptionMultiplier");
|
|
|
|
efficiencyMultiplier = tagCompound.getFloat("efficiencyMultiplier");
|
|
|
|
selfSacrificeEfficiencyMultiplier = tagCompound.getFloat("selfSacrificeEfficiencyMultiplier");
|
|
|
|
sacrificeEfficiencyMultiplier = tagCompound.getFloat("sacrificeEfficiencyMultiplier");
|
|
|
|
capacityMultiplier = tagCompound.getFloat("capacityMultiplier");
|
|
|
|
orbCapacityMultiplier = tagCompound.getFloat("orbCapacityMultiplier");
|
|
|
|
dislocationMultiplier = tagCompound.getFloat("dislocationMultiplier");
|
|
|
|
capacity = tagCompound.getInteger("capacity");
|
|
|
|
bufferCapacity = tagCompound.getInteger("bufferCapacity");
|
|
|
|
progress = tagCompound.getInteger("progress");
|
|
|
|
isResultBlock = tagCompound.getBoolean("isResultBlock");
|
|
|
|
lockdownDuration = tagCompound.getInteger("lockdownDuration");
|
|
|
|
accelerationUpgrades = tagCompound.getInteger("accelerationUpgrades");
|
|
|
|
demonBloodDuration = tagCompound.getInteger("demonBloodDuration");
|
|
|
|
cooldownAfterCrafting = tagCompound.getInteger("cooldownAfterCrafting");
|
2015-10-30 03:22:14 +00:00
|
|
|
}
|
|
|
|
|
2015-11-03 02:30:28 +00:00
|
|
|
@Override
|
2015-11-03 16:09:16 +00:00
|
|
|
public void writeToNBT(NBTTagCompound tagCompound) {
|
|
|
|
super.writeToNBT(tagCompound);
|
|
|
|
|
|
|
|
if (fluid != null)
|
|
|
|
fluid.writeToNBT(tagCompound);
|
|
|
|
else
|
|
|
|
tagCompound.setString("Empty", "");
|
|
|
|
|
|
|
|
|
|
|
|
if (fluidOutput != null)
|
|
|
|
tagCompound.setInteger("outputAmount", fluidOutput.amount);
|
|
|
|
|
|
|
|
if (fluidInput != null)
|
|
|
|
tagCompound.setInteger("inputAmount", fluidInput.amount);
|
|
|
|
|
|
|
|
tagCompound.setString("upgradeLevel", altarTier.name());
|
|
|
|
tagCompound.setBoolean("isActive", isActive);
|
|
|
|
tagCompound.setInteger("liquidRequired", liquidRequired);
|
|
|
|
tagCompound.setBoolean("canBeFilled", canBeFilled);
|
|
|
|
tagCompound.setBoolean("isUpgraded", isUpgraded);
|
|
|
|
tagCompound.setInteger("consumptionRate", consumptionRate);
|
|
|
|
tagCompound.setInteger("drainRate", drainRate);
|
|
|
|
tagCompound.setFloat("consumptionMultiplier", consumptionMultiplier);
|
|
|
|
tagCompound.setFloat("efficiencyMultiplier", efficiencyMultiplier);
|
|
|
|
tagCompound.setFloat("sacrificeEfficiencyMultiplier", sacrificeEfficiencyMultiplier);
|
|
|
|
tagCompound.setFloat("selfSacrificeEfficiencyMultiplier", selfSacrificeEfficiencyMultiplier);
|
|
|
|
tagCompound.setBoolean("isResultBlock", isResultBlock);
|
|
|
|
tagCompound.setFloat("capacityMultiplier", capacityMultiplier);
|
|
|
|
tagCompound.setFloat("orbCapacityMultiplier", orbCapacityMultiplier);
|
|
|
|
tagCompound.setFloat("dislocationMultiplier", dislocationMultiplier);
|
|
|
|
tagCompound.setInteger("capacity", capacity);
|
|
|
|
tagCompound.setInteger("progress", progress);
|
|
|
|
tagCompound.setInteger("bufferCapacity", bufferCapacity);
|
|
|
|
tagCompound.setInteger("lockdownDuration", lockdownDuration);
|
|
|
|
tagCompound.setInteger("accelerationUpgrades", this.accelerationUpgrades);
|
|
|
|
tagCompound.setInteger("demonBloodDuration", demonBloodDuration);
|
|
|
|
tagCompound.setInteger("cooldownAfterCrafting", cooldownAfterCrafting);
|
2015-11-03 15:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update() {
|
2015-11-03 16:09:16 +00:00
|
|
|
if (getWorld().isRemote)
|
2015-11-03 02:30:28 +00:00
|
|
|
return;
|
|
|
|
|
2015-11-03 16:09:16 +00:00
|
|
|
if (getWorld().getTotalWorldTime() % (Math.max(20 - getUpgrade().getSpeedCount(), 1)) == 0)
|
2015-11-03 02:30:28 +00:00
|
|
|
everySecond();
|
|
|
|
|
2015-11-03 16:09:16 +00:00
|
|
|
if (getWorld().getTotalWorldTime() % 100 == 0)
|
2015-11-03 02:30:28 +00:00
|
|
|
everyFiveSeconds();
|
|
|
|
}
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2015-11-03 15:34:11 +00:00
|
|
|
private void everySecond() {
|
|
|
|
startCycle();
|
2015-11-03 02:30:28 +00:00
|
|
|
}
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2015-11-03 15:34:11 +00:00
|
|
|
private void everyFiveSeconds() {
|
2015-11-03 02:30:28 +00:00
|
|
|
checkTier();
|
|
|
|
}
|
|
|
|
|
2015-11-03 15:34:11 +00:00
|
|
|
public void startCycle() {
|
2015-11-03 16:09:16 +00:00
|
|
|
if (worldObj != null)
|
2015-11-03 15:34:11 +00:00
|
|
|
worldObj.markBlockForUpdate(pos);
|
|
|
|
|
2015-11-03 16:09:16 +00:00
|
|
|
if (fluid == null || fluid.amount <= 0)
|
2015-11-03 15:34:11 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (getStackInSlot(0) != null) {
|
|
|
|
// Do recipes
|
2015-11-03 18:00:40 +00:00
|
|
|
if (AltarRecipeRegistry.getRecipes().containsKey(ItemStackWrapper.getHolder(getStackInSlot(0)))) {
|
|
|
|
AltarRecipe recipe = AltarRecipeRegistry.getRecipeForInput(ItemStackWrapper.getHolder(getStackInSlot(0)));
|
2015-11-03 15:34:11 +00:00
|
|
|
|
2015-11-03 16:09:16 +00:00
|
|
|
if (altarTier.ordinal() >= recipe.getMinTier().ordinal()) {
|
2015-11-03 15:34:11 +00:00
|
|
|
this.liquidRequired = recipe.getSyphon();
|
|
|
|
// this.canBeFilled = recipe
|
|
|
|
this.consumptionRate = recipe.getConsumeRate();
|
|
|
|
this.drainRate = recipe.getDrainRate();
|
|
|
|
this.isActive = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkTier() {
|
2015-11-03 02:30:28 +00:00
|
|
|
// TODO - Write checking for tier stuff
|
|
|
|
|
|
|
|
EnumAltarTier tier = BloodAltar.getAltarTier(getWorld(), getPos());
|
|
|
|
|
2015-11-03 16:09:16 +00:00
|
|
|
if (tier.equals(EnumAltarTier.ONE))
|
2015-11-03 02:30:28 +00:00
|
|
|
upgrade = new AltarUpgrade();
|
2015-11-03 16:09:16 +00:00
|
|
|
else
|
2015-11-03 15:34:11 +00:00
|
|
|
upgrade = BloodAltar.getUpgrades(worldObj, pos, tier);
|
|
|
|
|
2015-11-03 16:09:16 +00:00
|
|
|
if (this.fluid.amount > this.capacity)
|
2015-11-03 15:34:11 +00:00
|
|
|
this.fluid.amount = this.capacity;
|
|
|
|
|
|
|
|
worldObj.markBlockForUpdate(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sacrificialDaggerCall(int amount, boolean isSacrifice) {
|
2015-11-03 16:09:16 +00:00
|
|
|
if (this.lockdownDuration > 0) {
|
2015-11-03 15:34:11 +00:00
|
|
|
int amt = (int) Math.min(bufferCapacity - fluidInput.amount, (isSacrifice ? 1 + sacrificeEfficiencyMultiplier : 1 + selfSacrificeEfficiencyMultiplier) * amount);
|
|
|
|
fluidInput.amount += amt;
|
|
|
|
} else {
|
|
|
|
fluid.amount += Math.min(capacity - fluid.amount, (isSacrifice ? 1 + sacrificeEfficiencyMultiplier : 1 + selfSacrificeEfficiencyMultiplier) * amount);
|
2015-11-03 02:30:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-03 15:34:11 +00:00
|
|
|
@Override
|
|
|
|
public boolean isItemValidForSlot(int slot, ItemStack itemstack) {
|
|
|
|
return slot == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public TileAltar setUpgrade(AltarUpgrade upgrade) {
|
2015-10-30 03:22:14 +00:00
|
|
|
this.upgrade = upgrade;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-11-03 15:34:11 +00:00
|
|
|
public AltarUpgrade getUpgrade() {
|
2015-10-30 03:22:14 +00:00
|
|
|
return upgrade;
|
|
|
|
}
|
|
|
|
|
2015-11-03 16:09:16 +00:00
|
|
|
public TileAltar setTier(EnumAltarTier tier) {
|
|
|
|
this.altarTier = tier;
|
2015-10-30 03:22:14 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-11-03 15:34:11 +00:00
|
|
|
@Override
|
|
|
|
public int getCapacity() {
|
|
|
|
return capacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCurrentBlood() {
|
|
|
|
return getFluidAmount();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-03 16:09:16 +00:00
|
|
|
public EnumAltarTier getTier() {
|
|
|
|
return altarTier;
|
2015-11-03 15:34:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getProgress() {
|
|
|
|
return progress;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getSacrificeMultiplier() {
|
|
|
|
return sacrificeEfficiencyMultiplier;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getSelfSacrificeMultiplier() {
|
|
|
|
return selfSacrificeEfficiencyMultiplier;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getOrbMultiplier() {
|
|
|
|
return orbCapacityMultiplier;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getDislocationMultiplier() {
|
|
|
|
return dislocationMultiplier;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getBufferCapacity() {
|
|
|
|
return bufferCapacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addToDemonBloodDuration(int dur) {
|
|
|
|
this.demonBloodDuration += dur;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasDemonBlood() {
|
|
|
|
return this.demonBloodDuration > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void decrementDemonBlood() {
|
|
|
|
this.demonBloodDuration = Math.max(0, this.demonBloodDuration - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void requestPauseAfterCrafting(int amount) {
|
|
|
|
if (this.isActive) {
|
|
|
|
this.cooldownAfterCrafting = amount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMainFluid(FluidStack fluid) {
|
|
|
|
this.fluid = fluid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOutputFluid(FluidStack fluid) {
|
|
|
|
this.fluidOutput = fluid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setInputFluid(FluidStack fluid) {
|
|
|
|
this.fluidInput = fluid;
|
2015-10-30 03:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IFluidHandler
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidTankInfo[] getTankInfo(EnumFacing from) {
|
|
|
|
return new FluidTankInfo[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int fill(EnumFacing from, FluidStack resource, boolean doFill) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canFill(EnumFacing from, Fluid fluid) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canDrain(EnumFacing from, Fluid fluid) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// IFluidTank
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack getFluid() {
|
|
|
|
return fluid;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getFluidAmount() {
|
|
|
|
return fluid.amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidTankInfo getInfo() {
|
|
|
|
return new FluidTankInfo(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int fill(FluidStack resource, boolean doFill) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(int maxDrain, boolean doDrain) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|