Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
Update to 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Jun 8, 2023
1 parent 9b60abe commit e12c89f
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 101 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ allprojects {
modApi "net.fabricmc:fabric-loader:${project.loader_version}"

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
modImplementation "com.terraformersmc:modmenu:${project.mod_menu_version}"
modCompileOnly "com.terraformersmc:modmenu:${project.mod_menu_version}"

testImplementation sourceSets.main.output
}
Expand Down
38 changes: 19 additions & 19 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ mod_id=mccic
maven_group=dev.andante.mccic

version=4.0.0
minecraft_version=1.19.4
yarn_build=2
loader_version=0.14.19
minecraft_version=1.20
yarn_build=1
loader_version=0.14.21

mod_name=MCCI: Companion
major_version=1.19.4
supported_versions=1.19.4
major_version=1.20
supported_versions=1.20
github_repository=andantet/companion
github_branch=1.19.4
github_branch=1.20
curseforge_id=849200
modrinth_id=yF4Uptui
release_type=release

fabric_api_version=0.79.0+1.19.4
mod_menu_version=6.2.1
authme_version=6.0.0
fabric_api_version=0.83.0+1.20
mod_menu_version=7.0.0
authme_version=7.0.0

# module versions
mccic-api-version=1.0.0
mccic-chat-version=1.0.0
mccic-config-version=1.0.0
mccic-debug-version=1.0.0
mccic-discord-rp-version=1.0.0
mccic-hud-version=1.0.0
mccic-key-bindings-version=1.0.0
mccic-music-version=1.0.0
mccic-qol-version=1.0.0
mccic-toasts-version=1.0.0
mccic-api-version=1.0.1
mccic-chat-version=1.0.1
mccic-config-version=1.0.1
mccic-debug-version=1.0.1
mccic-discord-rp-version=1.0.1
mccic-hud-version=1.0.1
mccic-key-bindings-version=1.0.1
mccic-music-version=1.0.1
mccic-qol-version=1.0.1
mccic-toasts-version=1.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import com.mojang.blaze3d.systems.RenderSystem;
import dev.andante.mccic.api.mixin.client.access.SystemToastAccessor;
import dev.andante.mccic.api.mixin.client.access.SystemToastTypeAccessor;
import java.util.Objects;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.toast.Toast;
import net.minecraft.client.toast.ToastManager;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
Expand All @@ -30,62 +31,63 @@ public AdaptableIconToast(Identifier texture, String id) {
}

protected void setLines(@Nullable Text... lines) {
((SystemToastAccessor) this).setLines(Arrays.stream(lines).map(Text::asOrderedText).toList());
((SystemToastAccessor) this).setLines(Arrays.stream(lines).filter(Objects::nonNull).map(Text::asOrderedText).toList());
}

