use of WayofTime.bloodmagic.tile.TileDemonCrystal in project BloodMagic by WayofTime.
the class BlockDemonCrystal method breakBlock.
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileDemonCrystal) {
EnumDemonWillType type = state.getValue(TYPE);
int number = ((TileDemonCrystal) tile).getCrystalCount();
spawnAsEntity(world, pos, getItemStackDropped(type, number));
world.removeTileEntity(pos);
}
super.breakBlock(world, pos, state);
}
use of WayofTime.bloodmagic.tile.TileDemonCrystal in project BloodMagic by WayofTime.
the class RitualCrystalHarvest method performRitual.
@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
World world = masterRitualStone.getWorldObj();
int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
BlockPos pos = masterRitualStone.getBlockPos();
if (currentEssence < getRefreshCost()) {
masterRitualStone.getOwnerNetwork().causeNausea();
return;
}
int maxEffects = 1;
int totalEffects = 0;
AreaDescriptor crystalRange = getBlockRange(CRYSTAL_RANGE);
crystalRange.resetIterator();
while (crystalRange.hasNext()) {
BlockPos nextPos = crystalRange.next().add(pos);
TileEntity tile = world.getTileEntity(nextPos);
if (tile instanceof TileDemonCrystal) {
TileDemonCrystal demonCrystal = (TileDemonCrystal) tile;
if (demonCrystal.dropSingleCrystal()) {
IBlockState state = world.getBlockState(nextPos);
world.notifyBlockUpdate(nextPos, state, state, 3);
totalEffects++;
if (totalEffects >= maxEffects) {
break;
}
}
}
}
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost() * totalEffects);
}
use of WayofTime.bloodmagic.tile.TileDemonCrystal in project BloodMagic by WayofTime.
the class RitualForsakenSoul method performRitual.
@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
World world = masterRitualStone.getWorldObj();
int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
BlockPos pos = masterRitualStone.getBlockPos();
if (currentEssence < getRefreshCost()) {
masterRitualStone.getOwnerNetwork().causeNausea();
return;
}
int maxEffects = 100;
int totalEffects = 0;
List<TileDemonCrystal> crystalList = new ArrayList<>();
AreaDescriptor crystalRange = getBlockRange(CRYSTAL_RANGE);
crystalRange.resetIterator();
while (crystalRange.hasNext()) {
BlockPos nextPos = crystalRange.next().add(pos);
TileEntity tile = world.getTileEntity(nextPos);
if (tile instanceof TileDemonCrystal) {
crystalList.add((TileDemonCrystal) tile);
}
}
AreaDescriptor damageRange = getBlockRange(DAMAGE_RANGE);
AxisAlignedBB range = damageRange.getAABB(pos);
List<EntityLivingBase> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, range);
for (EntityLivingBase entity : entities) {
EntityEntry entityEntry = EntityRegistry.getEntry(entity.getClass());
if (entityEntry == null || BloodMagicAPI.INSTANCE.getBlacklist().getSacrifice().contains(entityEntry.getRegistryName()))
continue;
if (entity.isEntityAlive() && !(entity instanceof EntityPlayer)) {
if (entity.attackEntityFrom(DamageSource.OUT_OF_WORLD, 1)) {
if (!entity.isEntityAlive()) {
int uniqueness = calculateUniqueness(entity);
double modifier = 1;
if (entity instanceof EntityAnimal && !((EntityAnimal) entity).collided) {
modifier = 4;
}
willBuffer += modifier * getWillForUniqueness(uniqueness) / HEALTH_THRESHOLD * entity.getMaxHealth();
crystalBuffer += modifier * entity.getMaxHealth() / HEALTH_THRESHOLD;
totalEffects++;
if (totalEffects >= maxEffects) {
break;
}
}
}
}
}
if (crystalList.size() > 0 && crystalBuffer > 0) {
double growth = Math.min(crystalBuffer, 1);
double willSyphonAmount = growth * willBuffer / crystalBuffer;
TileDemonCrystal chosenCrystal = crystalList.get(world.rand.nextInt(crystalList.size()));
double percentageGrowth = chosenCrystal.growCrystalWithWillAmount(growth * willBuffer / crystalBuffer, growth);
if (percentageGrowth > 0) {
crystalBuffer -= percentageGrowth;
willBuffer -= percentageGrowth * willSyphonAmount;
}
}
masterRitualStone.getOwnerNetwork().syphon(getRefreshCost() * totalEffects);
}
use of WayofTime.bloodmagic.tile.TileDemonCrystal in project BloodMagic by WayofTime.
the class BlockDemonCrystal method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return true;
}
TileDemonCrystal crystal = (TileDemonCrystal) world.getTileEntity(pos);
if (PlayerDemonWillHandler.getTotalDemonWill(EnumDemonWillType.DEFAULT, player) > 1024) {
crystal.dropSingleCrystal();
world.notifyBlockUpdate(pos, state, state, 3);
}
return true;
}
use of WayofTime.bloodmagic.tile.TileDemonCrystal in project BloodMagic by WayofTime.
the class BlockDemonCrystal method neighborChanged.
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos) {
TileDemonCrystal tile = (TileDemonCrystal) world.getTileEntity(pos);
EnumFacing placement = tile.getPlacement();
BlockPos offsetPos = pos.offset(placement.getOpposite());
IBlockState offsetState = world.getBlockState(offsetPos);
Block offsetBlock = offsetState.getBlock();
if (!offsetBlock.isSideSolid(offsetState, world, offsetPos, placement)) {
world.setBlockToAir(pos);
}
}
Aggregations