Java Code Examples for net.minecraft.item.Item#getRegistryName()

The following examples show how to use net.minecraft.item.Item#getRegistryName() . 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: ClientProxy.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void registerAllItemBlockModels(BlockEnderUtilities blockIn, String variantPre, String variantPost)
{
    if (blockIn.isEnabled())
    {
        NonNullList<ItemStack> stacks = NonNullList.create();
        blockIn.getSubBlocks(blockIn.getCreativeTab(), stacks);
        String[] names = blockIn.getUnlocalizedNames();

        for (ItemStack stack : stacks)
        {
            Item item = stack.getItem();
            int meta = stack.getMetadata();
            ModelResourceLocation mrl = new ModelResourceLocation(item.getRegistryName(), variantPre + names[meta] + variantPost);
            ModelLoader.setCustomModelResourceLocation(item, meta, mrl);
        }
    }
}
 
Example 2
Source File: ItemCompound.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ItemCompound(String modid, Item item) {
    this.modid = modid;
    this.item = item;
    registryName = item.getRegistryName();
}
 
Example 3
Source File: ModelBakery.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void registerItemKeyGenerator(Item item, IItemStackKeyGenerator generator) {
    if (itemKeyGeneratorMap.containsKey(item)) {
        throw new IllegalArgumentException("Unable to register IItemStackKeyGenerator as one is already registered for item: " + item.getRegistryName());
    }
    itemKeyGeneratorMap.put(item, generator);
}
 
Example 4
Source File: PlaceCommandsImplementation.java    From malmo with MIT License 4 votes vote down vote up
@Override
protected boolean onExecute(String verb, String parameter, MissionInit missionInit) {
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    if (player == null)
        return false;

    if (!verb.equalsIgnoreCase("place"))
        return false;

    Item item = Item.getByNameOrId(parameter);
    Block block = Block.getBlockFromItem(item);
    if (item == null || item.getRegistryName() == null || block.getRegistryName() == null)
        return false;

    InventoryPlayer inv = player.inventory;
    boolean blockInInventory = false;
    ItemStack stackInInventory = null;
    int stackIndex = -1;
    for (int i = 0; !blockInInventory && i < inv.getSizeInventory(); i++) {
        Item stack = inv.getStackInSlot(i).getItem();
        if (stack.getRegistryName() != null && stack.getRegistryName().equals(item.getRegistryName())) {
            stackInInventory = inv.getStackInSlot(i);
            stackIndex = i;
            blockInInventory = true;
        }
    }

    // We don't have that item in our inventories
    if (!blockInInventory)
        return false;

    RayTraceResult mop = Minecraft.getMinecraft().objectMouseOver;
    if (mop.typeOfHit == RayTraceResult.Type.BLOCK) {
        BlockPos pos = mop.getBlockPos().add(mop.sideHit.getDirectionVec());
        // Can we place this block here?
        AxisAlignedBB axisalignedbb = block.getDefaultState().getCollisionBoundingBox(player.world, pos);
        if (axisalignedbb == null || player.world.checkNoEntityCollision(axisalignedbb.offset(pos), null)) {
            MalmoMod.network.sendToServer(new DiscreteMovementCommandsImplementation.UseActionMessage(mop.getBlockPos(), new ItemStack(block), mop.sideHit, false, mop.hitVec));
            if (stackInInventory.getCount() == 1)
                inv.setInventorySlotContents(stackIndex, new ItemStack(Block.getBlockById(0)));
            else
                stackInInventory.setCount(stackInInventory.getCount() - 1);
        }
    }

    return true;
}
 
Example 5
Source File: ItemStateModel.java    From OpenModsLib with MIT License 4 votes vote down vote up
private Map<State, ResourceLocation> createModelLocations() {
	if (!itemLocation.isPresent()) return ImmutableMap.of();

	final Item item = Item.REGISTRY.getObject(itemLocation.get());

	if (!(item instanceof IStateItem)) return ImmutableMap.of();

	final StateContainer stateContainer = ((IStateItem)item).getStateContainer();

	final ImmutableMap.Builder<State, ResourceLocation> result = ImmutableMap.builder();

	final ResourceLocation base = item.getRegistryName();

	for (State state : stateContainer.getAllStates())
		result.put(state, new ModelResourceLocation(base, state.getVariant()));

	return result.build();
}
 
Example 6
Source File: ModelUtils.java    From OpenModsLib with MIT License 3 votes vote down vote up
public static void registerMetaInsensitiveModel(Item item, String variant) {
	final ModelResourceLocation location = new ModelResourceLocation(item.getRegistryName(), variant);

	ModelBakery.registerItemVariants(item, location);

	ModelLoader.setCustomMeshDefinition(item, stack -> location);
}