Search in sources :

Example 16 with ExperienceOrbEntity

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

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 17 with ExperienceOrbEntity

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

the class EntityAIWorkFisherman method generateBonusLoot.

/**
 * Generates bonus fishing loot according to the building-level table
 */
private void generateBonusLoot() {
    final LootContext context = (new LootContext.Builder((ServerWorld) this.world)).withParameter(LootParameters.ORIGIN, entityFishHook.position()).withParameter(LootParameters.THIS_ENTITY, entityFishHook).withParameter(LootParameters.TOOL, worker.getMainHandItem()).withParameter(LootParameters.KILLER_ENTITY, worker).withRandom(worker.getRandom()).withLuck((float) getPrimarySkillLevel()).create(LootParameterSets.FISHING);
    final LootTable bonusLoot = this.world.getServer().getLootTables().get(ModLootTables.FISHERMAN_BONUS.getOrDefault(this.getOwnBuilding().getBuildingLevel(), new ResourceLocation("")));
    final List<ItemStack> loot = bonusLoot.getRandomItems(context);
    for (final ItemStack itemstack : loot) {
        final ItemEntity itementity = new ItemEntity(this.world, entityFishHook.position().x, entityFishHook.position().y, entityFishHook.position().z, itemstack);
        final double d0 = worker.getX() - entityFishHook.position().x;
        final double d1 = (worker.getY() + 0.5D) - entityFishHook.position().y;
        final double d2 = worker.getZ() - entityFishHook.position().z;
        itementity.noPhysics = true;
        itementity.setDeltaMovement(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D);
        this.world.addFreshEntity(itementity);
        worker.level.addFreshEntity(new ExperienceOrbEntity(worker.level, worker.getX(), worker.getY() + 0.5D, worker.getZ() + 0.5D, XP_PER_CATCH));
    }
}
Also used : LootTable(net.minecraft.loot.LootTable) ItemEntity(net.minecraft.entity.item.ItemEntity) LootContext(net.minecraft.loot.LootContext) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity)

Example 18 with ExperienceOrbEntity

use of net.minecraft.entity.item.ExperienceOrbEntity in project Enigmatic-Legacy by Aizistral-Studios.

the class XPScroll method onCurioTick.

