Java Code Examples for net.minecraft.block.Block#getBlockFromName()

The following examples show how to use net.minecraft.block.Block#getBlockFromName() . 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: IntegrationAutomagy.java    From Gadomancy with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void doInit() {
    Block infinityJar = Block.getBlockFromName("Automagy:blockCreativeJar");
    if(infinityJar != null) {
        RegisteredBlocks.registerStickyJar(infinityJar, 3, false, true);
        RegisteredItems.registerStickyJar(Item.getItemFromBlock(infinityJar), 3);
    }

    if(ModConfig.enableAdditionalNodeTypes) {
        CommonProxy.unregisterWandHandler("Automagy", ConfigBlocks.blockWarded, -1);
    }

    //Better bookshelves -> MOAR knowledge
    Block betterBookshelf = Block.getBlockFromName("Automagy:blockBookshelfEnchanted");
    if(betterBookshelf != null) {
        TileKnowledgeBook.knowledgeIncreaseMap.put(new TileKnowledgeBook.BlockSnapshot(betterBookshelf, 0), 2);
        TileKnowledgeBook.knowledgeIncreaseMap.put(new TileKnowledgeBook.BlockSnapshot(betterBookshelf, 1), 4);
    }
}
 
Example 2
Source File: BlockOptionHelper.java    From ForgeHax with MIT License 6 votes vote down vote up
public static BlockData fromUniqueName(String uniqueName)
    throws BlockDoesNotExistException, BadBlockEntryFormatException {
  String[] split = uniqueName.split("::");
  if (split.length < 1) {
    throw new BadBlockEntryFormatException();
  }
  String name = split[0];
  int meta = SafeConverter.toInteger(split.length > 1 ? split[1] : -1, -1);
  Block block = Block.getBlockFromName(name);
  if (block == null) {
    throw new BlockDoesNotExistException(uniqueName + " is not a valid block");
  }
  BlockData data = new BlockData();
  data.block = block;
  data.meta = meta;
  return data;
}
 
Example 3
Source File: AgentQuitFromTouchingBlockTypeImplementation.java    From malmo with MIT License 6 votes vote down vote up
@Override
public boolean parseParameters(Object params)
{
	if (params == null || !(params instanceof AgentQuitFromTouchingBlockType))
		return false;
	
	this.params = (AgentQuitFromTouchingBlockType)params;
	// Flatten all the possible block type names for ease of matching later:
	this.blockTypeNames = new ArrayList<String>();
	for (BlockSpec bs : this.params.getBlock())
	{
		for (BlockType bt : bs.getType())
		{
			Block b = Block.getBlockFromName(bt.value());
			this.blockTypeNames.add(b.getUnlocalizedName().toLowerCase());
		}
	}
	return true;
}
 
Example 4
Source File: CustomBlockInfoJson.java    From ExNihiloAdscensio with MIT License 6 votes vote down vote up
@Override
public BlockInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
    JsonHelper helper = new JsonHelper(json);
    
    String name = helper.getString("name");
    int meta = helper.getNullableInteger("meta", 0);

    Block block = Block.getBlockFromName(name);
    
    if(block == null)
    {
        LogUtil.error("Error parsing JSON: Invalid Block: " + json.toString());
        LogUtil.error("This may result in crashing or other undefined behavior");
    }
    
    return new BlockInfo(block, meta);
}
 
Example 5
Source File: RewardForTouchingBlockTypeImplementation.java    From malmo with MIT License 5 votes vote down vote up
BlockMatcher(BlockSpecWithRewardAndBehaviour spec) {
    this.spec = spec;

    // Get the allowed blocks:
    // (Convert from the enum name to the unlocalised name.)
    this.allowedBlockNames = new ArrayList<String>();
    List<BlockType> allowedTypes = spec.getType();
    if (allowedTypes != null) {
        for (BlockType bt : allowedTypes) {
            Block b = Block.getBlockFromName(bt.value());
            this.allowedBlockNames.add(b.getUnlocalizedName());
        }
    }
}
 
