diff options
| author | Lance5057 <Lance5057@gmail.com> | 2017-11-26 02:38:49 -0600 |
|---|---|---|
| committer | Lance5057 <Lance5057@gmail.com> | 2017-11-26 02:38:49 -0600 |
| commit | f2f2eedda86142a5c9b090f164c9a64d92e1ea66 (patch) | |
| tree | 46943eb4678691f9f71bf55263f47b6d1b9be88d /src/main/java/lance5057/tDefense/renderers | |
| parent | 6af565ab07a802518345df7f06772df56f6e205f (diff) | |
Added more materials, broke something in the tool table.
Diffstat (limited to 'src/main/java/lance5057/tDefense/renderers')
3 files changed, 185 insertions, 0 deletions
diff --git a/src/main/java/lance5057/tDefense/renderers/AlphaColorTexture.java b/src/main/java/lance5057/tDefense/renderers/AlphaColorTexture.java new file mode 100644 index 0000000..15da871 --- /dev/null +++ b/src/main/java/lance5057/tDefense/renderers/AlphaColorTexture.java @@ -0,0 +1,85 @@ +package lance5057.tDefense.renderers; + +import net.minecraft.util.ResourceLocation; +import slimeknights.tconstruct.library.client.RenderUtil; +import slimeknights.tconstruct.library.client.texture.AbstractColoredTexture; + +public class AlphaColorTexture extends AbstractColoredTexture { + protected final int colorLow; + protected final int colorMid; + protected final int colorHigh; + protected int minBrightness; + protected int maxBrightness; + protected int brightnessData[]; + + public AlphaColorTexture(int colorLow, int colorMid, int colorHigh, ResourceLocation baseTexture, + String spriteName) { + super(baseTexture, spriteName); + this.colorLow = colorLow; + this.colorMid = colorMid; + this.colorHigh = colorHigh; + } + + @Override + protected void preProcess(int[] data) { + // setup brigthness data + int max = 0; + int min = 255; + brightnessData = new int[data.length]; + for(int i = 0; i < data.length; i++) { + int pixel = data[i]; + if(RenderUtil.alpha(pixel) == 0) { + continue; + } + int brightness = getPerceptualBrightness(pixel); + if(brightness < min) { + min = brightness; + } + if(brightness > max) { + max = brightness; + } + brightnessData[i] = brightness; + } + + // calculate the actual limits where we change color + int brightnessDiff = max - min; + brightnessDiff /= 2; + minBrightness = Math.max(min + 1, min + (int) (brightnessDiff * 0.4f)); + maxBrightness = Math.min(max - 1, max - (int) (brightnessDiff * 0.3f)); + } + + @Override + protected void postProcess(int[] data) { + // delete memory that we don't need anymore. We only cached it for faster loading anyway + brightnessData = null; + } + + @Override + protected int colorPixel(int pixel, int pxCoord) { + int a = RenderUtil.alpha(pixel); + if(a == 0) { + return pixel; + } + + int brightness = brightnessData[pxCoord]; + int c = colorMid; + if(brightness < minBrightness) { + c = colorLow; + } + else if(brightness > maxBrightness) { + c = colorHigh; + } + + // multiply in the color + int r = RenderUtil.red(c); + int b = RenderUtil.blue(c); + int g = RenderUtil.green(c); + + r = mult(r, RenderUtil.red(pixel)) & 0xff; + g = mult(g, RenderUtil.blue(pixel)) & 0xff; + b = mult(b, RenderUtil.green(pixel)) & 0xff; + + // put it back together + return RenderUtil.compose(r, g, b, a); + } +} diff --git a/src/main/java/lance5057/tDefense/renderers/deserializers/AlphaColorTextureDeserializer.java b/src/main/java/lance5057/tDefense/renderers/deserializers/AlphaColorTextureDeserializer.java new file mode 100644 index 0000000..2242526 --- /dev/null +++ b/src/main/java/lance5057/tDefense/renderers/deserializers/AlphaColorTextureDeserializer.java @@ -0,0 +1,15 @@ +package lance5057.tDefense.renderers.deserializers; + +import lance5057.tDefense.renderers.info.TDMaterialRenderInfo; +import slimeknights.tconstruct.library.client.MaterialRenderInfo; +import slimeknights.tconstruct.library.client.material.deserializers.AbstractRenderInfoDeserializer; + +public class AlphaColorTextureDeserializer extends AbstractRenderInfoDeserializer { + + protected String color; + + @Override + public MaterialRenderInfo getMaterialRenderInfo() { + return new TDMaterialRenderInfo.AlphaColor(fromHex(color)); + } +}
\ No newline at end of file diff --git a/src/main/java/lance5057/tDefense/renderers/info/TDMaterialRenderInfo.java b/src/main/java/lance5057/tDefense/renderers/info/TDMaterialRenderInfo.java new file mode 100644 index 0000000..a22d514 --- /dev/null +++ b/src/main/java/lance5057/tDefense/renderers/info/TDMaterialRenderInfo.java @@ -0,0 +1,85 @@ +package lance5057.tDefense.renderers.info; + +import lance5057.tDefense.renderers.AlphaColorTexture; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.ResourceLocation; +import slimeknights.tconstruct.library.client.MaterialRenderInfo; +import slimeknights.tconstruct.library.client.MaterialRenderInfo.AbstractMaterialRenderInfo; +import slimeknights.tconstruct.library.client.texture.SimpleColoredTexture; +import slimeknights.tconstruct.library.client.texture.TinkerTexture; + +public interface TDMaterialRenderInfo { + + TextureAtlasSprite getTexture(ResourceLocation baseTexture, String location); + + boolean isStitched(); + + boolean useVertexColoring(); + + int getVertexColor(); + + // this actually would require its own thing, but we put it here for simplicity + String getTextureSuffix(); + + MaterialRenderInfo setTextureSuffix(String suffix); + + abstract class AbstractMaterialRenderInfo implements MaterialRenderInfo { + + private String suffix; + + @Override + public boolean isStitched() { + return true; + } + + @Override + public boolean useVertexColoring() { + return false; + } + + @Override + public int getVertexColor() { + return 0xffffffff; // white and opaque + } + + @Override + public String getTextureSuffix() { + return suffix; + } + + @Override + public MaterialRenderInfo setTextureSuffix(String suffix) { + this.suffix = suffix; + return this; + } + } + + class AlphaColor extends AbstractMaterialRenderInfo { + + public final int color; + + public AlphaColor(int color) { + this.color = color; + } + + @Override + public TextureAtlasSprite getTexture(ResourceLocation baseTexture, String location) { + return new AlphaColorTexture(color, color, color, baseTexture, location); + } + + @Override + public boolean isStitched() { + return false; + } + + @Override + public boolean useVertexColoring() { + return true; + } + + @Override + public int getVertexColor() { + return color; + } + } +} |
