Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to 1.8.9 (legacyfabric) #7

Open
wants to merge 4 commits into
base: 1.19
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version = "${project.mod_version}+${getMCVersionString()}"
group = project.maven_group

// This field defines the Java version your mod target.
def targetJavaVersion = 17
def targetJavaVersion = 8

boolean isMCVersionNonRelease() {
return project.minecraft_version.matches('^\\d\\dw\\d\\d[a-z]$')
Expand All @@ -26,14 +26,32 @@ String getMCVersionString() {
return version[0] + '.' + version[1]
}

repositories {
maven {
name = "legacy-fabric"
url = "https://maven.legacyfabric.net"
}
maven { url 'https://jitpack.io' }
mavenCentral()
}

loom {
setIntermediaryUrl('https://maven.legacyfabric.net/net/fabricmc/intermediary/%1$s/intermediary-%1$s-v2.jar')
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings(loom.layered {
addLayer(quiltMappings.mappings("org.quiltmc:quilt-mappings:${minecraft_version}+build.${quilt_mappings}:v2"))
})
mappings "net.legacyfabric:yarn:${project.minecraft_version}+build.${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

modImplementation fabricApi.module('fabric-resource-loader-v0', project.fabric_api_version)
modImplementation ("net.legacyfabric.legacy-fabric-api:legacy-fabric-api:${fabric_api_version}") {
exclude module: "legacy-fabric-entity-events-v1"
}

modImplementation include("com.github.moehreag:search-in-resources:1.0.2")

implementation include('it.unimi.dsi:fastutil:8.5.8') // 1.8.9 does not use fastutil by default
implementation('org.apache.logging.log4j:log4j-core:2.19.0')
}

java {
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
org.gradle.jvmargs = -Xmx1G

#Fabric properties
minecraft_version = 1.19
quilt_mappings = 1
loader_version = 0.12.12
minecraft_version = 1.8.9
yarn_mappings = 412
loader_version = 0.14.9

#Mod properties
mod_version = 1.2.0
maven_group = io.github.queerbric
archives_base_name = pridelib

#Dependencies
fabric_api_version = 0.41.0+1.17
fabric_api_version = 1.8.0+1.8.9
5 changes: 2 additions & 3 deletions src/main/java/io/github/queerbric/pride/PrideClient.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package io.github.queerbric.pride;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.minecraft.resource.ResourceType;
import net.legacyfabric.fabric.api.resource.ResourceManagerHelper;

public class PrideClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new PrideLoader());
ResourceManagerHelper.getInstance().registerReloadListener(new PrideLoader());
}
}
20 changes: 13 additions & 7 deletions src/main/java/io/github/queerbric/pride/PrideFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import it.unimi.dsi.fastutil.ints.IntLists;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;

