Search in sources :

Example 6 with ResourceLocation

use of net.minecraft.util.ResourceLocation in project malmo by Microsoft.

the class MinecraftTypeHelper method getDrawBlockFromBlockState.

/** Extract the type, variation and facing attributes of a blockstate and return them in a new DrawBlock object.<br>
     * @param state the IBlockState to be examined
     * @return A DrawBlock object
     */
public static DrawBlock getDrawBlockFromBlockState(IBlockState state, List<IProperty> extraProperties) {
    if (state == null)
        return null;
    DrawBlock block = new DrawBlock();
    Object blockName = Block.blockRegistry.getNameForObject(state.getBlock());
    if (blockName instanceof ResourceLocation) {
        String name = ((ResourceLocation) blockName).getResourcePath();
        BlockType type = BlockType.fromValue(name);
        block.setType(type);
    }
    Colour col = null;
    Variation var = null;
    Facing face = null;
    // Add properties:
    for (IProperty prop : (java.util.Set<IProperty>) state.getProperties().keySet()) {
        String propVal = state.getValue(prop).toString();
        boolean matched = false;
        // Try colour first:
        if (col == null) {
            col = attemptToGetAsColour(propVal);
            if (col != null)
                matched = true;
        }
        // Then variant:
        if (!matched && var == null) {
            var = attemptToGetAsVariant(propVal);
            if (var != null)
                matched = true;
        }
        // Then facing:
        if (!matched && face == null) {
            face = attemptToGetAsFacing(propVal);
            if (face != null)
                matched = true;
        }
        if (!matched) {
            if (extraProperties != null)
                extraProperties.add(prop);
        }
    }
    if (col != null)
        block.setColour(col);
    if (var != null)
        block.setVariant(var);
    if (face != null)
        block.setFace(face);
    return block;
}
Also used : Facing(com.microsoft.Malmo.Schemas.Facing) EnumFacing(net.minecraft.util.EnumFacing) BlockType(com.microsoft.Malmo.Schemas.BlockType) IProperty(net.minecraft.block.properties.IProperty) ResourceLocation(net.minecraft.util.ResourceLocation) DrawBlock(com.microsoft.Malmo.Schemas.DrawBlock) Variation(com.microsoft.Malmo.Schemas.Variation) Colour(com.microsoft.Malmo.Schemas.Colour)

Example 7 with ResourceLocation

use of net.minecraft.util.ResourceLocation in project malmo by Microsoft.

the class MinecraftTypeHelper method ParseItemType.

/**
     * Attempts to parse the item type string.
     * @param s The string to parse.
     * @param checkBlocks if string can't be parsed as an item, attempt to parse as a block, if checkBlocks is true
     * @return The item type, or null if the string is not recognised.
     */
public static Item ParseItemType(String s, boolean checkBlocks) {
    if (s == null)
        return null;
    // Minecraft returns null when it doesn't recognise the string
    Item item = (Item) Item.itemRegistry.getObject(new ResourceLocation(s));
    if (item == null && checkBlocks) {
        // Maybe this is a request for a block item?
        IBlockState block = MinecraftTypeHelper.ParseBlockType(s);
        item = (block != null && block.getBlock() != null) ? Item.getItemFromBlock(block.getBlock()) : null;
    }
    return item;
}
Also used : DrawItem(com.microsoft.Malmo.Schemas.DrawItem) Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 8 with ResourceLocation

use of net.minecraft.util.ResourceLocation in project malmo by Microsoft.

the class JSONWorldDataHelper method buildGridData.

/**
     * Build a signal for the cubic block grid centred on the player.<br>
     * Default is 3x3x4. (One cube all around the player.)<br>
     * Blocks are returned as a 1D array, in order
     * along the x, then z, then y axes.<br>
     * Data will be returned in an array called "Cells"
     * @param json a JSON object into which the info for the object under the mouse will be added.
     * @param environmentDimensions object which specifies the required dimensions of the grid to be returned.
     * @param jsonName name to use for identifying the returned JSON array.
     */
