Java Code Examples for net.minecraft.item.Item.getHasSubtypes()

The following are Jave code examples for showing how to use getHasSubtypes() of the net.minecraft.item.Item class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: customstuff4   File: ItemHelper.java   View Source Code Vote up 6 votes
public static NonNullList<ItemStack> createSubItems(Item item, CreativeTabs creativeTab, Attribute<String> tabLabels, int[] subtypes)
{
    NonNullList<ItemStack> list = NonNullList.create();

    if (item.getHasSubtypes())
    {
        for (int meta : subtypes)
        {
            tabLabels.get(meta)
                     .ifPresent(tabLabel ->
                                {
                                    if (creativeTab == null || creativeTab == CreativeTabs.SEARCH || Objects.equals(tabLabel, getTabLabel(creativeTab)))
                                    {
                                        list.add(new ItemStack(item, 1, meta));
                                    }
                                });
        }
    } else
    {
        list.add(new ItemStack(item, 1, 0));
    }

    return list;
}
 
Example 2
Project: CustomWorldGen   File: EntityEnderman.java   View Source Code Vote up 6 votes
/**
 * Drop the equipment for this entity.
 */
protected void dropEquipment(boolean wasRecentlyHit, int lootingModifier)
{
    super.dropEquipment(wasRecentlyHit, lootingModifier);
    IBlockState iblockstate = this.getHeldBlockState();

    if (iblockstate != null)
    {
        Item item = Item.getItemFromBlock(iblockstate.getBlock());

        if (item != null)
        {
            int i = item.getHasSubtypes() ? iblockstate.getBlock().getMetaFromState(iblockstate) : 0;
            this.entityDropItem(new ItemStack(item, 1, i), 0.0F);
        }
    }
}
 
Example 3
Project: CustomWorldGen   File: Block.java   View Source Code Vote up 6 votes
@Nullable
protected ItemStack createStackedBlock(IBlockState state)
{
    Item item = Item.getItemFromBlock(this);

    if (item == null)
    {
        return null;
    }
    else
    {
        int i = 0;

        if (item.getHasSubtypes())
        {
            i = this.getMetaFromState(state);
        }

        return new ItemStack(item, 1, i);
    }
}
 
Example 4
Project: FoodCraft-Reloaded   File: ItemLoader.java   View Source Code Vote up 6 votes
@Load(side = Side.CLIENT)
public void registerRenders() {
    for (Field field : FCRItems.class.getFields()) {
        field.setAccessible(true);
        RegItem anno = field.getAnnotation(RegItem.class);
        try {
            if (anno == null)
                continue;

            Item item = (Item) field.get(null);
            if (item.getHasSubtypes()) {
                if (item instanceof IMetadatable) {
                    for (int i = 0; i < ((IMetadatable) item).getMaxMetadata(); i++)
                        registerRender(item, i);
                }
            } else {
                registerRender(item, 0);
            }
        } catch (Exception e) {
            FoodCraftReloaded.getLogger().warn("Un-able to register item " + field.toGenericString(), e);
        }
    }
}
 
Example 5
Project: ModularMachinery   File: ItemUtils.java   View Source Code Vote up 6 votes
public static boolean stackEqualsNonNBT(@Nonnull ItemStack stack, @Nonnull  ItemStack other) {
    if (stack.isEmpty() && other.isEmpty())
        return true;
    if (stack.isEmpty() || other.isEmpty())
        return false;
    Item sItem = stack.getItem();
    Item oItem = other.getItem();
    if (sItem.getHasSubtypes() || oItem.getHasSubtypes()) {
        return sItem.equals(other.getItem()) &&
                (stack.getItemDamage() == other.getItemDamage() ||
                        stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ||
                        other.getItemDamage() == OreDictionary.WILDCARD_VALUE);
    } else {
        return sItem.equals(other.getItem());
    }
}
 
Example 6
Project: DecompiledMinecraft   File: Block.java   View Source Code Vote up 5 votes
protected ItemStack createStackedBlock(IBlockState state)
{
    int i = 0;
    Item item = Item.getItemFromBlock(this);

    if (item != null && item.getHasSubtypes())
    {
        i = this.getMetaFromState(state);
    }

    return new ItemStack(item, 1, i);
}
 
Example 7
Project: DecompiledMinecraft   File: Block.java   View Source Code Vote up 5 votes
protected ItemStack createStackedBlock(IBlockState state)
{
    int i = 0;
    Item item = Item.getItemFromBlock(this);

    if (item != null && item.getHasSubtypes())
    {
        i = this.getMetaFromState(state);
    }

    return new ItemStack(item, 1, i);
}
 
Example 8
Project: BaseClient   File: Block.java   View Source Code Vote up 5 votes
protected ItemStack createStackedBlock(IBlockState state) {
	int i = 0;
	Item item = Item.getItemFromBlock(this);

	if (item != null && item.getHasSubtypes()) {
		i = this.getMetaFromState(state);
	}

	return new ItemStack(item, 1, i);
}
 
Example 9
Project: BaseClient   File: Block.java   View Source Code Vote up 5 votes
protected ItemStack createStackedBlock(IBlockState state)
{
    int i = 0;
    Item item = Item.getItemFromBlock(this);

    if (item != null && item.getHasSubtypes())
    {
        i = this.getMetaFromState(state);
    }

    return new ItemStack(item, 1, i);
}
 
