Search in sources :

Example 1 with ExperienceOrbEntity

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

the class NewBobberEntity method getDamage.

public int getDamage() {
    if (!this.level.isClientSide && this.angler != null) {
        int i = 0;
        final net.minecraftforge.event.entity.player.ItemFishedEvent event = null;
        if (this.caughtEntity != null) {
            this.bringInHookedEntity();
            this.level.broadcastEntityEvent(this, (byte) 31);
            i = this.caughtEntity instanceof ItemEntity ? 3 : 5;
        } else if (this.ticksCatchable > 0) {
            LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerWorld) this.level)).withParameter(LootParameters.ORIGIN, this.position()).withParameter(LootParameters.TOOL, this.getAngler().getMainHandItem()).withParameter(LootParameters.THIS_ENTITY, this).withRandom(this.random).withLuck((float) this.luck);
            lootcontext$builder.withParameter(LootParameters.KILLER_ENTITY, this.angler).withParameter(LootParameters.THIS_ENTITY, this);
            final LootTable loottable = this.level.getServer().getLootTables().get(ModLootTables.FISHING);
            final List<ItemStack> list = loottable.getRandomItems(lootcontext$builder.create(LootParameterSets.FISHING));
            for (final ItemStack itemstack : list) {
                final ItemEntity itementity = new ItemEntity(this.level, onWaterPos.x, onWaterPos.y, onWaterPos.z, itemstack);
                final double d0 = this.angler.getX() - onWaterPos.x;
                final double d1 = (this.angler.getY() + 0.5D) - onWaterPos.y;
                final double d2 = this.angler.getZ() - onWaterPos.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.level.addFreshEntity(itementity);
                this.angler.level.addFreshEntity(new ExperienceOrbEntity(this.angler.level, this.angler.getX(), this.angler.getY() + 0.5D, this.angler.getZ() + 0.5D, XP_PER_CATCH));
            }
            i = 1;
        }
        if (this.inGround) {
            i = 2;
        }
        this.remove();
        return event == null ? i : event.getRodDamage();
    } else {
        return 0;
    }
}
Also used : LootTable(net.minecraft.loot.LootTable) ItemEntity(net.minecraft.entity.item.ItemEntity) LootContext(net.minecraft.loot.LootContext) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) ServerWorld(net.minecraft.world.server.ServerWorld) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ExperienceOrbEntity

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

the class ExperienceBottleEntityMixin method onImpact.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
protected void onImpact(RayTraceResult result) {
    if (!this.world.isRemote) {
        int i = 3 + this.world.rand.nextInt(5) + this.world.rand.nextInt(5);
        ExpBottleEvent event = CraftEventFactory.callExpBottleEvent((ExperienceBottleEntity) (Object) this, i);
        i = event.getExperience();
        if (event.getShowEffect()) {
            this.world.playEvent(2002, new BlockPos((ExperienceBottleEntity) (Object) this), PotionUtils.getPotionColor(Potions.WATER));
        }
        while (i > 0) {
            int j = ExperienceOrbEntity.getXPSplit(i);
            i -= j;
            this.world.addEntity(new ExperienceOrbEntity(this.world, this.posX, this.posY, this.posZ, j));
        }
        this.remove();
    }
}
Also used : ExpBottleEvent(org.bukkit.event.entity.ExpBottleEvent) BlockPos(net.minecraft.util.math.BlockPos) ExperienceBottleEntity(net.minecraft.entity.item.ExperienceBottleEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 3 with ExperienceOrbEntity

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

the class ExperienceOrbEntityMixin method onCollideWithPlayer.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void onCollideWithPlayer(PlayerEntity entityIn) {
    if (!this.world.isRemote) {
        if (this.delayBeforeCanPickup == 0 && entityIn.xpCooldown == 0) {
            if (MinecraftForge.EVENT_BUS.post(new PlayerXpEvent.PickupXp(entityIn, (ExperienceOrbEntity) (Object) this)))
                return;
            entityIn.xpCooldown = 2;
            entityIn.onItemPickup((ExperienceOrbEntity) (Object) this, 1);
            Map.Entry<EquipmentSlotType, ItemStack> entry = EnchantmentHelper.getRandomItemWithEnchantment(Enchantments.MENDING, entityIn);
            if (entry != null) {
                ItemStack itemstack = entry.getValue();
                if (!itemstack.isEmpty() && itemstack.isDamaged()) {
                    int i = Math.min((int) (this.xpValue * itemstack.getXpRepairRatio()), itemstack.getDamage());
                    org.bukkit.event.player.PlayerItemMendEvent event = CraftEventFactory.callPlayerItemMendEvent(entityIn, (ExperienceOrbEntity) (Object) this, itemstack, i);
                    i = event.getRepairAmount();
                    if (!event.isCancelled()) {
                        this.xpValue -= this.durabilityToXp(i);
                        itemstack.setDamage(itemstack.getDamage() - i);
                    }
                }
            }
            if (this.xpValue > 0) {
                entityIn.giveExperiencePoints(CraftEventFactory.callPlayerExpChangeEvent(entityIn, this.xpValue).getAmount());
            }
            this.remove();
        }
    }
}
Also used : EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) PlayerXpEvent(net.minecraftforge.event.entity.player.PlayerXpEvent) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with ExperienceOrbEntity

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

