2016-02-18 16:25:11 +00:00
|
|
|
package WayofTime.bloodmagic.ritual;
|
|
|
|
|
2016-03-17 20:00:44 +00:00
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
2016-06-12 20:41:02 +00:00
|
|
|
import WayofTime.bloodmagic.api.saving.SoulNetwork;
|
2016-03-17 20:00:44 +00:00
|
|
|
import WayofTime.bloodmagic.api.ritual.*;
|
|
|
|
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
2016-02-18 16:25:11 +00:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemBlock;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-03-17 20:00:44 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-02-18 16:25:11 +00:00
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.items.CapabilityItemHandler;
|
|
|
|
import net.minecraftforge.items.IItemHandler;
|
2016-03-17 20:00:44 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2016-02-18 16:25:11 +00:00
|
|
|
|
|
|
|
public class RitualPlacer extends Ritual
|
|
|
|
{
|
|
|
|
public static final String PLACER_RANGE = "placerRange";
|
2016-04-11 13:57:57 +00:00
|
|
|
public static final String CHEST_RANGE = "chest";
|
2016-02-18 16:25:11 +00:00
|
|
|
|
|
|
|
public RitualPlacer()
|
|
|
|
{
|
|
|
|
super("ritualPlacer", 0, 5000, "ritual." + Constants.Mod.MODID + ".placerRitual");
|
2016-04-03 16:17:42 +00:00
|
|
|
addBlockRange(PLACER_RANGE, new AreaDescriptor.Rectangle(new BlockPos(-2, 0, -2), 5, 1, 5));
|
2016-04-11 13:57:57 +00:00
|
|
|
addBlockRange(CHEST_RANGE, new AreaDescriptor.Rectangle(new BlockPos(0, 1, 0), 1));
|
|
|
|
|
|
|
|
setMaximumVolumeAndDistanceOfRange(PLACER_RANGE, 300, 7, 7);
|
|
|
|
setMaximumVolumeAndDistanceOfRange(CHEST_RANGE, 1, 3, 3);
|
2016-02-18 16:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void performRitual(IMasterRitualStone masterRitualStone)
|
|
|
|
{
|
|
|
|
World world = masterRitualStone.getWorldObj();
|
|
|
|
SoulNetwork network = NetworkHelper.getSoulNetwork(masterRitualStone.getOwner());
|
2016-04-11 13:57:57 +00:00
|
|
|
BlockPos masterPos = masterRitualStone.getBlockPos();
|
|
|
|
AreaDescriptor chestRange = getBlockRange(CHEST_RANGE);
|
|
|
|
TileEntity tileEntity = world.getTileEntity(chestRange.getContainedPositions(masterPos).get(0));
|
2016-02-18 16:25:11 +00:00
|
|
|
|
|
|
|
int currentEssence = network.getCurrentEssence();
|
|
|
|
|
|
|
|
if (currentEssence < getRefreshCost())
|
|
|
|
{
|
2016-06-12 20:41:02 +00:00
|
|
|
network.causeNausea();
|
2016-02-18 16:25:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AreaDescriptor areaDescriptor = getBlockRange(PLACER_RANGE);
|
|
|
|
IInventory iInventory;
|
|
|
|
|
|
|
|
if (tileEntity != null)
|
|
|
|
{
|
|
|
|
// Using the new Forge inventory system
|
|
|
|
if (tileEntity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN))
|
|
|
|
{
|
|
|
|
IItemHandler iItemHandler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
|
|
|
|
|
|
|
|
if (iItemHandler.getSlots() <= 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (BlockPos blockPos : areaDescriptor.getContainedPositions(masterRitualStone.getBlockPos()))
|
|
|
|
{
|
|
|
|
for (int inv = 0; inv < iItemHandler.getSlots(); inv++)
|
|
|
|
{
|
|
|
|
if (world.getBlockState(blockPos).getBlock().isReplaceable(world, blockPos) && iItemHandler.getStackInSlot(inv) != null && iItemHandler.getStackInSlot(inv).stackSize != 0)
|
|
|
|
{
|
|
|
|
if (iItemHandler.getStackInSlot(inv).getItem() instanceof ItemBlock && world.getBlockState(blockPos.down()) != null)
|
|
|
|
{
|
|
|
|
if (iItemHandler.extractItem(inv, 1, true) != null)
|
|
|
|
{
|
|
|
|
world.setBlockState(blockPos, Block.getBlockFromItem(iItemHandler.getStackInSlot(inv).getItem()).getStateFromMeta(iItemHandler.getStackInSlot(inv).getItemDamage()));
|
|
|
|
iItemHandler.extractItem(inv, 1, false);
|
|
|
|
tileEntity.markDirty();
|
|
|
|
network.syphon(getRefreshCost());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-16 22:41:06 +00:00
|
|
|
//Compatibility with the old system, as it still exists
|
2016-02-18 16:25:11 +00:00
|
|
|
} else if (tileEntity instanceof IInventory)
|
|
|
|
{
|
|
|
|
iInventory = (IInventory) tileEntity;
|
|
|
|
|
|
|
|
if (iInventory.getSizeInventory() <= 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (BlockPos blockPos : areaDescriptor.getContainedPositions(masterRitualStone.getBlockPos()))
|
|
|
|
{
|
|
|
|
for (int inv = 0; inv < iInventory.getSizeInventory(); inv++)
|
|
|
|
{
|
|
|
|
if (world.getBlockState(blockPos).getBlock().isReplaceable(world, blockPos) && iInventory.getStackInSlot(inv) != null && iInventory.getStackInSlot(inv).stackSize != 0)
|
|
|
|
{
|
|
|
|
if (iInventory.getStackInSlot(inv).getItem() instanceof ItemBlock && world.getBlockState(blockPos.down()) != null)
|
|
|
|
{
|
|
|
|
world.setBlockState(blockPos, Block.getBlockFromItem(iInventory.getStackInSlot(inv).getItem()).getStateFromMeta(iInventory.getStackInSlot(inv).getItemDamage()));
|
|
|
|
iInventory.decrStackSize(inv, 1);
|
|
|
|
iInventory.markDirty();
|
|
|
|
network.syphon(getRefreshCost());
|
2016-04-11 13:57:57 +00:00
|
|
|
break;
|
2016-02-18 16:25:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getRefreshCost()
|
|
|
|
{
|
|
|
|
return 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ArrayList<RitualComponent> getComponents()
|
|
|
|
{
|
|
|
|
ArrayList<RitualComponent> components = new ArrayList<RitualComponent>();
|
|
|
|
|
|
|
|
addRune(components, 3, 0, 3, EnumRuneType.EARTH);
|
|
|
|
addRune(components, 3, 0, -3, EnumRuneType.EARTH);
|
|
|
|
addRune(components, -3, 0, 3, EnumRuneType.EARTH);
|
|
|
|
addRune(components, -3, 0, -3, EnumRuneType.EARTH);
|
|
|
|
|
|
|
|
addRune(components, 3, 0, 2, EnumRuneType.WATER);
|
|
|
|
addRune(components, 3, 0, -2, EnumRuneType.WATER);
|
|
|
|
addRune(components, 2, 0, 3, EnumRuneType.WATER);
|
|
|
|
addRune(components, 2, 0, -3, EnumRuneType.WATER);
|
|
|
|
addRune(components, -2, 0, 3, EnumRuneType.WATER);
|
|
|
|
addRune(components, -2, 0, -3, EnumRuneType.WATER);
|
|
|
|
addRune(components, -3, 0, 2, EnumRuneType.WATER);
|
|
|
|
addRune(components, -3, 0, -2, EnumRuneType.WATER);
|
|
|
|
|
|
|
|
return components;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Ritual getNewCopy()
|
|
|
|
{
|
|
|
|
return new RitualPlacer();
|
|
|
|
}
|
|
|
|
}
|