net.minecraft.util.ResourceLocation#toString ( )源码实例Demo

下面列出了net.minecraft.util.ResourceLocation#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: litematica   文件: BlockInfo.java
public BlockInfo(IBlockState state, String titleKey)
{
    String pre = GuiBase.TXT_WHITE + GuiBase.TXT_BOLD;
    this.title = pre + StringUtils.translate(titleKey) + GuiBase.TXT_RST;
    this.state = state;
    this.stack = ItemUtils.getItemForState(this.state);

    ResourceLocation rl = Block.REGISTRY.getNameForObject(this.state.getBlock());
    this.blockRegistryname = rl != null ? rl.toString() : "<null>";

    this.stackName = this.stack.getDisplayName();

    int w = StringUtils.getStringWidth(this.stackName) + 20;
    w = Math.max(w, StringUtils.getStringWidth(this.blockRegistryname));
    w = Math.max(w, StringUtils.getStringWidth(this.title));
    this.columnWidth = w;

    this.props = BlockUtils.getFormattedBlockStateProperties(this.state, " = ");
    this.totalWidth = this.columnWidth + 40;
    this.totalHeight = this.props.size() * (StringUtils.getFontHeight() + 2) + 50;
}
 
源代码2 项目: litematica   文件: ToolHud.java
protected String getBlockStateString(IBlockState state)
{
    ResourceLocation id = Block.REGISTRY.getNameForObject(state.getBlock());
    String regName = id != null ? id.toString() : "<null>";

    String green = GuiBase.TXT_GREEN;
    String rst = GuiBase.TXT_RST;

    String strBlock = String.format("%s%s (%s)%s", green, regName, state.getBlock().getLocalizedName(), rst);
    EnumFacing facing = BlockUtils.getFirstPropertyFacingValue(state);

    if (facing != null)
    {
        String gold = GuiBase.TXT_GOLD;
        String strFacing = gold + facing.getName().toLowerCase() + rst;
        strBlock += " - " + StringUtils.translate("litematica.tool_hud.facing", strFacing);
    }

    return strBlock;
}
 
private void sendSetBlockCommand(int x, int y, int z, IBlockState state, EntityPlayerSP player)
{
    Block block = state.getBlock();
    ResourceLocation rl = Block.REGISTRY.getNameForObject(block);

    if (rl == null)
    {
        return;
    }

    String blockName = rl.toString();
    String cmdName = Configs.Generic.PASTE_COMMAND_SETBLOCK.getStringValue();
    String strCommand = String.format("/%s %d %d %d %s %d", cmdName, x, y, z, blockName, block.getMetaFromState(state));

    player.sendChatMessage(strCommand);
    ++this.sentCommandsTotal;
}
 
源代码4 项目: VanillaFix   文件: BuiltinLoader.java
@Override
public IModel loadModel(ResourceLocation modelLocation) throws Exception {
    String path = modelLocation.getPath();

    if ("builtin/generated".equals(path) || "block/builtin/generated".equals(path) || "item/builtin/generated".equals(path)) { // TODO: why is this necessary?
        return ItemLayerModel.INSTANCE; //new VanillaModelWrapper(modelLocation, MODEL_GENERATED);
    }

    if ("builtin/entity".equals(path)) {
        return new VanillaModelWrapper(modelLocation, MODEL_ENTITY);
    }

    if ("builtin/missing".equals(path)) {
        return WRAPPED_MODEL_MISSING;
    }

    throw new FileNotFoundException(modelLocation.toString());
}
 
源代码5 项目: VanillaFix   文件: VanillaLoader.java
@Override
public IModel loadModel(ResourceLocation modelLocation) throws Exception {
    // Load vanilla model
    ModelBlock vanillaModel;
    ResourceLocation vanillaModelLocation = new ResourceLocation(modelLocation.getNamespace(), modelLocation.getPath() + ".json");
    try (IResource resource = Minecraft.getMinecraft().getResourceManager().getResource(vanillaModelLocation);
         Reader reader = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8)) {
        vanillaModel = ModelBlock.deserialize(reader);
        vanillaModel.name = modelLocation.toString();
    }

    // Load armature animation (currently disabled for efficiency, see MixinModelBlockAnimation)
    String modelPath = modelLocation.getPath();
    if (modelPath.startsWith("models/")) {
        modelPath = modelPath.substring("models/".length());
    }
    ResourceLocation armatureLocation = new ResourceLocation(modelLocation.getNamespace(), "armatures/" + modelPath + ".json");
    ModelBlockAnimation animation = ModelBlockAnimation.loadVanillaAnimation(Minecraft.getMinecraft().getResourceManager(), armatureLocation);

    // Return the vanilla model weapped in a VanillaModelWrapper
    return new VanillaModelWrapper(modelLocation, vanillaModel , false, animation);
}
 
