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);
}
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;
}
Aggregations