Attempt to fix 1.16.3 branch's issues on the repository

Added the original 'wayoftime' folder back, so see if that fixed the multiple folder issue.
This commit is contained in:
WayofTime 2020-10-29 15:50:03 -04:00
parent 6b4145a67c
commit 9fa68e86ae
224 changed files with 24047 additions and 0 deletions

View file

@ -0,0 +1,62 @@
package wayoftime.bloodmagic.altar;
import net.minecraft.util.math.BlockPos;
/**
* Used for building the altar structure.
*/
public class AltarComponent
{
private final BlockPos offset;
private final ComponentType component;
private boolean upgradeSlot;
/**
* Sets a component location for the altar.
*
* @param offset - Where the block should be in relation to the Altar
* @param component - The type of Component the location should contain
*/
public AltarComponent(BlockPos offset, ComponentType component)
{
this.offset = offset;
this.component = component;
}
/**
* Use for setting a location at which there must be a block, but the type of
* block does not matter.
*
* @param offset - Where the block should be in relation to the Altar
*/
public AltarComponent(BlockPos offset)
{
this(offset, ComponentType.NOTAIR);
}
/**
* Sets the location to an upgrade slot.
*
* @return the current instance for further use.
*/
public AltarComponent setUpgradeSlot()
{
this.upgradeSlot = true;
return this;
}
public BlockPos getOffset()
{
return offset;
}
public boolean isUpgradeSlot()
{
return upgradeSlot;
}
public ComponentType getComponent()
{
return component;
}
}

View file

@ -0,0 +1,172 @@
package wayoftime.bloodmagic.altar;
import java.util.List;
import java.util.function.Consumer;
import com.google.common.collect.Lists;
import net.minecraft.util.math.BlockPos;
public enum AltarTier
{
ONE()
{
@Override
public void buildComponents(Consumer<AltarComponent> components)
{
// Nada
}
},
TWO()
{
@Override
public void buildComponents(Consumer<AltarComponent> components)
{
components.accept(new AltarComponent(new BlockPos(-1, -1, -1), ComponentType.BLOODRUNE));
components.accept(new AltarComponent(new BlockPos(0, -1, -1), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(1, -1, -1), ComponentType.BLOODRUNE));
components.accept(new AltarComponent(new BlockPos(-1, -1, 0), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(1, -1, 0), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(-1, -1, 1), ComponentType.BLOODRUNE));
components.accept(new AltarComponent(new BlockPos(0, -1, 1), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(1, -1, 1), ComponentType.BLOODRUNE));
}
},
THREE()
{
@Override
public void buildComponents(Consumer<AltarComponent> components)
{
// Doesn't pull from tier 2 because upgrades slots are different
components.accept(new AltarComponent(new BlockPos(-1, -1, -1), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(0, -1, -1), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(1, -1, -1), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(-1, -1, 0), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(1, -1, 0), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(-1, -1, 1), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(0, -1, 1), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(1, -1, 1), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(-3, -1, -3)));
components.accept(new AltarComponent(new BlockPos(-3, 0, -3)));
components.accept(new AltarComponent(new BlockPos(3, -1, -3)));
components.accept(new AltarComponent(new BlockPos(3, 0, -3)));
components.accept(new AltarComponent(new BlockPos(-3, -1, 3)));
components.accept(new AltarComponent(new BlockPos(-3, 0, 3)));
components.accept(new AltarComponent(new BlockPos(3, -1, 3)));
components.accept(new AltarComponent(new BlockPos(3, 0, 3)));
components.accept(new AltarComponent(new BlockPos(-3, 1, -3), ComponentType.GLOWSTONE));
components.accept(new AltarComponent(new BlockPos(3, 1, -3), ComponentType.GLOWSTONE));
components.accept(new AltarComponent(new BlockPos(-3, 1, 3), ComponentType.GLOWSTONE));
components.accept(new AltarComponent(new BlockPos(3, 1, 3), ComponentType.GLOWSTONE));
for (int i = -2; i <= 2; i++)
{
components.accept(new AltarComponent(new BlockPos(3, -2, i), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(-3, -2, i), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(i, -2, 3), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(i, -2, -3), ComponentType.BLOODRUNE).setUpgradeSlot());
}
}
},
FOUR()
{
@Override
public void buildComponents(Consumer<AltarComponent> components)
{
THREE.getAltarComponents().forEach(components);
for (int i = -3; i <= 3; i++)
{
components.accept(new AltarComponent(new BlockPos(5, -3, i), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(-5, -3, i), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(i, -3, 5), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(i, -3, -5), ComponentType.BLOODRUNE).setUpgradeSlot());
}
for (int i = -2; i <= 1; i++)
{
components.accept(new AltarComponent(new BlockPos(5, i, 5)));
components.accept(new AltarComponent(new BlockPos(5, i, -5)));
components.accept(new AltarComponent(new BlockPos(-5, i, -5)));
components.accept(new AltarComponent(new BlockPos(-5, i, 5)));
}
components.accept(new AltarComponent(new BlockPos(5, 2, 5), ComponentType.BLOODSTONE));
components.accept(new AltarComponent(new BlockPos(5, 2, -5), ComponentType.BLOODSTONE));
components.accept(new AltarComponent(new BlockPos(-5, 2, -5), ComponentType.BLOODSTONE));
components.accept(new AltarComponent(new BlockPos(-5, 2, 5), ComponentType.BLOODSTONE));
}
},
FIVE()
{
@Override
public void buildComponents(Consumer<AltarComponent> components)
{
FOUR.getAltarComponents().forEach(components);
components.accept(new AltarComponent(new BlockPos(-8, -3, 8), ComponentType.BEACON));
components.accept(new AltarComponent(new BlockPos(-8, -3, -8), ComponentType.BEACON));
components.accept(new AltarComponent(new BlockPos(8, -3, -8), ComponentType.BEACON));
components.accept(new AltarComponent(new BlockPos(8, -3, 8), ComponentType.BEACON));
for (int i = -6; i <= 6; i++)
{
components.accept(new AltarComponent(new BlockPos(8, -4, i), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(-8, -4, i), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(i, -4, 8), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(i, -4, -8), ComponentType.BLOODRUNE).setUpgradeSlot());
}
}
},
SIX()
{
@Override
public void buildComponents(Consumer<AltarComponent> components)
{
FIVE.getAltarComponents().forEach(components);
for (int i = -4; i <= 2; i++)
{
components.accept(new AltarComponent(new BlockPos(11, i, 11)));
components.accept(new AltarComponent(new BlockPos(-11, i, -11)));
components.accept(new AltarComponent(new BlockPos(11, i, -11)));
components.accept(new AltarComponent(new BlockPos(-11, i, 11)));
}
components.accept(new AltarComponent(new BlockPos(11, 3, 11), ComponentType.CRYSTAL));
components.accept(new AltarComponent(new BlockPos(-11, 3, -11), ComponentType.CRYSTAL));
components.accept(new AltarComponent(new BlockPos(11, 3, -11), ComponentType.CRYSTAL));
components.accept(new AltarComponent(new BlockPos(-11, 3, 11), ComponentType.CRYSTAL));
for (int i = -9; i <= 9; i++)
{
components.accept(new AltarComponent(new BlockPos(11, -5, i), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(-11, -5, i), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(i, -5, 11), ComponentType.BLOODRUNE).setUpgradeSlot());
components.accept(new AltarComponent(new BlockPos(i, -5, -11), ComponentType.BLOODRUNE).setUpgradeSlot());
}
}
};
public static final int MAXTIERS = values().length;
private List<AltarComponent> altarComponents;
AltarTier()
{
this.altarComponents = Lists.newArrayList();
buildComponents(altarComponents::add);
}
public abstract void buildComponents(Consumer<AltarComponent> components);
public int toInt()
{
return ordinal() + 1;
}
public List<AltarComponent> getAltarComponents()
{
return altarComponents;
}
}

