1.19 is back up and running! (A few... bugs though)

This commit is contained in:
TomTheFurry
2023-06-24 22:41:08 +08:00
parent b82d9d6d9a
commit a02fb42490
29 changed files with 465 additions and 249 deletions
@@ -23,7 +23,12 @@ import java.nio.FloatBuffer;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
#if PRE_MC_1_19_3
import com.mojang.math.Matrix4f;
#else
import org.joml.Matrix4f;
#endif
import com.seibel.distanthorizons.core.enums.ELodDirection;
import com.seibel.distanthorizons.core.pos.DhBlockPos;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
@@ -42,13 +47,43 @@ import net.minecraft.world.level.ChunkPos;
*/
public class McObjectConverter
{
private static int bufferIndex(int x, int y) {
return y * 4 + x;
}
/** Taken from Minecraft's com.mojang.math.Matrix4f class from 1.18.2 */
private static void storeMatrix(Matrix4f matrix, FloatBuffer buffer) {
#if PRE_MC_1_19_3
matrix.store(buffer);
#else
// Mojang starts to use joml's Matrix4f libary in 1.19.3 so we copy their store method and use it here if its newer than 1.19.3
buffer.put(bufferIndex(0, 0), matrix.m00());
buffer.put(bufferIndex(0, 1), matrix.m01());
buffer.put(bufferIndex(0, 2), matrix.m02());
buffer.put(bufferIndex(0, 3), matrix.m03());
buffer.put(bufferIndex(1, 0), matrix.m10());
buffer.put(bufferIndex(1, 1), matrix.m11());
buffer.put(bufferIndex(1, 2), matrix.m12());
buffer.put(bufferIndex(1, 3), matrix.m13());
buffer.put(bufferIndex(2, 0), matrix.m20());
buffer.put(bufferIndex(2, 1), matrix.m21());
buffer.put(bufferIndex(2, 2), matrix.m22());
buffer.put(bufferIndex(2, 3), matrix.m23());
buffer.put(bufferIndex(3, 0), matrix.m30());
buffer.put(bufferIndex(3, 1), matrix.m31());
buffer.put(bufferIndex(3, 2), matrix.m32());
buffer.put(bufferIndex(3, 3), matrix.m33());
#endif
}
/** 4x4 float matrix converter */
public static Mat4f Convert(Matrix4f mcMatrix)
{
FloatBuffer buffer = FloatBuffer.allocate(16);
mcMatrix.store(buffer);
storeMatrix(mcMatrix, buffer);
Mat4f matrix = new Mat4f(buffer);
matrix.transpose();
#if PRE_MC_1_19_4
matrix.transpose(); // In 1.19.3 and later, we no longer need to transpose it
#endif
return matrix;
}
@@ -20,6 +20,7 @@
package com.seibel.distanthorizons.common.wrappers;
import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
import net.minecraft.SharedConstants;
import net.minecraft.client.Minecraft;
/**
@@ -57,6 +58,10 @@ public class VersionConstants implements IVersionConstants
@Override
public String getMinecraftVersion() {
#if PRE_MC_1_19
return Minecraft.getInstance().getGame().getVersion().getId();
#else
return SharedConstants.getCurrentVersion().getId();
#endif
}
}
@@ -41,12 +41,19 @@ public class TextureAtlasSpriteWrapper {
return sprite.mainImage[0].getPixelRGBA(
x + sprite.framesX[frameIndex] * sprite.getWidth(),
y + sprite.framesY[frameIndex] * sprite.getHeight());
#else
#elif PRE_MC_1_19_4
if (sprite.animatedTexture != null) {
x += sprite.animatedTexture.getFrameX(frameIndex) * sprite.width;
y += sprite.animatedTexture.getFrameY(frameIndex) * sprite.height;
}
return sprite.mainImage[0].getPixelRGBA(x, y);
#else
if (sprite.contents().animatedTexture != null) {
x += sprite.contents().animatedTexture.getFrameX(frameIndex) * sprite.contents().width();
y += sprite.contents().animatedTexture.getFrameY(frameIndex) * sprite.contents().width();
}
return sprite.contents().originalImage.getPixelRGBA(x, y);
#endif
}
}
@@ -73,6 +73,23 @@ public class ClientBlockStateCache
return Default;
}
}
private static int getWidth(TextureAtlasSprite texture) {
#if PRE_MC_1_19_3
return texture.getWidth();
#else
return texture.contents().width();
#endif
}
private static int getHeight(TextureAtlasSprite texture) {
#if PRE_MC_1_19_3
return texture.getHeight();
#else
return texture.contents().height();
#endif
}
//TODO: Perhaps make this not just use the first frame?
private static int calculateColorFromTexture(TextureAtlasSprite texture, ColorMode colorMode) {
int count = 0;
@@ -83,9 +100,9 @@ public class ClientBlockStateCache
int tempColor;
{
// textures normally use u and v instead of x and y
for (int u = 0; u < texture.getWidth(); u++)
for (int u = 0; u < getWidth(texture); u++)
{
for (int v = 0; v < texture.getHeight(); v++)
for (int v = 0; v < getHeight(texture); v++)
{
//note: Minecraft color format is: 0xAA BB GG RR
//________ DH mod color format is: 0xAA RR GG BB
@@ -58,6 +58,7 @@ import net.minecraft.resources.ResourceLocation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import static com.seibel.distanthorizons.common.wrappers.gui.GuiHelper.*;
/**
@@ -106,42 +107,6 @@ public class ClassicConfigGUI
int index;
}
/**
* Helper static methods for versional compat
*/
private static Button MakeBtn(Component base, int a, int b, int c, int d, Button.OnPress action) {
#if PRE_MC_1_19
return new Button(a, b, c, d, base, action);
#else
return Button.builder(base, action).bounds(a,b,c,d).build();
#endif
}
private static MutableComponent TextOrLiteral(String text) {
#if PRE_MC_1_19
return new TextComponent(text);
#else
return Component.literal(text);
#endif
}
private static MutableComponent TextOrTranslatable(String text) {
#if PRE_MC_1_19
return new TextComponent(text);
#else
return Component.translatable(text);
#endif
}
private static MutableComponent Translatable(String text) {
#if PRE_MC_1_19
return new TranslatableComponent(text);
#else
return Component.translatable(text);
#endif
}
/**
* creates a text field
*/
@@ -463,9 +428,6 @@ public class ClassicConfigGUI
// return info;
}
public static class ConfigListWidget extends ContainerObjectSelectionList<ButtonEntry> {
Font textRenderer;
@@ -525,27 +487,15 @@ public class ClassicConfigGUI
@Override
public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
if (button != null) {
#if PRE_MC_1_19
button.y = y;
#else
button.SetY(y);
#endif
SetY(button, y);
button.render(matrices, mouseX, mouseY, tickDelta);
}
if (resetButton != null) {
#if PRE_MC_1_19
resetButton.y = y;
#else
resetButton.SetY(y);
#endif
SetY(resetButton, y);
resetButton.render(matrices, mouseX, mouseY, tickDelta);
}
if (indexButton != null) {
#if PRE_MC_1_19
indexButton.y = y;
#else
indexButton.SetY(y);
#endif
SetY(indexButton, y);
indexButton.render(matrices, mouseX, mouseY, tickDelta);
}
if (text != null && (!text.getString().contains("spacer") || button != null))
@@ -0,0 +1,22 @@
package com.seibel.distanthorizons.common.wrappers.gui;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
public class DhScreen extends Screen {
protected DhScreen(Component $$0) {
super($$0);
}
// addRenderableWidget in 1.17 and over
// addButton in 1.16 and below
protected void addBtn(Button button) {
#if PRE_MC_1_17_1
this.addButton(button);
#else
this.addRenderableWidget(button);
#endif
}
}
@@ -0,0 +1,60 @@
package com.seibel.distanthorizons.common.wrappers.gui;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.Button;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
public class GuiHelper {
/**
* Helper static methods for versional compat
*/
public static Button MakeBtn(Component base, int a, int b, int c, int d, Button.OnPress action) {
#if PRE_MC_1_19
return new Button(a, b, c, d, base, action);
#else
return Button.builder(base, action).bounds(a,b,c,d).build();
#endif
}
public static MutableComponent TextOrLiteral(String text) {
#if PRE_MC_1_19
return new TextComponent(text);
#else
return Component.literal(text);
#endif
}
public static MutableComponent TextOrTranslatable(String text) {
#if PRE_MC_1_19
return new TextComponent(text);
#else
return Component.translatable(text);
#endif
}
public static MutableComponent Translatable(String text, Object... args) {
#if PRE_MC_1_19
return new TranslatableComponent(text, args);
#else
return Component.translatable(text, args);
#endif
}
public static void SetX(AbstractWidget w, int x) {
#if PRE_MC_1_19
w.x = x;
#else
w.setX(x);
#endif
}
public static void SetY(AbstractWidget w, int y) {
#if PRE_MC_1_19
w.y = y;
#else
w.setY(y);
#endif
}
}
@@ -44,6 +44,7 @@ public class TexturedButtonWidget extends ImageButton {
super(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, text);
}
#if PRE_MC_1_19
public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, int hoveredVOffset, ResourceLocation texture, int textureWidth, int textureHeight, OnPress pressAction, OnTooltip tooltipSupplier, Component text) {
super(x, y, width, height, u, v, hoveredVOffset, texture, textureWidth, textureHeight, pressAction, tooltipSupplier, text);
}
@@ -58,7 +59,6 @@ public class TexturedButtonWidget extends ImageButton {
RenderSystem.setShaderTexture(0, WIDGETS_LOCATION);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, this.alpha);
#endif
int i = this.getYImage(this.isHovered);
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
@@ -68,4 +68,5 @@ public class TexturedButtonWidget extends ImageButton {
super.renderButton(matrices, mouseX, mouseY, delta);
}
#endif
}
@@ -1,6 +1,7 @@
package com.seibel.distanthorizons.common.wrappers.gui.updater;
import com.mojang.blaze3d.vertex.PoseStack;
import com.seibel.distanthorizons.common.wrappers.gui.DhScreen;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
import com.seibel.distanthorizons.coreapi.ModInfo;
@@ -16,7 +17,11 @@ import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.narration.NarratableEntry;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
#if PRE_MC_1_19
import net.minecraft.network.chat.TextComponent;
#endif
import static com.seibel.distanthorizons.common.wrappers.gui.GuiHelper.*;
import java.util.*;
@@ -27,7 +32,7 @@ import java.util.*;
*/
// TODO: After finishing the config, rewrite this in openGL as well
// TODO: Make this
public class ChangelogScreen extends Screen {
public class ChangelogScreen extends DhScreen {
private Screen parent;
private String versionID;
private List<String> changelog;
@@ -45,7 +50,7 @@ public class ChangelogScreen extends Screen {
}
public ChangelogScreen(Screen parent, String versionID) {
super(translate(ModInfo.ID + ".updater.title"));
super(Translatable(ModInfo.ID + ".updater.title"));
this.parent = parent;
this.versionID = versionID;
@@ -84,7 +89,7 @@ public class ChangelogScreen extends Screen {
this.addBtn( // Close
new Button(5, this.height - 25, 100, 20, translate(ModInfo.ID + ".general.back"), (btn) -> {
MakeBtn(Translatable(ModInfo.ID + ".general.back"), 5, this.height - 25, 100, 20, (btn) -> {
this.onClose();
})
);
@@ -92,7 +97,7 @@ public class ChangelogScreen extends Screen {
this.changelogArea = new TextArea(this.minecraft, this.width*2, this.height, 32, this.height - 32, 10);
for (int i = 0; i < changelog.size(); i++) {
this.changelogArea.addButton(new TextComponent(changelog.get(i)));
this.changelogArea.addButton( TextOrLiteral(changelog.get(i)));
// drawString(matrices, this.font, changelog.get(i), this.width / 2 - 175, this.height / 2 - 100 + i*10, 0xFFFFFF);
}
@@ -118,36 +123,6 @@ public class ChangelogScreen extends Screen {
Objects.requireNonNull(minecraft).setScreen(this.parent); // Goto the parent screen
}
// addRenderableWidget in 1.17 and over
// addButton in 1.16 and below
private void addBtn(Button button) {
#if PRE_MC_1_17_1
this.addButton(button);
#else
this.addRenderableWidget(button);
#endif
}
#if PRE_MC_1_19
public static net.minecraft.network.chat.TranslatableComponent translate (String str, Object... args) {
return new net.minecraft.network.chat.TranslatableComponent(str, args);
}
#else
public static net.minecraft.network.chat.MutableComponent translate (String str, Object... args) {
return net.minecraft.network.chat.Component.translatable(str, args);
}
#endif
public static class TextArea extends ContainerObjectSelectionList<ButtonEntry> {
Font textRenderer;
@@ -2,6 +2,7 @@ package com.seibel.distanthorizons.common.wrappers.gui.updater;
import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.blaze3d.vertex.PoseStack;
import com.seibel.distanthorizons.common.wrappers.gui.DhScreen;
import com.seibel.distanthorizons.common.wrappers.gui.TexturedButtonWidget;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.core.config.Config;
@@ -15,6 +16,8 @@ import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.resources.ResourceLocation;
import static com.seibel.distanthorizons.common.wrappers.gui.GuiHelper.*;
import java.util.*;
/**
@@ -24,13 +27,13 @@ import java.util.*;
*/
// TODO: After finishing the config, rewrite this in openGL as well
// and also maybe add this suggestion https://discord.com/channels/881614130614767666/1035863487110467625/1035949054485594192
public class UpdateModScreen extends Screen {
public class UpdateModScreen extends DhScreen {
private Screen parent;
private String newVersionID;
public UpdateModScreen(Screen parent, String newVersionID) {
super(translate(ModInfo.ID + ".updater.title"));
super(Translatable(ModInfo.ID + ".updater.title"));
this.parent = parent;
this.newVersionID = newVersionID;
}
@@ -64,7 +67,7 @@ public class UpdateModScreen extends Screen {
// For now it goes to the client option by default
(buttonWidget) -> System.out.println("Nice, you found an easter egg :)"), // TODO: Add a proper easter egg to pressing the logo (maybe with confetti)
// Add a title to the button
translate(ModInfo.ID + ".updater.title")
Translatable(ModInfo.ID + ".updater.title")
));
} catch (Exception e) { e.printStackTrace(); }
@@ -81,31 +84,31 @@ public class UpdateModScreen extends Screen {
// Create the button and tell it where to go
(buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(new ChangelogScreen(this, this.newVersionID)), // TODO: Add a proper easter egg to pressing the logo (maybe with confetti)
// Add a title to the button
translate(ModInfo.ID + ".updater.title")
Translatable(ModInfo.ID + ".updater.title")
));
this.addBtn( // Update
new Button(this.width / 2 - 75, this.height / 2 + 8, 150, 20, translate(ModInfo.ID + ".updater.update"), (btn) -> {
MakeBtn(Translatable(ModInfo.ID + ".updater.update"), this.width / 2 - 75, this.height / 2 + 8, 150, 20, (btn) -> {
SelfUpdater.deleteOldOnClose = true;
SelfUpdater.updateMod();
this.onClose();
})
);
this.addBtn( // Silent update
new Button(this.width / 2 - 75, this.height / 2 + 30, 150, 20, translate(ModInfo.ID + ".updater.silent"), (btn) -> {
MakeBtn(Translatable(ModInfo.ID + ".updater.silent"), this.width / 2 - 75, this.height / 2 + 30, 150, 20, (btn) -> {
Config.Client.Advanced.AutoUpdater.enableSilentUpdates.set(true);
SelfUpdater.updateMod();
this.onClose();
})
);
this.addBtn( // Later (not now)
new Button(this.width / 2 + 2, this.height / 2 + 70, 100, 20, translate(ModInfo.ID + ".updater.later"), (btn) -> {
MakeBtn(Translatable(ModInfo.ID + ".updater.later"), this.width / 2 + 2, this.height / 2 + 70, 100, 20, (btn) -> {
this.onClose();
})
);
this.addBtn( // Never
new Button(this.width / 2 - 102, this.height / 2 + 70, 100, 20, translate(ModInfo.ID + ".updater.never"), (btn) -> {
MakeBtn(Translatable(ModInfo.ID + ".updater.never"), this.width / 2 - 102, this.height / 2 + 70, 100, 20, (btn) -> {
Config.Client.Advanced.AutoUpdater.enableAutoUpdater.set(false);
this.onClose();
})
@@ -119,8 +122,8 @@ public class UpdateModScreen extends Screen {
// Render the text's
drawCenteredString(matrices, this.font, translate(ModInfo.ID + ".updater.text1"), this.width / 2, this.height / 2 - 35, 0xFFFFFF);
drawCenteredString(matrices, this.font, translate(ModInfo.ID + ".updater.text2", ModInfo.VERSION, ModrinthGetter.releaseNames.get(this.newVersionID)), this.width / 2, this.height / 2 -20, 0x52FD52);
drawCenteredString(matrices, this.font, Translatable(ModInfo.ID + ".updater.text1"), this.width / 2, this.height / 2 - 35, 0xFFFFFF);
drawCenteredString(matrices, this.font, Translatable(ModInfo.ID + ".updater.text2", ModInfo.VERSION, ModrinthGetter.releaseNames.get(this.newVersionID)), this.width / 2, this.height / 2 -20, 0x52FD52);
// TODO: add the tooltips for the buttons
super.render(matrices, mouseX, mouseY, delta); // Render the buttons
@@ -132,27 +135,4 @@ public class UpdateModScreen extends Screen {
public void onClose() {
Objects.requireNonNull(minecraft).setScreen(this.parent); // Goto the parent screen
}
// addRenderableWidget in 1.17 and over
// addButton in 1.16 and below
private void addBtn(Button button) {
#if PRE_MC_1_17_1
this.addButton(button);
#else
this.addRenderableWidget(button);
#endif
}
#if PRE_MC_1_19
public static net.minecraft.network.chat.TranslatableComponent translate (String str, Object... args) {
return new net.minecraft.network.chat.TranslatableComponent(str, args);
}
#else
public static net.minecraft.network.chat.MutableComponent translate (String str, Object... args) {
return net.minecraft.network.chat.Component.translatable(str, args);
}
#endif
}
@@ -37,7 +37,12 @@ import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.ILightMapWrapper;
#if PRE_MC_1_19_3
import com.mojang.math.Vector3f;
#else
import org.joml.Vector3f;
#endif
import com.seibel.distanthorizons.coreapi.util.math.Mat4f;
import com.seibel.distanthorizons.coreapi.util.math.Vec3d;
import com.seibel.distanthorizons.coreapi.util.math.Vec3f;
@@ -55,6 +55,10 @@ import com.seibel.distanthorizons.common.wrappers.worldGeneration.step.StepStruc
import com.seibel.distanthorizons.common.wrappers.worldGeneration.step.StepStructureStart;
import com.seibel.distanthorizons.common.wrappers.worldGeneration.step.StepSurface;
#if POST_MC_1_19
import net.minecraft.core.registries.Registries;
#endif
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.ChunkAccess;
@@ -302,6 +306,20 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
}
}
private static ProtoChunk EmptyChunk(ServerLevel level, ChunkPos chunkPos) {
return new ProtoChunk(chunkPos, UpgradeData.EMPTY
#if POST_MC_1_17_1, level #endif
#if POST_MC_1_18_1, level.registryAccess().registryOrThrow(
#if PRE_MC_1_19_3
Registry.BIOME_REGISTRY
#else
Registries.BIOME
#endif
), null #endif
);
}
public ChunkAccess loadOrMakeChunk(ChunkPos chunkPos, WorldGenLevelLightEngine lightEngine)
{
ServerLevel level = params.level;
@@ -309,16 +327,12 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
CompoundTag chunkData = null;
try
{
#if POST_MC_1_19
chunkData = level.getChunkSource().chunkMap.readChunk(chunkPos).get().orElse(null);
#else
// Warning: if multiple threads attempt to access this method at the same time,
// it can throw EOFExceptions that are caught and logged by Minecraft
//chunkData = level.getChunkSource().chunkMap.readChunk(chunkPos);
RegionFileStorage storage = params.level.getChunkSource().chunkMap.worker.storage;
RegionFileStorageExternalCache cache = getOrCreateRegionFileCache(storage);
chunkData = cache.read(chunkPos);
#endif
}
catch (Exception e)
{
@@ -327,10 +341,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
if (chunkData == null)
{
return new ProtoChunk(chunkPos, UpgradeData.EMPTY
#if POST_MC_1_17_1, level #endif
#if POST_MC_1_18_1, level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), null #endif
);
return EmptyChunk(level, chunkPos);
}
else
{
@@ -342,10 +353,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
catch (Exception e)
{
LOAD_LOGGER.error("DistantHorizons: Couldn't load or make chunk "+chunkPos+". Returning an empty chunk. Error: "+e.getMessage(), e);
return new ProtoChunk(chunkPos, UpgradeData.EMPTY
#if POST_MC_1_17_1 , level #endif
#if POST_MC_1_18_1 , level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY), null #endif
);
return EmptyChunk(level, chunkPos);
}
}
}
@@ -38,8 +38,12 @@ import net.minecraft.world.level.levelgen.WorldGenSettings;
#if PRE_MC_1_19
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
#else
import net.minecraft.world.level.levelgen.RandomState;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
import net.minecraft.world.level.levelgen.RandomState;
#if POST_MC_1_19
import net.minecraft.world.level.levelgen.WorldOptions;
import net.minecraft.core.registries.Registries;
#endif
#endif
import net.minecraft.world.level.storage.WorldData;
@@ -52,7 +56,11 @@ public final class GlobalParameters
public final StructureTemplateManager structures;
public final RandomState randomState;
#endif
#if PRE_MC_1_19_3
public final WorldGenSettings worldGenSettings;
#else
public final WorldOptions worldOptions;
#endif
public final ThreadedLevelLightEngine lightEngine;
public final IDhServerLevel lodLevel;
public final ServerLevel level;
@@ -73,10 +81,17 @@ public final class GlobalParameters
lightEngine = (ThreadedLevelLightEngine) level.getLightEngine();
MinecraftServer server = level.getServer();
WorldData worldData = server.getWorldData();
worldGenSettings = worldData.worldGenSettings();
registry = server.registryAccess();
#if PRE_MC_1_19_3
worldGenSettings = worldData.worldGenSettings();
biomes = registry.registryOrThrow(Registry.BIOME_REGISTRY);
worldSeed = worldGenSettings.seed();
#else
worldOptions = worldData.worldGenOptions();
biomes = registry.registryOrThrow(Registries.BIOME);
worldSeed = worldOptions.seed();
#endif
#if POST_MC_1_18_1
biomeManager = new BiomeManager(level, BiomeManager.obfuscateSeed(worldSeed));
chunkScanner = level.getChunkSource().chunkScanner();
@@ -80,7 +80,11 @@ public final class ThreadedParameters
public void makeStructFeat(WorldGenLevel genLevel, GlobalParameters param)
{
#if PRE_MC_1_19_3
structFeat = new WorldGenStructFeatManager(param.worldGenSettings, genLevel #if POST_MC_1_18_1, structCheck #endif);
#else
structFeat = new WorldGenStructFeatManager(param.worldOptions, genLevel, structCheck);
#endif
}
@@ -1,38 +1,49 @@
/*
* This file is part of the Distant Horizons mod (formerly the LOD Mod),
* licensed under the GNU LGPL v3 License.
* licensed under the GNU GPL v3 License.
*
* Copyright (C) 2020-2022 James Seibel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.seibel.distanthorizons.common.wrappers.worldGeneration.mimicObject;
import com.google.common.collect.Maps;
import com.mojang.serialization.Codec;
import com.mojang.serialization.Dynamic;
import com.seibel.distanthorizons.common.wrappers.worldGeneration.BatchGenerationEnvironment;
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import it.unimi.dsi.fastutil.longs.LongSet;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos;
#if POST_MC_1_19_4
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
#endif
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.*;
import net.minecraft.world.level.biome.Biome;
@@ -41,17 +52,29 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.*;
import net.minecraft.world.level.chunk.storage.ChunkSerializer;
import net.minecraft.world.level.levelgen.Heightmap;
#if POST_MC_1_18_1
import net.minecraft.world.level.levelgen.blending.BlendingData;
#if PRE_MC_1_19
import net.minecraft.world.level.levelgen.feature.StructureFeature;
#endif
import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceSerializationContext;
import net.minecraft.world.ticks.LevelChunkTicks;
#endif
#if POST_MC_1_18_2
import net.minecraft.core.Holder;
import net.minecraft.core.RegistryAccess;
#if PRE_MC_1_19
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
#endif
#endif
import net.minecraft.world.level.lighting.LevelLightEngine;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.Fluids;
import org.apache.logging.log4j.Logger;
public class ChunkLoader
{
@@ -80,11 +103,15 @@ public class ChunkLoader
return blendingData;
}
#endif
private static LevelChunkSection[] readSections(LevelAccessor level, LevelLightEngine lightEngine, ChunkPos chunkPos, CompoundTag chunkData)
{
#if POST_MC_1_18_1
#if PRE_MC_1_19_4
Registry<Biome> biomes = level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
#else
Registry<Biome> biomes = level.registryAccess().registryOrThrow(Registries.BIOME);
#endif
#if PRE_MC_1_18_2
Codec<PalettedContainer<Biome>> biomeCodec = PalettedContainer.codec(
biomes, biomes.byNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, biomes.getOrThrow(Biomes.PLAINS));
@@ -92,8 +119,8 @@ public class ChunkLoader
Codec<PalettedContainer<Holder<Biome>>> biomeCodec = PalettedContainer.codec(
biomes.asHolderIdMap(), biomes.holderByNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, biomes.getHolderOrThrow(Biomes.PLAINS));
#else
Codec<PalettedContainer<Holder<Biome>>> biomeCodec = PalettedContainer.codecRW(
biomes.asHolderIdMap(), biomes.holderByNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, biomes.getHolderOrThrow(Biomes.PLAINS));
Codec<PalettedContainer<Holder<Biome>>> biomeCodec = PalettedContainer.codecRW(
biomes.asHolderIdMap(), biomes.holderByNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, biomes.getHolderOrThrow(Biomes.PLAINS));
#endif
#endif
int i = #if PRE_MC_1_17_1 16; #else level.getSectionsCount(); #endif
@@ -143,21 +170,25 @@ public class ChunkLoader
? biomeCodec.parse(NbtOps.INSTANCE, tagSection.getCompound("biomes")).promotePartial(string -> logErrors(chunkPos, i, (String) string)).getOrThrow(false, LOGGER::error)
: new PalettedContainer<Holder<Biome>>(biomes.asHolderIdMap(), biomes.getHolderOrThrow(Biomes.PLAINS), PalettedContainer.Strategy.SECTION_BIOMES);
#endif
#if PRE_MC_1_20_1
chunkSections[sectionId] = new LevelChunkSection(sectionYPos, blockStateContainer, biomeContainer);
#else
chunkSections[sectionId] = new LevelChunkSection(blockStateContainer, biomeContainer);
#endif
}
#endif
if (!isLightOn) continue;
if (tagSection.contains("BlockLight", 7))
lightEngine.queueSectionData(LightLayer.BLOCK, SectionPos.of(chunkPos, sectionYPos),
new DataLayer(tagSection.getByteArray("BlockLight")), true);
new DataLayer(tagSection.getByteArray("BlockLight")) #if PRE_MC_1_20_1, true #endif);
if (hasSkyLight && tagSection.contains("SkyLight", 7))
lightEngine.queueSectionData(LightLayer.SKY, SectionPos.of(chunkPos, sectionYPos),
new DataLayer(tagSection.getByteArray("SkyLight")), true);
new DataLayer(tagSection.getByteArray("SkyLight")) #if PRE_MC_1_20_1, true #endif);
}
return chunkSections;
}
private static void readHeightmaps(LevelChunk chunk, CompoundTag chunkData)
{
CompoundTag tagHeightmaps = chunkData.getCompound("Heightmaps");
@@ -182,7 +213,7 @@ public class ChunkLoader
}
}
}
public static ChunkStatus.ChunkType readChunkType(CompoundTag tagLevel)
{
ChunkStatus chunkStatus = ChunkStatus.byName(tagLevel.getString("Status"));
@@ -191,7 +222,7 @@ public class ChunkLoader
}
return ChunkStatus.ChunkType.PROTOCHUNK;
}
public static LevelChunk read(WorldGenLevel level, LevelLightEngine lightEngine, ChunkPos chunkPos, CompoundTag chunkData)
{
#if PRE_MC_1_18_1
@@ -199,14 +230,13 @@ public class ChunkLoader
#else
CompoundTag tagLevel = chunkData;
#endif
ChunkPos actualPos = new ChunkPos(tagLevel.getInt("xPos"), tagLevel.getInt("zPos"));
if (!Objects.equals(chunkPos, actualPos))
{
LOGGER.warn("Chunk file at "+chunkPos+" is in the wrong location; Ignoring. (Expected "+chunkPos+", got "+actualPos+")");
if (!Objects.equals(chunkPos, actualPos)) {
LOGGER.error("Chunk file at {} is in the wrong location; Ignoring. (Expected {}, got {})", chunkPos, chunkPos, actualPos);
return null;
}
ChunkStatus.ChunkType chunkType = readChunkType(tagLevel);
#if PRE_MC_1_18_1
if (chunkType != ChunkStatus.ChunkType.LEVELCHUNK)
@@ -247,10 +277,17 @@ public class ChunkLoader
: new ProtoTickList<Fluid>(fluid -> (fluid == null || fluid == Fluids.EMPTY), chunkPos,
tagLevel.getList("LiquidsToBeTicked", 9)#if POST_MC_1_17_1, level #endif);
#else
#if PRE_MC_1_19_4
LevelChunkTicks<Block> blockTicks = LevelChunkTicks.load(tagLevel.getList(BLOCK_TICKS_TAG_18, 10),
string -> Registry.BLOCK.getOptional(ResourceLocation.tryParse(string)), chunkPos);
LevelChunkTicks<Fluid> fluidTicks = LevelChunkTicks.load(tagLevel.getList(FLUID_TICKS_TAG_18, 10),
string -> Registry.FLUID.getOptional(ResourceLocation.tryParse(string)), chunkPos);
#else
LevelChunkTicks<Block> blockTicks = LevelChunkTicks.load(tagLevel.getList(BLOCK_TICKS_TAG_18, 10),
(string -> BuiltInRegistries.BLOCK.getOptional(ResourceLocation.tryParse(string))), chunkPos);
LevelChunkTicks<Fluid> fluidTicks = LevelChunkTicks.load(tagLevel.getList(FLUID_TICKS_TAG_18, 10),
string -> BuiltInRegistries.FLUID.getOptional(ResourceLocation.tryParse(string)), chunkPos);
#endif
#endif
LevelChunkSection[] levelChunkSections = readSections(level, lightEngine, chunkPos, tagLevel);
@@ -260,8 +297,9 @@ public class ChunkLoader
LevelChunk chunk = new LevelChunk((Level) level.getLevel(), chunkPos, chunkBiomeContainer, upgradeData, blockTicks,
fluidTicks, inhabitedTime, levelChunkSections, null);
#else
LevelChunk chunk = new LevelChunk((Level) level, chunkPos, upgradeData, blockTicks,
fluidTicks, inhabitedTime, levelChunkSections, null, blendingData);
fluidTicks, inhabitedTime, levelChunkSections, null, blendingData);
#endif
// Set some states after object creation
chunk.setLightCorrect(isLightOn);
@@ -269,7 +307,7 @@ public class ChunkLoader
readPostPocessings(chunk, chunkData);
return chunk;
}
private static void logErrors(ChunkPos chunkPos, int i, String string)
{
LOGGER.error("Distant Horizons: Recoverable errors when loading section [" + chunkPos.x + ", " + i + ", " + chunkPos.z + "]: " + string);
@@ -32,6 +32,7 @@ import it.unimi.dsi.fastutil.longs.LongSet;
import net.minecraft.core.BlockPos;
import net.minecraft.core.SectionPos;
import net.minecraft.server.level.WorldGenRegion;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkStatus;
@@ -40,6 +41,7 @@ import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
import net.minecraft.world.level.StructureFeatureManager;
#else
import net.minecraft.world.level.levelgen.WorldOptions;
import net.minecraft.world.level.levelgen.structure.Structure;
import net.minecraft.world.level.StructureManager;
#endif
@@ -54,11 +56,18 @@ public class WorldGenStructFeatManager extends StructureFeatureManager {
public class WorldGenStructFeatManager extends StructureManager {
#endif
final WorldGenLevel genLevel;
#if PRE_MC_1_19
WorldGenSettings worldGenSettings;
#else
WorldOptions worldOptions;
#endif
#if POST_MC_1_18_1
StructureCheck structureCheck;
#endif
#if PRE_MC_1_19
public WorldGenStructFeatManager(WorldGenSettings worldGenSettings,
WorldGenLevel genLevel #if POST_MC_1_18_1 , StructureCheck structureCheck #endif ) {
@@ -66,12 +75,25 @@ public class WorldGenStructFeatManager extends StructureManager {
this.genLevel = genLevel;
this.worldGenSettings = worldGenSettings;
}
#else
public WorldGenStructFeatManager(WorldOptions worldOptions,
WorldGenLevel genLevel, StructureCheck structureCheck) {
super(genLevel, worldOptions, structureCheck);
this.genLevel = genLevel;
this.worldOptions = worldOptions;
}
#endif
@Override
public WorldGenStructFeatManager forWorldGenRegion(WorldGenRegion worldGenRegion) {
if (worldGenRegion == genLevel)
return this;
#if PRE_MC_1_19
return new WorldGenStructFeatManager(worldGenSettings, worldGenRegion #if POST_MC_1_18_1 , structureCheck #endif );
#else
return new WorldGenStructFeatManager(worldOptions, worldGenRegion, structureCheck);
#endif
}
private ChunkAccess _getChunk(int x, int z, ChunkStatus status) {
@@ -69,9 +69,12 @@ public final class StepBiomes {
#elif PRE_MC_1_19
chunk = environment.joinSync(environment.params.generator.createBiomes(environment.params.biomes, Runnable::run, Blender.of(worldGenRegion),
tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk));
#else
#elif PRE_MC_1_19_3
chunk = environment.joinSync(environment.params.generator.createBiomes(environment.params.biomes, Runnable::run, environment.params.randomState, Blender.of(worldGenRegion),
tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk));
#else
chunk = environment.joinSync(environment.params.generator.createBiomes(Runnable::run, environment.params.randomState, Blender.of(worldGenRegion),
tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk));
#endif
}
}
@@ -75,7 +75,7 @@ public final class StepStructureStart
#if PRE_MC_1_19
if (environment.params.worldGenSettings.generateFeatures()) {
#elif POST_MC_1_19
if (environment.params.worldGenSettings.generateStructures()) {
if (environment.params.worldOptions.generateStructures()) {
#endif
for (ChunkAccess chunk : chunksToDo)
{
@@ -83,9 +83,13 @@ public final class StepStructureStart
#if PRE_MC_1_19
environment.params.generator.createStructures(environment.params.registry, tParams.structFeat, chunk, environment.params.structures,
environment.params.worldSeed);
#elif POST_MC_1_19
#elif PRE_MC_1_19_3
environment.params.generator.createStructures(environment.params.registry, environment.params.randomState, tParams.structFeat, chunk, environment.params.structures,
environment.params.worldSeed);
#else
environment.params.generator.createStructures(environment.params.registry,
environment.params.level.getChunkSource().getGeneratorState(),
tParams.structFeat, chunk, environment.params.structures);
#endif
#if POST_MC_1_18_1
try
@@ -1,6 +1,5 @@
accessWidener v1 named
# used when determining where to save files to
accessible field net/minecraft/world/level/storage/DimensionDataStorage dataFolder Ljava/io/File;
@@ -23,16 +22,12 @@ accessible field net/minecraft/world/level/chunk/storage/IOWorker storage Lnet/m
accessible field net/minecraft/world/level/chunk/storage/RegionFileStorage regionCache Lit/unimi/dsi/fastutil/longs/Long2ObjectLinkedOpenHashMap;
accessible field net/minecraft/world/level/chunk/storage/RegionFileStorage folder Ljava/nio/file/Path;
# grabbing textures
accessible field net/minecraft/client/renderer/texture/TextureAtlasSprite animatedTexture Lnet/minecraft/client/renderer/texture/TextureAtlasSprite$AnimatedTexture;
accessible field net/minecraft/client/renderer/texture/TextureAtlasSprite width I
accessible field net/minecraft/client/renderer/texture/TextureAtlasSprite height I
accessible field net/minecraft/client/renderer/texture/TextureAtlasSprite mainImage [Lcom/mojang/blaze3d/platform/NativeImage;
accessible class net/minecraft/client/renderer/texture/TextureAtlasSprite$AnimatedTexture
accessible method net/minecraft/client/renderer/texture/TextureAtlasSprite$AnimatedTexture getFrameX (I)I
accessible method net/minecraft/client/renderer/texture/TextureAtlasSprite$AnimatedTexture getFrameY (I)I
extendable class com/mojang/math/Matrix4f
accessible class net/minecraft/client/renderer/texture/SpriteContents$AnimatedTexture
accessible method net/minecraft/client/renderer/texture/SpriteContents$AnimatedTexture getFrameX (I)I
accessible method net/minecraft/client/renderer/texture/SpriteContents$AnimatedTexture getFrameY (I)I
accessible field net/minecraft/client/renderer/texture/SpriteContents animatedTexture Lnet/minecraft/client/renderer/texture/SpriteContents$AnimatedTexture;
accessible field net/minecraft/client/renderer/texture/SpriteContents originalImage Lcom/mojang/blaze3d/platform/NativeImage;
# hacky stuff
accessible field net/minecraft/util/ThreadingDetector lock Ljava/util/concurrent/Semaphore;
@@ -81,11 +81,11 @@ public class FabricMain
if (SingletonInjector.INSTANCE.get(IModChecker.class).isModLoaded("optifine")) {
ModAccessorInjector.INSTANCE.bind(IOptifineAccessor.class, new OptifineAccessor());
}
#if POST_MC_1_17_1
/* #if POST_MC_1_17_1
if (SingletonInjector.INSTANCE.get(IModChecker.class).isModLoaded("bclib")) {
ModAccessorInjector.INSTANCE.bind(IBCLibAccessor.class, new BCLibAccessor());
}
#endif
#endif*/
LOGGER.info(ModInfo.READABLE_NAME + " Initialized");
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterDhInitEvent.class, null);
@@ -37,8 +37,12 @@ public class MixinClientPacketListener
void onHandleRespawnStart(CallbackInfo ci) { ClientApi.INSTANCE.clientLevelUnloadEvent(ClientLevelWrapper.getWrapper(level)); }
@Inject(method = "handleRespawn", at = @At("RETURN"))
void onHandleRespawnEnd(CallbackInfo ci) { ClientApi.INSTANCE.clientLevelLoadEvent(ClientLevelWrapper.getWrapper(level)); }
#if PRE_MC_1_19
@Inject(method = "cleanup", at = @At("HEAD"))
#else
@Inject(method = "close", at = @At("HEAD"))
#endif
void onCleanupStart(CallbackInfo ci)
{
// TODO which unload method should be used? do we need both?
@@ -20,7 +20,11 @@
package com.seibel.distanthorizons.fabric.mixins.client;
import com.mojang.blaze3d.vertex.PoseStack;
#if PRE_MC_1_19_3
import com.mojang.math.Matrix4f;
#else
import org.joml.Matrix4f;
#endif
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
import com.seibel.distanthorizons.core.config.Config;
import net.minecraft.client.multiplayer.ClientLevel;
@@ -66,28 +70,6 @@ public class MixinLevelRenderer
// have access to them
previousPartialTicks = partialTicks;
}
@Inject(at = @At("HEAD"),
method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDD)V",
cancellable = true)
private void renderChunkLayer(RenderType renderType, PoseStack matrixStackIn, double xIn, double yIn, double zIn, CallbackInfo callback)
{
// // only render before solid blocks
// if (renderType.equals(RenderType.solid()))
// {
// // get MC's current projection matrix
// float[] mcProjMatrixRaw = new float[16];
// GL15.glGetFloatv(GL15.GL_PROJECTION_MATRIX, mcProjMatrixRaw);
// Mat4f mcProjectionMatrix = new Mat4f(mcProjMatrixRaw);
// mcProjectionMatrix.transpose();
// Mat4f mcModelViewMatrix = McObjectConverter.Convert(matrixStackIn.last().pose());
//
// ClientApi.INSTANCE.renderLods(LevelWrapper.getWorldWrapper(level), mcModelViewMatrix, mcProjectionMatrix, previousPartialTicks);
// }
if (Config.Client.Advanced.lodOnlyMode.get()) {
callback.cancel();
}
}
#else
@Inject(method = "renderClouds", at = @At("HEAD"), cancellable = true)
public void renderClouds(PoseStack poseStack, Matrix4f projectionMatrix, float tickDelta, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) {
@@ -95,26 +77,30 @@ public class MixinLevelRenderer
// have access to them
previousPartialTicks = tickDelta;
}
#endif
#if PRE_MC_1_17_1
@Inject(at = @At("HEAD"),
method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDD)V",
cancellable = true)
private void renderChunkLayer(RenderType renderType, PoseStack matrixStackIn, double xIn, double yIn, double zIn, CallbackInfo callback)
#elif PRE_MC_1_19_4
@Inject(at = @At("HEAD"),
method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLcom/mojang/math/Matrix4f;)V",
cancellable = true)
private void renderChunkLayer(RenderType renderType, PoseStack modelViewMatrixStack, double cameraXBlockPos, double cameraYBlockPos, double cameraZBlockPos, Matrix4f projectionMatrix, CallbackInfo callback)
#else
@Inject(at = @At("HEAD"),
method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLorg/joml/Matrix4f;)V",
cancellable = true)
private void renderChunkLayer(RenderType renderType, PoseStack modelViewMatrixStack, double cameraXBlockPos, double cameraYBlockPos, double cameraZBlockPos, Matrix4f projectionMatrix, CallbackInfo callback)
#endif
{
// // only render before solid blocks
// if (renderType.equals(RenderType.solid()))
// {
// Mat4f mcModelViewMatrix = McObjectConverter.Convert(modelViewMatrixStack.last().pose());
// Mat4f mcProjectionMatrix = McObjectConverter.Convert(projectionMatrix);
//
// ClientApi.INSTANCE.renderLods(ClientLevelWrapper.getWrapper(level), mcModelViewMatrix, mcProjectionMatrix, previousPartialTicks);
// }
if (Config.Client.Advanced.Debugging.lodOnlyMode.get())
{
callback.cancel();
}
}
#endif
@Redirect(method =
"Lnet/minecraft/client/renderer/LevelRenderer;" +
@@ -122,7 +108,11 @@ public class MixinLevelRenderer
"FJZLnet/minecraft/client/Camera;" +
"Lnet/minecraft/client/renderer/GameRenderer;" +
"Lnet/minecraft/client/renderer/LightTexture;" +
#if PRE_MC_1_19_4
"Lcom/mojang/math/Matrix4f;)V"
#else
"Lorg/joml/Matrix4f;)V"
#endif
,
at = @At(
value = "INVOKE",
@@ -1,6 +1,6 @@
package com.seibel.distanthorizons.fabric.wrappers.modAccessor;
#if POST_MC_1_17_1
#if POST_MC_1_17_1 && FALSE
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IBCLibAccessor;
import ru.bclib.config.ClientConfig;
import ru.bclib.config.Configs;
@@ -24,8 +24,17 @@ import com.seibel.distanthorizons.core.api.internal.ClientApi;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraftforge.event.world.ChunkDataEvent;
#if PRE_MC_1_19
import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.event.world.WorldEvent;
#else
import net.minecraftforge.event.level.ChunkEvent;
import net.minecraftforge.event.level.LevelEvent;
#endif
import org.apache.logging.log4j.Logger;
import org.lwjgl.glfw.GLFW;
@@ -45,6 +54,12 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
*/
public class ForgeClientProxy
{
#if PRE_MC_1_19
private static LevelAccessor GetLevel(WorldEvent e) { return e.getWorld(); }
#else
private static LevelAccessor GetLevel(LevelEvent e) { return e.getLevel(); }
#endif
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
@SubscribeEvent
@@ -76,23 +91,23 @@ public class ForgeClientProxy
// }
@SubscribeEvent
public void clientChunkLoadEvent(ChunkDataEvent.Load event)
public void clientChunkLoadEvent(ChunkEvent.Load event)
{
if (event.getWorld() instanceof ClientLevel)
if (GetLevel(event) instanceof ClientLevel)
{
ClientLevelWrapper wrappedLevel = ClientLevelWrapper.getWrapper((ClientLevel) event.getWorld());
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), event.getWorld(), wrappedLevel);
ClientApi.INSTANCE.clientChunkLoadEvent(chunk, ClientLevelWrapper.getWrapper((ClientLevel) event.getWorld()));
ClientLevelWrapper wrappedLevel = ClientLevelWrapper.getWrapper((ClientLevel) GetLevel(event));
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), GetLevel(event), wrappedLevel);
ClientApi.INSTANCE.clientChunkLoadEvent(chunk, ClientLevelWrapper.getWrapper((ClientLevel) GetLevel(event)));
}
}
@SubscribeEvent
public void clientChunkSaveEvent(ChunkDataEvent.Save event)
public void clientChunkSaveEvent(ChunkEvent.Unload event)
{
if (event.getWorld() instanceof ClientLevel)
if (GetLevel(event) instanceof ClientLevel)
{
ClientLevelWrapper wrappedLevel = ClientLevelWrapper.getWrapper((ClientLevel) event.getWorld());
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), event.getWorld(), wrappedLevel);
ClientApi.INSTANCE.clientChunkSaveEvent(chunk, ClientLevelWrapper.getWrapper((ClientLevel) event.getWorld()));
ClientLevelWrapper wrappedLevel = ClientLevelWrapper.getWrapper((ClientLevel) GetLevel(event));
IChunkWrapper chunk = new ChunkWrapper(event.getChunk() , GetLevel(event), wrappedLevel);
ClientApi.INSTANCE.clientChunkSaveEvent(chunk, ClientLevelWrapper.getWrapper((ClientLevel) GetLevel(event)));
}
}
@@ -102,7 +117,7 @@ public class ForgeClientProxy
// Register KeyBindings
@SubscribeEvent
public void registerKeyBindings(InputEvent.KeyInputEvent event)
public void registerKeyBindings(#if PRE_MC_1_19 InputEvent.KeyInputEvent #else InputEvent.Key #endif event)
{
if (Minecraft.getInstance().player == null) return;
if (event.getAction() != GLFW.GLFW_PRESS) return;
@@ -45,7 +45,6 @@ import net.minecraft.world.level.ColorResolver;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.model.data.ModelDataMap;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
@@ -55,14 +54,26 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.ExtensionPoint;
#elif MC_1_17_1
import net.minecraftforge.fmlclient.ConfigGuiHandler;
#else // 1.18+
#elif POST_MC_1_18_2 && PRE_MC_1_19
import net.minecraftforge.client.ConfigGuiHandler;
#else
import net.minecraftforge.client.ConfigScreenHandler;
#endif
import org.apache.logging.log4j.Logger;
// these imports change due to forge refactoring classes in 1.19
#if PRE_MC_1_19
import net.minecraftforge.client.model.data.ModelDataMap;
import java.util.Random;
#else
import net.minecraft.util.RandomSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraftforge.client.model.data.ModelData;
#endif
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.Random;
/**
* Initialize and setup the Mod. <br>
@@ -109,14 +120,19 @@ public class ForgeMain implements LodForgeMethodCaller
if (ReflectionHandler.INSTANCE.optifinePresent()) {
ModAccessorInjector.INSTANCE.bind(IOptifineAccessor.class, new OptifineAccessor());
}
#if PRE_MC_1_17_1
ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY,
() -> (client, parent) -> GetConfigScreen.getScreen(parent));
#else
#elif POST_MC_1_18_2 && PRE_MC_1_19
ModLoadingContext.get().registerExtensionPoint(ConfigGuiHandler.ConfigGuiFactory.class,
() -> new ConfigGuiHandler.ConfigGuiFactory((client, parent) -> GetConfigScreen.getScreen(parent)));
#else
ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class,
() -> new ConfigScreenHandler.ConfigScreenFactory((client, parent) -> GetConfigScreen.getScreen(parent)));
#endif
LOGGER.info(ModInfo.READABLE_NAME + " Initialized");
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterDhInitEvent.class, null);
@@ -145,15 +161,20 @@ public class ForgeMain implements LodForgeMethodCaller
LOGGER.info("Mod Post-Initialized");
}
private final ModelDataMap dataMap = new ModelDataMap.Builder().build();
#if PRE_MC_1_19_1
private final ModelDataMap modelData = new ModelDataMap.Builder().build();
#else
private final ModelData modelData = ModelData.EMPTY;
#endif
@Override
#if PRE_MC_1_19
public List<BakedQuad> getQuads(MinecraftClientWrapper mc, Block block, BlockState blockState, Direction direction, Random random) {
return mc.getModelManager().getBlockModelShaper().getBlockModel(block.defaultBlockState()).getQuads(blockState, direction, random, dataMap);
return mc.getModelManager().getBlockModelShaper().getBlockModel(block.defaultBlockState()).getQuads(blockState, direction, random, modelData);
}
#else
public List<BakedQuad> getQuads(MinecraftClientWrapper mc, Block block, BlockState blockState, Direction direction, RandomSource random) {
return mc.getModelManager().getBlockModelShaper().getBlockModel(block.defaultBlockState()).getQuads(blockState, direction, random, dataMap);
return mc.getModelManager().getBlockModelShaper().getBlockModel(block.defaultBlockState()).getQuads(blockState, direction, random, modelData #if POST_MC_1_19, RenderType.solid() #endif);
}
#endif
@@ -13,11 +13,17 @@ import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.LevelAccessor;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.server.ServerAboutToStartEvent;
import net.minecraftforge.event.server.ServerStoppingEvent;
import net.minecraftforge.event.world.ChunkDataEvent;
#if PRE_MC_1_19
import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.event.world.WorldEvent;
#else
import net.minecraftforge.event.level.ChunkEvent;
import net.minecraftforge.event.level.LevelEvent;
#endif
import net.minecraftforge.eventbus.api.SubscribeEvent;
import org.apache.logging.log4j.Logger;
@@ -25,6 +31,12 @@ import java.util.function.Supplier;
public class ForgeServerProxy
{
#if PRE_MC_1_19
private static LevelAccessor GetLevel(WorldEvent e) { return e.getWorld(); }
#else
private static LevelAccessor GetLevel(LevelEvent e) { return e.getLevel(); }
#endif
private final ServerApi serverApi = ServerApi.INSTANCE;
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
private final boolean isDedicated;
@@ -83,43 +95,53 @@ public class ForgeServerProxy
// ServerLevelLoadEvent
@SubscribeEvent
public void serverLevelLoadEvent(WorldEvent.Load event) {
#if PRE_MC_1_19_1
public void serverLevelLoadEvent(WorldEvent.Load event)
#else
public void serverLevelLoadEvent(LevelEvent.Load event)
#endif
{
if (isValidTime()) {
if (event.getWorld() instanceof ServerLevel) {
serverApi.serverLevelLoadEvent(getLevelWrapper((ServerLevel) event.getWorld()));
if (GetLevel(event) instanceof ServerLevel) {
serverApi.serverLevelLoadEvent(getLevelWrapper((ServerLevel) GetLevel(event)));
}
}
}
// ServerLevelUnloadEvent
@SubscribeEvent
public void serverLevelUnloadEvent(WorldEvent.Unload event) {
#if PRE_MC_1_19_1
public void serverLevelUnloadEvent(WorldEvent.Unload event)
#else
public void serverLevelUnloadEvent(LevelEvent.Unload event)
#endif
{
if (isValidTime()) {
if (event.getWorld() instanceof ServerLevel) {
serverApi.serverLevelUnloadEvent(getLevelWrapper((ServerLevel) event.getWorld()));
if (GetLevel(event) instanceof ServerLevel) {
serverApi.serverLevelUnloadEvent(getLevelWrapper((ServerLevel) GetLevel(event)));
}
}
}
@SubscribeEvent
public void serverChunkLoadEvent(ChunkDataEvent.Load event)
public void serverChunkLoadEvent(ChunkEvent.Load event)
{
if (isValidTime()) {
if (event.getWorld() instanceof ServerLevel) {
ServerLevelWrapper wrappedLevel = ServerLevelWrapper.getWrapper((ServerLevel) event.getWorld());
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), event.getWorld(), wrappedLevel);
serverApi.serverChunkLoadEvent(chunk, getLevelWrapper((ServerLevel) event.getWorld()));
if (GetLevel(event) instanceof ServerLevel) {
ServerLevelWrapper wrappedLevel = ServerLevelWrapper.getWrapper((ServerLevel) GetLevel(event));
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), GetLevel(event), wrappedLevel);
serverApi.serverChunkLoadEvent(chunk, getLevelWrapper((ServerLevel) GetLevel(event)));
}
}
}
@SubscribeEvent
public void serverChunkSaveEvent(ChunkDataEvent.Save event)
public void serverChunkSaveEvent(ChunkEvent.Unload event)
{
if (isValidTime()) {
if (event.getWorld() instanceof ServerLevel) {
ServerLevelWrapper wrappedLevel = ServerLevelWrapper.getWrapper((ServerLevel) event.getWorld());
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), event.getWorld(), wrappedLevel);
serverApi.serverChunkSaveEvent(chunk, getLevelWrapper((ServerLevel) event.getWorld()));
if (GetLevel(event) instanceof ServerLevel) {
ServerLevelWrapper wrappedLevel = ServerLevelWrapper.getWrapper((ServerLevel) GetLevel(event));
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), GetLevel(event), wrappedLevel);
serverApi.serverChunkSaveEvent(chunk, getLevelWrapper((ServerLevel) GetLevel(event)));
}
}
}
@@ -20,7 +20,11 @@
package com.seibel.distanthorizons.forge.mixins.client;
import com.mojang.blaze3d.vertex.PoseStack;
#if PRE_MC_1_19_3
import com.mojang.math.Matrix4f;
#else
import org.joml.Matrix4f;
#endif
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
import com.seibel.distanthorizons.core.config.Config;
@@ -101,10 +105,22 @@ public class MixinLevelRenderer
}
// TODO: Can we move this o forge's client proxy simmilar to how fabric does it
#if PRE_MC_1_17_1
@Inject(at = @At("HEAD"),
method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDD)V",
cancellable = true)
private void renderChunkLayer(RenderType renderType, PoseStack matrixStackIn, double xIn, double yIn, double zIn, CallbackInfo callback)
#elif PRE_MC_1_19_4
@Inject(at = @At("HEAD"),
method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLcom/mojang/math/Matrix4f;)V",
cancellable = true)
private void renderChunkLayer(RenderType renderType, PoseStack modelViewMatrixStack, double cameraXBlockPos, double cameraYBlockPos, double cameraZBlockPos, Matrix4f projectionMatrix, CallbackInfo callback)
#else
@Inject(at = @At("HEAD"),
method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLcom/mojang/math/Matrix4f;)V",
method = "renderChunkLayer(Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLorg/joml/Matrix4f;)V",
cancellable = true)
private void renderChunkLayer(RenderType renderType, PoseStack modelViewMatrixStack, double cameraXBlockPos, double cameraYBlockPos, double cameraZBlockPos, Matrix4f projectionMatrix, CallbackInfo callback)
#endif
{
// only render before solid blocks
if (renderType.equals(RenderType.solid()))
@@ -32,6 +32,7 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.io.File;
import java.nio.file.Path;
#if FALSE
@Mixin(WorldUpgrader.class)
public class MixinWorldUpgrader {
static class FakeLevelWrapper implements IServerLevelWrapper {
@@ -152,3 +153,4 @@ public class MixinWorldUpgrader {
}
#endif
+1 -1
View File
@@ -33,4 +33,4 @@ versionStr=
# This defines what MC version Intellij will use for the preprocessor
# and what version is used automatically by build and run commands
mcVer=1.18.2
mcVer=1.19.4