Search in sources :

Example 1 with IIceEquipment

use of cavern.api.IIceEquipment in project Cavern2 by kegare.

the class CaveEventHooks method onItemCrafted.

@SubscribeEvent
public void onItemCrafted(ItemCraftedEvent event) {
    EntityPlayer player = event.player;
    ItemStack stack = event.crafting;
    World world = player.world;
    if (!world.isRemote && !stack.isEmpty()) {
        if (stack.getItem() instanceof IIceEquipment) {
            int charge = ((IIceEquipment) stack.getItem()).getCharge(stack);
            if (charge > 0 && stack.getTagCompound().getBoolean("AfterIceCharge")) {
                PlayerHelper.grantAdvancement(player, "ice_charge");
                stack.getTagCompound().removeTag("AfterIceCharge");
            }
        }
    }
}
Also used : IIceEquipment(cavern.api.IIceEquipment) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IIceEquipment

use of cavern.api.IIceEquipment in project Cavern2 by kegare.

the class CaveEventHooks method onBlockBreak.

@SubscribeEvent
public void onBlockBreak(BreakEvent event) {
    EntityPlayer entityPlayer = event.getPlayer();
    if (entityPlayer == null || entityPlayer instanceof FakePlayer || !(entityPlayer instanceof EntityPlayerMP)) {
        return;
    }
    EntityPlayerMP player = (EntityPlayerMP) entityPlayer;
    if (!CavernAPI.dimension.isInCaveDimensions(player)) {
        return;
    }
    World world = event.getWorld();
    IBlockState state = event.getState();
    ItemStack stack = player.getHeldItemMainhand();
    if (GeneralConfig.isMiningPointItem(stack)) {
        int point = MinerStats.getPointAmount(state);
        if (point != 0) {
            IMinerStats stats = MinerStats.get(player);
            IMiningData data = MiningData.get(player);
            if (player.inventory.hasItemStack(ItemCave.EnumType.MINER_ORB.getItemStack())) {
                if (RANDOM.nextDouble() < 0.15D) {
                    point += Math.max(point / 2, 1);
                }
            }
            stats.addPoint(point);
            stats.addMiningRecord(new BlockMeta(state));
            data.notifyMining(state, point);
            int combo = data.getMiningCombo();
            if (combo > 0 && combo % 10 == 0) {
                world.playSound(null, player.posX, player.posY + 0.25D, player.posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 0.1F, 0.5F * ((RANDOM.nextFloat() - RANDOM.nextFloat()) * 0.7F + 1.8F));
                player.addExperience(combo / 10);
            }
            if (combo >= 50) {
                PlayerHelper.grantAdvancement(player, "good_mine");
            }
            CaveNetworkRegistry.sendTo(new MiningMessage(state, point), player);
        }
    }
    if (CavernAPI.dimension.isInFrostMountains(player)) {
        if (player.capabilities.isCreativeMode) {
            return;
        }
        if (state.getBlock() != Blocks.PACKED_ICE || EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0) {
            return;
        }
        BlockPos pos = event.getPos();
        Biome biome = world.getBiome(pos);
        if (!biome.isSnowyBiome()) {
            return;
        }
        if (RANDOM.nextDouble() < 0.05D) {
            Block.spawnAsEntity(world, pos, new ItemStack(Blocks.ICE));
        } else if (RANDOM.nextDouble() < 0.005D) {
            Block.spawnAsEntity(world, pos, RandomiteHelper.getDropItem());
        } else if (stack.getItem() instanceof IIceEquipment && RANDOM.nextDouble() < 0.03D || RANDOM.nextDouble() < 0.01D) {
            Block.spawnAsEntity(world, pos, new ItemStack(Blocks.PACKED_ICE));
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IIceEquipment(cavern.api.IIceEquipment) World(net.minecraft.world.World) FakePlayer(net.minecraftforge.common.util.FakePlayer) IMinerStats(cavern.api.IMinerStats) IMiningData(cavern.api.IMiningData) Biome(net.minecraft.world.biome.Biome) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MiningMessage(cavern.network.client.MiningMessage) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) BlockMeta(cavern.util.BlockMeta) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with IIceEquipment

use of cavern.api.IIceEquipment in project Cavern2 by kegare.

the class RecipeChargeIceEquipment method matches.

@Override
public boolean matches(InventoryCrafting crafting, World world) {
    resultItem = ItemStack.EMPTY;
    if (!(crafting.getStackInRowAndColumn(1, 1).getItem() instanceof IIceEquipment)) {
        return false;
    }
    int ice = 0;
    for (int row = 0; row < 3; ++row) {
        for (int column = 0; column < 3; ++column) {
            if (row == 1 && column == 1) {
                continue;
            }
            ItemStack stack = crafting.getStackInRowAndColumn(row, column);
            if (!stack.isEmpty()) {
                Block block = Block.getBlockFromItem(stack.getItem());
                if (block == null) {
                    continue;
                }
                if (block instanceof BlockIce || block instanceof BlockPackedIce) {
                    if (row != 1 && column == 1 || row == 1 && column != 1) {
                        ++ice;
                    }
                } else if (row != 1 && column != 1) {
                    return false;
                }
            }
        }
    }
    if (ice >= 4) {
        resultItem = getResult(crafting);
        return true;
    }
    return false;
}
Also used : BlockIce(net.minecraft.block.BlockIce) IIceEquipment(cavern.api.IIceEquipment) BlockPackedIce(net.minecraft.block.BlockPackedIce) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IIceEquipment (cavern.api.IIceEquipment)3 ItemStack (net.minecraft.item.ItemStack)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 IMinerStats (cavern.api.IMinerStats)1 IMiningData (cavern.api.IMiningData)1 MiningMessage (cavern.network.client.MiningMessage)1 BlockMeta (cavern.util.BlockMeta)1 Block (net.minecraft.block.Block)1 BlockIce (net.minecraft.block.BlockIce)1 BlockPackedIce (net.minecraft.block.BlockPackedIce)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 BlockPos (net.minecraft.util.math.BlockPos)1 Biome (net.minecraft.world.biome.Biome)1 FakePlayer (net.minecraftforge.common.util.FakePlayer)1