View file

@ -0,0 +1,29 @@
package wayoftime.bloodmagic.altar;
import java.util.EnumMap;
import com.google.common.collect.Maps;
import wayoftime.bloodmagic.block.enums.BloodRuneType;
public class AltarUpgrade
{
private final EnumMap<BloodRuneType, Integer> upgradeLevels;
public AltarUpgrade()
{
this.upgradeLevels = Maps.newEnumMap(BloodRuneType.class);
}
public AltarUpgrade upgrade(BloodRuneType rune)
{
upgradeLevels.compute(rune, (r, l) -> l == null ? 1 : l + 1);
return this;
}
public int getLevel(BloodRuneType rune)
{
return upgradeLevels.getOrDefault(rune, 0);
}
}

View file

@ -0,0 +1,99 @@
package wayoftime.bloodmagic.altar;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang3.tuple.Pair;
import net.minecraft.block.BlockState;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import wayoftime.bloodmagic.api.impl.BloodMagicAPI;
import wayoftime.bloodmagic.common.block.BlockBloodRune;
import wayoftime.bloodmagic.tile.TileAltar;
public class AltarUtil
{
@Nonnull
public static AltarTier getTier(World world, BlockPos pos)
{
TileEntity tile = world.getTileEntity(pos);
if (!(tile instanceof TileAltar))
return AltarTier.ONE;
AltarTier lastCheck = AltarTier.ONE;
for (AltarTier tier : AltarTier.values())
{
for (AltarComponent component : tier.getAltarComponents())
{
BlockPos componentPos = pos.add(component.getOffset());
BlockState worldState = world.getBlockState(componentPos);
if (worldState.getBlock() instanceof IAltarComponent)
if (((IAltarComponent) worldState.getBlock()).getType(world, worldState, componentPos) == component.getComponent())
continue;
if (component.getComponent() == ComponentType.NOTAIR && worldState.getMaterial() != Material.AIR
&& !worldState.getMaterial().isLiquid())
continue;
List<BlockState> validStates = BloodMagicAPI.INSTANCE.getComponentStates(component.getComponent());
if (!validStates.contains(worldState))
return lastCheck;
}
lastCheck = tier;
}
return lastCheck;
}
@Nonnull
public static AltarUpgrade getUpgrades(World world, BlockPos pos, AltarTier currentTier)
{
AltarUpgrade upgrades = new AltarUpgrade();
for (AltarComponent component : currentTier.getAltarComponents())
{
if (!component.isUpgradeSlot() || component.getComponent() != ComponentType.BLOODRUNE)
continue;
BlockPos componentPos = pos.add(component.getOffset());
BlockState state = world.getBlockState(componentPos);
if (state.getBlock() instanceof BlockBloodRune)
upgrades.upgrade(((BlockBloodRune) state.getBlock()).getBloodRune(world, componentPos));
}
return upgrades;
}
@Nullable
public static Pair<BlockPos, ComponentType> getFirstMissingComponent(World world, BlockPos pos, int altarTier)
{
if (altarTier >= AltarTier.MAXTIERS)
return null;
for (AltarTier tier : AltarTier.values())
{
for (AltarComponent component : tier.getAltarComponents())
{
BlockPos componentPos = pos.add(component.getOffset());
BlockState worldState = world.getBlockState(componentPos);
if (component.getComponent() == ComponentType.NOTAIR && worldState.getMaterial() != Material.AIR
&& !worldState.getMaterial().isLiquid())
continue;
List<BlockState> validStates = BloodMagicAPI.INSTANCE.getComponentStates(component.getComponent());
if (!validStates.contains(worldState))
return Pair.of(componentPos, component.getComponent());
}
}
return null;
}
}

