diff --git a/gradle.properties b/gradle.properties index ddf396fb4..a3d4c5e69 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,13 +1,13 @@ -org.gradle.jvmargs=-Xmx1G +org.gradle.jvmargs=-Xmx2G kotlin.code.style=official # Fabric Properties # check these on https://fabricmc.net/develop/ -minecraft_version=1.21.1 -parchment_version=2024.06.23-1.21 -fabric_version=0.100.1+1.21 -fabric_loader_version=0.15.11 +minecraft_version=1.21.4 +parchment_version=2024.11.17-1.21.1 +fabric_version=0.110.5+1.21.4 +fabric_loader_version=0.16.9 embeddium.fabric_mode=false @@ -17,21 +17,21 @@ embeddium.fabric_mode=false archives_base_name = embeddium -forge_version=21.1.61 +forge_version=21.4.5-beta -codechicken_fileid=4382729 +codechicken_fileid=5826640 ie_fileid=1.20.4-10.0.1-pre.163 base_mc_version_commit=0263cc2ffd33599aa90d5b226242035459e45ee7 use_phi=false # find neoform version for your Minecraft version here: https://projects.neoforged.net/neoforged/neoform -neoform_version=20240605.103358 +neoform_version=20241203.161809 -asm_version=9.5 -mixin_version=0.13.4+mixin.0.8.5 -eventbus_version=7.2.0 -mixin_extras_version=0.3.5 +asm_version=9.7 +mixin_version=0.15.2+mixin.0.8.7 +eventbus_version=8.0.2 +mixin_extras_version=0.4.1 apache_maven_artifact_version=3.8.5 spi_version=9.0.2 -modlauncher_version=11.0.2 +modlauncher_version=11.0.4 diff --git a/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/TestBlock.java b/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/TestBlock.java index a11540bbd..809618ed5 100644 --- a/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/TestBlock.java +++ b/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/TestBlock.java @@ -19,7 +19,7 @@ public TestBlock() { } @Override - public VoxelShape getOcclusionShape(BlockState pState, BlockGetter pLevel, BlockPos pPos) { + public VoxelShape getOcclusionShape(BlockState pState) { return Shapes.empty(); } diff --git a/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/TestRegistry.java b/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/TestRegistry.java index bae686a41..427ca918f 100644 --- a/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/TestRegistry.java +++ b/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/TestRegistry.java @@ -12,6 +12,7 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.Difficulty; +import net.minecraft.world.flag.FeatureFlagSet; import net.minecraft.world.level.GameRules; import net.minecraft.world.level.GameType; import net.minecraft.world.level.LevelSettings; @@ -66,7 +67,7 @@ public class TestRegistry { public static final DeferredHolder TEST_BLOCK = BLOCKS.register("test_block", TestBlock::new); public static final DeferredHolder NOT_AN_AIR_BLOCK = BLOCKS.register("not_an_air_block", NotAnAirBlock::new); - public static final DeferredHolder, BlockEntityType> TEST_BLOCK_ENTITY = BLOCK_ENTITIES.register("test_block_entity", () -> BlockEntityType.Builder.of(TestBlockEntity::new, TEST_BLOCK.get()).build(null)); + public static final DeferredHolder, BlockEntityType> TEST_BLOCK_ENTITY = BLOCK_ENTITIES.register("test_block_entity", () -> new BlockEntityType<>(TestBlockEntity::new, TEST_BLOCK.get())); public static final ResourceLocation EMPTY_TEMPLATE = ResourceLocation.fromNamespaceAndPath(EmbeddiumConstants.MODID, "empty_structure"); public static final String EMPTY_TEMPLATE_STR = EMPTY_TEMPLATE.toString(); @@ -93,7 +94,7 @@ public static void registerPayloads(final RegisterPayloadHandlersEvent event) { private static void registerModelForAllStates(ModelEvent.ModifyBakingResult event, Block block, BakedModel model) { for(BlockState state : block.getStateDefinition().getPossibleStates()) { - event.getModels().put(BlockModelShaper.stateToModelLocation(state), model); + event.getBakingResult().blockStateModels().put(BlockModelShaper.stateToModelLocation(state), model); } } @@ -102,8 +103,8 @@ private static void registerModelForAllStates(ModelEvent.ModifyBakingResult even */ @SubscribeEvent public static void onBakingModify(ModelEvent.ModifyBakingResult event) { - registerModelForAllStates(event, TEST_BLOCK.get(), new TestModel(event.getModels().get(ModelBakery.MISSING_MODEL_VARIANT))); - registerModelForAllStates(event, NOT_AN_AIR_BLOCK.get(), new InstrumentingModelWrapper<>(event.getModels().get(BlockModelShaper.stateToModelLocation(Blocks.STONE.defaultBlockState())))); + registerModelForAllStates(event, TEST_BLOCK.get(), new TestModel(event.getBakingResult().missingModel())); + registerModelForAllStates(event, NOT_AN_AIR_BLOCK.get(), new InstrumentingModelWrapper<>(event.getBakingResult().blockStateModels().get(BlockModelShaper.stateToModelLocation(Blocks.STONE.defaultBlockState())))); } static class GameEvents { @@ -132,9 +133,9 @@ public static void onScreenInit(ScreenEvent.Init.Post event) { var messageScreen = new GenericMessageScreen(Component.literal("Bootstrapping gametests...")); mc.forceSetScreen(messageScreen); String levelName = "embeddium-test-" + UUID.randomUUID(); - LevelSettings settings = new LevelSettings(levelName, GameType.CREATIVE, false, Difficulty.PEACEFUL, true, new GameRules(), WorldDataConfiguration.DEFAULT); + LevelSettings settings = new LevelSettings(levelName, GameType.CREATIVE, false, Difficulty.PEACEFUL, true, new GameRules(FeatureFlagSet.of()), WorldDataConfiguration.DEFAULT); mc.createWorldOpenFlows().createFreshLevel(settings.levelName(), settings, new WorldOptions(1024, false, false), registry -> { - return registry.registryOrThrow(Registries.WORLD_PRESET).getHolderOrThrow(WorldPresets.FLAT).value().createWorldDimensions(); + return registry.lookupOrThrow(Registries.WORLD_PRESET).getOrThrow(WorldPresets.FLAT).value().createWorldDimensions(); }, messageScreen); } } diff --git a/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/client/InstrumentingModelWrapper.java b/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/client/InstrumentingModelWrapper.java index 46c713df6..bc2a66692 100644 --- a/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/client/InstrumentingModelWrapper.java +++ b/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/client/InstrumentingModelWrapper.java @@ -3,17 +3,17 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.DelegateBakedModel; import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; import net.minecraft.world.level.block.state.BlockState; -import net.neoforged.neoforge.client.model.BakedModelWrapper; import net.neoforged.neoforge.client.model.data.ModelData; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; -public class InstrumentingModelWrapper extends BakedModelWrapper { +public class InstrumentingModelWrapper extends DelegateBakedModel { private volatile boolean hasBeenCalled; public InstrumentingModelWrapper(T originalModel) { diff --git a/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/client/TestModel.java b/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/client/TestModel.java index 21e8187d3..e3a00f303 100644 --- a/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/client/TestModel.java +++ b/src/gametest/java/org/embeddedt/embeddium/impl/gametest/content/client/TestModel.java @@ -3,12 +3,12 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.client.resources.model.DelegateBakedModel; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; -import net.neoforged.neoforge.client.model.BakedModelWrapper; import net.neoforged.neoforge.client.model.data.ModelData; import net.neoforged.neoforge.client.model.data.ModelProperty; import org.embeddedt.embeddium.impl.gametest.content.TestBlockEntity; @@ -18,7 +18,7 @@ import java.util.List; import java.util.Objects; -public class TestModel extends BakedModelWrapper { +public class TestModel extends DelegateBakedModel { public static final ModelProperty TEST_MODEL_PROPERTY = new ModelProperty<>(); public static final Object TEST_MODEL_VALUE = new Object(); diff --git a/src/main/java/org/embeddedt/embeddium/impl/compatibility/checks/SodiumResourcePackMetadata.java b/src/main/java/org/embeddedt/embeddium/impl/compatibility/checks/SodiumResourcePackMetadata.java index 77299701e..33a117384 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/compatibility/checks/SodiumResourcePackMetadata.java +++ b/src/main/java/org/embeddedt/embeddium/impl/compatibility/checks/SodiumResourcePackMetadata.java @@ -2,7 +2,6 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraft.server.packs.metadata.MetadataSectionSerializer; import net.minecraft.server.packs.metadata.MetadataSectionType; import java.util.List; @@ -18,6 +17,5 @@ public record SodiumResourcePackMetadata(List ignoredShaders) { .forGetter(SodiumResourcePackMetadata::ignoredShaders)) .apply(instance, SodiumResourcePackMetadata::new) ); - public static final MetadataSectionType SERIALIZER = - MetadataSectionType.fromCodec("sodium", CODEC); + public static final MetadataSectionType SERIALIZER = new MetadataSectionType<>("sodium", CODEC); } diff --git a/src/main/java/org/embeddedt/embeddium/impl/gui/EmbeddiumGameOptionPages.java b/src/main/java/org/embeddedt/embeddium/impl/gui/EmbeddiumGameOptionPages.java index 403840cdd..f27592731 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/gui/EmbeddiumGameOptionPages.java +++ b/src/main/java/org/embeddedt/embeddium/impl/gui/EmbeddiumGameOptionPages.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.pipeline.RenderTarget; import com.mojang.blaze3d.platform.Window; import net.minecraft.ChatFormatting; +import net.minecraft.server.level.ParticleStatus; import net.neoforged.fml.ModList; import net.neoforged.neoforge.common.NeoForgeConfig; import org.embeddedt.embeddium.api.options.structure.OptionFlag; @@ -31,11 +32,15 @@ import org.embeddedt.embeddium.impl.render.ShaderModBridge; import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GLCapabilities; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; public class EmbeddiumGameOptionPages { + private static final Logger LOGGER = LoggerFactory.getLogger(EmbeddiumGameOptionPages.class); + private static final EmbeddiumOptionsStorage sodiumOpts = new EmbeddiumOptionsStorage(); private static final MinecraftOptionsStorage vanillaOpts = MinecraftOptionsStorage.INSTANCE; @@ -127,7 +132,8 @@ public static OptionPage general() { .setControl(option -> new SliderControl(option, 10, 260, 10, ControlValueFormatter.fpsLimit())) .setBinding((opts, value) -> { opts.framerateLimit().set(value); - Minecraft.getInstance().getWindow().setFramerateLimit(value); + LOGGER.warn("getWindow().setFramerateLimit(...) Not Yet Implemented"); + //Minecraft.getInstance().getWindow().setFramerateLimit(value); }, opts -> opts.framerateLimit().get()) .build()) .build()); @@ -191,7 +197,7 @@ public static OptionPage quality() { if (Minecraft.useShaderTransparency()) { RenderTarget framebuffer = Minecraft.getInstance().levelRenderer.getCloudsTarget(); if (framebuffer != null) { - framebuffer.clear(Minecraft.ON_OSX); + framebuffer.clear(); } } }, opts -> opts.cloudStatus().get()) diff --git a/src/main/java/org/embeddedt/embeddium/impl/gui/EmbeddiumVideoOptionsScreen.java b/src/main/java/org/embeddedt/embeddium/impl/gui/EmbeddiumVideoOptionsScreen.java index 23dafcfcb..a21bc8487 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/gui/EmbeddiumVideoOptionsScreen.java +++ b/src/main/java/org/embeddedt/embeddium/impl/gui/EmbeddiumVideoOptionsScreen.java @@ -2,6 +2,7 @@ import com.google.common.collect.Multimap; import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.FormattedText; import net.minecraft.network.chat.Style; import org.embeddedt.embeddium.impl.Embeddium; @@ -299,17 +300,17 @@ public void renderBackground(GuiGraphics gfx, int mouseX, int mouseY, float part super.renderBackground(gfx, mouseX, mouseY, partialTick); // Render watermarks - gfx.setColor(ColorARGB.unpackRed(DefaultColors.ELEMENT_ACTIVATED) / 255f, ColorARGB.unpackGreen(DefaultColors.ELEMENT_ACTIVATED) / 255f, ColorARGB.unpackBlue(DefaultColors.ELEMENT_ACTIVATED) / 255f, 0.8F); + //gfx.setColor(ColorARGB.unpackRed(DefaultColors.ELEMENT_ACTIVATED) / 255f, ColorARGB.unpackGreen(DefaultColors.ELEMENT_ACTIVATED) / 255f, ColorARGB.unpackBlue(DefaultColors.ELEMENT_ACTIVATED) / 255f, 0.8F); RenderSystem.disableDepthTest(); RenderSystem.depthMask(false); RenderSystem.enableBlend(); RenderSystem.blendFunc(770, 1); - gfx.blit(LOGO_LOCATION, this.logoDim.x(), this.logoDim.y(), this.logoDim.width(), this.logoDim.height(), 0.0F, 0.0F, LOGO_SIZE, LOGO_SIZE, LOGO_SIZE, LOGO_SIZE); + gfx.blit(RenderType::guiTextured, LOGO_LOCATION, this.logoDim.x(), this.logoDim.y(), this.logoDim.width(), this.logoDim.height(), 0, 0, LOGO_SIZE, LOGO_SIZE, LOGO_SIZE, LOGO_SIZE); RenderSystem.defaultBlendFunc(); RenderSystem.disableBlend(); RenderSystem.depthMask(true); RenderSystem.enableDepthTest(); - gfx.setColor(1.0F, 1.0F, 1.0F, 1.0F); + //gfx.setColor(1.0F, 1.0F, 1.0F, 1.0F); } @Override diff --git a/src/main/java/org/embeddedt/embeddium/impl/gui/frame/components/SearchTextFieldModel.java b/src/main/java/org/embeddedt/embeddium/impl/gui/frame/components/SearchTextFieldModel.java index b0b3dda34..8e9e4e412 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/gui/frame/components/SearchTextFieldModel.java +++ b/src/main/java/org/embeddedt/embeddium/impl/gui/frame/components/SearchTextFieldModel.java @@ -91,7 +91,7 @@ private void onChanged(String newText) { } } - Minecraft.getInstance().tell(() -> this.mainScreen.rebuildUI()); + Minecraft.getInstance().schedule(() -> this.mainScreen.rebuildUI()); } void erase(int offset) { diff --git a/src/main/java/org/embeddedt/embeddium/impl/gui/frame/tab/TabHeaderWidget.java b/src/main/java/org/embeddedt/embeddium/impl/gui/frame/tab/TabHeaderWidget.java index ff2c13f37..69a46c180 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/gui/frame/tab/TabHeaderWidget.java +++ b/src/main/java/org/embeddedt/embeddium/impl/gui/frame/tab/TabHeaderWidget.java @@ -1,6 +1,7 @@ package org.embeddedt.embeddium.impl.gui.frame.tab; import com.mojang.blaze3d.platform.NativeImage; +import net.minecraft.client.renderer.RenderType; import org.embeddedt.embeddium.impl.Embeddium; import org.embeddedt.embeddium.impl.gui.widgets.FlatButtonWidget; import org.embeddedt.embeddium.api.math.Dim2i; @@ -81,6 +82,6 @@ public void render(GuiGraphics drawContext, int mouseX, int mouseY, float delta) ResourceLocation icon = Objects.requireNonNullElse(this.logoTexture, FALLBACK_LOCATION); int fontHeight = Minecraft.getInstance().font.lineHeight; int imgY = this.dim.getCenterY() - (fontHeight / 2); - drawContext.blit(icon, this.dim.x() + 5, imgY, 0.0f, 0.0f, fontHeight, fontHeight, fontHeight, fontHeight); + drawContext.blit(RenderType::guiTextured, icon, this.dim.x() + 5, imgY, 0.0f, 0.0f, fontHeight, fontHeight, fontHeight, fontHeight); } } diff --git a/src/main/java/org/embeddedt/embeddium/impl/gui/screen/PromptScreen.java b/src/main/java/org/embeddedt/embeddium/impl/gui/screen/PromptScreen.java index 275118159..0c448b7b0 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/gui/screen/PromptScreen.java +++ b/src/main/java/org/embeddedt/embeddium/impl/gui/screen/PromptScreen.java @@ -50,7 +50,7 @@ public void init() { } @Override - protected void renderBlurredBackground(float f) { + protected void renderBlurredBackground() { // Disable the blur } diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/MinecraftClientMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/MinecraftClientMixin.java index 52becfa15..969c458e0 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/MinecraftClientMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/MinecraftClientMixin.java @@ -1,6 +1,7 @@ package org.embeddedt.embeddium.impl.mixin.core; import it.unimi.dsi.fastutil.longs.LongArrayFIFOQueue; +import net.minecraft.util.profiling.Profiler; import org.embeddedt.embeddium.impl.Embeddium; import org.embeddedt.embeddium.impl.gui.screen.ConfigCorruptedScreen; import net.minecraft.client.Minecraft; @@ -41,7 +42,7 @@ private void postInit(GameConfig args, CallbackInfo ci) { */ @Inject(method = "runTick", at = @At("HEAD")) private void preRender(boolean tick, CallbackInfo ci) { - ProfilerFiller profiler = Minecraft.getInstance().getProfiler(); + ProfilerFiller profiler = Profiler.get(); profiler.push("wait_for_gpu"); while (this.fences.size() > Embeddium.options().advanced.cpuRenderAheadLimit) { diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/collections/WeightedRandomListMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/collections/WeightedRandomListMixin.java new file mode 100644 index 000000000..66d90f51e --- /dev/null +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/collections/WeightedRandomListMixin.java @@ -0,0 +1,47 @@ +package org.embeddedt.embeddium.impl.mixin.core.collections; + +import com.google.common.collect.ImmutableList; +import net.minecraft.util.RandomSource; +import net.minecraft.util.random.WeightedEntry; +import net.minecraft.util.random.WeightedRandomList; +import org.embeddedt.embeddium.impl.util.collections.WeightedRandomListExtended; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; + +import java.util.List; + +@Mixin(WeightedRandomList.class) +public class WeightedRandomListMixin implements WeightedRandomListExtended { + @Shadow + @Final + private ImmutableList items; + + @Shadow + @Final + private int totalWeight; + + @Override + @Nullable + public E embeddium$getRandomItem(RandomSource random) { + return getAt(this.items, random.nextInt(this.totalWeight)); + } + + @Unique + private static T getAt(List pool, int totalWeight) { + int i = 0; + int len = pool.size(); + T weighted; + do { + if (i >= len) { + return null; + } + + weighted = pool.get(i++); + totalWeight -= weighted.getWeight().asInt(); + } while (totalWeight >= 0); + return weighted; + } +} diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/model/SimpleBakedModelBuilderMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/model/SimpleBakedModelBuilderMixin.java index 632518da6..ad11b854a 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/model/SimpleBakedModelBuilderMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/model/SimpleBakedModelBuilderMixin.java @@ -12,7 +12,7 @@ public class SimpleBakedModelBuilderMixin { @ModifyArg(method = { "addCulledFace", "addUnculledFace" }, at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", remap = false), require = 0) private Object setVanillaShadingFlag(Object quad) { BakedQuadView view = (BakedQuadView)quad; - view.setFlags(view.getFlags() | ModelQuadFlags.IS_VANILLA_SHADED); + view.addFlags(ModelQuadFlags.IS_VANILLA_SHADED); return quad; } } diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/model/colors/ItemColorsMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/model/colors/ItemColorsMixin.java deleted file mode 100644 index 1c17e2d8b..000000000 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/model/colors/ItemColorsMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.embeddedt.embeddium.impl.mixin.core.model.colors; - -import it.unimi.dsi.fastutil.objects.Reference2ReferenceMap; -import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap; -import org.embeddedt.embeddium.impl.model.color.interop.ItemColorsExtended; -import net.minecraft.client.color.item.ItemColor; -import net.minecraft.client.color.item.ItemColors; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ItemLike; -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.callback.CallbackInfo; - -@Mixin(ItemColors.class) -public class ItemColorsMixin implements ItemColorsExtended { - @Unique - private final Reference2ReferenceMap itemsToColor = - new Reference2ReferenceOpenHashMap<>(); - - @Inject(method = "register", at = @At("TAIL")) - private void preRegisterColor(ItemColor provider, ItemLike[] items, CallbackInfo ci) { - // Synchronize so the inevitable crash mods cause will come from the vanilla map - synchronized (this.itemsToColor) { - for (ItemLike convertible : items) { - this.itemsToColor.put(convertible.asItem(), provider); - } - } - } - - @Override - public ItemColor sodium$getColorProvider(ItemStack stack) { - return this.itemsToColor.get(stack.getItem()); - } -} diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/model/quad/BakedQuadFactoryMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/model/quad/BakedQuadFactoryMixin.java index 750b41d12..659117f77 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/model/quad/BakedQuadFactoryMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/model/quad/BakedQuadFactoryMixin.java @@ -20,7 +20,7 @@ public class BakedQuadFactoryMixin { * (meaning the particle sprite matches the encoded UVs) */ @ModifyReturnValue(method = "bakeQuad", at = @At("RETURN")) - private BakedQuad setMaterialClassification(BakedQuad quad, @Local(ordinal = 0, argsOnly = true) BlockElementFace face, @Local(ordinal = 0, argsOnly = true) TextureAtlasSprite sprite) { + private static BakedQuad setMaterialClassification(BakedQuad quad, @Local(ordinal = 0, argsOnly = true) BlockElementFace face, @Local(ordinal = 0, argsOnly = true) TextureAtlasSprite sprite) { if (sprite.getClass() == TextureAtlasSprite.class && sprite.contents().getClass() == SpriteContents.class) { float[] uvs = face.uv().uvs; float minUV = Float.MAX_VALUE, maxUV = Float.MIN_VALUE; @@ -31,13 +31,10 @@ private BakedQuad setMaterialClassification(BakedQuad quad, @Local(ordinal = 0, } if (minUV >= 0 && maxUV <= 16) { - // Quad UVs do not extend outside texture boundary, we can trust the given sprite - BakedQuadView view = (BakedQuadView)quad; - view.setFlags(view.getFlags() | ModelQuadFlags.IS_TRUSTED_SPRITE); + var view = (BakedQuadView)quad; + view.addFlags(ModelQuadFlags.IS_TRUSTED_SPRITE); } - } - return quad; } } diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/model/quad/BakedQuadMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/model/quad/BakedQuadMixin.java index 92a62157e..caf516b05 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/model/quad/BakedQuadMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/model/quad/BakedQuadMixin.java @@ -104,8 +104,8 @@ public int getFlags() { } @Override - public void setFlags(int flags) { - this.flags = flags; + public void addFlags(int flags) { + this.flags |= flags; } @Override diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/render/immediate/consumer/OverlayVertexConsumerMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/render/immediate/consumer/OverlayVertexConsumerMixin.java index 260ca6fb9..28bdc77c4 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/render/immediate/consumer/OverlayVertexConsumerMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/render/immediate/consumer/OverlayVertexConsumerMixin.java @@ -101,7 +101,7 @@ private static void transform(long ptr, int count, VertexFormatDescription forma normal.z = NormI8.unpackZ(packedNormal); Vector3f transformedNormal = inverseNormalMatrix.transform(normal); - Direction direction = Direction.getNearest(transformedNormal.x(), transformedNormal.y(), transformedNormal.z()); + Direction direction = Direction.getApproximateNearest(transformedNormal.x(), transformedNormal.y(), transformedNormal.z()); Vector4f transformedTexture = inverseTextureMatrix.transform(position); transformedTexture.rotateY(3.1415927F); diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/render/world/WorldRendererMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/render/world/WorldRendererMixin.java index e3fd6b381..e87e3ccbf 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/render/world/WorldRendererMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/render/world/WorldRendererMixin.java @@ -1,35 +1,31 @@ package org.embeddedt.embeddium.impl.mixin.core.render.world; +import com.llamalad7.mixinextras.sugar.Local; +import com.mojang.blaze3d.vertex.PoseStack; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import net.minecraft.client.renderer.*; +import net.neoforged.neoforge.client.ClientHooks; import org.embeddedt.embeddium.impl.gl.device.RenderDevice; import org.embeddedt.embeddium.impl.render.EmbeddiumWorldRenderer; import org.embeddedt.embeddium.impl.render.viewport.ViewportProvider; +import org.embeddedt.embeddium.impl.sodium.FlawlessFrames; import org.embeddedt.embeddium.impl.world.WorldRendererExtended; import net.minecraft.client.Camera; -import net.minecraft.client.DeltaTracker; import net.minecraft.client.Minecraft; import net.minecraft.client.Options; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; import net.minecraft.client.renderer.culling.Frustum; -import net.minecraft.client.renderer.entity.EntityRenderDispatcher; import net.minecraft.core.BlockPos; import net.minecraft.server.level.BlockDestructionProgress; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.neoforged.neoforge.client.ClientHooks; -import org.embeddedt.embeddium.impl.sodium.FlawlessFrames; -import org.jetbrains.annotations.Nullable; import org.joml.Matrix4f; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.*; 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.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.SortedSet; -import java.util.function.Consumer; @Mixin(LevelRenderer.class) public abstract class WorldRendererMixin implements WorldRendererExtended { @@ -41,6 +37,10 @@ public abstract class WorldRendererMixin implements WorldRendererExtended { @Final private Long2ObjectMap> destructionProgress; + @Shadow + @Final + private SectionOcclusionGraph sectionOcclusionGraph; + @Shadow private int ticks; @@ -48,11 +48,6 @@ public abstract class WorldRendererMixin implements WorldRendererExtended { @Final private Minecraft minecraft; - @Shadow(remap = false) - public Frustum getFrustum() { - return null; - } - @Unique private EmbeddiumWorldRenderer renderer; @@ -63,25 +58,31 @@ public Frustum getFrustum() { @Shadow @Nullable - private ClientLevel level; + private Frustum capturedFrustum; @Shadow - @Final - private SectionOcclusionGraph sectionOcclusionGraph; + private Frustum cullingFrustum; + + @Unique + private Frustum embeddium$getCurrentFrustum() { + return this.capturedFrustum != null ? this.capturedFrustum : this.cullingFrustum; + } @Override public EmbeddiumWorldRenderer sodium$getWorldRenderer() { return this.renderer; } - @Redirect(method = "allChanged()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Options;getEffectiveRenderDistance()I", ordinal = 1)) + @Redirect(method = "allChanged()V", at = + @At(value = "INVOKE", target = "Lnet/minecraft/client/Options;getEffectiveRenderDistance()I", ordinal = 1) + ) private int nullifyBuiltChunkStorage(Options options) { // Do not allow any resources to be allocated return 0; } @Inject(method = "", at = @At("RETURN")) - private void init(Minecraft client, EntityRenderDispatcher entityRenderDispatcher, BlockEntityRenderDispatcher blockEntityRenderDispatcher, RenderBuffers bufferBuilderStorage, CallbackInfo ci) { + private void init(CallbackInfo ci, @Local(ordinal = 0, argsOnly = true) Minecraft client) { this.renderer = new EmbeddiumWorldRenderer(client); } @@ -105,15 +106,6 @@ public int countRenderedSections() { return this.renderer.getVisibleChunkCount(); } - /** - * @reason Redirect to our renderer - * @author embeddedt - */ - @Overwrite - public void iterateVisibleBlockEntities(Consumer blockEntityConsumer) { - this.renderer.forEachVisibleBlockEntity(blockEntityConsumer); - } - /** * @reason Redirect the check to our renderer * @author JellySquid @@ -144,7 +136,7 @@ private void renderSectionLayer(RenderType renderLayer, double x, double y, doub // TODO: Avoid setting up and clearing the state a second time renderLayer.setupRenderState(); - ClientHooks.dispatchRenderStage(renderLayer, ((LevelRenderer)(Object)this), pose, matrix, this.ticks, this.minecraft.gameRenderer.getMainCamera(), this.getFrustum()); + ClientHooks.dispatchRenderStage(renderLayer, (LevelRenderer)(Object)this, pose, matrix, this.ticks, this.minecraft.gameRenderer.getMainCamera(), this.embeddium$getCurrentFrustum()); renderLayer.clearRenderState(); } @@ -206,10 +198,6 @@ private void setSectionDirty(int x, int y, int z, boolean important) { this.renderer.scheduleRebuildForChunk(x, y, z, important); } - /** - * @reason Redirect chunk updates to our renderer - * @author JellySquid - */ @Overwrite public boolean isSectionCompiled(BlockPos pos) { return this.renderer.isSectionReady(pos.getX() >> 4, pos.getY() >> 4, pos.getZ() >> 4); @@ -226,20 +214,13 @@ private void onReload(CallbackInfo ci) { } } - @Inject(method = "renderLevel", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/LevelRenderer;globalBlockEntities:Ljava/util/Set;", shift = At.Shift.BEFORE, ordinal = 0)) - private void onRenderBlockEntities(DeltaTracker deltaTracker, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightmapTextureManager, Matrix4f pose, Matrix4f positionMatrix, CallbackInfo ci) { - this.renderer.renderBlockEntities(pose, this.renderBuffers, this.destructionProgress, camera, deltaTracker.getGameTimeDeltaPartialTick(false)); - } - /** - * Target the flag that selects whether or not to enable the entity outline shader, and enable it if - * we rendered a block entity that requested it. - * - * NOTE: When updating Embeddium to newer versions of the game, this injection point must be checked. + * @author embeddedt + * @reason take over block entity rendering */ - @ModifyVariable(method = "renderLevel", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/LevelRenderer;globalBlockEntities:Ljava/util/Set;", shift = At.Shift.BEFORE, ordinal = 0), ordinal = 3) - private boolean changeEntityOutlineFlag(boolean bl) { - return bl || (this.renderer.didBlockEntityRequestOutline() && this.shouldShowEntityOutlines()); + @Overwrite + private void renderBlockEntities(PoseStack stack, MultiBufferSource.BufferSource bufferSource, MultiBufferSource.BufferSource bufferSource2, Camera camera, float partialTick) { + this.renderer.renderBlockEntities(new PoseStack(), this.renderBuffers, this.destructionProgress, camera, partialTick); } /** diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/world/biome/ClientWorldMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/world/biome/ClientWorldMixin.java index d04eb610a..2d4fe77a9 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/world/biome/ClientWorldMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/world/biome/ClientWorldMixin.java @@ -1,5 +1,6 @@ package org.embeddedt.embeddium.impl.mixin.core.world.biome; +import com.llamalad7.mixinextras.sugar.Local; import org.embeddedt.embeddium.impl.world.BiomeSeedProvider; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientPacketListener; @@ -23,17 +24,7 @@ public class ClientWorldMixin implements BiomeSeedProvider { private long biomeSeed; @Inject(method = "", at = @At("RETURN")) - private void captureSeed(ClientPacketListener networkHandler, - ClientLevel.ClientLevelData properties, - ResourceKey registryRef, - Holder dimensionTypeEntry, - int loadDistance, - int simulationDistance, - Supplier profiler, - LevelRenderer worldRenderer, - boolean debugWorld, - long seed, - CallbackInfo ci) { + private void captureSeed(CallbackInfo ci, @Local(ordinal = 0, argsOnly = true) long seed) { this.biomeSeed = seed; } diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/world/map/ClientPlayNetworkHandlerMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/world/map/ClientPlayNetworkHandlerMixin.java index d0ba9cc1e..4cbd6d965 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/core/world/map/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/core/world/map/ClientPlayNetworkHandlerMixin.java @@ -21,14 +21,13 @@ public class ClientPlayNetworkHandlerMixin { method = "applyLightData", at = @At("RETURN") ) - private void onLightDataReceived(int x, int z, ClientboundLightUpdatePacketData data, CallbackInfo ci) { + private void onLightDataReceived(int x, int z, ClientboundLightUpdatePacketData data, boolean invalidateSection, CallbackInfo ci) { ChunkTrackerHolder.get(this.level) .onChunkStatusAdded(x, z, ChunkStatus.FLAG_HAS_LIGHT_DATA); } @Inject(method = "handleForgetLevelChunk", at = @At("RETURN")) private void onChunkUnloadPacket(ClientboundForgetLevelChunkPacket packet, CallbackInfo ci) { - ChunkTrackerHolder.get(this.level) - .onChunkStatusRemoved(packet.pos().x, packet.pos().z, ChunkStatus.FLAG_ALL); + ChunkTrackerHolder.get(this.level).onChunkStatusRemoved(packet.pos().x, packet.pos().z, ChunkStatus.FLAG_ALL); } } diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/gui/hooks/console/GameRendererMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/gui/hooks/console/GameRendererMixin.java index 85701cea2..c071f7066 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/gui/hooks/console/GameRendererMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/gui/hooks/console/GameRendererMixin.java @@ -1,5 +1,6 @@ package org.embeddedt.embeddium.impl.mixin.features.gui.hooks.console; +import net.minecraft.util.profiling.Profiler; import org.embeddedt.embeddium.impl.gui.console.ConsoleHooks; import net.minecraft.client.DeltaTracker; import net.minecraft.client.Minecraft; @@ -38,8 +39,7 @@ private void onRender(DeltaTracker deltaTracker, boolean tick, CallbackInfo ci) } } - this.minecraft.getProfiler() - .push("sodium_console_overlay"); + Profiler.get().push("sodium_console_overlay"); GuiGraphics drawContext = new GuiGraphics(this.minecraft, this.renderBuffers.bufferSource()); @@ -47,8 +47,7 @@ private void onRender(DeltaTracker deltaTracker, boolean tick, CallbackInfo ci) drawContext.flush(); - this.minecraft.getProfiler() - .pop(); + Profiler.get().pop(); HAS_RENDERED_OVERLAY_ONCE = true; } diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/gui/screen/LevelLoadingScreenMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/gui/screen/LevelLoadingScreenMixin.java index e329b371c..f6a236247 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/gui/screen/LevelLoadingScreenMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/gui/screen/LevelLoadingScreenMixin.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.vertex.*; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap; +import net.minecraft.client.renderer.CoreShaders; import org.embeddedt.embeddium.api.vertex.format.common.ColorVertex; import org.embeddedt.embeddium.api.vertex.buffer.VertexBufferWriter; import org.embeddedt.embeddium.api.util.ColorABGR; @@ -55,7 +56,7 @@ public static void renderChunks(GuiGraphics drawContext, StoringChunkProgressLis .forEach(entry -> STATUS_TO_COLOR_FAST.put(entry.getKey(), ColorARGB.toABGR(entry.getIntValue(), 0xFF))); } - RenderSystem.setShader(GameRenderer::getPositionColorShader); + RenderSystem.setShader(CoreShaders.POSITION_COLOR); Matrix4f matrix = drawContext.pose().last().pose(); diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/model/ModelBakeryMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/model/ModelBakeryMixin.java index 7b049e1f6..28f543274 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/model/ModelBakeryMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/model/ModelBakeryMixin.java @@ -3,6 +3,8 @@ import net.minecraft.client.renderer.block.model.BlockElement; import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.resources.model.ModelBakery; +import net.minecraft.client.resources.model.ModelDiscovery; +import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.resources.ResourceLocation; import org.embeddedt.embeddium.impl.model.EpsilonizableBlockElement; import org.spongepowered.asm.mixin.Mixin; @@ -10,13 +12,12 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(ModelBakery.class) +@Mixin(ModelDiscovery.class) public class ModelBakeryMixin { @Inject(method = "loadBlockModel", at = @At("RETURN")) - private void epsilonizeBlockModel(ResourceLocation pLocation, CallbackInfoReturnable cir) { + private void epsilonizeBlockModel(ResourceLocation pLocation, CallbackInfoReturnable cir) { if(pLocation.getPath().startsWith("block/")) { - BlockModel bm = cir.getReturnValue(); - if(bm != null) { + if(cir.getReturnValue() instanceof BlockModel bm) { try { for(BlockElement vanillaElement : bm.getElements()) { ((EpsilonizableBlockElement)vanillaElement).embeddium$epsilonize(); diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/model/MultipartBakedModelMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/model/MultipartBakedModelMixin.java index 066335bc5..71959d57a 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/model/MultipartBakedModelMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/model/MultipartBakedModelMixin.java @@ -35,7 +35,7 @@ public class MultipartBakedModelMixin { @Shadow @Final - private List, BakedModel>> selectors; + private List selectors; @Unique private boolean embeddium$hasCustomRenderTypes; @@ -57,8 +57,8 @@ public class MultipartBakedModelMixin { @Inject(method = "", at = @At("RETURN")) private void checkSubModelRenderTypes(CallbackInfo ci) { boolean hasRenderTypes = false; - for (var pair : selectors) { - var model = pair.getRight(); + for (var selector : selectors) { + var model = selector.model(); // Check for the exact class in case someone extends SimpleBakedModel if (model.getClass() == SimpleBakedModel.class) { // SimpleBakedModel delegates to ItemBlockRenderTypes unless there is an explicit override @@ -90,9 +90,9 @@ private BakedModel[] getModelComponents(BlockState state) { try { List modelList = new ArrayList<>(this.selectors.size()); - for (Pair, BakedModel> pair : this.selectors) { - if (pair.getLeft().test(state)) { - modelList.add(pair.getRight()); + for (var selector : this.selectors) { + if (selector.condition().test(state)) { + modelList.add(selector.model()); } } diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/model/WeightedBakedModelMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/model/WeightedBakedModelMixin.java index 201c9207a..d9da55d15 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/model/WeightedBakedModelMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/model/WeightedBakedModelMixin.java @@ -7,11 +7,14 @@ import net.minecraft.client.resources.model.WeightedBakedModel; import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; +import net.minecraft.util.random.SimpleWeightedRandomList; import net.minecraft.util.random.WeightedEntry; +import net.minecraft.util.random.WeightedEntry.Wrapper; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.neoforge.client.ChunkRenderTypeSet; import net.neoforged.neoforge.client.model.data.ModelData; import org.embeddedt.embeddium.impl.model.UnwrappableBakedModel; +import org.embeddedt.embeddium.impl.util.collections.WeightedRandomListExtended; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.*; @@ -22,11 +25,11 @@ public class WeightedBakedModelMixin implements UnwrappableBakedModel { @Shadow @Final - private List> list; + private SimpleWeightedRandomList list; - @Shadow - @Final - private int totalWeight; + private WeightedEntry.Wrapper embeddium$readWeightedList(RandomSource random) { + return ((WeightedRandomListExtended>)this.list).embeddium$getRandomItem(random); + } /** * @author JellySquid @@ -34,11 +37,10 @@ public class WeightedBakedModelMixin implements UnwrappableBakedModel { */ @Overwrite public List getQuads(@Nullable BlockState state, @Nullable Direction face, RandomSource random, ModelData modelData, RenderType renderLayer) { - WeightedEntry.Wrapper quad = getAt(this.list, Math.abs((int) random.nextLong()) % this.totalWeight); + var quad = embeddium$readWeightedList(random); if (quad != null) { - return quad.data() - .getQuads(state, face, random, modelData, renderLayer); + return quad.data().getQuads(state, face, random, modelData, renderLayer); } return Collections.emptyList(); @@ -48,9 +50,9 @@ public List getQuads(@Nullable BlockState state, @Nullable Direction * @author embeddedt * @reason Avoid excessive object allocations */ - @Overwrite + @Overwrite(remap = false) public ChunkRenderTypeSet getRenderTypes(@NotNull BlockState state, @NotNull RandomSource rand, @NotNull ModelData data) { - WeightedEntry.Wrapper quad = getAt(this.list, Math.abs((int) rand.nextLong()) % this.totalWeight); + var quad = embeddium$readWeightedList(rand); if (quad != null) { return quad.data().getRenderTypes(state, rand, data); @@ -59,28 +61,9 @@ public ChunkRenderTypeSet getRenderTypes(@NotNull BlockState state, @NotNull Ran return ChunkRenderTypeSet.none(); } - @Unique - private static T getAt(List pool, int totalWeight) { - int i = 0; - int len = pool.size(); - - T weighted; - - do { - if (i >= len) { - return null; - } - - weighted = pool.get(i++); - totalWeight -= weighted.getWeight().asInt(); - } while (totalWeight >= 0); - - return weighted; - } - @Override public @Nullable BakedModel embeddium$getInnerModel(RandomSource rand) { - WeightedEntry.Wrapper quad = getAt(this.list, Math.abs((int) rand.nextLong()) % this.totalWeight); + var quad = embeddium$readWeightedList(rand); if (quad != null && quad.data().getClass() == SimpleBakedModel.class) { return quad.data(); diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/options/weather/WorldRendererMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/options/weather/WorldRendererMixin.java index 8f8e452bb..4d63f4352 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/options/weather/WorldRendererMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/options/weather/WorldRendererMixin.java @@ -1,5 +1,6 @@ package org.embeddedt.embeddium.impl.mixin.features.options.weather; +import net.minecraft.client.renderer.WeatherEffectRenderer; import org.embeddedt.embeddium.impl.Embeddium; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.LevelRenderer; @@ -7,9 +8,9 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -@Mixin(LevelRenderer.class) +@Mixin(WeatherEffectRenderer.class) public class WorldRendererMixin { - @Redirect(method = "renderSnowAndRain", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;useFancyGraphics()Z")) + @Redirect(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;useFancyGraphics()Z")) private boolean redirectGetFancyWeather() { return Embeddium.options().quality.weatherQuality.isFancy(Minecraft.getInstance().options.graphicsMode().get()); } diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/entity/cull/EntityRendererAccessor.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/entity/cull/EntityRendererAccessor.java new file mode 100644 index 000000000..939e60818 --- /dev/null +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/entity/cull/EntityRendererAccessor.java @@ -0,0 +1,14 @@ +package org.embeddedt.embeddium.impl.mixin.features.render.entity.cull; + +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.AABB; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(EntityRenderer.class) +public interface EntityRendererAccessor { + @Invoker + AABB callGetBoundingBoxForCulling(Entity entity); +} diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/entity/cull/EntityRendererMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/entity/cull/EntityRendererMixin.java index 965c11b63..32e56846e 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/entity/cull/EntityRendererMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/entity/cull/EntityRendererMixin.java @@ -24,7 +24,7 @@ private boolean checkSectionForCullingMain(boolean isWithinFrustum, @Local(ordin var renderer = EmbeddiumWorldRenderer.instanceNullable(); - return renderer == null || renderer.isEntityVisible(entity); + return renderer == null || renderer.isEntityVisible(entity, (EntityRenderer)(Object)this); } @ModifyExpressionValue(method = "shouldRender", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/culling/Frustum;isVisible(Lnet/minecraft/world/phys/AABB;)Z", ordinal = 1)) @@ -37,6 +37,6 @@ private boolean checkSectionForCullingMain(boolean isWithinFrustum, @Local(ordin var renderer = EmbeddiumWorldRenderer.instanceNullable(); - return renderer == null || renderer.isEntityVisible(leashable.getLeashHolder()); + return renderer == null || renderer.isEntityVisible(leashable.getLeashHolder(), (EntityRenderer)(Object)this); } } diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/entity/remove_streams/HierarchicalModelMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/entity/remove_streams/HierarchicalModelMixin.java deleted file mode 100644 index aa05d36e4..000000000 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/entity/remove_streams/HierarchicalModelMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.embeddedt.embeddium.impl.mixin.features.render.entity.remove_streams; - -import net.minecraft.client.model.HierarchicalModel; -import net.minecraft.client.model.geom.ModelPart; -import org.embeddedt.embeddium.render.entity.ModelPartExtended; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import org.spongepowered.asm.mixin.Shadow; - -import java.util.Optional; - -@Mixin(HierarchicalModel.class) -public abstract class HierarchicalModelMixin { - @Shadow - public abstract ModelPart root(); - - /** - * @author embeddedt - * @reason replace stream with cached lookup from map - */ - @Overwrite - public Optional getAnyDescendantWithName(String pName) { - var extendedRoot = ModelPartExtended.of(this.root()); - if(pName.equals("root")) { - return extendedRoot.embeddium$asOptional(); - } else { - var part = extendedRoot.embeddium$getDescendantsByName().get(pName); - return part != null ? ModelPartExtended.of(part).embeddium$asOptional() : Optional.empty(); - } - } -} diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/gui/font/GlyphRendererMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/gui/font/GlyphRendererMixin.java index 7e6d6fc98..8086f09e3 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/gui/font/GlyphRendererMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/gui/font/GlyphRendererMixin.java @@ -1,6 +1,7 @@ package org.embeddedt.embeddium.impl.mixin.features.render.gui.font; import com.mojang.blaze3d.vertex.VertexConsumer; +import org.embeddedt.embeddium.api.util.ColorARGB; import org.embeddedt.embeddium.api.vertex.format.common.GlyphVertex; import net.minecraft.client.gui.font.glyphs.BakedGlyph; import org.embeddedt.embeddium.api.vertex.buffer.VertexBufferWriter; @@ -51,14 +52,15 @@ public class GlyphRendererMixin { * @reason Use intrinsics * @author JellySquid */ - @Inject(method = "render", at = @At("HEAD"), cancellable = true) - private void renderFast(boolean italic, float x, float y, Matrix4f matrix, VertexConsumer vertexConsumer, float red, float green, float blue, float alpha, int light, CallbackInfo ci) { - if(drawFast(italic, x, y, matrix, vertexConsumer, red, green, blue, alpha, light)) { + @Inject(method = "render(ZFFFLorg/joml/Matrix4f;Lcom/mojang/blaze3d/vertex/VertexConsumer;IZI)V", at = @At("HEAD"), cancellable = true) + private void renderFast(boolean italic, float x, float y, float z, Matrix4f matrix, VertexConsumer vertexConsumer, int color, boolean applyBoldScale, int light, CallbackInfo ci) { + int packedColor = ColorARGB.toABGR(color); + if (drawFast(italic, x, y, z, matrix, vertexConsumer, packedColor, light, applyBoldScale)) { ci.cancel(); } } - private boolean drawFast(boolean italic, float x, float y, Matrix4f matrix, VertexConsumer vertexConsumer, float red, float green, float blue, float alpha, int light) { + private boolean drawFast(boolean italic, float x, float y, float z, Matrix4f matrix, VertexConsumer vertexConsumer, int color, int light, boolean applyBoldScale) { var writer = VertexBufferWriter.tryOf(vertexConsumer); if (writer == null) @@ -70,23 +72,22 @@ private boolean drawFast(boolean italic, float x, float y, Matrix4f matrix, Vert float h2 = y + this.down; float w1 = italic ? 1.0F - 0.25F * this.up : 0.0F; float w2 = italic ? 1.0F - 0.25F * this.down : 0.0F; - - int color = ColorABGR.pack(red, green, blue, alpha); + float boldScale = applyBoldScale ? 0.1F : 0.0F; try (MemoryStack stack = MemoryStack.stackPush()) { long buffer = stack.nmalloc(4 * GlyphVertex.STRIDE); long ptr = buffer; - write(ptr, matrix, x1 + w1, h1, 0.0F, color, this.u0, this.v0, light); + write(ptr, matrix, x1 + w1 - boldScale, h1 - boldScale, z, color, this.u0, this.v0, light); ptr += GlyphVertex.STRIDE; - write(ptr, matrix, x1 + w2, h2, 0.0F, color, this.u0, this.v1, light); + write(ptr, matrix, x1 + w2 - boldScale, h2 + boldScale, z, color, this.u0, this.v1, light); ptr += GlyphVertex.STRIDE; - write(ptr, matrix, x2 + w2, h2, 0.0F, color, this.u1, this.v1, light); + write(ptr, matrix, x2 + w2 + boldScale, h2 + boldScale, z, color, this.u1, this.v1, light); ptr += GlyphVertex.STRIDE; - write(ptr, matrix, x2 + w1, h1, 0.0F, color, this.u1, this.v0, light); + write(ptr, matrix, x2 + w1 + boldScale, h1 - boldScale, z, color, this.u1, this.v0, light); ptr += GlyphVertex.STRIDE; writer.push(stack, buffer, 4, GlyphVertex.FORMAT); diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/immediate/DirectionMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/immediate/DirectionMixin.java index 2c625d5b0..b6b74f673 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/immediate/DirectionMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/immediate/DirectionMixin.java @@ -29,7 +29,7 @@ public class DirectionMixin { */ @SuppressWarnings({ "StatementWithEmptyBody", "JavadocReference" }) @Overwrite - public static Direction getNearest(float x, float y, float z) { + public static Direction getApproximateNearest(float x, float y, float z) { // Vanilla quirk: return NORTH if all coordinates are zero if (x == 0 && y == 0 && z == 0) return Direction.NORTH; diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/model/item/ItemRendererMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/model/item/ItemRendererMixin.java deleted file mode 100644 index 67719a1f5..000000000 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/model/item/ItemRendererMixin.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.embeddedt.embeddium.impl.mixin.features.render.model.item; - -import org.embeddedt.embeddium.impl.model.quad.BakedQuadView; -import org.embeddedt.embeddium.impl.render.immediate.model.BakedModelEncoder; -import org.embeddedt.embeddium.api.render.texture.SpriteUtil; -import org.embeddedt.embeddium.impl.render.vertex.VertexConsumerUtils; -import org.embeddedt.embeddium.impl.model.color.interop.ItemColorsExtended; -import org.embeddedt.embeddium.impl.util.DirectionUtil; -import org.embeddedt.embeddium.api.util.ColorARGB; -import org.embeddedt.embeddium.api.vertex.buffer.VertexBufferWriter; -import net.minecraft.client.color.item.ItemColor; -import net.minecraft.client.color.item.ItemColors; -import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.entity.ItemRenderer; -import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.core.Direction; -import net.minecraft.util.RandomSource; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.levelgen.SingleThreadedRandomSource; -import org.spongepowered.asm.mixin.*; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.VertexConsumer; -import java.util.List; - -@Mixin(ItemRenderer.class) -public class ItemRendererMixin { - @Unique - private final RandomSource random = new SingleThreadedRandomSource(42L); - - @Shadow - @Final - private ItemColors itemColors; - - /** - * @reason Avoid allocations - * @author JellySquid - */ - @Inject(method = "renderModelLists", at = @At("HEAD"), cancellable = true) - private void renderModelFast(BakedModel model, ItemStack itemStack, int light, int overlay, PoseStack matrixStack, VertexConsumer vertexConsumer, CallbackInfo ci) { - var writer = VertexConsumerUtils.convertOrLog(vertexConsumer); - - if (writer == null) { - return; - } - - ci.cancel(); - - RandomSource random = this.random; - PoseStack.Pose matrices = matrixStack.last(); - - ItemColor colorProvider = null; - - if (!itemStack.isEmpty()) { - colorProvider = ((ItemColorsExtended) this.itemColors).sodium$getColorProvider(itemStack); - } - - for (Direction direction : DirectionUtil.ALL_DIRECTIONS) { - random.setSeed(42L); - List quads = model.getQuads(null, direction, random); - - if (!quads.isEmpty()) { - this.renderBakedItemQuads(matrices, writer, quads, itemStack, colorProvider, light, overlay); - } - } - - random.setSeed(42L); - List quads = model.getQuads(null, null, random); - - if (!quads.isEmpty()) { - this.renderBakedItemQuads(matrices, writer, quads, itemStack, colorProvider, light, overlay); - } - } - - @Unique - @SuppressWarnings("ForLoopReplaceableByForEach") - private void renderBakedItemQuads(PoseStack.Pose matrices, VertexBufferWriter writer, List quads, ItemStack itemStack, ItemColor colorProvider, int light, int overlay) { - for (int i = 0; i < quads.size(); i++) { - BakedQuad bakedQuad = quads.get(i); - - if (bakedQuad.getVertices().length < 32) { - continue; // ignore bad quads - } - - BakedQuadView quad = (BakedQuadView) bakedQuad; - - int color = 0xFFFFFFFF; - - if (colorProvider != null && quad.hasColor()) { - color = ColorARGB.toABGR(colorProvider.getColor(itemStack, quad.getColorIndex())); - } - - BakedModelEncoder.writeQuadVertices(writer, matrices, quad, color, light, overlay, true); - - SpriteUtil.markSpriteActive(quad.getSprite()); - } - } -} diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/world/ClientLevelMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/world/ClientLevelMixin.java index 52ef5ff1a..3cf861d7a 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/world/ClientLevelMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/world/ClientLevelMixin.java @@ -33,8 +33,16 @@ // Use a very low priority so most injects into doAnimateTick will still work @Mixin(value = ClientLevel.class, priority = 500) public abstract class ClientLevelMixin extends Level { - protected ClientLevelMixin(WritableLevelData p_270739_, ResourceKey p_270683_, RegistryAccess p_270200_, Holder p_270240_, Supplier p_270692_, boolean p_270904_, boolean p_270470_, long p_270248_, int p_270466_) { - super(p_270739_, p_270683_, p_270200_, p_270240_, p_270692_, p_270904_, p_270470_, p_270248_, p_270466_); + protected ClientLevelMixin( + final WritableLevelData p_270739_, + final ResourceKey p_270683_, + final RegistryAccess p_270200_, + final Holder p_270240_, + final boolean p_270904_, + final boolean p_270470_, + final long p_270248_, + final int p_270466_) { + super(p_270739_, p_270683_, p_270200_, p_270240_, p_270904_, p_270470_, p_270248_, p_270466_); } @Shadow diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/world/clouds/WorldRendererMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/world/clouds/WorldRendererMixin.java deleted file mode 100644 index 611e028a8..000000000 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/world/clouds/WorldRendererMixin.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.embeddedt.embeddium.impl.mixin.features.render.world.clouds; - -import com.mojang.blaze3d.vertex.PoseStack; -import org.embeddedt.embeddium.impl.render.immediate.CloudRenderer; -import net.minecraft.client.Minecraft; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.server.packs.resources.ResourceManager; -import org.jetbrains.annotations.Nullable; -import org.joml.Matrix4f; -import org.spongepowered.asm.mixin.*; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(value = LevelRenderer.class, priority = 990) -public class WorldRendererMixin { - @Shadow - private @Nullable ClientLevel level; - @Shadow - private int ticks; - - @Shadow - @Final - private Minecraft minecraft; - - @Unique - private CloudRenderer cloudRenderer; - - /** - * @author jellysquid3 - * @reason Optimize cloud rendering - */ - @Inject(method = "renderClouds", at = @At(value = "INVOKE", target = "Ljava/lang/Float;isNaN(F)Z", ordinal = 0), cancellable = true) - public void renderCloudsFast(PoseStack matrices, Matrix4f modelViewMatrix, Matrix4f projectionMatrix, float tickDelta, double x, double y, double z, CallbackInfo ci) { - if (this.cloudRenderer == null) { - this.cloudRenderer = new CloudRenderer(this.minecraft.getResourceManager()); - } - - boolean renderFasterClouds = true; //!Screen.hasAltDown() - - if (renderFasterClouds) { - this.cloudRenderer.render(this.level, this.minecraft.player, matrices, modelViewMatrix, projectionMatrix, this.ticks, tickDelta, x, y, z); - ci.cancel(); - } - } - - @Inject(method = "onResourceManagerReload(Lnet/minecraft/server/packs/resources/ResourceManager;)V", at = @At("RETURN")) - private void onReload(ResourceManager manager, CallbackInfo ci) { - if (this.cloudRenderer != null) { - this.cloudRenderer.reloadTextures(manager); - } - } - - @Inject(method = "allChanged()V", at = @At("RETURN")) - private void onReload(CallbackInfo ci) { - // will be re-allocated on next use - if (this.cloudRenderer != null) { - this.cloudRenderer.destroy(); - this.cloudRenderer = null; - } - } - - @Inject(method = "close", at = @At("RETURN")) - private void onClose(CallbackInfo ci) { - // will never be re-allocated, as the renderer is shutting down - if (this.cloudRenderer != null) { - this.cloudRenderer.destroy(); - this.cloudRenderer = null; - } - } -} diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/world/sky/BackgroundRendererMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/world/sky/BackgroundRendererMixin.java index 4bc265dec..fb62cda07 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/world/sky/BackgroundRendererMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/world/sky/BackgroundRendererMixin.java @@ -13,7 +13,11 @@ @Mixin(FogRenderer.class) public class BackgroundRendererMixin { - @Redirect(method = "setupColor", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/CubicSampler;gaussianSampleVec3(Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/util/CubicSampler$Vec3Fetcher;)Lnet/minecraft/world/phys/Vec3;")) + @Redirect( + method = "computeFogColor", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/util/CubicSampler;gaussianSampleVec3(Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/util/CubicSampler$Vec3Fetcher;)Lnet/minecraft/world/phys/Vec3;")) private static Vec3 redirectSampleColor(Vec3 pos, CubicSampler.Vec3Fetcher rgbFetcher, Camera camera, float tickDelta, ClientLevel world, int i, float f) { float u = Mth.clamp(Mth.cos(world.getTimeOfDay(tickDelta) * 6.2831855F) * 2.0F + 0.5F, 0.0F, 1.0F); diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/world/sky/WorldRendererMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/world/sky/WorldRendererMixin.java index 13e2a2fb0..774723f57 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/world/sky/WorldRendererMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/render/world/sky/WorldRendererMixin.java @@ -1,6 +1,8 @@ package org.embeddedt.embeddium.impl.mixin.features.render.world.sky; +import com.mojang.blaze3d.framegraph.FrameGraphBuilder; import net.minecraft.client.Camera; +import net.minecraft.client.renderer.FogParameters; import net.minecraft.client.renderer.FogRenderer; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.world.level.material.FogType; @@ -30,13 +32,17 @@ public class WorldRendererMixin { *

