diff --git a/build.gradle b/build.gradle index e1c4bd1..7ae6888 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,8 @@ plugins { - id 'fabric-loom' version '0.11-SNAPSHOT' + id 'fabric-loom' version '1.4.5' id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 - -archivesBaseName = project.archives_base_name version = project.mod_version group = project.maven_group @@ -30,31 +26,35 @@ dependencies { compileOnly 'com.google.code.findbugs:jsr305:+' } +base { + archivesName = project.archives_base_name +} + processResources { inputs.property "version", project.version filesMatching("fabric.mod.json") { expand "version": project.version } - - // from(sourceSets.main.resources.srcDirs) { - // exclude "fabric.mod.json" - // } } -// ensure that the encoding is set to UTF-8, no matter what the system default is -// this fixes some edge cases with special characters not displaying correctly -// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html -tasks.withType(JavaCompile) { - options.encoding = "UTF-8" +tasks.withType(JavaCompile).configureEach { + // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. + it.options.release = 17 + // ensure that the encoding is set to UTF-8, no matter what the system default is + // this fixes some edge cases with special characters not displaying correctly + // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html + it.options.encoding = "UTF-8" } -// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task -// if it is present. -// If you remove this task, sources will not be generated. -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = "sources" - from sourceSets.main.allSource +java { + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() + + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } jar { @@ -74,10 +74,4 @@ publishing { } } } - - // select the repositories you want to publish to - repositories { - // uncomment to publish to the local maven - // mavenLocal() - } -} +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 7bb54f7..02e51de 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,20 +2,17 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties - # check these on https://fabricmc.net/use - minecraft_version=1.19.3 - yarn_mappings=1.19.3+build.5 - loader_version=0.14.13 - +# check these on https://fabricmc.net/use +minecraft_version=1.21.4 +yarn_mappings=1.21.4+build.8 +loader_version=0.16.10 # Mod Properties - mod_version = 1.2.6 - maven_group = net.entityoutliner - archives_base_name = entity-outliner - - +mod_version = 1.2.6_1.21.4 +maven_group = net.entityoutliner +archives_base_name = entity-outliner # Dependencies - # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api - fabric_version=0.73.0+1.19.3 - modmenu_version=5.0.2 +# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api +fabric_version=0.91.1+1.20.4 +modmenu_version=9.0.0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 84d1f85..a595206 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/net/entityoutliner/ui/ColorWidget.java b/src/main/java/net/entityoutliner/ui/ColorWidget.java index 6652977..6ff6f57 100644 --- a/src/main/java/net/entityoutliner/ui/ColorWidget.java +++ b/src/main/java/net/entityoutliner/ui/ColorWidget.java @@ -2,15 +2,13 @@ import java.util.Map; -import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; - import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.gui.widget.PressableWidget; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.render.RenderLayer; import net.minecraft.entity.EntityType; import net.minecraft.entity.SpawnGroup; import net.minecraft.text.Text; @@ -18,9 +16,9 @@ @Environment(EnvType.CLIENT) public class ColorWidget extends PressableWidget { - private static final Identifier TEXTURE = new Identifier("entityoutliner:textures/gui/colors.png"); + private static final Identifier TEXTURE = Identifier.of("entityoutliner:textures/gui/colors.png"); private Color color; - private EntityType entityType; + private final EntityType entityType; private ColorWidget(int x, int y, int width, int height, Text message, EntityType entityType) { super(x, y, width, height, message); @@ -38,21 +36,18 @@ public void onShow() { this.color = EntitySelector.outlinedEntityTypes.get(this.entityType); } + @Override public void onPress() { this.color = this.color.next(); EntitySelector.outlinedEntityTypes.put(this.entityType, this.color); } - public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) { - MinecraftClient minecraftClient = MinecraftClient.getInstance(); - RenderSystem.setShaderTexture(0, TEXTURE); - RenderSystem.enableDepthTest(); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha); + @Override + protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) { + //context.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha); RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA); - drawTexture(matrices, this.getX(), this.getY(), this.isFocused() ? 20.0F : 0.0F, this.color.ordinal() * 20, 20, 20, 40, 180); - this.renderBackground(matrices, minecraftClient, mouseX, mouseY); + RenderSystem.enableDepthTest(); + context.drawTexture(RenderLayer::getGuiTexturedOverlay, TEXTURE, this.getX(), this.getY(), this.isFocused() ? 20.0F : 0.0F, this.color.ordinal() * 20, 20, 20, 40, 180); } public enum Color { @@ -66,9 +61,9 @@ public enum Color { PURPLE(127, 0, 127), PINK(255, 155, 182); - public int red; - public int green; - public int blue; + public final int red; + public final int green; + public final int blue; private static final Map spawnGroupColors = Map.of( SpawnGroup.AMBIENT, Color.PURPLE, @@ -81,9 +76,9 @@ public enum Color { SpawnGroup.WATER_CREATURE, Color.BLUE ); - private static Color[] colors = Color.values(); + private final static Color[] colors = Color.values(); - private Color(int red, int green, int blue) { + Color(int red, int green, int blue) { this.red = red; this.green = green; this.blue = blue; diff --git a/src/main/java/net/entityoutliner/ui/EntityListWidget.java b/src/main/java/net/entityoutliner/ui/EntityListWidget.java index 9a8d31e..0996de6 100644 --- a/src/main/java/net/entityoutliner/ui/EntityListWidget.java +++ b/src/main/java/net/entityoutliner/ui/EntityListWidget.java @@ -10,13 +10,12 @@ import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.Selectable; import net.minecraft.client.gui.widget.CheckboxWidget; import net.minecraft.client.gui.widget.ElementListWidget; import net.minecraft.client.gui.widget.PressableWidget; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.gui.DrawContext; import net.minecraft.entity.EntityType; import net.minecraft.entity.SpawnGroup; import net.minecraft.util.Language; @@ -24,8 +23,8 @@ @Environment(EnvType.CLIENT) public class EntityListWidget extends ElementListWidget { - public EntityListWidget(MinecraftClient client, int width, int height, int top, int bottom, int itemHeight) { - super(client, width, height, top, bottom, itemHeight); + public EntityListWidget(MinecraftClient client, int width, int height, int y, int itemHeight) { + super(client, width, height, y, itemHeight); this.centerListVertically = false; } @@ -37,12 +36,14 @@ public void clearListEntries() { super.clearEntries(); } + @Override public int getRowWidth() { return 400; } - protected int getScrollbarPositionX() { - return super.getScrollbarPositionX() + 32; + @Override + protected int getScrollbarX() { + return super.getScrollbarX() + 32; } @Environment(EnvType.CLIENT) @@ -62,28 +63,36 @@ private EntityEntry(CheckboxWidget checkbox, ColorWidget color, EntityType en this.color = color; this.children.add(checkbox); - if (EntitySelector.outlinedEntityTypes.containsKey(entityType)) + if (EntitySelector.outlinedEntityTypes.containsKey(entityType)) this.children.add(color); } - public static EntityListWidget.EntityEntry create(EntityType entityType, int width) { + public static EntityListWidget.EntityEntry create(EntityType entityType, int width, TextRenderer font) { + final CheckboxWidget checkbox = CheckboxWidget.builder(entityType.getName(), font) + .pos(width / 2 - 155, 0) + .checked(EntitySelector.outlinedEntityTypes.containsKey(entityType)) + .build(); + checkbox.setWidth(310); + checkbox.setHeight(20); return new EntityListWidget.EntityEntry( - new CheckboxWidget(width / 2 - 155, 0, 310, 20, entityType.getName(), EntitySelector.outlinedEntityTypes.containsKey(entityType)), + checkbox, new ColorWidget(width / 2 + 130, 0, 310, 20, entityType), entityType ); } - public void render(MatrixStack matrices, int i, int j, int k, int l, int m, int n, int o, boolean bl, float f) { - this.checkbox.setY(j); - this.checkbox.render(matrices, n, o, f); + @Override + public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + this.checkbox.setY(y); + this.checkbox.render(context, mouseX, mouseY, tickDelta); if (this.children.contains(this.color)) { - this.color.setY(j); - this.color.render(matrices, n, o, f); + this.color.setY(y); + this.color.render(context, mouseX, mouseY, tickDelta); } } + @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (EntitySelector.outlinedEntityTypes.containsKey(entityType)) { if (this.color.isMouseOver(mouseX, mouseY)) { @@ -105,18 +114,12 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { return true; } + @Override public List children() { return this.children; } - public EntityType getEntityType() { - return this.entityType; - } - - public CheckboxWidget getCheckbox() { - return this.checkbox; - } - + @Override public List selectableChildren() { return this.children; } @@ -136,11 +139,13 @@ private HeaderEntry(SpawnGroup category, TextRenderer font, int width, int heigh this.height = height; if (category != null) { - String title = ""; + StringBuilder title = new StringBuilder(); for (String term : category.getName().split("\\p{Punct}|\\p{Space}")) { - title += StringUtils.capitalize(term) + " "; + title.append(StringUtils.capitalize(term)); + title.append(' '); } - this.title = title.trim(); + title.deleteCharAt(title.length() - 1); + this.title = title.toString(); } else { this.title = Language.getInstance().get("gui.entity-outliner.no_results"); } @@ -151,14 +156,17 @@ public static EntityListWidget.HeaderEntry create(SpawnGroup category, TextRende return new EntityListWidget.HeaderEntry(category, font, width, height); } - public void render(MatrixStack matrices, int i, int j, int k, int l, int m, int n, int o, boolean bl, float f) { - DrawableHelper.drawCenteredText(matrices, this.font, this.title, this.width / 2, j + (this.height / 2) - (this.font.fontHeight / 2), 16777215); + @Override + public void render(DrawContext context, int i, int j, int k, int l, int m, int n, int o, boolean bl, float f) { + context.drawCenteredTextWithShadow(this.font, this.title, this.width / 2, j + (this.height / 2) - (this.font.fontHeight / 2), 16777215); } + @Override public List children() { return new ArrayList<>(); } + @Override public String toString() { return this.title; } diff --git a/src/main/java/net/entityoutliner/ui/EntitySelector.java b/src/main/java/net/entityoutliner/ui/EntitySelector.java index f6eb31a..3abad9c 100644 --- a/src/main/java/net/entityoutliner/ui/EntitySelector.java +++ b/src/main/java/net/entityoutliner/ui/EntitySelector.java @@ -4,18 +4,18 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; +import java.util.Map; import net.entityoutliner.EntityOutliner; import net.entityoutliner.ui.ColorWidget.Color; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.SpawnGroup; import net.minecraft.entity.EntityType; import net.minecraft.text.Text; -// import net.minecraft.util.registry.Registry; import net.minecraft.registry.Registries; public class EntitySelector extends Screen { @@ -23,33 +23,32 @@ public class EntitySelector extends Screen { private TextFieldWidget searchField; private EntityListWidget list; - public static boolean groupByCategory = true; + private static boolean groupByCategory = true; private static String searchText = ""; - public static HashMap>> searcher; // Prefix -> arr of results - public static HashMap, Color> outlinedEntityTypes = new HashMap<>(); + private static Map>> searcher = new HashMap<>(); // Prefix -> arr of results + public final static Map, Color> outlinedEntityTypes = new HashMap<>(); public EntitySelector(Screen parent) { super(Text.translatable("title.entity-outliner.selector")); this.parent = parent; + this.initializePrefixTree(); } - - public void onClose() { + + @Override + public void close() { this.client.setScreen(this.parent); } + @Override protected void init() { - if (searcher == null) { - initializePrefixTree(); - } - - this.list = new EntityListWidget(this.client, this.width, this.height, 32, this.height - 32, 25); - this.addSelectableChild(list); + this.list = new EntityListWidget(this.client, this.width, this.height - 64, 32, 25); + this.addDrawableChild(list); // Create search field this.searchField = new TextFieldWidget(this.textRenderer, this.width / 2 - 100, 6, 200, 20, Text.of(searchText)); this.searchField.setText(searchText); this.searchField.setChangedListener(this::onSearchFieldUpdate); - this.addSelectableChild(searchField); + this.addDrawableChild(searchField); // Create buttons int buttonWidth = 80; @@ -126,23 +125,18 @@ protected void init() { // Initializes the prefix tree used for searching in the entity selector screen private void initializePrefixTree() { - EntitySelector.searcher = new HashMap<>(); + searcher = new HashMap<>(); // Initialize no-text results List> allResults = new ArrayList>(); - EntitySelector.searcher.put("", allResults); + searcher.put("", allResults); // Get sorted list of entity types List> entityTypes = new ArrayList<>(); for (EntityType entityType : Registries.ENTITY_TYPE) { entityTypes.add(entityType); } - entityTypes.sort(new Comparator>() { - @Override - public int compare(EntityType o1, EntityType o2) { - return o1.getName().getString().compareTo(o2.getName().getString()); - } - }); + entityTypes.sort(Comparator.comparing(o -> o.getName().getString())); // Add each entity type to everywhere it belongs in the prefix "tree" for (EntityType entityType : entityTypes) { @@ -164,11 +158,11 @@ public int compare(EntityType o1, EntityType o2) { // Get results for current prefix List> results; - if (EntitySelector.searcher.containsKey(prefix)) { - results = EntitySelector.searcher.get(prefix); + if (searcher.containsKey(prefix)) { + results = searcher.get(prefix); } else { results = new ArrayList>(); - EntitySelector.searcher.put(prefix, results); + searcher.put(prefix, results); } results.add(entityType); @@ -210,7 +204,7 @@ private void onSearchFieldUpdate(String text) { this.list.addListEntry(EntityListWidget.HeaderEntry.create(category, this.client.textRenderer, this.width, 25)); for (EntityType entityType : resultsByCategory.get(category)) { - this.list.addListEntry(EntityListWidget.EntityEntry.create(entityType, this.width)); + this.list.addListEntry(EntityListWidget.EntityEntry.create(entityType, this.width, this.client.textRenderer)); } } @@ -218,7 +212,7 @@ private void onSearchFieldUpdate(String text) { } else { for (EntityType entityType : results) { - this.list.addListEntry(EntityListWidget.EntityEntry.create(entityType, this.width)); + this.list.addListEntry(EntityListWidget.EntityEntry.create(entityType, this.width, this.client.textRenderer)); } } } else { // If there are no results, let the user know @@ -226,35 +220,22 @@ private void onSearchFieldUpdate(String text) { } // This prevents an overscroll when the user is already scrolled down and the results list is shortened - this.list.setScrollAmount(this.list.getScrollAmount()); + this.list.setScrollY(this.list.getScrollY()); } // Called when config screen is escaped + @Override public void removed() { EntityOutliner.saveConfig(); } - public void tick() { - this.searchField.tick(); - } - - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { - // Render dirt background - this.renderBackground(matrices); - - // Render scrolling list - this.list.render(matrices, mouseX, mouseY, delta); - - // Render our search bar - this.setFocused(this.searchField); - this.searchField.setTextFieldFocused(true); - this.searchField.render(matrices, mouseX, mouseY, delta); - - // Render buttons - super.render(matrices, mouseX, mouseY, delta); + @Override + public void renderBackground(final DrawContext context, final int mouseX, final int mouseY, final float delta) { + super.renderInGameBackground(context); } // Sends mouseDragged event to the scrolling list + @Override public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { return this.list.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 04d78f5..d8f067c 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -33,11 +33,10 @@ ], "depends": { - "fabricloader": ">=0.7.4", - "fabric": "*", - "fabric-lifecycle-events-v1": "*", - "fabric-key-binding-api-v1": "*", - "minecraft": ">=1.19" + "fabricloader": ">=0.16.10", + "fabric-api": "*", + "minecraft": "~1.21.4", + "java": ">=21" }, "suggests": { "flamingo": "*"