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);
}
}
}
Aggregations