Example 10
Project: customstuff4   File: BlockMixin.java   View Source Code Vote up 5 votes
@Override
protected ItemStack getSilkTouchDrop(IBlockState state)
{
    Item item = Item.getItemFromBlock(this);
    int subtype = 0;

    if (item.getHasSubtypes())
    {
        subtype = getSubtype(state);
    }

    return new ItemStack(item, 1, subtype);
}
 
Example 11
Project: Backmemed   File: EntityEnderman.java   View Source Code Vote up 5 votes
/**
 * Drop the equipment for this entity.
 */
protected void dropEquipment(boolean wasRecentlyHit, int lootingModifier)
{
    super.dropEquipment(wasRecentlyHit, lootingModifier);
    IBlockState iblockstate = this.getHeldBlockState();

    if (iblockstate != null)
    {
        Item item = Item.getItemFromBlock(iblockstate.getBlock());
        int i = item.getHasSubtypes() ? iblockstate.getBlock().getMetaFromState(iblockstate) : 0;
        this.entityDropItem(new ItemStack(item, 1, i), 0.0F);
    }
}
 
Example 12
Project: Backmemed   File: Block.java   View Source Code Vote up 5 votes
protected ItemStack getSilkTouchDrop(IBlockState state)
{
    Item item = Item.getItemFromBlock(this);
    int i = 0;

    if (item.getHasSubtypes())
    {
        i = this.getMetaFromState(state);
    }

    return new ItemStack(item, 1, i);
}
 
Example 13
Project: ModularMachinery   File: CommandHand.java   View Source Code Vote up 5 votes
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    EntityPlayerMP player = getCommandSenderAsPlayer(sender);
    ItemStack held = player.getHeldItemMainhand();
    if(held.isEmpty()) {
        held = player.getHeldItemOffhand();
    }
    if(held.isEmpty()) {
        player.sendMessage(new TextComponentTranslation("command.modularmachinery.hand.empty"));
        return;
    }
    Item i = held.getItem();
    StringBuilder sb = new StringBuilder();
    sb.append(i.getRegistryName().toString());
    if(i.getHasSubtypes()) {
        sb.append("@").append(held.getItemDamage());
    }
    NBTTagCompound cmp = held.serializeNBT();
    if(cmp.hasKey("tag")) {
        String json = NBTJsonSerializer.serializeNBT(cmp.getTag("tag"));
        if(!json.isEmpty()) {
            sb.append(" (with nbt: ").append(json).append(" )");
        }
    }

    String str = sb.toString();
    player.sendMessage(new TextComponentString(str));
    ModularMachinery.NET_CHANNEL.sendTo(new PktCopyToClipboard(str), player);

    int burn = TileEntityFurnace.getItemBurnTime(held);
    if(burn > 0) {
        player.sendMessage(new TextComponentString("Fuel BurnTime: " + burn));
    }
}
 
Example 14
Project: Zombe-Modpack   File: ZWrapper.java   View Source Code Vote up 4 votes
public static boolean hasSubTypes(Item item) {
    return item != null && item.getHasSubtypes();
}
 
Example 15
Project: Backmemed   File: GuiCreateFlatWorld.java   View Source Code Vote up 4 votes
protected void drawSlot(int entryID, int insideLeft, int yPos, int insideSlotHeight, int mouseXIn, int mouseYIn)
{
    FlatLayerInfo flatlayerinfo = (FlatLayerInfo)GuiCreateFlatWorld.this.theFlatGeneratorInfo.getFlatLayers().get(GuiCreateFlatWorld.this.theFlatGeneratorInfo.getFlatLayers().size() - entryID - 1);
    IBlockState iblockstate = flatlayerinfo.getLayerMaterial();
    Block block = iblockstate.getBlock();
    Item item = Item.getItemFromBlock(block);

    if (item == Items.field_190931_a)
    {
        if (block != Blocks.WATER && block != Blocks.FLOWING_WATER)
        {
            if (block == Blocks.LAVA || block == Blocks.FLOWING_LAVA)
            {
                item = Items.LAVA_BUCKET;
            }
        }
        else
        {
            item = Items.WATER_BUCKET;
        }
    }

    ItemStack itemstack = new ItemStack(item, 1, item.getHasSubtypes() ? block.getMetaFromState(iblockstate) : 0);
    String s = item.getItemStackDisplayName(itemstack);
    this.drawItem(insideLeft, yPos, itemstack);
    GuiCreateFlatWorld.this.fontRendererObj.drawString(s, insideLeft + 18 + 5, yPos + 3, 16777215);
    String s1;

    if (entryID == 0)
    {
        s1 = I18n.format("createWorld.customize.flat.layer.top", new Object[] {Integer.valueOf(flatlayerinfo.getLayerCount())});
    }
    else if (entryID == GuiCreateFlatWorld.this.theFlatGeneratorInfo.getFlatLayers().size() - 1)
    {
        s1 = I18n.format("createWorld.customize.flat.layer.bottom", new Object[] {Integer.valueOf(flatlayerinfo.getLayerCount())});
    }
    else
    {
        s1 = I18n.format("createWorld.customize.flat.layer", new Object[] {Integer.valueOf(flatlayerinfo.getLayerCount())});
    }

    GuiCreateFlatWorld.this.fontRendererObj.drawString(s1, insideLeft + 2 + 213 - GuiCreateFlatWorld.this.fontRendererObj.getStringWidth(s1), yPos + 3, 16777215);
}