Search in sources :

Example 6 with IMinerStats

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

the class CaveEventHooks method onLivingUpdate.

@SubscribeEvent
public void onLivingUpdate(LivingUpdateEvent event) {
    EntityLivingBase entity = event.getEntityLiving();
    if (!(entity instanceof EntityPlayer) || entity instanceof FakePlayer) {
        return;
    }
    EntityPlayer player = (EntityPlayer) entity;
    MiningData.get(player).onUpdate();
    if (!player.isInWater() || !CavernAPI.dimension.isInCaveDimensions(player)) {
        return;
    }
    IMinerStats stats = MinerStats.get(player);
    if (stats.getRank() < MinerRank.AQUA_MINER.getRank()) {
        return;
    }
    if (!player.canBreatheUnderwater() && !player.isPotionActive(MobEffects.WATER_BREATHING) && player.ticksExisted % 20 == 0) {
        player.setAir(300);
    }
    if (player.capabilities.isFlying || EnchantmentHelper.getDepthStriderModifier(player) > 0) {
        return;
    }
    double prevY = player.posY;
    float vec1 = 0.6F;
    float vec2 = 0.01F;
    float vec3 = 0.4F;
    if (!player.onGround) {
        vec3 *= 0.5F;
    }
    if (player.getArmorVisibility() >= 0.75F) {
        vec3 *= 0.5F;
    }
    if (vec3 > 0.0F) {
        vec1 += (0.54600006F - vec1) * vec3 / 3.0F;
        vec2 += (player.getAIMoveSpeed() - vec2) * vec3 / 3.0F;
    }
    player.moveRelative(player.moveStrafing, player.moveVertical, player.moveForward, vec2);
    player.move(MoverType.SELF, player.motionX, player.motionY, player.motionZ);
    player.motionX *= vec1;
    player.motionY *= 0.800000011920929D;
    player.motionZ *= vec1;
    if (player.collidedHorizontally && player.isOffsetPositionInLiquid(player.motionX, player.motionY + 0.6000000238418579D - player.posY + prevY, player.motionZ)) {
        player.motionY = 0.30000001192092896D;
    }
    if (player.isSwingInProgress || player.isSneaking()) {
        player.motionY *= 0.3D;
    }
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) FakePlayer(net.minecraftforge.common.util.FakePlayer) IMinerStats(cavern.api.IMinerStats) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 7 with IMinerStats

use of cavern.api.IMinerStats 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 8 with IMinerStats

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

the class MiningAssistMessage method process.

@Override
public IMessage process(EntityPlayerMP player) {
    IMinerStats stats = MinerStats.get(player);
    if (stats.getRank() < MiningAssistConfig.minerRank.getValue()) {
        ITextComponent component = new TextComponentTranslation(MinerRank.get(MiningAssistConfig.minerRank.getValue()).getUnlocalizedName());
        component.getStyle().setItalic(Boolean.valueOf(true));
        component = new TextComponentTranslation("cavern.miningassist.toggle.failed.message", component);
        component.getStyle().setColor(TextFormatting.RED);
        player.sendMessage(component);
    } else {
        stats.toggleMiningAssist();
        stats.adjustData();
        ITextComponent component = new TextComponentTranslation(MiningAssist.get(stats.getMiningAssist()).getUnlocalizedName());
        component.getStyle().setColor(TextFormatting.GRAY).setItalic(Boolean.valueOf(true));
        component = new TextComponentTranslation("cavern.miningassist.toggle.message", component);
        player.sendMessage(component);
    }
    return null;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) ITextComponent(net.minecraft.util.text.ITextComponent) IMinerStats(cavern.api.IMinerStats)

Aggregations

IMinerStats (cavern.api.IMinerStats)8 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 ItemStack (net.minecraft.item.ItemStack)3 IMiningData (cavern.api.IMiningData)2 MiningAssist (cavern.miningassist.MiningAssist)2 IBlockState (net.minecraft.block.state.IBlockState)2 FakePlayer (net.minecraftforge.common.util.FakePlayer)2 IIceEquipment (cavern.api.IIceEquipment)1 IPlayerData (cavern.api.IPlayerData)1 IPortalCache (cavern.api.IPortalCache)1 ConfigDisplayPos (cavern.config.property.ConfigDisplayPos)1 MiningMessage (cavern.network.client.MiningMessage)1 MiningRecordsMessage (cavern.network.client.MiningRecordsMessage)1 MinerRank (cavern.stats.MinerRank)1 BlockMeta (cavern.util.BlockMeta)1 Minecraft (net.minecraft.client.Minecraft)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 RenderItem (net.minecraft.client.renderer.RenderItem)1