Search in sources :

Example 1 with BlockStack

use of WayofTime.bloodmagic.util.BlockStack in project BloodMagic by WayofTime.

the class RitualAltarBuilder method getBloodRune.

public BlockStack getBloodRune(TileEntity tileEntity) {
    if (tileEntity != null) {
        if (tileEntity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN)) {
            IItemHandler itemHandler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
            if (itemHandler.getSlots() <= 0) {
                return null;
            }
            for (int i = 0; i < itemHandler.getSlots(); i++) {
                if (!itemHandler.getStackInSlot(i).isEmpty() && itemHandler.getStackInSlot(i).getItem() instanceof ItemBlock && Block.getBlockFromItem(itemHandler.getStackInSlot(i).getItem()) instanceof BlockBloodRune && itemHandler.extractItem(i, 1, true) != null) {
                    BlockStack blockStack = new BlockStack(Utils.getBlockForComponent(ComponentType.BLOODRUNE), itemHandler.getStackInSlot(i).getItemDamage());
                    itemHandler.extractItem(i, 1, false);
                    return blockStack;
                }
            }
        } else if (tileEntity instanceof IInventory) {
            IInventory inv = (IInventory) tileEntity;
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                if (!inv.getStackInSlot(i).isEmpty() && inv.getStackInSlot(i).getItem() instanceof ItemBlock && Block.getBlockFromItem(inv.getStackInSlot(i).getItem()) instanceof BlockBloodRune) {
                    BlockStack blockStack = new BlockStack(Utils.getBlockForComponent(ComponentType.BLOODRUNE), inv.getStackInSlot(i).getItemDamage());
                    inv.decrStackSize(i, 1);
                    return blockStack;
                }
            }
        }
    }
    return null;
}
Also used : IInventory(net.minecraft.inventory.IInventory) IItemHandler(net.minecraftforge.items.IItemHandler) ItemBlock(net.minecraft.item.ItemBlock) BlockStack(WayofTime.bloodmagic.util.BlockStack) BlockBloodRune(WayofTime.bloodmagic.block.BlockBloodRune)

Example 2 with BlockStack

use of WayofTime.bloodmagic.util.BlockStack in project BloodMagic by WayofTime.

the class RitualAltarBuilder method getMundaneBlock.

public BlockStack getMundaneBlock(TileEntity tileEntity) {
    if (tileEntity != null) {
        if (tileEntity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN)) {
            IItemHandler itemHandler = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
            if (itemHandler.getSlots() <= 0) {
                return null;
            }
            for (int i = 0; i < itemHandler.getSlots(); i++) {
                if (!itemHandler.getStackInSlot(i).isEmpty() && itemHandler.getStackInSlot(i).getItem() instanceof ItemBlock && !(Block.getBlockFromItem(itemHandler.getStackInSlot(i).getItem()) instanceof BlockBloodRune) && !itemHandler.extractItem(i, 1, true).isEmpty()) {
                    Block block = Block.getBlockFromItem(itemHandler.getStackInSlot(i).getItem());
                    if (block != Blocks.AIR && block != Blocks.GLOWSTONE && block != RegistrarBloodMagicBlocks.DECORATIVE_BRICK) {
                        BlockStack blockStack = new BlockStack(block, itemHandler.getStackInSlot(i).getItemDamage());
                        itemHandler.extractItem(i, 1, false);
                        return blockStack;
                    }
                }
            }
        } else if (tileEntity instanceof IInventory) {
            IInventory inv = (IInventory) tileEntity;
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                if (!inv.getStackInSlot(i).isEmpty() && inv.getStackInSlot(i).getItem() instanceof ItemBlock && !(Block.getBlockFromItem(inv.getStackInSlot(i).getItem()) instanceof BlockBloodRune)) {
                    Block block = Block.getBlockFromItem(inv.getStackInSlot(i).getItem());
                    if (block != Blocks.GLOWSTONE && block != RegistrarBloodMagicBlocks.DECORATIVE_BRICK) {
                        BlockStack blockStack = new BlockStack(block, inv.getStackInSlot(i).getItemDamage());
                        inv.decrStackSize(i, 1);
                        return blockStack;
                    }
                }
            }
        }
    }
    return null;
}
Also used : IInventory(net.minecraft.inventory.IInventory) IItemHandler(net.minecraftforge.items.IItemHandler) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemBlock(net.minecraft.item.ItemBlock) BlockStack(WayofTime.bloodmagic.util.BlockStack) BlockBloodRune(WayofTime.bloodmagic.block.BlockBloodRune)

