Finished the Altar

This commit is contained in:
Arcaratus 2015-11-03 10:34:11 -05:00
parent ac5402df6b
commit ab60e5f3fe
10 changed files with 415 additions and 65 deletions

View file

@ -15,7 +15,7 @@ import java.util.List;
public class BloodAltar {
public static EnumAltarTier getAltarTier(World world, BlockPos pos) {
for (int i = EnumAltarTier.MAXTIERS; i >= 2; i--) {
for (int i = EnumAltarTier.MAXTIERS - 1; i >= 2; i--) {
if (checkAltarIsValid(world, pos, i)) {
return EnumAltarTier.values()[i];
}
@ -47,13 +47,15 @@ public class BloodAltar {
return true;
}
public static AltarUpgrade getUpgrades(World world, BlockPos pos, int altarTier) {
if (world.isRemote) {
public static AltarUpgrade getUpgrades(World world, BlockPos pos, EnumAltarTier altarTier)
{
if (world.isRemote)
{
return null;
}
AltarUpgrade upgrades = new AltarUpgrade();
List<AltarComponent> list = EnumAltarTier.values()[altarTier].getAltarComponents();
List<AltarComponent> list = altarTier.getAltarComponents();
for (AltarComponent altarComponent : list) {
BlockPos componentPos = pos.add(altarComponent.getOffset());

View file

@ -18,6 +18,19 @@ public class AltarUpgrade {
}
public AltarUpgrade(int speedCount, int efficiencyCount, int sacrificeCount, int selfSacrificeCount, int displacementCount, int capacityCount, int orbCapacityCount, int betterCapacityCount, int accelerationCount)
{
this.speedCount = speedCount;
this.efficiencyCount = efficiencyCount;
this.sacrificeCount = sacrificeCount;
this.selfSacrificeCount = selfSacrificeCount;
this.displacementCount = displacementCount;
this.capacityCount = capacityCount;
this.orbCapacityCount = orbCapacityCount;
this.betterCapacityCount = betterCapacityCount;
this.accelerationCount = accelerationCount;
}
// Adders
public AltarUpgrade addSpeed() {

View file

@ -0,0 +1,5 @@
package WayofTime.bloodmagic.api.iface;
public interface IAltarReader
{
}

View file

@ -1,9 +1,17 @@
package WayofTime.bloodmagic.block;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.iface.IAltarReader;
import WayofTime.bloodmagic.tile.TileAltar;
import WayofTime.bloodmagic.tile.TileInventory;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
public class BlockAltar extends BlockContainer {
@ -37,7 +45,54 @@ public class BlockAltar extends BlockContainer {
@Override
public TileEntity createNewTileEntity(World world, int meta) {
// return new TileAltar();
return null;
return new TileAltar();
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ)
{
TileAltar altar = (TileAltar) world.getTileEntity(pos);
if (altar == null || player.isSneaking())
{
return false;
}
ItemStack playerItem = player.getCurrentEquippedItem();
if (playerItem != null)
{
if (playerItem.getItem() instanceof IAltarReader)
{
playerItem.getItem().onItemRightClick(playerItem, world, player);
return true;
}
}
if (altar.getStackInSlot(0) == null && playerItem != null)
{
ItemStack newItem = playerItem.copy();
newItem.stackSize = 1;
--playerItem.stackSize;
altar.setInventorySlotContents(0, newItem);
// altar.startCycle();
}
else if (altar.getStackInSlot(0) != null && playerItem == null)
{
player.inventory.addItemStackToInventory(altar.getStackInSlot(0));
altar.setInventorySlotContents(0, null);
// altar.setActive();
}
world.markBlockForUpdate(pos);
return true;
}
@Override
public void breakBlock(World world, BlockPos blockPos, IBlockState blockState)
{
TileInventory tileInventory = (TileInventory) world.getTileEntity(blockPos);
if (tileInventory != null) tileInventory.dropItems();
super.breakBlock(world, blockPos, blockState);
}
}

View file

@ -0,0 +1,6 @@
package WayofTime.bloodmagic.item;
public class ItemSacrificialDagger
{
}

View file

@ -1,6 +1,8 @@
package WayofTime.bloodmagic.item.sigil;
import WayofTime.bloodmagic.api.altar.IBloodAltar;
import WayofTime.bloodmagic.api.iface.IAltarReader;
import WayofTime.bloodmagic.api.iface.ISigil;
import WayofTime.bloodmagic.api.util.helper.BindableHelper;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import WayofTime.bloodmagic.util.ChatUtil;
@ -12,7 +14,8 @@ import net.minecraft.util.ChatComponentText;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
public class ItemSigilDivination extends ItemSigilBase {
public class ItemSigilDivination extends ItemSigilBase implements ISigil, IAltarReader
{
public ItemSigilDivination() {
super("divination");
@ -29,14 +32,27 @@ public class ItemSigilDivination extends ItemSigilBase {
if (position == null) {
ChatUtil.sendNoSpam(player, new ChatComponentText(TextHelper.localize(tooltipBase + "currentEssence", currentEssence)));
return stack;
} else {
}
else
{
if (position.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
TileEntity tile = world.getTileEntity(position.getBlockPos());
if (!(tile instanceof IBloodAltar)) {
ChatUtil.sendNoSpam(player, new ChatComponentText(TextHelper.localize(tooltipBase + "currentEssence", currentEssence)));
return stack;
if (tile != null && tile instanceof IBloodAltar)
{
int tier = ((IBloodAltar) tile).getTier() + 1;
currentEssence = ((IBloodAltar) tile).getCurrentBlood();
int capacity = ((IBloodAltar) tile).getCapacity();
ChatUtil.sendNoSpam(player, new ChatComponentText(TextHelper.localize(tooltipBase + "currentAltarTier", tier)), new ChatComponentText(TextHelper.localize(tooltipBase + "currentEssence", currentEssence)), new ChatComponentText(TextHelper.localize(tooltipBase + "currentAltarCapacity", capacity)));
}
else
{
ChatUtil.sendNoSpam(player, new ChatComponentText(TextHelper.localize(tooltipBase + "currentEssence", currentEssence)));
}
return stack;
}
}
}

View file

@ -8,6 +8,7 @@ import WayofTime.bloodmagic.block.BlockLifeEssence;
import WayofTime.bloodmagic.block.BlockRitualController;
import WayofTime.bloodmagic.item.block.ItemBlockBloodRune;
import WayofTime.bloodmagic.item.block.ItemBlockRitualController;
import WayofTime.bloodmagic.tile.TileAltar;
import WayofTime.bloodmagic.tile.TileImperfectRitualStone;
import WayofTime.bloodmagic.tile.TileMasterRitualStone;
import WayofTime.bloodmagic.util.helper.InventoryRenderHelper;
@ -16,7 +17,8 @@ import net.minecraft.item.ItemBlock;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class ModBlocks {
public class ModBlocks
{
public static Block altar;
public static Block bloodRune;
public static Block ritualStone;
@ -26,7 +28,8 @@ public class ModBlocks {
public static Block crystal;
public static Block bloodStone;
public static void init() {
public static void init()
{
FluidRegistry.registerFluid(BlockLifeEssence.getLifeEssence());
lifeEssence = registerBlock(new BlockLifeEssence());
@ -37,12 +40,15 @@ public class ModBlocks {
initTiles();
}
public static void initTiles() {
public static void initTiles()
{
GameRegistry.registerTileEntity(TileAltar.class, BloodMagic.MODID + ":" + TileAltar.class.getSimpleName());
GameRegistry.registerTileEntity(TileImperfectRitualStone.class, BloodMagic.MODID + ":" + TileImperfectRitualStone.class.getSimpleName());
GameRegistry.registerTileEntity(TileMasterRitualStone.class, BloodMagic.MODID + ":" + TileMasterRitualStone.class.getSimpleName());
}
public static void initRenders() {
public static void initRenders()
{
InventoryRenderHelper renderHelper = BloodMagic.instance.getRenderHelper();
renderHelper.fluidRender(lifeEssence);

View file

@ -5,95 +5,336 @@ import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.altar.AltarRecipe;
import WayofTime.bloodmagic.api.altar.AltarUpgrade;
import WayofTime.bloodmagic.api.altar.EnumAltarTier;
import WayofTime.bloodmagic.api.altar.IBloodAltar;
import WayofTime.bloodmagic.api.registry.AltarRecipeRegistry;
import WayofTime.bloodmagic.block.BlockLifeEssence;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.gui.IUpdatePlayerListBox;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fluids.*;
public class TileAltar extends TileInventory implements IUpdatePlayerListBox, IFluidTank, IFluidHandler
{
public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlayerListBox, IFluidTank, IFluidHandler {
private int tier;
private AltarUpgrade upgrade = new AltarUpgrade();
private FluidStack fluid = new FluidStack(BloodMagicAPI.getLifeEssence(), 0);
protected FluidStack fluidOutput = new FluidStack(BlockLifeEssence.getLifeEssence(), 0);
protected FluidStack fluidInput = new FluidStack(BlockLifeEssence.getLifeEssence(), 0);
private int capacity;
public TileAltar()
{
private int upgradeLevel;
private int resultID;
private int resultDamage;
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;
private float orbCapacityMultiplier;
private float dislocationMultiplier;
private int accelerationUpgrades;
private boolean isUpgraded;
private boolean isResultBlock;
private int bufferCapacity;
private int progress;
public boolean isActive;
private int lockdownDuration;
private int demonBloodDuration;
private int cooldownAfterCrafting = 500;
public TileAltar() {
super(1, "altar");
this.capacity = 10000;
this.capacity = FluidContainerRegistry.BUCKET_VOLUME * 10;
this.bufferCapacity = FluidContainerRegistry.BUCKET_VOLUME;
this.resultID = 0;
this.resultDamage = 0;
this.isActive = false;
this.consumptionRate = 0;
this.drainRate = 0;
this.consumptionMultiplier = 0;
this.efficiencyMultiplier = 0;
this.capacityMultiplier = 1;
this.isUpgraded = false;
this.isResultBlock = false;
this.upgradeLevel = 0;
this.progress = 0;
this.lockdownDuration = 0;
this.demonBloodDuration = 0;
}
@Override
public void update()
{
if (getWorld().isRemote)
{
public void readFromNBT(NBTTagCompound par1NBTTagCompound) {
super.readFromNBT(par1NBTTagCompound);
resultID = par1NBTTagCompound.getInteger("resultID");
resultDamage = par1NBTTagCompound.getInteger("resultDamage");
if (!par1NBTTagCompound.hasKey("Empty")) {
FluidStack fluid = this.fluid.loadFluidStackFromNBT(par1NBTTagCompound);
if (fluid != null) {
setMainFluid(fluid);
}
FluidStack fluidOut = new FluidStack(BloodMagicAPI.getLifeEssence(), par1NBTTagCompound.getInteger("outputAmount"));
if (fluidOut != null) {
setOutputFluid(fluidOut);
}
FluidStack fluidIn = new FluidStack(BloodMagicAPI.getLifeEssence(), par1NBTTagCompound.getInteger("inputAmount"));
if (fluidIn != null) {
setInputFluid(fluidIn);
}
}
upgradeLevel = par1NBTTagCompound.getInteger("upgradeLevel");
isActive = par1NBTTagCompound.getBoolean("isActive");
liquidRequired = par1NBTTagCompound.getInteger("liquidRequired");
canBeFilled = par1NBTTagCompound.getBoolean("canBeFilled");
isUpgraded = par1NBTTagCompound.getBoolean("isUpgraded");
consumptionRate = par1NBTTagCompound.getInteger("consumptionRate");
drainRate = par1NBTTagCompound.getInteger("drainRate");
consumptionMultiplier = par1NBTTagCompound.getFloat("consumptionMultiplier");
efficiencyMultiplier = par1NBTTagCompound.getFloat("efficiencyMultiplier");
selfSacrificeEfficiencyMultiplier = par1NBTTagCompound.getFloat("selfSacrificeEfficiencyMultiplier");
sacrificeEfficiencyMultiplier = par1NBTTagCompound.getFloat("sacrificeEfficiencyMultiplier");
capacityMultiplier = par1NBTTagCompound.getFloat("capacityMultiplier");
orbCapacityMultiplier = par1NBTTagCompound.getFloat("orbCapacityMultiplier");
dislocationMultiplier = par1NBTTagCompound.getFloat("dislocationMultiplier");
capacity = par1NBTTagCompound.getInteger("capacity");
bufferCapacity = par1NBTTagCompound.getInteger("bufferCapacity");
progress = par1NBTTagCompound.getInteger("progress");
isResultBlock = par1NBTTagCompound.getBoolean("isResultBlock");
lockdownDuration = par1NBTTagCompound.getInteger("lockdownDuration");
accelerationUpgrades = par1NBTTagCompound.getInteger("accelerationUpgrades");
demonBloodDuration = par1NBTTagCompound.getInteger("demonBloodDuration");
cooldownAfterCrafting = par1NBTTagCompound.getInteger("cooldownAfterCrafting");
}
@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound) {
super.writeToNBT(par1NBTTagCompound);
par1NBTTagCompound.setInteger("resultID", resultID);
par1NBTTagCompound.setInteger("resultDamage", resultDamage);
if (fluid != null) {
fluid.writeToNBT(par1NBTTagCompound);
} else {
par1NBTTagCompound.setString("Empty", "");
}
if (fluidOutput != null) {
par1NBTTagCompound.setInteger("outputAmount", fluidOutput.amount);
}
if (fluidInput != null) {
par1NBTTagCompound.setInteger("inputAmount", fluidInput.amount);
}
par1NBTTagCompound.setInteger("upgradeLevel", upgradeLevel);
par1NBTTagCompound.setBoolean("isActive", isActive);
par1NBTTagCompound.setInteger("liquidRequired", liquidRequired);
par1NBTTagCompound.setBoolean("canBeFilled", canBeFilled);
par1NBTTagCompound.setBoolean("isUpgraded", isUpgraded);
par1NBTTagCompound.setInteger("consumptionRate", consumptionRate);
par1NBTTagCompound.setInteger("drainRate", drainRate);
par1NBTTagCompound.setFloat("consumptionMultiplier", consumptionMultiplier);
par1NBTTagCompound.setFloat("efficiencyMultiplier", efficiencyMultiplier);
par1NBTTagCompound.setFloat("sacrificeEfficiencyMultiplier", sacrificeEfficiencyMultiplier);
par1NBTTagCompound.setFloat("selfSacrificeEfficiencyMultiplier", selfSacrificeEfficiencyMultiplier);
par1NBTTagCompound.setBoolean("isResultBlock", isResultBlock);
par1NBTTagCompound.setFloat("capacityMultiplier", capacityMultiplier);
par1NBTTagCompound.setFloat("orbCapacityMultiplier", orbCapacityMultiplier);
par1NBTTagCompound.setFloat("dislocationMultiplier", dislocationMultiplier);
par1NBTTagCompound.setInteger("capacity", capacity);
par1NBTTagCompound.setInteger("progress", progress);
par1NBTTagCompound.setInteger("bufferCapacity", bufferCapacity);
par1NBTTagCompound.setInteger("lockdownDuration", lockdownDuration);
par1NBTTagCompound.setInteger("accelerationUpgrades", this.accelerationUpgrades);
par1NBTTagCompound.setInteger("demonBloodDuration", demonBloodDuration);
par1NBTTagCompound.setInteger("cooldownAfterCrafting", cooldownAfterCrafting);
}
@Override
public void update() {
if (getWorld().isRemote) {
return;
}
if (getWorld().getTotalWorldTime() % (Math.max(20 - getUpgrade().getSpeedCount(), 1)) == 0)
{
if (getWorld().getTotalWorldTime() % (Math.max(20 - getUpgrade().getSpeedCount(), 1)) == 0) {
everySecond();
}
if (getWorld().getTotalWorldTime() % 100 == 0)
{
if (getWorld().getTotalWorldTime() % 100 == 0) {
everyFiveSeconds();
}
}
private void everySecond()
{
// Do recipes
if (AltarRecipeRegistry.getRecipes().containsKey(getStackInSlot(0)))
{
AltarRecipe recipe = AltarRecipeRegistry.getRecipeForInput(getStackInSlot(0));
private void everySecond() {
startCycle();
}
if (!(tier >= recipe.minTier))
{
return;
private void everyFiveSeconds() {
checkTier();
}
public void startCycle() {
if (worldObj != null) {
worldObj.markBlockForUpdate(pos);
}
if (fluid == null || fluid.amount <= 0) {
return;
}
if (getStackInSlot(0) != null) {
// Do recipes
if (AltarRecipeRegistry.getRecipes().containsKey(getStackInSlot(0))) {
AltarRecipe recipe = AltarRecipeRegistry.getRecipeForInput(getStackInSlot(0));
if (tier >= recipe.getMinTier()) {
this.liquidRequired = recipe.getSyphon();
// this.canBeFilled = recipe
this.consumptionRate = recipe.getConsumeRate();
this.drainRate = recipe.getDrainRate();
this.isActive = true;
}
}
}
}
private void everyFiveSeconds()
{
checkTier();
}
private void checkTier()
{
private void checkTier() {
// TODO - Write checking for tier stuff
EnumAltarTier tier = BloodAltar.getAltarTier(getWorld(), getPos());
if (tier.equals(EnumAltarTier.ONE))
{
if (tier.equals(EnumAltarTier.ONE)) {
upgrade = new AltarUpgrade();
return;
} else {
upgrade = BloodAltar.getUpgrades(worldObj, pos, tier);
}
if (this.fluid.amount > this.capacity) {
this.fluid.amount = this.capacity;
}
worldObj.markBlockForUpdate(pos);
}
public void sacrificialDaggerCall(int amount, boolean isSacrifice) {
if (!isSacrifice && this.lockdownDuration > 0) {
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);
}
}
public TileAltar setUpgrade(AltarUpgrade upgrade)
{
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack) {
return slot == 0;
}
public TileAltar setUpgrade(AltarUpgrade upgrade) {
this.upgrade = upgrade;
return this;
}
public AltarUpgrade getUpgrade()
{
public AltarUpgrade getUpgrade() {
return upgrade;
}
public TileAltar setTier(int tier)
{
public TileAltar setTier(int tier) {
this.tier = tier;
return this;
}
@Override
public int getCapacity() {
return capacity;
}
@Override
public int getCurrentBlood() {
return getFluidAmount();
}
@Override
public int getTier() {
return tier;
return upgradeLevel;
}
@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;
}
// IFluidHandler
@ -140,11 +381,6 @@ public class TileAltar extends TileInventory implements IUpdatePlayerListBox, IF
return fluid.amount;
}
@Override
public int getCapacity() {
return capacity;
}
@Override
public FluidTankInfo getInfo() {
return new FluidTankInfo(this);

View file

@ -22,8 +22,11 @@ public class TileInventory extends TileEntity implements IInventory {
}
public void dropItems() {
for (ItemStack stack : inventory)
getWorld().spawnEntityInWorld(new EntityItem(getWorld(), getPos().getX(), pos.getY(), pos.getZ(), stack));
if (inventory != null)
{
for (ItemStack stack : inventory)
getWorld().spawnEntityInWorld(new EntityItem(getWorld(), getPos().getX(), pos.getY(), pos.getZ(), stack));
}
}
// IInventory
@ -51,13 +54,19 @@ public class TileInventory extends TileEntity implements IInventory {
}
@Override
public ItemStack getStackInSlotOnClosing(int index) {
return inventory[index];
public ItemStack getStackInSlotOnClosing(int slot) {
ItemStack stack = getStackInSlot(slot);
if (stack != null)
setInventorySlotContents(slot, null);
return stack;
}
@Override
public void setInventorySlotContents(int index, ItemStack stack) {
public void setInventorySlotContents(int slot, ItemStack stack) {
inventory[slot] = stack;
worldObj.markBlockForUpdate(pos);
if (stack != null && stack.stackSize > getInventoryStackLimit())
stack.stackSize = getInventoryStackLimit();
}
@Override

View file

@ -82,7 +82,9 @@ tooltip.BloodMagic.sigil.air.desc=&oI feel lighter already...
tooltip.BloodMagic.sigil.bloodLight.desc=&oI see a light!
tooltip.BloodMagic.sigil.compression.desc=&oHands of Diamonds
tooltip.BloodMagic.sigil.divination.desc=&oPeer into the soul
tooltip.BloodMagic.sigil.divination.currentAltarTier=Current Tier: %d
tooltip.BloodMagic.sigil.divination.currentEssence=Current Essence: %d LP
tooltip.BloodMagic.sigil.divination.currentAltarCapacity=Current Capacity: %d LP
tooltip.BloodMagic.activationCrystal.weak=Activates low-level rituals
tooltip.BloodMagic.activationCrystal.awakened=Activates more powerful rituals
tooltip.BloodMagic.activationCrystal.creative=Creative Only - Activates any ritual