Skip to content

Commit

Permalink
1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
gliscowo committed Jun 8, 2023
1 parent 7235a00 commit d54468c
Show file tree
Hide file tree
Showing 17 changed files with 112 additions and 129 deletions.
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_base_version=1.19.4
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.1
loader_version=0.14.18
minecraft_base_version=1.20
minecraft_version=1.20
yarn_mappings=1.20+build.1
loader_version=0.14.21
# Mod Properties
mod_version=0.4.4
maven_group=com.glisco
archives_base_name=isometric-renders
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.76.0+1.19.4
fabric_version=0.83.0+1.20

# https://maven.wispforest.io/io/wispforest/worldmesher/
worldmesher_version=0.3.0+1.19.3
worldmesher_version=0.3.0+1.20

# https://maven.wispforest.io/io/wispforest/exo/
exo_version=0.1.5+1.19

# https://maven.wispforest.io/io/wispforest/owo-lib/
owo_version=0.10.3+1.19.4
owo_version=0.11.0+1.20
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,8 @@ public class IsometricRenders implements ClientModInitializer {
public void onInitializeClient() {
ClientCommandRegistrationCallback.EVENT.register(IsorenderCommand::register);

ClientLifecycleEvents.CLIENT_STARTED.register(newClient -> {
TooltipRenderable.TooltipScreen.INSTANCE.init(newClient, 10000, 10000);
});

KeyBindingHelper.registerKeyBinding(SELECT);


final var ioStateId = "io-state";
final var areaSelectionHintId = "area-selection-hint";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private static int renderAreaSelection(CommandContext<FabricClientCommandSource>
private static <S> void withItemGroupFromContext(CommandContext<S> context, BiConsumer<List<ItemStack>, String> action) {
final var itemGroup = ItemGroupArgumentType.getItemGroup("itemgroup", context);
final var stacks = new ArrayList<>(itemGroup.getDisplayStacks());
action.accept(stacks, "creative-tab_" + itemGroup.getId().toShortTranslationKey());
action.accept(stacks, "creative-tab_" + Registries.ITEM_GROUP.getId(itemGroup).toShortTranslationKey());
}

public static BlockPos getPosFromArgument(DefaultPosArgument argument, FabricClientCommandSource source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.command.CommandSource;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemGroups;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;

import java.util.concurrent.CompletableFuture;
Expand All @@ -31,11 +32,11 @@ public static <S> ItemGroup getItemGroup(String name, CommandContext<S> context)
@Override
public ItemGroup parse(StringReader reader) throws CommandSyntaxException {
var id = Identifier.fromCommandInput(reader);
return ItemGroups.getGroups().stream().filter(itemGroup -> itemGroup.getId().equals(id)).findAny().orElseThrow(() -> NO_ITEMGROUP.create(id));
return ItemGroups.getGroups().stream().filter(itemGroup -> Registries.ITEM_GROUP.getId(itemGroup).equals(id)).findAny().orElseThrow(() -> NO_ITEMGROUP.create(id));
}

@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
return CommandSource.suggestIdentifiers(ItemGroups.getGroups().stream().map(ItemGroup::getId), builder);
return CommandSource.suggestIdentifiers(ItemGroups.getGroups().stream().map(Registries.ITEM_GROUP::getId), builder);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.glisco.isometricrenders.mixin;

import com.glisco.isometricrenders.IsometricRenders;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.tooltip.TooltipComponent;
import net.minecraft.client.gui.tooltip.TooltipPositioner;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.List;

@Mixin(DrawContext.class)
public class DrawContextMixin {

@Unique
private int isometric$tooltipWidth = 0;
@Unique
private int isometric$tooltipHeight = 0;

@Inject(method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;IILnet/minecraft/client/gui/tooltip/TooltipPositioner;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;push()V"), locals = LocalCapture.CAPTURE_FAILHARD)
private void captureTooltipDimensions(TextRenderer textRenderer, List<TooltipComponent> components, int x, int y, TooltipPositioner positioner, CallbackInfo ci, int width, int height) {
this.isometric$tooltipWidth = width;
this.isometric$tooltipHeight = height;
}

@ModifyVariable(method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;IILnet/minecraft/client/gui/tooltip/TooltipPositioner;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;push()V"), ordinal = 6)
private int centerXIfNeeded(int orig) {
if (!IsometricRenders.centerNextTooltip) return orig;
return orig - 12 - isometric$tooltipWidth / 2;
}

@ModifyVariable(method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;IILnet/minecraft/client/gui/tooltip/TooltipPositioner;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;push()V"), ordinal = 7)
private int centerYIfNeeded(int orig) {
if (!IsometricRenders.centerNextTooltip) return orig;
return orig + 12 - isometric$tooltipHeight / 2;
}

@Inject(method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;IILnet/minecraft/client/gui/tooltip/TooltipPositioner;)V", at = @At("TAIL"))
private void resetCenterState(TextRenderer textRenderer, List<TooltipComponent> components, int x, int y, TooltipPositioner positioner, CallbackInfo ci) {
IsometricRenders.centerNextTooltip = false;
}

}
47 changes: 0 additions & 47 deletions src/main/java/com/glisco/isometricrenders/mixin/ScreenMixin.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.TextureUtil;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.systems.VertexSorter;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.Framebuffer;
import net.minecraft.client.gl.SimpleFramebuffer;
Expand All @@ -28,7 +29,7 @@ public class RenderableDispatcher {
public static void drawIntoActiveFramebuffer(Renderable<?> renderable, float aspectRatio, float tickDelta, Consumer<MatrixStack> transformer) {
RenderSystem.backupProjectionMatrix();
Matrix4f projectionMatrix = new Matrix4f().setOrtho(-aspectRatio, aspectRatio, -1, 1, -1000, 3000);
RenderSystem.setProjectionMatrix(projectionMatrix);
RenderSystem.setProjectionMatrix(projectionMatrix, VertexSorter.BY_Z);

renderable.prepare();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import com.glisco.isometricrenders.screen.IsometricUI;
import com.glisco.isometricrenders.util.ExportPathSpec;
import io.wispforest.owo.ui.container.FlowLayout;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries;
import net.minecraft.text.Text;
import net.minecraft.util.math.RotationAxis;

public class TooltipRenderable extends DefaultRenderable<TooltipRenderable.TooltipPropertyBundle> {
Expand All @@ -24,7 +24,10 @@ public TooltipRenderable(ItemStack stack) {
@Override
public void emitVertices(MatrixStack matrices, VertexConsumerProvider vertexConsumers, float tickDelta) {
IsometricRenders.centerNextTooltip = true;
TooltipScreen.INSTANCE.renderTooltip(matrices, this.stack, 0, 0);

var client = MinecraftClient.getInstance();
new DrawContext(client, client.getBufferBuilders().getEntityVertexConsumers())
.drawItemTooltip(client.textRenderer, this.stack, 0, 0);
}

@Override
Expand Down Expand Up @@ -56,18 +59,4 @@ public void applyToViewMatrix(MatrixStack modelViewStack) {
modelViewStack.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(180));
}
}

public static class TooltipScreen extends Screen {

public static final TooltipScreen INSTANCE = new TooltipScreen();

private TooltipScreen() {
super(Text.empty());
}

@Override
public void renderTooltip(MatrixStack matrices, ItemStack stack, int x, int y) {
super.renderTooltip(matrices, stack, x, y);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
import io.wispforest.owo.ui.core.Insets;
import io.wispforest.owo.ui.core.Sizing;
import io.wispforest.owo.ui.core.VerticalAlignment;
import io.wispforest.owo.ui.util.Drawer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;

import java.util.function.Supplier;
Expand Down Expand Up @@ -62,15 +61,15 @@ public static void intControl(FlowLayout container, IntProperty property, String
}
}

public static void drawExportProgressBar(MatrixStack matrices, int x, int y, int drawWidth, int barWidth, double speed) {
public static void drawExportProgressBar(DrawContext context, int x, int y, int drawWidth, int barWidth, double speed) {
int end = x + drawWidth + barWidth;

int offset = (int) (System.currentTimeMillis() / speed % (drawWidth + barWidth));

int endWithOffset = x + offset;
if (endWithOffset > end) endWithOffset = end;

Drawer.fill(matrices, Math.max(x + offset - barWidth, x), y, Math.min(endWithOffset, x + drawWidth), y + 2, 0xFF00FF00);
context.fill(Math.max(x + offset - barWidth, x), y, Math.min(endWithOffset, x + drawWidth), y + 2, 0xFF00FF00);
}

public static RowBuilder row(FlowLayout container) {
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/com/glisco/isometricrenders/screen/RenderScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.Framebuffer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ConfirmLinkScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.tooltip.TooltipComponent;
Expand Down Expand Up @@ -303,7 +304,7 @@ protected void build(FlowLayout rootComponent) {
}

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

if (this.guiRebuildScheduled) {
this.guiRebuildScheduled = false;
Expand All @@ -316,9 +317,9 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
}

if (this.drawOnlyBackground) {
fill(matrices, 0, 0, this.width, this.height, GlobalProperties.backgroundColor | 255 << 24);
context.fill(0, 0, this.width, this.height, GlobalProperties.backgroundColor | 255 << 24);
} else {
renderBackground(matrices);
renderBackground(context);
}

final var window = client.getWindow();
Expand All @@ -333,11 +334,11 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
);

if (!this.drawOnlyBackground && this.uiAdapter != null) {
drawFramingHint(matrices);
drawGuiBackground(matrices);
drawFramingHint(context);
drawGuiBackground(context);

RenderSystem.clear(GL11.GL_DEPTH_BUFFER_BIT, MinecraftClient.IS_SYSTEM_MAC);
super.render(matrices, mouseX, mouseY, delta);
super.render(context, mouseX, mouseY, delta);

if (this.exportAnimationButton != null) {
this.exportAnimationButton.tooltip(this.memoryGuard.getStatusTooltip(this.estimateMemoryUsage(exportFrames)).stream().map(text -> TooltipComponent.of(text.asOrderedText())).toList());
Expand Down Expand Up @@ -545,15 +546,15 @@ public void removed() {
this.client.getWindow().setFramerateLimit(this.client.options.getMaxFps().getValue());
}

private void drawFramingHint(MatrixStack matrices) {
fill(matrices, viewportBeginX + 5, 0, viewportEndX - 5, 5, 0x90000000);
fill(matrices, viewportBeginX + 5, height - 5, viewportEndX - 5, height, 0x90000000);
fill(matrices, viewportBeginX, 0, viewportBeginX + 5, height, 0x90000000);
fill(matrices, viewportEndX - 5, 0, viewportEndX, height, 0x90000000);
private void drawFramingHint(DrawContext context) {
context.fill(viewportBeginX + 5, 0, viewportEndX - 5, 5, 0x90000000);
context.fill(viewportBeginX + 5, height - 5, viewportEndX - 5, height, 0x90000000);
context.fill(viewportBeginX, 0, viewportBeginX + 5, height, 0x90000000);
context.fill(viewportEndX - 5, 0, viewportEndX, height, 0x90000000);
}

private void drawGuiBackground(MatrixStack matrices) {
fill(matrices, 0, 0, viewportBeginX, height, 0x90000000);
fill(matrices, viewportEndX, 0, width, height, 0x90000000);
private void drawGuiBackground(DrawContext context) {
context.fill(0, 0, viewportBeginX, height, 0x90000000);
context.fill(viewportEndX, 0, width, height, 0x90000000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.glisco.isometricrenders.util.Translate;
import io.wispforest.owo.ui.component.Components;
import io.wispforest.owo.ui.container.VerticalFlowLayout;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.core.Insets;
import io.wispforest.owo.ui.core.Sizing;
import io.wispforest.owo.ui.core.Surface;
Expand All @@ -15,10 +15,10 @@
import static com.glisco.isometricrenders.util.AreaSelectionHelper.pos1;
import static com.glisco.isometricrenders.util.AreaSelectionHelper.pos2;

public class AreaSelectionComponent extends VerticalFlowLayout {
public class AreaSelectionComponent extends FlowLayout {

public AreaSelectionComponent() {
super(Sizing.content(), Sizing.content());
super(Sizing.content(), Sizing.content(), Algorithm.VERTICAL);

this.surface(Surface.flat(0x77000000).and(Surface.outline(0x77000000)));
this.padding(Insets.of(5));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.glisco.isometricrenders.widget;

import io.wispforest.owo.ui.base.BaseComponent;
import io.wispforest.owo.ui.core.OwoUIDrawContext;
import io.wispforest.owo.ui.core.Sizing;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;

import java.util.function.Supplier;
Expand Down Expand Up @@ -42,13 +42,7 @@ protected int determineVerticalContentSize(Sizing sizing) {
}

@Override
public void draw(MatrixStack matrices, int mouseX, int mouseY, float partialTicks, float delta) {
if (this.shadow) {
this.textRenderer.drawWithShadow(matrices, this.content.get(), this.x, this.y, this.color);
} else {
this.textRenderer.draw(matrices, this.content.get(), this.x, this.y, this.color);
}
public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partialTicks, float delta) {
context.drawText(this.textRenderer, this.content.get(), this.x, this.y, this.color, this.shadow);
}


}
Loading

0 comments on commit d54468c

Please sign in to comment.