Search in sources :

Example 1 with TIntObjectMap

use of gnu.trove.map.TIntObjectMap in project Charset by CharsetMC.

the class ProxyClient method onTextureStitch.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onTextureStitch(TextureStitchEvent.Pre event) {
    GateRenderDefinitions.INSTANCE.load("simplelogic:gatedefs/base.json", SimpleLogicGates.logicDefinitions);
    for (ResourceLocation rs : SimpleLogicGates.logicClasses.keySet()) {
        Set<ResourceLocation> textures = new HashSet<>();
        Map<String, TIntObjectMap<String>> colorMasks = new HashMap<>();
        // step 1: gather colormasks
        int i = 0;
        for (GateRenderDefinitions.Layer layer : GateRenderDefinitions.INSTANCE.getGateDefinition(rs).layers) {
            if (layer.color_mask != null) {
                layer.texture = rs.getResourceDomain() + ":blocks/" + rs.getResourcePath() + "/layer_" + i;
                colorMasks.computeIfAbsent(layer.textureBase, (k) -> new TIntObjectHashMap<>()).put(Integer.parseInt(layer.color_mask, 16), layer.texture);
            }
            i++;
        }
        // step 2: gather textures
        GateRenderDefinitions.Definition def = GateRenderDefinitions.INSTANCE.getGateDefinition(rs);
        for (IModel model : def.getAllModels()) {
            textures.addAll(model.getTextures());
        }
        for (GateRenderDefinitions.Layer layer : GateRenderDefinitions.INSTANCE.getGateDefinition(rs).layers) {
            if (layer.texture != null) {
                textures.add(new ResourceLocation(layer.texture));
            }
        }
        // step 3: add colormasked textures
        for (String baseTexture : colorMasks.keySet()) {
            TIntObjectMap<String> resultingTextures = colorMasks.get(baseTexture);
            resultingTextures.forEachEntry((color, resultingTexture) -> {
                event.getMap().setTextureEntry(new PixelOperationSprite(resultingTexture, new ResourceLocation(baseTexture), ((getter, x, y, value) -> (value & 0xFFFFFF) == color ? -1 : 0)));
                textures.remove(new ResourceLocation(resultingTexture));
                return true;
            });
            event.getMap().setTextureEntry(new PixelOperationSprite(baseTexture, new ResourceLocation(baseTexture), (((getter, x, y, value) -> {
                if (resultingTextures.containsKey(value & 0xFFFFFF)) {
                    return 0;
                } else {
                    return value;
                }
            }))));
            textures.remove(new ResourceLocation(baseTexture));
        }
        // step 4: add non-colormasked textures
        for (ResourceLocation location : textures) {
            event.getMap().registerSprite(location);
        }
    }
}
Also used : ModelBakeEvent(net.minecraftforge.client.event.ModelBakeEvent) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) TIntObjectMap(gnu.trove.map.TIntObjectMap) ModelRegistryEvent(net.minecraftforge.client.event.ModelRegistryEvent) Set(java.util.Set) GateRenderDefinitions(pl.asie.simplelogic.gates.render.GateRenderDefinitions) HashMap(java.util.HashMap) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IModel(net.minecraftforge.client.model.IModel) HashSet(java.util.HashSet) PixelOperationSprite(pl.asie.charset.lib.render.sprite.PixelOperationSprite) Side(net.minecraftforge.fml.relauncher.Side) RendererGate(pl.asie.simplelogic.gates.render.RendererGate) RegistryUtils(pl.asie.charset.lib.utils.RegistryUtils) Map(java.util.Map) TextureStitchEvent(net.minecraftforge.client.event.TextureStitchEvent) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) IModel(net.minecraftforge.client.model.IModel) PixelOperationSprite(pl.asie.charset.lib.render.sprite.PixelOperationSprite) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) HashMap(java.util.HashMap) GateRenderDefinitions(pl.asie.simplelogic.gates.render.GateRenderDefinitions) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) TIntObjectMap(gnu.trove.map.TIntObjectMap) HashSet(java.util.HashSet) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

TIntObjectMap (gnu.trove.map.TIntObjectMap)1 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 ModelBakeEvent (net.minecraftforge.client.event.ModelBakeEvent)1 ModelRegistryEvent (net.minecraftforge.client.event.ModelRegistryEvent)1 TextureStitchEvent (net.minecraftforge.client.event.TextureStitchEvent)1 IModel (net.minecraftforge.client.model.IModel)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 Side (net.minecraftforge.fml.relauncher.Side)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1 PixelOperationSprite (pl.asie.charset.lib.render.sprite.PixelOperationSprite)1 RegistryUtils (pl.asie.charset.lib.utils.RegistryUtils)1 GateRenderDefinitions (pl.asie.simplelogic.gates.render.GateRenderDefinitions)1 RendererGate (pl.asie.simplelogic.gates.render.RendererGate)1