@Override
public Toast.Visibility draw(MatrixStack matrices, ToastManager manager, long startTime) {
public Toast.Visibility draw(DrawContext context, ToastManager manager, long startTime) {
SystemToastAccessor that = (SystemToastAccessor) this;

if (that.isJustUpdated()) {
that.setStartTime(startTime);
that.setJustUpdated(false);
}

RenderSystem.setShaderTexture(0, this.getTexture());
Identifier texture = this.getTexture();
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
int width = this.getWidth();
List<OrderedText> lines = that.getLines();
if (width == 160 && lines.size() <= 1) {
manager.drawTexture(matrices, 0, 0, 0, 64, width, this.getHeight());
context.drawTexture(texture, 0, 0, 0, 64, width, this.getHeight());
} else {
int height = this.getHeight();
int l = Math.min(4, height - 28);
this.drawPart(matrices, manager, width, 0, 0, 28);
this.drawPart(context, width, 0, 0, 28);

for (int i = 28; i < height - l; i += 10) {
this.drawPart(matrices, manager, width, 16, i, Math.min(16, height - i - l));
this.drawPart(context, width, 16, i, Math.min(16, height - i - l));
}

this.drawPart(matrices, manager, width, 32 - l, height - l, l);
this.drawPart(context, width, 32 - l, height - l, l);
}

TextRenderer textRenderer = manager.getClient().textRenderer;
Text title = that.getTitle();
float x = 5.0F + 16.0F + 5.0F + 2.0F;
int x = 5 + 16 + 5 + 2;
if (lines.isEmpty()) {
textRenderer.draw(matrices, title, x, 12.0F, 0xFFFFFF00);
context.drawTextWithShadow(textRenderer, title, x, 12, 0xFFFFFF00);
} else {
textRenderer.draw(matrices, title, x, 7.0F, 0xFFFFFF00);
context.drawTextWithShadow(textRenderer, title, x, 7, 0xFFFFFF00);

for (int i = 0; i < lines.size(); i++) {
textRenderer.draw(matrices, lines.get(i), x, (float) (18 + i * 12), 0xFFFFFFFF);
context.drawTextWithShadow(textRenderer, lines.get(i), x, 18 + i * 12, 0xFFFFFFFF);
}
}

return startTime - that.getStartTime() < ((SystemToastTypeAccessor) (Object) that.getType()).getDisplayDuration() ? Visibility.SHOW : Visibility.HIDE;
}

protected void drawPart(MatrixStack matrices, ToastManager manager, int width, int textureV, int y, int height) {
protected void drawPart(DrawContext context, int width, int textureV, int y, int height) {
int i = textureV == 0 ? 22 : 5;
int j = Math.min(60, width - i);
manager.drawTexture(matrices, 0, y, 0, 64 + textureV, i, height);
Identifier texture = this.getTexture();
context.drawTexture(texture, 0, y, 0, 64 + textureV, i, height);

for (int k = i; k < width - j; k += 64) {
manager.drawTexture(matrices, k, y, 32, 64 + textureV, Math.min(64, width - k - j), height);
context.drawTexture(texture, k, y, 32, 64 + textureV, Math.min(64, width - k - j), height);
}

manager.drawTexture(matrices, width - j, y, 160 - j, 64 + textureV, j, height);
context.drawTexture(texture, width - j, y, 160 - j, 64 + textureV, j, height);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.andante.mccic.api.client.toast.CustomToastTexture;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.toast.SystemToast;
import net.minecraft.client.toast.Toast;
import net.minecraft.client.toast.ToastManager;
Expand All @@ -23,11 +24,11 @@ public class SystemToastMixin {
method = "draw",
at = @At(
value = "INVOKE",
target = "Lcom/mojang/blaze3d/systems/RenderSystem;setShaderTexture(ILnet/minecraft/util/Identifier;)V",
target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V",
shift = At.Shift.AFTER
)
)
private void onDrawSetTexture(MatrixStack matrices, ToastManager manager, long startTime, CallbackInfoReturnable<Toast.Visibility> cir) {
private void onDrawSetTexture(DrawContext context, ToastManager manager, long startTime, CallbackInfoReturnable<Toast.Visibility> cir) {
SystemToast that = (SystemToast) (Object) this;
if (that instanceof CustomToastTexture customToast) {
RenderSystem.setShaderTexture(0, customToast.getTexture());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.ButtonWidget;
Expand Down Expand Up @@ -128,20 +129,20 @@ protected void reloadConfig() {
}

@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
// background
this.renderBackground(matrices);
super.render(matrices, mouseX, mouseY, delta);
this.renderBackground(context);
super.render(context, mouseX, mouseY, delta);

// title
int padding = 6;
ClientHelper.drawOpaqueBlack(0, TITLE_Y - padding, this.width, TITLE_Y + this.textRenderer.fontHeight + padding);

this.textRenderer.draw(matrices, this.title, (int) ((this.width / 2f) - (this.textRenderer.getWidth(this.title) / 2f)), TITLE_Y, 0xFFFFFFFF);
context.drawTextWithShadow(this.textRenderer, this.title, (int) ((this.width / 2f) - (this.textRenderer.getWidth(this.title) / 2f)), TITLE_Y, 0xFFFFFFFF);

// options
if (!this.list.children().isEmpty()) {
this.list.render(matrices, mouseX, mouseY, delta);
this.list.render(context, mouseX, mouseY, delta);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import dev.andante.mccic.config.client.ClientConfigRegistry;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -53,8 +54,8 @@ protected void reloadConfig() {
}

@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
super.render(matrices, mouseX, mouseY, delta);
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);

int l = OTHER_CONFIG_LOCATION_TEXTS.size();
int padding = 6;
Expand All @@ -63,7 +64,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {

for (int i = 0; i < l; i++) {
Text text = OTHER_CONFIG_LOCATION_TEXTS.get(i);
this.textRenderer.draw(matrices, text,
context.drawTextWithShadow(this.textRenderer, text,
(int) ((this.width / 2f) - (this.textRenderer.getWidth(text) / 2f)),
y + ((this.textRenderer.fontHeight + 1) * i),
0xFFFFFFFF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.command.CommandRegistryAccess;
Expand Down Expand Up @@ -107,7 +108,7 @@ private void registerCommands(CommandDispatcher<FabricClientCommandSource> dispa
}));
}

private void onHudRender(MatrixStack matrices, float tickDelta) {
private void onHudRender(DrawContext context, float tickDelta) {
if (!DebugClientConfig.getConfig().debugHud()) {
return;
}
Expand All @@ -120,33 +121,33 @@ private void onHudRender(MatrixStack matrices, float tickDelta) {
ClientHelper.drawOpaqueBlack(2, 2, 130, this.y + MinecraftClient.getInstance().textRenderer.fontHeight);
this.y = 4;

this.drawText(matrices, Text.of("State: " + gameTracker.getGameState().name()), false);
this.renderContent(matrices, gameTracker.getGame(), gameTracker.getTime());
this.drawText(context, Text.of("State: " + gameTracker.getGameState().name()), false);
this.renderContent(context, gameTracker.getGame(), gameTracker.getTime());

QueueTracker queueTracker = QueueTracker.INSTANCE;
this.y += 5;
this.drawText(matrices, Text.literal(" ").formatted(Formatting.STRIKETHROUGH), false);
this.drawText(context, Text.literal(" ").formatted(Formatting.STRIKETHROUGH), false);
this.y -= 4;
this.drawText(matrices, Text.of("Queue Type: " + queueTracker.getQueueType().name()));
this.renderContent(matrices, queueTracker.getGame(), queueTracker.getTime());
this.drawText(context, Text.of("Queue Type: " + queueTracker.getQueueType().name()));
this.renderContent(context, queueTracker.getGame(), queueTracker.getTime());
}

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
private void renderContent(MatrixStack matrices, Optional<Game> maybeGame, OptionalInt maybeTime) {
maybeGame.map(Game::getDisplayString).ifPresent(game -> this.drawText(matrices, Text.of("Game: " + game)));
maybeTime.ifPresent(time -> this.drawText(matrices, Text.of("Time: %s (%sm %ss)".formatted(time, time / 60, time % 60))));
private void renderContent(DrawContext context, Optional<Game> maybeGame, OptionalInt maybeTime) {
maybeGame.map(Game::getDisplayString).ifPresent(game -> this.drawText(context, Text.of("Game: " + game)));
maybeTime.ifPresent(time -> this.drawText(context, Text.of("Time: %s (%sm %ss)".formatted(time, time / 60, time % 60))));
}

private void drawText(MatrixStack matrices, Text text, boolean bump) {
private void drawText(DrawContext context, Text text, boolean bump) {
if (bump) {
this.y += 10;
}

MinecraftClient.getInstance().textRenderer.draw(matrices, text, 4, this.y, 0xFFFFFF);
context.drawTextWithShadow(MinecraftClient.getInstance().textRenderer, text, 4, this.y, 0xFFFFFF);
}

private void drawText(MatrixStack matrices, Text text) {
this.drawText(matrices, text, true);
private void drawText(DrawContext context, Text text) {
this.drawText(context, text, true);
}

private EventResult onChatMessage(MCCIChatEvent.Context context) {
Expand Down

0 comments on commit e12c89f

Please sign in to comment.