BloodMagic/src/main/java/WayofTime/bloodmagic/altar/BloodAltar.java

116 lines
4.1 KiB
Java
Raw Normal View History

package WayofTime.bloodmagic.altar;
import WayofTime.bloodmagic.api.BlockStack;
2015-11-03 02:30:28 +00:00
import WayofTime.bloodmagic.api.altar.*;
import WayofTime.bloodmagic.block.BlockBloodRune;
import WayofTime.bloodmagic.util.Utils;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
2015-11-03 02:30:28 +00:00
import java.util.List;
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();
}
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--) {
if (checkAltarIsValid(world, pos, i)) {
return EnumAltarTier.values()[i];
2015-11-03 02:30:28 +00:00
}
}
return EnumAltarTier.ONE;
}
public static boolean checkAltarIsValid(World world, BlockPos worldPos, int altarTier) {
2015-11-28 01:15:19 +00:00
for (AltarComponent altarComponent : EnumAltarTier.values()[altarTier].getAltarComponents()) {
BlockPos componentPos = worldPos.add(altarComponent.getOffset());
BlockStack worldBlock = new BlockStack(world.getBlockState(componentPos).getBlock(), world.getBlockState(componentPos).getBlock().getMetaFromState(world.getBlockState(componentPos)));
if (altarComponent.getComponent() != EnumAltarComponent.NOTAIR) {
if (worldBlock.getBlock() instanceof IAltarComponent) {
EnumAltarComponent component = ((IAltarComponent) worldBlock.getBlock()).getType(worldBlock.getMeta());
if (component != altarComponent.getComponent())
return false;
} else if (worldBlock.getBlock() != Utils.getBlockForComponent(altarComponent.getComponent())) {
return false;
2015-11-03 02:30:28 +00:00
}
} else {
if (world.isAirBlock(componentPos))
return false;
}
}
2015-11-28 01:15:19 +00:00
return true;
}
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
for (AltarComponent altarComponent : list) {
2015-11-03 02:30:28 +00:00
BlockPos componentPos = pos.add(altarComponent.getOffset());
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)));
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:
upgrades.addDisplacement();
2015-11-03 02:30:28 +00:00
break;
case 6:
upgrades.addCapacity();
2015-11-03 02:30:28 +00:00
break;
case 7:
upgrades.addBetterCapacity();
2015-11-03 02:30:28 +00:00
break;
case 8:
upgrades.addOrbCapacity();
2015-11-03 02:30:28 +00:00
break;
case 9:
upgrades.addAcceleration();
break;
}
}
}
}
2015-11-03 02:30:28 +00:00
return upgrades;
}
}