Example 3 with BlockStack

use of WayofTime.bloodmagic.util.BlockStack in project BloodMagic by WayofTime.

the class RitualAltarBuilder method performRitual.

@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
    World world = masterRitualStone.getWorldObj();
    TileEntity tileEntity = world.getTileEntity(masterRitualStone.getBlockPos().up());
    BlockPos altarPos = masterRitualStone.getBlockPos().up(2);
    int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
    if (currentEssence < getRefreshCost()) {
        masterRitualStone.getOwnerNetwork().causeNausea();
        return;
    }
    if (cycleDone) {
        altarComponentsIterator = new ArrayList<>(AltarTier.SIX.getAltarComponents()).iterator();
    }
    if (world.getBlockState(altarPos).getBlock().isReplaceable(world, altarPos) && hasItem(tileEntity, Item.getItemFromBlock(RegistrarBloodMagicBlocks.ALTAR), 0, true)) {
        world.setBlockState(altarPos, RegistrarBloodMagicBlocks.ALTAR.getDefaultState());
        lightning(world, altarPos);
        masterRitualStone.getOwnerNetwork().syphon(getRefreshCost());
    }
    if (altarComponentsIterator.hasNext()) {
        currentComponent = altarComponentsIterator.next();
        currentPos = altarPos.add(currentComponent.getOffset());
        if (world.getBlockState(currentPos).getBlock().isReplaceable(world, currentPos)) {
            switch(currentComponent.getComponent()) {
                case NOTAIR:
                    {
                        BlockStack blockStack = getMundaneBlock(tileEntity);
                        if (blockStack != null) {
                            world.setBlockState(currentPos, blockStack.getState(), 3);
                            lightning(world, currentPos);
                            masterRitualStone.getOwnerNetwork().syphon(getRefreshCost());
                        }
                        break;
                    }
                case BLOODRUNE:
                    {
                        BlockStack blockStack = getBloodRune(tileEntity);
                        if (blockStack != null) {
                            world.setBlockState(currentPos, blockStack.getState(), 3);
                            lightning(world, currentPos);
                            masterRitualStone.getOwnerNetwork().syphon(getRefreshCost());
                        }
                        break;
                    }
                default:
                    {
                        BlockStack blockStack = new BlockStack(Utils.getBlockForComponent(currentComponent.getComponent()), 0);
                        if (hasItem(tileEntity, Item.getItemFromBlock(blockStack.getBlock()), blockStack.getMeta(), true)) {
                            world.setBlockState(currentPos, blockStack.getState(), 3);
                            lightning(world, currentPos);
                            masterRitualStone.getOwnerNetwork().syphon(getRefreshCost());
                        }
                        break;
                    }
            }
        }
    } else {
        cycleDone = true;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) BlockStack(WayofTime.bloodmagic.util.BlockStack)

Example 4 with BlockStack

use of WayofTime.bloodmagic.util.BlockStack in project BloodMagic by WayofTime.

the class ItemBoundPickaxe method onBoundRelease.

@Override
protected void onBoundRelease(ItemStack stack, World world, EntityPlayer player, int charge) {
    if (world.isRemote)
        return;
    boolean silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
    int fortuneLvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
    // Charge is a max of 30 - want 5 to be the max
    int range = (charge / 6);
    HashMultiset<ItemStackWrapper> drops = HashMultiset.create();
    BlockPos playerPos = player.getPosition();
    for (int i = -range; i <= range; i++) {
        for (int j = 0; j <= 2 * range; j++) {
            for (int k = -range; k <= range; k++) {
                BlockPos blockPos = playerPos.add(i, j, k);
                BlockStack blockStack = BlockStack.getStackFromPos(world, blockPos);
                if (blockStack.getBlock().isAir(blockStack.getState(), world, blockPos))
                    continue;
                if (blockStack.getState().getMaterial() != Material.ROCK && !EFFECTIVE_ON.contains(blockStack.getBlock()))
                    continue;
                BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockStack.getState(), player);
                if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
                    continue;
                if (blockStack.getBlock() != null && blockStack.getBlock().getBlockHardness(blockStack.getState(), world, blockPos) != -1) {
                    float strengthVsBlock = getDestroySpeed(stack, blockStack.getState());
                    if (strengthVsBlock > 1.1F && world.canMineBlockBody(player, blockPos)) {
                        if (silkTouch && blockStack.getBlock().canSilkHarvest(world, blockPos, world.getBlockState(blockPos), player))
                            drops.add(new ItemStackWrapper(blockStack));
                        else {
                            List<ItemStack> itemDrops = blockStack.getBlock().getDrops(world, blockPos, world.getBlockState(blockPos), fortuneLvl);
                            for (ItemStack stacks : itemDrops) drops.add(ItemStackWrapper.getHolder(stacks));
                        }
                        world.setBlockToAir(blockPos);
                    }
                }
            }
        }
    }
    NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, (int) (charge * charge * charge / 2.7));
    world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.5F, false);
    dropStacks(drops, world, playerPos.add(0, 1, 0));
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) ItemStackWrapper(WayofTime.bloodmagic.util.ItemStackWrapper) BlockStack(WayofTime.bloodmagic.util.BlockStack) ItemStack(net.minecraft.item.ItemStack) BlockEvent(net.minecraftforge.event.world.BlockEvent)