the class LivingEntityMixin_1_14 method onDeathUpdate.

// @formatter:on
/**
 * @author IzzelAliz
 * @reason
 */
@SuppressWarnings("ConstantConditions")
@Overwrite
protected void onDeathUpdate() {
    ++this.deathTime;
    if (this.deathTime >= 20 && !this.removed) {
        if (!this.world.isRemote && (this.isPlayer() || this.recentlyHit > 0 && this.canDropLoot() && this.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT))) {
            int i = this.bridge$getExpToDrop();
            while (i > 0) {
                int j = ExperienceOrbEntity.getXPSplit(i);
                i -= j;
                this.world.addEntity(new ExperienceOrbEntity(this.world, this.posX, this.posY, this.posZ, j));
            }
            this.bridge$setExpToDrop(0);
        }
        // Forge keep data until we revive player
        this.remove((Object) this instanceof ServerPlayerEntity);
        for (int k = 0; k < 20; ++k) {
            double d2 = this.rand.nextGaussian() * 0.02D;
            double d0 = this.rand.nextGaussian() * 0.02D;
            double d1 = this.rand.nextGaussian() * 0.02D;
            this.world.addParticle(ParticleTypes.POOF, this.posX + (double) (this.rand.nextFloat() * this.getWidth() * 2.0F) - (double) this.getWidth(), this.posY + (double) (this.rand.nextFloat() * this.getHeight()), this.posZ + (double) (this.rand.nextFloat() * this.getWidth() * 2.0F) - (double) this.getWidth(), d2, d0, d1);
        }
    }
}
Also used : ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 5 with ExperienceOrbEntity

use of net.minecraft.entity.item.ExperienceOrbEntity in project Fragile-Glass by fredtargaryen.

the class SugarCauldronBlock method onPlayerDestroy.

@Override
public void onPlayerDestroy(IWorld worldIn, BlockPos pos, BlockState state) {
    World w = (World) worldIn;
    if (state.get(AGE_0_7).equals(6) && !w.isRemote) {
        double x = pos.getX();
        double y = pos.getY();
        double z = pos.getZ();
        ItemEntity entityItem = new ItemEntity(w, x + 0.5D, y + 1.0D, z + 0.5D, new ItemStack(FragileGlassBase.FRAGILE_GLASS, WorldgenConfig.GLASS_YIELD.get()));
        w.addEntity(entityItem);
        w.addEntity(new ExperienceOrbEntity(w, x + 0.5, y + 0.5, z + 0.5, 4));
    }
    super.onPlayerDestroy(worldIn, pos, state);
}
Also used : ItemEntity(net.minecraft.entity.item.ItemEntity) ServerWorld(net.minecraft.world.server.ServerWorld) IWorld(net.minecraft.world.IWorld) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) 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