/**
Expand All @@ -20,16 +19,16 @@ protected PrideFlag(String id, Properties props) {
if (props.shape == null) {
this.shapeId = new Identifier("pride", "horizontal_stripes");
} else {
this.shapeId = props.shape.contains(":") ? Identifier.tryParse(props.shape) : new Identifier("pride", props.shape);
this.shapeId = parseIdentifier(props.shape);
}

this.shape = PrideFlagShapes.get(this.shapeId);
if (this.shape == null) {
throw new IllegalArgumentException("Unknown pride flag shape " + this.shapeId);
}

var colorsTmp = new IntArrayList(props.colors.length);
for (var color : props.colors) {
IntArrayList colorsTmp = new IntArrayList(props.colors.length);
for (String color : props.colors) {
colorsTmp.add(Integer.parseInt(color.substring(1), 16) | 0xFF000000);
}
this.colors = IntLists.unmodifiable(colorsTmp);
Expand All @@ -54,14 +53,21 @@ public IntList getColors() {
/**
* Renders this flag at the specified coordinates and with the specified dimensions.
*
* @param matrices the matrix stack
* @param x the X-coordinate to render to
* @param y the Y-coordinate to render to
* @param width the render width of the flag
* @param height the render height of the flag
*/
public void render(MatrixStack matrices, float x, float y, float width, float height) {
this.shape.render(this.colors, matrices, x, y, width, height);
public void render(float x, float y, float width, float height) {
this.shape.render(this.colors, x, y, width, height);
}

private Identifier parseIdentifier(String s){
if(s.contains(":")){
String[] array = s.split(":",1);
return new Identifier(array[0], array[1]);
}
return new Identifier("pride", s);
}

static class Properties {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/github/queerbric/pride/PrideFlagShape.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.github.queerbric.pride;

import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.client.util.math.MatrixStack;

public interface PrideFlagShape {
void render(IntList colors, MatrixStack matrices, float x, float y, float width, float height);
void render(IntList colors, float x, float y, float width, float height);
}
125 changes: 59 additions & 66 deletions src/main/java/io/github/queerbric/pride/PrideFlagShapes.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package io.github.queerbric.pride;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.Tessellator;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.blaze3d.vertex.VertexFormats;
import com.mojang.blaze3d.platform.GlStateManager;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Matrix4f;

import java.util.Map;

Expand All @@ -29,67 +27,64 @@ private PrideFlagShapes() {

static {
PrideFlagShape horizStripes;
register(new Identifier("pride", "horizontal_stripes"), horizStripes = (colors, matrices, x, y, w, h) -> {
register(new Identifier("pride", "horizontal_stripes"), horizStripes = (colors, x, y, w, h) -> {
float sh = h / colors.size();
RenderSystem.disableTexture();
Matrix4f mat = matrices.peek().getPosition();
GlStateManager.disableTexture();
Tessellator t = Tessellator.getInstance();
BufferBuilder bb = t.getBufferBuilder();
bb.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
BufferBuilder bb = t.getBuffer();
bb.begin(7, VertexFormats.POSITION_COLOR);
for (int i = 0; i < colors.size(); i++) {
int color = colors.getInt(i);
float r = ((color >> 16) & 0xFF) / 255f;
float g = ((color >> 8) & 0xFF) / 255f;
float b = ((color >> 0) & 0xFF) / 255f;
bb.vertex(mat, x, y + sh, 0).color(r, g, b, 1).next();
bb.vertex(mat, x + w, y + sh, 0).color(r, g, b, 1).next();
bb.vertex(mat, x + w, y, 0).color(r, g, b, 1).next();
bb.vertex(mat, x, y, 0).color(r, g, b, 1).next();
float b = ((color) & 0xFF) / 255f;
bb.vertex(x, y + sh, 0).color(r, g, b, 1).next();
bb.vertex(x + w, y + sh, 0).color(r, g, b, 1).next();
bb.vertex(x + w, y, 0).color(r, g, b, 1).next();
bb.vertex(x, y, 0).color(r, g, b, 1).next();
y += sh;
}
t.draw();
// Mojang when will you use your state manager system to add fast pushAttrib/popAttrib
RenderSystem.enableTexture();
GlStateManager.enableTexture();
});
register(new Identifier("pride", "vertical_stripes"), (colors, matrices, x, y, w, h) -> {
register(new Identifier("pride", "vertical_stripes"), (colors, x, y, w, h) -> {
float sw = w / colors.size();
RenderSystem.disableTexture();
Matrix4f mat = matrices.peek().getPosition();
GlStateManager.disableTexture();
Tessellator t = Tessellator.getInstance();
BufferBuilder bb = t.getBufferBuilder();
bb.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
BufferBuilder bb = t.getBuffer();
bb.begin(7, VertexFormats.POSITION_COLOR);
for (int i = 0; i < colors.size(); i++) {
int color = colors.getInt(i);
float r = ((color >> 16) & 0xFF) / 255f;
float g = ((color >> 8) & 0xFF) / 255f;
float b = ((color >> 0) & 0xFF) / 255f;
bb.vertex(mat, x, y + h, 0).color(r, g, b, 1).next();
bb.vertex(mat, x + sw, y + h, 0).color(r, g, b, 1).next();
bb.vertex(mat, x + sw, y, 0).color(r, g, b, 1).next();
bb.vertex(mat, x, y, 0).color(r, g, b, 1).next();
float b = ((color) & 0xFF) / 255f;
bb.vertex(x, y + h, 0).color(r, g, b, 1).next();
bb.vertex(x + sw, y + h, 0).color(r, g, b, 1).next();
bb.vertex(x + sw, y, 0).color(r, g, b, 1).next();
bb.vertex(x, y, 0).color(r, g, b, 1).next();
x += sw;
}
t.draw();
RenderSystem.enableTexture();
GlStateManager.enableTexture();
});
register(new Identifier("pride", "circle"), (colors, matrices, x, y, w, h) -> {
RenderSystem.disableTexture();
Matrix4f mat = matrices.peek().getPosition();
register(new Identifier("pride", "circle"), (colors, x, y, w, h) -> {
GlStateManager.disableTexture();
Tessellator tess = Tessellator.getInstance();
BufferBuilder bb = tess.getBufferBuilder();
BufferBuilder bb = tess.getBuffer();
{
int color = colors.getInt(0);
float r = ((color >> 16) & 0xFF) / 255f;
float g = ((color >> 8) & 0xFF) / 255f;
float b = ((color >> 0) & 0xFF) / 255f;
bb.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bb.vertex(mat, x, y + h, 0).color(r, g, b, 1).next();
bb.vertex(mat, x + w, y + h, 0).color(r, g, b, 1).next();
bb.vertex(mat, x + w, y, 0).color(r, g, b, 1).next();
bb.vertex(mat, x, y, 0).color(r, g, b, 1).next();
float b = ((color) & 0xFF) / 255f;
bb.begin(7, VertexFormats.POSITION_COLOR);
bb.vertex(x, y + h, 0).color(r, g, b, 1).next();
bb.vertex(x + w, y + h, 0).color(r, g, b, 1).next();
bb.vertex(x + w, y, 0).color(r, g, b, 1).next();
bb.vertex(x, y, 0).color(r, g, b, 1).next();
tess.draw();
}
bb.begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR);
bb.begin(6, VertexFormats.POSITION_COLOR); // Seems like the int-pendant to TRIANGLE_FAN is 6.
float br = Math.min(w, h) * 0.3f;
float cx = x + (w / 2);
float cy = y + (h / 2);
Expand All @@ -98,54 +93,52 @@ private PrideFlagShapes() {
int color = (p == 0 ? colors.getInt(1) : colors.getInt(0));
float r = ((color >> 16) & 0xFF) / 255f;
float g = ((color >> 8) & 0xFF) / 255f;
float b = ((color >> 0) & 0xFF) / 255f;
bb.vertex(mat, cx, cy, 0).color(r, g, b, 1).next();
float b = ((color) & 0xFF) / 255f;
bb.vertex(cx, cy, 0).color(r, g, b, 1).next();
for (int i = 0; i < 65; i++) {
float t = (i / 64f);
final float TAU = (float) (Math.PI * 2);
bb.vertex(mat, cx + (MathHelper.sin(t * TAU) * rd), cy + (MathHelper.cos(t * TAU) * rd), 0).color(r, g, b, 1).next();
bb.vertex(cx + (MathHelper.sin(t * TAU) * rd), cy + (MathHelper.cos(t * TAU) * rd), 0).color(r, g, b, 1).next();
}
}
tess.draw();
RenderSystem.enableTexture();
GlStateManager.enableTexture();
});
register(new Identifier("pride", "arrow"), (colors, matrices, x, y, w, h) -> {
register(new Identifier("pride", "arrow"), (colors, x, y, w, h) -> {
float s = Math.min(w, h) / 2;
float cy = y + (h / 2);
horizStripes.render(colors.subList(1, colors.size()), matrices, x, y, w, h);
RenderSystem.disableTexture();
Matrix4f mat = matrices.peek().getPosition();
horizStripes.render(colors.subList(1, colors.size()), x, y, w, h);
GlStateManager.disableTexture();
Tessellator t = Tessellator.getInstance();
BufferBuilder bb = t.getBufferBuilder();
bb.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR);
BufferBuilder bb = t.getBuffer();
bb.begin(4, VertexFormats.POSITION_COLOR); // Int-pendant to TRIANGLE is 4.
int color = colors.getInt(0);
float r = ((color >> 16) & 0xFF) / 255f;
float g = ((color >> 8) & 0xFF) / 255f;
float b = ((color >> 0) & 0xFF) / 255f;
bb.vertex(mat, x, cy + s, 0).color(r, g, b, 1).next();
float b = ((color) & 0xFF) / 255f;
bb.vertex(x, cy + s, 0).color(r, g, b, 1).next();
// yes, 1.5. the demisexual flag triangle appears to not be equilateral?
bb.vertex(mat, x + (s * 1.5f), cy, 0).color(r, g, b, 1).next();
bb.vertex(mat, x, cy - s, 0).color(r, g, b, 1).next();
bb.vertex(x + (s * 1.5f), cy, 0).color(r, g, b, 1).next();
bb.vertex(x, cy - s, 0).color(r, g, b, 1).next();
t.draw();
RenderSystem.enableTexture();
GlStateManager.enableTexture();
});
var progressBg = new IntArrayList(new int[]{
IntArrayList progressBg = new IntArrayList(new int[]{
0xD40606,
0xEE9C00,
0xE3FF00,
0x06BF00,
0x001A98,
0x760089,
});
register(new Identifier("pride", "progress"), (colors, matrices, x, y, w, h) -> {
register(new Identifier("pride", "progress"), (colors, x, y, w, h) -> {
float hm = Math.min(w, h) / 2;
float cy = y + (h / 2);
Matrix4f mat = matrices.peek().getPosition();
Tessellator t = Tessellator.getInstance();
BufferBuilder bb = t.getBufferBuilder();
horizStripes.render(progressBg, matrices, x, y, w, h);
RenderSystem.disableTexture();
bb.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR);
BufferBuilder bb = t.getBuffer();
horizStripes.render(progressBg, x, y, w, h);
GlStateManager.disableTexture();
bb.begin(4, VertexFormats.POSITION_COLOR);
int[] triangleColors = {
0x000000,
0x603813,
Expand All @@ -157,14 +150,14 @@ private PrideFlagShapes() {
for (int color : triangleColors) {
float r = ((color >> 16) & 0xFF) / 255f;
float g = ((color >> 8) & 0xFF) / 255f;
float b = ((color >> 0) & 0xFF) / 255f;
bb.vertex(mat, x, cy + s, 0).color(r, g, b, 1).next();
bb.vertex(mat, x + (s * 1.1f), cy, 0).color(r, g, b, 1).next();
bb.vertex(mat, x, cy - s, 0).color(r, g, b, 1).next();
float b = ((color) & 0xFF) / 255f;
bb.vertex(x, cy + s, 0).color(r, g, b, 1).next();
bb.vertex(x + (s * 1.1f), cy, 0).color(r, g, b, 1).next();
bb.vertex(x, cy - s, 0).color(r, g, b, 1).next();
s -= hm / 6;
}
t.draw();
RenderSystem.enableTexture();
GlStateManager.enableTexture();
});
}
}
4 changes: 2 additions & 2 deletions src/main/java/io/github/queerbric/pride/PrideFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class PrideFlags {

protected static void setFlags(List<PrideFlag> flags) {
PrideFlags.flags = Collections.unmodifiableList(flags);
var flagsById = new Object2ObjectOpenHashMap<String, PrideFlag>(flags.size());
for (var flag : flags) {
Object2ObjectOpenHashMap<String, PrideFlag> flagsById = new Object2ObjectOpenHashMap<String, PrideFlag>(flags.size());
for (PrideFlag flag : flags) {
flagsById.put(flag.getId(), flag);
}
PrideFlags.flagsById = Collections.unmodifiableMap(flagsById);
Expand Down
Loading