Example 5 with BlockStack

use of WayofTime.bloodmagic.util.BlockStack in project BloodMagic by WayofTime.

the class ItemBoundAxe method onBoundRelease.

@Override
protected void onBoundRelease(ItemStack stack, World world, EntityPlayer player, int charge) {
    if (world.isRemote)
        return;
    boolean silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
    int fortuneLvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
    // Charge is a max of 30 - want 5 to be the max
    int range = charge / 6;
    HashMultiset<ItemStackWrapper> drops = HashMultiset.create();
    BlockPos playerPos = player.getPosition();
    for (int i = -range; i <= range; i++) {
        for (int j = 0; j <= 2 * range; j++) {
            for (int k = -range; k <= range; k++) {
                BlockPos blockPos = playerPos.add(i, j, k);
                BlockStack blockStack = BlockStack.getStackFromPos(world, blockPos);
                if (blockStack.getBlock().isAir(blockStack.getState(), world, blockPos))
                    continue;
                if (blockStack.getState().getMaterial() != Material.WOOD && !EFFECTIVE_ON.contains(blockStack.getBlock()))
                    continue;
                BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockStack.getState(), player);
                if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
                    continue;
                if (blockStack.getState().getBlockHardness(world, blockPos) != -1.0F) {
                    float strengthVsBlock = getDestroySpeed(stack, blockStack.getState());
                    if (strengthVsBlock > 1.1F || blockStack.getBlock() instanceof BlockLeaves && world.canMineBlockBody(player, blockPos)) {
                        if (silkTouch && blockStack.getBlock().canSilkHarvest(world, blockPos, world.getBlockState(blockPos), player))
                            drops.add(new ItemStackWrapper(blockStack));
                        else {
                            List<ItemStack> itemDrops = blockStack.getBlock().getDrops(world, blockPos, world.getBlockState(blockPos), fortuneLvl);
                            for (ItemStack stacks : itemDrops) drops.add(ItemStackWrapper.getHolder(stacks));
                        }
                        world.setBlockToAir(blockPos);
                    }
                }
            }
        }
    }
    NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, (int) (charge * charge * charge / 2.7));
    world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.1F, false);
    dropStacks(drops, world, playerPos.add(0, 1, 0));
}
Also used : BlockStack(WayofTime.bloodmagic.util.BlockStack) BlockLeaves(net.minecraft.block.BlockLeaves) BlockPos(net.minecraft.util.math.BlockPos) ItemStackWrapper(WayofTime.bloodmagic.util.ItemStackWrapper) ItemStack(net.minecraft.item.ItemStack) BlockEvent(net.minecraftforge.event.world.BlockEvent)

Aggregations

BlockStack (WayofTime.bloodmagic.util.BlockStack)6 BlockPos (net.minecraft.util.math.BlockPos)4 ItemStackWrapper (WayofTime.bloodmagic.util.ItemStackWrapper)3 ItemStack (net.minecraft.item.ItemStack)3 BlockEvent (net.minecraftforge.event.world.BlockEvent)3 BlockBloodRune (WayofTime.bloodmagic.block.BlockBloodRune)2 IInventory (net.minecraft.inventory.IInventory)2 ItemBlock (net.minecraft.item.ItemBlock)2 IItemHandler (net.minecraftforge.items.IItemHandler)2 ArrayList (java.util.ArrayList)1 Block (net.minecraft.block.Block)1 BlockLeaves (net.minecraft.block.BlockLeaves)1 Material (net.minecraft.block.material.Material)1 TileEntity (net.minecraft.tileentity.TileEntity)1 World (net.minecraft.world.World)1