Search in sources :

Example 11 with ExperienceOrbEntity

use of net.minecraft.entity.item.ExperienceOrbEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityCQRExterminator method tickDeath.

// Death animation
// Death animation time: 1.44s => 29 ticks
@Override
protected void tickDeath() {
    ++this.deathTime;
    if (this.deathTime == 65) {
        this.spawnDeathPoofParticles();
    }
    if (this.deathTime >= 70 && this.isServerWorld()) {
        if (this.deathCause != null) {
            super.dropAllDeathLoot(deathCause);
        // super.dropLoot(this.lastHurtByPlayerTime > 0, net.minecraftforge.common.ForgeHooks.getLootingLevel(this, this.deathCause.getEntity(), this.deathCause), this.deathCause);
        }
        // Copied from EntityLivingBase
        if (!this.level.isClientSide && this.lastHurtByPlayerTime > 0 && this.shouldDropLoot() && this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
            int i = this.getExperienceReward(this.lastHurtByPlayer);
            i = net.minecraftforge.event.ForgeEventFactory.getExperienceDrop(this, this.lastHurtByPlayer, i);
            while (i > 0) {
                int j = ExperienceOrbEntity.getExperienceValue(i);
                i -= j;
                this.level.addFreshEntity(new ExperienceOrbEntity(this.level, this.getX(), this.getY(), this.getZ(), j));
            }
        }
        this.remove();
        this.onFinalDeath();
    }
}
Also used : ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity)

Example 12 with ExperienceOrbEntity

use of net.minecraft.entity.item.ExperienceOrbEntity in project minecolonies by ldtteam.

the class CitizenExperienceHandler method dropExperience.

@Override
public void dropExperience() {
    int experience;
    if (!CompatibilityUtils.getWorldFromCitizen(citizen).isClientSide && citizen.getRecentlyHit() > 0 && citizen.checkCanDropLoot() && CompatibilityUtils.getWorldFromCitizen(citizen).getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
        experience = (int) (citizen.getCitizenData().getCitizenSkillHandler().getTotalXP());
        while (experience > 0) {
            final int j = ExperienceOrbEntity.getExperienceValue(experience);
            experience -= j;
            CompatibilityUtils.getWorldFromCitizen(citizen).addFreshEntity(new ExperienceOrbEntity(CompatibilityUtils.getWorldFromCitizen(citizen), citizen.getX(), citizen.getY(), citizen.getZ(), j));
        }
    }
    // Spawn particle explosion of xp orbs on death
    for (int i = 0; i < XP_PARTICLE_EXPLOSION_SIZE; ++i) {
        final double d2 = citizen.getRandom().nextGaussian() * 0.02D;
        final double d0 = citizen.getRandom().nextGaussian() * 0.02D;
        final double d1 = citizen.getRandom().nextGaussian() * 0.02D;
        CompatibilityUtils.getWorldFromCitizen(citizen).addParticle(ParticleTypes.EXPLOSION, citizen.getX() + (citizen.getRandom().nextDouble() * citizen.getBbWidth() * 2.0F) - (double) citizen.getBbWidth(), citizen.getY() + (citizen.getRandom().nextDouble() * citizen.getBbHeight()), citizen.getZ() + (citizen.getRandom().nextDouble() * citizen.getBbWidth() * 2.0F) - (double) citizen.getBbWidth(), d2, d0, d1);
    }
}
Also used : ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity)

Example 13 with ExperienceOrbEntity

use of net.minecraft.entity.item.ExperienceOrbEntity in project minecolonies by ldtteam.

the class CitizenExperienceHandler method gatherXp.

