2015-12-30 15:24:25 -05:00
|
|
|
package WayofTime.bloodmagic.ritual;
|
|
|
|
|
2016-08-10 17:24:36 -04:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
|
2015-12-30 15:24:25 -05:00
|
|
|
import net.minecraft.block.Block;
|
2016-08-11 16:14:06 -04:00
|
|
|
import net.minecraft.block.BlockFarmland;
|
2015-12-30 15:24:25 -05:00
|
|
|
import net.minecraft.block.IGrowable;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
2016-08-10 17:24:36 -04:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-08-11 16:14:06 -04:00
|
|
|
import net.minecraft.init.Blocks;
|
2016-08-10 17:24:36 -04:00
|
|
|
import net.minecraft.potion.PotionEffect;
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
2016-03-17 13:00:44 -07:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-08-10 17:24:36 -04:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
|
|
|
import net.minecraft.util.text.TextComponentTranslation;
|
2015-12-30 15:24:25 -05:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.IPlantable;
|
2016-08-10 17:24:36 -04:00
|
|
|
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.AreaDescriptor;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.EnumRuneType;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.IMasterRitualStone;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.Ritual;
|
|
|
|
import WayofTime.bloodmagic.api.ritual.RitualComponent;
|
|
|
|
import WayofTime.bloodmagic.api.saving.SoulNetwork;
|
|
|
|
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
|
|
|
|
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
|
|
|
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
|
|
|
|
import WayofTime.bloodmagic.registry.ModPotions;
|
2016-08-11 16:14:06 -04:00
|
|
|
import WayofTime.bloodmagic.util.Utils;
|
2015-12-30 15:24:25 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public class RitualGreenGrove extends Ritual
|
|
|
|
{
|
|
|
|
public static final String GROW_RANGE = "growing";
|
2016-08-10 17:24:36 -04:00
|
|
|
public static final String LEECH_RANGE = "leech";
|
2016-08-11 16:14:06 -04:00
|
|
|
public static final String HYDRATE_RANGE = "hydrate";
|
2016-08-10 17:24:36 -04:00
|
|
|
|
|
|
|
public static double corrosiveWillDrain = 0.2;
|
2016-08-10 21:54:36 -04:00
|
|
|
public static double rawWillDrain = 0.05;
|
2016-08-11 16:14:06 -04:00
|
|
|
public static double steadfastWillDrain = 0.05;
|
2016-08-10 21:54:36 -04:00
|
|
|
|
|
|
|
public int refreshTime = 20;
|
|
|
|
public static int defaultRefreshTime = 20;
|
2015-12-30 15:34:40 -05:00
|
|
|
|
2016-08-11 16:14:06 -04:00
|
|
|
public static IBlockState farmlandState = Blocks.FARMLAND.getDefaultState().withProperty(BlockFarmland.MOISTURE, 7);
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public RitualGreenGrove()
|
|
|
|
{
|
2016-01-02 17:15:33 -05:00
|
|
|
super("ritualGreenGrove", 0, 5000, "ritual." + Constants.Mod.MODID + ".greenGroveRitual");
|
2015-12-31 11:25:24 -05:00
|
|
|
addBlockRange(GROW_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-1, 2, -1), 3, 1, 3));
|
2016-08-10 17:24:36 -04:00
|
|
|
addBlockRange(LEECH_RANGE, new AreaDescriptor.Rectangle(new BlockPos(0, 0, 0), 1));
|
2016-08-11 16:14:06 -04:00
|
|
|
addBlockRange(HYDRATE_RANGE, new AreaDescriptor.Rectangle(new BlockPos(0, 0, 0), 1));
|
2016-04-11 15:36:27 -04:00
|
|
|
setMaximumVolumeAndDistanceOfRange(GROW_RANGE, 81, 4, 4);
|
2016-08-10 17:24:36 -04:00
|
|
|
setMaximumVolumeAndDistanceOfRange(LEECH_RANGE, 0, 15, 15);
|
2016-08-11 16:14:06 -04:00
|
|
|
setMaximumVolumeAndDistanceOfRange(HYDRATE_RANGE, 0, 15, 15);
|
2015-12-30 15:34:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void performRitual(IMasterRitualStone masterRitualStone)
|
|
|
|
{
|
2016-01-03 08:30:59 -05:00
|
|
|
World world = masterRitualStone.getWorldObj();
|
2016-08-10 17:24:36 -04:00
|
|
|
BlockPos pos = masterRitualStone.getBlockPos();
|
2015-12-31 20:10:57 -05:00
|
|
|
SoulNetwork network = NetworkHelper.getSoulNetwork(masterRitualStone.getOwner());
|
2015-12-30 15:34:40 -05:00
|
|
|
int currentEssence = network.getCurrentEssence();
|
|
|
|
|
|
|
|
if (currentEssence < getRefreshCost())
|
2015-12-31 20:47:01 -05:00
|
|
|
{
|
2016-06-12 13:41:02 -07:00
|
|
|
network.causeNausea();
|
2015-12-30 15:34:40 -05:00
|
|
|
return;
|
2015-12-31 20:47:01 -05:00
|
|
|
}
|
2015-12-30 15:34:40 -05:00
|
|
|
|
|
|
|
int maxGrowths = currentEssence / getRefreshCost();
|
|
|
|
int totalGrowths = 0;
|
|
|
|
|
2016-08-10 17:24:36 -04:00
|
|
|
List<EnumDemonWillType> willConfig = masterRitualStone.getActiveWillConfig();
|
|
|
|
|
|
|
|
double corrosiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.CORROSIVE, willConfig);
|
2016-08-10 21:54:36 -04:00
|
|
|
double rawWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.DEFAULT, willConfig);
|
2016-08-11 16:14:06 -04:00
|
|
|
double steadfastWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.STEADFAST, willConfig);
|
2016-08-10 21:54:36 -04:00
|
|
|
|
|
|
|
refreshTime = getRefreshTimeForRawWill(rawWill);
|
|
|
|
|
|
|
|
boolean consumeRawWill = rawWill >= rawWillDrain && refreshTime != defaultRefreshTime;
|
|
|
|
|
|
|
|
double rawDrain = 0;
|
2016-08-10 17:24:36 -04:00
|
|
|
|
2015-12-30 16:19:50 -05:00
|
|
|
AreaDescriptor growingRange = getBlockRange(GROW_RANGE);
|
2015-12-30 15:34:40 -05:00
|
|
|
|
2016-08-11 16:14:06 -04:00
|
|
|
for (BlockPos newPos : growingRange.getContainedPositions(pos))
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2015-12-30 16:19:50 -05:00
|
|
|
IBlockState state = world.getBlockState(newPos);
|
|
|
|
Block block = state.getBlock();
|
2016-01-23 00:32:10 -08:00
|
|
|
|
2016-02-16 11:46:47 -05:00
|
|
|
if (!BloodMagicAPI.getGreenGroveBlacklist().contains(block))
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2016-01-23 00:32:10 -08:00
|
|
|
if (block instanceof IPlantable || block instanceof IGrowable)
|
|
|
|
{
|
2016-08-11 16:14:06 -04:00
|
|
|
if (world.rand.nextDouble() < 0.3)
|
2016-08-10 21:54:36 -04:00
|
|
|
{
|
2016-08-11 16:14:06 -04:00
|
|
|
block.updateTick(world, newPos, state, new Random());
|
|
|
|
IBlockState newState = world.getBlockState(newPos);
|
|
|
|
if (!newState.equals(state))
|
|
|
|
{
|
|
|
|
totalGrowths++;
|
|
|
|
if (consumeRawWill)
|
|
|
|
{
|
|
|
|
rawWill -= rawWillDrain;
|
|
|
|
rawDrain += rawWillDrain;
|
|
|
|
}
|
|
|
|
}
|
2016-08-10 21:54:36 -04:00
|
|
|
}
|
2016-01-23 00:32:10 -08:00
|
|
|
}
|
2015-12-30 15:34:40 -05:00
|
|
|
}
|
|
|
|
|
2016-08-11 16:14:06 -04:00
|
|
|
if (totalGrowths >= maxGrowths || (consumeRawWill && rawWill < rawWillDrain))
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-10 21:54:36 -04:00
|
|
|
if (rawDrain > 0)
|
|
|
|
{
|
|
|
|
WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.DEFAULT, rawDrain, true);
|
|
|
|
}
|
|
|
|
|
2016-08-11 16:14:06 -04:00
|
|
|
AreaDescriptor hydrateRange = getBlockRange(HYDRATE_RANGE);
|
|
|
|
|
|
|
|
double steadfastDrain = 0;
|
|
|
|
if (steadfastWill > steadfastWillDrain)
|
|
|
|
{
|
|
|
|
AxisAlignedBB aabb = hydrateRange.getAABB(pos);
|
|
|
|
steadfastDrain += steadfastWillDrain * Utils.plantSeedsInArea(world, aabb, 2, 1);
|
|
|
|
steadfastWill -= steadfastDrain;
|
|
|
|
|
|
|
|
for (BlockPos newPos : hydrateRange.getContainedPositions(pos))
|
|
|
|
{
|
|
|
|
if (steadfastWill < steadfastWillDrain)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
IBlockState state = world.getBlockState(newPos);
|
|
|
|
Block block = state.getBlock();
|
|
|
|
|
|
|
|
boolean hydratedBlock = false;
|
|
|
|
if (block == Blocks.DIRT || block == Blocks.GRASS)
|
|
|
|
{
|
|
|
|
world.setBlockState(newPos, farmlandState);
|
|
|
|
hydratedBlock = true;
|
|
|
|
} else if (block == Blocks.FARMLAND)
|
|
|
|
{
|
|
|
|
int meta = block.getMetaFromState(state);
|
|
|
|
if (meta < 7)
|
|
|
|
{
|
|
|
|
world.setBlockState(newPos, farmlandState);
|
|
|
|
hydratedBlock = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hydratedBlock)
|
|
|
|
{
|
|
|
|
steadfastWill -= steadfastWillDrain;
|
|
|
|
steadfastDrain += steadfastWillDrain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (steadfastDrain > 0)
|
|
|
|
{
|
|
|
|
WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.STEADFAST, steadfastDrain, true);
|
|
|
|
}
|
|
|
|
|
2016-08-10 17:24:36 -04:00
|
|
|
double corrosiveDrain = 0;
|
|
|
|
if (corrosiveWill > corrosiveWillDrain)
|
|
|
|
{
|
|
|
|
AreaDescriptor leechRange = getBlockRange(LEECH_RANGE);
|
|
|
|
AxisAlignedBB mobArea = leechRange.getAABB(pos);
|
|
|
|
List<EntityLivingBase> entityList = world.getEntitiesWithinAABB(EntityLivingBase.class, mobArea);
|
|
|
|
for (EntityLivingBase entityLiving : entityList)
|
|
|
|
{
|
|
|
|
if (corrosiveWill < corrosiveWillDrain)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entityLiving instanceof EntityPlayer)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entityLiving.isPotionActive(ModPotions.plantLeech) || !entityLiving.isPotionApplicable(new PotionEffect(ModPotions.plantLeech)))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
entityLiving.addPotionEffect(new PotionEffect(ModPotions.plantLeech, 200, 0));
|
|
|
|
|
|
|
|
corrosiveWill -= corrosiveWillDrain;
|
|
|
|
corrosiveDrain += corrosiveWillDrain;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (corrosiveWillDrain > 0)
|
|
|
|
{
|
|
|
|
WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.CORROSIVE, corrosiveDrain, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
network.syphon(totalGrowths * getRefreshCost());
|
|
|
|
}
|
|
|
|
|
2016-08-10 21:54:36 -04:00
|
|
|
public int getRefreshTimeForRawWill(double rawWill)
|
|
|
|
{
|
|
|
|
if (rawWill > 0)
|
|
|
|
{
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
return defaultRefreshTime;
|
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
@Override
|
|
|
|
public int getRefreshTime()
|
|
|
|
{
|
2016-08-10 21:54:36 -04:00
|
|
|
return refreshTime;
|
2015-12-30 15:34:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getRefreshCost()
|
|
|
|
{
|
2016-08-11 16:14:06 -04:00
|
|
|
return 20; //TODO: Need to find a way to balance this
|
2015-12-30 15:34:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ArrayList<RitualComponent> getComponents()
|
|
|
|
{
|
|
|
|
ArrayList<RitualComponent> components = new ArrayList<RitualComponent>();
|
|
|
|
|
|
|
|
this.addCornerRunes(components, 1, 0, EnumRuneType.EARTH);
|
|
|
|
this.addParallelRunes(components, 1, 0, EnumRuneType.WATER);
|
|
|
|
|
|
|
|
return components;
|
|
|
|
}
|
2015-12-31 13:50:38 -05:00
|
|
|
|
2016-08-10 17:24:36 -04:00
|
|
|
@Override
|
|
|
|
public ITextComponent[] provideInformationOfRitualToPlayer(EntityPlayer player)
|
|
|
|
{
|
2016-08-11 16:14:06 -04:00
|
|
|
return new ITextComponent[] { new TextComponentTranslation(this.getUnlocalizedName() + ".info"), new TextComponentTranslation(this.getUnlocalizedName() + ".default.info"), new TextComponentTranslation(this.getUnlocalizedName() + ".corrosive.info"), new TextComponentTranslation(this.getUnlocalizedName() + ".steadfast.info") };
|
2016-08-10 17:24:36 -04:00
|
|
|
}
|
|
|
|
|
2015-12-31 08:01:39 -05:00
|
|
|
@Override
|
|
|
|
public Ritual getNewCopy()
|
|
|
|
{
|
|
|
|
return new RitualGreenGrove();
|
|
|
|
}
|
2015-12-30 15:24:25 -05:00
|
|
|
}
|