Altar works

This commit is contained in:
Arcaratus 2015-11-27 20:15:19 -05:00
parent 352c6b9e5f
commit a6d329cf98
12 changed files with 266 additions and 110 deletions

View file

@ -1,7 +1,7 @@
package WayofTime.bloodmagic;
import WayofTime.bloodmagic.api.util.helper.LogHelper;
import WayofTime.bloodmagic.network.AlchemicalWizardryPacketHandler;
import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
import WayofTime.bloodmagic.proxy.CommonProxy;
import WayofTime.bloodmagic.registry.*;
import WayofTime.bloodmagic.util.handler.EventHandler;
@ -66,7 +66,7 @@ public class BloodMagic {
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
AlchemicalWizardryPacketHandler.init();
BloodMagicPacketHandler.init();
ModRecipes.init();
ModRituals.initRituals();

View file

@ -5,6 +5,7 @@ import WayofTime.bloodmagic.api.altar.*;
import WayofTime.bloodmagic.block.BlockBloodRune;
import WayofTime.bloodmagic.block.BlockBloodStoneBrick;
import WayofTime.bloodmagic.registry.ModBlocks;
import net.minecraft.block.BlockAir;
import net.minecraft.block.BlockBeacon;
import net.minecraft.block.BlockGlowstone;
import net.minecraft.init.Blocks;
@ -15,8 +16,17 @@ import java.util.List;
public class BloodAltar {
static {
EnumAltarTier.ONE.buildComponents();
EnumAltarTier.TWO.buildComponents();
EnumAltarTier.THREE.buildComponents();
EnumAltarTier.FOUR.buildComponents();
EnumAltarTier.FIVE.buildComponents();
EnumAltarTier.SIX.buildComponents();
}
public static EnumAltarTier getAltarTier(World world, BlockPos pos) {
for (int i = EnumAltarTier.MAXTIERS - 1; i >= 2; i--) {
for (int i = EnumAltarTier.MAXTIERS - 1; i >= 1; i--) {
if (checkAltarIsValid(world, pos, i)) {
return EnumAltarTier.values()[i];
}
@ -26,6 +36,7 @@ public class BloodAltar {
}
public static boolean checkAltarIsValid(World world, BlockPos worldPos, int altarTier) {
for (AltarComponent altarComponent : EnumAltarTier.values()[altarTier].getAltarComponents()) {
BlockPos componentPos = worldPos.add(altarComponent.getOffset());
@ -35,8 +46,9 @@ public class BloodAltar {
if (!checkRune(altarComponent, worldBlock)) {
return false;
}
} else {
if (((altarComponent.getBlockStack().getBlock() != worldBlock.getBlock()) || (altarComponent.getBlockStack().getMeta() != worldBlock.getMeta())) && (altarComponent.getBlockStack().getBlock() == Blocks.air && !world.isAirBlock(componentPos))) {
} else if (!altarComponent.isBloodRune()) {
if (world.isAirBlock(componentPos)) return false;
if (((altarComponent.getBlockStack().getBlock() != worldBlock.getBlock()) || (altarComponent.getBlockStack().getMeta() != worldBlock.getMeta()))) {
if (!checkSpecials(altarComponent, worldBlock)) {
return false;
}
@ -44,7 +56,7 @@ public class BloodAltar {
}
}
return false;
return true;
}
public static AltarUpgrade getUpgrades(World world, BlockPos pos, EnumAltarTier altarTier) {
@ -111,7 +123,6 @@ public class BloodAltar {
if (blockStack.getBlock() instanceof BlockBloodRune || (blockStack.getBlock() instanceof IAltarComponent && (((IAltarComponent) blockStack.getBlock()).getType(blockStack.getMeta()) == EnumAltarComponent.BLOODRUNE))) {
return true;
}
}
return false;
}
@ -119,11 +130,11 @@ public class BloodAltar {
private static boolean checkSpecials(AltarComponent altarComponent, BlockStack blockStack) {
if (altarComponent.getBlockStack().getBlock() == ModBlocks.bloodStoneBrick)
if (blockStack.getBlock() instanceof BlockBloodStoneBrick || (blockStack.getBlock() instanceof IAltarComponent && (((IAltarComponent) blockStack.getBlock()).getType(blockStack.getMeta()) == EnumAltarComponent.BLOODSTONE)))
return true;
return true;
if (altarComponent.getBlockStack().getBlock() == ModBlocks.crystal)
// if (altarComponent.getBlockStack().getBlock() == ModBlocks.crystal)
// if (blockStack.getBlock() instanceof BlockCrystal || (blockStack.getBlock() instanceof IAltarComponent && (((IAltarComponent) blockStack.getBlock()).getType(blockStack.getMeta()) == EnumAltarComponent.CRYSTAL)))
return true;
// return true;
if (altarComponent.getBlockStack().getBlock() == Blocks.glowstone)
if (blockStack.getBlock() instanceof BlockGlowstone || (blockStack.getBlock() instanceof IAltarComponent && (((IAltarComponent) blockStack.getBlock()).getType(blockStack.getMeta()) == EnumAltarComponent.GLOWSTONE)))
@ -133,6 +144,10 @@ public class BloodAltar {
if (blockStack.getBlock() instanceof BlockBeacon || (blockStack.getBlock() instanceof IAltarComponent && (((IAltarComponent) blockStack.getBlock()).getType(blockStack.getMeta()) == EnumAltarComponent.BEACON)))
return true;
if (altarComponent.getBlockStack().getBlock() == Blocks.air)
if (blockStack.getBlock() != Blocks.air)
return true;
return false;
}
}

View file

@ -20,10 +20,34 @@ public class NBTHolder {
public static final String NBT_RUNTIME = "runtime";
public static final String NBT_REAGENTTANK = "reagentTanks";
public static final String NBT_CURRENT_INCENSE = "BM:CurrentIncense";
public static final String NBT_EMPTY = "Empty";
public static final String NBT_OUTPUT_AMOUNT = "outputAmount";
public static final String NBT_INPUT_AMOUNT = "inputAmount";
//Altar Shtuff
public static final String NBT_ALTAR_TIER = "upgradeLevel";
public static final String NBT_ALTAR_ACTIVE = "isActive";
public static final String NBT_ALTAR_LIQUID_REQ = "liquidRequired";
public static final String NBT_ALTAR_FILLABLE = "canBeFilled";
public static final String NBT_ALTAR_UPGRADED = "isUpgraded";
public static final String NBT_ALTAR_CONSUMPTION_RATE = "consumptionRate";
public static final String NBT_ALTAR_DRAIN_RATE = "drainRate";
public static final String NBT_ALTAR_CONSUMPTION_MULTIPLIER = "consumptionMultiplier";
public static final String NBT_ALTAR_EFFICIENCY_MULTIPLIER = "efficiencyMultiplier";
public static final String NBT_ALTAR_SELF_SACRIFICE_MULTIPLIER = "selfSacrificeMultiplier";
public static final String NBT_ALTAR_SACRIFICE_MULTIPLIER = "sacrificeMultiplier";
public static final String NBT_ALTAR_CAPACITY_MULTIPLIER = "capacityMultiplier";
public static final String NBT_ALTAR_ORB_CAPACITY_MULTIPLIER = "orbCapacityMultiplier";
public static final String NBT_ALTAR_DISLOCATION_MULTIPLIER = "dislocationMultiplier";
public static final String NBT_ALTAR_CAPACITY = "capacity";
public static final String NBT_ALTAR_BUFFER_CAPACITY = "bufferCapacity";
public static final String NBT_ALTAR_PROGRESS = "progress";
public static final String NBT_ALTAR_IS_RESULT_BLOCK = "isResultBlock";
public static final String NBT_ALTAR_LOCKDOWN_DURATION = "lockdownDuration";
public static final String NBT_ALTAR_ACCELERATION_UPGRADES = "accelerationUpgrades";
public static final String NBT_ALTAR_DEMON_BLOOD_DURATION = "demonBloodDuration";
public static final String NBT_ALTAR_COOLDOWN_AFTER_CRAFTING = "cooldownAfterCrafting";
public static final String NBT_STORED_LP = "storedLP";
public static ItemStack checkNBT(ItemStack stack) {

View file

@ -1,8 +1,8 @@
package WayofTime.bloodmagic.api.altar;
import WayofTime.bloodmagic.api.ItemStackWrapper;
import lombok.Getter;
import lombok.ToString;
import net.minecraft.item.ItemStack;
import javax.annotation.Nullable;
@ -12,7 +12,7 @@ public class AltarRecipe {
public final int syphon, consumeRate, drainRate;
public final boolean useTag;
public final ItemStackWrapper input, output;
public final ItemStack input, output;
public final EnumAltarTier minTier;
/**
@ -27,7 +27,26 @@ public class AltarRecipe {
* @param drainRate - The rate at which LP is drained during crafting
* @param useTag -
*/
public AltarRecipe(ItemStackWrapper input, @Nullable ItemStackWrapper output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate, boolean useTag) {
// public AltarRecipe(ItemStackWrapper input, @Nullable ItemStackWrapper output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate, boolean useTag) {
// this.input = input;
// this.output = output;
// this.minTier = minTier;
// this.syphon = syphon;
// this.consumeRate = consumeRate;
// this.drainRate = drainRate;
// this.useTag = useTag;
// }
//
// public AltarRecipe(ItemStackWrapper input, ItemStackWrapper output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate) {
// this(input, output, minTier, syphon, consumeRate, drainRate, false);
// }
//
// public AltarRecipe(ItemStackWrapper input, EnumAltarTier minTier, int consumeRate, int drainRate) {
// this(input, null, minTier, 0, consumeRate, drainRate);
// }
public AltarRecipe(ItemStack input, @Nullable ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate, boolean useTag) {
this.input = input;
this.output = output;
this.minTier = minTier;
@ -37,11 +56,11 @@ public class AltarRecipe {
this.useTag = useTag;
}
public AltarRecipe(ItemStackWrapper input, ItemStackWrapper output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate) {
public AltarRecipe(ItemStack input, ItemStack output, EnumAltarTier minTier, int syphon, int consumeRate, int drainRate) {
this(input, output, minTier, syphon, consumeRate, drainRate, false);
}
public AltarRecipe (ItemStackWrapper input, EnumAltarTier minTier, int consumeRate, int drainRate) {
public AltarRecipe(ItemStack input, EnumAltarTier minTier, int consumeRate, int drainRate) {
this(input, null, minTier, 0, consumeRate, drainRate);
}
}

View file

@ -1,16 +1,16 @@
package WayofTime.bloodmagic.api.registry;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.ItemStackWrapper;
import WayofTime.bloodmagic.api.altar.AltarRecipe;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import lombok.Getter;
import net.minecraft.item.ItemStack;
public class AltarRecipeRegistry {
@Getter
private static BiMap<ItemStackWrapper, AltarRecipe> recipes = HashBiMap.create();
private static BiMap<ItemStack, AltarRecipe> recipes = HashBiMap.create();
public static void registerRecipe(AltarRecipe recipe) {
if (!recipes.containsValue(recipe))
@ -19,7 +19,7 @@ public class AltarRecipeRegistry {
BloodMagicAPI.getLogger().error("Error adding recipe for " + recipe.input.getDisplayName() + (recipe.output == null ? "" : " -> " + recipe.output.getDisplayName()) + ". Recipe already exists.");
}
public static AltarRecipe getRecipeForInput(ItemStackWrapper input) {
public static AltarRecipe getRecipeForInput(ItemStack input) {
return recipes.get(input);
}
}

View file

@ -65,7 +65,10 @@ public class BlockAltar extends BlockContainer {
}
}
Utils.insertItemToTile(altar, player);
if (Utils.insertItemToTile(altar, player))
altar.startCycle();
else
altar.setActive();
world.markBlockForUpdate(pos);
return true;

View file

@ -9,7 +9,7 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;
public class AlchemicalWizardryPacketHandler {
public class BloodMagicPacketHandler {
public static final SimpleNetworkWrapper INSTANCE = new SimpleNetworkWrapper(BloodMagic.MODID);

View file

@ -1,10 +1,10 @@
package WayofTime.bloodmagic.registry;
import WayofTime.bloodmagic.api.ItemStackWrapper;
import WayofTime.bloodmagic.api.altar.AltarRecipe;
import WayofTime.bloodmagic.api.altar.EnumAltarTier;
import WayofTime.bloodmagic.api.registry.AltarRecipeRegistry;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
public class ModRecipes {
public static void init() {
@ -12,7 +12,8 @@ public class ModRecipes {
}
public static void addAltarRecipes() {
AltarRecipeRegistry.registerRecipe(new AltarRecipe(new ItemStackWrapper(ModItems.bloodOrb, 0), new ItemStackWrapper(Items.diamond), EnumAltarTier.ONE, 2000, 2, 1, false));
// AltarRecipeRegistry.registerRecipe(new AltarRecipe(new ItemStackWrapper(Items.diamond), new ItemStackWrapper(ModItems.bloodOrb, 0), EnumAltarTier.ONE, 2000, 2, 1, false));
AltarRecipeRegistry.registerRecipe(new AltarRecipe(new ItemStack(Items.diamond), new ItemStack(ModItems.bloodOrb, 0), EnumAltarTier.ONE, 2000, 2, 1, false));
// AltarRecipeRegistry.registerRecipe(new ItemStack(ModItems.bloodOrb, 1), new ItemStack(Items.emerald), 2, 5000, 5, 5, false);
// AltarRecipeRegistry.registerRecipe(new ItemStack(ModItems.bloodOrb, 2), new ItemStack(Blocks.gold_block), 3, 25000, 20, 20, false);
// AltarRecipeRegistry.registerRecipe(new ItemStack(ModItems.bloodOrb, 3), new ItemStack(ModItems.weakBloodShard), 4, 40000, 30, 50, false);

View file

@ -2,7 +2,6 @@ package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.altar.BloodAltar;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.ItemStackWrapper;
import WayofTime.bloodmagic.api.NBTHolder;
import WayofTime.bloodmagic.api.altar.AltarRecipe;
import WayofTime.bloodmagic.api.altar.AltarUpgrade;
@ -13,10 +12,13 @@ import WayofTime.bloodmagic.api.registry.AltarRecipeRegistry;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import WayofTime.bloodmagic.block.BlockLifeEssence;
import com.google.common.base.Enums;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.gui.IUpdatePlayerListBox;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraftforge.fluids.*;
public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlayerListBox, IFluidTank, IFluidHandler {
@ -46,34 +48,33 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
private int bufferCapacity = FluidContainerRegistry.BUCKET_VOLUME;
private int progress;
public boolean isActive;
public boolean isActive = false;
private int lockdownDuration;
private int demonBloodDuration;
private int cooldownAfterCrafting = 500;
private ItemStack result;
public TileAltar() {
super(1, "altar");
this.capacity = FluidContainerRegistry.BUCKET_VOLUME * 10;
this.bufferCapacity = FluidContainerRegistry.BUCKET_VOLUME;
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
if (!tagCompound.hasKey("Empty")) {
if (!tagCompound.hasKey(NBTHolder.NBT_EMPTY)) {
FluidStack fluid = FluidStack.loadFluidStackFromNBT(tagCompound);
if (fluid != null)
setMainFluid(fluid);
FluidStack fluidOut = new FluidStack(BloodMagicAPI.getLifeEssence(), tagCompound.getInteger("outputAmount"));
FluidStack fluidOut = new FluidStack(BloodMagicAPI.getLifeEssence(), tagCompound.getInteger(NBTHolder.NBT_OUTPUT_AMOUNT));
setOutputFluid(fluidOut);
FluidStack fluidIn = new FluidStack(BloodMagicAPI.getLifeEssence(), tagCompound.getInteger("inputAmount"));
FluidStack fluidIn = new FluidStack(BloodMagicAPI.getLifeEssence(), tagCompound.getInteger(NBTHolder.NBT_INPUT_AMOUNT));
setInputFluid(fluidIn);
}
@ -81,24 +82,24 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
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");
isUpgraded = tagCompound.getBoolean(NBTHolder.NBT_ALTAR_UPGRADED);
consumptionRate = tagCompound.getInteger(NBTHolder.NBT_ALTAR_CONSUMPTION_RATE);
drainRate = tagCompound.getInteger(NBTHolder.NBT_ALTAR_DRAIN_RATE);
consumptionMultiplier = tagCompound.getFloat(NBTHolder.NBT_ALTAR_CONSUMPTION_MULTIPLIER);
efficiencyMultiplier = tagCompound.getFloat(NBTHolder.NBT_ALTAR_EFFICIENCY_MULTIPLIER);
selfSacrificeEfficiencyMultiplier = tagCompound.getFloat(NBTHolder.NBT_ALTAR_SELF_SACRIFICE_MULTIPLIER);
sacrificeEfficiencyMultiplier = tagCompound.getFloat(NBTHolder.NBT_ALTAR_SACRIFICE_MULTIPLIER);
capacityMultiplier = tagCompound.getFloat(NBTHolder.NBT_ALTAR_CAPACITY_MULTIPLIER);
orbCapacityMultiplier = tagCompound.getFloat(NBTHolder.NBT_ALTAR_ORB_CAPACITY_MULTIPLIER);
dislocationMultiplier = tagCompound.getFloat(NBTHolder.NBT_ALTAR_DISLOCATION_MULTIPLIER);
capacity = tagCompound.getInteger(NBTHolder.NBT_ALTAR_CAPACITY);
bufferCapacity = tagCompound.getInteger(NBTHolder.NBT_ALTAR_BUFFER_CAPACITY);
progress = tagCompound.getInteger(NBTHolder.NBT_ALTAR_PROGRESS);
isResultBlock = tagCompound.getBoolean(NBTHolder.NBT_ALTAR_IS_RESULT_BLOCK);
lockdownDuration = tagCompound.getInteger(NBTHolder.NBT_ALTAR_LOCKDOWN_DURATION);
accelerationUpgrades = tagCompound.getInteger(NBTHolder.NBT_ALTAR_ACCELERATION_UPGRADES);
demonBloodDuration = tagCompound.getInteger(NBTHolder.NBT_ALTAR_DEMON_BLOOD_DURATION);
cooldownAfterCrafting = tagCompound.getInteger(NBTHolder.NBT_ALTAR_COOLDOWN_AFTER_CRAFTING);
}
@Override
@ -108,37 +109,37 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
if (fluid != null)
fluid.writeToNBT(tagCompound);
else
tagCompound.setString("Empty", "");
tagCompound.setString(NBTHolder.NBT_EMPTY, "");
if (fluidOutput != null)
tagCompound.setInteger("outputAmount", fluidOutput.amount);
tagCompound.setInteger(NBTHolder.NBT_OUTPUT_AMOUNT, fluidOutput.amount);
if (fluidInput != null)
tagCompound.setInteger("inputAmount", fluidInput.amount);
tagCompound.setInteger(NBTHolder.NBT_INPUT_AMOUNT, 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);
tagCompound.setString(NBTHolder.NBT_ALTAR_TIER, altarTier.name());
tagCompound.setBoolean(NBTHolder.NBT_ALTAR_ACTIVE, isActive);
tagCompound.setInteger(NBTHolder.NBT_ALTAR_LIQUID_REQ, liquidRequired);
tagCompound.setBoolean(NBTHolder.NBT_ALTAR_FILLABLE, canBeFilled);
tagCompound.setBoolean(NBTHolder.NBT_ALTAR_UPGRADED, isUpgraded);
tagCompound.setInteger(NBTHolder.NBT_ALTAR_CONSUMPTION_RATE, consumptionRate);
tagCompound.setInteger(NBTHolder.NBT_ALTAR_DRAIN_RATE, drainRate);
tagCompound.setFloat(NBTHolder.NBT_ALTAR_CONSUMPTION_MULTIPLIER, consumptionMultiplier);
tagCompound.setFloat(NBTHolder.NBT_ALTAR_EFFICIENCY_MULTIPLIER, efficiencyMultiplier);
tagCompound.setFloat(NBTHolder.NBT_ALTAR_SACRIFICE_MULTIPLIER, sacrificeEfficiencyMultiplier);
tagCompound.setFloat(NBTHolder.NBT_ALTAR_SELF_SACRIFICE_MULTIPLIER, selfSacrificeEfficiencyMultiplier);
tagCompound.setBoolean(NBTHolder.NBT_ALTAR_IS_RESULT_BLOCK, isResultBlock);
tagCompound.setFloat(NBTHolder.NBT_ALTAR_CAPACITY_MULTIPLIER, capacityMultiplier);
tagCompound.setFloat(NBTHolder.NBT_ALTAR_ORB_CAPACITY_MULTIPLIER, orbCapacityMultiplier);
tagCompound.setFloat(NBTHolder.NBT_ALTAR_DISLOCATION_MULTIPLIER, dislocationMultiplier);
tagCompound.setInteger(NBTHolder.NBT_ALTAR_CAPACITY, capacity);
tagCompound.setInteger(NBTHolder.NBT_ALTAR_PROGRESS, progress);
tagCompound.setInteger(NBTHolder.NBT_ALTAR_BUFFER_CAPACITY, bufferCapacity);
tagCompound.setInteger(NBTHolder.NBT_ALTAR_LOCKDOWN_DURATION, lockdownDuration);
tagCompound.setInteger(NBTHolder.NBT_ALTAR_ACCELERATION_UPGRADES, accelerationUpgrades);
tagCompound.setInteger(NBTHolder.NBT_ALTAR_DEMON_BLOOD_DURATION, demonBloodDuration);
tagCompound.setInteger(NBTHolder.NBT_ALTAR_COOLDOWN_AFTER_CRAFTING, cooldownAfterCrafting);
}
@Override
@ -146,11 +147,34 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
if (getWorld().isRemote)
return;
if (getWorld().getTotalWorldTime() % (Math.max(20 - getUpgrade().getSpeedCount(), 1)) == 0)
this.decrementDemonBlood();
if (lockdownDuration > 0)
lockdownDuration--;
if (!worldObj.isRemote && worldObj.getWorldTime() % 20 == 0) {
{
IBlockState block = worldObj.getBlockState(new BlockPos(this.pos.getX() + 1, this.pos.getY(), this.pos.getZ()));
block.getBlock().onNeighborBlockChange(worldObj, new BlockPos(this.pos.getX() + 1, this.pos.getY(), this.pos.getZ()), block, block.getBlock());
block = worldObj.getBlockState(new BlockPos(this.pos.getX() + 1, this.pos.getY(), this.pos.getZ()));
block.getBlock().onNeighborBlockChange(worldObj, new BlockPos(this.pos.getX() - 1, this.pos.getY(), this.pos.getZ()), block, block.getBlock());
block = worldObj.getBlockState(new BlockPos(this.pos.getX(), this.pos.getY() + 1, this.pos.getZ()));
block.getBlock().onNeighborBlockChange(worldObj, new BlockPos(this.pos.getX() , this.pos.getY() + 1, this.pos.getZ()), block, block.getBlock());
block = worldObj.getBlockState(new BlockPos(this.pos.getX(), this.pos.getY() - 1, this.pos.getZ()));
block.getBlock().onNeighborBlockChange(worldObj, new BlockPos(this.pos.getX(), this.pos.getY() - 1, this.pos.getZ()), block, block.getBlock());
block = worldObj.getBlockState(new BlockPos(this.pos.getX(), this.pos.getY(), this.pos.getZ() + 1));
block.getBlock().onNeighborBlockChange(worldObj, new BlockPos(this.pos.getX(), this.pos.getY(), this.pos.getZ() + 1), block, block.getBlock());
block = worldObj.getBlockState(new BlockPos(this.pos.getX(), this.pos.getY(), this.pos.getZ() - 1));
block.getBlock().onNeighborBlockChange(worldObj, new BlockPos(this.pos.getX(), this.pos.getY(), this.pos.getZ() - 1), block, block.getBlock());
}
}
if (getWorld().getTotalWorldTime() % (Math.max(20 - this.accelerationUpgrades, 1)) == 0)
everySecond();
if (getWorld().getTotalWorldTime() % 100 == 0)
if (getWorld().getTotalWorldTime() % 100 == 0 && (this.isActive || this.cooldownAfterCrafting <= 0))
everyFiveSeconds();
updat();
}
private void everySecond() {
@ -169,9 +193,9 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
private void everyFiveSeconds() {
startCycle();
updat();
}
@Override
public void startCycle() {
if (worldObj != null)
worldObj.markBlockForUpdate(pos);
@ -187,15 +211,19 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
if (getStackInSlot(0) != null) {
// Do recipes
if (AltarRecipeRegistry.getRecipes().containsKey(ItemStackWrapper.getHolder(getStackInSlot(0)))) {
AltarRecipe recipe = AltarRecipeRegistry.getRecipeForInput(ItemStackWrapper.getHolder(getStackInSlot(0)));
for (ItemStack itemStack : AltarRecipeRegistry.getRecipes().keySet()) {
if (getStackInSlot(0).getIsItemStackEqual(AltarRecipeRegistry.getRecipes().get(itemStack).getInput())) {
AltarRecipe recipe = AltarRecipeRegistry.getRecipeForInput(itemStack);
if (altarTier.ordinal() >= recipe.getMinTier().ordinal()) {
this.liquidRequired = recipe.getSyphon();
this.canBeFilled = recipe.isUseTag();
this.consumptionRate = recipe.getConsumeRate();
this.drainRate = recipe.getDrainRate();
this.isActive = true;
if (altarTier.ordinal() >= recipe.getMinTier().ordinal()) {
this.isActive = true;
this.result = new ItemStack(recipe.getOutput().getItem(), 1, recipe.getOutput().getMetadata());
this.liquidRequired = recipe.getSyphon();
this.canBeFilled = recipe.isUseTag();
this.consumptionRate = recipe.getConsumeRate();
this.drainRate = recipe.getDrainRate();
return;
}
}
}
}
@ -208,6 +236,7 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
if (cooldownAfterCrafting > 0) {
cooldownAfterCrafting--;
}
return;
}
if (getStackInSlot(0) == null) {
@ -216,9 +245,13 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
int worldTime = (int) (worldObj.getWorldTime() % 24000);
if (worldObj.isRemote) {
if (worldObj.isRemote)
return;
}
float f = 1.0F;
float f1 = f * 0.6F + 0.4F;
float f2 = f * f * 0.7F - 0.5F;
float f3 = f * f * 0.6F - 0.7F;
if (!canBeFilled) {
if (fluid != null && fluid.amount >= 1) {
@ -233,11 +266,11 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
progress += liquidDrained;
if (worldTime % 4 == 0) {
// SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 1, xCoord, yCoord, zCoord);
worldObj.spawnParticle(EnumParticleTypes.REDSTONE, this.pos.getX() + Math.random() - Math.random(), this.pos.getY() + Math.random() - Math.random(), this.pos.getZ() + Math.random() - Math.random(), f1, f2, f3);
}
if (progress >= liquidRequired * stackSize) {
ItemStack result = AltarRecipeRegistry.getRecipeForInput(ItemStackWrapper.getHolder(getStackInSlot(0))) != null ? (AltarRecipeRegistry.getRecipeForInput(ItemStackWrapper.getHolder(getStackInSlot(0))).getOutput() != null ? AltarRecipeRegistry.getRecipeForInput(ItemStackWrapper.getHolder(getStackInSlot(0))).getOutput().toStack() : null) : null;
ItemStack result = this.result;
if (result != null) {
result.stackSize *= stackSize;
}
@ -246,7 +279,7 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
progress = 0;
for (int i = 0; i < 8; i++) {
// SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 4, xCoord + 0.5f, yCoord + 1.0f, zCoord + 0.5f);
worldObj.spawnParticle(EnumParticleTypes.REDSTONE, this.pos.getX() + Math.random() - Math.random(), this.pos.getY() + Math.random() - Math.random(), this.pos.getZ() + Math.random() - Math.random(), f1, f2, f3);
}
this.isActive = false;
}
@ -254,7 +287,7 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
progress -= (int) (efficiencyMultiplier * drainRate);
if (worldTime % 2 == 0) {
// SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 2, xCoord, yCoord, zCoord);
worldObj.spawnParticle(EnumParticleTypes.REDSTONE, this.pos.getX() + Math.random() - Math.random(), this.pos.getY() + Math.random() - Math.random(), this.pos.getZ() + Math.random() - Math.random(), f1, f2, f3);
}
}
} else {
@ -271,7 +304,7 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
return;
}
String ownerName = itemTag.getString("ownerName");
String ownerName = itemTag.getString(NBTHolder.NBT_OWNER);
if (ownerName.equals("")) {
return;
@ -285,7 +318,7 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
fluid.amount = fluid.amount - drain;
if (worldTime % 4 == 0) {
// SpellHelper.sendIndexedParticleToAllAround(worldObj, xCoord, yCoord, zCoord, 20, worldObj.provider.dimensionId, 3, xCoord, yCoord, zCoord);
worldObj.spawnParticle(EnumParticleTypes.REDSTONE, this.pos.getX() + Math.random() - Math.random(), this.pos.getY() + Math.random() - Math.random(), this.pos.getZ() + Math.random() - Math.random(), f1, f2, f3);
}
}
}
@ -318,6 +351,7 @@ public class TileAltar extends TileInventory implements IBloodAltar, IUpdatePlay
return filledAmount;
}
@Override
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);

View file

@ -1,15 +1,21 @@
package WayofTime.bloodmagic.tile;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
public class TileInventory extends TileEntity implements IInventory {
@ -17,12 +23,23 @@ public class TileInventory extends TileEntity implements IInventory {
private int size;
private String name;
protected int[] syncedSlots = new int[0];
public TileInventory(int size, String name) {
this.inventory = new ItemStack[size];
this.size = size;
this.name = name;
}
private boolean isSyncedSlot(int slot) {
for (int s : this.syncedSlots) {
if (s == slot) {
return true;
}
}
return false;
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
@ -30,11 +47,13 @@ public class TileInventory extends TileEntity implements IInventory {
inventory = new ItemStack[getSizeInventory()];
for (int i = 0; i < tags.tagCount(); i++) {
NBTTagCompound data = tags.getCompoundTagAt(i);
int j = data.getByte("Slot") & 255;
if (!isSyncedSlot(i)) {
NBTTagCompound data = tags.getCompoundTagAt(i);
byte j = data.getByte("Slot") ;
if (j >= 0 && j < inventory.length) {
inventory[j] = ItemStack.loadItemStackFromNBT(data);
if (j >= 0 && j < inventory.length) {
inventory[j] = ItemStack.loadItemStackFromNBT(data);
}
}
}
}
@ -45,7 +64,7 @@ public class TileInventory extends TileEntity implements IInventory {
NBTTagList tags = new NBTTagList();
for (int i = 0; i < inventory.length; i++) {
if (inventory[i] != null) {
if ((inventory[i] != null) && !isSyncedSlot(i)) {
NBTTagCompound data = new NBTTagCompound();
data.setByte("Slot", (byte) i);
inventory[i].writeToNBT(data);
@ -74,30 +93,46 @@ public class TileInventory extends TileEntity implements IInventory {
@Override
public ItemStack decrStackSize(int index, int count) {
ItemStack slotStack = getStackInSlot(index);
if (inventory[index] != null) {
if (!worldObj.isRemote)
worldObj.markBlockForUpdate(this.pos);
if (slotStack.stackSize > count)
slotStack.stackSize -= count;
else if (slotStack.stackSize <= count)
return null;
if (inventory[index].stackSize <= count) {
ItemStack itemStack = inventory[index];
inventory[index] = null;
markDirty();
return itemStack;
}
return slotStack;
ItemStack itemStack = inventory[index].splitStack(count);
if (inventory[index].stackSize == 0)
inventory[index] = null;
markDirty();
return itemStack;
}
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
ItemStack stack = getStackInSlot(slot);
if (stack != null)
if (inventory[slot] != null) {
ItemStack itemStack = inventory[slot];
setInventorySlotContents(slot, null);
return stack;
return itemStack;
}
return null;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
inventory[slot] = stack;
worldObj.markBlockForUpdate(pos);
if (stack != null && stack.stackSize > getInventoryStackLimit())
stack.stackSize = getInventoryStackLimit();
markDirty();
if (!worldObj.isRemote)
worldObj.markBlockForUpdate(this.pos);
}
@Override
@ -161,4 +196,25 @@ public class TileInventory extends TileEntity implements IInventory {
public IChatComponent getDisplayName() {
return new ChatComponentTranslation("tile.BloodMagic." + name + ".name");
}
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound nbt = new NBTTagCompound();
writeToNBT(nbt);
return new S35PacketUpdateTileEntity(getPos(), -999, nbt);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
{
super.onDataPacket(net, pkt);
readFromNBT(pkt.getNbtCompound());
}
@Override
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState)
{
return oldState.getBlock() != newState.getBlock();
}
}

View file

@ -1,6 +1,6 @@
package WayofTime.bloodmagic.util;
import WayofTime.bloodmagic.network.AlchemicalWizardryPacketHandler;
import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
import WayofTime.bloodmagic.util.helper.TextHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
@ -233,6 +233,6 @@ public class ChatUtil {
*/
public static void sendNoSpam(EntityPlayerMP player, IChatComponent... lines) {
if (lines.length > 0)
AlchemicalWizardryPacketHandler.INSTANCE.sendTo(new PacketNoSpamChat(lines), player);
BloodMagicPacketHandler.INSTANCE.sendTo(new PacketNoSpamChat(lines), player);
}
}

View file

@ -27,18 +27,22 @@ public class Utils {
* @param tile - The {@link TileInventory} to input the item to
* @param player - The player to take the item from.
*/
public static void insertItemToTile(TileInventory tile, EntityPlayer player) {
public static boolean insertItemToTile(TileInventory tile, EntityPlayer player) {
if (tile.getStackInSlot(0) == null && player.getHeldItem() != null) {
ItemStack input = player.getHeldItem().copy();
input.stackSize = 1;
player.getHeldItem().stackSize--;
tile.setInventorySlotContents(0, input);
return true;
} else if (tile.getStackInSlot(0) != null && player.getHeldItem() == null) {
if (!tile.getWorld().isRemote) {
EntityItem invItem = new EntityItem(tile.getWorld(), player.posX, player.posY + 0.25, player.posZ, tile.getStackInSlot(0));
tile.getWorld().spawnEntityInWorld(invItem);
}
tile.clear();
return false;
}
return false;
}
}