View file

@ -0,0 +1,816 @@
package wayoftime.bloodmagic.altar;
import com.google.common.base.Enums;
import net.minecraft.block.BlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.particles.RedstoneParticleData;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.templates.FluidTank;
import net.minecraftforge.items.ItemHandlerHelper;
import wayoftime.bloodmagic.api.event.BloodMagicCraftedEvent;
import wayoftime.bloodmagic.api.impl.BloodMagicAPI;
import wayoftime.bloodmagic.api.impl.recipe.RecipeBloodAltar;
import wayoftime.bloodmagic.block.enums.BloodRuneType;
import wayoftime.bloodmagic.common.block.BloodMagicBlocks;
import wayoftime.bloodmagic.core.data.Binding;
import wayoftime.bloodmagic.iface.IBindable;
import wayoftime.bloodmagic.orb.BloodOrb;
import wayoftime.bloodmagic.orb.IBloodOrb;
import wayoftime.bloodmagic.tile.TileAltar;
import wayoftime.bloodmagic.util.Constants;
import wayoftime.bloodmagic.util.helper.NetworkHelper;
public class BloodAltar// implements IFluidHandler
{
public boolean isActive;
protected FluidStack fluidOutput = new FluidStack(BloodMagicBlocks.LIFE_ESSENCE_FLUID.get(), 0); // TODO: Fix
protected FluidStack fluidInput = new FluidStack(BloodMagicBlocks.LIFE_ESSENCE_FLUID.get(), 0);
protected FluidTank tank = new FluidTank(FluidAttributes.BUCKET_VOLUME);
private final LazyOptional<IFluidHandler> holder = LazyOptional.of(() -> tank);
private TileAltar tileAltar;
private int internalCounter = 0;
private AltarTier altarTier = AltarTier.ONE;
private AltarUpgrade upgrade;
private int capacity = FluidAttributes.BUCKET_VOLUME * 10;
private FluidStack fluid = new FluidStack(BloodMagicBlocks.LIFE_ESSENCE_FLUID.get(), 0);
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;
private float capacityMultiplier = 1;
private float orbCapacityMultiplier;
private float dislocationMultiplier;
private int accelerationUpgrades;
private boolean isUpgraded;
private boolean isResultBlock;
private int bufferCapacity = FluidAttributes.BUCKET_VOLUME;
private int progress;
private int lockdownDuration;
private int demonBloodDuration;
private int totalCharge = 0; // TODO save
private int chargingRate = 0;
private int chargingFrequency = 0;
private int maxCharge = 0;
private int cooldownAfterCrafting = 60;
private RecipeBloodAltar recipe;
private AltarTier currentTierDisplayed = AltarTier.ONE;
public BloodAltar(TileAltar tileAltar)
{
this.tileAltar = tileAltar;
}
public void readFromNBT(CompoundNBT tagCompound)
{
if (!tagCompound.contains(Constants.NBT.EMPTY))
{
FluidStack fluid = FluidStack.loadFluidStackFromNBT(tagCompound);
if (fluid != null)
{
setMainFluid(new FluidStack(BloodMagicBlocks.LIFE_ESSENCE_FLUID.get(), fluid.getAmount()));
// setMainFluid(fluid);
} else
{
// setMainFluid(new FluidStack(BloodMagicBlocks.LIFE_ESSENCE_FLUID.get(), fluid.getAmount()));
}
FluidStack fluidOut = new FluidStack(BloodMagicBlocks.LIFE_ESSENCE_FLUID.get(), tagCompound.getInt(Constants.NBT.OUTPUT_AMOUNT));
setOutputFluid(fluidOut);
FluidStack fluidIn = new FluidStack(BloodMagicBlocks.LIFE_ESSENCE_FLUID.get(), tagCompound.getInt(Constants.NBT.INPUT_AMOUNT));
setInputFluid(fluidIn);
}
internalCounter = tagCompound.getInt("internalCounter");
altarTier = Enums.getIfPresent(AltarTier.class, tagCompound.getString(Constants.NBT.ALTAR_TIER)).or(AltarTier.ONE);
isActive = tagCompound.getBoolean(Constants.NBT.ALTAR_ACTIVE);
liquidRequired = tagCompound.getInt(Constants.NBT.ALTAR_LIQUID_REQ);
canBeFilled = tagCompound.getBoolean(Constants.NBT.ALTAR_FILLABLE);
isUpgraded = tagCompound.getBoolean(Constants.NBT.ALTAR_UPGRADED);
consumptionRate = tagCompound.getInt(Constants.NBT.ALTAR_CONSUMPTION_RATE);
drainRate = tagCompound.getInt(Constants.NBT.ALTAR_DRAIN_RATE);
consumptionMultiplier = tagCompound.getFloat(Constants.NBT.ALTAR_CONSUMPTION_MULTIPLIER);
efficiencyMultiplier = tagCompound.getFloat(Constants.NBT.ALTAR_EFFICIENCY_MULTIPLIER);
selfSacrificeEfficiencyMultiplier = tagCompound.getFloat(Constants.NBT.ALTAR_SELF_SACRIFICE_MULTIPLIER);
sacrificeEfficiencyMultiplier = tagCompound.getFloat(Constants.NBT.ALTAR_SACRIFICE_MULTIPLIER);
capacityMultiplier = tagCompound.getFloat(Constants.NBT.ALTAR_CAPACITY_MULTIPLIER);
orbCapacityMultiplier = tagCompound.getFloat(Constants.NBT.ALTAR_ORB_CAPACITY_MULTIPLIER);
dislocationMultiplier = tagCompound.getFloat(Constants.NBT.ALTAR_DISLOCATION_MULTIPLIER);
capacity = tagCompound.getInt(Constants.NBT.ALTAR_CAPACITY);
bufferCapacity = tagCompound.getInt(Constants.NBT.ALTAR_BUFFER_CAPACITY);
progress = tagCompound.getInt(Constants.NBT.ALTAR_PROGRESS);
isResultBlock = tagCompound.getBoolean(Constants.NBT.ALTAR_IS_RESULT_BLOCK);
lockdownDuration = tagCompound.getInt(Constants.NBT.ALTAR_LOCKDOWN_DURATION);
accelerationUpgrades = tagCompound.getInt(Constants.NBT.ALTAR_ACCELERATION_UPGRADES);
demonBloodDuration = tagCompound.getInt(Constants.NBT.ALTAR_DEMON_BLOOD_DURATION);
cooldownAfterCrafting = tagCompound.getInt(Constants.NBT.ALTAR_COOLDOWN_AFTER_CRAFTING);
chargingRate = tagCompound.getInt(Constants.NBT.ALTAR_CHARGE_RATE);
chargingFrequency = tagCompound.getInt(Constants.NBT.ALTAR_CHARGE_FREQUENCY);
totalCharge = tagCompound.getInt(Constants.NBT.ALTAR_TOTAL_CHARGE);
maxCharge = tagCompound.getInt(Constants.NBT.ALTAR_MAX_CHARGE);
currentTierDisplayed = Enums.getIfPresent(AltarTier.class, tagCompound.getString(Constants.NBT.ALTAR_CURRENT_TIER_DISPLAYED)).or(AltarTier.ONE);
}
public void writeToNBT(CompoundNBT tagCompound)
{
if (fluid != null)
fluid.writeToNBT(tagCompound);
else
tagCompound.putString(Constants.NBT.EMPTY, "");
if (fluidOutput != null)
tagCompound.putInt(Constants.NBT.OUTPUT_AMOUNT, fluidOutput.getAmount());
if (fluidInput != null)
tagCompound.putInt(Constants.NBT.INPUT_AMOUNT, fluidInput.getAmount());
tagCompound.putInt("internalCounter", internalCounter);
tagCompound.putString(Constants.NBT.ALTAR_TIER, altarTier.name());
tagCompound.putBoolean(Constants.NBT.ALTAR_ACTIVE, isActive);
tagCompound.putInt(Constants.NBT.ALTAR_LIQUID_REQ, liquidRequired);
tagCompound.putBoolean(Constants.NBT.ALTAR_FILLABLE, canBeFilled);
tagCompound.putBoolean(Constants.NBT.ALTAR_UPGRADED, isUpgraded);
tagCompound.putInt(Constants.NBT.ALTAR_CONSUMPTION_RATE, consumptionRate);
tagCompound.putInt(Constants.NBT.ALTAR_DRAIN_RATE, drainRate);
tagCompound.putFloat(Constants.NBT.ALTAR_CONSUMPTION_MULTIPLIER, consumptionMultiplier);
tagCompound.putFloat(Constants.NBT.ALTAR_EFFICIENCY_MULTIPLIER, efficiencyMultiplier);
tagCompound.putFloat(Constants.NBT.ALTAR_SACRIFICE_MULTIPLIER, sacrificeEfficiencyMultiplier);
tagCompound.putFloat(Constants.NBT.ALTAR_SELF_SACRIFICE_MULTIPLIER, selfSacrificeEfficiencyMultiplier);
tagCompound.putBoolean(Constants.NBT.ALTAR_IS_RESULT_BLOCK, isResultBlock);
tagCompound.putFloat(Constants.NBT.ALTAR_CAPACITY_MULTIPLIER, capacityMultiplier);
tagCompound.putFloat(Constants.NBT.ALTAR_ORB_CAPACITY_MULTIPLIER, orbCapacityMultiplier);
tagCompound.putFloat(Constants.NBT.ALTAR_DISLOCATION_MULTIPLIER, dislocationMultiplier);
tagCompound.putInt(Constants.NBT.ALTAR_CAPACITY, capacity);
tagCompound.putInt(Constants.NBT.ALTAR_PROGRESS, progress);
tagCompound.putInt(Constants.NBT.ALTAR_BUFFER_CAPACITY, bufferCapacity);
tagCompound.putInt(Constants.NBT.ALTAR_LOCKDOWN_DURATION, lockdownDuration);
tagCompound.putInt(Constants.NBT.ALTAR_ACCELERATION_UPGRADES, accelerationUpgrades);
tagCompound.putInt(Constants.NBT.ALTAR_DEMON_BLOOD_DURATION, demonBloodDuration);
tagCompound.putInt(Constants.NBT.ALTAR_COOLDOWN_AFTER_CRAFTING, cooldownAfterCrafting);
tagCompound.putInt(Constants.NBT.ALTAR_CHARGE_RATE, chargingRate);
tagCompound.putInt(Constants.NBT.ALTAR_CHARGE_FREQUENCY, chargingFrequency);
tagCompound.putInt(Constants.NBT.ALTAR_TOTAL_CHARGE, totalCharge);
tagCompound.putInt(Constants.NBT.ALTAR_MAX_CHARGE, maxCharge);
tagCompound.putString(Constants.NBT.ALTAR_CURRENT_TIER_DISPLAYED, currentTierDisplayed.name());
}
public void startCycle()
{
if (tileAltar.getWorld() != null)
tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3);
checkTier();
// Temporary thing to test the recipes.
// fluid.setAmount(10000);
// this.setMainFluid(new FluidStack(BloodMagicBlocks.LIFE_ESSENCE_FLUID.get(), 10000));
if ((fluid == null || fluid.getAmount() <= 0) && totalCharge <= 0)
return;
if (!isActive)
progress = 0;
ItemStack input = tileAltar.getStackInSlot(0);
if (!input.isEmpty())
{
// Do recipes
RecipeBloodAltar recipe = BloodMagicAPI.INSTANCE.getRecipeRegistrar().getBloodAltar(tileAltar.getWorld(), input);
if (recipe != null)
{
if (recipe.getMinimumTier().ordinal() <= altarTier.ordinal())
{
this.isActive = true;
this.recipe = recipe;
this.liquidRequired = recipe.getSyphon();
this.consumptionRate = recipe.getConsumeRate();
this.drainRate = recipe.getDrainRate();
this.canBeFilled = false;
return;
}
} else if (input.getItem() instanceof IBloodOrb)
{
this.isActive = true;
this.canBeFilled = true;
return;
}
}
isActive = false;
}
public void update()
{
// World world = tileAltar.getWorld();
//
// RecipeBloodAltar recipe = BloodMagicAPI.INSTANCE.getRecipeRegistrar().getBloodAltar(world, new ItemStack(Items.DIAMOND));
//
// if (recipe != null)
// {
// System.out.println("Found a recipe!");
// }
//
// List<RecipeBloodAltar> altarRecipes = world.getRecipeManager().getRecipesForType(BloodMagicRecipeType.ALTAR);
//
// System.out.println("There are currently " + altarRecipes.size() + " Altar Recipes loaded.");
//
World world = tileAltar.getWorld();
BlockPos pos = tileAltar.getPos();
if (world.isRemote)
return;
// Used instead of the world time for checks that do not happen every tick
internalCounter++;
if (lockdownDuration > 0)
lockdownDuration--;
if (internalCounter % 20 == 0)
{
for (Direction facing : Direction.values())
{
BlockPos newPos = pos.offset(facing);
BlockState block = world.getBlockState(newPos);
block.getBlock().onNeighborChange(block, world, newPos, pos);
}
}
if (internalCounter % (Math.max(20 - this.accelerationUpgrades, 1)) == 0)
{
int syphonMax = (int) (20 * this.dislocationMultiplier);
int fluidInputted;
int fluidOutputted;
fluidInputted = Math.min(syphonMax, -this.fluid.getAmount() + capacity);
fluidInputted = Math.min(this.fluidInput.getAmount(), fluidInputted);
this.fluid.setAmount(this.fluid.getAmount() + fluidInputted);
this.fluidInput.setAmount(this.fluidInput.getAmount() - fluidInputted);
fluidOutputted = Math.min(syphonMax, this.bufferCapacity - this.fluidOutput.getAmount());
fluidOutputted = Math.min(this.fluid.getAmount(), fluidOutputted);
this.fluidOutput.setAmount(this.fluidOutput.getAmount() + fluidOutputted);
this.fluid.setAmount(this.fluid.getAmount() - fluidOutputted);
tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3);
}
if (internalCounter % this.getChargingFrequency() == 0 && !this.isActive)
{
// int chargeInputted = Math.min(chargingRate, this.fluid.getAmount());
// chargeInputted = Math.min(chargeInputted, maxCharge - totalCharge);
// totalCharge += chargeInputted;
// this.fluid.setAmount(this.fluid.getAmount() - chargeInputted);
// tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3);
}
if (internalCounter % 100 == 0 && (this.isActive || this.cooldownAfterCrafting <= 0))
startCycle();
updateAltar();
}
private void updateAltar()
{
// System.out.println("Updating altar.");
if (!isActive)
{
if (cooldownAfterCrafting > 0)
cooldownAfterCrafting--;
return;
}
if (!canBeFilled && recipe == null)
{
startCycle();
return;
}
ItemStack input = tileAltar.getStackInSlot(0);
if (input.isEmpty())
return;
World world = tileAltar.getWorld();
BlockPos pos = tileAltar.getPos();
if (world.isRemote)
return;
if (!canBeFilled)
{
boolean hasOperated = false;
int stackSize = input.getCount();
if (totalCharge > 0)
{
int chargeDrained = Math.min(liquidRequired * stackSize - progress, totalCharge);
totalCharge -= chargeDrained;
progress += chargeDrained;
hasOperated = true;
}
if (fluid != null && fluid.getAmount() >= 1)
{
// int liquidDrained = Math.min((int) (altarTier.ordinal() >= 1
// ? consumptionRate * (1 + consumptionMultiplier)
// : consumptionRate), fluid.getAmount());
int liquidDrained = Math.min((int) (consumptionRate * (1 + consumptionMultiplier)), fluid.getAmount());
if (liquidDrained > (liquidRequired * stackSize - progress))
liquidDrained = liquidRequired * stackSize - progress;
fluid.setAmount(fluid.getAmount() - liquidDrained);
progress += liquidDrained;
hasOperated = true;
if (internalCounter % 4 == 0 && world instanceof ServerWorld)
{
ServerWorld server = (ServerWorld) world;
// server.spawnParticle(ParticleTypes.SPLASH, (double) pos.getX()
// + worldIn.rand.nextDouble(), (double) (pos.getY() + 1), (double) pos.getZ()
// + worldIn.rand.nextDouble(), 1, 0.0D, 0.0D, 0.0D, 1.0D);
server.spawnParticle(RedstoneParticleData.REDSTONE_DUST, pos.getX() + 0.5, pos.getY()
+ 1.0, pos.getZ() + 0.5, 1, 0.2, 0.0, 0.2, 0.0);
}
} else if (!hasOperated && progress > 0)
{
progress -= (int) (efficiencyMultiplier * drainRate);
if (internalCounter % 2 == 0 && world instanceof ServerWorld)
{
ServerWorld server = (ServerWorld) world;
server.spawnParticle(ParticleTypes.LARGE_SMOKE, pos.getX() + 0.5, pos.getY() + 1, pos.getZ()
+ 0.5, 1, 0.1, 0, 0.1, 0);
}
}
if (hasOperated)
{
if (progress >= liquidRequired * stackSize)
{
ItemStack result = ItemHandlerHelper.copyStackWithSize(recipe.getOutput(), stackSize);
BloodMagicCraftedEvent.Altar event = new BloodMagicCraftedEvent.Altar(result, input.copy());
MinecraftForge.EVENT_BUS.post(event);
tileAltar.setInventorySlotContents(0, event.getOutput());
progress = 0;
if (world instanceof ServerWorld)
{
ServerWorld server = (ServerWorld) world;
server.spawnParticle(RedstoneParticleData.REDSTONE_DUST, pos.getX() + 0.5, pos.getY()
+ 1, pos.getZ() + 0.5, 40, 0.3, 0, 0.3, 0);
}
this.cooldownAfterCrafting = 30;
this.isActive = false;
}
}
} else
{
ItemStack contained = tileAltar.getStackInSlot(0);
if (contained.isEmpty() || !(contained.getItem() instanceof IBloodOrb)
|| !(contained.getItem() instanceof IBindable))
return;
BloodOrb orb = ((IBloodOrb) contained.getItem()).getOrb(contained);
Binding binding = ((IBindable) contained.getItem()).getBinding(contained);
if (binding == null || orb == null)
return;
if (fluid != null && fluid.getAmount() >= 1)
{
// int liquidDrained = Math.min((int) (altarTier.ordinal() >= 2
// ? orb.getFillRate() * (1 + consumptionMultiplier)
// : orb.getFillRate()), fluid.getAmount());
int liquidDrained = Math.min((int) (orb.getFillRate()
* (1 + consumptionMultiplier)), fluid.getAmount());
int drain = NetworkHelper.getSoulNetwork(binding).add(liquidDrained, (int) (orb.getCapacity()
* this.orbCapacityMultiplier));
fluid.setAmount(fluid.getAmount() - drain);
if (drain > 0 && internalCounter % 4 == 0 && world instanceof ServerWorld)
{
ServerWorld server = (ServerWorld) world;
server.spawnParticle(ParticleTypes.WITCH, pos.getX() + 0.5, pos.getY() + 1, pos.getZ()
+ 0.5, 1, 0, 0, 0, 0.001);
}
}
}
tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3);
}
public void checkTier()
{
AltarTier tier = AltarUtil.getTier(tileAltar.getWorld(), tileAltar.getPos());
this.altarTier = tier;
upgrade = AltarUtil.getUpgrades(tileAltar.getWorld(), tileAltar.getPos(), tier);
if (tier.equals(currentTierDisplayed))
currentTierDisplayed = AltarTier.ONE;
if (tier.equals(AltarTier.ONE))
{
upgrade = null;
isUpgraded = false;
this.consumptionMultiplier = 0;
this.efficiencyMultiplier = 1;
this.sacrificeEfficiencyMultiplier = 0;
this.selfSacrificeEfficiencyMultiplier = 0;
this.capacityMultiplier = 1;
this.orbCapacityMultiplier = 1;
this.dislocationMultiplier = 1;
this.accelerationUpgrades = 0;
this.chargingFrequency = 20;
this.chargingRate = 0;
this.maxCharge = 0;
this.totalCharge = 0;
return;
} else if (!tier.equals(AltarTier.ONE))
{
this.isUpgraded = true;
this.accelerationUpgrades = upgrade.getLevel(BloodRuneType.ACCELERATION);
this.consumptionMultiplier = (float) (0.20 * upgrade.getLevel(BloodRuneType.SPEED));
this.efficiencyMultiplier = (float) Math.pow(0.85, upgrade.getLevel(BloodRuneType.EFFICIENCY));
this.sacrificeEfficiencyMultiplier = (float) (0.10 * upgrade.getLevel(BloodRuneType.SACRIFICE));
this.selfSacrificeEfficiencyMultiplier = (float) (0.10 * upgrade.getLevel(BloodRuneType.SELF_SACRIFICE));
this.capacityMultiplier = (float) ((1 * Math.pow(1.10, upgrade.getLevel(BloodRuneType.AUGMENTED_CAPACITY)))
+ 0.20 * upgrade.getLevel(BloodRuneType.CAPACITY));
this.dislocationMultiplier = (float) (Math.pow(1.2, upgrade.getLevel(BloodRuneType.DISPLACEMENT)));
this.orbCapacityMultiplier = (float) (1 + 0.02 * upgrade.getLevel(BloodRuneType.ORB));
this.chargingFrequency = Math.max(20 - accelerationUpgrades, 1);
this.chargingRate = (int) (10 * upgrade.getLevel(BloodRuneType.CHARGING) * (1 + consumptionMultiplier / 2));
this.maxCharge = (int) (FluidAttributes.BUCKET_VOLUME * Math.max(0.5 * capacityMultiplier, 1)
* upgrade.getLevel(BloodRuneType.CHARGING));
}
this.capacity = (int) (FluidAttributes.BUCKET_VOLUME * 10 * capacityMultiplier);
this.bufferCapacity = (int) (FluidAttributes.BUCKET_VOLUME * 1 * capacityMultiplier);
if (this.fluid.getAmount() > this.capacity)
this.fluid.setAmount(this.capacity);
if (this.fluidOutput.getAmount() > this.bufferCapacity)
this.fluidOutput.setAmount(this.bufferCapacity);
if (this.fluidInput.getAmount() > this.bufferCapacity)
this.fluidInput.setAmount(this.bufferCapacity);
if (this.totalCharge > this.maxCharge)
this.totalCharge = this.maxCharge;
tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3);
}
public int fillMainTank(int amount)
{
int filledAmount = Math.min(capacity - fluid.getAmount(), amount);
fluid.setAmount(fluid.getAmount() + filledAmount);
return filledAmount;
}
public void sacrificialDaggerCall(int amount, boolean isSacrifice)
{
if (this.lockdownDuration > 0)
{
int amt = (int) Math.min(bufferCapacity
- fluidInput.getAmount(), (isSacrifice ? 1 + sacrificeEfficiencyMultiplier
: 1 + selfSacrificeEfficiencyMultiplier) * amount);
fluidInput.setAmount(fluidInput.getAmount() + amt);
} else
{
fluid.setAmount((int) (fluid.getAmount()
+ Math.min(capacity - fluid.getAmount(), (isSacrifice ? 1 + sacrificeEfficiencyMultiplier
: 1 + selfSacrificeEfficiencyMultiplier) * 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;
}
public AltarUpgrade getUpgrade()
{
return upgrade;
}
public void setUpgrade(AltarUpgrade upgrade)
{
this.upgrade = upgrade;
}
public int getCapacity()
{
return capacity;
}
public FluidStack getFluid()
{
return fluid;
}
public int getFluidAmount()
{
return fluid.getAmount();
}
public int getCurrentBlood()
{
return getFluidAmount();
}
public AltarTier getTier()
{
return altarTier;
}
public void setTier(AltarTier tier)
{
this.altarTier = tier;
}
public int getProgress()
{
return progress;
}
public float getSacrificeMultiplier()
{
return sacrificeEfficiencyMultiplier;
}
public float getSelfSacrificeMultiplier()
{
return selfSacrificeEfficiencyMultiplier;
}
public float getOrbMultiplier()
{
return orbCapacityMultiplier;
}
public float getDislocationMultiplier()
{
return dislocationMultiplier;
}
public float getConsumptionMultiplier()
{
return consumptionMultiplier;
}
public float getConsumptionRate()
{
return consumptionRate;
}
public int getLiquidRequired()
{
return liquidRequired;
}
public int getBufferCapacity()
{
return bufferCapacity;
}
public boolean setCurrentTierDisplayed(AltarTier altarTier)
{
if (currentTierDisplayed == altarTier)
return false;
else
currentTierDisplayed = altarTier;
return true;
}
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);
}
public void setActive()
{
// if (tileAltar.getStackInSlot(0).isEmpty())
// {
// isActive = false;
// }
}
public boolean isActive()
{
return isActive;
}
public void requestPauseAfterCrafting(int amount)
{
if (this.isActive)
{
this.cooldownAfterCrafting = amount;
}
}
public int getChargingRate()
{
return chargingRate;
}
public int getTotalCharge()
{
return totalCharge;
}
public int getChargingFrequency()
{
return chargingFrequency == 0 ? 1 : chargingFrequency;
}
public int fill(FluidStack resource, boolean doFill)
{
if (resource == null || resource.getFluid() != BloodMagicBlocks.LIFE_ESSENCE_FLUID.get())
{
return 0;
}
if (!doFill)
{
if (fluidInput == null)
{
return Math.min(bufferCapacity, resource.getAmount());
}
if (!fluidInput.isFluidEqual(resource))
{
return 0;
}
return Math.min(bufferCapacity - fluidInput.getAmount(), resource.getAmount());
}
if (fluidInput == null)
{
fluidInput = new FluidStack(resource, Math.min(bufferCapacity, resource.getAmount()));
return fluidInput.getAmount();
}
if (!fluidInput.isFluidEqual(resource))
{
return 0;
}
int filled = bufferCapacity - fluidInput.getAmount();
if (resource.getAmount() < filled)
{
fluidInput.setAmount(fluidInput.getAmount() + resource.getAmount());
filled = resource.getAmount();
} else
{
fluidInput.setAmount(bufferCapacity);
}
return filled;
}
public FluidStack drain(FluidStack resource, boolean doDrain)
{
if (resource == null || !resource.isFluidEqual(fluidOutput))
{
return null;
}
return drain(resource.getAmount(), doDrain);
}
public FluidStack drain(int maxDrain, boolean doDrain)
{
if (fluidOutput == null)
{
return null;
}
int drained = maxDrain;
if (fluidOutput.getAmount() < drained)
{
drained = fluidOutput.getAmount();
}
FluidStack stack = new FluidStack(fluidOutput, drained);
if (doDrain)
{
fluidOutput.setAmount(fluidOutput.getAmount() - drained);
}
return stack;
}
// @Override
// public IFluidTankProperties[] getTankProperties()
// {
// return new IFluidTankProperties[]
// { new FluidTankPropertiesWrapper(new FluidTank(fluid, capacity)) };
// }
public AltarTier getCurrentTierDisplayed()
{
return currentTierDisplayed;
}
static class VariableSizeFluidHandler implements IFluidHandler
{
BloodAltar altar;
VariableSizeFluidHandler(BloodAltar altar)
{
this.altar = altar;
}
@Override
public int getTanks()
{
// TODO Auto-generated method stub
return 1;
}
@Override
public FluidStack getFluidInTank(int tank)
{
// TODO Auto-generated method stub
return null;
}
@Override
public int getTankCapacity(int tank)
{
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean isFluidValid(int tank, FluidStack stack)
{
return false;
}
@Override
public int fill(FluidStack resource, FluidAction action)
{
return altar.fill(resource, action == FluidAction.EXECUTE);
}
@Override
public FluidStack drain(FluidStack resource, FluidAction action)
{
return altar.drain(resource, action == FluidAction.EXECUTE);
}
@Override
public FluidStack drain(int maxDrain, FluidAction action)
{
// TODO Auto-generated method stub
return null;
}
}
}

View file

@ -0,0 +1,25 @@
package wayoftime.bloodmagic.altar;
import java.util.Locale;
/**
* List of different components used to construct different tiers of altars.
*/
public enum ComponentType
{
GLOWSTONE, BLOODSTONE, BEACON, BLOODRUNE, CRYSTAL, NOTAIR;
public static final ComponentType[] VALUES = values();
private static final String BASE = "chat.bloodmagic.altar.comp.";
private String key;
ComponentType()
{
this.key = BASE + name().toLowerCase(Locale.ENGLISH);
}
public String getKey()
{
return key;
}
}

View file

@ -0,0 +1,13 @@
package wayoftime.bloodmagic.altar;
import javax.annotation.Nullable;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public interface IAltarComponent
{
@Nullable
ComponentType getType(World world, BlockState state, BlockPos pos);
}

View file

@ -0,0 +1,55 @@
package wayoftime.bloodmagic.altar;
public interface IBloodAltar
{
int getCapacity();
int getCurrentBlood();
AltarTier getTier();
int getProgress();
float getSacrificeMultiplier();
float getSelfSacrificeMultiplier();
float getOrbMultiplier();
float getDislocationMultiplier();
float getConsumptionMultiplier();
float getConsumptionRate();
int getChargingRate();
int getChargingFrequency();
int getTotalCharge();
int getLiquidRequired();
int getBufferCapacity();
void sacrificialDaggerCall(int amount, boolean isSacrifice);
void startCycle();
void checkTier();
boolean isActive();
void setActive();
int fillMainTank(int amount);
/**
* Will set the altar to initiate a cooldown cycle after it crafts before
* starting to craft again, giving the user time to interact with the altar.
* This can only be set while the altar is not active.
*
* @param cooldown - How long the cooldown should last
*/
void requestPauseAfterCrafting(int cooldown);
}