2016-01-09 18:17:38 -05:00
|
|
|
package WayofTime.bloodmagic.ritual;
|
|
|
|
|
2016-04-13 17:58:06 -04:00
|
|
|
import java.util.ArrayList;
|
2016-07-11 19:47:19 -04:00
|
|
|
import java.util.HashMap;
|
2016-04-13 17:58:06 -04:00
|
|
|
import java.util.List;
|
2016-07-11 19:47:19 -04:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
2016-04-13 17:58:06 -04:00
|
|
|
|
2016-01-09 18:17:38 -05:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
2016-07-11 19:47:19 -04:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-01-09 18:17:38 -05:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-17 13:00:44 -07:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-07-11 19:47:19 -04:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
|
|
|
import net.minecraft.util.text.TextComponentTranslation;
|
2016-01-09 18:17:38 -05:00
|
|
|
import net.minecraft.world.World;
|
2016-04-13 17:58:06 -04:00
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
2016-07-11 19:47:19 -04:00
|
|
|
import WayofTime.bloodmagic.api.recipe.AlchemyTableRecipe;
|
|
|
|
import WayofTime.bloodmagic.api.registry.AlchemyTableRecipeRegistry;
|
2016-04-13 17:58:06 -04:00
|
|
|
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;
|
2016-07-11 16:47:27 -04:00
|
|
|
import WayofTime.bloodmagic.api.saving.SoulNetwork;
|
|
|
|
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
|
2016-04-13 17:58:06 -04:00
|
|
|
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
2016-07-11 16:47:27 -04:00
|
|
|
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
|
2016-04-13 17:58:06 -04:00
|
|
|
import WayofTime.bloodmagic.registry.ModBlocks;
|
|
|
|
import WayofTime.bloodmagic.util.Utils;
|
2016-01-09 18:17:38 -05:00
|
|
|
|
|
|
|
public class RitualCrushing extends Ritual
|
|
|
|
{
|
|
|
|
public static final String CRUSHING_RANGE = "crushingRange";
|
2016-04-11 09:57:57 -04:00
|
|
|
public static final String CHEST_RANGE = "chest";
|
2016-01-09 18:17:38 -05:00
|
|
|
|
2016-07-11 16:47:27 -04:00
|
|
|
public static double rawWillDrain = 0.5;
|
2016-07-11 19:47:19 -04:00
|
|
|
public static double steadfastWillDrain = 0.2;
|
|
|
|
public static double destructiveWillDrain = 0.2;
|
|
|
|
|
|
|
|
public static Map<ItemStack, Integer> cuttingFluidLPMap = new HashMap<ItemStack, Integer>();
|
|
|
|
public static Map<ItemStack, Double> cuttingFluidWillMap = new HashMap<ItemStack, Double>();
|
2016-07-11 16:47:27 -04:00
|
|
|
|
2016-01-09 18:17:38 -05:00
|
|
|
public RitualCrushing()
|
|
|
|
{
|
2016-02-16 11:46:47 -05:00
|
|
|
super("ritualCrushing", 0, 5000, "ritual." + Constants.Mod.MODID + ".crushingRitual");
|
2016-01-09 18:17:38 -05:00
|
|
|
addBlockRange(CRUSHING_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-1, -3, -1), 3));
|
2016-04-11 09:57:57 -04:00
|
|
|
addBlockRange(CHEST_RANGE, new AreaDescriptor.Rectangle(new BlockPos(0, 1, 0), 1));
|
|
|
|
|
|
|
|
setMaximumVolumeAndDistanceOfRange(CRUSHING_RANGE, 50, 10, 10);
|
|
|
|
setMaximumVolumeAndDistanceOfRange(CHEST_RANGE, 1, 3, 3);
|
2016-01-09 18:17:38 -05:00
|
|
|
}
|
|
|
|
|
2016-07-11 19:47:19 -04:00
|
|
|
public static void registerCuttingFluid(ItemStack stack, int lpDrain, double willDrain)
|
|
|
|
{
|
|
|
|
cuttingFluidLPMap.put(stack, lpDrain);
|
|
|
|
cuttingFluidWillMap.put(stack, willDrain);
|
|
|
|
}
|
|
|
|
|
2016-01-09 18:17:38 -05:00
|
|
|
@Override
|
|
|
|
public void performRitual(IMasterRitualStone masterRitualStone)
|
|
|
|
{
|
|
|
|
World world = masterRitualStone.getWorldObj();
|
|
|
|
SoulNetwork network = NetworkHelper.getSoulNetwork(masterRitualStone.getOwner());
|
|
|
|
int currentEssence = network.getCurrentEssence();
|
|
|
|
|
|
|
|
if (currentEssence < getRefreshCost())
|
|
|
|
{
|
2016-06-12 13:41:02 -07:00
|
|
|
network.causeNausea();
|
2016-01-09 18:17:38 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-11 16:47:27 -04:00
|
|
|
BlockPos pos = masterRitualStone.getBlockPos();
|
2016-07-11 19:47:19 -04:00
|
|
|
AreaDescriptor chestRange = getBlockRange(CHEST_RANGE);
|
|
|
|
TileEntity tile = world.getTileEntity(chestRange.getContainedPositions(pos).get(0));
|
|
|
|
|
|
|
|
if (tile != null && Utils.getNumberOfFreeSlots(tile, EnumFacing.DOWN) < 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-07-11 16:47:27 -04:00
|
|
|
|
|
|
|
List<EnumDemonWillType> willConfig = masterRitualStone.getActiveWillConfig();
|
|
|
|
|
2016-07-11 19:47:19 -04:00
|
|
|
double steadfastWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.STEADFAST, willConfig);
|
|
|
|
double corrosiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.CORROSIVE, willConfig);
|
|
|
|
double destructiveWill = this.getWillRespectingConfig(world, pos, EnumDemonWillType.DESTRUCTIVE, willConfig);
|
2016-07-11 16:47:27 -04:00
|
|
|
|
|
|
|
boolean isSilkTouch = steadfastWill >= steadfastWillDrain;
|
2016-07-11 19:47:19 -04:00
|
|
|
boolean useCuttingFluid = corrosiveWill > 0;
|
2016-01-09 18:17:38 -05:00
|
|
|
|
2016-07-11 19:47:19 -04:00
|
|
|
int fortune = destructiveWill > 0 ? 3 : 0;
|
2016-01-09 18:17:38 -05:00
|
|
|
|
|
|
|
AreaDescriptor crushingRange = getBlockRange(CRUSHING_RANGE);
|
|
|
|
|
|
|
|
for (BlockPos newPos : crushingRange.getContainedPositions(pos))
|
|
|
|
{
|
|
|
|
if (world.isAirBlock(newPos))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
IBlockState state = world.getBlockState(newPos);
|
|
|
|
Block block = state.getBlock();
|
2016-09-10 16:13:20 -07:00
|
|
|
if (block.equals(ModBlocks.RITUAL_CONTROLLER) || block.equals(ModBlocks.RITUAL_STONE) || block.getBlockHardness(state, world, newPos) == -1.0F || Utils.isBlockLiquid(state))
|
2016-01-09 18:17:38 -05:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:47:19 -04:00
|
|
|
boolean isBlockClaimed = false;
|
|
|
|
if (useCuttingFluid)
|
|
|
|
{
|
|
|
|
ItemStack checkStack = block.getItem(world, newPos, state);
|
|
|
|
if (checkStack == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack copyStack = checkStack.copy();
|
|
|
|
|
|
|
|
for (Entry<ItemStack, Integer> entry : cuttingFluidLPMap.entrySet())
|
|
|
|
{
|
|
|
|
ItemStack cuttingStack = entry.getKey();
|
|
|
|
int lpDrain = entry.getValue();
|
|
|
|
double willDrain = cuttingFluidWillMap.containsKey(cuttingStack) ? cuttingFluidWillMap.get(cuttingStack) : 0;
|
|
|
|
|
|
|
|
if (corrosiveWill < willDrain || currentEssence < lpDrain + getRefreshCost())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
cuttingStack = cuttingStack.copy();
|
|
|
|
List<ItemStack> input = new ArrayList<ItemStack>();
|
|
|
|
input.add(cuttingStack);
|
|
|
|
input.add(copyStack);
|
|
|
|
|
|
|
|
AlchemyTableRecipe recipe = AlchemyTableRecipeRegistry.getMatchingRecipe(input, world, pos);
|
|
|
|
if (recipe == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack result = recipe.getRecipeOutput(input);
|
|
|
|
if (result == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tile != null)
|
2016-07-28 09:23:31 -04:00
|
|
|
{
|
2016-07-11 19:47:19 -04:00
|
|
|
result = Utils.insertStackIntoTile(result, tile, EnumFacing.DOWN);
|
2016-07-28 09:23:31 -04:00
|
|
|
if (result != null && result.stackSize > 0)
|
|
|
|
{
|
|
|
|
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, result);
|
|
|
|
}
|
|
|
|
} else
|
2016-07-11 19:47:19 -04:00
|
|
|
{
|
|
|
|
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.CORROSIVE, willDrain, true);
|
|
|
|
corrosiveWill -= willDrain;
|
|
|
|
|
|
|
|
network.syphon(lpDrain);
|
|
|
|
currentEssence -= lpDrain;
|
|
|
|
|
|
|
|
isBlockClaimed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isBlockClaimed && isSilkTouch && block.canSilkHarvest(world, newPos, state, null))
|
2016-01-09 18:17:38 -05:00
|
|
|
{
|
2016-07-11 16:47:27 -04:00
|
|
|
ItemStack checkStack = block.getItem(world, newPos, state);
|
|
|
|
if (checkStack == null)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack copyStack = checkStack.copy();
|
|
|
|
|
|
|
|
if (steadfastWill >= steadfastWillDrain)
|
|
|
|
{
|
|
|
|
WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.STEADFAST, steadfastWillDrain, true);
|
|
|
|
steadfastWill -= steadfastWillDrain;
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-01-09 18:17:38 -05:00
|
|
|
|
2016-05-13 16:50:07 -07:00
|
|
|
if (tile != null)
|
2016-07-11 16:47:27 -04:00
|
|
|
copyStack = Utils.insertStackIntoTile(copyStack, tile, EnumFacing.DOWN);
|
2016-05-13 16:50:07 -07:00
|
|
|
else
|
|
|
|
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
|
2016-01-09 18:17:38 -05:00
|
|
|
|
2016-07-11 16:47:27 -04:00
|
|
|
if (copyStack != null && copyStack.stackSize > 0)
|
2016-01-09 18:17:38 -05:00
|
|
|
{
|
2016-05-13 16:50:07 -07:00
|
|
|
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
|
2016-01-09 18:17:38 -05:00
|
|
|
}
|
2016-07-11 19:47:19 -04:00
|
|
|
} else if (!isBlockClaimed)
|
2016-01-09 18:17:38 -05:00
|
|
|
{
|
2016-07-11 19:47:19 -04:00
|
|
|
if (fortune > 0 && destructiveWill < destructiveWillDrain)
|
|
|
|
{
|
|
|
|
fortune = 0;
|
|
|
|
}
|
|
|
|
|
2016-01-09 18:17:38 -05:00
|
|
|
List<ItemStack> stackList = block.getDrops(world, newPos, state, fortune);
|
|
|
|
|
|
|
|
if (stackList != null && !stackList.isEmpty())
|
|
|
|
{
|
|
|
|
for (ItemStack item : stackList)
|
|
|
|
{
|
|
|
|
ItemStack copyStack = ItemStack.copyItemStack(item);
|
|
|
|
|
2016-05-13 16:50:07 -07:00
|
|
|
if (tile != null)
|
|
|
|
{
|
|
|
|
copyStack = Utils.insertStackIntoTile(copyStack, tile, EnumFacing.DOWN);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
|
|
|
|
continue;
|
|
|
|
}
|
2016-04-13 17:58:06 -04:00
|
|
|
if (copyStack != null && copyStack.stackSize > 0)
|
2016-01-09 18:17:38 -05:00
|
|
|
{
|
2016-05-13 16:50:07 -07:00
|
|
|
Utils.spawnStackAtBlock(world, pos, EnumFacing.UP, copyStack);
|
2016-01-09 18:17:38 -05:00
|
|
|
}
|
|
|
|
}
|
2016-07-11 19:47:19 -04:00
|
|
|
|
|
|
|
if (fortune > 0)
|
|
|
|
{
|
|
|
|
WorldDemonWillHandler.drainWill(world, pos, EnumDemonWillType.DESTRUCTIVE, destructiveWillDrain, true);
|
|
|
|
destructiveWill -= destructiveWillDrain;
|
|
|
|
}
|
2016-01-09 18:17:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 19:12:33 -07:00
|
|
|
world.destroyBlock(newPos, false);
|
2016-02-19 20:11:29 -05:00
|
|
|
network.syphon(getRefreshCost());
|
2016-02-16 11:46:47 -05:00
|
|
|
|
|
|
|
break;
|
2016-01-09 18:17:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getRefreshTime()
|
|
|
|
{
|
|
|
|
return 40;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getRefreshCost()
|
|
|
|
{
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ArrayList<RitualComponent> getComponents()
|
|
|
|
{
|
|
|
|
ArrayList<RitualComponent> components = new ArrayList<RitualComponent>();
|
|
|
|
|
2016-07-12 16:57:22 -04:00
|
|
|
this.addParallelRunes(components, 1, 0, EnumRuneType.EARTH);
|
2016-01-09 18:17:38 -05:00
|
|
|
this.addParallelRunes(components, 2, 0, EnumRuneType.FIRE);
|
|
|
|
this.addCornerRunes(components, 2, 0, EnumRuneType.DUSK);
|
|
|
|
this.addParallelRunes(components, 2, 1, EnumRuneType.AIR);
|
|
|
|
|
|
|
|
return components;
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:47:19 -04:00
|
|
|
@Override
|
|
|
|
public ITextComponent[] provideInformationOfRitualToPlayer(EntityPlayer player)
|
|
|
|
{
|
|
|
|
return new ITextComponent[] { new TextComponentTranslation(this.getUnlocalizedName() + ".info"), new TextComponentTranslation(this.getUnlocalizedName() + ".destructive.info"), new TextComponentTranslation(this.getUnlocalizedName() + ".corrosive.info"), new TextComponentTranslation(this.getUnlocalizedName() + ".steadfast.info") };
|
|
|
|
}
|
|
|
|
|
2016-01-09 18:17:38 -05:00
|
|
|
@Override
|
|
|
|
public Ritual getNewCopy()
|
|
|
|
{
|
|
|
|
return new RitualCrushing();
|
|
|
|
}
|
|
|
|
}
|