Search in sources :

Example 1 with GlowMetaSpawn

use of net.glowstone.inventory.GlowMetaSpawn in project Glowstone by GlowstoneMC.

the class ItemSpawn method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc) {
    Location location = against.getLocation().add(face.getModX(), face.getModY(), face.getModZ());
    // TODO: change mob spawner when clicked by monster egg
    if (holding.hasItemMeta() && holding.getItemMeta() instanceof GlowMetaSpawn) {
        GlowMetaSpawn meta = (GlowMetaSpawn) holding.getItemMeta();
        EntityType type = meta.getSpawnedType();
        CompoundTag tag = meta.getEntityTag();
        if (type != null) {
            GlowEntity entity = against.getWorld().spawn(location.add(0.5, 0, 0.5), EntityRegistry.getEntity(type), SpawnReason.SPAWNER_EGG);
            if (tag != null) {
                EntityStorage.load(entity, tag);
            }
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) GlowEntity(net.glowstone.entity.GlowEntity) GlowMetaSpawn(net.glowstone.inventory.GlowMetaSpawn) CompoundTag(net.glowstone.util.nbt.CompoundTag) Location(org.bukkit.Location)

Example 2 with GlowMetaSpawn

use of net.glowstone.inventory.GlowMetaSpawn in project Glowstone by GlowstoneMC.

the class GlowAgeable method entityInteract.

@Override
public boolean entityInteract(GlowPlayer player, InteractEntityMessage message) {
    if (!super.entityInteract(player, message) && message.getAction() == InteractEntityMessage.Action.INTERACT.ordinal()) {
        ItemStack item = InventoryUtil.itemOrEmpty(player.getInventory().getItem(message.getHandSlot()));
        int growthAmount = computeGrowthAmount(item.getType());
        // TODO: 1.13 spawn eggs
        if (item.getType() == Material.LEGACY_MONSTER_EGG && item.hasItemMeta()) {
            GlowMetaSpawn meta = (GlowMetaSpawn) item.getItemMeta();
            if (meta.hasSpawnedType() && meta.getSpawnedType() == this.getType()) {
                this.createBaby();
                if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) {
                    player.getInventory().consumeItemInHand(message.getHandSlot());
                }
                return true;
            }
        } else if (growthAmount > 0) {
            grow(growthAmount);
            world.spawnParticle(Particle.VILLAGER_HAPPY, location, 5);
            if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) {
                player.getInventory().consumeItemInHand(message.getHandSlot());
            }
            return true;
        }
    }
    return false;
}
Also used : GlowMetaSpawn(net.glowstone.inventory.GlowMetaSpawn) ItemStack(org.bukkit.inventory.ItemStack)

Example 3 with GlowMetaSpawn

use of net.glowstone.inventory.GlowMetaSpawn in project Glowstone by GlowstoneMC.

the class ItemSpawn method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc, EquipmentSlot hand) {
    Location location = against.getLocation().add(face.getModX(), face.getModY(), face.getModZ());
    // TODO: change mob spawner when clicked by monster egg
    if (holding.hasItemMeta() && holding.getItemMeta() instanceof GlowMetaSpawn) {
        GlowMetaSpawn meta = (GlowMetaSpawn) holding.getItemMeta();
        EntityType type = meta.getSpawnedType();
        CompoundTag tag = meta.getEntityTag();
        if (type != null) {
            GlowEntity entity = against.getWorld().spawn(location.add(0.5, 0, 0.5), EntityRegistry.getEntity(type), SpawnReason.SPAWNER_EGG);
            if (tag != null) {
                EntityStorage.load(entity, tag);
            }
            if (player.getGameMode() != GameMode.CREATIVE) {
                holding.setAmount(holding.getAmount() - 1);
            }
        }
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) GlowEntity(net.glowstone.entity.GlowEntity) GlowMetaSpawn(net.glowstone.inventory.GlowMetaSpawn) CompoundTag(net.glowstone.util.nbt.CompoundTag) Location(org.bukkit.Location)

Aggregations

GlowMetaSpawn (net.glowstone.inventory.GlowMetaSpawn)3 GlowEntity (net.glowstone.entity.GlowEntity)2 CompoundTag (net.glowstone.util.nbt.CompoundTag)2 Location (org.bukkit.Location)2 EntityType (org.bukkit.entity.EntityType)2 ItemStack (org.bukkit.inventory.ItemStack)1