Search in sources :

Example 1 with IMasterRitualStone

use of WayofTime.bloodmagic.ritual.IMasterRitualStone in project BloodMagic by WayofTime.

the class ItemRitualReader method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    if (!world.isRemote) {
        EnumRitualReaderState state = this.getState(stack);
        TileEntity tile = world.getTileEntity(pos);
        if (tile instanceof IMasterRitualStone) {
            IMasterRitualStone master = (IMasterRitualStone) tile;
            this.setMasterBlockPos(stack, pos);
            this.setBlockPos(stack, BlockPos.ORIGIN);
            switch(state) {
                case INFORMATION:
                    master.provideInformationOfRitualToPlayer(player);
                    break;
                case SET_AREA:
                    String range = this.getCurrentBlockRange(stack);
                    if (player.isSneaking()) {
                        String newRange = master.getNextBlockRange(range);
                        range = newRange;
                        this.setCurrentBlockRange(stack, newRange);
                    }
                    master.provideInformationOfRangeToPlayer(player, range);
                    break;
                case SET_WILL_TYPES:
                    List<EnumDemonWillType> typeList = new ArrayList<>();
                    NonNullList<ItemStack> inv = player.inventory.mainInventory;
                    for (int i = 0; i < 9; i++) {
                        ItemStack testStack = inv.get(i);
                        if (testStack.isEmpty()) {
                            continue;
                        }
                        if (testStack.getItem() instanceof IDiscreteDemonWill) {
                            EnumDemonWillType type = ((IDiscreteDemonWill) testStack.getItem()).getType(testStack);
                            if (!typeList.contains(type)) {
                                typeList.add(type);
                            }
                        }
                    }
                    master.setActiveWillConfig(player, typeList);
                    master.provideInformationOfWillConfigToPlayer(player, typeList);
                    break;
            }
            return EnumActionResult.FAIL;
        } else {
            if (state == EnumRitualReaderState.SET_AREA) {
                BlockPos masterPos = this.getMasterBlockPos(stack);
                if (!masterPos.equals(BlockPos.ORIGIN)) {
                    BlockPos containedPos = getBlockPos(stack);
                    if (containedPos.equals(BlockPos.ORIGIN)) {
                        this.setBlockPos(stack, pos.subtract(masterPos));
                        player.sendStatusMessage(new TextComponentTranslation("ritual.bloodmagic.blockRange.firstBlock"), true);
                    // TODO: Notify player.
                    } else {
                        tile = world.getTileEntity(masterPos);
                        if (tile instanceof IMasterRitualStone) {
                            IMasterRitualStone master = (IMasterRitualStone) tile;
                            master.setBlockRangeByBounds(player, this.getCurrentBlockRange(stack), containedPos, pos.subtract(masterPos));
                        }
                        this.setBlockPos(stack, BlockPos.ORIGIN);
                    }
                }
            }
        }
    }
    return super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IDiscreteDemonWill(WayofTime.bloodmagic.soul.IDiscreteDemonWill) EnumRitualReaderState(WayofTime.bloodmagic.ritual.EnumRitualReaderState) ArrayList(java.util.ArrayList) TileEntity(net.minecraft.tileentity.TileEntity) IMasterRitualStone(WayofTime.bloodmagic.ritual.IMasterRitualStone) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EnumDemonWillType(WayofTime.bloodmagic.soul.EnumDemonWillType)

Aggregations

EnumRitualReaderState (WayofTime.bloodmagic.ritual.EnumRitualReaderState)1 IMasterRitualStone (WayofTime.bloodmagic.ritual.IMasterRitualStone)1 EnumDemonWillType (WayofTime.bloodmagic.soul.EnumDemonWillType)1 IDiscreteDemonWill (WayofTime.bloodmagic.soul.IDiscreteDemonWill)1 ArrayList (java.util.ArrayList)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 BlockPos (net.minecraft.util.math.BlockPos)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1