net.minecraft.item.ItemMonsterPlacer Java Examples
The following examples show how to use
net.minecraft.item.ItemMonsterPlacer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DispenserBehaviorMobEgg.java From Artifacts with MIT License | 6 votes |
/** * Dispense the specified stack, play the dispense sound and spawn particles. */ public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack) { EnumFacing enumfacing = BlockDispenser.func_149937_b/*getFacing*/(par1IBlockSource.getBlockMetadata()); double d0 = par1IBlockSource.getX() + (double)enumfacing.getFrontOffsetX(); double d1 = (double)((float)par1IBlockSource.getYInt() + 0.2F) + enumfacing.getFrontOffsetY(); double d2 = par1IBlockSource.getZ() + (double)enumfacing.getFrontOffsetZ(); Entity entity = ItemMonsterPlacer.spawnCreature(par1IBlockSource.getWorld(), par2ItemStack.getItemDamage(), d0, d1, d2); if (entity instanceof EntityLiving && par2ItemStack.hasDisplayName()) { ((EntityLiving)entity).setCustomNameTag(par2ItemStack.getDisplayName()); } par2ItemStack.splitStack(1); return par2ItemStack; }
Example #2
Source File: MinecraftTypeHelper.java From malmo with MIT License | 4 votes |
/** Attempt to break the item on this itemstack into a type/variant/colour which we can use for communication with the Malmo platform. * @param is the ItemStack containing the item we are attempting to deconstruct. * @return an XML DrawItem object containing the item's type, variant, colour etc. */ public static DrawItem getDrawItemFromItemStack(ItemStack is) { if (is == null) return null; DrawItem di = new DrawItem(); String name = is.getUnlocalizedName(); // Get unlocalised name from the stack, not the stack's item - this ensures we keep the metadata. if (is.getHasSubtypes()) { // If the item has subtypes, then there are varieties - eg different colours, types, etc. // Attempt to map from these subtypes back to variant/colour. // Do this by decomposing the unlocalised name: List<String> itemParts = new ArrayList<String>(Arrays.asList(name.split("\\."))); if (is.getItem() instanceof ItemMonsterPlacer) { // Special case for eggs: itemParts.add(ItemMonsterPlacer.getNamedIdFrom(is).toString()); } // First part will be "tile" or "item". // Second part will be the item itself (eg "dyePowder" or "stainedGlass" etc). // Third part will be the variant, colour etc. Colour col = null; Variation var = null; for (int part = 2; part < itemParts.size(); part++) { String section = itemParts.get(part); // First see if this matches a colour: if (col == null) { col = attemptToGetAsColour(section); if (col == null && var == null) // If it wasn't a colour, check to see if it was a variant: var = attemptToGetAsVariant(section, is); } else if (var == null) var = attemptToGetAsVariant(section, is); } di.setColour(col); di.setVariant(var); } // Use the item registry name for the item - this is what we use in Types.XSD Object obj = Item.REGISTRY.getNameForObject(is.getItem()); String publicName; if (obj instanceof ResourceLocation) publicName = ((ResourceLocation)obj).getResourcePath(); else publicName = obj.toString(); di.setType(publicName); return di; }
Example #3
Source File: CreativeTabCommunity.java From CommunityMod with GNU Lesser General Public License v2.1 | 3 votes |
@Override @SideOnly(Side.CLIENT) public void displayAllRelevantItems(NonNullList<ItemStack> itemList) { super.displayAllRelevantItems(itemList); if (entityCache == null) { entityCache = new ArrayList<>(); for (EntityEntry entityEntry : ForgeRegistries.ENTITIES.getValuesCollection()) { if (entityEntry.getRegistryName().getNamespace().equalsIgnoreCase(CommunityGlobals.MOD_ID)) { entityCache.add(entityEntry.getRegistryName()); } } } for (final ResourceLocation id : entityCache) { final ItemStack spawner = new ItemStack(Items.SPAWN_EGG); ItemMonsterPlacer.applyEntityIdToItemStack(spawner, id); itemList.add(spawner); } }