源代码6 项目: GregTech   文件: ResourcePackHook.java
@Override
public InputStream getInputStream(ResourceLocation location) throws IOException {
    for (IResourcePackFileHook hook : hooks) {
        if (hook.resourceExists(location))
            return hook.getInputStream(location);
    }
    throw new FileNotFoundException(location.toString());
}
 
源代码7 项目: GregTech   文件: AbstractBlockModelFactory.java
@Override
public InputStream getInputStream(ResourceLocation location) throws IOException {
    String resourcePath = location.getResourcePath(); // blockstates/compressed_1.json
    resourcePath = resourcePath.substring(0, resourcePath.length() - 5); //remove .json
    resourcePath = resourcePath.substring(12); //remove blockstates/
    if (resourcePath.startsWith(blockNamePrefix)) {
        Block block = Block.REGISTRY.getObject(new ResourceLocation(location.getResourceDomain(), resourcePath));
        if (block != null && block != Blocks.AIR) {
            return FileUtility.writeInputStream(fillSample(block, blockStateSample));
        }
        throw new IllegalArgumentException("Block not found: " + resourcePath);
    }
    throw new FileNotFoundException(location.toString());
}
 
private void summonEntities(IntBoundingBox box, WorldSchematic worldSchematic, EntityPlayerSP player)
{
    AxisAlignedBB bb = new AxisAlignedBB(box.minX, box.minY, box.minZ, box.maxX + 1, box.maxY + 1, box.maxZ + 1);
    List<Entity> entities = worldSchematic.getEntitiesWithinAABBExcludingEntity(null, bb);

    for (Entity entity : entities)
    {
        ResourceLocation rl = EntityList.getKey(entity);

        if (rl != null)
        {
            String entityName = rl.toString();
            /*
            NBTTagCompound nbt = new NBTTagCompound();
            entity.writeToNBTOptional(nbt);
            String nbtString = nbt.toString();
            */

            String strCommand = String.format(Locale.ROOT, "/summon %s %f %f %f", entityName, entity.posX, entity.posY, entity.posZ);
            /*
            String strCommand = String.format("/summon %s %f %f %f %s", entityName, entity.posX, entity.posY, entity.posZ, nbtString);
            System.out.printf("entity: %s\n", entity);
            System.out.printf("%s\n", strCommand);
            System.out.printf("nbt: %s\n", nbtString);
            */

            player.sendChatMessage(strCommand);
        }
    }
}
 
public BlockMismatchInfo(IBlockState stateExpected, IBlockState stateFound)
{
    this.stateExpected = stateExpected;
    this.stateFound = stateFound;

    this.stackExpected = ItemUtils.getItemForState(this.stateExpected);
    this.stackFound = ItemUtils.getItemForState(this.stateFound);

    Block blockExpected = this.stateExpected.getBlock();
    Block blockFound = this.stateFound.getBlock();
    ResourceLocation rl1 = Block.REGISTRY.getNameForObject(blockExpected);
    ResourceLocation rl2 = Block.REGISTRY.getNameForObject(blockFound);

    this.blockRegistrynameExpected = rl1 != null ? rl1.toString() : "<null>";
    this.blockRegistrynameFound = rl2 != null ? rl2.toString() : "<null>";

    this.nameExpected = getDisplayName(stateExpected, this.stackExpected);
    this.nameFound =    getDisplayName(stateFound,    this.stackFound);

    List<String> propsExpected = BlockUtils.getFormattedBlockStateProperties(this.stateExpected, " = ");
    List<String> propsFound = BlockUtils.getFormattedBlockStateProperties(this.stateFound, " = ");

    int w1 = Math.max(StringUtils.getStringWidth(this.nameExpected) + 20, StringUtils.getStringWidth(this.blockRegistrynameExpected));
    int w2 = Math.max(StringUtils.getStringWidth(this.nameFound) + 20, StringUtils.getStringWidth(this.blockRegistrynameFound));
    w1 = Math.max(w1, fi.dy.masa.litematica.render.RenderUtils.getMaxStringRenderLength(propsExpected));
    w2 = Math.max(w2, fi.dy.masa.litematica.render.RenderUtils.getMaxStringRenderLength(propsFound));

    this.columnWidthExpected = w1;
    this.totalWidth = this.columnWidthExpected + w2 + 40;
    this.totalHeight = Math.max(propsExpected.size(), propsFound.size()) * (StringUtils.getFontHeight() + 2) + 50;
}
 
