Search in sources :

Example 21 with ExperienceOrbEntity

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

the class LivingEntityMixin_1_15 method dropExperience.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
protected void dropExperience() {
    // if (!this.world.isRemote && (this.isPlayer() || this.recentlyHit > 0 && this.canDropLoot() && this.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT))) {
    if (true) {
        int i = bridge$getExpToDrop();
        while (i > 0) {
            int j = ExperienceOrbEntity.getXPSplit(i);
            i -= j;
            this.world.addEntity(new ExperienceOrbEntity(this.world, this.getPosX(), this.getPosY(), this.getPosZ(), j));
        }
        bridge$setExpToDrop(0);
    }
}
Also used : ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 22 with ExperienceOrbEntity

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

the class AbstractFurnaceTileEntityMixin method spawnExpOrbs.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
private static void spawnExpOrbs(PlayerEntity entity, int ex, float f) {
    if (f == 0.0F) {
        ex = 0;
    } else if (f < 1.0F) {
        int i = MathHelper.floor((float) ex * f);
        if (i < MathHelper.ceil((float) ex * f) && Math.random() < (double) ((float) ex * f - (float) i)) {
            ++i;
        }
        ex = i;
    }
    if (arclight$captureFurnace != null && arclight$captureAmount != 0) {
        FurnaceExtractEvent event = new FurnaceExtractEvent(((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity(), CraftBlock.at(arclight$captureFurnace.getWorld(), arclight$captureFurnace.getPos()), CraftMagicNumbers.getMaterial(arclight$item.getItem()), arclight$captureAmount, ex);
        Bukkit.getPluginManager().callEvent(event);
        ex = event.getExpToDrop();
    }
    while (ex > 0) {
        int j = ExperienceOrbEntity.getXPSplit(ex);
        ex -= j;
        entity.world.addEntity(new ExperienceOrbEntity(entity.world, entity.posX, entity.posY + 0.5D, entity.posZ + 0.5D, j));
    }
}
Also used : FurnaceExtractEvent(org.bukkit.event.inventory.FurnaceExtractEvent) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 23 with ExperienceOrbEntity

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

the class ServerPlayNetHandlerMixin method processUseEntity.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void processUseEntity(final CUseEntityPacket packetIn) {
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, (ServerPlayNetHandler) (Object) this, this.player.getServerWorld());
    if (((ServerPlayerEntityBridge) this.player).bridge$isMovementBlocked()) {
        return;
    }
    final ServerWorld world = this.minecraftServer.getWorld(this.player.dimension);
    final Entity entity = packetIn.getEntityFromWorld(world);
    this.player.markPlayerActive();
    if (entity != null) {
        final boolean flag = this.player.canEntityBeSeen(entity);
        double d0 = 36.0;
        if (!flag) {
            d0 = 9.0;
        }
        if (this.player.getDistanceSq(entity) < d0) {
            final ItemStack itemInHand = this.player.getHeldItem((packetIn.getHand() == null) ? Hand.MAIN_HAND : packetIn.getHand());
            if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT || packetIn.getAction() == CUseEntityPacket.Action.INTERACT_AT) {
                final boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof MobEntity;
                final Item origItem = (this.player.inventory.getCurrentItem() == null) ? null : this.player.inventory.getCurrentItem().getItem();
                PlayerInteractEntityEvent event;
                if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT) {
                    event = new PlayerInteractEntityEvent(this.getPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), (packetIn.getHand() == Hand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND);
                } else {
                    final Vec3d target = packetIn.getHitVec();
                    event = new PlayerInteractAtEntityEvent(this.getPlayer(), ((EntityBridge) entity).bridge$getBukkitEntity(), new Vector(target.x, target.y, target.z), (packetIn.getHand() == Hand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND);
                }
                this.server.getPluginManager().callEvent(event);
                if (entity instanceof AbstractFishEntity && origItem != null && origItem.asItem() == Items.WATER_BUCKET && (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem)) {
                    this.sendPacket(new SSpawnMobPacket((LivingEntity) entity));
                    this.player.sendContainerToPlayer(this.player.openContainer);
                }
                if (triggerLeashUpdate && (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem)) {
                    this.sendPacket(new SMountEntityPacket(entity, ((MobEntity) entity).getLeashHolder()));
                }
                if (event.isCancelled() || this.player.inventory.getCurrentItem() == null || this.player.inventory.getCurrentItem().getItem() != origItem) {
                    this.sendPacket(new SEntityMetadataPacket(entity.getEntityId(), entity.getDataManager(), true));
                }
                if (event.isCancelled()) {
                    return;
                }
            }
            if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT) {
                final Hand hand = packetIn.getHand();
                this.player.interactOn(entity, hand);
                if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
                    this.player.sendContainerToPlayer(this.player.openContainer);
                }
            } else if (packetIn.getAction() == CUseEntityPacket.Action.INTERACT_AT) {
                final Hand hand = packetIn.getHand();
                if (net.minecraftforge.common.ForgeHooks.onInteractEntityAt(player, entity, packetIn.getHitVec(), hand) != null)
                    return;
                ActionResultType result = entity.applyPlayerInteraction(this.player, packetIn.getHitVec(), hand);
                if (result == ActionResultType.SUCCESS) {
                    this.player.swingArm(hand);
                }
                if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
                    this.player.sendContainerToPlayer(this.player.openContainer);
                }
            } else if (packetIn.getAction() == CUseEntityPacket.Action.ATTACK) {
                if (entity instanceof ItemEntity || entity instanceof ExperienceOrbEntity || entity instanceof AbstractArrowEntity || (entity == this.player && !this.player.isSpectator())) {
                    this.disconnect(new TranslationTextComponent("multiplayer.disconnect.invalid_entity_attacked"));
                    this.minecraftServer.logWarning("Player " + this.player.getName().getString() + " tried to attack an invalid entity");
                    return;
                }
                this.player.attackTargetEntityWithCurrentItem(entity);
                if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
                    this.player.sendContainerToPlayer(this.player.openContainer);
                }
            }
        }
    }
}
Also used : SignTileEntity(net.minecraft.tileentity.SignTileEntity) LivingEntity(net.minecraft.entity.LivingEntity) TileEntity(net.minecraft.tileentity.TileEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) AbstractFishEntity(net.minecraft.entity.passive.fish.AbstractFishEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) MobEntity(net.minecraft.entity.MobEntity) Entity(net.minecraft.entity.Entity) ItemEntity(net.minecraft.entity.item.ItemEntity) ActionResultType(net.minecraft.util.ActionResultType) SMountEntityPacket(net.minecraft.network.play.server.SMountEntityPacket) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) SSpawnMobPacket(net.minecraft.network.play.server.SSpawnMobPacket) ServerWorld(net.minecraft.world.server.ServerWorld) LivingEntity(net.minecraft.entity.LivingEntity) WritableBookItem(net.minecraft.item.WritableBookItem) Item(net.minecraft.item.Item) PlayerInteractAtEntityEvent(org.bukkit.event.player.PlayerInteractAtEntityEvent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) SignTileEntityBridge(io.izzel.arclight.common.bridge.tileentity.SignTileEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) Vector(org.bukkit.util.Vector) PlayerInteractEntityEvent(org.bukkit.event.player.PlayerInteractEntityEvent) ItemEntity(net.minecraft.entity.item.ItemEntity) AbstractFishEntity(net.minecraft.entity.passive.fish.AbstractFishEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) Hand(net.minecraft.util.Hand) Vec3d(net.minecraft.util.math.Vec3d) SEntityMetadataPacket(net.minecraft.network.play.server.SEntityMetadataPacket) CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) ItemStack(net.minecraft.item.ItemStack) MobEntity(net.minecraft.entity.MobEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 24 with ExperienceOrbEntity

use of net.minecraft.entity.item.ExperienceOrbEntity in project SimpleMagnets by SuperMartijn642.

the class MagnetItem method inventoryTick.

@Override
public void inventoryTick(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
    CompoundNBT tag = stack.getOrCreateTag();
    if (tag.contains("active") && tag.getBoolean("active")) {
        if (this.canPickupItems(tag)) {
            int r = this.getRangeItems(tag);
            AxisAlignedBB area = new AxisAlignedBB(entityIn.getCommandSenderWorldPosition().add(-r, -r, -r), entityIn.getCommandSenderWorldPosition().add(r, r, r));
            List<ItemEntity> items = worldIn.getEntities(EntityType.ITEM, area, item -> item.isAlive() && (!worldIn.isClientSide || item.tickCount > 1) && (item.getThrower() == null || !item.getThrower().equals(entityIn.getUUID()) || !item.hasPickUpDelay()) && !item.getItem().isEmpty() && !item.getPersistentData().contains("PreventRemoteMovement") && this.canPickupStack(tag, item.getItem()));
            items.forEach(item -> item.setPos(entityIn.getX(), entityIn.getY(), entityIn.getZ()));
            // Directly add items to the player's inventory when ItemPhysic is installed
            if (!worldIn.isClientSide && entityIn instanceof PlayerEntity && ModList.get().isLoaded("itemphysic"))
                items.forEach(item -> playerTouch(item, (PlayerEntity) entityIn));
        }
        if (!worldIn.isClientSide && this.canPickupXp(tag) && entityIn instanceof PlayerEntity) {
            int r = this.getRangeXp(tag);
            AxisAlignedBB area = new AxisAlignedBB(entityIn.getCommandSenderWorldPosition().add(-r, -r, -r), entityIn.getCommandSenderWorldPosition().add(r, r, r));
            PlayerEntity player = (PlayerEntity) entityIn;
            List<ExperienceOrbEntity> orbs = worldIn.getEntitiesOfClass(ExperienceOrbEntity.class, area);
            orbs.forEach(orb -> {
                orb.throwTime = 0;
                player.takeXpDelay = 0;
                orb.playerTouch(player);
            });
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityType(net.minecraft.entity.EntityType) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) Item(net.minecraft.item.Item) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) CompoundNBT(net.minecraft.nbt.CompoundNBT) ITooltipFlag(net.minecraft.client.util.ITooltipFlag) ITextComponent(net.minecraft.util.text.ITextComponent) Dist(net.minecraftforge.api.distmarker.Dist) ItemStack(net.minecraft.item.ItemStack) Stats(net.minecraft.stats.Stats) Hand(net.minecraft.util.Hand) Mod(net.minecraftforge.fml.common.Mod) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) PlayerEvent(net.minecraftforge.event.entity.player.PlayerEvent) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) ModList(net.minecraftforge.fml.ModList) PacketToggleMagnetMessage(com.supermartijn642.simplemagnets.packets.magnet.PacketToggleMagnetMessage) ActionResult(net.minecraft.util.ActionResult) List(java.util.List) PacketItemInfo(com.supermartijn642.simplemagnets.packets.magnet.PacketItemInfo) ItemEntity(net.minecraft.entity.item.ItemEntity) ActionResultType(net.minecraft.util.ActionResultType) ItemEntity(net.minecraft.entity.item.ItemEntity) CompoundNBT(net.minecraft.nbt.CompoundNBT) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 25 with ExperienceOrbEntity

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

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)

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