Example 6
Source File: ItemEnderBag.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void addTooltipLines(ItemStack stack, EntityPlayer player, List<String> list, boolean verbose)
{
    TargetData target = TargetData.getTargetFromSelectedModule(stack, ModuleType.TYPE_LINKCRYSTAL);

    if (target != null)
    {
        if ("minecraft:ender_chest".equals(target.blockName))
        {
            ItemStack targetStack = new ItemStack(Block.getBlockFromName(target.blockName), 1, target.blockMeta & 0xF);
            String targetName = (targetStack.isEmpty() == false ? targetStack.getDisplayName() : "");

            String textPre = TextFormatting.DARK_GREEN.toString();
            String rst = TextFormatting.RESET.toString() + TextFormatting.GRAY.toString();
            list.add(I18n.format("enderutilities.tooltip.item.target") + ": " + textPre + targetName + rst);

            // Ender Capacitor charge, if one has been installed
            ItemStack capacitorStack = this.getSelectedModuleStack(stack, ModuleType.TYPE_ENDERCAPACITOR);

            if (capacitorStack.isEmpty() == false && capacitorStack.getItem() instanceof ItemEnderCapacitor)
            {
                ((ItemEnderCapacitor) capacitorStack.getItem()).addTooltipLines(capacitorStack, player, list, verbose);
            }

            return;
        }
    }

    super.addTooltipLines(stack, player, list, verbose);
}
 
Example 7
Source File: ModValidator.java    From AgriCraft with MIT License 5 votes vote down vote up
@Override
public boolean isValidBlock(String block) {
    String[] parts = block.split(":");
    if (parts.length < 2) {
        return false;
    } else if (OreDictUtil.isValidOre(block)) {
        return true;
    } else {
        Block b = Block.getBlockFromName(parts[0] + ":" + parts[1]);
        //AgriCore.getLogger("agricraft").debug(b);
        return b != null;
    }
}
 
Example 8
Source File: BaseMetals.java    From BaseMetals with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Parses a String in the format (stack-size)*(modid):(item/block name)#(metadata value). The 
 * stacksize and metadata value parameters are optional.
 * @param str A String describing an itemstack (e.g. "4*minecraft:dye#15" or "minecraft:bow")
 * @param allowWildcard If true, then item strings that do not specify a metadata value will use 
 * the OreDictionary wildcard value. If false, then the default meta value is 0 instead.
 * @return An ItemStack representing the item, or null if the item is not found
 */
public static ItemStack parseStringAsItemStack(String str, boolean allowWildcard){
	str = str.trim();
	int count = 1;
	int meta;
	if(allowWildcard){
		meta = OreDictionary.WILDCARD_VALUE;
	} else {
		meta = 0;
	}
	int nameStart = 0;
	int nameEnd = str.length();
	if(str.contains("*")){
		count = Integer.parseInt(str.substring(0,str.indexOf("*")).trim());
		nameStart = str.indexOf("*")+1;
	}
	if(str.contains("#")){
		meta = Integer.parseInt(str.substring(str.indexOf("#")+1,str.length()).trim());
		nameEnd = str.indexOf("#");
	}
	String id = str.substring(nameStart,nameEnd).trim();
	if(Block.getBlockFromName(id) != null){
		// is a block
		return new ItemStack(Block.getBlockFromName(id),count,meta);
	} else if(Item.getByNameOrId(id) != null){
		// is an item
		return new ItemStack(Item.getByNameOrId(id),count,meta);
	} else {
		// item not found
		FMLLog.severe("Failed to find item or block for ID '"+id+"'");
		return null;
	}
}
 
