Search in sources :

Example 26 with ItemEntity

use of net.minecraft.entity.ItemEntity in project friends-and-foes by Faboslav.

the class MoobloomEntity method sheared.

public void sheared(SoundCategory shearedSoundCategory) {
    this.world.playSoundFromEntity(null, this, SoundEvents.ENTITY_MOOSHROOM_SHEAR, shearedSoundCategory, 1.0F, 1.0F);
    if (!this.world.isClient()) {
        ((ServerWorld) this.world).spawnParticles(ParticleTypes.EXPLOSION, this.getX(), this.getBodyY(0.5D), this.getZ(), 1, 0.0D, 0.0D, 0.0D, 0.0D);
        this.discard();
        CowEntity cowEntity = EntityType.COW.create(this.world);
        if (cowEntity == null) {
            return;
        }
        cowEntity.setHealth(this.getHealth());
        cowEntity.copyPositionAndRotation(this);
        cowEntity.prevBodyYaw = this.prevBodyYaw;
        cowEntity.bodyYaw = this.bodyYaw;
        cowEntity.prevHeadYaw = this.prevHeadYaw;
        cowEntity.headYaw = this.headYaw;
        if (this.hasCustomName()) {
            cowEntity.setCustomName(this.getCustomName());
            cowEntity.setCustomNameVisible(this.isCustomNameVisible());
        }
        if (this.isPersistent()) {
            cowEntity.setPersistent();
        }
        cowEntity.setInvulnerable(this.isInvulnerable());
        this.getEntityWorld().spawnEntity(cowEntity);
        for (int i = 0; i < 5; ++i) {
            this.getEntityWorld().spawnEntity(new ItemEntity(this.world, this.getX(), this.getBodyY(1.0D), this.getZ(), new ItemStack(ModBlocks.BUTTERCUP.get())));
        }
    }
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) ItemEntity(net.minecraft.entity.ItemEntity) ItemStack(net.minecraft.item.ItemStack) CowEntity(net.minecraft.entity.passive.CowEntity)

Example 27 with ItemEntity

use of net.minecraft.entity.ItemEntity in project Client by MatHax.

the class ClientPlayNetworkHandlerMixin method onItemPickupAnimation.