@Override
public void onCurioTick(String identifier, LivingEntity entity) {
    ItemStack itemstack = SuperpositionHandler.getCurioStack(entity, EnigmaticLegacy.xpScroll);
    if (!(entity instanceof PlayerEntity) || entity.world.isRemote || !ItemNBTHelper.getBoolean(itemstack, "IsActive", false))
        return;
    PlayerEntity player = (PlayerEntity) entity;
    World world = player.world;
    if (ItemNBTHelper.getBoolean(itemstack, "AbsorptionMode", true)) {
        if (player.experienceTotal >= xpPortion) {
            player.giveExperiencePoints(-xpPortion);
            ItemNBTHelper.setInt(itemstack, "XPStored", ItemNBTHelper.getInt(itemstack, "XPStored", 0) + xpPortion);
        } else if (player.experienceTotal > 0 & ExperienceHelper.getPlayerXP(player) < xpPortion) {
            int exp = player.experienceTotal;
            player.giveExperiencePoints(-exp);
            ItemNBTHelper.setInt(itemstack, "XPStored", ItemNBTHelper.getInt(itemstack, "XPStored", 0) + exp);
        }
    } else {
        int xp = ItemNBTHelper.getInt(itemstack, "XPStored", 0);
        if (xp >= xpPortion) {
            ItemNBTHelper.setInt(itemstack, "XPStored", xp - xpPortion);
            player.giveExperiencePoints(xpPortion);
        } else if (xp > 0 & xp < xpPortion) {
            ItemNBTHelper.setInt(itemstack, "XPStored", 0);
            player.giveExperiencePoints(xp);
        }
    }
    List<ExperienceOrbEntity> orbs = world.getEntitiesWithinAABB(ExperienceOrbEntity.class, SuperpositionHandler.getBoundingBoxAroundEntity(player, ConfigHandler.XP_SCROLL_COLLECTION_RANGE.getValue()));
    for (ExperienceOrbEntity processed : orbs) {
        if (!processed.isAlive())
            continue;
        player.xpCooldown = 0;
        processed.onCollideWithPlayer(player);
    // processed.setPositionAndUpdate(player.posX, player.posY, player.posZ);
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 19 with ExperienceOrbEntity

use of net.minecraft.entity.item.ExperienceOrbEntity in project Arclight by IzzelAliz.

the class FishingBobberEntityMixin method handleHookRetraction.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public int handleHookRetraction(ItemStack p_146034_1_) {
    if (!this.world.isRemote && this.angler != null) {
        int i = 0;
        ItemFishedEvent event = null;
        if (this.caughtEntity != null) {
            PlayerFishEvent fishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) this.angler).bridge$getBukkitEntity(), ((EntityBridge) this.caughtEntity).bridge$getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_ENTITY);
            Bukkit.getPluginManager().callEvent(fishEvent);
            if (fishEvent.isCancelled()) {
                return 0;
            }
            this.bringInHookedEntity();
            CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayerEntity) this.angler, p_146034_1_, (FishingBobberEntity) (Object) this, Collections.emptyList());
            this.world.setEntityState((FishingBobberEntity) (Object) this, (byte) 31);
            i = this.caughtEntity instanceof ItemEntity ? 3 : 5;
        } else if (this.ticksCatchable > 0) {
            LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerWorld) this.world)).withParameter(LootParameters.POSITION, new BlockPos((FishingBobberEntity) (Object) this)).withParameter(LootParameters.TOOL, p_146034_1_).withRandom(this.rand).withLuck((float) this.luck + this.angler.getLuck());
            lootcontext$builder.withParameter(LootParameters.KILLER_ENTITY, this.angler).withParameter(LootParameters.THIS_ENTITY, (FishingBobberEntity) (Object) this);
            LootTable loottable = this.world.getServer().getLootTableManager().getLootTableFromLocation(LootTables.GAMEPLAY_FISHING);
            List<ItemStack> list = loottable.generate(lootcontext$builder.build(LootParameterSets.FISHING));
            event = new ItemFishedEvent(list, this.inGround ? 2 : 1, (FishingBobberEntity) (Object) this);
            MinecraftForge.EVENT_BUS.post(event);
            if (event.isCanceled()) {
                this.remove();
                return event.getRodDamage();
            }
            CriteriaTriggers.FISHING_ROD_HOOKED.trigger((ServerPlayerEntity) this.angler, p_146034_1_, (FishingBobberEntity) (Object) this, list);
            for (ItemStack itemstack : list) {
                ItemEntity itementity = new ItemEntity(this.world, this.posX, this.posY, this.posZ, itemstack);
                PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) this.angler).bridge$getBukkitEntity(), ((EntityBridge) itementity).bridge$getBukkitEntity(), (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.CAUGHT_FISH);
                playerFishEvent.setExpToDrop(this.rand.nextInt(6) + 1);
                Bukkit.getPluginManager().callEvent(playerFishEvent);
                if (playerFishEvent.isCancelled()) {
                    return 0;
                }
                double d0 = this.angler.posX - this.posX;
                double d1 = this.angler.posY - this.posY;
                double d2 = this.angler.posZ - this.posZ;
                double d3 = 0.1D;
                itementity.setMotion(d0 * 0.1D, d1 * 0.1D + Math.sqrt(Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2)) * 0.08D, d2 * 0.1D);
                this.world.addEntity(itementity);
                if (playerFishEvent.getExpToDrop() > 0) {
                    this.angler.world.addEntity(new ExperienceOrbEntity(this.angler.world, this.angler.posX, this.angler.posY + 0.5D, this.angler.posZ + 0.5D, playerFishEvent.getExpToDrop()));
                }
                if (itemstack.getItem().isIn(ItemTags.FISHES)) {
                    this.angler.addStat(Stats.FISH_CAUGHT, 1);
                }
            }
            i = 1;
        }
        if (this.inGround) {
            PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) this.angler).bridge$getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.IN_GROUND);
            Bukkit.getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return 0;
            }
            i = 2;
        }
        if (i == 0) {
            PlayerFishEvent playerFishEvent = new PlayerFishEvent(((ServerPlayerEntityBridge) this.angler).bridge$getBukkitEntity(), null, (FishHook) this.getBukkitEntity(), PlayerFishEvent.State.REEL_IN);
            Bukkit.getPluginManager().callEvent(playerFishEvent);
            if (playerFishEvent.isCancelled()) {
                return 0;
            }
        }
        this.remove();
        return event == null ? i : event.getRodDamage();
    } else {
        return 0;
    }
}
Also used : LootTable(net.minecraft.world.storage.loot.LootTable) FishingBobberEntity(net.minecraft.entity.projectile.FishingBobberEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) FishHook(org.bukkit.entity.FishHook) PlayerFishEvent(org.bukkit.event.player.PlayerFishEvent) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) ItemFishedEvent(net.minecraftforge.event.entity.player.ItemFishedEvent) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 20 with ExperienceOrbEntity

