Search in sources :

Example 1 with MaterialIconSet

use of gregtech.api.unification.material.info.MaterialIconSet in project GregTech by GregTechCEu.

the class MetaOreDictItem method registerModels.

@Override
@SideOnly(Side.CLIENT)
public void registerModels() {
    TIntObjectHashMap<ModelResourceLocation> alreadyRegistered = new TIntObjectHashMap<>();
    for (Map.Entry<Short, OreDictValueItem> metaItem : ITEMS.entrySet()) {
        OrePrefix prefix = metaItem.getValue().orePrefix;
        MaterialIconSet materialIconSet = metaItem.getValue().materialIconSet;
        if (prefix.materialIconType == null || DISALLOWED_TYPES.contains(prefix.materialIconType))
            continue;
        int registrationKey = prefix.id * 1000 + materialIconSet.id;
        if (!alreadyRegistered.containsKey(registrationKey)) {
            prefix.materialIconType.getItemModelPath(materialIconSet);
            ResourceLocation resourceLocation = prefix.materialIconType.getItemModelPath(materialIconSet);
            ModelBakery.registerItemVariants(this, resourceLocation);
            alreadyRegistered.put(registrationKey, new ModelResourceLocation(resourceLocation, "inventory"));
        }
        ModelResourceLocation resourceLocation = alreadyRegistered.get(registrationKey);
        metaItemsModels.put(metaItem.getKey(), resourceLocation);
    }
}
Also used : MaterialIconSet(gregtech.api.unification.material.info.MaterialIconSet) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) OrePrefix(gregtech.api.unification.ore.OrePrefix) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) HashMap(java.util.HashMap) Map(java.util.Map) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with MaterialIconSet

use of gregtech.api.unification.material.info.MaterialIconSet in project GregTech by GregTechCEu.

the class ClientProxy method registerSprites.

@SubscribeEvent
public static void registerSprites(TextureStitchEvent.Pre event) {
    for (MaterialIconSet set : MaterialIconSet.ICON_SETS.values()) {
        event.getMap().registerSprite(MaterialIconType.ore.getBlockPath(set));
        event.getMap().registerSprite(MaterialIconType.block.getBlockPath(set));
    }
    MetaBlocks.COMPRESSED.values().stream().distinct().forEach(c -> c.onTextureStitch(event));
    MetaBlocks.FRAMES.values().stream().distinct().forEach(f -> f.onTextureStitch(event));
    MetaBlocks.ORES.forEach(o -> o.onTextureStitch(event));
}
Also used : MaterialIconSet(gregtech.api.unification.material.info.MaterialIconSet) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with MaterialIconSet

use of gregtech.api.unification.material.info.MaterialIconSet in project GregTech by GregTechCEu.

the class MetaPrefixItem method registerModels.

@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings("ConstantConditions")
public void registerModels() {
    TShortObjectHashMap<ModelResourceLocation> alreadyRegistered = new TShortObjectHashMap<>();
    for (short metaItem : metaItems.keySet()) {
        MaterialIconSet materialIconSet = GregTechAPI.MATERIAL_REGISTRY.getObjectById(metaItem).getMaterialIconSet();
        short registrationKey = (short) (prefix.id + materialIconSet.id);
        if (!alreadyRegistered.containsKey(registrationKey)) {
            ResourceLocation resourceLocation = prefix.materialIconType.getItemModelPath(materialIconSet);
            ModelBakery.registerItemVariants(this, resourceLocation);
            alreadyRegistered.put(registrationKey, new ModelResourceLocation(resourceLocation, "inventory"));
        }
        ModelResourceLocation resourceLocation = alreadyRegistered.get(registrationKey);
        metaItemsModels.put(metaItem, resourceLocation);
    }
    // Make some default model for meta prefix items without any materials associated
    if (metaItems.keySet().isEmpty()) {
        MaterialIconSet defaultIcon = MaterialIconSet.DULL;
        ResourceLocation defaultLocation = OrePrefix.ingot.materialIconType.getItemModelPath(defaultIcon);
        ModelBakery.registerItemVariants(this, defaultLocation);
    }
}
Also used : MaterialIconSet(gregtech.api.unification.material.info.MaterialIconSet) TShortObjectHashMap(gnu.trove.map.hash.TShortObjectHashMap) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 4 with MaterialIconSet

