Skip to content

Commit

Permalink
1.16 update
Browse files Browse the repository at this point in the history
  • Loading branch information
Draylar committed Jun 24, 2020
1 parent 18988c4 commit d928344
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 100 deletions.
63 changes: 51 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
plugins {
id 'fabric-loom' version '0.2.7-SNAPSHOT'
id 'fabric-loom' version '0.4-SNAPSHOT'
id 'maven-publish'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

archivesBaseName = "colorunchained"
version = "1.0.2"
version = project.mod_version + "-" + project.minecraft_version

minecraft {
}
Expand All @@ -15,26 +16,64 @@ repositories {
maven { url = "https://maven.fabricmc.net/" }
}


dependencies {
minecraft "com.mojang:minecraft:1.15.2"
mappings "net.fabricmc:yarn:1.15.2+build.14:v2"
modCompile "net.fabricmc:fabric-loader:0.7.8+build.184"
modCompile "net.fabricmc.fabric-api:fabric-api:0.4.32+build.292-1.15"
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_version}:v2"
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"
modCompile "net.fabricmc.fabric-api:fabric-api:${project.api_version}"

modCompile "io.github.prospector:modmenu:${project.modmenu_version}"
}

processResources {
inputs.property "version", project.version

modApi ("io.github.prospector:modmenu:1.8.5+build.23"){
transitive = false
from(sourceSets.main.resources.srcDirs) {
include "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"
}

// 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'
classifier = "sources"
from sourceSets.main.allSource
}

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
jar {
from "LICENSE"
}

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}

// select the repositories you want to publish to
repositories {
// uncomment to publish to the local maven
// mavenLocal()
}
}
13 changes: 12 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
#Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.jvmargs=-Xmx1G

mod_version = 1.1.0

## Game / Fabric deps
minecraft_version = 1.16.1
yarn_version=1.16.1+build.4
loader_version=0.8.8+build.202
api_version=0.13.1+build.370-1.16

## Dev Deps
modmenu_version=1.12+
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
package com.github.draylar.cu.client.gui;
package draylar.cu.client.gui;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.TextFormat;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.MathHelper;

