2015-11-02 20:39:44 +00:00
|
|
|
package WayofTime.bloodmagic.altar;
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2015-11-02 20:39:44 +00:00
|
|
|
import WayofTime.bloodmagic.api.BlockStack;
|
2015-11-03 02:30:28 +00:00
|
|
|
import WayofTime.bloodmagic.api.altar.*;
|
|
|
|
import WayofTime.bloodmagic.block.BlockBloodRune;
|
2015-11-08 02:37:12 +00:00
|
|
|
import WayofTime.bloodmagic.block.BlockBloodStoneBrick;
|
2015-11-30 00:04:50 +00:00
|
|
|
import WayofTime.bloodmagic.block.BlockCrystal;
|
2015-11-03 02:30:28 +00:00
|
|
|
import WayofTime.bloodmagic.registry.ModBlocks;
|
2015-10-30 03:22:14 +00:00
|
|
|
import net.minecraft.block.BlockBeacon;
|
|
|
|
import net.minecraft.block.BlockGlowstone;
|
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2015-11-03 02:30:28 +00:00
|
|
|
import java.util.List;
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2015-11-03 03:18:53 +00:00
|
|
|
public class BloodAltar {
|
|
|
|
|
2015-11-28 01:15:19 +00:00
|
|
|
static {
|
|
|
|
EnumAltarTier.ONE.buildComponents();
|
|
|
|
EnumAltarTier.TWO.buildComponents();
|
|
|
|
EnumAltarTier.THREE.buildComponents();
|
|
|
|
EnumAltarTier.FOUR.buildComponents();
|
|
|
|
EnumAltarTier.FIVE.buildComponents();
|
|
|
|
EnumAltarTier.SIX.buildComponents();
|
|
|
|
}
|
|
|
|
|
2015-11-03 03:18:53 +00:00
|
|
|
public static EnumAltarTier getAltarTier(World world, BlockPos pos) {
|
2015-11-28 01:15:19 +00:00
|
|
|
for (int i = EnumAltarTier.MAXTIERS - 1; i >= 1; i--) {
|
2015-11-03 03:18:53 +00:00
|
|
|
if (checkAltarIsValid(world, pos, i)) {
|
2015-10-30 03:22:14 +00:00
|
|
|
return EnumAltarTier.values()[i];
|
2015-11-03 02:30:28 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-30 03:22:14 +00:00
|
|
|
|
|
|
|
return EnumAltarTier.ONE;
|
|
|
|
}
|
|
|
|
|
2015-11-03 03:18:53 +00:00
|
|
|
public static boolean checkAltarIsValid(World world, BlockPos worldPos, int altarTier) {
|
2015-11-28 01:15:19 +00:00
|
|
|
|
2015-11-03 03:18:53 +00:00
|
|
|
for (AltarComponent altarComponent : EnumAltarTier.values()[altarTier].getAltarComponents()) {
|
2015-10-30 03:22:14 +00:00
|
|
|
|
|
|
|
BlockPos componentPos = worldPos.add(altarComponent.getOffset());
|
|
|
|
BlockStack worldBlock = new BlockStack(world.getBlockState(componentPos).getBlock(), world.getBlockState(componentPos).getBlock().getMetaFromState(world.getBlockState(componentPos)));
|
|
|
|
|
2015-11-03 03:18:53 +00:00
|
|
|
if (altarComponent.isBloodRune()) {
|
|
|
|
if (!checkRune(altarComponent, worldBlock)) {
|
2015-10-30 03:22:14 +00:00
|
|
|
return false;
|
2015-11-03 02:30:28 +00:00
|
|
|
}
|
2015-11-28 01:15:19 +00:00
|
|
|
} else if (!altarComponent.isBloodRune()) {
|
|
|
|
if (world.isAirBlock(componentPos)) return false;
|
|
|
|
if (((altarComponent.getBlockStack().getBlock() != worldBlock.getBlock()) || (altarComponent.getBlockStack().getMeta() != worldBlock.getMeta()))) {
|
2015-11-03 03:18:53 +00:00
|
|
|
if (!checkSpecials(altarComponent, worldBlock)) {
|
2015-10-30 03:22:14 +00:00
|
|
|
return false;
|
2015-11-03 02:30:28 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-30 03:22:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-28 01:15:19 +00:00
|
|
|
return true;
|
2015-10-30 03:22:14 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 02:37:12 +00:00
|
|
|
public static AltarUpgrade getUpgrades(World world, BlockPos pos, EnumAltarTier altarTier) {
|
|
|
|
if (world.isRemote) {
|
2015-11-03 02:30:28 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
AltarUpgrade upgrades = new AltarUpgrade();
|
2015-11-03 15:34:11 +00:00
|
|
|
List<AltarComponent> list = altarTier.getAltarComponents();
|
2015-11-03 02:30:28 +00:00
|
|
|
|
2015-11-03 03:18:53 +00:00
|
|
|
for (AltarComponent altarComponent : list) {
|
2015-11-03 02:30:28 +00:00
|
|
|
BlockPos componentPos = pos.add(altarComponent.getOffset());
|
|
|
|
|
2015-11-03 03:18:53 +00:00
|
|
|
if (altarComponent.isUpgradeSlot()) {
|
2015-11-03 02:30:28 +00:00
|
|
|
BlockStack worldBlock = new BlockStack(world.getBlockState(componentPos).getBlock(), world.getBlockState(componentPos).getBlock().getMetaFromState(world.getBlockState(componentPos)));
|
|
|
|
|
2015-11-03 03:18:53 +00:00
|
|
|
if (worldBlock.getBlock() instanceof BlockBloodRune) {
|
|
|
|
switch (((BlockBloodRune) worldBlock.getBlock()).getRuneEffect(worldBlock.getMeta())) {
|
2015-11-03 02:30:28 +00:00
|
|
|
case 1:
|
|
|
|
upgrades.addSpeed();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
upgrades.addEfficiency();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
upgrades.addSacrifice();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
upgrades.addSelfSacrifice();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
2015-11-03 03:18:53 +00:00
|
|
|
upgrades.addDisplacement();
|
2015-11-03 02:30:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
2015-11-03 03:18:53 +00:00
|
|
|
upgrades.addCapacity();
|
2015-11-03 02:30:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
2015-11-03 03:18:53 +00:00
|
|
|
upgrades.addBetterCapacity();
|
2015-11-03 02:30:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
2015-11-03 03:18:53 +00:00
|
|
|
upgrades.addOrbCapacity();
|
2015-11-03 02:30:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 9:
|
|
|
|
upgrades.addAcceleration();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2015-11-03 02:30:28 +00:00
|
|
|
return upgrades;
|
|
|
|
}
|
|
|
|
|
2015-11-03 03:18:53 +00:00
|
|
|
private static boolean checkRune(AltarComponent altarComponent, BlockStack blockStack) {
|
|
|
|
if (altarComponent.getBlockStack().getBlock() == ModBlocks.bloodRune) {
|
|
|
|
if (blockStack.getBlock() instanceof BlockBloodRune || (blockStack.getBlock() instanceof IAltarComponent && (((IAltarComponent) blockStack.getBlock()).getType(blockStack.getMeta()) == EnumAltarComponent.BLOODRUNE))) {
|
2015-11-03 02:30:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-10-30 03:22:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-03 03:18:53 +00:00
|
|
|
private static boolean checkSpecials(AltarComponent altarComponent, BlockStack blockStack) {
|
2015-11-08 02:37:12 +00:00
|
|
|
if (altarComponent.getBlockStack().getBlock() == ModBlocks.bloodStoneBrick)
|
|
|
|
if (blockStack.getBlock() instanceof BlockBloodStoneBrick || (blockStack.getBlock() instanceof IAltarComponent && (((IAltarComponent) blockStack.getBlock()).getType(blockStack.getMeta()) == EnumAltarComponent.BLOODSTONE)))
|
2015-11-28 01:15:19 +00:00
|
|
|
return true;
|
2015-10-30 03:22:14 +00:00
|
|
|
|
2015-11-30 00:04:50 +00:00
|
|
|
if (altarComponent.getBlockStack().getBlock() == ModBlocks.crystal)
|
|
|
|
if (blockStack.getBlock() instanceof BlockCrystal || (blockStack.getBlock() instanceof IAltarComponent && (((IAltarComponent) blockStack.getBlock()).getType(blockStack.getMeta()) == EnumAltarComponent.CRYSTAL)))
|
2015-12-02 05:14:26 +00:00
|
|
|
return true;
|
2015-10-30 03:22:14 +00:00
|
|
|
|
|
|
|
if (altarComponent.getBlockStack().getBlock() == Blocks.glowstone)
|
|
|
|
if (blockStack.getBlock() instanceof BlockGlowstone || (blockStack.getBlock() instanceof IAltarComponent && (((IAltarComponent) blockStack.getBlock()).getType(blockStack.getMeta()) == EnumAltarComponent.GLOWSTONE)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (altarComponent.getBlockStack().getBlock() == Blocks.beacon)
|
|
|
|
if (blockStack.getBlock() instanceof BlockBeacon || (blockStack.getBlock() instanceof IAltarComponent && (((IAltarComponent) blockStack.getBlock()).getType(blockStack.getMeta()) == EnumAltarComponent.BEACON)))
|
|
|
|
return true;
|
|
|
|
|
2015-11-28 01:15:19 +00:00
|
|
|
if (altarComponent.getBlockStack().getBlock() == Blocks.air)
|
|
|
|
if (blockStack.getBlock() != Blocks.air)
|
|
|
|
return true;
|
|
|
|
|
2015-10-30 03:22:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|