Compare commits

...
4 Commits
Author SHA1 Message Date
tth05 ea4f68d163 Add map to provide fast access to all config tags in sub-tree (#18) 2024-07-18 21:37:30 +07:00
Dream Master 549f769747 update 2024-07-17 16:47:04 +07:00
Caedis cba2e0f642 Fix casing 2024-07-04 00:30:22 -07:00
Jason Mitchell 3740253590 Maybe more backwards compatible (#16)
* Maybe more backwards compatible
2024-07-03 11:21:27 -07:00
17 changed files with 180 additions and 120 deletions

No files matched your search

+3
View File
@@ -55,6 +55,9 @@ generateGradleTokenClass = codechicken.core.asm.Tags
# Name of the token containing the project's current version to generate/replace.
gradleTokenVersion = VERSION
# [DEPRECATED] Mod Group replacement token.
gradleTokenGroupName =
# [DEPRECATED]
# Multiple source files can be defined here by providing a comma-separated list: Class1.java,Class2.java,Class3.java
# public static final String VERSION = "GRADLETOKEN_VERSION";
Binary file not shown.
Vendored
+1 -1
View File
@@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -119,11 +119,9 @@ public class RedirectorTransformer implements IClassTransformer {
changed = true;
}
} else if (node.getOpcode() == Opcodes.INVOKESTATIC && node instanceof MethodInsnNode mNode) {
if (redirectedMethods.contains(mNode.name) && mNode.owner.equals(RenderStateClass)) {
mNode.name = mNode.name + "Static";
changed = true;
} else if (redirectedSimpleMethods.contains(mNode.name) && mNode.owner.equals(RenderStateClass)) {
} else if (node instanceof MethodInsnNode mNode) {
if (node.getOpcode() == Opcodes.INVOKESTATIC && redirectedSimpleMethods.contains(mNode.name)
&& mNode.owner.equals(RenderStateClass)) {
mn.instructions.insertBefore(
mNode,
new MethodInsnNode(
@@ -132,8 +130,15 @@ public class RedirectorTransformer implements IClassTransformer {
"instance",
"()Lcodechicken/lib/render/CCRenderState;"));
mNode.setOpcode(Opcodes.INVOKEVIRTUAL);
mNode.name = mNode.name + "Instance";
changed = true;
}
} else if (node.getOpcode() == Opcodes.INVOKEVIRTUAL && mNode.owner.equals(RenderStateClass)
&& (redirectedSimpleMethods.contains(mNode.name)
|| redirectedMethods.contains(mNode.name))) {
// Handle mods that updated to previously new API
mNode.name = mNode.name + "Instance";
changed = true;
}
}
}
}
@@ -6,8 +6,10 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.TreeMap;
public abstract class ConfigTagParent {
@@ -21,25 +23,30 @@ public abstract class ConfigTagParent {
}
public int compare(ConfigTag o1, ConfigTag o2) {
if (o1.position != o2.position) return compareInt(o1.position, o2.position);
if (o1.position != o2.position) return Integer.compare(o1.position, o2.position);
if (o1.brace != o2.brace) return o1.brace ? 1 : -1; // braced one goes after
switch (sortMode) {
case 1:
if (o1.value == o2.value) return 0;
if (o1.value == null) return 1;
if (o2.value == null) return -1;
return o1.value.compareTo(o2.value);
default:
return o1.name.compareTo(o2.name);
if (sortMode == 1) {
if (Objects.equals(o1.value, o2.value)) return 0;
if (o1.value == null) return 1;
if (o2.value == null) return -1;
return o1.value.compareTo(o2.value);
} else {
return o1.name.compareTo(o2.name);
}
}
private int compareInt(int a, int b) {
return a == b ? 0 : a < b ? -1 : 1;
}
}
private TreeMap<String, ConfigTag> childtags = new TreeMap<String, ConfigTag>();
/**
* The immediate child tags of this tag
*/
private final TreeMap<String, ConfigTag> childtags = new TreeMap<>();
/**
* A map of all tags in the tree, meaning all tags in this tag and all tags in child tags (recursively). Allows for
* quick access to any tag in the tree, without the need to traverse the tree part by part.
*/
private final Map<String, ConfigTag> allTagsInTree = new HashMap<>();
public String comment;
/**
* 0 = name, 1 = value
@@ -88,7 +95,7 @@ public abstract class ConfigTagParent {
}
public boolean containsTag(String tagname) {
return getTag(tagname, false) != null;
return allTagsInTree.get(tagname) != null;
}
public ConfigTag getNewTag(String tagname) {
@@ -96,6 +103,12 @@ public abstract class ConfigTagParent {
}
public ConfigTag getTag(String tagname, boolean create) {
ConfigTag tag = allTagsInTree.get(tagname);
if (tag == null && create) return getTagRecursive(tagname, create);
return tag;
}
public ConfigTag getTagRecursive(String tagname, boolean create) {
int dotpos = tagname.indexOf(".");
String basetagname = dotpos == -1 ? tagname : tagname.substring(0, dotpos);
ConfigTag basetag = childtags.get(basetagname);
@@ -115,6 +128,8 @@ public abstract class ConfigTagParent {
}
public boolean removeTag(String tagname) {
removeChildFromFlatMap(tagname);
ConfigTag tag = getTag(tagname, false);
if (tag == null) return false;
@@ -131,6 +146,22 @@ public abstract class ConfigTagParent {
public void addChild(ConfigTag tag) {
childtags.put(tag.name, tag);
addChildToFlatMap(tag.name, tag);
}
private void addChildToFlatMap(String path, ConfigTag tag) {
allTagsInTree.put(path, tag);
// Stupid cast but these two garbage classes are interlinked anyway
if ((this instanceof ConfigTag t) && t.parent != null) t.parent.addChildToFlatMap(t.name + "." + path, tag);
}
private void removeChildFromFlatMap(String path) {
allTagsInTree.remove(path);
// Stupid cast but these two garbage classes are interlinked anyway
if ((this instanceof ConfigTag t) && t.parent != null) t.parent.removeChildFromFlatMap(t.name + "." + path);
}
public <T extends ConfigTag> ArrayList<T> getSortedTagList() {
@@ -64,15 +64,15 @@ public class Canvas9Seg {
public void draw(CCRenderState state, int x, int y, int w, int h) {
CCRenderState.changeTexture(tex);
state.reset();
state.startDrawing();
state.resetInstance();
state.startDrawingInstance();
int[] sw = new int[] { x, x + seg_w[0], x + w - seg_w[2], x + w };
int[] sh = new int[] { y, y + seg_h[0], y + h - seg_h[2], y + h };
for (int seg = 0; seg < 9; seg++) drawSeg(sw, sh, seg);
state.draw();
state.drawInstance();
}
public void draw(int x, int y, int w, int h) {
@@ -128,8 +128,8 @@ public class LightMatrix implements CCRenderState.IVertexOperation {
float[] a = ao(lc.side);
float f = (a[0] * lc.fa + a[1] * lc.fb + a[2] * lc.fc + a[3] * lc.fd);
int[] b = brightness(lc.side);
state.setColour(ColourRGBA.multiplyC(state.colour, f));
state.setBrightness((int) (b[0] * lc.fa + b[1] * lc.fb + b[2] * lc.fc + b[3] * lc.fd) & 0xFF00FF);
state.setColourInstance(ColourRGBA.multiplyC(state.colour, f));
state.setBrightnessInstance((int) (b[0] * lc.fa + b[1] * lc.fb + b[2] * lc.fc + b[3] * lc.fd) & 0xFF00FF);
}
@Override
@@ -88,7 +88,7 @@ public class LightModel implements CCRenderState.IVertexOperation {
@Override
public void operate(CCRenderState state) {
state.setColour(apply(state.colour, state.normal));
state.setColourInstance(apply(state.colour, state.normal));
}
@Override
@@ -47,7 +47,7 @@ public class PlanarLightMatrix extends PlanarLightModel {
@Override
public void operate(CCRenderState state) {
super.operate(state);
state.setBrightness(brightness(state.side));
state.setBrightnessInstance(brightness(state.side));
}
@Override
@@ -27,7 +27,7 @@ public class PlanarLightModel implements CCRenderState.IVertexOperation {
@Override
public void operate(CCRenderState state) {
state.setColour(ColourRGBA.multiply(state.colour, colours[state.side]));
state.setColourInstance(ColourRGBA.multiply(state.colour, colours[state.side]));
}
@Override
@@ -46,7 +46,7 @@ public class SimpleBrightnessModel implements CCRenderState.IVertexOperation {
@Override
public void operate(CCRenderState state) {
state.setBrightness(sample(state.side));
state.setBrightnessInstance(sample(state.side));
}
@Override
@@ -154,7 +154,7 @@ public class BlockRenderer {
// public static void renderFullBlock(int sideMask) {
public static void renderFullBlock(CCRenderState state, int sideMask) {
state.setModel(fullBlock);
state.setModelInstance(fullBlock);
renderFaces(state, sideMask);
}
@@ -171,8 +171,8 @@ public class BlockRenderer {
public static void renderFaces(CCRenderState state, int sideMask) {
if (sideMask == 0x3F) return;
for (int s = 0; s < 6; s++) if ((sideMask & 1 << s) == 0) {
state.setVertexRange(s * 4, (s + 1) * 4);
state.render();
state.setVertexRangeInstance(s * 4, (s + 1) * 4);
state.renderInstance();
}
}
@@ -191,10 +191,10 @@ public class BlockRenderer {
public static void renderCuboid(CCRenderState state, Cuboid6 bounds, int sideMask) {
if (sideMask == 0x3F) return;
state.setModel(face);
state.setModelInstance(face);
for (int s = 0; s < 6; s++) if ((sideMask & 1 << s) == 0) {
face.loadCuboidFace(bounds, s);
state.render();
state.renderInstance();
}
}
@@ -467,8 +467,8 @@ public class CCModel implements CCRenderState.IVertexSource, Copyable<CCModel> {
* @param ops Operations to apply
*/
public void render(CCRenderState state, int start, int end, CCRenderState.IVertexOperation... ops) {
state.setPipeline(this, start, end, ops);
state.render();
state.setPipelineInstance(this, start, end, ops);
state.renderInstance();
}
public void render(int start, int end, CCRenderState.IVertexOperation... ops) {
@@ -49,7 +49,7 @@ public class CCRenderPipeline {
public void render() {
rebuild();
renderState.render();
renderState.renderInstance();
}
}
@@ -101,7 +101,7 @@ public class CCRenderState {
/**
* Management class for a vertex attrute such as colour, normal etc This class should handle the loading of the
* attrute from an array provided by IVertexSource.getAttributes or the computation of this attrute from others
*
*
* @param <T> The array type for this attrute eg. int[], Vector3[]
*/
public abstract static class VertexAttribute<T> implements IVertexOperation {
@@ -146,7 +146,7 @@ public class CCRenderState {
/**
* Gets an array of vertex attrutes
*
*
* @param attr The vertex attrute to get
* @param <T> The attrute array type
* @return An array, or null if not computed
@@ -193,8 +193,8 @@ public class CCRenderState {
@Override
public void operate(CCRenderState state) {
if (normalRef != null) state.setNormal(normalRef[state.vertexIndex]);
else state.setNormal(Rotation.axes[state.side]);
if (normalRef != null) state.setNormalInstance(normalRef[state.vertexIndex]);
else state.setNormalInstance(Rotation.axes[state.side]);
}
};
public static VertexAttribute<int[]> colourAttrib = new VertexAttribute<>() {
@@ -214,8 +214,9 @@ public class CCRenderState {
@Override
public void operate(CCRenderState state) {
if (colourRef != null) state.setColour(ColourRGBA.multiply(state.baseColour, colourRef[state.vertexIndex]));
else state.setColour(state.baseColour);
if (colourRef != null)
state.setColourInstance(ColourRGBA.multiply(state.baseColour, colourRef[state.vertexIndex]));
else state.setColourInstance(state.baseColour);
}
};
public static VertexAttribute<int[]> lightingAttrib = new VertexAttribute<>() {
@@ -241,7 +242,7 @@ public class CCRenderState {
@Override
public void operate(CCRenderState state) {
state.setColour(ColourRGBA.multiply(state.colour, colourRef[state.vertexIndex]));
state.setColourInstance(ColourRGBA.multiply(state.colour, colourRef[state.vertexIndex]));
}
};
public static VertexAttribute<int[]> sideAttrib = new VertexAttribute<>() {
@@ -326,11 +327,15 @@ public class CCRenderState {
public boolean hasBrightness;
public int brightness;
// attrute storage
// attribute storage
public int side;
public LC lc = new LC();
public void reset() {
public static void reset() {
instance().resetInstance();
}
public void resetInstance() {
model = null;
pipeline.reset();
useNormals = hasNormal = hasBrightness = hasColour = false;
@@ -338,27 +343,27 @@ public class CCRenderState {
baseColour = alphaOverride = -1;
}
public void setPipeline(IVertexOperation... ops) {
public void setPipelineInstance(IVertexOperation... ops) {
pipeline.setPipeline(ops);
}
@Deprecated
public static void setPipelineStatic(IVertexOperation... ops) {
instance().setPipeline(ops);
public static void setPipeline(IVertexOperation... ops) {
instance().setPipelineInstance(ops);
}
public void setPipeline(IVertexSource model, int start, int end, IVertexOperation... ops) {
public void setPipelineInstance(IVertexSource model, int start, int end, IVertexOperation... ops) {
pipeline.reset();
setModel(model, start, end);
setModelInstance(model, start, end);
pipeline.setPipeline(ops);
}
@Deprecated
public static void setPipelineStatic(IVertexSource model, int start, int end, IVertexOperation... ops) {
instance().setPipeline(model, start, end, ops);
public static void setPipeline(IVertexSource model, int start, int end, IVertexOperation... ops) {
instance().setPipelineInstance(model, start, end, ops);
}
public void bindModel(IVertexSource model) {
public void bindModelInstance(IVertexSource model) {
if (this.model != model) {
this.model = model;
pipeline.rebuild();
@@ -366,74 +371,74 @@ public class CCRenderState {
}
@Deprecated
public static void bindModelStatic(IVertexSource model) {
instance().bindModel(model);
public static void bindModel(IVertexSource model) {
instance().bindModelInstance(model);
}
public void setModel(IVertexSource source) {
setModel(source, 0, source.getVertices().length);
public void setModelInstance(IVertexSource source) {
setModelInstance(source, 0, source.getVertices().length);
}
@Deprecated
public static void setModelStatic(IVertexSource source) {
instance().setModel(source);
public static void setModel(IVertexSource source) {
instance().setModelInstance(source);
}
public void setModel(IVertexSource source, int start, int end) {
bindModel(source);
setVertexRange(start, end);
public void setModelInstance(IVertexSource source, int start, int end) {
bindModelInstance(source);
setVertexRangeInstance(start, end);
}
@Deprecated
public static void setModelStatic(IVertexSource source, int start, int end) {
instance().setModel(source, start, end);
public static void setModel(IVertexSource source, int start, int end) {
instance().setModelInstance(source, start, end);
}
public void setVertexRange(int start, int end) {
public void setVertexRangeInstance(int start, int end) {
firstVertexIndex = start;
lastVertexIndex = end;
}
@Deprecated
public static void setVertexRangeStatic(int start, int end) {
instance().setVertexRange(start, end);
public static void setVertexRange(int start, int end) {
instance().setVertexRangeInstance(start, end);
}
public void render(IVertexOperation... ops) {
setPipeline(ops);
render();
public void renderInstance(IVertexOperation... ops) {
setPipelineInstance(ops);
renderInstance();
}
@Deprecated
public static void renderStatic(IVertexOperation... ops) {
instance().render(ops);
public static void render(IVertexOperation... ops) {
instance().renderInstance(ops);
}
public void render() {
public void renderInstance() {
Vertex5[] verts = model.getVertices();
for (vertexIndex = firstVertexIndex; vertexIndex < lastVertexIndex; vertexIndex++) {
model.prepareVertex(this);
vert.set(verts[vertexIndex]);
runPipeline();
writeVert();
runPipelineInstance();
writeVertInstance();
}
}
@Deprecated
public static void renderStatic() {
instance().render();
public static void render() {
instance().renderInstance();
}
public void runPipeline() {
public void runPipelineInstance() {
pipeline.operate();
}
@Deprecated
public static void runPipelineStatic() {
instance().runPipeline();
public static void runPipeline() {
instance().runPipelineInstance();
}
public void writeVert() {
public void writeVertInstance() {
if (hasNormal) Tessellator.instance.setNormal((float) normal.x, (float) normal.y, (float) normal.z);
if (hasColour) Tessellator.instance.setColorRGBA(
colour >>> 24,
@@ -445,71 +450,83 @@ public class CCRenderState {
}
@Deprecated
public static void writeVertStatic() {
instance().writeVert();
public static void writeVert() {
instance().writeVertInstance();
}
public void setNormal(double x, double y, double z) {
public void setNormalInstance(double x, double y, double z) {
hasNormal = true;
normal.set(x, y, z);
}
@Deprecated
public static void setNormalStatic(double x, double y, double z) {
instance().setNormal(x, y, z);
public static void setNormal(double x, double y, double z) {
instance().setNormalInstance(x, y, z);
}
public void setNormal(Vector3 n) {
public void setNormalInstance(Vector3 n) {
hasNormal = true;
normal.set(n);
}
@Deprecated
public static void setNormalStatic(Vector3 n) {
instance().setNormal(n);
public static void setNormal(Vector3 n) {
instance().setNormalInstance(n);
}
public void setColour(int c) {
public void setColourInstance(int c) {
hasColour = true;
colour = c;
}
@Deprecated
public static void setColourStatic(int c) {
instance().setColour(c);
public static void setColour(int c) {
instance().setColourInstance(c);
}
public void setBrightness(int b) {
public void setBrightnessInstance(int b) {
hasBrightness = true;
brightness = b;
}
@Deprecated
public static void setBrightnessStatic(int b) {
instance().setBrightness(b);
public static void setBrightness(int b) {
instance().setBrightnessInstance(b);
}
public void setBrightness(IBlockAccess world, int x, int y, int z) {
setBrightness(world.getBlock(x, y, z).getMixedBrightnessForBlock(world, x, y, z));
public void setBrightnessInstance(IBlockAccess world, int x, int y, int z) {
setBrightnessInstance(world.getBlock(x, y, z).getMixedBrightnessForBlock(world, x, y, z));
}
@Deprecated
public static void setBrightnessStatic(IBlockAccess world, int x, int y, int z) {
instance().setBrightness(world, x, y, z);
public static void setBrightness(IBlockAccess world, int x, int y, int z) {
instance().setBrightnessInstance(world, x, y, z);
}
public void pullLightmap() {
setBrightness((int) OpenGlHelper.lastBrightnessY << 16 | (int) OpenGlHelper.lastBrightnessX);
public static void pullLightmap() {
instance().pullLightmapInstance();
}
public void pushLightmap() {
public void pullLightmapInstance() {
setBrightnessInstance((int) OpenGlHelper.lastBrightnessY << 16 | (int) OpenGlHelper.lastBrightnessX);
}
public static void pushLightmap() {
instance().pushLightmapInstance();
}
public void pushLightmapInstance() {
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, brightness & 0xFFFF, brightness >>> 16);
}
/**
* Compact helper for setting dynamic rendering context. Uses normals and doesn't compute lighting
*/
public void setDynamic() {
public static void setDynamic() {
instance().setDynamicInstance();
}
public void setDynamicInstance() {
useNormals = true;
computeLighting = false;
}
@@ -522,16 +539,16 @@ public class CCRenderState {
Minecraft.getMinecraft().renderEngine.bindTexture(texture);
}
public void startDrawing() {
startDrawing(7);
public void startDrawingInstance() {
startDrawingInstance(7);
}
@Deprecated
public static void startDrawingStatic() {
instance().startDrawing();
public static void startDrawing() {
instance().startDrawingInstance();
}
public void startDrawing(int mode) {
public void startDrawingInstance(int mode) {
Tessellator.instance.startDrawing(mode);
if (hasColour) Tessellator.instance.setColorRGBA(
colour >>> 24,
@@ -542,11 +559,15 @@ public class CCRenderState {
}
@Deprecated
public static void startDrawingStatic(int mode) {
instance().startDrawing(mode);
public static void startDrawing(int mode) {
instance().startDrawingInstance(mode);
}
public void draw() {
public static void draw() {
Tessellator.instance.draw();
}
public void drawInstance() {
Tessellator.instance.draw();
}
}
@@ -23,7 +23,7 @@ public class ColourMultiplier implements CCRenderState.IVertexOperation {
@Override
public boolean load(CCRenderState state) {
if (colour == -1) {
state.setColour(-1);
state.setColourInstance(-1);
return false;
}
@@ -33,7 +33,7 @@ public class ColourMultiplier implements CCRenderState.IVertexOperation {
@Override
public void operate(CCRenderState state) {
state.setColour(ColourRGBA.multiply(state.colour, colour));
state.setColourInstance(ColourRGBA.multiply(state.colour, colour));
}
@Override
@@ -259,7 +259,7 @@ public class RenderUtils {
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Fluid fluid = stack.getFluid();
state.setColour(fluid.getColor(stack) << 8 | alpha);
state.setColourInstance(fluid.getColor(stack) << 8 | alpha);
TextureUtils.bindAtlas(fluid.getSpriteNumber());
return TextureUtils.safeIcon(fluid.getIcon(stack));
}
@@ -300,9 +300,9 @@ public class RenderUtils {
else bound.max.y = bound.min.y + (bound.max.y - bound.min.y) * density;
IIcon tex = prepareFluidRender(state, stack, alpha);
state.startDrawing();
state.startDrawingInstance();
renderFluidCuboid(state, bound, tex, res);
state.draw();
state.drawInstance();
postFluidRender();
}
@@ -323,14 +323,14 @@ public class RenderUtils {
}
IIcon tex = prepareFluidRender(state, stack, alpha);
state.startDrawing();
state.startDrawingInstance();
renderFluidQuad(
new Vector3(rect.x, rect.y + rect.h, 0),
new Vector3(rect.w, 0, 0),
new Vector3(0, -rect.h, 0),
tex,
res);
state.draw();
state.drawInstance();
postFluidRender();
}