Class SpawnEggItem

java.lang.Object
net.minecraft.item.Item
net.minecraft.item.SpawnEggItem
All Implemented Interfaces:
ItemConvertible

public class SpawnEggItem
extends Item
  • Field Details

    • SPAWN_EGGS

      private static final Map<EntityType<?>,​SpawnEggItem> SPAWN_EGGS
    • primaryColor

      private final int primaryColor
    • secondaryColor

      private final int secondaryColor
    • type

      private final EntityType<?> type
  • Constructor Details

    • SpawnEggItem

      public SpawnEggItem​(EntityType<?> type, int primaryColor, int secondaryColor, Item.Settings settings)
  • Method Details

    • useOnBlock

      public ActionResult useOnBlock​(ItemUsageContext context)
      Called when an item is used on a block.

      This method is called on both the logical client and logical server, so take caution when using this method. The logical side can be checked using context.getWorld().isClient().

      Overrides:
      useOnBlock in class Item
      Parameters:
      context - the usage context
      Returns:
      an action result that specifies if using the item on a block was successful.
    • use

      public TypedActionResult<ItemStack> use​(World world, PlayerEntity user, Hand hand)
      Called when an item is used by a player. The use action, by default, is bound to the right mouse button.

      This method is called on both the logical client and logical server, so take caution when overriding this method. The logical side can be checked using world.isClient().

      Overrides:
      use in class Item
      Parameters:
      world - the world the item was used in
      user - the player who used the item
      hand - the hand used
      Returns:
      a typed action result that specifies whether using the item was successful. The action result contains the new item stack that the player's hand will be set to.
    • isOfSameEntityType

      public boolean isOfSameEntityType​(@Nullable CompoundTag tag, EntityType<?> type)
    • getColor

      @Environment(CLIENT) public int getColor​(int num)
    • forEntity

      @Environment(CLIENT) @Nullable public static SpawnEggItem forEntity​(@Nullable EntityType<?> type)
    • getAll

      public static Iterable<SpawnEggItem> getAll()
    • getEntityType

      public EntityType<?> getEntityType​(@Nullable CompoundTag tag)
    • spawnBaby

      public Optional<MobEntity> spawnBaby​(PlayerEntity user, MobEntity mobEntity, EntityType<? extends MobEntity> entityType, ServerWorld serverWorld, Vec3d vec3d, ItemStack itemStack)