Skip to content

Commit

Permalink
general cleanup, port to 1.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gliscowo committed Mar 16, 2022
1 parent fb7110c commit 94170c1
Show file tree
Hide file tree
Showing 29 changed files with 189 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ protected HandledScreenMixin(Text title) {
super(title);
}

@Inject(method = "keyPressed", at = @At("HEAD"), cancellable = true)
@Inject(method = "keyPressed", at = @At("HEAD"))
public void renderInventory(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> cir) {
if (keyCode == GLFW.GLFW_KEY_F12) {
if (Screen.hasControlDown()) {
client.setScreen(new BatchIsometricBlockRenderScreen(IsometricRenderHelper.extractBlocks(handler.slots.stream().map(Slot::getStack).collect(Collectors.toList())), "inventory"));
cir.cancel();
} else if (Screen.hasAltDown()) {
client.setScreen(new BatchIsometricItemRenderScreen(handler.slots.stream().map(Slot::getStack).iterator(), "inventory"));
cir.cancel();
} else if (Screen.hasShiftDown()) {
IsometricRenderHelper.renderItemAtlas("inventory", handler.slots.stream().map(Slot::getStack).filter(itemStack -> !itemStack.isEmpty()).collect(Collectors.toList()), true);
cir.cancel();
}
if (keyCode != GLFW.GLFW_KEY_F12) return;

if (Screen.hasControlDown()) {
client.setScreen(new BatchIsometricBlockRenderScreen(IsometricRenderHelper.extractBlocks(handler.slots.stream().map(Slot::getStack).collect(Collectors.toList())), "inventory"));
cir.cancel();
} else if (Screen.hasAltDown()) {
client.setScreen(new BatchIsometricItemRenderScreen(handler.slots.stream().map(Slot::getStack).iterator(), "inventory"));
cir.cancel();
} else if (Screen.hasShiftDown()) {
IsometricRenderHelper.renderItemAtlas("inventory", handler.slots.stream().map(Slot::getStack).filter(itemStack -> !itemStack.isEmpty()).collect(Collectors.toList()), true);
cir.cancel();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public class MinecraftClientMixin {

@Inject(method = "setScreen", at = @At("HEAD"), cancellable = true)
public void openScheduled(Screen screen, CallbackInfo ci) {
if (screen == null && IsometricRenderHelper.isScreenScheduled()) {
IsometricRenderHelper.openScheduledScreen();
ci.cancel();
}
if (screen != null || !IsometricRenderHelper.isScreenScheduled()) return;

IsometricRenderHelper.openScheduledScreen();
ci.cancel();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class TextureManagerMixin {

@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
public void stopTick(CallbackInfo ci) {
if (MinecraftClient.getInstance().currentScreen instanceof RenderScreen && !((RenderScreen) MinecraftClient.getInstance().currentScreen).playAnimations) {
ci.cancel();
}
if (!(MinecraftClient.getInstance().currentScreen instanceof RenderScreen) || ((RenderScreen) MinecraftClient.getInstance().currentScreen).playAnimations)
return;
ci.cancel();
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.glisco.isometricrenders.mixin;
package com.glisco.isometricrenders.mixin.access;

import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.glisco.isometricrenders.mixin;
package com.glisco.isometricrenders.mixin.access;

import net.minecraft.command.argument.BlockStateArgument;
import net.minecraft.nbt.NbtCompound;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.glisco.isometricrenders.mixin;
package com.glisco.isometricrenders.mixin.access;

import net.minecraft.client.render.Camera;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.glisco.isometricrenders.mixin;
package com.glisco.isometricrenders.mixin.access;

import net.minecraft.command.argument.CoordinateArgument;
import net.minecraft.command.argument.DefaultPosArgument;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.glisco.isometricrenders.mixin;
package com.glisco.isometricrenders.mixin.access;

import net.minecraft.command.argument.EntitySummonArgumentType;
import net.minecraft.util.Identifier;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.glisco.isometricrenders.mixin;
package com.glisco.isometricrenders.mixin.access;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderTickCounter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.glisco.isometricrenders.mixin;
package com.glisco.isometricrenders.mixin.access;

import net.minecraft.client.texture.NativeImage;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.glisco.isometricrenders.mixin;
package com.glisco.isometricrenders.mixin.access;

import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.glisco.isometricrenders.mixin;
package com.glisco.isometricrenders.mixin.access;

import net.minecraft.client.gui.widget.SliderWidget;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.glisco.isometricrenders.render;

import com.glisco.isometricrenders.util.Translate;
import net.minecraft.client.render.DiffuseLighting;
import net.minecraft.text.Text;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.util.math.Vec3f;

import static com.glisco.isometricrenders.util.Translator.tr;

public class DefaultLightingProfiles {

public static final LightingProfile FLAT = new FlatLightingProfile();
Expand All @@ -21,7 +20,7 @@ public void setup() {

@Override
public Text getFriendlyName() {
return tr("gui.isometric-renders.lighting_profile.flat");
return Translate.gui("lighting_profile.flat");
}
}

Expand All @@ -41,7 +40,7 @@ public void setup() {

@Override
public Text getFriendlyName() {
return tr("gui.isometric-renders.lighting_profile.default");
return Translate.gui("lighting_profile.default");
}

@Override
Expand Down Expand Up @@ -70,7 +69,7 @@ public void setup() {

@Override
public Text getFriendlyName() {
return tr("gui.isometric-renders.lighting_profile.custom");
return Translate.gui("lighting_profile.custom");
}

public Vec3f getVector() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.glisco.isometricrenders.render;

import com.glisco.isometricrenders.mixin.BlockEntityAccessor;
import com.glisco.isometricrenders.mixin.CameraInvoker;
import com.glisco.isometricrenders.mixin.DefaultPosArgumentAccessor;
import com.glisco.isometricrenders.mixin.NativeImageAccessor;
import com.glisco.isometricrenders.mixin.access.BlockEntityAccessor;
import com.glisco.isometricrenders.mixin.access.CameraInvoker;
import com.glisco.isometricrenders.mixin.access.DefaultPosArgumentAccessor;
import com.glisco.isometricrenders.mixin.access.NativeImageAccessor;
import com.glisco.isometricrenders.screen.BatchIsometricBlockRenderScreen;
import com.glisco.isometricrenders.screen.BatchIsometricItemRenderScreen;
import com.glisco.isometricrenders.screen.ItemAtlasRenderScreen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.glisco.isometricrenders.screen.AreaIsometricRenderScreen;
import com.glisco.isometricrenders.screen.IsometricRenderScreen;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
Expand Down Expand Up @@ -62,14 +63,18 @@ public static void setupAreaRender(IsometricRenderScreen screen, BlockPos origin
public static void setupBlockEntityRender(IsometricRenderScreen screen, @NotNull BlockEntity entity) {

final MinecraftClient client = MinecraftClient.getInstance();
final Identifier blockId = Registry.BLOCK.getId(entity.getCachedState().getBlock());
final var state = entity.getCachedState();
final var block = state.getBlock();
final Identifier blockId = Registry.BLOCK.getId(block);

screen.setup((matrices, vertexConsumerProvider, tickDelta) -> {

matrices.push();
matrices.translate(-0.5, -0.5, -0.5);

client.getBlockRenderManager().renderBlockAsEntity(entity.getCachedState(), matrices, vertexConsumerProvider, 15728880, OverlayTexture.DEFAULT_UV);
if (block.getRenderType(state) != BlockRenderType.ENTITYBLOCK_ANIMATED) {
client.getBlockRenderManager().renderBlockAsEntity(state, matrices, vertexConsumerProvider, 15728880, OverlayTexture.DEFAULT_UV);
}

if (client.getBlockEntityRenderDispatcher().get(entity) != null) {
client.getBlockEntityRenderDispatcher().get(entity).render(entity, tickDelta, matrices, vertexConsumerProvider, 15728880, OverlayTexture.DEFAULT_UV);
Expand All @@ -90,12 +95,12 @@ public static void setupBlockEntityRender(IsometricRenderScreen screen, @NotNull

screen.setTickCallback(() -> {

if (entity.getCachedState().getBlockEntityTicker(client.world, entity.getType()) != null) {
entity.getCachedState().getBlockEntityTicker(client.world, (BlockEntityType<BlockEntity>) entity.getType()).tick(client.world, client.player.getBlockPos(), entity.getCachedState(), entity);
if (state.getBlockEntityTicker(client.world, entity.getType()) != null) {
state.getBlockEntityTicker(client.world, (BlockEntityType<BlockEntity>) entity.getType()).tick(client.world, client.player.getBlockPos(), state, entity);
}

if (client.world.random.nextDouble() < 0.150) {
entity.getCachedState().getBlock().randomDisplayTick(entity.getCachedState(), client.world, client.player.getBlockPos(), client.world.random);
block.randomDisplayTick(state, client.world, client.player.getBlockPos(), client.world.random);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.glisco.isometricrenders.screen;

import com.glisco.isometricrenders.render.IsometricRenderHelper;
import com.glisco.isometricrenders.util.Translate;
import com.mojang.blaze3d.systems.RenderSystem;
import io.wispforest.worldmesher.WorldMesh;
import net.minecraft.client.MinecraftClient;
Expand All @@ -9,12 +10,11 @@
import net.minecraft.client.util.Window;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.util.math.Vec3f;

import static com.glisco.isometricrenders.util.Translator.gui;
import static com.glisco.isometricrenders.util.Translator.tr;
import static com.glisco.isometricrenders.util.RuntimeConfig.*;

public class AreaIsometricRenderScreen extends IsometricRenderScreen {
Expand Down Expand Up @@ -47,7 +47,7 @@ protected void buildGuiElements() {
if (tempOpacity == areaRenderOpacity) return;
opacitySlider.setValue(areaRenderOpacity / 100f);
});
opacitySlider = new RenderScreen.SliderWidgetImpl(50, 275, sliderWidth, tr("message.isometric-renders.opacity"), 1, 0.05, areaRenderOpacity / 100f, aDouble -> {
opacitySlider = new RenderScreen.SliderWidgetImpl(50, 275, sliderWidth, Translate.make("message.isometric-renders.opacity"), 1, 0.05, areaRenderOpacity / 100f, aDouble -> {
areaRenderOpacity = (int) Math.round(aDouble * 100);
opacityField.setText(String.valueOf(areaRenderOpacity));
});
Expand All @@ -61,12 +61,12 @@ protected void drawGuiText(MatrixStack matrices) {
super.drawGuiText(matrices);

final AreaRenderCallback renderCallback = (AreaRenderCallback) this.renderCallback;
var meshStatus = gui("mesh_status");
var meshStatus = Translate.gui("mesh_status");
if (renderCallback.canRender()) {
meshStatus.append(gui("mesh_ready"));
meshStatus.append(Translate.gui("mesh_ready").formatted(Formatting.GREEN));
} else {
var percentage = Math.round(renderCallback.getMeshProgress() * 100);
meshStatus.append(gui("mesh_building", percentage));
meshStatus.append(Translate.gui("mesh_building", percentage).formatted(Formatting.RED));
}

MinecraftClient.getInstance().textRenderer.draw(matrices, meshStatus, 12, 260, 0xAAAAAA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.glisco.isometricrenders.util.ImageExporter;
import com.glisco.isometricrenders.util.RuntimeConfig;
import net.minecraft.client.MinecraftClient;
import com.glisco.isometricrenders.util.Translate;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.util.math.MatrixStack;
Expand All @@ -13,7 +13,6 @@

import static com.glisco.isometricrenders.util.RuntimeConfig.exportResolution;
import static com.glisco.isometricrenders.util.RuntimeConfig.useExternalRenderer;
import static com.glisco.isometricrenders.util.Translator.msg;

public abstract class BatchIsometricRenderScreen<T> extends IsometricRenderScreen {

Expand All @@ -29,14 +28,14 @@ public BatchIsometricRenderScreen(Iterator<T> renderObjects, String name) {
this.name = name;

if (ImageExporter.Threaded.busy()) {
MinecraftClient.getInstance().player.sendMessage(msg("threaded_export_system_not_available"), false);
Translate.chat("threaded_export_system_not_available");
invalid = true;
}

ImageExporter.Threaded.init();

if (useExternalRenderer && exportResolution > 2048 && !RuntimeConfig.allowInsaneResolutions) {
MinecraftClient.getInstance().player.sendMessage(msg("resolution_not_supported"), false);
Translate.chat("resolution_not_supported");
invalid = true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.glisco.isometricrenders.screen;

import com.glisco.isometricrenders.mixin.MinecraftClientAccessor;
import com.glisco.isometricrenders.mixin.access.MinecraftClientAccessor;
import com.glisco.isometricrenders.render.DefaultLightingProfiles;
import com.glisco.isometricrenders.render.IsometricRenderHelper;
import com.glisco.isometricrenders.util.ImageExporter;
Expand All @@ -21,8 +21,8 @@
import java.io.File;
import java.util.concurrent.CompletableFuture;

import static com.glisco.isometricrenders.util.Translator.gui;
import static com.glisco.isometricrenders.util.RuntimeConfig.*;
import static com.glisco.isometricrenders.util.Translate.gui;

public class IsometricRenderScreen extends RenderScreen {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.glisco.isometricrenders.screen;

import com.glisco.isometricrenders.mixin.MinecraftClientAccessor;
import com.glisco.isometricrenders.render.IsometricRenderHelper;
import com.glisco.isometricrenders.util.ImageExporter;
import com.mojang.blaze3d.systems.RenderSystem;
Expand All @@ -15,8 +14,8 @@
import java.util.Locale;
import java.util.concurrent.CompletableFuture;

import static com.glisco.isometricrenders.util.Translator.gui;
import static com.glisco.isometricrenders.util.RuntimeConfig.*;
import static com.glisco.isometricrenders.util.Translate.gui;

public class ItemAtlasRenderScreen extends RenderScreen {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.glisco.isometricrenders.screen;

import com.glisco.isometricrenders.mixin.ParticleManagerAccessor;
import com.glisco.isometricrenders.mixin.SliderWidgetInvoker;
import com.glisco.isometricrenders.mixin.access.ParticleManagerAccessor;
import com.glisco.isometricrenders.mixin.access.SliderWidgetInvoker;
import com.glisco.isometricrenders.render.IsometricRenderHelper;
import com.glisco.isometricrenders.util.ImageExporter;
import com.glisco.isometricrenders.util.RuntimeConfig;
Expand All @@ -23,8 +23,8 @@
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;

import static com.glisco.isometricrenders.util.Translator.*;
import static com.glisco.isometricrenders.util.RuntimeConfig.*;
import static com.glisco.isometricrenders.util.Translate.gui;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;

public abstract class RenderScreen extends Screen {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;

import static com.glisco.isometricrenders.util.Translator.msg;
import static com.glisco.isometricrenders.util.Translator.tr;

public class AreaSelectionHelper {

public static BlockPos pos1 = null;
Expand All @@ -29,7 +26,7 @@ public static boolean shouldDraw() {
public static void clear() {
AreaSelectionHelper.pos1 = null;
AreaSelectionHelper.pos2 = null;
MinecraftClient.getInstance().player.sendMessage(msg("selection_cleared"), true);
Translate.actionBar("selection_cleared");
}

public static void renderSelectionBox(MatrixStack matrices, Camera camera) {
Expand Down Expand Up @@ -65,9 +62,9 @@ public static void select() {

if (pos1 == null) {
pos1 = targetPos;
client.player.sendMessage(msg("selection_started"), true);
Translate.actionBar("selection_started");
} else {
client.player.sendMessage(msg("selection_finished"), true);
Translate.actionBar("selection_finished");
pos2 = targetPos;
}
}
Expand Down
Empty file.
Loading

0 comments on commit 94170c1

Please sign in to comment.