@Inject(method = "onItemPickupAnimation", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientWorld;getEntityById(I)Lnet/minecraft/entity/Entity;", ordinal = 0))
private void onItemPickupAnimation(ItemPickupAnimationS2CPacket packet, CallbackInfo info) {
    Entity itemEntity = client.world.getEntityById(packet.getEntityId());
    Entity entity = client.world.getEntityById(packet.getCollectorEntityId());
    if (itemEntity instanceof ItemEntity && entity == client.player)
        MatHax.EVENT_BUS.post(PickItemsEvent.get(((ItemEntity) itemEntity).getStack(), packet.getStackAmount()));
}
Also used : Entity(net.minecraft.entity.Entity) ItemEntity(net.minecraft.entity.ItemEntity) ItemEntity(net.minecraft.entity.ItemEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 28 with ItemEntity

use of net.minecraft.entity.ItemEntity in project AurorasDecorations by LambdAurora.

the class ShelfBlock method onBlockBreakStart.

@Override
public void onBlockBreakStart(BlockState state, World world, BlockPos pos, PlayerEntity player) {
    var shelf = AurorasDecoRegistry.SHELF_BLOCK_ENTITY_TYPE.get(world, pos);
    if (shelf != null && !shelf.isEmpty()) {
        Direction facing = state.get(FACING);
        var cameraPosVec = player.getCameraPosVec(1.0F);
        var rotationVec = player.getRotationVec(1.0F);
        var extendedVec = cameraPosVec.add(rotationVec.x * 4.5F, rotationVec.y * 4.5F, rotationVec.z * 4.5F);
        var rayCtx = new RaycastContext(cameraPosVec, extendedVec, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, player);
        var hit = world.raycast(rayCtx);
        int y = 0;
        if (AuroraUtil.posMod(hit.getPos().getY(), 1) <= 0.5)
            y = 1;
        int x;
        if (facing.getAxis() == Direction.Axis.Z) {
            x = (int) (AuroraUtil.posMod(hit.getPos().getX(), 1) * 4.0);
        } else {
            x = 3 - (int) (AuroraUtil.posMod(hit.getPos().getZ(), 1) * 4.0);
        }
        if (facing.getDirection() == Direction.AxisDirection.NEGATIVE) {
            x = 3 - x;
        }
        int slot = y * 4 + x;
        var stack = shelf.getStack(slot);
        if (!stack.isEmpty()) {
            if (player.getStackInHand(Hand.MAIN_HAND).isEmpty()) {
                player.setStackInHand(Hand.MAIN_HAND, stack.copy());
                shelf.removeStack(slot);
            } else {
                var item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, stack.copy());
                float speed = world.random.nextFloat() * .5f;
                float angle = world.random.nextFloat() * 6.2831855f;
                item.setVelocity(-MathHelper.sin(angle) * speed, 0.20000000298023224, MathHelper.cos(angle) * speed);
                world.spawnEntity(item);
                shelf.removeStack(slot);
            }
            world.emitGameEvent(player, GameEvent.BLOCK_CHANGE, pos);
        }
    }
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity) Direction(net.minecraft.util.math.Direction)

Example 29 with ItemEntity

use of net.minecraft.entity.ItemEntity in project Terracraft by SimplyCmd.

the class SickleItem method postMine.

@Override
public boolean postMine(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity miner) {
    if (miner instanceof ServerPlayerEntity && !((ServerPlayerEntity) miner).isCreative() && state.getBlock() instanceof FernBlock) {
        ItemEntity entity = new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), BlockRegistry.grass_bale.getItem().get().getDefaultStack());
        entity.updatePosition(pos.getX(), pos.getY(), pos.getZ());
        world.spawnEntity(entity);
    }
    stack.damage(1, miner, (e) -> e.sendEquipmentBreakStatus(EquipmentSlot.MAINHAND));
    return true;
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) FernBlock(net.minecraft.block.FernBlock)

Example 30 with ItemEntity

use of net.minecraft.entity.ItemEntity in project Terracraft by SimplyCmd.

the class CoinPortalEntity method tick.

@Override
public void tick() {
    tick++;
    if (tick % 10 == 0) {
        ItemEntity coin = new ItemEntity(world, this.getX(), this.getY(), this.getZ(), ItemRegistry.gold_coin.getItem().getDefaultStack());
        world.spawnEntity(coin);
    }
    if (tick >= 100)
        kill();
    this.move(MovementType.SELF, this.getVelocity());
    this.baseTick();
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity)

Aggregations

ItemEntity (net.minecraft.entity.ItemEntity)32 ItemStack (net.minecraft.item.ItemStack)15 PlayerEntity (net.minecraft.entity.player.PlayerEntity)7 Inject (org.spongepowered.asm.mixin.injection.Inject)6 Entity (net.minecraft.entity.Entity)5 LivingEntity (net.minecraft.entity.LivingEntity)5 Box (net.minecraft.util.math.Box)4 Monster (net.minecraft.entity.mob.Monster)3 Vec3d (net.minecraft.util.math.Vec3d)3 Item (net.minecraft.item.Item)2 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)2 World (net.minecraft.world.World)2 AllowConcurrentEvents (com.google.common.eventbus.AllowConcurrentEvents)1 Subscribe (com.google.common.eventbus.Subscribe)1 CapeItem (com.jab125.thonkutil.api.CapeItem)1 CauldronRecipe (de.siphalor.nbtcrafting.recipe.cauldron.CauldronRecipe)1 TemporaryCauldronInventory (de.siphalor.nbtcrafting.recipe.cauldron.TemporaryCauldronInventory)1 FlyRandomlyGoal (frozenblock.wild.mod.liukrastapi.FlyRandomlyGoal)1 Color (java.awt.Color)1 Iterator (java.util.Iterator)1