use of net.minecraft.entity.item.ExperienceOrbEntity in project Arclight by IzzelAliz.

the class FoxEntity_MateGoalMixin method spawnBaby.

/**
 * @author IzzekAkuz
 * @reason
 */
@Overwrite
protected void spawnBaby() {
    FoxEntity foxentity = (FoxEntity) this.animal.createChild(this.targetMate);
    if (foxentity != null) {
        ServerPlayerEntity serverplayerentity = this.animal.getLoveCause();
        ServerPlayerEntity serverplayerentity1 = this.targetMate.getLoveCause();
        ServerPlayerEntity serverplayerentity2 = serverplayerentity;
        if (serverplayerentity != null) {
            ((FoxEntityBridge) foxentity).bridge$addTrustedUUID(serverplayerentity.getUniqueID());
        } else {
            serverplayerentity2 = serverplayerentity1;
        }
        if (serverplayerentity1 != null && serverplayerentity != serverplayerentity1) {
            ((FoxEntityBridge) foxentity).bridge$addTrustedUUID(serverplayerentity1.getUniqueID());
        }
        int experience = this.animal.getRNG().nextInt(7) + 1;
        final EntityBreedEvent entityBreedEvent = CraftEventFactory.callEntityBreedEvent(foxentity, this.animal, this.targetMate, serverplayerentity, ((AnimalEntityBridge) this.animal).bridge$getBreedItem(), experience);
        if (entityBreedEvent.isCancelled()) {
            return;
        }
        experience = entityBreedEvent.getExperience();
        if (serverplayerentity2 != null) {
            serverplayerentity2.addStat(Stats.ANIMALS_BRED);
            CriteriaTriggers.BRED_ANIMALS.trigger(serverplayerentity2, this.animal, this.targetMate, foxentity);
        }
        int i = 6000;
        this.animal.setGrowingAge(6000);
        this.targetMate.setGrowingAge(6000);
        this.animal.resetInLove();
        this.targetMate.resetInLove();
        foxentity.setGrowingAge(-24000);
        foxentity.setLocationAndAngles(this.animal.posX, this.animal.posY, this.animal.posZ, 0.0F, 0.0F);
        ((WorldBridge) this.world).bridge$pushAddEntityReason(CreatureSpawnEvent.SpawnReason.BREEDING);
        this.world.addEntity(foxentity);
        this.world.setEntityState(this.animal, (byte) 18);
        if (this.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
            if (experience > 0) {
                this.world.addEntity(new ExperienceOrbEntity(this.world, this.animal.posX, this.animal.posY, this.animal.posZ, experience));
            }
        }
    }
}
Also used : EntityBreedEvent(org.bukkit.event.entity.EntityBreedEvent) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) FoxEntity(net.minecraft.entity.passive.FoxEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) FoxEntityBridge(io.izzel.arclight.common.bridge.entity.passive.FoxEntityBridge) Overwrite(org.spongepowered.asm.mixin.Overwrite)

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