Example 9
Source File: TileEntityQuantumComputer.java    From qcraft-mod with Apache License 2.0 5 votes vote down vote up
public static AreaData decode( NBTTagCompound nbttagcompound )
{
    AreaData storedData = new AreaData();
    storedData.m_shape = new AreaShape();
    storedData.m_shape.m_xMin = nbttagcompound.getInteger( "xmin" );
    storedData.m_shape.m_xMax = nbttagcompound.getInteger( "xmax" );
    storedData.m_shape.m_yMin = nbttagcompound.getInteger( "ymin" );
    storedData.m_shape.m_yMax = nbttagcompound.getInteger( "ymax" );
    storedData.m_shape.m_zMin = nbttagcompound.getInteger( "zmin" );
    storedData.m_shape.m_zMax = nbttagcompound.getInteger( "zmax" );

    int size =
        ( storedData.m_shape.m_xMax - storedData.m_shape.m_xMin + 1 ) *
        ( storedData.m_shape.m_yMax - storedData.m_shape.m_yMin + 1 ) *
        ( storedData.m_shape.m_zMax - storedData.m_shape.m_zMin + 1 );
    storedData.m_blocks = new Block[ size ];
    if( nbttagcompound.hasKey( "blockData" ) )
    {
        int[] blockIDs = nbttagcompound.getIntArray( "blockData" );
        for( int i=0; i<size; ++i )
        {
            storedData.m_blocks[i] = Block.getBlockById( blockIDs[i] );
        }
    }
    else
    {
        NBTTagList blockNames = nbttagcompound.getTagList( "blockNames", Constants.NBT.TAG_STRING );
        for( int i=0; i<size; ++i )
        {
            String name = blockNames.getStringTagAt( i );
            if( name.length() > 0 && !name.equals( "null" ) )
            {
                storedData.m_blocks[i] = Block.getBlockFromName( name );
            }
        }
    }
    storedData.m_metaData = nbttagcompound.getIntArray( "metaData" );
    return storedData;
}
 
Example 10
Source File: IntegrationThaumicExploration.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void doInit() {
    Block trashJar = Block.getBlockFromName("ThaumicExploration:trashJar");
    if(trashJar != null) {
        RegisteredBlocks.registerStickyJar(trashJar, 0, false, true);
        RegisteredItems.registerStickyJar(Item.getItemFromBlock(trashJar), 0, new ItemStack(trashJar), "TRASHJAR");
    }
}
 
Example 11
Source File: IntegrationThaumicHorizions.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void doInit() {
    if(Gadomancy.proxy.getSide() == Side.CLIENT) {
        RendererLivingEntity render = ClientProxy.unregisterRenderer(EntityGolemTH.class, RenderGolemTH.class);
        if(render != null) {
            RenderingRegistry.registerEntityRenderingHandler(EntityGolemTH.class, new RenderAdditionalGolemTH(render.mainModel));
        }

        modMatrix = Block.getBlockFromName("ThaumicHorizons:modMatrix");

        RegisteredBlocks.registerClawClickBehavior(new ClickBehavior(true) {
            private TileVat vat;

            @Override
            public boolean isValidForBlock() {
                if (block == modMatrix && metadata == 0) {
                    this.vat = ((TileVatMatrix) world.getTileEntity(x, y, z)).getVat();
                    return vat != null;
                }
                return false;
            }

            @Override
            public int getComparatorOutput() {
                return (vat.mode != 0 && vat.mode != 4) ? 15 : 0;
            }

            @Override
            public void addInstability(int instability) {
                vat.instability += Math.ceil(instability * 0.5);
            }
        });
    }

    MinecraftForge.EVENT_BUS.register(this);
}
 
Example 12
Source File: XRayConfig.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Load config from file
 *
 * @throws IOException
 */
@Override
protected void loadConfig() throws IOException {
    final XRay xRay = (XRay) LiquidBounce.moduleManager.getModule(XRay.class);

    if(xRay == null) {
        ClientUtils.getLogger().error("[FileManager] Failed to find xray module.");
        return;
    }

    final JsonArray jsonArray = new JsonParser().parse(new BufferedReader(new FileReader(getFile()))).getAsJsonArray();

    xRay.getXrayBlocks().clear();

    for(final JsonElement jsonElement : jsonArray) {
        try {
            final Block block = Block.getBlockFromName(jsonElement.getAsString());

            if (xRay.getXrayBlocks().contains(block)) {
                ClientUtils.getLogger().error("[FileManager] Skipped xray block '" + block.getRegistryName() + "' because the block is already added.");
                continue;
            }

            xRay.getXrayBlocks().add(block);
        }catch(final Throwable throwable) {
            ClientUtils.getLogger().error("[FileManager] Failed to add block to xray.", throwable);
        }
    }
}
 
Example 13
Source File: AgentQuitFromTouchingBlockTypeImplementation.java    From malmo with MIT License 5 votes vote down vote up
private boolean findNameMatch(BlockSpec blockspec, String blockName)
{
	for (BlockType bt : blockspec.getType())
	{
		Block b = Block.getBlockFromName(bt.value());
		if (b.getUnlocalizedName().equalsIgnoreCase(blockName))
			return true;
	}
	return false;
}
 