When updating Sodium to new releases of the game, please check for new * ways the fog can be reduced in {@link FogRenderer#setupFog(Camera, FogRenderer.FogMode, float, boolean, float)} ()}.

*/ - @Inject(method = "renderSky", at = @At("HEAD"), cancellable = true) - private void preRenderSky(Matrix4f matrices, Matrix4f projectionMatrix, float tickDelta, Camera camera, boolean bl, Runnable runnable, CallbackInfo ci) { + @Inject(method = "addSkyPass", at = @At("HEAD"), cancellable = true) + private void preRenderSky(FrameGraphBuilder frameGraphBuilder, Camera camera, float f, FogParameters fogParameters, CallbackInfo ci) { // Cancels sky rendering when the camera is submersed underwater. // This prevents the sky from being visible through chunks culled by Sodium's fog occlusion. // Fixes https://bugs.mojang.com/browse/MC-152504. // Credit to bytzo for noticing the change in 1.18.2. - if (!ShaderModBridge.areShadersEnabled() && camera.getFluidInCamera() == FogType.WATER) { + if (ShaderModBridge.areShadersEnabled()) { + return; + } + + if (camera.getFluidInCamera() == FogType.WATER) { ci.cancel(); } } diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/shader/uniform/ShaderProgramMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/shader/uniform/ShaderProgramMixin.java index bf9933e8a..a34b9b3bf 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/shader/uniform/ShaderProgramMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/shader/uniform/ShaderProgramMixin.java @@ -1,21 +1,16 @@ package org.embeddedt.embeddium.impl.mixin.features.shader.uniform; -import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.mojang.blaze3d.shaders.Uniform; -import com.mojang.blaze3d.systems.RenderSystem; -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; import java.util.Collections; import java.util.List; -import net.minecraft.client.renderer.ShaderInstance; +import net.minecraft.client.renderer.CompiledShaderProgram; /** * On the NVIDIA drivers (and maybe some others), the OpenGL submission thread requires expensive state synchronization @@ -23,50 +18,14 @@ * these uniform locations can be trivially cached. */ // High priority so replacement happens before other mods increase the sampler count, so that we see the updated value -@Mixin(value = ShaderInstance.class, priority = 500) +@Mixin(value = CompiledShaderProgram.class, priority = 500) public abstract class ShaderProgramMixin { - @Shadow - @Final - private List samplerNames; - - @Shadow - @Final - private int programId; - @Shadow @Final private List uniforms; - @Shadow - public abstract void setSampler(String p_173351_, Object p_173352_); - - @Unique - private Object2IntMap uniformCache; - - @Redirect(method = "apply", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/shaders/Uniform;glGetUniformLocation(ILjava/lang/CharSequence;)I")) - private int redirectGetUniformLocation(int program, CharSequence name) { - if(this.uniformCache == null) { - this.uniformCache = new Object2IntOpenHashMap<>(); - this.uniformCache.defaultReturnValue(-1); - - for (var samplerName : this.samplerNames) { - var location = Uniform.glGetUniformLocation(this.programId, samplerName); - - if(location != -1) - this.uniformCache.put(samplerName, location); - } - } - var location = this.uniformCache.getInt(name); - - if (location == -1) { - throw new IllegalStateException("Failed to find uniform '%s' during shader bind".formatted(name)); - } - - return location; - } - - @Redirect(method = "apply", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/ShaderInstance;uniforms:Ljava/util/List;", ordinal = 0)) - private List uploadUniforms(ShaderInstance instance) { + @Redirect(method = "apply", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/CompiledShaderProgram;uniforms:Ljava/util/List;", ordinal = 0)) + private List uploadUniforms(CompiledShaderProgram instance) { List uniforms = this.uniforms; //noinspection ForLoopReplaceableByForEach for(int i = 0; i < uniforms.size(); i++) { @@ -74,32 +33,4 @@ private List uploadUniforms(ShaderInstance instance) { } return Collections.emptyList(); } - - private static final int DEFAULT_NUM_SAMPLERS = 12; - private static String[] SAMPLER_IDS = embeddium$makeSamplerIds(DEFAULT_NUM_SAMPLERS); - - private static String[] embeddium$makeSamplerIds(int len) { - String[] samplerIds = new String[len]; - for(int i = 0; i < len; i++) { - samplerIds[i] = "Sampler" + i; - } - return samplerIds; - } - - /** - * @author embeddedt - * @reason Avoid regenerating the sampler ID strings every time a buffer is drawn - */ - @ModifyExpressionValue(method = "setDefaultUniforms", at = @At(value = "CONSTANT", args = "intValue=" + DEFAULT_NUM_SAMPLERS, ordinal = 0)) - private int setSamplersManually(int numSamplers) { - String[] samplerIds = SAMPLER_IDS; - if (samplerIds.length < numSamplers) { - samplerIds = embeddium$makeSamplerIds(numSamplers); - SAMPLER_IDS = samplerIds; - } - for(int i = 0; i < numSamplers; i++) { - setSampler(samplerIds[i], RenderSystem.getShaderTexture(i)); - } - return 0; - } } diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/animations/tracking/DrawContextMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/animations/tracking/DrawContextMixin.java index 47b3900e8..2f6df225b 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/animations/tracking/DrawContextMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/animations/tracking/DrawContextMixin.java @@ -1,5 +1,7 @@ package org.embeddedt.embeddium.impl.mixin.features.textures.animations.tracking; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.resources.ResourceLocation; import org.embeddedt.embeddium.api.render.texture.SpriteUtil; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -8,23 +10,18 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.function.Function; + @Mixin(GuiGraphics.class) public class DrawContextMixin { - @Inject(method = "blit(IIIIILnet/minecraft/client/renderer/texture/TextureAtlasSprite;)V", at = @At("HEAD")) - private void preDrawSprite(int x, int y, int z, - int width, int height, - TextureAtlasSprite sprite, - CallbackInfo ci) + @Inject(method = "blitSprite(Ljava/util/function/Function;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;IIIIIIIII)V", at = @At("HEAD")) + private void preDrawSprite(Function function, TextureAtlasSprite sprite, int i, int j, int k, int l, int m, int n, int o, int p, int q, CallbackInfo ci) { SpriteUtil.markSpriteActive(sprite); } - @Inject(method = "blit(IIIIILnet/minecraft/client/renderer/texture/TextureAtlasSprite;FFFF)V", at = @At("HEAD")) - private void preDrawSprite(int x, int y, int z, - int width, int height, - TextureAtlasSprite sprite, - float red, float green, float blue, float alpha, - CallbackInfo ci) + @Inject(method = "blitSprite(Ljava/util/function/Function;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;IIIII)V", at = @At("HEAD")) + private void preDrawSprite(Function function, TextureAtlasSprite sprite, int i, int j, int k, int l, int m, CallbackInfo ci) { SpriteUtil.markSpriteActive(sprite); } diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/animations/tracking/SpriteContentsAnimatorImplMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/animations/tracking/SpriteContentsAnimatorImplMixin.java index 73fb73c48..bb0fe212e 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/animations/tracking/SpriteContentsAnimatorImplMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/animations/tracking/SpriteContentsAnimatorImplMixin.java @@ -44,7 +44,7 @@ private void preTick(CallbackInfo ci) { if (onDemand && !parent.sodium$isActive()) { this.subFrame++; List frames = ((SpriteContentsAnimationAccessor)this.animationInfo).getFrames(); - if (this.subFrame >= ((SpriteContentsAnimationFrameAccessor)frames.get(this.frame)).getTime()) { + if (this.subFrame >= ((SpriteContentsAnimationFrameAccessor)(Object)frames.get(this.frame)).getTime()) { this.frame = (this.frame + 1) % frames.size(); this.subFrame = 0; } diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/animations/upload/SpriteContentsInterpolationMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/animations/upload/SpriteContentsInterpolationMixin.java index a90853186..28437d838 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/animations/upload/SpriteContentsInterpolationMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/animations/upload/SpriteContentsInterpolationMixin.java @@ -43,10 +43,10 @@ void uploadInterpolatedFrame(int x, int y, SpriteContents.Ticker arg) { SpriteContentsAnimationAccessor animation2 = (SpriteContentsAnimationAccessor) ((SpriteContentsAnimatorImplAccessor) arg).getAnimationInfo(); List frames = ((SpriteContentsAnimationAccessor) animation).getFrames(); SpriteContentsAnimatorImplAccessor accessor = (SpriteContentsAnimatorImplAccessor) arg; - SpriteContentsAnimationFrameAccessor animationFrame = (SpriteContentsAnimationFrameAccessor) frames.get(accessor.getFrameIndex()); + SpriteContentsAnimationFrameAccessor animationFrame = (SpriteContentsAnimationFrameAccessor)(Object)frames.get(accessor.getFrameIndex()); int curIndex = animationFrame.getIndex(); - int nextIndex = ((SpriteContentsAnimationFrameAccessor) animation2.getFrames().get((accessor.getFrameIndex() + 1) % frames.size())).getIndex(); + int nextIndex = ((SpriteContentsAnimationFrameAccessor)(Object)animation2.getFrames().get((accessor.getFrameIndex() + 1) % frames.size())).getIndex(); if (curIndex == nextIndex) { return; diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/mipmaps/MipmapHelperMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/mipmaps/MipmapHelperMixin.java index e23ee0d70..c7cfb3f0c 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/mipmaps/MipmapHelperMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/mipmaps/MipmapHelperMixin.java @@ -1,8 +1,8 @@ package org.embeddedt.embeddium.impl.mixin.features.textures.mipmaps; +import net.minecraft.util.ARGB; import org.embeddedt.embeddium.impl.util.color.ColorSRGB; import net.minecraft.client.renderer.texture.MipmapGenerator; -import net.minecraft.util.FastColor; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Unique; @@ -42,8 +42,8 @@ private static int alphaBlend(int one, int two, int three, int four, boolean che @Unique private static int weightedAverageColor(int one, int two) { - int alphaOne = FastColor.ABGR32.alpha(one); - int alphaTwo = FastColor.ABGR32.alpha(two); + int alphaOne = ARGB.alpha(one); + int alphaTwo = ARGB.alpha(two); // In the case where the alpha values of the same, we can get by with an unweighted average. if (alphaOne == alphaTwo) { @@ -68,13 +68,13 @@ private static int weightedAverageColor(int one, int two) { float relativeWeightTwo = alphaTwo * scale; // Convert the color components into linear space, then multiply the corresponding weight. - float oneR = ColorSRGB.srgbToLinear(FastColor.ABGR32.red(one)) * relativeWeightOne; - float oneG = ColorSRGB.srgbToLinear(FastColor.ABGR32.green(one)) * relativeWeightOne; - float oneB = ColorSRGB.srgbToLinear(FastColor.ABGR32.blue(one)) * relativeWeightOne; + float oneR = ColorSRGB.srgbToLinear(ARGB.red(one)) * relativeWeightOne; + float oneG = ColorSRGB.srgbToLinear(ARGB.green(one)) * relativeWeightOne; + float oneB = ColorSRGB.srgbToLinear(ARGB.blue(one)) * relativeWeightOne; - float twoR = ColorSRGB.srgbToLinear(FastColor.ABGR32.red(two)) * relativeWeightTwo; - float twoG = ColorSRGB.srgbToLinear(FastColor.ABGR32.green(two)) * relativeWeightTwo; - float twoB = ColorSRGB.srgbToLinear(FastColor.ABGR32.blue(two)) * relativeWeightTwo; + float twoR = ColorSRGB.srgbToLinear(ARGB.red(two)) * relativeWeightTwo; + float twoG = ColorSRGB.srgbToLinear(ARGB.green(two)) * relativeWeightTwo; + float twoB = ColorSRGB.srgbToLinear(ARGB.blue(two)) * relativeWeightTwo; // Combine the color components of each color float linearR = oneR + twoR; @@ -91,13 +91,13 @@ private static int weightedAverageColor(int one, int two) { // Computes a non-weighted average of the two sRGB colors in linear space, avoiding brightness losses. @Unique private static int averageRgb(int a, int b, int alpha) { - float ar = ColorSRGB.srgbToLinear(FastColor.ABGR32.red(a)); - float ag = ColorSRGB.srgbToLinear(FastColor.ABGR32.green(a)); - float ab = ColorSRGB.srgbToLinear(FastColor.ABGR32.blue(a)); + float ar = ColorSRGB.srgbToLinear(ARGB.red(a)); + float ag = ColorSRGB.srgbToLinear(ARGB.green(a)); + float ab = ColorSRGB.srgbToLinear(ARGB.blue(a)); - float br = ColorSRGB.srgbToLinear(FastColor.ABGR32.red(b)); - float bg = ColorSRGB.srgbToLinear(FastColor.ABGR32.green(b)); - float bb = ColorSRGB.srgbToLinear(FastColor.ABGR32.blue(b)); + float br = ColorSRGB.srgbToLinear(ARGB.red(b)); + float bg = ColorSRGB.srgbToLinear(ARGB.green(b)); + float bb = ColorSRGB.srgbToLinear(ARGB.blue(b)); return ColorSRGB.linearToSrgb((ar + br) * 0.5f, (ag + bg) * 0.5f, (ab + bb) * 0.5f, alpha); } diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/mipmaps/SpriteContentsMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/mipmaps/SpriteContentsMixin.java index fb6a9f755..2a9301410 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/mipmaps/SpriteContentsMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/features/textures/mipmaps/SpriteContentsMixin.java @@ -1,12 +1,12 @@ package org.embeddedt.embeddium.impl.mixin.features.textures.mipmaps; import com.mojang.blaze3d.platform.NativeImage; +import net.minecraft.util.ARGB; import org.embeddedt.embeddium.impl.util.NativeImageHelper; import org.embeddedt.embeddium.impl.util.color.ColorSRGB; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.SpriteContents; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.FastColor; import org.embeddedt.embeddium.impl.render.chunk.sprite.SpriteTransparencyLevel; import org.embeddedt.embeddium.impl.render.chunk.sprite.SpriteTransparencyLevelHolder; import org.lwjgl.system.MemoryUtil; @@ -80,7 +80,7 @@ public class SpriteContentsMixin implements SpriteTransparencyLevelHolder { long pPixel = ppPixel + (pixelIndex * 4); int color = MemoryUtil.memGetInt(pPixel); - int alpha = FastColor.ABGR32.alpha(color); + int alpha = ARGB.alpha(color); // Ignore all fully-transparent pixels for the purposes of computing an average color. if (alpha > 0) { @@ -94,9 +94,9 @@ public class SpriteContentsMixin implements SpriteTransparencyLevelHolder { float weight = (float) alpha; // Make sure to convert to linear space so that we don't lose brightness. - r += ColorSRGB.srgbToLinear(FastColor.ABGR32.red(color)) * weight; - g += ColorSRGB.srgbToLinear(FastColor.ABGR32.green(color)) * weight; - b += ColorSRGB.srgbToLinear(FastColor.ABGR32.blue(color)) * weight; + r += ColorSRGB.srgbToLinear(ARGB.red(color)) * weight; + g += ColorSRGB.srgbToLinear(ARGB.green(color)) * weight; + b += ColorSRGB.srgbToLinear(ARGB.blue(color)) * weight; totalWeight += weight; } @@ -124,7 +124,7 @@ public class SpriteContentsMixin implements SpriteTransparencyLevelHolder { long pPixel = ppPixel + (pixelIndex * 4); int color = MemoryUtil.memGetInt(pPixel); - int alpha = FastColor.ABGR32.alpha(color); + int alpha = ARGB.alpha(color); // Replace the color values of pixels which are fully transparent, since they have no color data. if (alpha == 0) { diff --git a/src/main/java/org/embeddedt/embeddium/impl/mixin/workarounds/context_creation/WindowMixin.java b/src/main/java/org/embeddedt/embeddium/impl/mixin/workarounds/context_creation/WindowMixin.java index 9f5d23480..7123be911 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/mixin/workarounds/context_creation/WindowMixin.java +++ b/src/main/java/org/embeddedt/embeddium/impl/mixin/workarounds/context_creation/WindowMixin.java @@ -88,7 +88,7 @@ private GLCapabilities postWindowCreated() { return caps; } - @Inject(method = "updateDisplay", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;flipFrame(J)V", shift = At.Shift.AFTER)) + @Inject(method = "updateDisplay", at = @At(value = "RETURN")) private void preSwapBuffers(CallbackInfo ci) { if (this.wglPrevContext == MemoryUtil.NULL) { // There is no prior recorded context. diff --git a/src/main/java/org/embeddedt/embeddium/impl/model/color/interop/ItemColorsExtended.java b/src/main/java/org/embeddedt/embeddium/impl/model/color/interop/ItemColorsExtended.java deleted file mode 100644 index 96dddb142..000000000 --- a/src/main/java/org/embeddedt/embeddium/impl/model/color/interop/ItemColorsExtended.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.embeddedt.embeddium.impl.model.color.interop; - -import net.minecraft.client.color.item.ItemColor; -import net.minecraft.world.item.ItemStack; - -public interface ItemColorsExtended { - ItemColor sodium$getColorProvider(ItemStack stack); -} diff --git a/src/main/java/org/embeddedt/embeddium/impl/model/light/data/LightDataAccess.java b/src/main/java/org/embeddedt/embeddium/impl/model/light/data/LightDataAccess.java index 88dbb3076..f31981efb 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/model/light/data/LightDataAccess.java +++ b/src/main/java/org/embeddedt/embeddium/impl/model/light/data/LightDataAccess.java @@ -64,8 +64,8 @@ protected int compute(int x, int y, int z) { BlockState state = world.getBlockState(pos); boolean em = state.emissiveRendering(world, pos); - boolean op = state.isViewBlocking(world, pos) && state.getLightBlock(world, pos) != 0; - boolean fo = state.isSolidRender(world, pos); + boolean op = state.isViewBlocking(world, pos) && state.getLightBlock() != 0; + boolean fo = state.isSolidRender(); boolean fc = state.isCollisionShapeFullBlock(world, pos); int lu = state.getLightEmission(world, pos); diff --git a/src/main/java/org/embeddedt/embeddium/impl/model/quad/BakedQuadView.java b/src/main/java/org/embeddedt/embeddium/impl/model/quad/BakedQuadView.java index cb752e6a6..b209e1b9c 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/model/quad/BakedQuadView.java +++ b/src/main/java/org/embeddedt/embeddium/impl/model/quad/BakedQuadView.java @@ -7,5 +7,5 @@ public interface BakedQuadView extends ModelQuadView { boolean hasShade(); - void setFlags(int flags); + void addFlags(int flags); } diff --git a/src/main/java/org/embeddedt/embeddium/impl/render/EmbeddiumWorldRenderer.java b/src/main/java/org/embeddedt/embeddium/impl/render/EmbeddiumWorldRenderer.java index 7954c6346..dbf707ff5 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/render/EmbeddiumWorldRenderer.java +++ b/src/main/java/org/embeddedt/embeddium/impl/render/EmbeddiumWorldRenderer.java @@ -7,9 +7,12 @@ import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexMultiConsumer; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.util.profiling.Profiler; import org.embeddedt.embeddium.impl.Embeddium; import org.embeddedt.embeddium.impl.gl.device.CommandList; import org.embeddedt.embeddium.impl.gl.device.RenderDevice; +import org.embeddedt.embeddium.impl.mixin.features.render.entity.cull.EntityRendererAccessor; import org.embeddedt.embeddium.impl.model.quad.blender.BlendedColorProvider; import org.embeddedt.embeddium.impl.render.chunk.ChunkRenderMatrices; import org.embeddedt.embeddium.impl.render.chunk.RenderSectionManager; @@ -175,7 +178,7 @@ public void setupTerrain(Camera camera, this.reload(); } - ProfilerFiller profiler = this.client.getProfiler(); + ProfilerFiller profiler = Profiler.get(); profiler.push("camera_setup"); LocalPlayer player = this.client.player; @@ -187,7 +190,7 @@ public void setupTerrain(Camera camera, Vec3 pos = camera.getPosition(); float pitch = camera.getXRot(); float yaw = camera.getYRot(); - float fogDistance = RenderSystem.getShaderFogEnd(); + float fogDistance = RenderSystem.getShaderFog().end(); boolean dirty = pos.x != this.lastCameraX || pos.y != this.lastCameraY || pos.z != this.lastCameraZ || pitch != this.lastCameraPitch || yaw != this.lastCameraYaw || fogDistance != this.lastFogDistance; @@ -393,7 +396,7 @@ public void forEachVisibleBlockEntity(Consumer consumer) { } } - public void renderBlockEntities(Matrix4f pose, + public void renderBlockEntities(PoseStack poseStack, RenderBuffers bufferBuilders, Long2ObjectMap> blockBreakingProgressions, Camera camera, @@ -408,8 +411,6 @@ public void renderBlockEntities(Matrix4f pose, BlockEntityRenderDispatcher blockEntityRenderer = Minecraft.getInstance().getBlockEntityRenderDispatcher(); this.blockEntityRequestedOutline = false; - - final PoseStack poseStack = new PoseStack(); this.renderBlockEntities(poseStack, bufferBuilders, blockBreakingProgressions, tickDelta, immediate, x, y, z, blockEntityRenderer); this.renderGlobalBlockEntities(poseStack, bufferBuilders, blockBreakingProgressions, tickDelta, immediate, x, y, z, blockEntityRenderer); @@ -460,10 +461,6 @@ private void renderBlockEntities(PoseStack matrices, if(ENABLE_BLOCKENTITY_CULLING && !isBlockEntityRendererVisible(blockEntityRenderer, blockEntity)) continue; - if (blockEntity.hasCustomOutlineRendering(this.client.player)) { - this.blockEntityRequestedOutline = true; - } - renderBlockEntity(matrices, bufferBuilders, blockBreakingProgressions, tickDelta, immediate, x, y, z, blockEntityRenderer, blockEntity); } } @@ -490,10 +487,6 @@ private void renderGlobalBlockEntities(PoseStack matrices, if(ENABLE_BLOCKENTITY_CULLING && !isBlockEntityRendererVisible(blockEntityRenderer, blockEntity)) continue; - if (blockEntity.hasCustomOutlineRendering(this.client.player)) { - this.blockEntityRequestedOutline = true; - } - renderBlockEntity(matrices, bufferBuilders, blockBreakingProgressions, tickDelta, immediate, x, y, z, blockEntityRenderer, blockEntity); } } @@ -559,7 +552,7 @@ private static boolean isInfiniteExtentsBox(AABB box) { * Returns whether or not the entity intersects with any visible chunks in the graph. * @return True if the entity is visible, otherwise false */ - public boolean isEntityVisible(Entity entity) { + public boolean isEntityVisible(Entity entity, EntityRenderer renderer) { if (!this.useEntityCulling) { return true; } @@ -569,7 +562,8 @@ public boolean isEntityVisible(Entity entity) { return true; } - AABB box = entity.getBoundingBoxForCulling(); + var accessor = (EntityRendererAccessor)renderer; + AABB box = accessor.callGetBoundingBoxForCulling(entity); if (isInfiniteExtentsBox(box)) { return true; @@ -588,7 +582,7 @@ public boolean isEntityVisible(Entity entity) { public boolean isBoxVisible(double x1, double y1, double z1, double x2, double y2, double z2) { // Boxes outside the valid world height will never map to a rendered chunk // Always render these boxes or they'll be culled incorrectly! - if (y2 < this.world.getMinBuildHeight() + 0.5D || y1 > this.world.getMaxBuildHeight() - 0.5D) { + if (y2 < this.world.getMinY() + 0.5D || y1 > this.world.getMaxY() - 0.5D) { return true; } diff --git a/src/main/java/org/embeddedt/embeddium/impl/render/chunk/RenderSectionManager.java b/src/main/java/org/embeddedt/embeddium/impl/render/chunk/RenderSectionManager.java index e660e3382..89bccb66e 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/render/chunk/RenderSectionManager.java +++ b/src/main/java/org/embeddedt/embeddium/impl/render/chunk/RenderSectionManager.java @@ -248,8 +248,7 @@ private boolean shouldUseOcclusionCulling(Camera camera, boolean spectator) { final boolean useOcclusionCulling; BlockPos origin = camera.getBlockPosition(); - if (spectator && this.world.getBlockState(origin) - .isSolidRender(this.world, origin)) + if (spectator && this.world.getBlockState(origin).isSolidRender()) { useOcclusionCulling = false; } else { @@ -628,17 +627,16 @@ private static boolean allowImportantRebuilds() { } private float getEffectiveRenderDistance() { - var color = RenderSystem.getShaderFogColor(); - var distance = RenderSystem.getShaderFogEnd(); + var fogParams = RenderSystem.getShaderFog(); var renderDistance = this.getRenderDistance(); // The fog must be fully opaque in order to skip rendering of chunks behind it - if (!Mth.equal(color[3], 1.0f)) { + if (!Mth.equal(fogParams.alpha(), 1.0f)) { return renderDistance; } - return Math.min(renderDistance, distance + 0.5f); + return Math.min(renderDistance, fogParams.end() + 0.5f); } private float getRenderDistance() { @@ -792,13 +790,13 @@ public boolean isSectionBuilt(int x, int y, int z) { } public void onChunkAdded(int x, int z) { - for (int y = this.world.getMinSection(); y < this.world.getMaxSection(); y++) { + for (int y = this.world.getMinSectionY(); y < this.world.getMaxSectionY(); y++) { this.onSectionAdded(x, y, z); } } public void onChunkRemoved(int x, int z) { - for (int y = this.world.getMinSection(); y < this.world.getMaxSection(); y++) { + for (int y = this.world.getMinSectionY(); y < this.world.getMaxSectionY(); y++) { this.onSectionRemoved(x, y, z); } } diff --git a/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/pipeline/BlockOcclusionCache.java b/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/pipeline/BlockOcclusionCache.java index 154787239..f1158ea9d 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/pipeline/BlockOcclusionCache.java +++ b/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/pipeline/BlockOcclusionCache.java @@ -41,8 +41,8 @@ public boolean shouldDrawSide(BlockState selfState, BlockGetter view, BlockPos p // Explicitly asked to skip rendering this face return false; } else if (adjState.canOcclude()) { - VoxelShape selfShape = selfState.getFaceOcclusionShape(view, pos, facing); - VoxelShape adjShape = adjState.getFaceOcclusionShape(view, adjPos, facing.getOpposite()); + VoxelShape selfShape = selfState.getFaceOcclusionShape(facing); + VoxelShape adjShape = adjState.getFaceOcclusionShape(facing.getOpposite()); if (selfShape == Shapes.block() && adjShape == Shapes.block()) { // If both blocks use full-cube occlusion shapes, then the neighbor certainly occludes us, and we diff --git a/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/pipeline/BlockRenderer.java b/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/pipeline/BlockRenderer.java index 2438223f1..adf0fecc7 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/pipeline/BlockRenderer.java +++ b/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/pipeline/BlockRenderer.java @@ -109,7 +109,7 @@ public void renderModel(BlockRenderContext ctx, ChunkBuildBuffers buffers) { Vec3 renderOffset; if (ctx.state().hasOffsetFunction()) { - renderOffset = ctx.state().getOffset(ctx.localSlice(), ctx.pos()); + renderOffset = ctx.state().getOffset(ctx.pos()); } else { renderOffset = Vec3.ZERO; } diff --git a/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/pipeline/FluidRenderer.java b/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/pipeline/FluidRenderer.java index b094cf52f..85be7c978 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/pipeline/FluidRenderer.java +++ b/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/pipeline/FluidRenderer.java @@ -109,7 +109,7 @@ private boolean isFluidOccluded(BlockAndTintGetter world, int x, int y, int z, D return false; } - VoxelShape sideShape = blockState.getFaceOcclusionShape(world, pos, dir); + VoxelShape sideShape = blockState.getFaceOcclusionShape(dir); if (sideShape == Shapes.block()) { // The face fills the 1x1 area, so the fluid is occluded return true; @@ -127,7 +127,7 @@ private boolean isSideExposed(BlockAndTintGetter world, int x, int y, int z, Dir BlockState blockState = world.getBlockState(pos); if (blockState.canOcclude()) { - VoxelShape shape = blockState.getOcclusionShape(world, pos); + VoxelShape shape = blockState.getOcclusionShape(); // Hoist these checks to avoid allocating the shape below if (shape == Shapes.block()) { diff --git a/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/tasks/ChunkBuilderMeshingTask.java b/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/tasks/ChunkBuilderMeshingTask.java index 530699d4a..5562d2196 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/tasks/ChunkBuilderMeshingTask.java +++ b/src/main/java/org/embeddedt/embeddium/impl/render/chunk/compile/tasks/ChunkBuilderMeshingTask.java @@ -152,7 +152,7 @@ public ChunkBuildOutput execute(ChunkBuildContext buildContext, CancellationToke } } - if (blockState.isSolidRender(slice, blockPos)) { + if (blockState.isSolidRender()) { occluder.setOpaque(blockPos); } } diff --git a/src/main/java/org/embeddedt/embeddium/impl/render/chunk/occlusion/OcclusionCuller.java b/src/main/java/org/embeddedt/embeddium/impl/render/chunk/occlusion/OcclusionCuller.java index c16fe853e..d220fecb6 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/render/chunk/occlusion/OcclusionCuller.java +++ b/src/main/java/org/embeddedt/embeddium/impl/render/chunk/occlusion/OcclusionCuller.java @@ -202,14 +202,14 @@ private void init(Visitor visitor, { var origin = viewport.getChunkCoord(); - if (origin.getY() < this.world.getMinSection()) { + if (origin.getY() < this.world.getMinSectionY()) { // below the world this.initOutsideWorldHeight(queue, viewport, searchDistance, frame, - this.world.getMinSection(), GraphDirectionSet.of(GraphDirection.DOWN)); - } else if (origin.getY() >= this.world.getMaxSection()) { + this.world.getMinSectionY(), GraphDirectionSet.of(GraphDirection.DOWN)); + } else if (origin.getY() >= this.world.getMaxSectionY()) { // above the world this.initOutsideWorldHeight(queue, viewport, searchDistance, frame, - this.world.getMaxSection() - 1, GraphDirectionSet.of(GraphDirection.UP)); + this.world.getMaxSectionY() - 1, GraphDirectionSet.of(GraphDirection.UP)); } else if(this.getRenderSection(origin.getX(), origin.getY(), origin.getZ()) == null) { // inside the world height-wise, but in an unloaded section this.initOutsideWorldHeight(queue, viewport, searchDistance, frame, diff --git a/src/main/java/org/embeddedt/embeddium/impl/render/chunk/shader/ChunkShaderFogComponent.java b/src/main/java/org/embeddedt/embeddium/impl/render/chunk/shader/ChunkShaderFogComponent.java index 7447cdfc1..9a5bd601a 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/render/chunk/shader/ChunkShaderFogComponent.java +++ b/src/main/java/org/embeddedt/embeddium/impl/render/chunk/shader/ChunkShaderFogComponent.java @@ -30,6 +30,7 @@ public void setup() { } public static class Smooth extends ChunkShaderFogComponent { + private final float[] fogColorBuffer; private final GlUniformFloat4v uFogColor; private final GlUniformInt uFogShape; @@ -37,6 +38,7 @@ public static class Smooth extends ChunkShaderFogComponent { private final GlUniformFloat uFogEnd; public Smooth(ShaderBindingContext context) { + this.fogColorBuffer = new float[4]; this.uFogColor = context.bindUniform("u_FogColor", GlUniformFloat4v::new); this.uFogShape = context.bindUniform("u_FogShape", GlUniformInt::new); this.uFogStart = context.bindUniform("u_FogStart", GlUniformFloat::new); @@ -45,11 +47,16 @@ public Smooth(ShaderBindingContext context) { @Override public void setup() { - this.uFogColor.set(RenderSystem.getShaderFogColor()); - this.uFogShape.set(RenderSystem.getShaderFogShape().getIndex()); - - this.uFogStart.setFloat(RenderSystem.getShaderFogStart()); - this.uFogEnd.setFloat(RenderSystem.getShaderFogEnd()); + var fogProperties = RenderSystem.getShaderFog(); + fogColorBuffer[0] = fogProperties.red(); + fogColorBuffer[1] = fogProperties.green(); + fogColorBuffer[2] = fogProperties.blue(); + fogColorBuffer[3] = fogProperties.alpha(); + + this.uFogColor.set(fogColorBuffer); + this.uFogShape.set(fogProperties.shape().getIndex()); + this.uFogStart.setFloat(fogProperties.start()); + this.uFogEnd.setFloat(fogProperties.end()); } } diff --git a/src/main/java/org/embeddedt/embeddium/impl/render/frapi/IndigoBlockRenderContext.java b/src/main/java/org/embeddedt/embeddium/impl/render/frapi/IndigoBlockRenderContext.java index 88f086628..18ed5bb6e 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/render/frapi/IndigoBlockRenderContext.java +++ b/src/main/java/org/embeddedt/embeddium/impl/render/frapi/IndigoBlockRenderContext.java @@ -87,28 +87,6 @@ public float ao(BlockPos pos, BlockState state) { }; } - @Override - public boolean isFaceCulled(@Nullable Direction face) { - if (face == null) { - return false; - } - - int fM = (1 << face.ordinal()); - - // Use a bitmask to cache the cull checks so we don't run them more than once per face - if((cullChecked & fM) != 0) { - return (cullValue & fM) != 0; - } else { - var ctx = this.currentContext; - boolean flag = !this.occlusionCache.shouldDrawSide(ctx.state(), ctx.localSlice(), ctx.pos(), face); - if(flag) { - cullValue |= fM; - } - cullChecked |= fM; - return flag; - } - } - @Override protected VertexConsumer getVertexConsumer(RenderType layer) { var material = DefaultMaterials.forRenderLayer(layer); diff --git a/src/main/java/org/embeddedt/embeddium/impl/render/frapi/SpriteFinderCache.java b/src/main/java/org/embeddedt/embeddium/impl/render/frapi/SpriteFinderCache.java index 293882550..7f4edaa8e 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/render/frapi/SpriteFinderCache.java +++ b/src/main/java/org/embeddedt/embeddium/impl/render/frapi/SpriteFinderCache.java @@ -2,7 +2,9 @@ import net.fabricmc.fabric.api.renderer.v1.model.SpriteFinder; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureContents; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.packs.resources.SimplePreparableReloadListener; import net.minecraft.util.profiling.ProfilerFiller; @@ -54,7 +56,7 @@ protected Object prepare(ResourceManager pResourceManager, ProfilerFiller pProfi protected void apply(Object pObject, ResourceManager pResourceManager, ProfilerFiller pProfiler) { var modelManager = Minecraft.getInstance().getModelManager(); Finder finder = NULL_FINDER; - var fabricFinder = SpriteFinder.get(modelManager.getAtlas(InventoryMenu.BLOCK_ATLAS)); + var fabricFinder = SpriteFinder.get(modelManager.getAtlas(TextureAtlas.LOCATION_BLOCKS)); try { MethodType bootstrapType = MethodType.methodType(Finder.class, SpriteFinder.class); MethodType invocationType = MethodType.methodType(TextureAtlasSprite.class, float.class, float.class); diff --git a/src/main/java/org/embeddedt/embeddium/impl/render/immediate/CloudRenderer.java b/src/main/java/org/embeddedt/embeddium/impl/render/immediate/CloudRenderer.java index 316f69f2d..7c00e0b3c 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/render/immediate/CloudRenderer.java +++ b/src/main/java/org/embeddedt/embeddium/impl/render/immediate/CloudRenderer.java @@ -1,9 +1,14 @@ package org.embeddedt.embeddium.impl.render.immediate; +import com.mojang.blaze3d.buffers.BufferUsage; import com.mojang.blaze3d.platform.NativeImage; +import com.mojang.blaze3d.shaders.CompiledShader; import com.mojang.blaze3d.shaders.FogShape; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; +import net.minecraft.client.renderer.CoreShaders; +import net.minecraft.client.renderer.FogParameters; +import net.minecraft.client.renderer.ShaderManager; import org.embeddedt.embeddium.api.util.ColorABGR; import org.embeddedt.embeddium.api.util.ColorARGB; import org.embeddedt.embeddium.api.util.ColorMixer; @@ -16,7 +21,7 @@ import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.renderer.FogRenderer; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.ShaderInstance; +import net.minecraft.client.renderer.CompiledShaderProgram; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.Resource; import net.minecraft.server.packs.resources.ResourceManager; @@ -74,7 +79,7 @@ public class CloudRenderer { private VertexBuffer vertexBuffer; private CloudEdges edges; - private ShaderInstance shader; + private CompiledShaderProgram shader; private final FogRenderer.FogData fogData = new FogRenderer.FogData(FogRenderer.FogMode.FOG_TERRAIN); private int prevCenterCellX, prevCenterCellY, cachedRenderDistance; @@ -83,8 +88,8 @@ public class CloudRenderer { private CloudStatus cloudRenderMode; private boolean hasCloudGeometry; - public CloudRenderer(ResourceProvider factory) { - this.reloadTextures(factory); + public CloudRenderer(ShaderManager shaderManager) { + this.reloadTextures(shaderManager); } private static int fireModifyCloudRenderDistanceEvent(int distance) { @@ -105,7 +110,7 @@ public void render(@Nullable ClientLevel world, LocalPlayer player, PoseStack st return; } - Vec3 color = world.getCloudColor(tickDelta); + Vec3 color = Vec3.fromRGB24(world.getCloudColor(tickDelta)); double cloudTime = (ticks + tickDelta) * 0.03F; double cloudCenterX = (cameraX + cloudTime); @@ -125,7 +130,7 @@ public void render(@Nullable ClientLevel world, LocalPlayer player, PoseStack st this.rebuildGeometry(bufferBuilder, cloudDistance, centerCellX, centerCellZ); if (this.vertexBuffer == null) { - this.vertexBuffer = new VertexBuffer(VertexBuffer.Usage.DYNAMIC); + this.vertexBuffer = new VertexBuffer(BufferUsage.DYNAMIC_WRITE); } this.vertexBuffer.bind(); @@ -151,16 +156,24 @@ public void render(@Nullable ClientLevel world, LocalPlayer player, PoseStack st return; } - float previousEnd = RenderSystem.getShaderFogEnd(); - float previousStart = RenderSystem.getShaderFogStart(); + var previousData = RenderSystem.getShaderFog(); + float previousEnd = previousData.end(); + float previousStart = previousData.start(); this.fogData.end = cloudDistance * this.fogDistanceMultiplier; this.fogData.start = (cloudDistance * this.fogDistanceMultiplier) - 16; applyFogModifiers(world, this.fogData, player, (int)(cloudDistance * this.fogDistanceMultiplier), tickDelta); - RenderSystem.setShaderFogEnd(this.fogData.end); - RenderSystem.setShaderFogStart(this.fogData.start); + RenderSystem.setShaderFog( + new FogParameters( + this.fogData.start, + this.fogData.end, + this.fogData.shape, + previousData.red(), + previousData.green(), + previousData.blue(), + previousData.alpha())); float translateX = (float) (cloudCenterX - (centerCellX * this.cloudSizeX)); float translateZ = (float) (cloudCenterZ - (centerCellZ * this.cloudSizeZ)); @@ -197,8 +210,7 @@ public void render(@Nullable ClientLevel world, LocalPlayer player, PoseStack st RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); - RenderSystem.setShaderFogEnd(previousEnd); - RenderSystem.setShaderFogStart(previousStart); + RenderSystem.setShaderFog(previousData); } private void applyFogModifiers(ClientLevel world, FogRenderer.FogData fogData, LocalPlayer player, int cloudDistance, float tickDelta) { @@ -364,7 +376,7 @@ private static long writeVertex(long buffer, float x, float y, float z, int colo return buffer + ColorVertex.STRIDE; } - public void reloadTextures(ResourceProvider factory) { + public void reloadTextures(ShaderManager manager) { this.destroy(); this.edges = createCloudEdges(); @@ -382,11 +394,7 @@ public void reloadTextures(ResourceProvider factory) { this.cloudDistanceMinimum = (int) (width * CLOUD_PIXELS_TO_MINIMUM_RENDER_DISTANCE); this.cloudDistanceMaximum = (int) (width * CLOUD_PIXELS_TO_MAXIMUM_RENDER_DISTANCE); - try { - this.shader = new ShaderInstance(factory, "clouds", DefaultVertexFormat.POSITION_COLOR); - } catch (IOException e) { - throw new RuntimeException(e); - } + this.shader = manager.getProgram(CoreShaders.RENDERTYPE_CLOUDS); } public void destroy() { @@ -433,7 +441,7 @@ public CloudEdges(NativeImage texture) { for (int x = 0; x < width; x++) { for (int z = 0; z < height; z++) { int index = index(x, z, width, height); - int cell = texture.getPixelRGBA(x, z); + int cell = texture.getPixel(x, z); this.colors[index] = cell; @@ -442,25 +450,25 @@ public CloudEdges(NativeImage texture) { if (isOpaqueCell(cell)) { edges |= DIR_NEG_Y | DIR_POS_Y; - int negX = texture.getPixelRGBA(wrap(x - 1, width), wrap(z, height)); + int negX = texture.getPixel(wrap(x - 1, width), wrap(z, height)); if (cell != negX) { edges |= DIR_NEG_X; } - int posX = texture.getPixelRGBA(wrap(x + 1, width), wrap(z, height)); + int posX = texture.getPixel(wrap(x + 1, width), wrap(z, height)); if (!isOpaqueCell(posX) && cell != posX) { edges |= DIR_POS_X; } - int negZ = texture.getPixelRGBA(wrap(x, width), wrap(z - 1, height)); + int negZ = texture.getPixel(wrap(x, width), wrap(z - 1, height)); if (cell != negZ) { edges |= DIR_NEG_Z; } - int posZ = texture.getPixelRGBA(wrap(x, width), wrap(z + 1, height)); + int posZ = texture.getPixel(wrap(x, width), wrap(z + 1, height)); if (!isOpaqueCell(posZ) && cell != posZ) { edges |= DIR_POS_Z; diff --git a/src/main/java/org/embeddedt/embeddium/impl/util/collections/WeightedRandomListExtended.java b/src/main/java/org/embeddedt/embeddium/impl/util/collections/WeightedRandomListExtended.java new file mode 100644 index 000000000..aab5ba7e8 --- /dev/null +++ b/src/main/java/org/embeddedt/embeddium/impl/util/collections/WeightedRandomListExtended.java @@ -0,0 +1,9 @@ +package org.embeddedt.embeddium.impl.util.collections; + +import net.minecraft.util.RandomSource; +import org.jetbrains.annotations.Nullable; + +public interface WeightedRandomListExtended { + @Nullable + E embeddium$getRandomItem(RandomSource random); +} diff --git a/src/main/java/org/embeddedt/embeddium/impl/util/color/ColorSRGB.java b/src/main/java/org/embeddedt/embeddium/impl/util/color/ColorSRGB.java index f3ce1768f..74bb6beaf 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/util/color/ColorSRGB.java +++ b/src/main/java/org/embeddedt/embeddium/impl/util/color/ColorSRGB.java @@ -1,7 +1,7 @@ package org.embeddedt.embeddium.impl.util.color; -import net.minecraft.util.FastColor; +import net.minecraft.util.ARGB; /** * This is a port of the fast-srgb8 library from thomcc on GitHub. @@ -82,7 +82,7 @@ public static float srgbToLinear(int c) { * @param a The alpha-component in linear RGB space (0 to 255) */ public static int linearToSrgb(float r, float g, float b, int a) { - return FastColor.ABGR32.color(a, linearToSrgb(b), linearToSrgb(g), linearToSrgb(r)); + return ARGB.color(a, linearToSrgb(b), linearToSrgb(g), linearToSrgb(r)); } /** diff --git a/src/main/java/org/embeddedt/embeddium/impl/world/WorldSlice.java b/src/main/java/org/embeddedt/embeddium/impl/world/WorldSlice.java index 259d295fa..8387200a2 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/world/WorldSlice.java +++ b/src/main/java/org/embeddedt/embeddium/impl/world/WorldSlice.java @@ -384,8 +384,8 @@ public int getHeight() { } @Override - public int getMinBuildHeight() { - return this.world.getMinBuildHeight(); + public int getMinY() { + return this.world.getMinY(); } @Override diff --git a/src/main/java/org/embeddedt/embeddium/impl/world/biome/BiomeSlice.java b/src/main/java/org/embeddedt/embeddium/impl/world/biome/BiomeSlice.java index 2e6a9bae9..852bbe90c 100644 --- a/src/main/java/org/embeddedt/embeddium/impl/world/biome/BiomeSlice.java +++ b/src/main/java/org/embeddedt/embeddium/impl/world/biome/BiomeSlice.java @@ -44,8 +44,7 @@ public void update(ClientLevel world, ChunkRenderContext context) { private void copyBiomeData(Level world, ChunkRenderContext context) { var defaultValue = world.registryAccess() - .registryOrThrow(Registries.BIOME) - .getHolderOrThrow(Biomes.PLAINS); + .holderOrThrow(Biomes.PLAINS); for (int sectionX = 0; sectionX < 3; sectionX++) { for (int sectionY = 0; sectionY < 3; sectionY++) { diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index b63bc1c72..3ceaa2a06 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -1,22 +1,32 @@ -public net.minecraft.client.model.geom.ModelPart$Vertex +public com.mojang.blaze3d.vertex.PoseStack$Pose (Lorg/joml/Matrix4f;Lorg/joml/Matrix3f;)V +public com.mojang.blaze3d.vertex.PoseStack$Pose trustedNormals Z + +public net.minecraft.client.gui.font.FontSet$GlyphInfoFilter + public net.minecraft.client.model.geom.ModelPart$Polygon -public net.minecraft.client.renderer.texture.SpriteContents$InterpolationData +public net.minecraft.client.model.geom.ModelPart$Vertex + +public net.minecraft.client.renderer.block.model.BlockModel getElements()Ljava/util/List; + +public net.minecraft.client.renderer.FogRenderer$FogData +public net.minecraft.client.renderer.FogRenderer$MobEffectFogFunction + +public net.minecraft.client.renderer.FogRenderer getPriorityFogFunction(Lnet/minecraft/world/entity/Entity;F)Lnet/minecraft/client/renderer/FogRenderer$MobEffectFogFunction; + +public net.minecraft.client.renderer.SectionBufferBuilderPool (Ljava/util/List;)V + public net.minecraft.client.renderer.texture.SpriteContents$AnimatedTexture public net.minecraft.client.renderer.texture.SpriteContents$FrameInfo +public net.minecraft.client.renderer.texture.SpriteContents$InterpolationData public net.minecraft.client.renderer.texture.SpriteContents$Ticker -public net.minecraft.world.level.chunk.PalettedContainer$Data -public net.minecraft.world.level.chunk.PalettedContainer$Configuration -public net.minecraft.client.renderer.FogRenderer$FogData -public net.minecraft.client.renderer.FogRenderer$MobEffectFogFunction + public net.minecraft.client.renderer.texture.Stitcher$Holder + public net.minecraft.world.level.biome.Biome$ClimateSettings -public com.mojang.blaze3d.vertex.PoseStack$Pose (Lorg/joml/Matrix4f;Lorg/joml/Matrix3f;)V -public net.minecraft.client.gui.font.FontSet$GlyphInfoFilter -public com.mojang.blaze3d.vertex.PoseStack$Pose trustedNormals # trustedNormals +public net.minecraft.world.level.chunk.PalettedContainer$Configuration +public net.minecraft.world.level.chunk.PalettedContainer$Data -public net.minecraft.client.renderer.SectionBufferBuilderPool (Ljava/util/List;)V +public net.minecraft.world.level.FoliageColor pixels public net.minecraft.world.level.GrassColor pixels -public net.minecraft.world.level.FoliageColor pixels -public net.minecraft.client.renderer.FogRenderer getPriorityFogFunction(Lnet/minecraft/world/entity/Entity;F)Lnet/minecraft/client/renderer/FogRenderer$MobEffectFogFunction; diff --git a/src/main/resources/assets/embeddium/shaders/include/fog.glsl b/src/main/resources/assets/embeddium/shaders/include/fog.glsl index 198d566d3..3d6291b53 100644 --- a/src/main/resources/assets/embeddium/shaders/include/fog.glsl +++ b/src/main/resources/assets/embeddium/shaders/include/fog.glsl @@ -22,4 +22,13 @@ float getFragDistance(int fogShape, vec3 position) { case FOG_SHAPE_CYLINDRICAL: return max(length(position.xz), abs(position.y)); default: return length(position); // This shouldn't be possible to get, but return a sane value just in case } +} + +float fog_distance(int fogShape, vec3 position) { + // Use the maximum of the horizontal and vertical distance to get cylindrical fog if fog shape is cylindrical + switch (fogShape) { + case FOG_SHAPE_SPHERICAL: return length(position); + case FOG_SHAPE_CYLINDRICAL: return max(length(position.xz), abs(position.y)); + default: return length(position); // This shouldn't be possible to get, but return a sane value just in case + } } \ No newline at end of file diff --git a/src/main/resources/assets/minecraft/shaders/core/clouds.json b/src/main/resources/assets/minecraft/shaders/core/clouds.json index 05627fdf4..5d19ad16b 100644 --- a/src/main/resources/assets/minecraft/shaders/core/clouds.json +++ b/src/main/resources/assets/minecraft/shaders/core/clouds.json @@ -1,14 +1,6 @@ { - "blend": { - "func": "add", - "srcrgb": "srcalpha", - "dstrgb": "1-srcalpha" - }, "vertex": "clouds", "fragment": "clouds", - "attributes": [ - "Color" - ], "samplers": [ ], "uniforms": [ @@ -17,7 +9,8 @@ { "name": "ColorModulator", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] }, { "name": "FogStart", "type": "float", "count": 1, "values": [ 0.0 ] }, { "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] }, - { "name": "FogColor", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] } + { "name": "FogColor", "type": "float", "count": 4, "values": [ 1.0, 1.0, 1.0, 1.0 ] }, + { "name": "FogShape", "type": "int", "count": 1, "values": [ 0 ] } ] } diff --git a/src/main/resources/assets/minecraft/shaders/core/clouds.vsh b/src/main/resources/assets/minecraft/shaders/core/clouds.vsh index 230d293b2..7bb6e5548 100644 --- a/src/main/resources/assets/minecraft/shaders/core/clouds.vsh +++ b/src/main/resources/assets/minecraft/shaders/core/clouds.vsh @@ -1,5 +1,5 @@ #version 150 -#moj_import +#moj_import in vec3 Position; in vec4 Color; @@ -7,6 +7,7 @@ in vec4 Color; uniform mat4 ModelViewMat; uniform mat4 ProjMat; uniform int FogShape; +uniform vec4 ColorModulator; out float vertexDistance; out vec4 vertexColor; @@ -14,7 +15,9 @@ out vec4 vertexColor; // Custom cloud fog algorithm by Balint, for use in Sodium void main() { gl_Position = ProjMat * ModelViewMat * vec4(Position, 1.0); + vec4 pos = ModelViewMat * vec4(Position.x, 0.0, Position.z, 1.0); - vertexDistance = length(pos.xyz); - vertexColor = Color; + + vertexDistance = fog_distance(pos.xyz); + vertexColor = Color * ColorModulator; } diff --git a/src/main/resources/embeddium.accesswidener b/src/main/resources/embeddium.accesswidener index 32f4740ca..c85dfdd62 100644 --- a/src/main/resources/embeddium.accesswidener +++ b/src/main/resources/embeddium.accesswidener @@ -1,42 +1,34 @@ accessWidener v2 named -# embeddium { -# public net.minecraft.client.model.geom.ModelPart$Vertex -transitive-accessible class net/minecraft/client/model/geom/ModelPart$Vertex -# public net.minecraft.client.model.geom.ModelPart$Polygon +transitive-accessible method com/mojang/blaze3d/vertex/PoseStack$Pose (Lorg/joml/Matrix4f;Lorg/joml/Matrix3f;)V +transitive-accessible field com/mojang/blaze3d/vertex/PoseStack$Pose trustedNormals Z + +transitive-accessible class net/minecraft/client/gui/font/FontSet$GlyphInfoFilter + transitive-accessible class net/minecraft/client/model/geom/ModelPart$Polygon -# public net.minecraft.client.renderer.texture.SpriteContents$InterpolationData -transitive-accessible class net/minecraft/client/renderer/texture/SpriteContents$InterpolationData -# public net.minecraft.client.renderer.texture.SpriteContents$AnimatedTexture +transitive-accessible class net/minecraft/client/model/geom/ModelPart$Vertex + +accessible method net/minecraft/client/renderer/block/model/BlockModel getElements ()Ljava/util/List; + +transitive-accessible class net/minecraft/client/renderer/FogRenderer$FogData +transitive-accessible class net/minecraft/client/renderer/FogRenderer$MobEffectFogFunction + +transitive-accessible method net/minecraft/client/renderer/FogRenderer getPriorityFogFunction (Lnet/minecraft/world/entity/Entity;F)Lnet/minecraft/client/renderer/FogRenderer$MobEffectFogFunction; + +transitive-accessible method net/minecraft/client/renderer/SectionBufferBuilderPool (Ljava/util/List;)V + transitive-accessible class net/minecraft/client/renderer/texture/SpriteContents$AnimatedTexture -# public net.minecraft.client.renderer.texture.SpriteContents$FrameInfo transitive-accessible class net/minecraft/client/renderer/texture/SpriteContents$FrameInfo -# public net.minecraft.client.renderer.texture.SpriteContents$Ticker +transitive-accessible class net/minecraft/client/renderer/texture/SpriteContents$InterpolationData transitive-accessible class net/minecraft/client/renderer/texture/SpriteContents$Ticker -# public net.minecraft.world.level.chunk.PalettedContainer$Data -transitive-accessible class net/minecraft/world/level/chunk/PalettedContainer$Data -# public net.minecraft.world.level.chunk.PalettedContainer$Configuration -transitive-accessible class net/minecraft/world/level/chunk/PalettedContainer$Configuration -# public net.minecraft.client.renderer.FogRenderer$FogData -transitive-accessible class net/minecraft/client/renderer/FogRenderer$FogData -# public net.minecraft.client.renderer.FogRenderer$MobEffectFogFunction -transitive-accessible class net/minecraft/client/renderer/FogRenderer$MobEffectFogFunction -# public net.minecraft.client.renderer.texture.Stitcher$Holder + transitive-accessible class net/minecraft/client/renderer/texture/Stitcher$Holder -# public net.minecraft.world.level.biome.Biome$ClimateSettings + transitive-accessible class net/minecraft/world/level/biome/Biome$ClimateSettings -# public com.mojang.blaze3d.vertex.PoseStack$Pose (Lorg/joml/Matrix4f;Lorg/joml/Matrix3f;)V -transitive-accessible method com/mojang/blaze3d/vertex/PoseStack$Pose (Lorg/joml/Matrix4f;Lorg/joml/Matrix3f;)V -# public net.minecraft.client.gui.font.FontSet$GlyphInfoFilter -transitive-accessible class net/minecraft/client/gui/font/FontSet$GlyphInfoFilter -# public com.mojang.blaze3d.vertex.PoseStack$Pose trustedNormals # trustedNormals -transitive-accessible field com/mojang/blaze3d/vertex/PoseStack$Pose trustedNormals Z -# public net.minecraft.client.renderer.SectionBufferBuilderPool (Ljava/util/List;)V -transitive-accessible method net/minecraft/client/renderer/SectionBufferBuilderPool (Ljava/util/List;)V -# public net.minecraft.world.level.GrassColor pixels -transitive-accessible field net/minecraft/world/level/GrassColor pixels [I -# public net.minecraft.world.level.FoliageColor pixels + +transitive-accessible class net/minecraft/world/level/chunk/PalettedContainer$Configuration +transitive-accessible class net/minecraft/world/level/chunk/PalettedContainer$Data + transitive-accessible field net/minecraft/world/level/FoliageColor pixels [I -# public net.minecraft.client.renderer.FogRenderer getPriorityFogFunction(Lnet/minecraft/world/entity/Entity;F)Lnet/minecraft/client/renderer/FogRenderer$MobEffectFogFunction; -transitive-accessible method net/minecraft/client/renderer/FogRenderer getPriorityFogFunction (Lnet/minecraft/world/entity/Entity;F)Lnet/minecraft/client/renderer/FogRenderer$MobEffectFogFunction; -# } + +transitive-accessible field net/minecraft/world/level/GrassColor pixels [I \ No newline at end of file