public class ColorButtonWidget extends ButtonWidget {

private int x;
private int y;
private Formatting formatting;
private final int x;
private final int y;
private final Formatting formatting;

public ColorButtonWidget(Formatting formatting, int x, int y, int width, int height, Text message, PressAction onPress) {
super(x, y, width, height, message, onPress);

public ColorButtonWidget(TextFormat format, int x, int y, int width, int height, String text, PressAction pressAction) {
super(x, y, width, height, text, pressAction);
this.x = x;
this.y = y;

formatting = Formatting.byCode(format.getChar());
visible = false;
this.formatting = formatting;
this.visible = false;
}

@Override
public void renderButton(int mouseX, int mouseY, float float_1) {
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float float_1) {
MinecraftClient client = MinecraftClient.getInstance();
client.getTextureManager().bindTexture(WIDGETS_LOCATION);

Expand All @@ -35,8 +36,8 @@ public void renderButton(int mouseX, int mouseY, float float_1) {
RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO);
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);

this.blit(this.x, this.y, 0, 46 + int_3 * 20, this.width / 2, this.height + 4);
this.blit(this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + int_3 * 20, this.width / 2, this.height + 4);
this.drawTexture(matrices, this.x, this.y, 0, 46 + int_3 * 20, this.width / 2, this.height + 4);
this.drawTexture(matrices, this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + int_3 * 20, this.width / 2, this.height + 4);

int int_4 = 14737632;
if (!this.active) {
Expand All @@ -46,7 +47,7 @@ public void renderButton(int mouseX, int mouseY, float float_1) {
}

if(formatting.getColorValue() != null) {
DrawableHelper.fill(x + 5, y + 6, x + 11, y + 12, formatting.getColorValue() | 0xFF000000);
DrawableHelper.fill(matrices,x + 5, y + 6, x + 11, y + 12, formatting.getColorValue() | 0xFF000000);
} else {
String icon = "";
switch(formatting) {
Expand All @@ -68,7 +69,7 @@ public void renderButton(int mouseX, int mouseY, float float_1) {
case RESET:
icon = "R";
}
this.drawCenteredString(MinecraftClient.getInstance().textRenderer, icon, this.x + this.width / 2, this.y + (this.height - 8) / 2, int_4 | MathHelper.ceil(this.alpha * 255.0F) << 24);
this.drawCenteredString(matrices, MinecraftClient.getInstance().textRenderer, icon, this.x + this.width / 2, this.y + (this.height - 8) / 2, int_4 | MathHelper.ceil(this.alpha * 255.0F) << 24);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
package com.github.draylar.cu.client.gui;
package draylar.cu.client.gui;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;

import java.awt.*;

public class ColorToggleWidget extends ButtonWidget {

private int x;
private int y;
private final int x;
private final int y;

int index = 0;

private PressAction pressAction;
private final PressAction pressAction;

public ColorToggleWidget(int x, int y, int width, int height, String text, PressAction pressAction) {
public ColorToggleWidget(int x, int y, int width, int height, Text text, PressAction pressAction) {
super(x, y, width, height, text, pressAction);

this.x = x;
this.y = y;
this.pressAction = pressAction;
}

@Override
public void onClick(double double_1, double double_2) {
super.onClick(double_1, double_2);
public void onClick(double x, double y) {
super.onClick(x, y);
}

public void onPress() {
this.pressAction.onPress(this);
}

@Override
public void render(int mouseX, int mouseY, float float_1) {
public void render(MatrixStack stack, int mouseX, int mouseY, float float_1) {
MinecraftClient client = MinecraftClient.getInstance();
client.getTextureManager().bindTexture(WIDGETS_LOCATION);

Expand All @@ -44,15 +47,15 @@ public void render(int mouseX, int mouseY, float float_1) {
RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO);
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);

this.blit(this.x, this.y, 0, 46 + int_3 * 20, this.width / 2, this.height + 4);
this.blit(this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + int_3 * 20, this.width / 2, this.height + 4);
this.drawTexture(stack, this.x, this.y, 0, 46 + int_3 * 20, this.width / 2, this.height + 4);
this.drawTexture(stack, this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + int_3 * 20, this.width / 2, this.height + 4);


double red = Math.sin(.03 * index + 0) * 127 + 128;
double green = Math.sin(.03 * index + 2) * 127 + 128;
double blue = Math.sin(.03 * index + 4) * 127 + 128;

DrawableHelper.fill(x + 5, y + 5, x + 11, y + 14, new Color((int) red, (int) green, (int) blue).getRGB());
DrawableHelper.fill(stack,x + 5, y + 5, x + 11, y + 14, new Color((int) red, (int) green, (int) blue).getRGB());

index++;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.github.draylar.cu.mixin;
package draylar.cu.mixin;

import com.github.draylar.cu.client.gui.ColorButtonWidget;
import com.github.draylar.cu.client.gui.ColorToggleWidget;
import draylar.cu.client.gui.ColorButtonWidget;
import draylar.cu.client.gui.ColorToggleWidget;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.AnvilScreen;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.util.TextFormat;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -25,7 +26,7 @@ public abstract class AnvilScreenMixin extends Screen {
@Shadow private TextFieldWidget nameField;
boolean showColors = false;

ColorToggleWidget colorButton = new ColorToggleWidget(2, 2, 16, 16, "Color", (widget) -> {
ColorToggleWidget colorButton = new ColorToggleWidget(2, 2, 16, 16, new LiteralText("Color"), (widget) -> {
toggleVisible();
});

Expand All @@ -42,14 +43,14 @@ private void toggleVisible() {
}


@Inject(at = @At("HEAD"), method = "init")
@Inject(at = @At("HEAD"), method = "setup")
private void init(CallbackInfo ci) {
int index = 0;

for(TextFormat color : TextFormat.values()) {
for(Formatting color : Formatting.values()) {
index++;
ColorButtonWidget red = new ColorButtonWidget(color,18 * index + 3, 2, 16, 16, color.getName(), (widget) -> {
nameField.setText(nameField.getText() + "§" + color.getChar());
ColorButtonWidget red = new ColorButtonWidget(color,18 * index + 3, 2, 16, 16, new LiteralText(color.getName()), (widget) -> {
nameField.setText(nameField.getText() + "§" + ((FormattingAccessor) (Object) color).getCode());
this.setFocused(nameField);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.github.draylar.cu.mixin;
package draylar.cu.mixin;

import com.github.draylar.cu.client.gui.ColorButtonWidget;
import com.github.draylar.cu.client.gui.ColorToggleWidget;
import draylar.cu.client.gui.ColorButtonWidget;
import draylar.cu.client.gui.ColorToggleWidget;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.BookEditScreen;
import net.minecraft.client.util.TextFormat;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -26,26 +27,26 @@ public abstract class BookEditScreenMixin extends Screen {

@Shadow public abstract boolean charTyped(char char_1, int int_1);

@Inject(at = @At("HEAD"), method = "stripFromatting", cancellable = true)
private void stripFromatting(String string_1, CallbackInfoReturnable<String> info) {
StringBuilder stringBuilder_1 = new StringBuilder();
char[] var3 = string_1.toCharArray();
int var4 = var3.length;

for(int var5 = 0; var5 < var4; ++var5) {
char char_1 = var3[var5];
if (char_1 != 127) {
stringBuilder_1.append(char_1);
}
}

info.setReturnValue(stringBuilder_1.toString());
}
// @Inject(at = @At("HEAD"), method = "stripFromatting", cancellable = true)
// private void stripFromatting(String string_1, CallbackInfoReturnable<String> info) {
// StringBuilder stringBuilder_1 = new StringBuilder();
// char[] var3 = string_1.toCharArray();
// int var4 = var3.length;
//
// for(int var5 = 0; var5 < var4; ++var5) {
// char char_1 = var3[var5];
// if (char_1 != 127) {
// stringBuilder_1.append(char_1);
// }
// }
//
// info.setReturnValue(stringBuilder_1.toString());
// }


boolean showColors = false;

ColorToggleWidget colorButton = new ColorToggleWidget(2, 2, 16, 16, "Color", (widget) -> {
ColorToggleWidget colorButton = new ColorToggleWidget(2, 2, 16, 16, new LiteralText("Color"), (widget) -> {
toggleVisible();
});

Expand Down Expand Up @@ -79,10 +80,10 @@ private void init(CallbackInfo ci) {
int x = 0;
int y = 0;

for(TextFormat color : TextFormat.values()) {
ColorButtonWidget red = new ColorButtonWidget(color, 2 + x * 20, 2 + y * 20, 16, 16, color.getName(), (widget) -> {
for(Formatting color : Formatting.values()) {
ColorButtonWidget red = new ColorButtonWidget(color, 2 + x * 20, 2 + y * 20, 16, 16, new LiteralText(color.getName()), (widget) -> {
this.charTyped('§', 1);
this.charTyped(color.getChar(), 0);
this.charTyped(((FormattingAccessor) (Object) color).getCode(), 0);
});

if(y < 8) {
Expand Down
Loading

1 comment on commit d928344

@Mhowser
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay thank you Draylar!

Please sign in to comment.