Example 14
Source File: EditBlockListScreen.java    From ForgeWurst with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void drawSlot(int slotIdx, int entryRight, int slotTop,
	int slotBuffer, Tessellator tess)
{
	String name = list.get(slotIdx);
	
	ItemStack stack = new ItemStack(Block.getBlockFromName(name));
	FontRenderer fr = WMinecraft.getFontRenderer();
	
	String displayName = renderIconAndGetName(stack, slotTop);
	fr.drawString(displayName + " (" + name + ")", 68, slotTop + 2,
		0xf0f0f0);
}
 
Example 15
Source File: EditBlockListScreen.java    From ForgeWurst with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateScreen()
{
	blockNameField.updateCursorCounter();
	
	blockToAdd = Block.getBlockFromName(blockNameField.getText());
	addButton.enabled = blockToAdd != null;
	
	removeButton.enabled =
		listGui.selected >= 0 && listGui.selected < listGui.list.size();
}
 
Example 16
Source File: TargetData.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
public String getTargetBlockDisplayName()
{
    Block block = Block.getBlockFromName(this.blockName);
    ItemStack targetStack = new ItemStack(block, 1, this.itemMeta);

    if (targetStack.isEmpty() == false)
    {
        return targetStack.getDisplayName();
    }

    return null;
}
 
Example 17
Source File: BlockEntry.java    From ForgeHax with MIT License 4 votes vote down vote up
public BlockEntry(String name, int meta) throws BlockDoesNotExistException {
  this(Block.getBlockFromName(name), meta, !BlockOptionHelper.isAir(name));
}
 
Example 18
Source File: MetaRotations.java    From archimedes-ships with MIT License 4 votes vote down vote up
public boolean parseMetaRotations(BufferedReader reader) throws IOException, OutdatedMrotException
{
	boolean hasversionno = false;
	int lineno = 0;
	String line;
	String[] as;
	while ((line = reader.readLine()) != null)
	{
		lineno++;
		if (line.startsWith("#") || line.length() == 0)
		{
			continue;
		} else if (line.startsWith("version="))
		{
			hasversionno = true;
			as = line.split("=");
			if (as.length != 2)
			{
				mrotError("Version number is invalid", lineno);
				throw new OutdatedMrotException("?");
			}
			String modversion = ArchimedesShipMod.MOD_VERSION;
			String version = as[1].trim();
			if (!version.equals(modversion))
			{
				throw new OutdatedMrotException(version);
			}
			continue;
		}
		
		Block[] blocks;
		int mask = 0xFFFFFFFF;
		int[] rot = new int[4];
		
		as = line.split(";");
		if (as.length < 3)
		{
			mrotError("Not enough parameters", lineno);
			continue;
		}
		
		String[] blocksstr = as[0].split(",");
		blocks = new Block[blocksstr.length];
		for (int i = 0; i < blocksstr.length; i++)
		{
			String name = blocksstr[i].trim();
			blocks[i] = Block.getBlockFromName(name);
			if (blocks[i] == null)
			{
				mrotError("No block exists for " + name, lineno);
			}
		}
		
		try
		{
			mask = Integer.decode(as[1].trim()).intValue();
			String[] srot = as[2].split(",");
			for (int i = 0; i < rot.length; i++)
			{
				rot[i] = Integer.parseInt(srot[i].trim());
			}
		} catch (NumberFormatException e)
		{
			mrotError(e.getLocalizedMessage(), lineno);
		}
		
		for (Block b : blocks)
		{
			addMetaRotation(b, mask, rot);
		}
	}
	return hasversionno;
}
 
Example 19
Source File: WrapperBlock.java    From ClientBase with MIT License 4 votes vote down vote up
public static WrapperBlock getBlockFromName(String var0) {
    return new WrapperBlock(Block.getBlockFromName(var0));
}
 
Example 20
Source File: GTMaterialGen.java    From GT-Classic with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * A getter for retrieving modded blocks.
 * 
 * @param modname - String, the mod name
 * @param blockid - String, the block by name
 * @return ItemStack - the ItemStack requested
 */
public static ItemStack getModBlock(String modname, String blockid) {
	String pair = modname + ":" + blockid;
	return new ItemStack(Block.getBlockFromName(pair));
}