public static void buildGridData(JsonObject json, GridDimensions environmentDimensions, EntityPlayerMP player, String jsonName) {
    if (player == null || json == null)
        return;
    JsonArray arr = new JsonArray();
    BlockPos pos = new BlockPos(player.posX, player.posY, player.posZ);
    for (int y = environmentDimensions.yMin; y <= environmentDimensions.yMax; y++) {
        for (int z = environmentDimensions.zMin; z <= environmentDimensions.zMax; z++) {
            for (int x = environmentDimensions.xMin; x <= environmentDimensions.xMax; x++) {
                BlockPos p;
                if (environmentDimensions.absoluteCoords)
                    p = new BlockPos(x, y, z);
                else
                    p = pos.add(x, y, z);
                String name = "";
                IBlockState state = player.worldObj.getBlockState(p);
                Object blockName = Block.blockRegistry.getNameForObject(state.getBlock());
                if (blockName instanceof ResourceLocation) {
                    name = ((ResourceLocation) blockName).getResourcePath();
                }
                JsonElement element = new JsonPrimitive(name);
                arr.add(element);
            }
        }
    }
    json.add(jsonName, arr);
}
Also used : JsonArray(com.google.gson.JsonArray) IBlockState(net.minecraft.block.state.IBlockState) JsonPrimitive(com.google.gson.JsonPrimitive) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.BlockPos) JsonObject(com.google.gson.JsonObject)

Example 9 with ResourceLocation

use of net.minecraft.util.ResourceLocation in project MinecraftForge by MinecraftForge.

the class ModelLoader method onPostBakeEvent.

/**
     * Internal, do not use.
     */
