Search in sources :

Example 1 with BounceBugEntity

use of com.toadstoolstudios.sprout.entities.BounceBugEntity in project Sprout by ThatGravyBoat.

the class BounceBugBottleItem method useOnBlock.

@Override
public ActionResult useOnBlock(ItemUsageContext context) {
    var player = context.getPlayer();
    if (player != null) {
        ItemStack stackInHand = player.getStackInHand(context.getHand());
        NbtCompound nbt = stackInHand.getNbt();
        if (!player.isSneaking()) {
            World world = context.getWorld();
            if (!world.isClient) {
                BounceBugEntity bug = new BounceBugEntity(SproutEntities.BOUNCE_BUG_ENTITY.get(), world);
                if (nbt != null)
                    bug.readNbt(nbt.getCompound("bug"));
                stackInHand.decrement(1);
                player.getInventory().offerOrDrop(Items.GLASS_BOTTLE.getDefaultStack());
                BlockPos blockPos = context.getBlockPos().offset(context.getSide());
                bug.setPos(blockPos.getX() + 0.5, blockPos.getY() + 0.1, blockPos.getZ() + 0.5);
                bug.setVelocity(0, 0.1, 0);
                bug.setOwner(player);
                world.spawnEntity(bug);
            }
            return ActionResult.success(world.isClient());
        }
    }
    return super.useOnBlock(context);
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) BounceBugEntity(com.toadstoolstudios.sprout.entities.BounceBugEntity)

Example 2 with BounceBugEntity

use of com.toadstoolstudios.sprout.entities.BounceBugEntity in project Sprout by ThatGravyBoat.

the class BounceBugBottleBlockEntity method getOrCreateEntity.

public Entity getOrCreateEntity(World world) {
    if (renderEntity == null) {
        renderEntity = new BounceBugEntity(SproutEntities.BOUNCE_BUG_ENTITY.get(), world, true);
        if (entity != null)
            renderEntity.readNbt(entity);
        renderEntity.setPos(0, 0, 0);
        renderEntity.setBodyYaw(0);
        renderEntity.setPitch(0);
    }
    return renderEntity;
}
Also used : BounceBugEntity(com.toadstoolstudios.sprout.entities.BounceBugEntity)

Aggregations

BounceBugEntity (com.toadstoolstudios.sprout.entities.BounceBugEntity)2 ItemStack (net.minecraft.item.ItemStack)1 NbtCompound (net.minecraft.nbt.NbtCompound)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1