@Override
public void gatherXp() {
    if (citizen.level.isClientSide) {
        return;
    }
    final int growSize = counterMovedXp > 0 || citizen.getRandom().nextInt(100) < 20 ? 8 : 2;
    final AxisAlignedBB box = citizen.getBoundingBox().inflate(growSize);
    if (!WorldUtil.isAABBLoaded(citizen.level, box)) {
        return;
    }
    boolean movedXp = false;
    for (@NotNull final ExperienceOrbEntity orb : citizen.level.getLoadedEntitiesOfClass(ExperienceOrbEntity.class, box)) {
        if (orb.tickCount < 5) {
            continue;
        }
        Vector3d vec3d = new Vector3d(citizen.getX() - orb.getX(), citizen.getY() + (double) this.citizen.getEyeHeight() / 2.0D - orb.getY(), citizen.getZ() - orb.getZ());
        double d1 = vec3d.lengthSqr();
        if (d1 < 1.0D) {
            addExperience(orb.getValue() / 2.5D);
            orb.remove();
            counterMovedXp = 0;
        } else if (counterMovedXp > MAX_XP_PICKUP_ATTEMPTS) {
            addExperience(orb.getValue() / 2.0D);
            orb.remove();
            counterMovedXp = 0;
            return;
        }
        double d2 = 1.0D - Math.sqrt(d1) / 8.0D;
        orb.setDeltaMovement(orb.getDeltaMovement().add(vec3d.normalize().scale(d2 * d2 * 0.1D)));
        movedXp = true;
        counterMovedXp++;
    }
    if (!movedXp) {
        counterMovedXp = 0;
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Vector3d(net.minecraft.util.math.vector.Vector3d) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with ExperienceOrbEntity

use of net.minecraft.entity.item.ExperienceOrbEntity in project ChaosAwakens by ChaosAwakens.

the class UltimateFishingBobberEntity method retrieve.

@Override
public int retrieve(ItemStack p_146034_1_) {
    PlayerEntity playerentity = this.getPlayerOwner();
    if (!this.level.isClientSide && playerentity != null) {
        int i = 0;
        net.minecraftforge.event.entity.player.ItemFishedEvent e = null;
        if (this.hookedIn != null) {
            this.bringInHookedEntity();
            CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayerEntity) playerentity, p_146034_1_, this, Collections.emptyList());
            this.level.broadcastEntityEvent(this, (byte) 31);
            i = this.hookedIn instanceof ItemEntity ? 3 : 5;
        } else if (this.nibble > 0) {
            LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerWorld) this.level)).withParameter(LootParameters.ORIGIN, this.position()).withParameter(LootParameters.TOOL, p_146034_1_).withParameter(LootParameters.THIS_ENTITY, this).withRandom(this.random).withLuck((float) this.luck + playerentity.getLuck());
            lootcontext$builder.withParameter(LootParameters.KILLER_ENTITY, this.getOwner()).withParameter(LootParameters.THIS_ENTITY, this);
            double d = (float) MathHelper.floor(this.getBoundingBox().minY) + 1.0F;
            BlockState state = this.level.getBlockState(new BlockPos(this.getX(), d - 1.0D, this.getZ()));
            ResourceLocation table;
            if (state.getMaterial() == Material.LAVA) {
                World w = playerentity.level;
                // final String location = biome.location().toString();
                if (BiomeDictionary.hasType(Biomes.NETHER_WASTES, BiomeDictionary.Type.NETHER) || BiomeDictionary.hasType(Biomes.CRIMSON_FOREST, BiomeDictionary.Type.NETHER) || BiomeDictionary.hasType(Biomes.WARPED_FOREST, BiomeDictionary.Type.NETHER)) {
                    // loottable = this.level.getServer().getLootTables().get(CALootTables.FISHING_NETHER_FISH);
                    table = CALootTables.FISHING_NETHER_FISH;
                } else if (!BiomeDictionary.hasType(Biomes.NETHER_WASTES, BiomeDictionary.Type.NETHER) || BiomeDictionary.hasType(Biomes.CRIMSON_FOREST, BiomeDictionary.Type.NETHER) || BiomeDictionary.hasType(Biomes.WARPED_FOREST, BiomeDictionary.Type.NETHER)) {
                    // loottable = this.level.getServer().getLootTables().get(CALootTables.FISHING_LAVA_FISH);
                    table = CALootTables.FISHING_LAVA_FISH;
                } else {
                    table = CALootTables.FISHING_LAVA_FISH;
                }
            } else {
                // loottable = this.level.getServer().getLootTables().get(LootTables.FISHING);
                table = LootTables.FISHING;
            }
            LootTable loottable = this.level.getServer().getLootTables().get(table);
            List<ItemStack> list = loottable.getRandomItems(lootcontext$builder.create(LootParameterSets.FISHING));
            e = new net.minecraftforge.event.entity.player.ItemFishedEvent(list, this.onGround ? 2 : 1, this);
            net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(e);
            if (e.isCanceled()) {
                this.remove();
                return e.getRodDamage();
            }
            CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayerEntity) playerentity, p_146034_1_, this, list);
            for (ItemStack itemstack : list) {
                ItemEntity itementity = new ItemEntity(this.level, this.getX(), this.getY(), this.getZ(), itemstack);
                double d0 = playerentity.getX() - this.getX();
                double d1 = playerentity.getY() - this.getY();
                double d2 = playerentity.getZ() - this.getZ();
                double d3 = 0.1D;
                itementity.setDeltaMovement(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D);
                this.level.addFreshEntity(itementity);
                playerentity.level.addFreshEntity(new ExperienceOrbEntity(playerentity.level, playerentity.getX(), playerentity.getY() + 0.5D, playerentity.getZ() + 0.5D, this.random.nextInt(6) + 1));
                if (itemstack.getItem().is(ItemTags.FISHES)) {
                    playerentity.awardStat(Stats.FISH_CAUGHT, 1);
                }
            }
            i = 1;
        }
        if (this.onGround) {
            i = 2;
        }
        this.remove();
        return e == null ? i : e.getRodDamage();
    } else {
        return 0;
    }
}
Also used : ItemEntity(net.minecraft.entity.item.ItemEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ServerWorld(net.minecraft.world.server.ServerWorld) BlockState(net.minecraft.block.BlockState) ResourceLocation(net.minecraft.util.ResourceLocation) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 15 with ExperienceOrbEntity

use of net.minecraft.entity.item.ExperienceOrbEntity in project minecolonies by Minecolonies.

the class CitizenExperienceHandler method dropExperience.

@Override
public void dropExperience() {
    int experience;
    if (!CompatibilityUtils.getWorldFromCitizen(citizen).isClientSide && citizen.getRecentlyHit() > 0 && citizen.checkCanDropLoot() && CompatibilityUtils.getWorldFromCitizen(citizen).getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
        experience = (int) (citizen.getCitizenData().getCitizenSkillHandler().getTotalXP());
        while (experience > 0) {
            final int j = ExperienceOrbEntity.getExperienceValue(experience);
            experience -= j;
            CompatibilityUtils.getWorldFromCitizen(citizen).addFreshEntity(new ExperienceOrbEntity(CompatibilityUtils.getWorldFromCitizen(citizen), citizen.getX(), citizen.getY(), citizen.getZ(), j));
        }
    }
    // Spawn particle explosion of xp orbs on death
    for (int i = 0; i < XP_PARTICLE_EXPLOSION_SIZE; ++i) {
        final double d2 = citizen.getRandom().nextGaussian() * 0.02D;
        final double d0 = citizen.getRandom().nextGaussian() * 0.02D;
        final double d1 = citizen.getRandom().nextGaussian() * 0.02D;
        CompatibilityUtils.getWorldFromCitizen(citizen).addParticle(ParticleTypes.EXPLOSION, citizen.getX() + (citizen.getRandom().nextDouble() * citizen.getBbWidth() * 2.0F) - (double) citizen.getBbWidth(), citizen.getY() + (citizen.getRandom().nextDouble() * citizen.getBbHeight()), citizen.getZ() + (citizen.getRandom().nextDouble() * citizen.getBbWidth() * 2.0F) - (double) citizen.getBbWidth(), d2, d0, d1);
    }
}
Also used : ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity)

Aggregations

ExperienceOrbEntity (net.minecraft.entity.item.ExperienceOrbEntity)26 ItemStack (net.minecraft.item.ItemStack)12 ItemEntity (net.minecraft.entity.item.ItemEntity)10 Overwrite (org.spongepowered.asm.mixin.Overwrite)8 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)6 List (java.util.List)5 ServerWorld (net.minecraft.world.server.ServerWorld)5 LootContext (net.minecraft.loot.LootContext)4 LootTable (net.minecraft.loot.LootTable)4 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)4 World (net.minecraft.world.World)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 Item (net.minecraft.item.Item)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)2 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)2 Entity (net.minecraft.entity.Entity)2 ActionResultType (net.minecraft.util.ActionResultType)2 Hand (net.minecraft.util.Hand)2 PacketItemInfo (com.supermartijn642.simplemagnets.packets.magnet.PacketItemInfo)1