use of gregtech.api.unification.material.info.MaterialIconSet in project GregTech by GregTechCEu.

the class OreBakedModel method getQuads.

@Override
@Nonnull
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
    if (state != null) {
        BlockOre ore = (BlockOre) state.getBlock();
        StoneType stoneType = state.getValue(ore.STONE_TYPE);
        MaterialIconSet materialIconSet = ore.material.getMaterialIconSet();
        TextureAtlasSprite textureAtlasSprite = stoneTypeModels.computeIfAbsent(stoneType, type -> Minecraft.getMinecraft().blockRenderDispatcher.getModelForState(type.stone.get()).getParticleTexture());
        particle.set(textureAtlasSprite);
        if (model == null) {
            model = new ModelFactory(ModelFactory.ModelTemplate.CUBE_2_LAYER_ALL_TINT_INDEX).bake();
        }
        BakedQuad bakedQuad = cacheBottom.get(stoneType, side);
        if (side == null)
            return Collections.emptyList();
        if (bakedQuad == null) {
            cacheBottom.put(stoneType, side, bakedQuad = new BakedQuadRetextured(model.getQuads(state, side, rand).get(0), textureAtlasSprite));
        }
        BakedQuad[] bakedQuads = cacheTop.get(materialIconSet, side);
        if (bakedQuads == null) {
            bakedQuads = new BakedQuad[2];
            bakedQuads[0] = new BakedQuadRetextured(model.getQuads(state, side, rand).get(1), ModelLoader.defaultTextureGetter().apply(MaterialIconType.ore.getBlockPath(materialIconSet)));
            bakedQuads[1] = CustomTexture.rebake(15, 15, bakedQuads[0]);
            cacheTop.put(materialIconSet, side, bakedQuads);
        }
        BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer();
        boolean hasEmissive = ore.material.getProperty(PropertyKey.ORE).isEmissive();
        boolean isEmissiveLayer = hasEmissive && (layer == BloomEffectUtil.getRealBloomLayer() || layer == null);
        List<BakedQuad> quads = new ArrayList<>();
        if (!hasEmissive || !isEmissiveLayer || layer == null) {
            quads.add(bakedQuad);
        }
        if (hasEmissive && isEmissiveLayer) {
            quads.add(bakedQuads[1]);
        } else {
            quads.add(bakedQuads[0]);
        }
        return quads;
    } else {
        List<BakedQuad> quads = new ArrayList<>();
        ItemStack stack = OreItemOverride.INSTANCE.stack.get();
        if (!stack.isEmpty()) {
            BlockOre ore = (BlockOre) ((ItemBlock) stack.getItem()).getBlock();
            IBlockState oreState = ore.getDefaultState().withProperty(ore.STONE_TYPE, ore.STONE_TYPE.getAllowedValues().get(stack.getMetadata()));
            for (EnumFacing face : EnumFacing.VALUES) {
                quads.addAll(getQuads(oreState, face, rand));
            }
        }
        return quads;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) MaterialIconSet(gregtech.api.unification.material.info.MaterialIconSet) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) StoneType(gregtech.api.unification.ore.StoneType) EnumFacing(net.minecraft.util.EnumFacing) BlockOre(gregtech.common.blocks.BlockOre) ModelFactory(gregtech.client.model.ModelFactory) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

MaterialIconSet (gregtech.api.unification.material.info.MaterialIconSet)4 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)1 TShortObjectHashMap (gnu.trove.map.hash.TShortObjectHashMap)1 OrePrefix (gregtech.api.unification.ore.OrePrefix)1 StoneType (gregtech.api.unification.ore.StoneType)1 ModelFactory (gregtech.client.model.ModelFactory)1 BlockOre (gregtech.common.blocks.BlockOre)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Nonnull (javax.annotation.Nonnull)1 IBlockState (net.minecraft.block.state.IBlockState)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 ItemStack (net.minecraft.item.ItemStack)1 BlockRenderLayer (net.minecraft.util.BlockRenderLayer)1 EnumFacing (net.minecraft.util.EnumFacing)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1