public void onPostBakeEvent(IRegistry<ModelResourceLocation, IBakedModel> modelRegistry) {
    IBakedModel missingModel = modelRegistry.getObject(MODEL_MISSING);
    Map<String, Integer> modelErrors = Maps.newHashMap();
    Set<ResourceLocation> printedBlockStateErrors = Sets.newHashSet();
    Multimap<ModelResourceLocation, IBlockState> reverseBlockMap = null;
    Multimap<ModelResourceLocation, String> reverseItemMap = null;
    if (enableVerboseMissingInfo) {
        reverseBlockMap = HashMultimap.create();
        for (Map.Entry<IBlockState, ModelResourceLocation> entry : blockModelShapes.getBlockStateMapper().putAllStateModelLocations().entrySet()) {
            reverseBlockMap.put(entry.getValue(), entry.getKey());
        }
        reverseItemMap = HashMultimap.create();
        for (Item item : GameData.getItemRegistry().typeSafeIterable()) {
            for (String s : getVariantNames(item)) {
                ModelResourceLocation memory = getInventoryVariant(s);
                reverseItemMap.put(memory, item.getRegistryName().toString());
            }
        }
    }
    for (Map.Entry<ResourceLocation, Exception> entry : loadingExceptions.entrySet()) {
        // ignoring pure ResourceLocation arguments, all things we care about pass ModelResourceLocation
        if (entry.getKey() instanceof ModelResourceLocation) {
            ModelResourceLocation location = (ModelResourceLocation) entry.getKey();
            IBakedModel model = modelRegistry.getObject(location);
            if (model == null || model == missingModel) {
                String domain = entry.getKey().getResourceDomain();
                Integer errorCountBox = modelErrors.get(domain);
                int errorCount = errorCountBox == null ? 0 : errorCountBox;
                errorCount++;
                if (errorCount < verboseMissingInfoCount) {
                    String errorMsg = "Exception loading model for variant " + entry.getKey();
                    if (enableVerboseMissingInfo) {
                        Collection<IBlockState> blocks = reverseBlockMap.get(location);
                        if (!blocks.isEmpty()) {
                            if (blocks.size() == 1) {
                                errorMsg += " for blockstate \"" + blocks.iterator().next() + "\"";
                            } else {
                                errorMsg += " for blockstates [\"" + Joiner.on("\", \"").join(blocks) + "\"]";
                            }
                        }
                        Collection<String> items = reverseItemMap.get(location);
                        if (!items.isEmpty()) {
                            if (!blocks.isEmpty())
                                errorMsg += " and";
                            if (items.size() == 1) {
                                errorMsg += " for item \"" + items.iterator().next() + "\"";
                            } else {
                                errorMsg += " for items [\"" + Joiner.on("\", \"").join(items) + "\"]";
                            }
                        }
                    }
                    if (entry.getValue() instanceof ItemLoadingException) {
                        ItemLoadingException ex = (ItemLoadingException) entry.getValue();
                        FMLLog.getLogger().error(errorMsg + ", normal location exception: ", ex.normalException);
                        FMLLog.getLogger().error(errorMsg + ", blockstate location exception: ", ex.blockstateException);
                    } else {
                        FMLLog.getLogger().error(errorMsg, entry.getValue());
                    }
                    ResourceLocation blockstateLocation = new ResourceLocation(location.getResourceDomain(), location.getResourcePath());
                    if (loadingExceptions.containsKey(blockstateLocation) && !printedBlockStateErrors.contains(blockstateLocation)) {
                        FMLLog.getLogger().error("Exception loading blockstate for the variant " + location + ": ", loadingExceptions.get(blockstateLocation));
                        printedBlockStateErrors.add(blockstateLocation);
                    }
                }
                modelErrors.put(domain, errorCount);
            }
            if (model == null) {
                modelRegistry.putObject(location, missingModel);
            }
        }
    }
    for (ModelResourceLocation missing : missingVariants) {
        IBakedModel model = modelRegistry.getObject(missing);
        if (model == null || model == missingModel) {
            String domain = missing.getResourceDomain();
            Integer errorCountBox = modelErrors.get(domain);
            int errorCount = errorCountBox == null ? 0 : errorCountBox;
            errorCount++;
            if (errorCount < verboseMissingInfoCount) {
                FMLLog.severe("Model definition for location %s not found", missing);
            }
            modelErrors.put(domain, errorCount);
        }
        if (model == null) {
            modelRegistry.putObject(missing, missingModel);
        }
    }
    for (Map.Entry<String, Integer> e : modelErrors.entrySet()) {
        if (e.getValue() >= verboseMissingInfoCount) {
            FMLLog.severe("Suppressed additional %s model loading errors for domain %s", e.getValue() - verboseMissingInfoCount, e.getKey());
        }
    }
    isLoading = false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) MissingVariantException(net.minecraft.client.renderer.block.model.ModelBlockDefinition.MissingVariantException) Item(net.minecraft.item.Item) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Map(java.util.Map) TextureMap(net.minecraft.client.renderer.texture.TextureMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 10 with ResourceLocation

use of net.minecraft.util.ResourceLocation in project MinecraftForge by MinecraftForge.

the class ModelLoader method loadItemModels.

@Override
protected void loadItemModels() {
    // register model for the universal bucket, if it exists
    if (FluidRegistry.isUniversalBucketEnabled()) {
        setBucketModelDefinition(ForgeModContainer.getInstance().universalBucket);
    }
    registerVariantNames();
    List<Item> items = Lists.newArrayList(Iterables.filter(Item.REGISTRY, new Predicate<Item>() {

        public boolean apply(Item item) {
            return item.getRegistryName() != null;
        }
    }));
    Collections.sort(items, new Comparator<Item>() {

        public int compare(Item i1, Item i2) {
            return i1.getRegistryName().toString().compareTo(i2.getRegistryName().toString());
        }
    });
    ProgressBar itemBar = ProgressManager.push("ModelLoader: items", items.size());
    for (Item item : items) {
        itemBar.step(item.getRegistryName().toString());
        for (String s : getVariantNames(item)) {
            ResourceLocation file = getItemLocation(s);
            ModelResourceLocation memory = getInventoryVariant(s);
            IModel model = ModelLoaderRegistry.getMissingModel();
            Exception exception = null;
            try {
                model = ModelLoaderRegistry.getModel(file);
            } catch (Exception normalException) {
                // try blockstate json if the item model is missing
                FMLLog.fine("Item json isn't found for '" + memory + "', trying to load the variant from the blockstate json");
                try {
                    model = ModelLoaderRegistry.getModel(memory);
                } catch (Exception blockstateException) {
                    exception = new ItemLoadingException("Could not load item model either from the normal location " + file + " or from the blockstate", normalException, blockstateException);
                }
            }
            if (exception != null) {
                storeException(memory, exception);
                model = ModelLoaderRegistry.getMissingModel(memory, exception);
            }
            stateModels.put(memory, model);
        }
    }
    ProgressManager.pop(itemBar);
    // replace vanilla bucket models if desired. done afterwards for performance reasons
    if (ForgeModContainer.replaceVanillaBucketModel) {
        // ensure the bucket model is loaded
        if (!stateModels.containsKey(ModelDynBucket.LOCATION)) {
            // load forges blockstate json for it
            try {
                registerVariant(getModelBlockDefinition(ModelDynBucket.LOCATION), ModelDynBucket.LOCATION);
            } catch (Exception exception) {
                FMLLog.getLogger().error("Could not load the forge bucket model from the blockstate", exception);
                return;
            }
        }
        // empty bucket
        for (String s : getVariantNames(Items.BUCKET)) {
            ModelResourceLocation memory = getInventoryVariant(s);
            IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(ForgeVersion.MOD_ID, "item/bucket"));
            // only on successful load, otherwise continue using the old model
            if (model != getMissingModel()) {
                stateModels.put(memory, model);
            }
        }
        setBucketModel(Items.WATER_BUCKET);
        setBucketModel(Items.LAVA_BUCKET);
        // milk bucket only replaced if some mod adds milk
        if (FluidRegistry.isFluidRegistered("milk")) {
            // can the milk be put into a bucket?
            Fluid milk = FluidRegistry.getFluid("milk");
            FluidStack milkStack = new FluidStack(milk, Fluid.BUCKET_VOLUME);
            IFluidHandler bucketHandler = FluidUtil.getFluidHandler(new ItemStack(Items.BUCKET));
            if (bucketHandler != null && bucketHandler.fill(milkStack, false) == Fluid.BUCKET_VOLUME) {
                setBucketModel(Items.MILK_BUCKET);
            }
        } else {
            // milk bucket if no milk fluid is present
            for (String s : getVariantNames(Items.MILK_BUCKET)) {
                ModelResourceLocation memory = getInventoryVariant(s);
                IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(ForgeVersion.MOD_ID, "item/bucket_milk"));
                // only on successful load, otherwise continue using the old model
                if (model != getMissingModel()) {
                    stateModels.put(memory, model);
                }
            }
        }
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) MissingVariantException(net.minecraft.client.renderer.block.model.ModelBlockDefinition.MissingVariantException) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) Predicate(com.google.common.base.Predicate) Item(net.minecraft.item.Item) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) ProgressBar(net.minecraftforge.fml.common.ProgressManager.ProgressBar)

Aggregations

ResourceLocation (net.minecraft.util.ResourceLocation)272 ItemStack (net.minecraft.item.ItemStack)51 Block (net.minecraft.block.Block)47 Item (net.minecraft.item.Item)32 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)31 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)30 IBlockState (net.minecraft.block.state.IBlockState)17 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)15 ArrayList (java.util.ArrayList)14 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)14 Map (java.util.Map)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)11 ShaderLayer (blusunrize.immersiveengineering.api.shader.ShaderCase.ShaderLayer)10 IOException (java.io.IOException)10 TileEntity (net.minecraft.tileentity.TileEntity)9 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)8 EnumFacing (net.minecraft.util.EnumFacing)8 BlockPos (net.minecraft.util.math.BlockPos)8 Random (java.util.Random)7 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)7