源代码10 项目: CodeChickenLib   文件: CustomGradient.java
public CustomGradient(ResourceLocation textureFile) {
    BufferedImage img = TextureUtils.loadBufferedImage(textureFile);
    if (img == null) {
        throw new RuntimeException("File not found: " + textureFile.toString());
    }

    int[] data = new int[img.getWidth()];
    img.getRGB(0, 0, img.getWidth(), 1, data, 0, img.getWidth());
    gradient = new int[img.getWidth()];
    for (int i = 0; i < data.length; i++) {
        gradient[i] = (data[i] << 8) | (((data[i]) >> 24) & 0xFF);
    }
}
 
源代码11 项目: AdvancedRocketry   文件: WavefrontObject.java
public WavefrontObject(ResourceLocation resource) throws ModelFormatException
{
    this.fileName = resource.toString();

    try
    {
        IResource res = Minecraft.getMinecraft().getResourceManager().getResource(resource);
        loadObjModel(res.getInputStream());
    }
    catch (IOException e)
    {
        throw new ModelFormatException("IO Exception reading model format", e);
    }
}
 
源代码12 项目: YUNoMakeGoodMap   文件: GuiCustomizeWorld.java
private StructInfo getInfo(ResourceLocation res)
{
    StructInfo ret = structInfo.get(res);
    if (ret != null)
        return ret;

    try
    {
        IResource ir = this.mc.getResourceManager().getResource(new ResourceLocation(res.getResourceDomain(), "structures/" + res.getResourcePath() + ".json"));
        ret = GSON.fromJson(new InputStreamReader(ir.getInputStream()), StructInfo.class);

        if (ret.logo != null)
        {
            ir = this.mc.getResourceManager().getResource(new ResourceLocation(res.getResourceDomain(), "structures/" + ret.logo));
            if (ir != null)
            {
                BufferedImage l = ImageIO.read(ir.getInputStream());
                ret.logoPath = this.mc.getTextureManager().getDynamicTextureLocation("platformlogo", new DynamicTexture(l));
                ret.logoSize = new Dimension(l.getWidth(), l.getHeight());
            }
        }
    }
    catch (IOException e)
    {
        //Ugh wish it had a 'hasResource'
    }

    if (ret == null)
        ret = new StructInfo();

    if (ret.name == null)
        ret.name = res.toString();

    structInfo.put(res, ret);
    return ret;
}
 
源代码13 项目: CodeChickenLib   文件: CustomGradient.java
public CustomGradient(ResourceLocation textureFile)
{
    BufferedImage img = TextureUtils.loadBufferedImage(textureFile);
    if(img == null)
        throw new RuntimeException("File not found: "+textureFile.toString());

    int[] data = new int[img.getWidth()];
    img.getRGB(0, 0, img.getWidth(), 1, data, 0, img.getWidth());
    gradient = new int[img.getWidth()];
    for(int i = 0; i < data.length; i++)
        gradient[i] = (data[i]<<8)|(((data[i])>>24)&0xFF);
}
 
源代码14 项目: litematica   文件: TaskFillArea.java
protected TaskFillArea(List<SelectionBox> boxes, IBlockState fillState, @Nullable IBlockState replaceState, boolean removeEntities, String nameOnHud)
{
    super(nameOnHud);

    this.fillState = fillState;
    this.replaceState = replaceState;
    this.removeEntities = removeEntities;

    ResourceLocation rl = Block.REGISTRY.getNameForObject(fillState.getBlock());
    String strName = null;

    if (rl != null)
    {
        String blockName = rl.toString();
        strName = blockName + " " + String.valueOf(fillState.getBlock().getMetaFromState(fillState));

        if (replaceState != null)
        {
            rl = Block.REGISTRY.getNameForObject(replaceState.getBlock());

            if (rl != null)
            {
                strName += " replace " + rl.toString();
            }
            else
            {
                InfoUtils.showGuiOrInGameMessage(MessageType.ERROR, "litematica-message.error.invalid_block", replaceState.toString());
                strName = null;
            }
        }
    }
    else
    {
        InfoUtils.showGuiOrInGameMessage(MessageType.ERROR, "litematica-message.error.invalid_block", fillState.toString());
    }

    this.blockString = strName;

    this.addBoxesPerChunks(boxes);
    this.updateInfoHudLinesMissingChunks(this.requiredChunks);
}
 
源代码15 项目: OpenModsLib   文件: CustomRecipeBase.java
public CustomRecipeBase(ResourceLocation group) {
	this.group = group.toString();
}