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