From 7a169c9a150493346a9435879c70d5eb5d3c3252 Mon Sep 17 00:00:00 2001 From: Dragon-Seeker Date: Fri, 18 Oct 2024 15:37:18 -0500 Subject: [PATCH 1/8] Port to 1.21.2 --- build.gradle | 2 +- gradle.properties | 12 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../io/wispforest/owo/client/OwoClient.java | 7 + .../texture/AnimatedTextureDrawable.java | 9 +- .../owo/command/debug/OwoDebugCommands.java | 2 +- .../owo/compat/rei/OwoReiPlugin.java | 2 - .../owo/compat/rei/ReiUIAdapter.java | 2 +- .../owo/ext/DerivedComponentMap.java | 6 +- .../io/wispforest/owo/itemgroup/Icon.java | 3 +- .../itemgroup/gui/ItemGroupButtonWidget.java | 7 +- .../CachedRegistryInfoGetterAccessor.java | 2 +- .../ServerPlayerInteractionManagerMixin.java | 8 +- .../owo/mixin/ext/ItemStackMixin.java | 17 +- ...r.java => MergedComponentMapAccessor.java} | 6 +- ...ixin.java => MergedComponentMapMixin.java} | 8 +- .../CreativeInventoryScreenMixin.java | 22 +- ...in.java => StatusEffectsDisplayMixin.java} | 10 +- .../CraftingResultSlotMixin.java | 50 ++++ .../JsonDataLoaderMixin.java | 67 +++++ .../recipe_remainders/RecipeManagerMixin.java | 72 ----- .../mixin/registry/SimpleRegistryMixin.java | 2 +- .../owo/mixin/shader/GameRendererMixin.java | 26 -- .../mixin/shader/ShaderProgramAccessor.java | 2 +- .../owo/mixin/shader/ShaderProgramMixin.java | 29 --- .../owo/mixin/ui/DrawContextInvoker.java | 8 +- .../owo/mixin/ui/DrawContextMixin.java | 54 ---- .../mixin/ui/EntityRenderDispatcherMixin.java | 3 +- .../owo/mixin/ui/EntityRendererMixin.java | 7 +- .../owo/mixin/ui/HandledScreenMixin.java | 25 +- .../owo/mixin/ui/MinecraftClientMixin.java | 2 +- .../owo/mixin/ui/TessellatorMixin.java | 61 ----- .../owo/mixin/ui/layers/KeyboardMixin.java | 23 +- .../owo/mixin/ui/layers/MouseMixin.java | 9 +- .../java/io/wispforest/owo/ops/ItemOps.java | 2 +- .../java/io/wispforest/owo/ops/WorldOps.java | 4 +- .../reflect/BlockRegistryContainer.java | 81 +++--- .../reflect/EntityRegistryContainer.java | 33 +-- .../reflect/ItemRegistryContainer.java | 28 +- .../io/wispforest/owo/shader/BlurProgram.java | 6 +- .../io/wispforest/owo/shader/GlProgram.java | 40 +-- .../wispforest/owo/ui/base/BaseOwoToast.java | 27 +- .../owo/ui/base/BaseOwoTooltipComponent.java | 6 +- .../owo/ui/base/BaseParentComponent.java | 2 +- .../owo/ui/component/BlockComponent.java | 7 +- .../owo/ui/component/ButtonComponent.java | 3 +- .../owo/ui/component/DropdownComponent.java | 3 +- .../owo/ui/component/EntityComponent.java | 9 +- .../owo/ui/component/ItemComponent.java | 8 +- .../owo/ui/component/LabelComponent.java | 2 +- .../owo/ui/component/SlimSliderComponent.java | 5 +- .../ui/component/SmallCheckboxComponent.java | 5 +- .../owo/ui/component/SpriteComponent.java | 4 +- .../owo/ui/component/TextureComponent.java | 9 +- .../owo/ui/container/RenderEffectWrapper.java | 9 +- .../owo/ui/core/OwoUIDrawContext.java | 141 +++++----- .../owo/ui/core/OwoUIRenderLayers.java | 71 +++++ .../java/io/wispforest/owo/ui/core/Size.java | 13 + .../io/wispforest/owo/ui/core/Surface.java | 16 +- .../owo/ui/parsing/UIModelLoader.java | 2 +- .../owo/ui/util/NinePatchTexture.java | 245 ++++++++++++------ .../wispforest/owo/ui/util/ScissorStack.java | 9 +- .../wispforest/owo/ui/util/UIErrorToast.java | 17 +- .../wispforest/owo/util/RegistryAccess.java | 29 --- .../io/wispforest/owo/util/TagInjector.java | 2 - .../assets/owo/shaders/core/blur.json | 9 +- .../assets/owo/shaders/core/spectrum.json | 9 +- src/main/resources/owo.mixins.json | 12 +- src/testmod/java/io/wispforest/uwu/Uwu.java | 11 +- .../uwu/client/ComponentTestScreen.java | 4 +- .../uwu/client/SmolComponentTestScreen.java | 4 +- .../io/wispforest/uwu/client/UwuClient.java | 2 +- .../wispforest/uwu/items/UwuCounterItem.java | 13 +- .../io/wispforest/uwu/items/UwuItems.java | 55 ++-- .../uwu/items/UwuScreenShardItem.java | 11 +- .../uwu/items/UwuTestStickItem.java | 27 +- 76 files changed, 809 insertions(+), 753 deletions(-) rename src/main/java/io/wispforest/owo/mixin/ext/{ComponentMapImplAccessor.java => MergedComponentMapAccessor.java} (75%) rename src/main/java/io/wispforest/owo/mixin/ext/{ComponentMapImplMixin.java => MergedComponentMapMixin.java} (66%) rename src/main/java/io/wispforest/owo/mixin/itemgroup/{AbstractInventoryScreenMixin.java => StatusEffectsDisplayMixin.java} (61%) create mode 100644 src/main/java/io/wispforest/owo/mixin/recipe_remainders/JsonDataLoaderMixin.java delete mode 100644 src/main/java/io/wispforest/owo/mixin/recipe_remainders/RecipeManagerMixin.java delete mode 100644 src/main/java/io/wispforest/owo/mixin/shader/GameRendererMixin.java delete mode 100644 src/main/java/io/wispforest/owo/mixin/shader/ShaderProgramMixin.java delete mode 100644 src/main/java/io/wispforest/owo/mixin/ui/DrawContextMixin.java delete mode 100644 src/main/java/io/wispforest/owo/mixin/ui/TessellatorMixin.java create mode 100644 src/main/java/io/wispforest/owo/ui/core/OwoUIRenderLayers.java delete mode 100644 src/main/java/io/wispforest/owo/util/RegistryAccess.java diff --git a/build.gradle b/build.gradle index 4205acf9..80c8845c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ //file:noinspection GradlePackageVersionRange plugins { - id 'fabric-loom' version '1.6-SNAPSHOT' + id 'fabric-loom' version '1.7-SNAPSHOT' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index f66b92e9..c9c27149 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,16 +2,16 @@ org.gradle.jvmargs=-Xmx2G # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_base_version=1.21 -minecraft_version=1.21 -yarn_mappings=1.21+build.2 -loader_version=0.15.11 +minecraft_base_version=1.21.2 +minecraft_version=1.21.2-pre2 +yarn_mappings=1.21.2-pre2+build.4 +loader_version=0.16.7 # Mod Properties mod_version=0.12.15 maven_group=io.wispforest archives_base_name=owo-lib # Dependencies -fabric_version=0.100.1+1.21 +fabric_version=0.105.3+1.21.2 # https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/ rei_version=15.0.728 @@ -23,7 +23,7 @@ emi_version=1.1.6+1.20.6 jankson_version=1.2.2 # https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu -modmenu_version=11.0.0-rc.2 +modmenu_version=12.0.0-beta.1 # https://maven.nucleoid.xyz/xyz/nucleoid/server-translations-api/ stapi_version=2.3.1+1.21-pre2 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 48c0a02c..0d184210 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/io/wispforest/owo/client/OwoClient.java b/src/main/java/io/wispforest/owo/client/OwoClient.java index 3e13fc8a..4890ff68 100644 --- a/src/main/java/io/wispforest/owo/client/OwoClient.java +++ b/src/main/java/io/wispforest/owo/client/OwoClient.java @@ -15,7 +15,9 @@ import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.resource.ResourceManagerHelper; +import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener; import net.minecraft.client.render.VertexFormats; +import net.minecraft.resource.ResourceManager; import net.minecraft.resource.ResourceType; import net.minecraft.util.Identifier; import net.minecraft.util.Util; @@ -74,5 +76,10 @@ public void onInitializeClient() { if (!Owo.DEBUG) return; OwoDebugCommands.Client.register(); + + ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() { + @Override public Identifier getFabricId() { return Identifier.of("owo", "after_shader_load"); } + @Override public void reload(ResourceManager manager) { GlProgram.forEachProgram(Runnable::run); } + }); } } diff --git a/src/main/java/io/wispforest/owo/client/texture/AnimatedTextureDrawable.java b/src/main/java/io/wispforest/owo/client/texture/AnimatedTextureDrawable.java index f37b087e..8e750d29 100644 --- a/src/main/java/io/wispforest/owo/client/texture/AnimatedTextureDrawable.java +++ b/src/main/java/io/wispforest/owo/client/texture/AnimatedTextureDrawable.java @@ -3,6 +3,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.Drawable; +import net.minecraft.client.render.RenderLayer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; import net.minecraft.util.Util; @@ -88,12 +89,6 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { frame = 0; } - RenderSystem.enableBlend(); - RenderSystem.enableDepthTest(); - - context.drawTexture(this.texture, x, y, (frame / rows) * metadata.frameWidth(), (frame % rows) * metadata.frameHeight(), width, height, metadata.width(), metadata.height()); - - RenderSystem.disableDepthTest(); - RenderSystem.disableBlend(); + context.drawTexture(RenderLayer::getGuiTextured, this.texture, x, y, (frame / rows) * metadata.frameWidth(), (frame % rows) * metadata.frameHeight(), width, height, metadata.width(), metadata.height()); } } diff --git a/src/main/java/io/wispforest/owo/command/debug/OwoDebugCommands.java b/src/main/java/io/wispforest/owo/command/debug/OwoDebugCommands.java index 19b15785..63cc324c 100644 --- a/src/main/java/io/wispforest/owo/command/debug/OwoDebugCommands.java +++ b/src/main/java/io/wispforest/owo/command/debug/OwoDebugCommands.java @@ -70,7 +70,7 @@ public static void register() { dispatcher.register(literal("query-poi").then(argument("poi_type", IdentifierArgumentType.identifier()).suggests(POI_TYPES) .then(argument("radius", IntegerArgumentType.integer()).executes(context -> { var player = context.getSource().getPlayer(); - var poiType = Registries.POINT_OF_INTEREST_TYPE.getOrEmpty(IdentifierArgumentType.getIdentifier(context, "poi_type")) + var poiType = Registries.POINT_OF_INTEREST_TYPE.getOptionalValue(IdentifierArgumentType.getIdentifier(context, "poi_type")) .orElseThrow(NO_POI_TYPE::create); var entries = ((ServerWorld) player.getWorld()).getPointOfInterestStorage().getInCircle(type -> type.value() == poiType, diff --git a/src/main/java/io/wispforest/owo/compat/rei/OwoReiPlugin.java b/src/main/java/io/wispforest/owo/compat/rei/OwoReiPlugin.java index b9ccc81a..b0864638 100644 --- a/src/main/java/io/wispforest/owo/compat/rei/OwoReiPlugin.java +++ b/src/main/java/io/wispforest/owo/compat/rei/OwoReiPlugin.java @@ -155,7 +155,6 @@ private static void renderOverlay(Screen screen, Runnable renderFunction) { modelView.rotate(RotationAxis.POSITIVE_Z.rotationDegrees(i * 18)); modelView.translate(screen.width / -2f, screen.height / -2f, 0); - RenderSystem.applyModelViewMatrix(); ScissorStack.pushDirect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE); renderFunction.run(); GlStateManager._enableScissorTest(); @@ -164,7 +163,6 @@ private static void renderOverlay(Screen screen, Runnable renderFunction) { } modelView.popMatrix(); - RenderSystem.applyModelViewMatrix(); } else { ScissorStack.pushDirect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE); renderFunction.run(); diff --git a/src/main/java/io/wispforest/owo/compat/rei/ReiUIAdapter.java b/src/main/java/io/wispforest/owo/compat/rei/ReiUIAdapter.java index d5a99d47..28f8b7ad 100644 --- a/src/main/java/io/wispforest/owo/compat/rei/ReiUIAdapter.java +++ b/src/main/java/io/wispforest/owo/compat/rei/ReiUIAdapter.java @@ -94,7 +94,7 @@ public boolean charTyped(char chr, int modifiers) { @Override public void render(DrawContext context, int mouseX, int mouseY, float partialTicks) { - ScissorStack.push(this.adapter.x(), this.adapter.y(), this.adapter.width(), this.adapter.height(), context.getMatrices()); + ScissorStack.push(this.adapter.x(), this.adapter.y(), this.adapter.width(), this.adapter.height(), context); this.adapter.render(context, mouseX, mouseY, partialTicks); ScissorStack.pop(); diff --git a/src/main/java/io/wispforest/owo/ext/DerivedComponentMap.java b/src/main/java/io/wispforest/owo/ext/DerivedComponentMap.java index 85ecd012..59da93ad 100644 --- a/src/main/java/io/wispforest/owo/ext/DerivedComponentMap.java +++ b/src/main/java/io/wispforest/owo/ext/DerivedComponentMap.java @@ -2,7 +2,7 @@ import net.minecraft.component.ComponentChanges; import net.minecraft.component.ComponentMap; -import net.minecraft.component.ComponentMapImpl; +import net.minecraft.component.MergedComponentMap; import net.minecraft.component.ComponentType; import net.minecraft.item.ItemStack; import org.jetbrains.annotations.ApiStatus; @@ -14,11 +14,11 @@ @ApiStatus.Internal public class DerivedComponentMap implements ComponentMap { private final ComponentMap base; - private final ComponentMapImpl delegate; + private final MergedComponentMap delegate; public DerivedComponentMap(ComponentMap base) { this.base = base; - this.delegate = new ComponentMapImpl(base); + this.delegate = new MergedComponentMap(base); } public static ComponentMap reWrapIfNeeded(ComponentMap original) { diff --git a/src/main/java/io/wispforest/owo/itemgroup/Icon.java b/src/main/java/io/wispforest/owo/itemgroup/Icon.java index 0a72ab4c..b8c5e908 100644 --- a/src/main/java/io/wispforest/owo/itemgroup/Icon.java +++ b/src/main/java/io/wispforest/owo/itemgroup/Icon.java @@ -5,6 +5,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.render.RenderLayer; import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; @@ -37,7 +38,7 @@ static Icon of(Identifier texture, int u, int v, int textureWidth, int textureHe return new Icon() { @Override public void render(DrawContext context, int x, int y, int mouseX, int mouseY, float delta) { - context.drawTexture(texture, x, y, u, v, 16, 16, textureWidth, textureHeight); + context.drawTexture(RenderLayer::getGuiTextured, texture, x, y, u, v, 16, 16, textureWidth, textureHeight); } }; } diff --git a/src/main/java/io/wispforest/owo/itemgroup/gui/ItemGroupButtonWidget.java b/src/main/java/io/wispforest/owo/itemgroup/gui/ItemGroupButtonWidget.java index 8acd32c3..3d7128cc 100644 --- a/src/main/java/io/wispforest/owo/itemgroup/gui/ItemGroupButtonWidget.java +++ b/src/main/java/io/wispforest/owo/itemgroup/gui/ItemGroupButtonWidget.java @@ -4,6 +4,7 @@ import io.wispforest.owo.itemgroup.OwoItemGroup; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.render.RenderLayer; import org.jetbrains.annotations.ApiStatus; import java.util.function.Consumer; @@ -23,13 +24,9 @@ public ItemGroupButtonWidget(int x, int y, int baseU, OwoItemGroup.ButtonDefinit @Override public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) { - RenderSystem.enableDepthTest(); - context.drawTexture(this.definition.texture(), this.getX(), this.getY(), this.baseU, this.isSelected() || this.isSelected ? this.height : 0, this.width, this.height, 64, 64); + context.drawTexture(RenderLayer::getGuiTextured, this.definition.texture(), this.getX(), this.getY(), this.baseU, this.isSelected() || this.isSelected ? this.height : 0, this.width, this.height, 64, 64); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); this.definition.icon().render(context, this.getX() + 4, this.getY() + 4, mouseX, mouseY, delta); - RenderSystem.disableBlend(); } public boolean isTab() { diff --git a/src/main/java/io/wispforest/owo/mixin/CachedRegistryInfoGetterAccessor.java b/src/main/java/io/wispforest/owo/mixin/CachedRegistryInfoGetterAccessor.java index 878cd526..bc24c2fd 100644 --- a/src/main/java/io/wispforest/owo/mixin/CachedRegistryInfoGetterAccessor.java +++ b/src/main/java/io/wispforest/owo/mixin/CachedRegistryInfoGetterAccessor.java @@ -7,5 +7,5 @@ @Mixin(RegistryOps.CachedRegistryInfoGetter.class) public interface CachedRegistryInfoGetterAccessor { - @Accessor("registriesLookup") RegistryWrapper.WrapperLookup owo$getRegistriesLookup(); + @Accessor("registries") RegistryWrapper.WrapperLookup owo$getRegistriesLookup(); } diff --git a/src/main/java/io/wispforest/owo/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/wispforest/owo/mixin/ServerPlayerInteractionManagerMixin.java index 35cc06f8..c0510a4b 100644 --- a/src/main/java/io/wispforest/owo/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/ServerPlayerInteractionManagerMixin.java @@ -18,11 +18,11 @@ public class ServerPlayerInteractionManagerMixin { @Inject(method = "interactItem", at = @At("RETURN")) private void incrementUseState(ServerPlayerEntity player, World world, ItemStack stack, Hand hand, CallbackInfoReturnable cir) { - if (!((OwoItemExtensions) stack.getItem()).owo$shouldTrackUsageStat() || !cir.getReturnValue().shouldIncrementStat()) { - return; - } + var result = cir.getReturnValue(); - player.incrementStat(Stats.USED.getOrCreateStat(stack.getItem())); + if(((OwoItemExtensions) stack.getItem()).owo$shouldTrackUsageStat() || (result instanceof ActionResult.Success successResult && successResult.shouldIncrementStat())) { + player.incrementStat(Stats.USED.getOrCreateStat(stack.getItem())); + } } } diff --git a/src/main/java/io/wispforest/owo/mixin/ext/ItemStackMixin.java b/src/main/java/io/wispforest/owo/mixin/ext/ItemStackMixin.java index 47cb50b9..188da664 100644 --- a/src/main/java/io/wispforest/owo/mixin/ext/ItemStackMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/ext/ItemStackMixin.java @@ -3,7 +3,7 @@ import io.wispforest.owo.ext.DerivedComponentMap; import net.minecraft.component.ComponentChanges; import net.minecraft.component.ComponentMap; -import net.minecraft.component.ComponentMapImpl; +import net.minecraft.component.MergedComponentMap; import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import org.spongepowered.asm.mixin.Final; @@ -16,25 +16,26 @@ @Mixin(ItemStack.class) public class ItemStackMixin { - @Shadow @Final ComponentMapImpl components; + @Shadow @Final + MergedComponentMap components; @Unique private DerivedComponentMap owo$derivedMap; - @Inject(method = "(Lnet/minecraft/item/ItemConvertible;ILnet/minecraft/component/ComponentMapImpl;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;postProcessComponents(Lnet/minecraft/item/ItemStack;)V")) - private void injectDerivedComponentMap(ItemConvertible item, int count, ComponentMapImpl components, CallbackInfo ci) { - var base = ((ComponentMapImplAccessor)(Object) this.components).owo$getBaseComponents(); + @Inject(method = "(Lnet/minecraft/item/ItemConvertible;ILnet/minecraft/component/MergedComponentMap;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;postProcessComponents(Lnet/minecraft/item/ItemStack;)V")) + private void injectDerivedComponentMap(ItemConvertible item, int count, MergedComponentMap components, CallbackInfo ci) { + var base = ((MergedComponentMapAccessor)(Object) this.components).owo$getBaseComponents(); if (base instanceof DerivedComponentMap derived) { owo$derivedMap = derived; } else { owo$derivedMap = new DerivedComponentMap(base); - ((ComponentMapImplAccessor)(Object) this.components).owo$setBaseComponents(owo$derivedMap); + ((MergedComponentMapAccessor)(Object) this.components).owo$setBaseComponents(owo$derivedMap); } } // TODO: for some reason mixin doesn't like it if I put all the injects in one method. - @Inject(method = "(Lnet/minecraft/item/ItemConvertible;ILnet/minecraft/component/ComponentMapImpl;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;postProcessComponents(Lnet/minecraft/item/ItemStack;)V", shift = At.Shift.AFTER)) - private void deriveComponents1(ItemConvertible item, int count, ComponentMapImpl components, CallbackInfo ci) { + @Inject(method = "(Lnet/minecraft/item/ItemConvertible;ILnet/minecraft/component/MergedComponentMap;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;postProcessComponents(Lnet/minecraft/item/ItemStack;)V", shift = At.Shift.AFTER)) + private void deriveComponents1(ItemConvertible item, int count, MergedComponentMap components, CallbackInfo ci) { if (owo$derivedMap == null) return; owo$derivedMap.derive((ItemStack)(Object) this); } diff --git a/src/main/java/io/wispforest/owo/mixin/ext/ComponentMapImplAccessor.java b/src/main/java/io/wispforest/owo/mixin/ext/MergedComponentMapAccessor.java similarity index 75% rename from src/main/java/io/wispforest/owo/mixin/ext/ComponentMapImplAccessor.java rename to src/main/java/io/wispforest/owo/mixin/ext/MergedComponentMapAccessor.java index 717ba5d3..5381aefd 100644 --- a/src/main/java/io/wispforest/owo/mixin/ext/ComponentMapImplAccessor.java +++ b/src/main/java/io/wispforest/owo/mixin/ext/MergedComponentMapAccessor.java @@ -1,13 +1,13 @@ package io.wispforest.owo.mixin.ext; import net.minecraft.component.ComponentMap; -import net.minecraft.component.ComponentMapImpl; +import net.minecraft.component.MergedComponentMap; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.gen.Accessor; -@Mixin(ComponentMapImpl.class) -public interface ComponentMapImplAccessor { +@Mixin(MergedComponentMap.class) +public interface MergedComponentMapAccessor { @Accessor("baseComponents") ComponentMap owo$getBaseComponents(); diff --git a/src/main/java/io/wispforest/owo/mixin/ext/ComponentMapImplMixin.java b/src/main/java/io/wispforest/owo/mixin/ext/MergedComponentMapMixin.java similarity index 66% rename from src/main/java/io/wispforest/owo/mixin/ext/ComponentMapImplMixin.java rename to src/main/java/io/wispforest/owo/mixin/ext/MergedComponentMapMixin.java index 6ea852f3..e34efd59 100644 --- a/src/main/java/io/wispforest/owo/mixin/ext/ComponentMapImplMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/ext/MergedComponentMapMixin.java @@ -3,13 +3,13 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import io.wispforest.owo.ext.DerivedComponentMap; import net.minecraft.component.ComponentMap; -import net.minecraft.component.ComponentMapImpl; +import net.minecraft.component.MergedComponentMap; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -@Mixin(ComponentMapImpl.class) -public class ComponentMapImplMixin { - @ModifyExpressionValue(method = "copy", at = @At(value = "FIELD", target = "Lnet/minecraft/component/ComponentMapImpl;baseComponents:Lnet/minecraft/component/ComponentMap;")) +@Mixin(MergedComponentMap.class) +public class MergedComponentMapMixin { + @ModifyExpressionValue(method = "copy", at = @At(value = "FIELD", target = "Lnet/minecraft/component/MergedComponentMap;baseComponents:Lnet/minecraft/component/ComponentMap;")) private ComponentMap reWrapDerived(ComponentMap original) { return DerivedComponentMap.reWrapIfNeeded(original); } diff --git a/src/main/java/io/wispforest/owo/mixin/itemgroup/CreativeInventoryScreenMixin.java b/src/main/java/io/wispforest/owo/mixin/itemgroup/CreativeInventoryScreenMixin.java index 6eedb666..6dd5cb37 100644 --- a/src/main/java/io/wispforest/owo/mixin/itemgroup/CreativeInventoryScreenMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/itemgroup/CreativeInventoryScreenMixin.java @@ -9,8 +9,8 @@ import io.wispforest.owo.util.pond.OwoCreativeInventoryScreenExtensions; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen; import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; +import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -18,7 +18,6 @@ import net.minecraft.resource.featuretoggle.FeatureSet; import net.minecraft.text.Text; import net.minecraft.util.Identifier; -import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -35,7 +34,7 @@ import java.util.function.Consumer; @Mixin(CreativeInventoryScreen.class) -public abstract class CreativeInventoryScreenMixin extends AbstractInventoryScreen implements OwoCreativeInventoryScreenExtensions { +public abstract class CreativeInventoryScreenMixin extends HandledScreen implements OwoCreativeInventoryScreenExtensions { @Shadow private static ItemGroup selectedTab; @@ -67,7 +66,7 @@ private void captureFeatures(ClientPlayerEntity player, FeatureSet enabledFeatur // Background // ---------- - @ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 0)) + @ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIFFIIII)V", ordinal = 0)) private Identifier injectCustomGroupTexture(Identifier original) { if (!(selectedTab instanceof OwoItemGroup owoGroup) || owoGroup.getBackgroundTexture() == null) return original; return owoGroup.getBackgroundTexture(); @@ -77,18 +76,20 @@ private Identifier injectCustomGroupTexture(Identifier original) { // Scrollbar slider // ---------------- - @ModifyArgs(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V")) - private void injectCustomScrollbarTexture(Args args) { - if (!(selectedTab instanceof OwoItemGroup owoGroup) || owoGroup.getScrollerTextures() == null) return; + @ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIII)V")) + private Identifier injectCustomScrollbarTexture(Identifier texture) { + if (!(selectedTab instanceof OwoItemGroup owoGroup) || owoGroup.getScrollerTextures() == null) return texture; - args.set(0, this.hasScrollbar() ? owoGroup.getScrollerTextures().enabled() : owoGroup.getScrollerTextures().disabled()); + return this.hasScrollbar() + ? owoGroup.getScrollerTextures().enabled() + : owoGroup.getScrollerTextures().disabled(); } // ------------- // Group headers // ------------- - @ModifyArg(method = "renderTabIcon", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V")) + @ModifyArg(method = "renderTabIcon", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIII)V")) private Identifier injectCustomTabTexture(Identifier texture, @Local(argsOnly = true) ItemGroup group) { if(!(group instanceof OwoItemGroup contextGroup) || contextGroup.getTabTextures() == null) return texture; @@ -190,7 +191,8 @@ private void render(DrawContext context, int mouseX, int mouseY, float delta, Ca ? List.of(button.getMessage(), Text.translatable("text.owo.itemGroup.select_hint")) : List.of(button.getMessage()), mouseX, - mouseY + mouseY, + null ); anyButtonHovered = true; } diff --git a/src/main/java/io/wispforest/owo/mixin/itemgroup/AbstractInventoryScreenMixin.java b/src/main/java/io/wispforest/owo/mixin/itemgroup/StatusEffectsDisplayMixin.java similarity index 61% rename from src/main/java/io/wispforest/owo/mixin/itemgroup/AbstractInventoryScreenMixin.java rename to src/main/java/io/wispforest/owo/mixin/itemgroup/StatusEffectsDisplayMixin.java index f6475ad7..450a1234 100644 --- a/src/main/java/io/wispforest/owo/mixin/itemgroup/AbstractInventoryScreenMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/itemgroup/StatusEffectsDisplayMixin.java @@ -1,16 +1,18 @@ package io.wispforest.owo.mixin.itemgroup; import io.wispforest.owo.itemgroup.OwoItemGroup; -import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen; import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; +import net.minecraft.client.gui.screen.ingame.StatusEffectsDisplay; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; -@Mixin(AbstractInventoryScreen.class) -public class AbstractInventoryScreenMixin { +@Mixin(StatusEffectsDisplay.class) +public class StatusEffectsDisplayMixin { - @ModifyVariable(method = "drawStatusEffects", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/screen/ingame/AbstractInventoryScreen;width:I", ordinal = 0), ordinal = 2) + @ModifyVariable(method = "drawStatusEffects(Lnet/minecraft/client/gui/DrawContext;II)V", + at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/screen/ingame/HandledScreen;width:I", ordinal = 0), + ordinal = 2) private int shiftStatusEffects(int x) { if (!((Object) this instanceof CreativeInventoryScreen)) return x; if (!(CreativeInventoryScreenAccessor.owo$getSelectedTab() instanceof OwoItemGroup group)) return x; diff --git a/src/main/java/io/wispforest/owo/mixin/recipe_remainders/CraftingResultSlotMixin.java b/src/main/java/io/wispforest/owo/mixin/recipe_remainders/CraftingResultSlotMixin.java index b7edf029..801f0022 100644 --- a/src/main/java/io/wispforest/owo/mixin/recipe_remainders/CraftingResultSlotMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/recipe_remainders/CraftingResultSlotMixin.java @@ -1,10 +1,22 @@ package io.wispforest.owo.mixin.recipe_remainders; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; +import io.wispforest.owo.util.RecipeRemainderStorage; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeEntry; +import net.minecraft.recipe.RecipeType; +import net.minecraft.recipe.ServerRecipeManager; import net.minecraft.recipe.input.CraftingRecipeInput; +import net.minecraft.recipe.input.RecipeInput; import net.minecraft.screen.slot.CraftingResultSlot; import net.minecraft.util.collection.DefaultedList; +import net.minecraft.world.World; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -13,6 +25,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; +import java.util.Optional; +import java.util.function.Function; + @Mixin(CraftingResultSlot.class) public class CraftingResultSlotMixin { @@ -35,4 +50,39 @@ private void fixRemainderStacking(PlayerEntity player, ItemStack stack, Callback } } + @WrapOperation(method = "getRecipeRemainders", at = @At(value = "INVOKE", target = "Lnet/minecraft/recipe/ServerRecipeManager;getFirstMatch(Lnet/minecraft/recipe/RecipeType;Lnet/minecraft/recipe/input/RecipeInput;Lnet/minecraft/world/World;)Ljava/util/Optional;")) + private > Optional> captureRecipeEntry(ServerRecipeManager instance, RecipeType type, I input, World world, Operation>> original, @Share("owo_recipe_entry") LocalRef>> recipeEntry) { + var entry = original.call(instance, type, input, world); + + recipeEntry.set(entry); + + return entry; + } + + @WrapOperation(method = "getRecipeRemainders", at = @At(value = "INVOKE", target = "Ljava/util/Optional;map(Ljava/util/function/Function;)Ljava/util/Optional;")) + private Optional addRecipeSpecificRemainders(Optional instance, Function mapper, Operation> original, @Share("owo_recipe_entry") LocalRef>> recipeEntry, @Local(argsOnly = true) CraftingRecipeInput input) { + var recipeEntryOptional = recipeEntry.get(); + + var mappedValue = original.call(instance, mapper); + + var defaultList = (DefaultedList) (Object) mappedValue; + + if (recipeEntryOptional.isPresent() ){ + var recipeId = recipeEntryOptional.get().id().getValue(); + + if(RecipeRemainderStorage.has(recipeId)) { + var remainders = defaultList; + var owoRemainders = RecipeRemainderStorage.get(recipeId); + + for (int i = 0; i < remainders.size(); ++i) { + var item = input.getStackInSlot(i).getItem(); + if (!owoRemainders.containsKey(item)) continue; + + remainders.set(i, owoRemainders.get(item).copy()); + } + } + } + + return mappedValue; + } } diff --git a/src/main/java/io/wispforest/owo/mixin/recipe_remainders/JsonDataLoaderMixin.java b/src/main/java/io/wispforest/owo/mixin/recipe_remainders/JsonDataLoaderMixin.java new file mode 100644 index 00000000..1c741821 --- /dev/null +++ b/src/main/java/io/wispforest/owo/mixin/recipe_remainders/JsonDataLoaderMixin.java @@ -0,0 +1,67 @@ +package io.wispforest.owo.mixin.recipe_remainders; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import com.mojang.serialization.JsonOps; +import io.wispforest.owo.util.RecipeRemainderStorage; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeEntry; +import net.minecraft.recipe.RecipeType; +import net.minecraft.recipe.input.RecipeInput; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.resource.JsonDataLoader; +import net.minecraft.resource.ResourceManager; +import net.minecraft.util.Identifier; +import net.minecraft.util.JsonHelper; +import net.minecraft.util.collection.DefaultedList; +import net.minecraft.util.profiler.Profiler; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.io.Reader; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +@Mixin(JsonDataLoader.class) +public abstract class JsonDataLoaderMixin { + + @WrapOperation(method = "load", at = @At(value = "INVOKE", target = "Lcom/google/gson/JsonParser;parseReader(Ljava/io/Reader;)Lcom/google/gson/JsonElement;")) + private static JsonElement deserializeRecipeSpecificRemainders(Reader jsonReader, Operation original, @Local(argsOnly = true) String dataType, @Local(ordinal = 1) Identifier recipeId) { + var element = original.call(jsonReader); + + if (dataType.equals(RegistryKeys.getPath(RegistryKeys.RECIPE)) && element instanceof JsonObject json) { + if (json.has("owo:remainders")) { + var remainders = new HashMap(); + + for (var remainderEntry : json.getAsJsonObject("owo:remainders").entrySet()) { + var item = JsonHelper.asItem(new JsonPrimitive(remainderEntry.getKey()), remainderEntry.getKey()); + + if (remainderEntry.getValue().isJsonObject()) { + var remainderStack = ItemStack.CODEC.parse(JsonOps.INSTANCE, remainderEntry.getValue().getAsJsonObject()).getOrThrow(JsonParseException::new); + remainders.put(item.value(), remainderStack); + } else { + var remainderItem = JsonHelper.asItem(remainderEntry.getValue(), "item"); + remainders.put(item.value(), new ItemStack(remainderItem)); + } + } + + if (!remainders.isEmpty()) RecipeRemainderStorage.store(recipeId, remainders); + } + } + + return element; + } +} diff --git a/src/main/java/io/wispforest/owo/mixin/recipe_remainders/RecipeManagerMixin.java b/src/main/java/io/wispforest/owo/mixin/recipe_remainders/RecipeManagerMixin.java deleted file mode 100644 index 1298fd98..00000000 --- a/src/main/java/io/wispforest/owo/mixin/recipe_remainders/RecipeManagerMixin.java +++ /dev/null @@ -1,72 +0,0 @@ -package io.wispforest.owo.mixin.recipe_remainders; - -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.llamalad7.mixinextras.sugar.Local; -import com.mojang.serialization.JsonOps; -import io.wispforest.owo.util.RecipeRemainderStorage; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.recipe.Recipe; -import net.minecraft.recipe.RecipeEntry; -import net.minecraft.recipe.RecipeManager; -import net.minecraft.recipe.RecipeType; -import net.minecraft.recipe.input.RecipeInput; -import net.minecraft.resource.ResourceManager; -import net.minecraft.util.Identifier; -import net.minecraft.util.JsonHelper; -import net.minecraft.util.collection.DefaultedList; -import net.minecraft.util.profiler.Profiler; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -@Mixin(RecipeManager.class) -public abstract class RecipeManagerMixin { - - @Inject(method = "apply(Ljava/util/Map;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/recipe/RecipeEntry;(Lnet/minecraft/util/Identifier;Lnet/minecraft/recipe/Recipe;)V")) - private void deserializeRecipeSpecificRemainders(Map map, ResourceManager resourceManager, Profiler profiler, CallbackInfo ci, @Local Map.Entry entry) { - var json = entry.getValue().getAsJsonObject(); - if (!json.has("owo:remainders")) return; - - var remainders = new HashMap(); - for (var remainderEntry : json.getAsJsonObject("owo:remainders").entrySet()) { - var item = JsonHelper.asItem(new JsonPrimitive(remainderEntry.getKey()), remainderEntry.getKey()); - - if (remainderEntry.getValue().isJsonObject()) { - var remainderStack = ItemStack.CODEC.parse(JsonOps.INSTANCE, remainderEntry.getValue().getAsJsonObject()).getOrThrow(JsonParseException::new); - remainders.put(item.value(), remainderStack); - } else { - var remainderItem = JsonHelper.asItem(remainderEntry.getValue(), "item"); - remainders.put(item.value(), new ItemStack(remainderItem)); - } - } - - if (remainders.isEmpty()) return; - RecipeRemainderStorage.store(entry.getKey(), remainders); - } - - @Inject(method = "getRemainingStacks", at = @At(value = "RETURN", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD) - private > void addRecipeSpecificRemainders(RecipeType type, I inventory, World world, CallbackInfoReturnable> cir, Optional> optional) { - if (optional.isEmpty() || !RecipeRemainderStorage.has(optional.get().id())) return; - - var remainders = cir.getReturnValue(); - var owoRemainders = RecipeRemainderStorage.get(optional.get().id()); - - for (int i = 0; i < remainders.size(); ++i) { - var item = inventory.getStackInSlot(i).getItem(); - if (!owoRemainders.containsKey(item)) continue; - - remainders.set(i, owoRemainders.get(item).copy()); - } - } -} diff --git a/src/main/java/io/wispforest/owo/mixin/registry/SimpleRegistryMixin.java b/src/main/java/io/wispforest/owo/mixin/registry/SimpleRegistryMixin.java index 8a875c6f..85803755 100644 --- a/src/main/java/io/wispforest/owo/mixin/registry/SimpleRegistryMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/registry/SimpleRegistryMixin.java @@ -56,7 +56,7 @@ public abstract class SimpleRegistryMixin implements MutableRegistry, OwoS ((ReferenceAccessor) reference).owo$setRegistryKey(arg); } else { - reference = this.keyToEntry.computeIfAbsent(arg, k -> RegistryEntry.Reference.standAlone(this.getEntryOwner(), k)); + reference = this.keyToEntry.computeIfAbsent(arg, k -> RegistryEntry.Reference.standAlone(this, k)); ((ReferenceAccessor) reference).owo$setValue((T)object); } diff --git a/src/main/java/io/wispforest/owo/mixin/shader/GameRendererMixin.java b/src/main/java/io/wispforest/owo/mixin/shader/GameRendererMixin.java deleted file mode 100644 index e09e0624..00000000 --- a/src/main/java/io/wispforest/owo/mixin/shader/GameRendererMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.wispforest.owo.mixin.shader; - -import com.mojang.datafixers.util.Pair; -import io.wispforest.owo.shader.GlProgram; -import net.minecraft.client.gl.ShaderProgram; -import net.minecraft.client.gl.ShaderStage; -import net.minecraft.client.render.GameRenderer; -import net.minecraft.resource.ResourceFactory; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -import java.util.List; -import java.util.function.Consumer; - -@Mixin(GameRenderer.class) -public class GameRendererMixin { - - @Inject(method = "loadPrograms", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD) - void loadAllTheShaders(ResourceFactory factory, CallbackInfo ci, List stages, List>> shadersToLoad) { - GlProgram.forEachProgram(loader -> shadersToLoad.add(new Pair<>(loader.getLeft().apply(factory), loader.getRight()))); - } - -} diff --git a/src/main/java/io/wispforest/owo/mixin/shader/ShaderProgramAccessor.java b/src/main/java/io/wispforest/owo/mixin/shader/ShaderProgramAccessor.java index f5f88f34..e9a4a718 100644 --- a/src/main/java/io/wispforest/owo/mixin/shader/ShaderProgramAccessor.java +++ b/src/main/java/io/wispforest/owo/mixin/shader/ShaderProgramAccessor.java @@ -10,7 +10,7 @@ @Mixin(ShaderProgram.class) public interface ShaderProgramAccessor { - @Accessor("loadedUniforms") + @Accessor("uniformsByName") Map owo$getLoadedUniforms(); } diff --git a/src/main/java/io/wispforest/owo/mixin/shader/ShaderProgramMixin.java b/src/main/java/io/wispforest/owo/mixin/shader/ShaderProgramMixin.java deleted file mode 100644 index 1c71be03..00000000 --- a/src/main/java/io/wispforest/owo/mixin/shader/ShaderProgramMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.wispforest.owo.mixin.shader; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import com.llamalad7.mixinextras.sugar.Local; -import io.wispforest.owo.shader.GlProgram; -import net.minecraft.client.gl.ShaderProgram; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -@Mixin(ShaderProgram.class) -public class ShaderProgramMixin { - - @WrapOperation(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Identifier;ofVanilla(Ljava/lang/String;)Lnet/minecraft/util/Identifier;"), require = 0) - private Identifier fixIdentifier(String path, Operation original, @Local(argsOnly = true) String name) { - if ((Object) this instanceof GlProgram.OwoShaderProgram) { - var pathParts = path.split(name); - if (pathParts.length == 2 && pathParts[0].startsWith("shaders/core/")) { - var programParts = name.split(":"); - - return Identifier.of(programParts[0], pathParts[0] + programParts[1] + pathParts[1]); - } - } - - return original.call(path); - } - -} diff --git a/src/main/java/io/wispforest/owo/mixin/ui/DrawContextInvoker.java b/src/main/java/io/wispforest/owo/mixin/ui/DrawContextInvoker.java index bcdc6f38..e2d804e0 100644 --- a/src/main/java/io/wispforest/owo/mixin/ui/DrawContextInvoker.java +++ b/src/main/java/io/wispforest/owo/mixin/ui/DrawContextInvoker.java @@ -4,7 +4,10 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.tooltip.TooltipComponent; import net.minecraft.client.gui.tooltip.TooltipPositioner; +import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.gen.Accessor; @@ -16,7 +19,10 @@ public interface DrawContextInvoker { @Invoker("drawTooltip") - void owo$renderTooltipFromComponents(TextRenderer textRenderer, List components, int x, int y, TooltipPositioner positioner); + void owo$renderTooltipFromComponents(TextRenderer textRenderer, List components, int x, int y, TooltipPositioner positioner, @Nullable Identifier texture); + + @Accessor("vertexConsumers") + VertexConsumerProvider.Immediate owo$vertexConsumers(); @Accessor("matrices") MatrixStack owo$getMatrices(); diff --git a/src/main/java/io/wispforest/owo/mixin/ui/DrawContextMixin.java b/src/main/java/io/wispforest/owo/mixin/ui/DrawContextMixin.java deleted file mode 100644 index 4f386f44..00000000 --- a/src/main/java/io/wispforest/owo/mixin/ui/DrawContextMixin.java +++ /dev/null @@ -1,54 +0,0 @@ -package io.wispforest.owo.mixin.ui; - -import com.llamalad7.mixinextras.sugar.Local; -import io.wispforest.owo.mixin.BufferBuilderAccessor; -import io.wispforest.owo.ui.core.OwoUIDrawContext; -import io.wispforest.owo.util.pond.OwoTessellatorExtension; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.Tessellator; -import net.minecraft.util.Identifier; -import org.joml.Matrix4f; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(DrawContext.class) -public class DrawContextMixin { - - @SuppressWarnings("ConstantValue") - @Inject(method = "drawTexturedQuad(Lnet/minecraft/util/Identifier;IIIIIFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Tessellator;begin(Lnet/minecraft/client/render/VertexFormat$DrawMode;Lnet/minecraft/client/render/VertexFormat;)Lnet/minecraft/client/render/BufferBuilder;"), locals = LocalCapture.CAPTURE_FAILHARD) - private void injectBufferBegin(Identifier texture, int x1, int x2, int y1, int y2, int z, float u1, float u2, float v1, float v2, CallbackInfo ci, Matrix4f matrix4f) { - if (!((Object) this instanceof OwoUIDrawContext context) || !context.recording()) return; - - ((OwoTessellatorExtension) Tessellator.getInstance()).owo$skipNextBegin(); - } - - @SuppressWarnings("ConstantValue") - @Inject(method = "drawTexturedQuad(Lnet/minecraft/util/Identifier;IIIIIFFFFFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Tessellator;begin(Lnet/minecraft/client/render/VertexFormat$DrawMode;Lnet/minecraft/client/render/VertexFormat;)Lnet/minecraft/client/render/BufferBuilder;"), locals = LocalCapture.CAPTURE_FAILHARD) - private void injectBufferBeginPartTwo(Identifier texture, int x1, int x2, int y1, int y2, int z, float u1, float u2, float v1, float v2, float red, float green, float blue, float alpha, CallbackInfo ci, Matrix4f matrix4f) { - if (!((Object) this instanceof OwoUIDrawContext context) || !context.recording()) return; - - ((OwoTessellatorExtension) Tessellator.getInstance()).owo$skipNextBegin(); - } - - @SuppressWarnings("ConstantValue") - @Inject(method = "drawTexturedQuad(Lnet/minecraft/util/Identifier;IIIIIFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/BufferBuilder;end()Lnet/minecraft/client/render/BuiltBuffer;"), cancellable = true) - private void skipDraw(Identifier texture, int x1, int x2, int y1, int y2, int z, float u1, float u2, float v1, float v2, CallbackInfo ci, @Local(ordinal = 0) BufferBuilder builder) { - if ((Object) this instanceof OwoUIDrawContext context && context.recording()) { - ci.cancel(); - ((OwoTessellatorExtension) Tessellator.getInstance()).owo$setStoredBuilder(builder); - } - } - - @SuppressWarnings("ConstantValue") - @Inject(method = "drawTexturedQuad(Lnet/minecraft/util/Identifier;IIIIIFFFFFFFF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/BufferBuilder;end()Lnet/minecraft/client/render/BuiltBuffer;"), cancellable = true) - private void skipDrawSeason2(Identifier texture, int x1, int x2, int y1, int y2, int z, float u1, float u2, float v1, float v2, float red, float green, float blue, float alpha, CallbackInfo ci, @Local(ordinal = 0) BufferBuilder builder) { - if ((Object) this instanceof OwoUIDrawContext context && context.recording()) { - ci.cancel(); - ((OwoTessellatorExtension) Tessellator.getInstance()).owo$setStoredBuilder(builder); - } - } -} diff --git a/src/main/java/io/wispforest/owo/mixin/ui/EntityRenderDispatcherMixin.java b/src/main/java/io/wispforest/owo/mixin/ui/EntityRenderDispatcherMixin.java index 7380c1fc..e6cb05f0 100644 --- a/src/main/java/io/wispforest/owo/mixin/ui/EntityRenderDispatcherMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/ui/EntityRenderDispatcherMixin.java @@ -4,6 +4,7 @@ import net.minecraft.client.render.Camera; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.render.entity.state.EntityRenderState; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.Entity; import net.minecraft.util.math.RotationAxis; @@ -43,7 +44,7 @@ public class EntityRenderDispatcherMixin implements OwoEntityRenderDispatcherExt @Shadow public Camera camera; @Inject(method = "renderFire", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;multiply(Lorg/joml/Quaternionf;)V", shift = At.Shift.AFTER)) - private void cancelFireRotation(MatrixStack matrices, VertexConsumerProvider vertexConsumers, Entity entity, Quaternionf rotation, CallbackInfo ci) { + private void cancelFireRotation(MatrixStack matrices, VertexConsumerProvider vertexConsumers, EntityRenderState renderState, Quaternionf rotation, CallbackInfo ci) { if (!this.owo$counterRotate) return; matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(this.camera.getYaw() + 170)); matrices.translate(0, 0, .1); diff --git a/src/main/java/io/wispforest/owo/mixin/ui/EntityRendererMixin.java b/src/main/java/io/wispforest/owo/mixin/ui/EntityRendererMixin.java index e0626d3a..2e86d10a 100644 --- a/src/main/java/io/wispforest/owo/mixin/ui/EntityRendererMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/ui/EntityRendererMixin.java @@ -4,6 +4,7 @@ import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.client.render.entity.EntityRenderer; +import net.minecraft.client.render.entity.state.EntityRenderState; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.Entity; import net.minecraft.text.Text; @@ -17,20 +18,20 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(EntityRenderer.class) -public class EntityRendererMixin { +public class EntityRendererMixin { @Shadow @Final protected EntityRenderDispatcher dispatcher; @Inject(method = "renderLabelIfPresent", at = @At("HEAD"), cancellable = true) - private void cancelLabel(T entity, Text text, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, float tickDelta, CallbackInfo ci) { + private void cancelLabel(S state, Text text, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { if (((OwoEntityRenderDispatcherExtension) this.dispatcher).owo$showNametag()) return; ci.cancel(); } @Inject(method = "renderLabelIfPresent", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;multiply(Lorg/joml/Quaternionf;)V", shift = At.Shift.AFTER)) - private void adjustLabelRotation(T entity, Text text, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, float tickDelta, CallbackInfo ci) { + private void adjustLabelRotation(S state, Text text, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { if (!((OwoEntityRenderDispatcherExtension) this.dispatcher).owo$counterRotate()) return; matrices.multiply(new Quaternionf(this.dispatcher.getRotation()).invert()); diff --git a/src/main/java/io/wispforest/owo/mixin/ui/HandledScreenMixin.java b/src/main/java/io/wispforest/owo/mixin/ui/HandledScreenMixin.java index dad47f6f..5e0878bb 100644 --- a/src/main/java/io/wispforest/owo/mixin/ui/HandledScreenMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/ui/HandledScreenMixin.java @@ -61,18 +61,19 @@ private void clearSlotScissors(DrawContext context, Slot slot, CallbackInfo ci) GlStateManager._disableScissorTest(); } - @Inject(method = "drawSlotHighlight", at = @At(value = "HEAD")) - private static void enableSlotDepth(DrawContext context, int x, int y, int z, CallbackInfo ci) { - if (!owo$inOwoScreen) return; - RenderSystem.enableDepthTest(); - context.getMatrices().translate(0, 0, 300); - } - - @Inject(method = "drawSlotHighlight", at = @At("TAIL")) - private static void clearSlotDepth(DrawContext context, int x, int y, int z, CallbackInfo ci) { - if (!owo$inOwoScreen) return; - context.getMatrices().translate(0, 0, -300); - } + // TODO: [1.21.2-Porting] Figure out f such is still needed and how to handle such +// @Inject(method = "drawSlotHighlight", at = @At(value = "HEAD")) +// private static void enableSlotDepth(DrawContext context, int x, int y, int z, CallbackInfo ci) { +// if (!owo$inOwoScreen) return; +// RenderSystem.enableDepthTest(); +// context.getMatrices().translate(0, 0, 300); +// } +// +// @Inject(method = "drawSlotHighlight", at = @At("TAIL")) +// private static void clearSlotDepth(DrawContext context, int x, int y, int z, CallbackInfo ci) { +// if (!owo$inOwoScreen) return; +// context.getMatrices().translate(0, 0, -300); +// } @ModifyVariable(method = "mouseClicked", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/SimpleOption;getValue()Ljava/lang/Object;", ordinal = 0), ordinal = 3) private int doNoThrow(int slotId, @Local() Slot slot) { diff --git a/src/main/java/io/wispforest/owo/mixin/ui/MinecraftClientMixin.java b/src/main/java/io/wispforest/owo/mixin/ui/MinecraftClientMixin.java index 701bb951..3d04b5f6 100644 --- a/src/main/java/io/wispforest/owo/mixin/ui/MinecraftClientMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/ui/MinecraftClientMixin.java @@ -44,7 +44,7 @@ private void beforeRender(boolean tick, CallbackInfo ci) { ClientRenderCallback.BEFORE.invoker().onRender((MinecraftClient) (Object) this); } - @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/Window;swapBuffers()V", shift = At.Shift.AFTER)) + @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/Window;swapBuffers(Lnet/minecraft/client/util/tracy/TracyFrameCapturer;)V", shift = At.Shift.AFTER)) private void afterRender(boolean tick, CallbackInfo ci) { ClientRenderCallback.AFTER.invoker().onRender((MinecraftClient) (Object) this); } diff --git a/src/main/java/io/wispforest/owo/mixin/ui/TessellatorMixin.java b/src/main/java/io/wispforest/owo/mixin/ui/TessellatorMixin.java deleted file mode 100644 index f96cf53c..00000000 --- a/src/main/java/io/wispforest/owo/mixin/ui/TessellatorMixin.java +++ /dev/null @@ -1,61 +0,0 @@ -package io.wispforest.owo.mixin.ui; - -import io.wispforest.owo.mixin.BufferBuilderAccessor; -import io.wispforest.owo.util.pond.OwoTessellatorExtension; -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.Tessellator; -import net.minecraft.client.render.VertexFormat; -import org.jetbrains.annotations.Nullable; -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.CallbackInfoReturnable; - -@Mixin(Tessellator.class) -public class TessellatorMixin implements OwoTessellatorExtension { - - @Unique - private boolean owo$skipBegin = false; - - @Unique - @Nullable - private BufferBuilder bufferBuilder = null; - - @Inject(method = "begin", at = @At("HEAD"), cancellable = true) - private void skipBegin(VertexFormat.DrawMode drawMode, VertexFormat format, CallbackInfoReturnable cir) { - if(this.bufferBuilder == null) return; - - var bl = this.owo$skipBegin - && builderAccessor().getDrawMode().equals(drawMode) - && builderAccessor().getFormat().equals(format); - - if (!bl) return; - - this.owo$skipBegin = false; - - cir.setReturnValue(this.bufferBuilder); - - this.bufferBuilder = null; - } - - @Override - public void owo$skipNextBegin() { - if(this.bufferBuilder != null && builderAccessor().isBuilding()) this.owo$skipBegin = true; - } - - @Override - public void owo$setStoredBuilder(BufferBuilder builder) { - this.bufferBuilder = builder; - } - - @Override - public BufferBuilder owo$getStoredBuilder() { - return this.bufferBuilder; - } - - @Unique - private BufferBuilderAccessor builderAccessor() { - return (BufferBuilderAccessor) this.bufferBuilder; - } -} diff --git a/src/main/java/io/wispforest/owo/mixin/ui/layers/KeyboardMixin.java b/src/main/java/io/wispforest/owo/mixin/ui/layers/KeyboardMixin.java index 9fbff2fb..79d51e6c 100644 --- a/src/main/java/io/wispforest/owo/mixin/ui/layers/KeyboardMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/ui/layers/KeyboardMixin.java @@ -1,9 +1,12 @@ package io.wispforest.owo.mixin.ui.layers; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import io.wispforest.owo.ui.layers.Layers; import net.minecraft.client.Keyboard; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.screen.Screen; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -12,26 +15,14 @@ @Mixin(Keyboard.class) public class KeyboardMixin { - @Inject(method = "method_1473", at = @At("HEAD"), cancellable = true) - private static void captureScreenCharTyped(Element element, char character, int modifiers, CallbackInfo ci) { + @WrapOperation(method = "onChar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;charTyped(CI)Z")) + private boolean captureScreenCharTyped(Screen screen, char character, int modifiers, Operation original) { boolean handled = false; - for (var instance : Layers.getInstances(MinecraftClient.getInstance().currentScreen)) { + for (var instance : Layers.getInstances(screen)) { handled = instance.adapter.charTyped(character, modifiers); if (handled) break; } - if (handled) ci.cancel(); + return handled || original.call(screen, character, modifiers); } - - @Inject(method = "method_1458", at = @At("HEAD"), cancellable = true) - private static void captureScreenCharTyped(Element element, int character, int modifiers, CallbackInfo ci) { - boolean handled = false; - for (var instance : Layers.getInstances(MinecraftClient.getInstance().currentScreen)) { - handled = instance.adapter.charTyped((char) character, modifiers); - if (handled) break; - } - - if (handled) ci.cancel(); - } - } diff --git a/src/main/java/io/wispforest/owo/mixin/ui/layers/MouseMixin.java b/src/main/java/io/wispforest/owo/mixin/ui/layers/MouseMixin.java index 885fe4a5..44734bf1 100644 --- a/src/main/java/io/wispforest/owo/mixin/ui/layers/MouseMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/ui/layers/MouseMixin.java @@ -1,5 +1,7 @@ package io.wispforest.owo.mixin.ui.layers; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import io.wispforest.owo.ui.layers.Layers; import net.minecraft.client.Mouse; import net.minecraft.client.gui.screen.Screen; @@ -14,15 +16,14 @@ public class MouseMixin { @Shadow private int activeButton; - @Inject(method = "method_55795", at = @At("HEAD"), cancellable = true) - private void captureScreenMouseDrag(Screen screen, double mouseX, double mouseY, double deltaX, double deltaY, CallbackInfo ci) { + @WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;mouseDragged(DDIDD)Z")) + private boolean captureScreenMouseDrag(Screen screen, double mouseX, double mouseY, int i, double deltaX, double deltaY, Operation original) { boolean handled = false; for (var instance : Layers.getInstances(screen)) { handled = instance.adapter.mouseDragged(mouseX, mouseY, this.activeButton, deltaX, deltaY); if (handled) break; } - if (handled) ci.cancel(); + return handled || original.call(screen, mouseX, mouseY, i, deltaX, deltaY); } - } diff --git a/src/main/java/io/wispforest/owo/ops/ItemOps.java b/src/main/java/io/wispforest/owo/ops/ItemOps.java index 498d63fd..8f416f32 100644 --- a/src/main/java/io/wispforest/owo/ops/ItemOps.java +++ b/src/main/java/io/wispforest/owo/ops/ItemOps.java @@ -119,7 +119,7 @@ public static boolean decrementPlayerHandItem(PlayerEntity player, Hand hand, in public static void store(RegistryWrapper.WrapperLookup registries, ItemStack stack, NbtCompound nbt, String key) { if (stack.isEmpty()) return; - nbt.put(key, stack.encode(registries)); + nbt.put(key, stack.toNbt(registries)); } /** diff --git a/src/main/java/io/wispforest/owo/ops/WorldOps.java b/src/main/java/io/wispforest/owo/ops/WorldOps.java index b474bbf6..2e9eb3cf 100644 --- a/src/main/java/io/wispforest/owo/ops/WorldOps.java +++ b/src/main/java/io/wispforest/owo/ops/WorldOps.java @@ -15,6 +15,8 @@ import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; +import java.util.Set; + /** * A collection of common operations done on {@link World} */ @@ -114,7 +116,7 @@ public static void teleportToWorld(ServerPlayerEntity player, ServerWorld target * @param pitch The target pitch */ public static void teleportToWorld(ServerPlayerEntity player, ServerWorld target, Vec3d pos, float yaw, float pitch) { - player.teleport(target, pos.x, pos.y, pos.z, yaw, pitch); + player.teleport(target, pos.x, pos.y, pos.z, Set.of(), yaw, pitch, false); player.addExperience(0); player.getStatusEffects().forEach(effect -> { diff --git a/src/main/java/io/wispforest/owo/registration/reflect/BlockRegistryContainer.java b/src/main/java/io/wispforest/owo/registration/reflect/BlockRegistryContainer.java index 21f87efd..25787ae0 100644 --- a/src/main/java/io/wispforest/owo/registration/reflect/BlockRegistryContainer.java +++ b/src/main/java/io/wispforest/owo/registration/reflect/BlockRegistryContainer.java @@ -14,41 +14,48 @@ import java.lang.annotation.Target; import java.lang.reflect.Field; -public interface BlockRegistryContainer extends AutoRegistryContainer { - - @Override - default Registry getRegistry() { - return Registries.BLOCK; - } - - @Override - default Class getTargetFieldType() { - return Block.class; - } - - @Override - default void postProcessField(String namespace, Block value, String identifier, Field field) { - if (field.isAnnotationPresent(NoBlockItem.class)) return; - Registry.register(Registries.ITEM, Identifier.of(namespace, identifier), createBlockItem(value, identifier)); - } - - /** - * Creates a block item for the given block - * - * @param block The block to create an item for - * @param identifier The identifier the field was assigned, possibly overridden by an {@link AssignedName} - * annotation and always fully lowercase - * @return The created BlockItem instance - */ - default BlockItem createBlockItem(Block block, String identifier) { - return new BlockItem(block, new Item.Settings()); - } - - /** - * Declares that the annotated field should not - * have a block item created for it - */ - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.FIELD) - @interface NoBlockItem {} +/** + * Due to changes within 1.21.2 makes {@link AutoRegistryContainer} impossible due to requiring + * the {@link net.minecraft.registry.RegistryKey} leading to the need to supplier the key before + * fully creating the desired entry. + *

+ * Recommend using Minecraft methods for registering such entry + */ +@Deprecated(forRemoval = true) +public interface BlockRegistryContainer /*extends AutoRegistryContainer*/ { +// @Override +// default Registry getRegistry() { +// return Registries.BLOCK; +// } +// +// @Override +// default Class getTargetFieldType() { +// return Block.class; +// } +// +// @Override +// default void postProcessField(String namespace, Block value, String identifier, Field field) { +// if (field.isAnnotationPresent(NoBlockItem.class)) return; +// Registry.register(Registries.ITEM, Identifier.of(namespace, identifier), createBlockItem(value, identifier)); +// } +// +// /** +// * Creates a block item for the given block +// * +// * @param block The block to create an item for +// * @param identifier The identifier the field was assigned, possibly overridden by an {@link AssignedName} +// * annotation and always fully lowercase +// * @return The created BlockItem instance +// */ +// default BlockItem createBlockItem(Block block, String identifier) { +// return new BlockItem(block, new Item.Settings()); +// } +// +// /** +// * Declares that the annotated field should not +// * have a block item created for it +// */ +// @Retention(RetentionPolicy.RUNTIME) +// @Target(ElementType.FIELD) +// @interface NoBlockItem {} } diff --git a/src/main/java/io/wispforest/owo/registration/reflect/EntityRegistryContainer.java b/src/main/java/io/wispforest/owo/registration/reflect/EntityRegistryContainer.java index a18bf10f..bcc5d136 100644 --- a/src/main/java/io/wispforest/owo/registration/reflect/EntityRegistryContainer.java +++ b/src/main/java/io/wispforest/owo/registration/reflect/EntityRegistryContainer.java @@ -1,18 +1,21 @@ package io.wispforest.owo.registration.reflect; -import net.minecraft.entity.EntityType; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; - -public interface EntityRegistryContainer extends AutoRegistryContainer> { - - @Override - default Registry> getRegistry() { - return Registries.ENTITY_TYPE; - } - - @Override - default Class> getTargetFieldType() { - return AutoRegistryContainer.conform(EntityType.class); - } +/** + * Due to changes within 1.21.2 makes {@link AutoRegistryContainer} impossible due to requiring + * the {@link net.minecraft.registry.RegistryKey} leading to the need to supplier the key before + * fully creating the desired entry. + *

+ * Recommend using Minecraft methods for registering such entry + */ +@Deprecated(forRemoval = true) +public interface EntityRegistryContainer /*extends AutoRegistryContainer>*/ { +// @Override +// default Registry> getRegistry() { +// return Registries.ENTITY_TYPE; +// } +// +// @Override +// default Class> getTargetFieldType() { +// return AutoRegistryContainer.conform(EntityType.class); +// } } diff --git a/src/main/java/io/wispforest/owo/registration/reflect/ItemRegistryContainer.java b/src/main/java/io/wispforest/owo/registration/reflect/ItemRegistryContainer.java index 6e7aedbf..685ca082 100644 --- a/src/main/java/io/wispforest/owo/registration/reflect/ItemRegistryContainer.java +++ b/src/main/java/io/wispforest/owo/registration/reflect/ItemRegistryContainer.java @@ -4,14 +4,22 @@ import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; -public interface ItemRegistryContainer extends AutoRegistryContainer { - @Override - default Registry getRegistry() { - return Registries.ITEM; - } - - @Override - default Class getTargetFieldType() { - return Item.class; - } +/** + * Due to changes within 1.21.2 makes {@link AutoRegistryContainer} impossible due to requiring + * the {@link net.minecraft.registry.RegistryKey} leading to the need to supplier the key before + * fully creating the desired entry. + *

+ * Recommend using Minecraft methods for registering such entry + */ +@Deprecated(forRemoval = true) +public interface ItemRegistryContainer /*extends AutoRegistryContainer*/ { +// @Override +// default Registry getRegistry() { +// return Registries.ITEM; +// } +// +// @Override +// default Class getTargetFieldType() { +// return Item.class; +// } } diff --git a/src/main/java/io/wispforest/owo/shader/BlurProgram.java b/src/main/java/io/wispforest/owo/shader/BlurProgram.java index f0bc937a..0b4ee30b 100644 --- a/src/main/java/io/wispforest/owo/shader/BlurProgram.java +++ b/src/main/java/io/wispforest/owo/shader/BlurProgram.java @@ -28,7 +28,7 @@ public BlurProgram() { WindowResizeCallback.EVENT.register((client, window) -> { if (this.input == null) return; - this.input.resize(window.getFramebufferWidth(), window.getFramebufferHeight(), MinecraftClient.IS_SYSTEM_MAC); + this.input.resize(window.getFramebufferWidth(), window.getFramebufferHeight()); }); } @@ -48,7 +48,7 @@ public void use() { buffer.beginWrite(false); this.inputResolution.set((float) buffer.textureWidth, (float) buffer.textureHeight); - this.backingProgram.addSampler("InputSampler", this.input.getColorAttachment()); + this.backingProgram.addSamplerTexture("InputSampler", this.input.getColorAttachment()); super.use(); } @@ -61,6 +61,6 @@ protected void setup() { this.size = this.findUniform("Size"); var window = MinecraftClient.getInstance().getWindow(); - this.input = new SimpleFramebuffer(window.getFramebufferWidth(), window.getFramebufferHeight(), false, MinecraftClient.IS_SYSTEM_MAC); + this.input = new SimpleFramebuffer(window.getFramebufferWidth(), window.getFramebufferHeight(), false); } } \ No newline at end of file diff --git a/src/main/java/io/wispforest/owo/shader/GlProgram.java b/src/main/java/io/wispforest/owo/shader/GlProgram.java index ef690e90..dc569386 100644 --- a/src/main/java/io/wispforest/owo/shader/GlProgram.java +++ b/src/main/java/io/wispforest/owo/shader/GlProgram.java @@ -2,8 +2,9 @@ import com.mojang.blaze3d.systems.RenderSystem; import io.wispforest.owo.mixin.shader.ShaderProgramAccessor; -import net.minecraft.client.gl.GlUniform; -import net.minecraft.client.gl.ShaderProgram; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gl.*; +import net.minecraft.client.render.RenderPhase; import net.minecraft.client.render.VertexFormat; import net.minecraft.resource.ResourceFactory; import net.minecraft.util.Identifier; @@ -33,7 +34,7 @@ */ public class GlProgram { - private static final List, Consumer>> REGISTERED_PROGRAMS = new ArrayList<>(); + private static final List REGISTERED_PROGRAMS = new ArrayList<>(); /** * The actual Minecraft shader program @@ -42,20 +43,25 @@ public class GlProgram { */ protected ShaderProgram backingProgram; + protected ShaderProgramKey programKey; + public GlProgram(Identifier id, VertexFormat vertexFormat) { - REGISTERED_PROGRAMS.add(new Pair<>( - resourceFactory -> { + this.programKey = new ShaderProgramKey(id.withPrefixedPath("core/"), vertexFormat, Defines.EMPTY); + + REGISTERED_PROGRAMS.add( + () -> { try { - return new OwoShaderProgram(resourceFactory, id.toString(), vertexFormat); - } catch (IOException e) { + this.backingProgram = MinecraftClient.getInstance().getShaderLoader().getProgramToLoad(programKey); + this.setup(); + } catch (ShaderLoader.LoadException e) { throw new RuntimeException("Failed to initialized owo shader program", e); } - }, - program -> { - this.backingProgram = program; - this.setup(); } - )); + ); + } + + public RenderPhase.ShaderProgram renderPhaseProgram() { + return new RenderPhase.ShaderProgram(programKey); } /** @@ -67,7 +73,7 @@ public GlProgram(Identifier id, VertexFormat vertexFormat) { * invoking {@code use()} */ public void use() { - RenderSystem.setShader(() -> this.backingProgram); + RenderSystem.setShader(this.programKey); } protected void setup() {} @@ -84,13 +90,7 @@ protected void setup() {} } @ApiStatus.Internal - public static void forEachProgram(Consumer, Consumer>> loader) { + public static void forEachProgram(Consumer loader) { REGISTERED_PROGRAMS.forEach(loader); } - - public static class OwoShaderProgram extends ShaderProgram { - private OwoShaderProgram(ResourceFactory factory, String name, VertexFormat format) throws IOException { - super(factory, name, format); - } - } } diff --git a/src/main/java/io/wispforest/owo/ui/base/BaseOwoToast.java b/src/main/java/io/wispforest/owo/ui/base/BaseOwoToast.java index f3862060..337cf648 100644 --- a/src/main/java/io/wispforest/owo/ui/base/BaseOwoToast.java +++ b/src/main/java/io/wispforest/owo/ui/base/BaseOwoToast.java @@ -4,6 +4,7 @@ import io.wispforest.owo.ui.core.ParentComponent; import io.wispforest.owo.ui.core.Size; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.toast.Toast; import net.minecraft.client.toast.ToastManager; @@ -33,15 +34,33 @@ protected BaseOwoToast(Supplier rootComponent, Duration timeout) { this(rootComponent, VisibilityPredicate.timeout(timeout)); } + private Visibility visibility = Visibility.HIDE; + @Override - public Visibility draw(DrawContext context, ToastManager manager, long startTime) { - var client = MinecraftClient.getInstance(); + public void update(ToastManager manager, long time) { + final var delta = MinecraftClient.getInstance().getRenderTickCounter().getLastFrameDuration(); + + var client = manager.getClient(); + var window = client.getWindow(); + + int mouseX = -1000; //(int)(client.mouse.getX() * (double) window.getScaledWidth() / (double) window.getWidth()); + int mouseY = -1000; //(int)(client.mouse.getY() * (double) window.getScaledHeight() / (double) window.getHeight()); + + this.rootComponent.update(delta, mouseX, mouseY); + + this.visibility = this.visibilityPredicate.test(this, time); + } + @Override + public Visibility getVisibility() { + return this.visibility; + } + + @Override + public void draw(DrawContext context, TextRenderer textRenderer, long startTime) { var tickCounter = MinecraftClient.getInstance().getRenderTickCounter(); this.rootComponent.draw(OwoUIDrawContext.of(context), -1000, -1000, tickCounter.getTickDelta(false), tickCounter.getLastFrameDuration()); - - return this.visibilityPredicate.test(this, startTime); } @Override diff --git a/src/main/java/io/wispforest/owo/ui/base/BaseOwoTooltipComponent.java b/src/main/java/io/wispforest/owo/ui/base/BaseOwoTooltipComponent.java index 3bbe65b3..73fc5817 100644 --- a/src/main/java/io/wispforest/owo/ui/base/BaseOwoTooltipComponent.java +++ b/src/main/java/io/wispforest/owo/ui/base/BaseOwoTooltipComponent.java @@ -25,9 +25,7 @@ protected BaseOwoTooltipComponent(Supplier components) { } @Override - public void drawItems(TextRenderer textRenderer, int x, int y, DrawContext context) { - var client = MinecraftClient.getInstance(); - + public void drawItems(TextRenderer textRenderer, int x, int y, int width, int height, DrawContext context) { var tickCounter = MinecraftClient.getInstance().getRenderTickCounter(); this.rootComponent.moveTo(x, y); @@ -35,7 +33,7 @@ public void drawItems(TextRenderer textRenderer, int x, int y, DrawContext conte } @Override - public int getHeight() { + public int getHeight(TextRenderer textRenderer) { return this.rootComponent.fullSize().height(); } diff --git a/src/main/java/io/wispforest/owo/ui/base/BaseParentComponent.java b/src/main/java/io/wispforest/owo/ui/base/BaseParentComponent.java index c44a5f8a..0cfa662a 100644 --- a/src/main/java/io/wispforest/owo/ui/base/BaseParentComponent.java +++ b/src/main/java/io/wispforest/owo/ui/base/BaseParentComponent.java @@ -340,7 +340,7 @@ protected void mountChild(@Nullable Component child, Consumer layoutF protected void drawChildren(OwoUIDrawContext context, int mouseX, int mouseY, float partialTicks, float delta, List children) { if (!this.allowOverflow) { var padding = this.padding.get(); - ScissorStack.push(this.x + padding.left(), this.y + padding.top(), this.width - padding.horizontal(), this.height - padding.vertical(), context.getMatrices()); + ScissorStack.push(this.x + padding.left(), this.y + padding.top(), this.width - padding.horizontal(), this.height - padding.vertical(), context); } var focusHandler = this.focusHandler(); diff --git a/src/main/java/io/wispforest/owo/ui/component/BlockComponent.java b/src/main/java/io/wispforest/owo/ui/component/BlockComponent.java index c99307b8..9801df17 100644 --- a/src/main/java/io/wispforest/owo/ui/component/BlockComponent.java +++ b/src/main/java/io/wispforest/owo/ui/component/BlockComponent.java @@ -47,7 +47,8 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial context.getMatrices().translate(-.5, -.5, -.5); - RenderSystem.runAsFancy(() -> { + // TODO: [1.21.2-Porting] Figure out if this is still needed or not + //RenderSystem.runAsFancy(() -> { final var vertexConsumers = client.getBufferBuilders().getEntityVertexConsumers(); if (this.state.getRenderType() != BlockRenderType.ENTITYBLOCK_ANIMATED) { this.client.getBlockRenderManager().renderBlockAsEntity( @@ -66,7 +67,7 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial RenderSystem.setShaderLights(new Vector3f(-1.5f, -.5f, 0), new Vector3f(0, -1, 0)); vertexConsumers.draw(); DiffuseLighting.enableGuiDepthLighting(); - }); + //}); context.getMatrices().pop(); } @@ -94,7 +95,7 @@ public static BlockComponent parse(Element element) { UIParsing.expectAttributes(element, "state"); try { - var result = BlockArgumentParser.block(Registries.BLOCK.getReadOnlyWrapper(), element.getAttribute("state"), true); + var result = BlockArgumentParser.block(Registries.BLOCK, element.getAttribute("state"), true); return Components.block(result.blockState(), result.nbt()); } catch (CommandSyntaxException cse) { throw new UIModelParsingException("Invalid block state", cse); diff --git a/src/main/java/io/wispforest/owo/ui/component/ButtonComponent.java b/src/main/java/io/wispforest/owo/ui/component/ButtonComponent.java index 5ca3cf4f..3a3250d5 100644 --- a/src/main/java/io/wispforest/owo/ui/component/ButtonComponent.java +++ b/src/main/java/io/wispforest/owo/ui/component/ButtonComponent.java @@ -15,6 +15,7 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.tooltip.HoveredTooltipPositioner; import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.render.RenderLayer; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import org.w3c.dom.Element; @@ -136,7 +137,7 @@ static Renderer texture(Identifier texture, int u, int v, int textureWidth, int } RenderSystem.enableDepthTest(); - context.drawTexture(texture, button.getX(), button.getY(), u, renderV, button.width, button.height, textureWidth, textureHeight); + context.drawTexture(RenderLayer::getGuiTextured, texture, button.getX(), button.getY(), u, renderV, button.width, button.height, textureWidth, textureHeight); }; } diff --git a/src/main/java/io/wispforest/owo/ui/component/DropdownComponent.java b/src/main/java/io/wispforest/owo/ui/component/DropdownComponent.java index f0a42b98..23b6359f 100644 --- a/src/main/java/io/wispforest/owo/ui/component/DropdownComponent.java +++ b/src/main/java/io/wispforest/owo/ui/component/DropdownComponent.java @@ -9,6 +9,7 @@ import io.wispforest.owo.ui.util.UISounds; import net.fabricmc.fabric.api.client.screen.v1.ScreenMouseEvents; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.render.RenderLayer; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; @@ -197,7 +198,7 @@ protected void parseAndApplyEntries(Element container) { } protected static void drawIconFromTexture(OwoUIDrawContext context, ParentComponent dropdown, int y, int u, int v) { - context.drawTexture(ICONS_TEXTURE, + context.drawTexture(RenderLayer::getGuiTextured, ICONS_TEXTURE, dropdown.x() + dropdown.width() - dropdown.padding().get().right() - 10, y, u, v, 9, 9, diff --git a/src/main/java/io/wispforest/owo/ui/component/EntityComponent.java b/src/main/java/io/wispforest/owo/ui/component/EntityComponent.java index cb0b4024..9c925988 100644 --- a/src/main/java/io/wispforest/owo/ui/component/EntityComponent.java +++ b/src/main/java/io/wispforest/owo/ui/component/EntityComponent.java @@ -24,6 +24,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.SpawnReason; import net.minecraft.entity.player.PlayerModelPart; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.StringNbtReader; @@ -72,7 +73,7 @@ protected EntityComponent(Sizing sizing, EntityType type, @Nullable NbtCompou this.dispatcher = client.getEntityRenderDispatcher(); this.entityBuffers = client.getBufferBuilders().getEntityVertexConsumers(); - this.entity = type.create(client.world); + this.entity = type.create(client.world, SpawnReason.BREEDING); if (nbt != null) entity.readNbt(nbt); entity.updatePosition(client.player.getX(), client.player.getY(), client.player.getZ()); @@ -117,7 +118,7 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial RenderSystem.setShaderLights(new Vector3f(.15f, 1, 0), new Vector3f(.15f, -1, 0)); this.dispatcher.setRenderShadows(false); - this.dispatcher.render(this.entity, 0, 0, 0, 0, 0, matrices, this.entityBuffers, LightmapTextureManager.MAX_LIGHT_COORDINATE); + this.dispatcher.render(this.entity, 0, 0, 0, 0, matrices, this.entityBuffers, LightmapTextureManager.MAX_LIGHT_COORDINATE); this.dispatcher.setRenderShadows(true); this.entityBuffers.draw(); DiffuseLighting.enableGuiDepthLighting(); @@ -228,7 +229,7 @@ public void parseProperties(UIModel model, Element element, Map public static EntityComponent parse(Element element) { UIParsing.expectAttributes(element, "type"); var entityId = UIParsing.parseIdentifier(element.getAttributeNode("type")); - var entityType = Registries.ENTITY_TYPE.getOrEmpty(entityId).orElseThrow(() -> new UIModelParsingException("Unknown entity type " + entityId)); + var entityType = Registries.ENTITY_TYPE.getOptionalValue(entityId).orElseThrow(() -> new UIModelParsingException("Unknown entity type " + entityId)); NbtCompound nbt = null; if (element.hasAttribute("nbt")) { @@ -255,7 +256,7 @@ protected RenderablePlayerEntity(GameProfile profile) { profile, new WorldSession(TelemetrySender.NOOP, false, Duration.ZERO, ""), MinecraftClient.getInstance().world.getRegistryManager().toImmutable(), MinecraftClient.getInstance().world.getEnabledFeatures(), - "Wisp Forest Enterprises", null, null, Map.of(), null, false, Map.of(), ServerLinks.EMPTY + "Wisp Forest Enterprises", null, null, Map.of(), null, Map.of(), ServerLinks.EMPTY )), null, null, false, false ); diff --git a/src/main/java/io/wispforest/owo/ui/component/ItemComponent.java b/src/main/java/io/wispforest/owo/ui/component/ItemComponent.java index a0f8101b..6a7586ac 100644 --- a/src/main/java/io/wispforest/owo/ui/component/ItemComponent.java +++ b/src/main/java/io/wispforest/owo/ui/component/ItemComponent.java @@ -17,7 +17,7 @@ import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.item.ItemRenderer; -import net.minecraft.client.render.model.json.ModelTransformationMode; +import net.minecraft.item.ModelTransformationMode; import net.minecraft.command.argument.ItemStringReader; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; @@ -95,7 +95,7 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial matrices.pop(); if (this.showOverlay) { - context.drawItemInSlot(client.textRenderer, this.stack, this.x, this.y); + context.drawStackOverlay(client.textRenderer, this.stack, this.x, this.y); } if (notSideLit) { DiffuseLighting.enableGuiDepthLighting(); @@ -185,13 +185,13 @@ public void parseProperties(UIModel model, Element element, Map UIParsing.apply(children, "item", UIParsing::parseIdentifier, itemId -> { Owo.debugWarn(Owo.LOGGER, "Deprecated property populated on item component - migrate to instead"); - var item = Registries.ITEM.getOrEmpty(itemId).orElseThrow(() -> new UIModelParsingException("Unknown item " + itemId)); + var item = Registries.ITEM.getOptionalValue(itemId).orElseThrow(() -> new UIModelParsingException("Unknown item " + itemId)); this.stack(item.getDefaultStack()); }); UIParsing.apply(children, "stack", $ -> $.getTextContent().strip(), stackString -> { try { - var result = new ItemStringReader(RegistryWrapper.WrapperLookup.of(Stream.of(Registries.ITEM.getReadOnlyWrapper()))) + var result = new ItemStringReader(RegistryWrapper.WrapperLookup.of(Stream.of(Registries.ITEM))) .consume(new StringReader(stackString)); var stack = new ItemStack(result.item()); diff --git a/src/main/java/io/wispforest/owo/ui/component/LabelComponent.java b/src/main/java/io/wispforest/owo/ui/component/LabelComponent.java index 6da5787f..8450d407 100644 --- a/src/main/java/io/wispforest/owo/ui/component/LabelComponent.java +++ b/src/main/java/io/wispforest/owo/ui/component/LabelComponent.java @@ -198,7 +198,7 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial final int lambdaX = x; final int lambdaY = y; - context.draw(() -> { + context.draw((vertexConsumerProvider) -> { for (int i = 0; i < this.wrappedText.size(); i++) { var renderText = this.wrappedText.get(i); int renderX = lambdaX; diff --git a/src/main/java/io/wispforest/owo/ui/component/SlimSliderComponent.java b/src/main/java/io/wispforest/owo/ui/component/SlimSliderComponent.java index 736c5a62..60a231b9 100644 --- a/src/main/java/io/wispforest/owo/ui/component/SlimSliderComponent.java +++ b/src/main/java/io/wispforest/owo/ui/component/SlimSliderComponent.java @@ -13,6 +13,7 @@ import io.wispforest.owo.util.EventStream; import io.wispforest.owo.util.Observable; import net.minecraft.client.gui.tooltip.TooltipComponent; +import net.minecraft.client.render.RenderLayer; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -74,10 +75,10 @@ protected int determineVerticalContentSize(Sizing sizing) { public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partialTicks, float delta) { if (this.axis == Axis.HORIZONTAL) { NinePatchTexture.draw(TRACK_TEXTURE, context, this.x + 1, this.y + 3, this.width - 2, 3); - context.drawTexture(TEXTURE, (int) (this.x + (this.width - 4) * this.value.get()), this.y + 1, 4, 7, 0, 3, 4, 7, 16, 16); + context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, (int) (this.x + (this.width - 4) * this.value.get()), this.y + 1, 4, 7, 0, 3, 4, 7, 16, 16); } else { NinePatchTexture.draw(TRACK_TEXTURE, context, this.x + 3, this.y + 1, 3, this.height - 2); - context.drawTexture(TEXTURE, this.x + 1, (int) (this.y + (this.height - 4) * this.value.get()), 7, 4, 4, 3, 7, 4, 16, 16); + context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.x + 1, (int) (this.y + (this.height - 4) * this.value.get()), 7, 4, 4, 3, 7, 4, 16, 16); } } diff --git a/src/main/java/io/wispforest/owo/ui/component/SmallCheckboxComponent.java b/src/main/java/io/wispforest/owo/ui/component/SmallCheckboxComponent.java index 01e5b65d..c3491bf3 100644 --- a/src/main/java/io/wispforest/owo/ui/component/SmallCheckboxComponent.java +++ b/src/main/java/io/wispforest/owo/ui/component/SmallCheckboxComponent.java @@ -12,6 +12,7 @@ import io.wispforest.owo.util.EventStream; import io.wispforest.owo.util.Observable; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.RenderLayer; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import org.jetbrains.annotations.Nullable; @@ -47,9 +48,9 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial context.drawText(MinecraftClient.getInstance().textRenderer, this.label.get(), this.x + 13 + 2, this.y + 3, Color.WHITE.argb(), this.labelShadow); } - context.drawTexture(TEXTURE, this.x, this.y, 13, 13, 0, 0, 13, 13, 32, 16); + context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.x, this.y, 13, 13, 0, 0, 13, 13, 32, 16); if (this.checked) { - context.drawTexture(TEXTURE, this.x, this.y, 13, 13, 16, 0, 13, 13, 32, 16); + context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.x, this.y, 13, 13, 16, 0, 13, 13, 32, 16); } } diff --git a/src/main/java/io/wispforest/owo/ui/component/SpriteComponent.java b/src/main/java/io/wispforest/owo/ui/component/SpriteComponent.java index 676c1767..a4285ef2 100644 --- a/src/main/java/io/wispforest/owo/ui/component/SpriteComponent.java +++ b/src/main/java/io/wispforest/owo/ui/component/SpriteComponent.java @@ -3,10 +3,12 @@ import com.mojang.blaze3d.systems.RenderSystem; import io.wispforest.owo.ui.base.BaseComponent; import io.wispforest.owo.ui.core.OwoUIDrawContext; +import io.wispforest.owo.ui.core.OwoUIRenderLayers; import io.wispforest.owo.ui.core.Sizing; import io.wispforest.owo.ui.parsing.UIModel; import io.wispforest.owo.ui.parsing.UIParsing; import io.wispforest.owo.ui.util.SpriteUtilInvoker; +import net.minecraft.client.render.RenderLayer; import net.minecraft.client.texture.Sprite; import net.minecraft.client.util.SpriteIdentifier; import org.w3c.dom.Element; @@ -41,7 +43,7 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial RenderSystem.defaultBlendFunc(); } - context.drawSprite(this.x, this.y, 0, this.width, this.height, this.sprite); + context.drawSprite(identifier -> OwoUIRenderLayers.getGuiTextured(identifier, this.blend), this.sprite, this.x, this.y, this.width, this.height); if (this.blend) { RenderSystem.disableBlend(); diff --git a/src/main/java/io/wispforest/owo/ui/component/TextureComponent.java b/src/main/java/io/wispforest/owo/ui/component/TextureComponent.java index 50087e93..d812642f 100644 --- a/src/main/java/io/wispforest/owo/ui/component/TextureComponent.java +++ b/src/main/java/io/wispforest/owo/ui/component/TextureComponent.java @@ -2,12 +2,10 @@ import com.mojang.blaze3d.systems.RenderSystem; import io.wispforest.owo.ui.base.BaseComponent; -import io.wispforest.owo.ui.core.AnimatableProperty; -import io.wispforest.owo.ui.core.OwoUIDrawContext; -import io.wispforest.owo.ui.core.PositionedRectangle; -import io.wispforest.owo.ui.core.Sizing; +import io.wispforest.owo.ui.core.*; import io.wispforest.owo.ui.parsing.UIModel; import io.wispforest.owo.ui.parsing.UIParsing; +import net.minecraft.client.render.RenderLayer; import net.minecraft.util.Identifier; import org.w3c.dom.Element; @@ -70,7 +68,8 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial int bottomEdge = Math.min(visibleArea.y() + visibleArea.height(), regionHeight); int rightEdge = Math.min(visibleArea.x() + visibleArea.width(), regionWidth); - context.drawTexture(this.texture, + context.drawTexture(identifier -> OwoUIRenderLayers.getGuiTextured(identifier, this.blend), + this.texture, visibleArea.x(), visibleArea.y(), rightEdge - visibleArea.x(), diff --git a/src/main/java/io/wispforest/owo/ui/container/RenderEffectWrapper.java b/src/main/java/io/wispforest/owo/ui/container/RenderEffectWrapper.java index a89a7b2c..2c6d41ed 100644 --- a/src/main/java/io/wispforest/owo/ui/container/RenderEffectWrapper.java +++ b/src/main/java/io/wispforest/owo/ui/container/RenderEffectWrapper.java @@ -10,6 +10,7 @@ import io.wispforest.owo.ui.util.ScissorStack; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gl.Framebuffer; +import net.minecraft.client.gl.ShaderProgramKeys; import net.minecraft.client.gl.SimpleFramebuffer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.BufferRenderer; @@ -60,13 +61,13 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial var window = MinecraftClient.getInstance().getWindow(); while (drawDepth > FRAMEBUFFERS.size()) { - FRAMEBUFFERS.add(new SimpleFramebuffer(window.getFramebufferWidth(), window.getFramebufferHeight(), true, MinecraftClient.IS_SYSTEM_MAC)); + FRAMEBUFFERS.add(new SimpleFramebuffer(window.getFramebufferWidth(), window.getFramebufferHeight(), true)); } var previousFramebuffer = GlStateManager.getBoundFramebuffer(); var framebuffer = FRAMEBUFFERS.get(drawDepth - 1); framebuffer.setClearColor(0, 0, 0, 0); - ScissorStack.drawUnclipped(() -> framebuffer.clear(MinecraftClient.IS_SYSTEM_MAC)); + ScissorStack.drawUnclipped(framebuffer::clear); framebuffer.beginWrite(false); this.drawChildren(context, mouseX, mouseY, partialTicks, delta, this.childView); @@ -87,7 +88,7 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial buffer.vertex(matrix, 0, 0, 0).texture(0, 1).color(1f, 1f, 1f, 1f); RenderSystem.setShaderTexture(0, framebuffer.getColorAttachment()); - RenderSystem.setShader(GameRenderer::getPositionTexColorProgram); + RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX_COLOR); BufferRenderer.drawWithGlobalProgram(buffer.end()); while (iter.hasPrevious()) { @@ -124,7 +125,7 @@ public void clearEffects() { static { WindowResizeCallback.EVENT.register((client, window) -> { FRAMEBUFFERS.forEach(framebuffer -> { - framebuffer.resize(window.getFramebufferWidth(), window.getFramebufferHeight(), MinecraftClient.IS_SYSTEM_MAC); + framebuffer.resize(window.getFramebufferWidth(), window.getFramebufferHeight()); }); }); } diff --git a/src/main/java/io/wispforest/owo/ui/core/OwoUIDrawContext.java b/src/main/java/io/wispforest/owo/ui/core/OwoUIDrawContext.java index 3d4c11c6..0fc3a8bf 100644 --- a/src/main/java/io/wispforest/owo/ui/core/OwoUIDrawContext.java +++ b/src/main/java/io/wispforest/owo/ui/core/OwoUIDrawContext.java @@ -44,35 +44,23 @@ private OwoUIDrawContext(MinecraftClient client, VertexConsumerProvider.Immediat } public static OwoUIDrawContext of(DrawContext context) { - var owoContext = new OwoUIDrawContext(MinecraftClient.getInstance(), context.getVertexConsumers()); + var owoContext = new OwoUIDrawContext(MinecraftClient.getInstance(), ((DrawContextInvoker)context).owo$vertexConsumers()); ((DrawContextInvoker) owoContext).owo$setScissorStack(((DrawContextInvoker) context).owo$getScissorStack()); ((DrawContextInvoker) owoContext).owo$setMatrices(((DrawContextInvoker) context).owo$getMatrices()); return owoContext; } - public static UtilityScreen utilityScreen() { - return UtilityScreen.get(); - } - - public void recordQuads() { - recording = true; + public VertexConsumerProvider.Immediate vertexConsumers() { + return ((DrawContextInvoker) this).owo$vertexConsumers(); } - public boolean recording() { - return recording; + public static UtilityScreen utilityScreen() { + return UtilityScreen.get(); } - public void submitQuads() { - recording = false; - - var extension = ((OwoTessellatorExtension) Tessellator.getInstance()); - - var buffer = extension.owo$getStoredBuilder(); - - extension.owo$setStoredBuilder(null); - - BufferRenderer.drawWithGlobalProgram(buffer.end()); + public void drawRectOutline(int x, int y, int width, int height, int color) { + drawRectOutline(RenderLayer.getGui(), x, y, width, height, color); } /** @@ -84,12 +72,16 @@ public void submitQuads() { * @param height The height of the rectangle * @param color The color of the rectangle */ - public void drawRectOutline(int x, int y, int width, int height, int color) { - this.fill(x, y, x + width, y + 1, color); - this.fill(x, y + height - 1, x + width, y + height, color); + public void drawRectOutline(RenderLayer layer, int x, int y, int width, int height, int color) { + this.fill(layer, x, y, x + width, y + 1, color); + this.fill(layer, x, y + height - 1, x + width, y + height, color); - this.fill(x, y + 1, x + 1, y + height - 1, color); - this.fill(x + width - 1, y + 1, x + width, y + height - 1, color); + this.fill(layer, x, y + 1, x + 1, y + height - 1, color); + this.fill(layer, x + width - 1, y + 1, x + width, y + height - 1, color); + } + + public void drawGradientRect(int x, int y, int width, int height, int topLeftColor, int topRightColor, int bottomRightColor, int bottomLeftColor) { + this.drawGradientRect(RenderLayer.getGui(), x, y, width, height, topLeftColor, topRightColor, bottomRightColor, bottomLeftColor); } /** @@ -104,22 +96,14 @@ public void drawRectOutline(int x, int y, int width, int height, int color) { * @param bottomRightColor The color at the rectangle's bottom right corner * @param bottomLeftColor The color at the rectangle's bottom left corner */ - public void drawGradientRect(int x, int y, int width, int height, int topLeftColor, int topRightColor, int bottomRightColor, int bottomLeftColor) { - var buffer = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + public void drawGradientRect(RenderLayer layer, int x, int y, int width, int height, int topLeftColor, int topRightColor, int bottomRightColor, int bottomLeftColor) { + var buffer = vertexConsumers().getBuffer(layer); var matrix = this.getMatrices().peek().getPositionMatrix(); buffer.vertex(matrix, x + width, y, 0).color(topRightColor); buffer.vertex(matrix, x, y, 0).color(topLeftColor); buffer.vertex(matrix, x, y + height, 0).color(bottomLeftColor); buffer.vertex(matrix, x + width, y + height, 0).color(bottomRightColor); - - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - - RenderSystem.setShader(GameRenderer::getPositionColorProgram); - BufferRenderer.drawWithGlobalProgram(buffer.end()); - - RenderSystem.disableBlend(); } /** @@ -137,16 +121,13 @@ public void drawPanel(int x, int y, int width, int height, boolean dark) { } public void drawSpectrum(int x, int y, int width, int height, boolean vertical) { - var buffer = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + var buffer = this.vertexConsumers().getBuffer(OwoUIRenderLayers.GUI_SPECTRUM); var matrix = this.getMatrices().peek().getPositionMatrix(); buffer.vertex(matrix, x, y, 0).color(1f, 1f, 1f, 1f); buffer.vertex(matrix, x, y + height, 0).color(vertical ? 0f : 1f, 1f, 1f, 1f); buffer.vertex(matrix, x + width, y + height, 0).color(0f, 1f, 1f, 1f); buffer.vertex(matrix, x + width, y, 0).color(vertical ? 1f : 0f, 1f, 1f, 1f); - - OwoClient.HSV_PROGRAM.use(); - BufferRenderer.drawWithGlobalProgram(buffer.end()); } public void drawText(Text text, float x, float y, float scale, int color) { @@ -176,11 +157,14 @@ public void drawText(Text text, float x, float y, float scale, int color, TextAn public enum TextAnchor { TOP_RIGHT, BOTTOM_RIGHT, TOP_LEFT, BOTTOM_LEFT } - public void drawLine(int x1, int y1, int x2, int y2, double thiccness, Color color) { + drawLine(RenderLayer.getGui(), x1, y1, x2, y2, thiccness, color); + } + + public void drawLine(RenderLayer layer, int x1, int y1, int x2, int y2, double thiccness, Color color) { var offset = new Vector2d(x2 - x1, y2 - y1).perpendicular().normalize().mul(thiccness * .5d); - var buffer = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + var buffer = vertexConsumers().getBuffer(layer); var matrix = this.getMatrices().peek().getPositionMatrix(); int vColor = color.argb(); @@ -188,22 +172,24 @@ public void drawLine(int x1, int y1, int x2, int y2, double thiccness, Color col buffer.vertex(matrix, (float) (x1 - offset.x), (float) (y1 - offset.y), 0).color(vColor); buffer.vertex(matrix, (float) (x2 - offset.x), (float) (y2 - offset.y), 0).color(vColor); buffer.vertex(matrix, (float) (x2 + offset.x), (float) (y2 + offset.y), 0).color(vColor); - - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.setShader(GameRenderer::getPositionColorProgram); - - BufferRenderer.drawWithGlobalProgram(buffer.end()); } public void drawCircle(int centerX, int centerY, int segments, double radius, Color color) { - drawCircle(centerX, centerY, 0, 360, segments, radius, color); + drawCircle(OwoUIRenderLayers.GUI_TRIANGLE_FAN, centerX, centerY, segments, radius, color); } public void drawCircle(int centerX, int centerY, double angleFrom, double angleTo, int segments, double radius, Color color) { + drawCircle(OwoUIRenderLayers.GUI_TRIANGLE_FAN, centerX, centerY, angleFrom, angleTo, segments, radius, color); + } + + public void drawCircle(RenderLayer renderLayer, int centerX, int centerY, int segments, double radius, Color color) { + drawCircle(renderLayer, centerX, centerY, 0, 360, segments, radius, color); + } + + public void drawCircle(RenderLayer renderLayer, int centerX, int centerY, double angleFrom, double angleTo, int segments, double radius, Color color) { Preconditions.checkArgument(angleFrom < angleTo, "angleFrom must be less than angleTo"); - var buffer = Tessellator.getInstance().begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION_COLOR); + var buffer = vertexConsumers().getBuffer(renderLayer); var matrix = this.getMatrices().peek().getPositionMatrix(); double angleStep = Math.toRadians(angleTo - angleFrom) / segments; @@ -216,23 +202,25 @@ public void drawCircle(int centerX, int centerY, double angleFrom, double angleT buffer.vertex(matrix, (float) (centerX - Math.cos(theta) * radius), (float) (centerY - Math.sin(theta) * radius), 0) .color(vColor); } - - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.setShader(GameRenderer::getPositionColorProgram); - - BufferRenderer.drawWithGlobalProgram(buffer.end()); } public void drawRing(int centerX, int centerY, int segments, double innerRadius, double outerRadius, Color innerColor, Color outerColor) { - drawRing(centerX, centerY, 0d, 360d, segments, innerRadius, outerRadius, innerColor, outerColor); + drawRing(OwoUIRenderLayers.GUI_TRIANGLE_STRIP, centerX, centerY, segments, innerRadius, outerRadius, innerColor, outerColor); } public void drawRing(int centerX, int centerY, double angleFrom, double angleTo, int segments, double innerRadius, double outerRadius, Color innerColor, Color outerColor) { + drawRing(OwoUIRenderLayers.GUI_TRIANGLE_STRIP, centerX, centerY, angleFrom, angleTo, segments, innerRadius, outerRadius, innerColor, outerColor); + } + + public void drawRing(RenderLayer renderLayer, int centerX, int centerY, int segments, double innerRadius, double outerRadius, Color innerColor, Color outerColor) { + drawRing(renderLayer, centerX, centerY, 0d, 360d, segments, innerRadius, outerRadius, innerColor, outerColor); + } + + public void drawRing(RenderLayer renderLayer, int centerX, int centerY, double angleFrom, double angleTo, int segments, double innerRadius, double outerRadius, Color innerColor, Color outerColor) { Preconditions.checkArgument(angleFrom < angleTo, "angleFrom must be less than angleTo"); Preconditions.checkArgument(innerRadius < outerRadius, "innerRadius must be less than outerRadius"); - var buffer = Tessellator.getInstance().begin(VertexFormat.DrawMode.TRIANGLE_STRIP, VertexFormats.POSITION_COLOR); + var buffer = vertexConsumers().getBuffer(renderLayer); var matrix = this.getMatrices().peek().getPositionMatrix(); double angleStep = Math.toRadians(angleTo - angleFrom) / segments; @@ -247,20 +235,22 @@ public void drawRing(int centerX, int centerY, double angleFrom, double angleTo, buffer.vertex(matrix, (float) (centerX - Math.cos(theta) * innerRadius), (float) (centerY - Math.sin(theta) * innerRadius), 0) .color(inColor); } - - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.setShader(GameRenderer::getPositionColorProgram); - - BufferRenderer.drawWithGlobalProgram(buffer.end()); } public void drawTooltip(TextRenderer textRenderer, int x, int y, List components) { - ((DrawContextInvoker) this).owo$renderTooltipFromComponents(textRenderer, components, x, y, HoveredTooltipPositioner.INSTANCE); + drawTooltip(textRenderer, x, y, components, null); + } + + public void drawTooltip(TextRenderer textRenderer, int x, int y, List components, @Nullable Identifier texture) { + ((DrawContextInvoker) this).owo$renderTooltipFromComponents(textRenderer, components, x, y, HoveredTooltipPositioner.INSTANCE, texture); } // --- debug rendering --- + public void drawInsets(int x, int y, int width, int height, Insets insets, int color) { + drawInsets(RenderLayer.getGui(), x, y, width, height, insets, color); + } + /** * Draw the area around the given rectangle which * the given insets describe @@ -272,12 +262,12 @@ public void drawTooltip(TextRenderer textRenderer, int x, int y, List GUI_TEXTURED = Util.memoize( + (texture, bl) -> RenderLayer.of( + "gui_textured", + VertexFormats.POSITION_TEXTURE_COLOR, + VertexFormat.DrawMode.QUADS, + 786432, + RenderLayer.MultiPhaseParameters.builder() + .texture(new RenderPhase.Texture(texture, TriState.FALSE, false)) + .program(POSITION_TEXTURE_COLOR_PROGRAM) + .transparency(bl ? TRANSLUCENT_TRANSPARENCY : NO_TRANSPARENCY) + .depthTest(LEQUAL_DEPTH_TEST) + .build(false) + ) + ); + + public static RenderLayer getGuiTextured(Identifier texture, boolean blend) { + return GUI_TEXTURED.apply(texture, blend); + } + +} diff --git a/src/main/java/io/wispforest/owo/ui/core/Size.java b/src/main/java/io/wispforest/owo/ui/core/Size.java index ab0f8f40..e2fb83f1 100644 --- a/src/main/java/io/wispforest/owo/ui/core/Size.java +++ b/src/main/java/io/wispforest/owo/ui/core/Size.java @@ -1,5 +1,8 @@ package io.wispforest.owo.ui.core; +import io.wispforest.endec.Endec; +import io.wispforest.endec.StructEndec; +import io.wispforest.endec.impl.StructEndecBuilder; import org.jetbrains.annotations.ApiStatus; /** @@ -11,6 +14,8 @@ */ public record Size(int width, int height) { + public static final Endec ENDEC = createEndec("width", "height"); + private static final Size ZERO = new Size(0, 0); @ApiStatus.Internal @@ -31,4 +36,12 @@ public static Size square(int sideLength) { public static Size zero() { return ZERO; } + + public static StructEndec createEndec(String widthName, String heightName) { + return StructEndecBuilder.of( + Endec.INT.fieldOf(widthName, Size::width), + Endec.INT.fieldOf(heightName, Size::height), + Size::of + ); + } } diff --git a/src/main/java/io/wispforest/owo/ui/core/Surface.java b/src/main/java/io/wispforest/owo/ui/core/Surface.java index d2336c14..4325db9b 100644 --- a/src/main/java/io/wispforest/owo/ui/core/Surface.java +++ b/src/main/java/io/wispforest/owo/ui/core/Surface.java @@ -14,6 +14,7 @@ import net.minecraft.client.render.*; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; +import org.jetbrains.annotations.Nullable; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -41,14 +42,13 @@ public interface Surface { Surface OPTIONS_BACKGROUND = Surface.panorama(ScreenAccessor.owo$ROTATING_PANORAMA_RENDERER(), false) .and(Surface.blur(5, 10)); - Surface TOOLTIP = (context, component) -> { - context.draw(() -> { - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); + Surface TOOLTIP = tooltip(null); - TooltipBackgroundRenderer.render(context, component.x() + 4, component.y() + 4, component.width() - 8, component.height() - 8, 0); - }); - }; + static Surface tooltip(@Nullable Identifier texture) { + return (context, component) -> { + TooltipBackgroundRenderer.render(context, component.x() + 4, component.y() + 4, component.width() - 8, component.height() - 8, 0, texture); + }; + } static Surface blur(float quality, float size) { return (context, component) -> { @@ -120,7 +120,7 @@ static Surface outline(int color) { static Surface tiled(Identifier texture, int textureWidth, int textureHeight) { return (context, component) -> { - context.drawTexture(texture, component.x(), component.y(), 0, 0, component.width(), component.height(), textureWidth, textureHeight); + context.drawTexture(RenderLayer::getGuiTextured, texture, component.x(), component.y(), 0, 0, component.width(), component.height(), textureWidth, textureHeight); }; } diff --git a/src/main/java/io/wispforest/owo/ui/parsing/UIModelLoader.java b/src/main/java/io/wispforest/owo/ui/parsing/UIModelLoader.java index eb174179..923b8a55 100644 --- a/src/main/java/io/wispforest/owo/ui/parsing/UIModelLoader.java +++ b/src/main/java/io/wispforest/owo/ui/parsing/UIModelLoader.java @@ -55,7 +55,7 @@ public class UIModelLoader implements SynchronousResourceReloader, IdentifiableR try (var stream = Files.newInputStream(HOT_RELOAD_LOCATIONS.get(id))) { return UIModel.load(stream); } catch (ParserConfigurationException | IOException | SAXException e) { - MinecraftClient.getInstance().player.sendMessage(TextOps.concat(Owo.PREFIX, TextOps.withFormatting("hot ui model reload failed, check the log for details", Formatting.RED))); + MinecraftClient.getInstance().player.sendMessage(TextOps.concat(Owo.PREFIX, TextOps.withFormatting("hot ui model reload failed, check the log for details", Formatting.RED)), false); Owo.LOGGER.error("Hot UI model reload failed", e); } } diff --git a/src/main/java/io/wispforest/owo/ui/util/NinePatchTexture.java b/src/main/java/io/wispforest/owo/ui/util/NinePatchTexture.java index daf0963d..651be89b 100644 --- a/src/main/java/io/wispforest/owo/ui/util/NinePatchTexture.java +++ b/src/main/java/io/wispforest/owo/ui/util/NinePatchTexture.java @@ -1,50 +1,58 @@ package io.wispforest.owo.ui.util; -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.mojang.blaze3d.systems.RenderSystem; +import io.wispforest.endec.Endec; +import io.wispforest.endec.StructEndec; +import io.wispforest.endec.impl.StructEndecBuilder; +import io.wispforest.owo.serialization.CodecUtils; +import io.wispforest.owo.serialization.endec.MinecraftEndecs; import io.wispforest.owo.ui.core.OwoUIDrawContext; import io.wispforest.owo.ui.core.PositionedRectangle; import io.wispforest.owo.ui.core.Size; import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.render.RenderLayer; import net.minecraft.resource.JsonDataLoader; import net.minecraft.resource.ResourceManager; import net.minecraft.util.Identifier; -import net.minecraft.util.JsonHelper; import net.minecraft.util.profiler.Profiler; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; import java.util.function.Consumer; +import java.util.function.Function; public class NinePatchTexture { private final Identifier texture; private final int u, v; - private final Size cornerPatchSize; - private final Size centerPatchSize; + private final PatchSizing patchSizing; private final Size textureSize; private final boolean repeat; - public NinePatchTexture(Identifier texture, int u, int v, Size cornerPatchSize, Size centerPatchSize, Size textureSize, boolean repeat) { + public NinePatchTexture(Identifier texture, int u, int v, PatchSizing patchSizing, Size textureSize, boolean repeat) { this.texture = texture; this.u = u; this.v = v; this.textureSize = textureSize; - this.cornerPatchSize = cornerPatchSize; - this.centerPatchSize = centerPatchSize; + this.patchSizing = patchSizing; this.repeat = repeat; } + public NinePatchTexture(Identifier texture, int u, int v, Size cornerPatchSize, Size centerPatchSize, Size textureSize, boolean repeat) { + this(texture, u, v, new PatchSizing(null, cornerPatchSize, centerPatchSize), textureSize, repeat); + } + public NinePatchTexture(Identifier texture, int u, int v, Size patchSize, Size textureSize, boolean repeat) { - this(texture, u, v, patchSize, patchSize, textureSize, repeat); + this(texture, u, v, new PatchSizing(patchSize, null, null), textureSize, repeat); } - public NinePatchTexture(Identifier texture, Size patchSize, Size textureSize, boolean repeat) { - this(texture, 0, 0, patchSize, textureSize, repeat); + private Size cornerPatchSize() { + return this.patchSizing.cornerPatchSize(); + } + + private Size centerPatchSize() { + return this.patchSizing.centerPatchSize(); } public void draw(OwoUIDrawContext context, PositionedRectangle rectangle) { @@ -52,95 +60,141 @@ public void draw(OwoUIDrawContext context, PositionedRectangle rectangle) { } public void draw(OwoUIDrawContext context, int x, int y, int width, int height) { - context.recordQuads(); + draw(context, RenderLayer::getGuiTextured, x, y, width, height); + } - int rightEdge = this.cornerPatchSize.width() + this.centerPatchSize.width(); - int bottomEdge = this.cornerPatchSize.height() + this.centerPatchSize.height(); + public void draw(OwoUIDrawContext context, Function renderLayers, int x, int y, int width, int height) { + int rightEdge = this.cornerPatchSize().width() + this.centerPatchSize().width(); + int bottomEdge = this.cornerPatchSize().height() + this.centerPatchSize().height(); - context.drawTexture(this.texture, x, y, this.u, this.v, this.cornerPatchSize.width(), this.cornerPatchSize.height(), this.textureSize.width(), this.textureSize.height()); - context.drawTexture(this.texture, x + width - this.cornerPatchSize.width(), y, this.u + rightEdge, this.v, this.cornerPatchSize.width(), this.cornerPatchSize.height(), this.textureSize.width(), this.textureSize.height()); - context.drawTexture(this.texture, x, y + height - this.cornerPatchSize.height(), this.u, this.v + bottomEdge, this.cornerPatchSize.width(), this.cornerPatchSize.height(), this.textureSize.width(), this.textureSize.height()); - context.drawTexture(this.texture, x + width - this.cornerPatchSize.width(), y + height - this.cornerPatchSize.height(), this.u + rightEdge, this.v + bottomEdge, this.cornerPatchSize.width(), this.cornerPatchSize.height(), this.textureSize.width(), this.textureSize.height()); + context.drawTexture(renderLayers, this.texture, x, y, this.u, this.v, this.cornerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height()); + context.drawTexture(renderLayers, this.texture, x + width - this.cornerPatchSize().width(), y, this.u + rightEdge, this.v, this.cornerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height()); + context.drawTexture(renderLayers, this.texture, x, y + height - this.cornerPatchSize().height(), this.u, this.v + bottomEdge, this.cornerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height()); + context.drawTexture(renderLayers, this.texture, x + width - this.cornerPatchSize().width(), y + height - this.cornerPatchSize().height(), this.u + rightEdge, this.v + bottomEdge, this.cornerPatchSize().width(), this.cornerPatchSize().height(), this.textureSize.width(), this.textureSize.height()); if (this.repeat) { - this.drawRepeated(context, x, y, width, height); + this.drawRepeated(context, renderLayers, x, y, width, height); } else { - this.drawStretched(context, x, y, width, height); + this.drawStretched(context, renderLayers, x, y, width, height); } - context.submitQuads(); } - protected void drawStretched(OwoUIDrawContext context, int x, int y, int width, int height) { - int doubleCornerHeight = this.cornerPatchSize.height() * 2; - int doubleCornerWidth = this.cornerPatchSize.width() * 2; + protected void drawStretched(OwoUIDrawContext context, Function renderLayers, int x, int y, int width, int height) { + int doubleCornerHeight = this.cornerPatchSize().height() * 2; + int doubleCornerWidth = this.cornerPatchSize().width() * 2; - int rightEdge = this.cornerPatchSize.width() + this.centerPatchSize.width(); - int bottomEdge = this.cornerPatchSize.height() + this.centerPatchSize.height(); + int rightEdge = this.cornerPatchSize().width() + this.centerPatchSize().width(); + int bottomEdge = this.cornerPatchSize().height() + this.centerPatchSize().height(); if (width > doubleCornerWidth && height > doubleCornerHeight) { - context.drawTexture(this.texture, x + this.cornerPatchSize.width(), y + this.cornerPatchSize.height(), width - doubleCornerWidth, height - doubleCornerHeight, this.u + this.cornerPatchSize.width(), this.v + this.cornerPatchSize.height(), this.centerPatchSize.width(), this.centerPatchSize.height(), this.textureSize.width(), this.textureSize.height()); + context.drawTexture(renderLayers, this.texture, x + this.cornerPatchSize().width(), y + this.cornerPatchSize().height(), + this.u + this.cornerPatchSize().width(), this.v + this.cornerPatchSize().height(), + width - doubleCornerWidth, height - doubleCornerHeight, + this.centerPatchSize().width(), this.centerPatchSize().height(), + this.textureSize.width(), this.textureSize.height()); } if (width > doubleCornerWidth) { - context.drawTexture(this.texture, x + this.cornerPatchSize.width(), y, width - doubleCornerWidth, this.cornerPatchSize.height(), this.u + this.cornerPatchSize.width(), this.v, this.centerPatchSize.width(), this.cornerPatchSize.height(), this.textureSize.width(), this.textureSize.height()); - context.drawTexture(this.texture, x + this.cornerPatchSize.width(), y + height - this.cornerPatchSize.height(), width - doubleCornerWidth, this.cornerPatchSize.height(), this.u + this.cornerPatchSize.width(), this.v + bottomEdge, this.centerPatchSize.width(), this.cornerPatchSize.height(), this.textureSize.width(), this.textureSize.height()); + context.drawTexture(renderLayers, this.texture, x + this.cornerPatchSize().width(), y, + this.u + this.cornerPatchSize().width(), this.v, + width - doubleCornerWidth, this.cornerPatchSize().height(), + this.centerPatchSize().width(), this.cornerPatchSize().height(), + this.textureSize.width(), this.textureSize.height()); + context.drawTexture(renderLayers, this.texture, x + this.cornerPatchSize().width(), y + height - this.cornerPatchSize().height(), + this.u + this.cornerPatchSize().width(), this.v + bottomEdge, + width - doubleCornerWidth, this.cornerPatchSize().height(), + this.centerPatchSize().width(), this.cornerPatchSize().height(), + this.textureSize.width(), this.textureSize.height()); } if (height > doubleCornerHeight) { - context.drawTexture(this.texture, x, y + this.cornerPatchSize.height(), this.cornerPatchSize.width(), height - doubleCornerHeight, this.u, this.v + this.cornerPatchSize.height(), this.cornerPatchSize.width(), this.centerPatchSize.height(), this.textureSize.width(), this.textureSize.height()); - context.drawTexture(this.texture, x + width - this.cornerPatchSize.width(), y + this.cornerPatchSize.height(), this.cornerPatchSize.width(), height - doubleCornerHeight, this.u + rightEdge, this.v + this.cornerPatchSize.height(), this.cornerPatchSize.width(), this.centerPatchSize.height(), this.textureSize.width(), this.textureSize.height()); + context.drawTexture(renderLayers, this.texture, x, y + this.cornerPatchSize().height(), + this.u, this.v + this.cornerPatchSize().height(), + this.cornerPatchSize().width(), height - doubleCornerHeight, + this.cornerPatchSize().width(), this.centerPatchSize().height(), + this.textureSize.width(), this.textureSize.height()); + context.drawTexture(renderLayers, this.texture, x + width - this.cornerPatchSize().width(), y + this.cornerPatchSize().height(), + this.u + rightEdge, this.v + this.cornerPatchSize().height(), + this.cornerPatchSize().width(), height - doubleCornerHeight, + this.cornerPatchSize().width(), this.centerPatchSize().height(), + this.textureSize.width(), this.textureSize.height()); } } - protected void drawRepeated(OwoUIDrawContext context, int x, int y, int width, int height) { - int doubleCornerHeight = this.cornerPatchSize.height() * 2; - int doubleCornerWidth = this.cornerPatchSize.width() * 2; + protected void drawRepeated(OwoUIDrawContext context, Function renderLayers, int x, int y, int width, int height) { + int doubleCornerHeight = this.cornerPatchSize().height() * 2; + int doubleCornerWidth = this.cornerPatchSize().width() * 2; - int rightEdge = this.cornerPatchSize.width() + this.centerPatchSize.width(); - int bottomEdge = this.cornerPatchSize.height() + this.centerPatchSize.height(); + int rightEdge = this.cornerPatchSize().width() + this.centerPatchSize().width(); + int bottomEdge = this.cornerPatchSize().height() + this.centerPatchSize().height(); if (width > doubleCornerWidth && height > doubleCornerHeight) { int leftoverHeight = height - doubleCornerHeight; while (leftoverHeight > 0) { - int drawHeight = Math.min(this.centerPatchSize.height(), leftoverHeight); + int drawHeight = Math.min(this.centerPatchSize().height(), leftoverHeight); int leftoverWidth = width - doubleCornerWidth; while (leftoverWidth > 0) { - int drawWidth = Math.min(this.centerPatchSize.width(), leftoverWidth); - context.drawTexture(this.texture, x + this.cornerPatchSize.width() + leftoverWidth - drawWidth, y + this.cornerPatchSize.height() + leftoverHeight - drawHeight, drawWidth, drawHeight, this.u + this.cornerPatchSize.width() + this.centerPatchSize.width() - drawWidth, this.v + this.cornerPatchSize.height() + this.centerPatchSize.height() - drawHeight, drawWidth, drawHeight, this.textureSize.width(), this.textureSize.height()); - - leftoverWidth -= this.centerPatchSize.width(); + int drawWidth = Math.min(this.centerPatchSize().width(), leftoverWidth); + context.drawTexture(renderLayers, this.texture, + x + this.cornerPatchSize().width() + leftoverWidth - drawWidth, y + this.cornerPatchSize().height() + leftoverHeight - drawHeight, + this.u + this.cornerPatchSize().width() + this.centerPatchSize().width() - drawWidth, this.v + this.cornerPatchSize().height() + this.centerPatchSize().height() - drawHeight, + drawWidth, drawHeight, + drawWidth, drawHeight, + this.textureSize.width(), this.textureSize.height()); + + leftoverWidth -= this.centerPatchSize().width(); } - leftoverHeight -= this.centerPatchSize.height(); + leftoverHeight -= this.centerPatchSize().height(); } } if (width > doubleCornerWidth) { int leftoverWidth = width - doubleCornerWidth; while (leftoverWidth > 0) { - int drawWidth = Math.min(this.centerPatchSize.width(), leftoverWidth); - - context.drawTexture(this.texture, x + this.cornerPatchSize.width() + leftoverWidth - drawWidth, y, drawWidth, this.cornerPatchSize.height(), this.u + this.cornerPatchSize.width() + this.centerPatchSize.width() - drawWidth, this.v, drawWidth, this.cornerPatchSize.height(), this.textureSize.width(), this.textureSize.height()); - context.drawTexture(this.texture, x + this.cornerPatchSize.width() + leftoverWidth - drawWidth, y + height - this.cornerPatchSize.height(), drawWidth, this.cornerPatchSize.height(), this.u + this.cornerPatchSize.width() + this.centerPatchSize.width() - drawWidth, this.v + bottomEdge, drawWidth, this.cornerPatchSize.height(), this.textureSize.width(), this.textureSize.height()); - - leftoverWidth -= this.centerPatchSize.width(); + int drawWidth = Math.min(this.centerPatchSize().width(), leftoverWidth); + + context.drawTexture(renderLayers, this.texture, x + this.cornerPatchSize().width() + leftoverWidth - drawWidth, y, + this.u + this.cornerPatchSize().width() + this.centerPatchSize().width() - drawWidth, this.v, + drawWidth, this.cornerPatchSize().height(), + drawWidth, this.cornerPatchSize().height(), + this.textureSize.width(), this.textureSize.height()); + context.drawTexture(renderLayers, this.texture, x + this.cornerPatchSize().width() + leftoverWidth - drawWidth, y + height - this.cornerPatchSize().height(), + this.u + this.cornerPatchSize().width() + this.centerPatchSize().width() - drawWidth, this.v + bottomEdge, + drawWidth, this.cornerPatchSize().height(), + drawWidth, this.cornerPatchSize().height(), + this.textureSize.width(), this.textureSize.height()); + + leftoverWidth -= this.centerPatchSize().width(); } } if (height > doubleCornerHeight) { int leftoverHeight = height - doubleCornerHeight; while (leftoverHeight > 0) { - int drawHeight = Math.min(this.centerPatchSize.height(), leftoverHeight); - context.drawTexture(this.texture, x, y + this.cornerPatchSize.height() + leftoverHeight - drawHeight, this.cornerPatchSize.width(), drawHeight, this.u, this.v + this.cornerPatchSize.height() + this.centerPatchSize.height() - drawHeight, this.cornerPatchSize.width(), drawHeight, this.textureSize.width(), this.textureSize.height()); - context.drawTexture(this.texture, x + width - this.cornerPatchSize.width(), y + this.cornerPatchSize.height() + leftoverHeight - drawHeight, this.cornerPatchSize.width(), drawHeight, this.u + rightEdge, this.v + this.cornerPatchSize.height() + this.centerPatchSize.height() - drawHeight, this.cornerPatchSize.width(), drawHeight, this.textureSize.width(), this.textureSize.height()); - - leftoverHeight -= this.centerPatchSize.height(); + int drawHeight = Math.min(this.centerPatchSize().height(), leftoverHeight); + context.drawTexture(renderLayers, this.texture, x, y + this.cornerPatchSize().height() + leftoverHeight - drawHeight, + this.u, this.v + this.cornerPatchSize().height() + this.centerPatchSize().height() - drawHeight, + this.cornerPatchSize().width(), drawHeight, + this.cornerPatchSize().width(), drawHeight, + this.textureSize.width(), this.textureSize.height()); + context.drawTexture(renderLayers, this.texture, x + width - this.cornerPatchSize().width(), y + this.cornerPatchSize().height() + leftoverHeight - drawHeight, + this.u + rightEdge, this.v + this.cornerPatchSize().height() + this.centerPatchSize().height() - drawHeight, + this.cornerPatchSize().width(), drawHeight, + this.cornerPatchSize().width(), drawHeight, + this.textureSize.width(), this.textureSize.height()); + + leftoverHeight -= this.centerPatchSize().height(); } } } public static void draw(Identifier texture, OwoUIDrawContext context, int x, int y, int width, int height) { - ifPresent(texture, ninePatchTexture -> ninePatchTexture.draw(context, x, y, width, height)); + draw(texture, context, RenderLayer::getGuiTextured, x, y, width, height); + } + + public static void draw(Identifier texture, OwoUIDrawContext context, Function renderLayers, int x, int y, int width, int height) { + ifPresent(texture, ninePatchTexture -> ninePatchTexture.draw(context, renderLayers, x, y, width, height)); } public static void draw(Identifier texture, OwoUIDrawContext context, PositionedRectangle rectangle) { @@ -152,45 +206,64 @@ private static void ifPresent(Identifier texture, Consumer act action.accept(MetadataLoader.LOADED_TEXTURES.get(texture)); } - public static class MetadataLoader extends JsonDataLoader implements IdentifiableResourceReloadListener { - - private static final Map LOADED_TEXTURES = new HashMap<>(); - - public MetadataLoader() { - super(new Gson(), "nine_patch_textures"); + public static final Endec ENDEC = StructEndecBuilder.of( + MinecraftEndecs.IDENTIFIER.fieldOf("texture", (texture) -> texture.texture), + Endec.INT.optionalFieldOf("u", (texture) -> texture.u, 0), + Endec.INT.optionalFieldOf("v", (texture) -> texture.v, 0), + PatchSizing.ENDEC.flatFieldOf((texture) -> texture.patchSizing), + Size.createEndec("texture_width", "texture_height").flatFieldOf((texture) -> texture.textureSize), + Endec.BOOLEAN.fieldOf("repeat", (texture) -> texture.repeat), + NinePatchTexture::new + ); + + private record PatchSizing(@Nullable Size patchSize, @Nullable Size cornerPatchSize, @Nullable Size centerPatchSize) { + public static final StructEndec ENDEC = StructEndecBuilder.of( + Size.ENDEC.nullableOf().optionalFieldOf("patch_size", PatchSizing::patchSize, () -> null), + Size.ENDEC.nullableOf().optionalFieldOf("corner_patch_size", PatchSizing::cornerPatchSize, () -> null), + Size.ENDEC.nullableOf().optionalFieldOf("center_patch_size", PatchSizing::centerPatchSize, () -> null), + PatchSizing::new + ); + + public PatchSizing { + if (patchSize == null) { + if ((cornerPatchSize != null && centerPatchSize == null)) { + throw new IllegalStateException("Missing center Patch Size while providing corner Patch Size!"); + } else if ((cornerPatchSize == null && centerPatchSize != null)) { + throw new IllegalStateException("Missing corner Patch Size while providing center Patch Size!"); + } else if ((cornerPatchSize == null && centerPatchSize == null)) { + throw new IllegalStateException("Missing base patch Size or patch size for both corner and center!"); + } + } } + @NotNull @Override - public Identifier getFabricId() { - return Identifier.of("owo", "nine_patch_metadata"); + public Size cornerPatchSize() { + return (this.cornerPatchSize != null) ? this.cornerPatchSize : this.patchSize; } + @NotNull @Override - protected void apply(Map prepared, ResourceManager manager, Profiler profiler) { - prepared.forEach((resourceId, jsonElement) -> { - if (!(jsonElement instanceof JsonObject object)) return; - - var texture = Identifier.of(JsonHelper.getString(object, "texture")); - var textureSize = Size.of(JsonHelper.getInt(object, "texture_width"), JsonHelper.getInt(object, "texture_height")); + public Size centerPatchSize() { + return (this.centerPatchSize != null) ? this.centerPatchSize : this.patchSize; + } + } - int u = JsonHelper.getInt(object, "u", 0), v = JsonHelper.getInt(object, "v", 0); - boolean repeat = JsonHelper.getBoolean(object, "repeat"); + public static class MetadataLoader extends JsonDataLoader implements IdentifiableResourceReloadListener { - if (object.has("corner_patch_size")) { - var cornerPatchObject = JsonHelper.getObject(object, "corner_patch_size"); - var centerPatchObject = JsonHelper.getObject(object, "center_patch_size"); + private static final Map LOADED_TEXTURES = new HashMap<>(); - var cornerPatchSize = Size.of(JsonHelper.getInt(cornerPatchObject, "width"), JsonHelper.getInt(cornerPatchObject, "height")); - var centerPatchSize = Size.of(JsonHelper.getInt(centerPatchObject, "width"), JsonHelper.getInt(centerPatchObject, "height")); + public MetadataLoader() { + super(CodecUtils.toCodec(NinePatchTexture.ENDEC), "nine_patch_textures"); + } - LOADED_TEXTURES.put(resourceId, new NinePatchTexture(texture, u, v, cornerPatchSize, centerPatchSize, textureSize, repeat)); - } else { - var patchSizeObject = JsonHelper.getObject(object, "patch_size"); - var patchSize = Size.of(JsonHelper.getInt(patchSizeObject, "width"), JsonHelper.getInt(patchSizeObject, "height")); + @Override + public Identifier getFabricId() { + return Identifier.of("owo", "nine_patch_metadata"); + } - LOADED_TEXTURES.put(resourceId, new NinePatchTexture(texture, u, v, patchSize, textureSize, repeat)); - } - }); + protected void apply(Map prepared, ResourceManager manager, Profiler profiler) { + LOADED_TEXTURES.putAll(prepared); } } diff --git a/src/main/java/io/wispforest/owo/ui/util/ScissorStack.java b/src/main/java/io/wispforest/owo/ui/util/ScissorStack.java index 39a5b4d7..09ade93d 100644 --- a/src/main/java/io/wispforest/owo/ui/util/ScissorStack.java +++ b/src/main/java/io/wispforest/owo/ui/util/ScissorStack.java @@ -5,6 +5,7 @@ import io.wispforest.owo.ui.core.Component; import io.wispforest.owo.ui.core.PositionedRectangle; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; @@ -31,10 +32,16 @@ public static void pushDirect(int x, int y, int width, int height) { (int) (window.getScaledHeight() - (y / scale) - height / scale), (int) (width / scale), (int) (height / scale), - null + (MatrixStack) null ); } + public static void push(int x, int y, int width, int height, DrawContext context) { + context.draw(); + + push(x, y, width, height, context.getMatrices()); + } + public static void push(int x, int y, int width, int height, @Nullable MatrixStack matrices) { final var newFrame = withGlTransform(x, y, width, height, matrices); diff --git a/src/main/java/io/wispforest/owo/ui/util/UIErrorToast.java b/src/main/java/io/wispforest/owo/ui/util/UIErrorToast.java index 6951eccc..b1472e77 100644 --- a/src/main/java/io/wispforest/owo/ui/util/UIErrorToast.java +++ b/src/main/java/io/wispforest/owo/ui/util/UIErrorToast.java @@ -71,8 +71,20 @@ private static void logErrorsDuringInitialLoad() { ); } + private Visibility visibility = Visibility.HIDE; + @Override - public Visibility draw(DrawContext context, ToastManager manager, long startTime) { + public void update(ToastManager manager, long time) { + this.visibility = time > 10000 ? Visibility.HIDE : Visibility.SHOW; + } + + @Override + public Visibility getVisibility() { + return this.visibility; + } + + @Override + public void draw(DrawContext context, TextRenderer textRenderer, long startTime) { var owoContext = OwoUIDrawContext.of(context); owoContext.fill(0, 0, this.getWidth(), this.getHeight(), 0x77000000); @@ -84,11 +96,8 @@ public Visibility draw(DrawContext context, ToastManager manager, long startTime for (int i = 1; i < this.errorMessage.size(); i++) { owoContext.drawText(this.textRenderer, this.errorMessage.get(i), 4, 4 + i * 11, 0xFFFFFF, false); } - - return startTime > 10000 ? Visibility.HIDE : Visibility.SHOW; } - @Override public int getHeight() { return 6 + this.errorMessage.size() * 11; diff --git a/src/main/java/io/wispforest/owo/util/RegistryAccess.java b/src/main/java/io/wispforest/owo/util/RegistryAccess.java deleted file mode 100644 index ef11309c..00000000 --- a/src/main/java/io/wispforest/owo/util/RegistryAccess.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.wispforest.owo.util; - -import net.minecraft.registry.Registry; -import net.minecraft.util.Identifier; -import net.minecraft.registry.entry.RegistryEntry; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; - -@Deprecated(forRemoval = true) -public final class RegistryAccess { - - private RegistryAccess() {} - - /** - * @deprecated Use {@link Registry#getEntry(Identifier)} - */ - @Nullable - public static RegistryEntry getEntry(Registry registry, Identifier id) { - return registry.getEntry(id).orElse(null); - } - - /** - * @deprecated Use {@link Registry#getEntry(T)} - */ - @Nullable - public static RegistryEntry getEntry(Registry registry, T value) { - return registry.getEntry(value); - } -} diff --git a/src/main/java/io/wispforest/owo/util/TagInjector.java b/src/main/java/io/wispforest/owo/util/TagInjector.java index 0ba3c7eb..47cb92c1 100644 --- a/src/main/java/io/wispforest/owo/util/TagInjector.java +++ b/src/main/java/io/wispforest/owo/util/TagInjector.java @@ -2,10 +2,8 @@ import com.google.common.collect.ForwardingMap; import net.minecraft.registry.Registry; -import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.tag.TagEntry; -import net.minecraft.registry.tag.TagManagerLoader; import net.minecraft.util.Identifier; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; diff --git a/src/main/resources/assets/owo/shaders/core/blur.json b/src/main/resources/assets/owo/shaders/core/blur.json index c824c5e5..3c1acbff 100644 --- a/src/main/resources/assets/owo/shaders/core/blur.json +++ b/src/main/resources/assets/owo/shaders/core/blur.json @@ -1,11 +1,6 @@ { - "blend": { - "func": "add", - "srcrgb": "srcalpha", - "dstrgb": "1-srcalpha" - }, - "vertex": "position", - "fragment": "owo:blur", + "vertex": "minecraft:core/position", + "fragment": "owo:core/blur", "attributes": [], "samplers": [ { "name": "InputSampler" } diff --git a/src/main/resources/assets/owo/shaders/core/spectrum.json b/src/main/resources/assets/owo/shaders/core/spectrum.json index 89711f4a..32d989fa 100644 --- a/src/main/resources/assets/owo/shaders/core/spectrum.json +++ b/src/main/resources/assets/owo/shaders/core/spectrum.json @@ -1,11 +1,6 @@ { - "blend": { - "func": "add", - "srcrgb": "srcalpha", - "dstrgb": "1-srcalpha" - }, - "vertex": "position_color", - "fragment": "owo:spectrum", + "vertex": "minecraft:core/position_color", + "fragment": "owo:core/spectrum", "attributes": [], "samplers": [], "uniforms": [ diff --git a/src/main/resources/owo.mixins.json b/src/main/resources/owo.mixins.json index 46ef156e..940e972f 100644 --- a/src/main/resources/owo.mixins.json +++ b/src/main/resources/owo.mixins.json @@ -23,8 +23,8 @@ "ServerPlayerInteractionManagerMixin", "SetComponentsLootFunctionAccessor", "TagGroupLoaderMixin", - "ext.ComponentMapImplAccessor", - "ext.ComponentMapImplMixin", + "ext.MergedComponentMapAccessor", + "ext.MergedComponentMapMixin", "ext.ItemMixin", "ext.ItemStackMixin", "itemgroup.ItemGroupAccessor", @@ -35,7 +35,7 @@ "offline.ProgressMapAccessor", "offline.WorldSaveHandlerMixin", "recipe_remainders.CraftingResultSlotMixin", - "recipe_remainders.RecipeManagerMixin", + "recipe_remainders.JsonDataLoaderMixin", "registry.ReferenceAccessor", "registry.SimpleRegistryMixin", "text.LanguageMixin", @@ -54,20 +54,17 @@ "ClientLoginNetworkHandlerAccessor", "DrawContextMixin", "MinecraftClientMixin", - "itemgroup.AbstractInventoryScreenMixin", + "itemgroup.StatusEffectsDisplayMixin", "itemgroup.CreativeInventoryScreenAccessor", "itemgroup.CreativeInventoryScreenMixin", "itemgroup.MixinCreativeInventoryScreenMixin", - "shader.GameRendererMixin", "shader.ShaderProgramAccessor", - "shader.ShaderProgramMixin", "text.TranslationStorageMixin", "tweaks.OperatingSystemMixin", "tweaks.TextFieldWidgetMixin", "ui.ChatScreenMixin", "ui.ClickableWidgetMixin", "ui.DrawContextInvoker", - "ui.DrawContextMixin", "ui.EditBoxWidgetMixin", "ui.EntityRenderDispatcherMixin", "ui.EntityRendererMixin", @@ -76,7 +73,6 @@ "ui.RenderSystemMixin", "ui.ScreenMixin", "ui.SliderWidgetMixin", - "ui.TessellatorMixin", "ui.TextFieldWidgetMixin", "ui.access.BaseOwoHandledScreenAccessor", "ui.access.ButtonWidgetAccessor", diff --git a/src/testmod/java/io/wispforest/uwu/Uwu.java b/src/testmod/java/io/wispforest/uwu/Uwu.java index c5d28765..bde6bec6 100644 --- a/src/testmod/java/io/wispforest/uwu/Uwu.java +++ b/src/testmod/java/io/wispforest/uwu/Uwu.java @@ -37,7 +37,6 @@ import io.wispforest.owo.serialization.format.nbt.NbtSerializer; import io.wispforest.owo.text.CustomTextRegistry; import io.wispforest.owo.ui.core.Color; -import io.wispforest.owo.util.RegistryAccess; import io.wispforest.owo.util.TagInjector; import io.wispforest.uwu.config.BruhConfig; import io.wispforest.uwu.config.UwuConfig; @@ -201,7 +200,7 @@ public void onInitialize() { System.out.println(serializer.result().read(SerializationContext.empty(), stackEndec)); System.out.println(CodecUtils.toCodec(MinecraftEndecs.BLOCK_POS).encodeStart(NbtOps.INSTANCE, new BlockPos(34, 35, 69)).result().get()); - FieldRegistrationHandler.register(UwuItems.class, "uwu", true); + UwuItems.init(); TagInjector.inject(Registries.BLOCK, BlockTags.BASE_STONE_OVERWORLD.id(), Blocks.GLASS); TagInjector.injectTagReference(Registries.ITEM, ItemTags.COALS.id(), ItemTags.FOX_FOOD.id()); @@ -226,8 +225,8 @@ public void onInitialize() { new ParticleSystemController(Identifier.of("uwu", "server_only_particles")); } - System.out.println(RegistryAccess.getEntry(Registries.ITEM, Items.ACACIA_BOAT)); - System.out.println(RegistryAccess.getEntry(Registries.ITEM, Identifier.of("acacia_planks"))); + System.out.println(Registries.ITEM.getEntry(Items.ACACIA_BOAT)); + System.out.println(Registries.ITEM.getEntry(Identifier.of("acacia_planks"))); // UwuShapedRecipe.init(); @@ -377,7 +376,7 @@ public void onInitialize() { { LOGGER.info("--- Format Based Endec Test"); - var nbtDataStack = handStack.encode(access); + var nbtDataStack = handStack.toNbt(access); LOGGER.info(" Input: " + nbtDataStack.asString().replace("\n", "\\n")); @@ -399,7 +398,7 @@ public void onInitialize() { { LOGGER.info("--- Transpose Format Based Endec Test"); - var nbtDataStack = handStack.encode(access); + var nbtDataStack = handStack.toNbt(access); LOGGER.info(" Input: " + nbtDataStack.asString().replace("\n", "\\n")); diff --git a/src/testmod/java/io/wispforest/uwu/client/ComponentTestScreen.java b/src/testmod/java/io/wispforest/uwu/client/ComponentTestScreen.java index 3e71bcbf..050d9e49 100644 --- a/src/testmod/java/io/wispforest/uwu/client/ComponentTestScreen.java +++ b/src/testmod/java/io/wispforest/uwu/client/ComponentTestScreen.java @@ -60,7 +60,7 @@ protected void init() { .child(Components.button(Text.of("Dark Background"), button -> rootComponent.surface(Surface.flat(0x77000000))).horizontalSizing(Sizing.fixed(95))) .child(Components.button(Text.of("No Background"), button -> rootComponent.surface(Surface.BLANK)).margins(Insets.vertical(5)).horizontalSizing(Sizing.fixed(95))) .child(Components.button(Text.of("Dirt Background"), button -> rootComponent.surface(Surface.OPTIONS_BACKGROUND)).horizontalSizing(Sizing.fixed(95))) - .child(Components.checkbox(Text.of("bruh")).onChanged(aBoolean -> this.client.player.sendMessage(Text.of("bruh: " + aBoolean))).margins(Insets.top(5))) + .child(Components.checkbox(Text.of("bruh")).onChanged(aBoolean -> this.client.player.sendMessage(Text.of("bruh: " + aBoolean), false)).margins(Insets.top(5))) .padding(Insets.of(10)) .surface(Surface.vanillaPanorama(true)) .positioning(Positioning.relative(1, 1)) @@ -172,7 +172,7 @@ protected void init() { .message(value -> Text.translatable("text.ui.test_slider", value)) .onChanged().subscribe(value -> { slider.parent().surface(Surface.blur(3, (float) (value * 3))); - this.client.player.sendMessage(Text.of("sliding towards " + value)); + this.client.player.sendMessage(Text.of("sliding towards " + value), false); }) )) .gap(10) diff --git a/src/testmod/java/io/wispforest/uwu/client/SmolComponentTestScreen.java b/src/testmod/java/io/wispforest/uwu/client/SmolComponentTestScreen.java index 8c11b3dd..6d15ffcc 100644 --- a/src/testmod/java/io/wispforest/uwu/client/SmolComponentTestScreen.java +++ b/src/testmod/java/io/wispforest/uwu/client/SmolComponentTestScreen.java @@ -21,11 +21,11 @@ protected void build(FlowLayout rootComponent) { rootComponent.childById(SlimSliderComponent.class, "precise-slider").tooltipSupplier(SlimSliderComponent.valueTooltipSupplier(2)); rootComponent.childById(SlimSliderComponent.class, "tiny-steppy-man").tooltipSupplier(SlimSliderComponent.VALUE_TOOLTIP_SUPPLIER).onChanged().subscribe(value -> { - this.client.player.sendMessage(Text.literal("tiny steppy man: " + value)); + this.client.player.sendMessage(Text.literal("tiny steppy man: " + value), false); }); rootComponent.childById(SlimSliderComponent.class, "big-steppy-man").tooltipSupplier(value -> Text.literal("big steppy man: " + value)).onChanged().subscribe(value -> { - this.client.player.sendMessage(Text.literal("big steppy man: " + value)); + this.client.player.sendMessage(Text.literal("big steppy man: " + value), false); }); rootComponent.childById(SlimSliderComponent.class, "inset-slider").configure(slider -> { diff --git a/src/testmod/java/io/wispforest/uwu/client/UwuClient.java b/src/testmod/java/io/wispforest/uwu/client/UwuClient.java index 7e49469d..a177606e 100644 --- a/src/testmod/java/io/wispforest/uwu/client/UwuClient.java +++ b/src/testmod/java/io/wispforest/uwu/client/UwuClient.java @@ -143,7 +143,7 @@ public void onInitializeClient() { ButtonComponent button; instance.adapter.rootComponent.child( (button = Components.button(Text.literal(":)"), buttonComponent -> { - MinecraftClient.getInstance().player.sendMessage(Text.literal("handled screen moment")); + MinecraftClient.getInstance().player.sendMessage(Text.literal("handled screen moment"), false); })).verticalSizing(Sizing.fixed(12)) ); diff --git a/src/testmod/java/io/wispforest/uwu/items/UwuCounterItem.java b/src/testmod/java/io/wispforest/uwu/items/UwuCounterItem.java index 259bdc47..dbc78787 100644 --- a/src/testmod/java/io/wispforest/uwu/items/UwuCounterItem.java +++ b/src/testmod/java/io/wispforest/uwu/items/UwuCounterItem.java @@ -11,13 +11,12 @@ import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; +import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; import net.minecraft.util.Rarity; -import net.minecraft.util.TypedActionResult; import net.minecraft.world.World; public class UwuCounterItem extends Item { @@ -29,12 +28,12 @@ public class UwuCounterItem extends Item { .build() ); - public UwuCounterItem() { - super(new Settings().rarity(Rarity.UNCOMMON)); + public UwuCounterItem(Item.Settings settings) { + super(settings.rarity(Rarity.UNCOMMON)); } @Override - public TypedActionResult use(World world, PlayerEntity user, Hand hand) { + public ActionResult use(World world, PlayerEntity user, Hand hand) { var stack = user.getStackInHand(hand); if (user.isSneaking()) { @@ -43,13 +42,13 @@ public TypedActionResult use(World world, PlayerEntity user, Hand han stack.apply(COUNT, 0, old -> old + 1); } - return TypedActionResult.success(stack); + return ActionResult.SUCCESS.withNewHandStack(stack); } @Override public void deriveStackComponents(ComponentMap source, ComponentChanges.Builder target) { target.add(DataComponentTypes.ATTRIBUTE_MODIFIERS, AttributeModifiersComponent.builder() - .add(EntityAttributes.GENERIC_ATTACK_DAMAGE, + .add(EntityAttributes.ATTACK_DAMAGE, new EntityAttributeModifier(Identifier.of("uwu", "counter_attribute"), source.getOrDefault(COUNT, 0), EntityAttributeModifier.Operation.ADD_VALUE), AttributeModifierSlot.MAINHAND) .build()); diff --git a/src/testmod/java/io/wispforest/uwu/items/UwuItems.java b/src/testmod/java/io/wispforest/uwu/items/UwuItems.java index 68786734..ceffff61 100644 --- a/src/testmod/java/io/wispforest/uwu/items/UwuItems.java +++ b/src/testmod/java/io/wispforest/uwu/items/UwuItems.java @@ -1,30 +1,51 @@ package io.wispforest.uwu.items; -import io.wispforest.owo.registration.annotations.AssignedName; -import io.wispforest.owo.registration.annotations.RegistryNamespace; -import io.wispforest.owo.registration.reflect.ItemRegistryContainer; import io.wispforest.uwu.Uwu; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.item.Item; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.util.Identifier; -import java.lang.reflect.Field; +import java.util.function.Function; -public class UwuItems implements ItemRegistryContainer { +public class UwuItems { - public static final Item TEST_STICK = new UwuTestStickItem(); - public static final Item SCREEN_SHARD = new UwuScreenShardItem(); - public static final Item COUNTER = new UwuCounterItem(); + public static final Item TEST_STICK = register("test_stick", UwuTestStickItem::new); + public static final Item SCREEN_SHARD = register("screen_shard", UwuScreenShardItem::new); + public static final Item COUNTER = register("counter", UwuCounterItem::new); - @RegistryNamespace("uowou") - public static class OwoCompatItems implements ItemRegistryContainer { + public static class OwoCompatItems { + public static final Item OWO_COMPAT_ITEM = register(Identifier.of("owo", "owo_compat_item"), new Item.Settings().group(Uwu.FOUR_TAB_GROUP).tab(2)); + } + + public static T register(String path, Function factory) { + return register(path, factory, new Item.Settings()); + } + + public static Item register(String path, Item.Settings settings) { + return register(Identifier.of("uwu", path), Item::new, settings); + } + + public static T register(String path, Function factory, Item.Settings settings) { + return register(Identifier.of("uwu", path), factory, settings); + } + + public static Item register(Identifier identifier, Item.Settings settings) { + return register(identifier, Item::new, settings); + } + + + public static T register(Identifier identifier, Function factory, Item.Settings settings) { + var registryKey = RegistryKey.of(RegistryKeys.ITEM, identifier); + + settings.registryKey(registryKey); - @AssignedName("owo_ingot") - public static final Item OWO_COMPAT_ITEM = new Item(new Item.Settings().group(Uwu.FOUR_TAB_GROUP).tab(2)); + T t = factory.apply(settings); - @Override - public boolean shouldProcessField(Item value, String identifier, Field field) { - return FabricLoader.getInstance().isModLoaded("owo"); - } + return Registry.register(Registries.ITEM, registryKey, t); } + public static void init() {} } diff --git a/src/testmod/java/io/wispforest/uwu/items/UwuScreenShardItem.java b/src/testmod/java/io/wispforest/uwu/items/UwuScreenShardItem.java index aca6218c..c3f817a5 100644 --- a/src/testmod/java/io/wispforest/uwu/items/UwuScreenShardItem.java +++ b/src/testmod/java/io/wispforest/uwu/items/UwuScreenShardItem.java @@ -8,26 +8,25 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; import net.minecraft.screen.NamedScreenHandlerFactory; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandlerContext; import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.Rarity; -import net.minecraft.util.TypedActionResult; import net.minecraft.world.World; import org.jetbrains.annotations.NotNull; public class UwuScreenShardItem extends Item { - public UwuScreenShardItem() { - super(new Settings().rarity(Rarity.UNCOMMON)); + public UwuScreenShardItem(Item.Settings settings) { + super(settings.rarity(Rarity.UNCOMMON)); } @Override @Environment(EnvType.CLIENT) - public TypedActionResult use(World world, PlayerEntity user, Hand hand) { + public ActionResult use(World world, PlayerEntity user, Hand hand) { if (user.isSneaking()) { if (world.isClient) MinecraftClient.getInstance().setScreen(new SelectUwuScreenScreen()); } else if (!world.isClient) { @@ -43,6 +42,6 @@ public Text getDisplayName() { } }); } - return TypedActionResult.pass(user.getStackInHand(hand)); + return ActionResult.PASS; } } diff --git a/src/testmod/java/io/wispforest/uwu/items/UwuTestStickItem.java b/src/testmod/java/io/wispforest/uwu/items/UwuTestStickItem.java index e4f2b0b9..53be1bbb 100644 --- a/src/testmod/java/io/wispforest/uwu/items/UwuTestStickItem.java +++ b/src/testmod/java/io/wispforest/uwu/items/UwuTestStickItem.java @@ -31,11 +31,9 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.MutableText; import net.minecraft.text.Text; -import net.minecraft.text.TextCodecs; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; -import net.minecraft.util.TypedActionResult; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; @@ -65,8 +63,8 @@ public DataResult encode(String input, DynamicOps ops, T prefix) { private static final Endec YEP_SAME_HERE = CodecUtils.toEndec(CodecUtils.toCodec(CodecUtils.toEndec(THIS_CODEC_NEEDS_REGISTRIES))); private static final KeyedEndec KYED = YEP_SAME_HERE.keyed("kyed", (String) null); - public UwuTestStickItem() { - super(new Item.Settings() + public UwuTestStickItem(Item.Settings settings) { + super(settings .group(Uwu.SIX_TAB_GROUP).tab(3).maxCount(1) .trackUsageStat() .stackGenerator(OwoItemGroup.DEFAULT_STACK_GENERATOR.andThen((item, stacks) -> { @@ -81,9 +79,9 @@ public UwuTestStickItem() { } @Override - public TypedActionResult use(World world, PlayerEntity user, Hand hand) { + public ActionResult use(World world, PlayerEntity user, Hand hand) { if (user.isSneaking()) { - if (world.isClient) return TypedActionResult.success(user.getStackInHand(hand)); + if (world.isClient) return ActionResult.SUCCESS; Uwu.CHANNEL.serverHandle(user).send(new Uwu.OtherTestMessage(user.getBlockPos(), "based")); @@ -92,17 +90,16 @@ public TypedActionResult use(World world, PlayerEntity user, Hand han WorldOps.teleportToWorld((ServerPlayerEntity) user, teleportTo, new Vec3d(0, 128, 0)); - return TypedActionResult.success(user.getStackInHand(hand)); } else { - if (!world.isClient) return TypedActionResult.success(user.getStackInHand(hand)); + if (!world.isClient) return ActionResult.SUCCESS; Uwu.CHANNEL.clientHandle().send(Uwu.MESSAGE); Uwu.CUBE.spawn(world, user.getEyePos().add(user.getRotationVec(0).multiply(3)).subtract(.5, .5, .5), null); - user.sendMessage(Text.translatable("uwu.a", "bruh")); - - return TypedActionResult.success(user.getStackInHand(hand)); + user.sendMessage(Text.translatable("uwu.a", "bruh"), false); } + + return ActionResult.SUCCESS; } @Override @@ -115,7 +112,7 @@ public ActionResult useOnBlock(ItemUsageContext context) { var data = stack.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT).getNbt() .get(SerializationContext.attributes(RegistriesAttribute.of(context.getWorld().getRegistryManager())), KYED); - context.getPlayer().sendMessage(Text.literal("current: " + data)); + context.getPlayer().sendMessage(Text.literal("current: " + data), false); stack.apply(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT, nbt -> { return nbt.apply(nbtCompound -> nbtCompound.put( @@ -124,9 +121,9 @@ public ActionResult useOnBlock(ItemUsageContext context) { String.valueOf(context.getWorld().random.nextInt(10000)) )); }); - context.getPlayer().sendMessage(Text.literal("modified")); + context.getPlayer().sendMessage(Text.literal("modified"), false); } catch (Exception bruh) { - context.getPlayer().sendMessage(Text.literal("bruh: " + bruh.getMessage())); + context.getPlayer().sendMessage(Text.literal("bruh: " + bruh.getMessage()), false); } return ActionResult.SUCCESS; @@ -136,7 +133,7 @@ public ActionResult useOnBlock(ItemUsageContext context) { final var breakStack = new ItemStack(Items.NETHERITE_PICKAXE); - final var fortune = context.getWorld().getRegistryManager().get(RegistryKeys.ENCHANTMENT).getEntry(Enchantments.FORTUNE).orElseThrow(); + final var fortune = context.getWorld().getRegistryManager().getOrThrow(RegistryKeys.ENCHANTMENT).getOrThrow(Enchantments.FORTUNE); breakStack.addEnchantment(fortune, 3); WorldOps.breakBlockWithItem(context.getWorld(), context.getBlockPos(), breakStack); From 9aa2ee04551478dd74e3a14652296a660f3cf221 Mon Sep 17 00:00:00 2001 From: Dragon-Seeker Date: Fri, 18 Oct 2024 15:46:16 -0500 Subject: [PATCH 2/8] Make shaders be processed outside of debug --- .../java/io/wispforest/owo/client/OwoClient.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/wispforest/owo/client/OwoClient.java b/src/main/java/io/wispforest/owo/client/OwoClient.java index 4890ff68..2cfefd6f 100644 --- a/src/main/java/io/wispforest/owo/client/OwoClient.java +++ b/src/main/java/io/wispforest/owo/client/OwoClient.java @@ -56,6 +56,10 @@ public void onInitializeClient() { ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new UIModelLoader()); ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new NinePatchTexture.MetadataLoader()); + ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() { + @Override public Identifier getFabricId() { return Identifier.of("owo", "after_shader_load"); } + @Override public void reload(ResourceManager manager) { GlProgram.forEachProgram(Runnable::run); } + }); final var renderdocPath = System.getProperty("owo.renderdocPath"); if (renderdocPath != null) { @@ -74,12 +78,8 @@ public void onInitializeClient() { ClientCommandRegistrationCallback.EVENT.register(OwoConfigCommand::register); - if (!Owo.DEBUG) return; - OwoDebugCommands.Client.register(); - - ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() { - @Override public Identifier getFabricId() { return Identifier.of("owo", "after_shader_load"); } - @Override public void reload(ResourceManager manager) { GlProgram.forEachProgram(Runnable::run); } - }); + if (Owo.DEBUG) { + OwoDebugCommands.Client.register(); + } } } From f576dcd7ecffefb8d143886d64352d961d1cbf1e Mon Sep 17 00:00:00 2001 From: Dragon-Seeker Date: Sun, 20 Oct 2024 16:08:26 -0500 Subject: [PATCH 3/8] Adjust Shader API operations and naming's --- src/main/java/io/wispforest/owo/client/OwoClient.java | 2 +- .../owo/mixin/shader/ShaderProgramAccessor.java | 2 +- src/main/java/io/wispforest/owo/shader/GlProgram.java | 10 +++------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/wispforest/owo/client/OwoClient.java b/src/main/java/io/wispforest/owo/client/OwoClient.java index 2cfefd6f..8ef2e0e2 100644 --- a/src/main/java/io/wispforest/owo/client/OwoClient.java +++ b/src/main/java/io/wispforest/owo/client/OwoClient.java @@ -58,7 +58,7 @@ public void onInitializeClient() { ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new NinePatchTexture.MetadataLoader()); ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() { @Override public Identifier getFabricId() { return Identifier.of("owo", "after_shader_load"); } - @Override public void reload(ResourceManager manager) { GlProgram.forEachProgram(Runnable::run); } + @Override public void reload(ResourceManager manager) { GlProgram.loadAndSetupPrograms(); } }); final var renderdocPath = System.getProperty("owo.renderdocPath"); diff --git a/src/main/java/io/wispforest/owo/mixin/shader/ShaderProgramAccessor.java b/src/main/java/io/wispforest/owo/mixin/shader/ShaderProgramAccessor.java index e9a4a718..b02a3323 100644 --- a/src/main/java/io/wispforest/owo/mixin/shader/ShaderProgramAccessor.java +++ b/src/main/java/io/wispforest/owo/mixin/shader/ShaderProgramAccessor.java @@ -11,6 +11,6 @@ public interface ShaderProgramAccessor { @Accessor("uniformsByName") - Map owo$getLoadedUniforms(); + Map owo$getUniformsByName(); } diff --git a/src/main/java/io/wispforest/owo/shader/GlProgram.java b/src/main/java/io/wispforest/owo/shader/GlProgram.java index dc569386..a6d06717 100644 --- a/src/main/java/io/wispforest/owo/shader/GlProgram.java +++ b/src/main/java/io/wispforest/owo/shader/GlProgram.java @@ -6,17 +6,13 @@ import net.minecraft.client.gl.*; import net.minecraft.client.render.RenderPhase; import net.minecraft.client.render.VertexFormat; -import net.minecraft.resource.ResourceFactory; import net.minecraft.util.Identifier; -import net.minecraft.util.Pair; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; -import java.util.function.Function; /** * A simple wrapper around Minecraft's built-in core shaders. In order to load and use @@ -86,11 +82,11 @@ protected void setup() {} * the value of the uniform, or {@code null} if no such uniform exists */ protected @Nullable GlUniform findUniform(String name) { - return ((ShaderProgramAccessor) this.backingProgram).owo$getLoadedUniforms().get(name); + return ((ShaderProgramAccessor) this.backingProgram).owo$getUniformsByName().get(name); } @ApiStatus.Internal - public static void forEachProgram(Consumer loader) { - REGISTERED_PROGRAMS.forEach(loader); + public static void loadAndSetupPrograms() { + REGISTERED_PROGRAMS.forEach(Runnable::run); } } From a9f4516b1282456b93006d4a76d30efeb97bedd4 Mon Sep 17 00:00:00 2001 From: Dragon-Seeker Date: Sun, 20 Oct 2024 16:09:14 -0500 Subject: [PATCH 4/8] Remove helper method to create size endec --- src/main/java/io/wispforest/owo/ui/core/Size.java | 15 +++++---------- .../wispforest/owo/ui/util/NinePatchTexture.java | 6 +++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/wispforest/owo/ui/core/Size.java b/src/main/java/io/wispforest/owo/ui/core/Size.java index e2fb83f1..f835825d 100644 --- a/src/main/java/io/wispforest/owo/ui/core/Size.java +++ b/src/main/java/io/wispforest/owo/ui/core/Size.java @@ -1,7 +1,6 @@ package io.wispforest.owo.ui.core; import io.wispforest.endec.Endec; -import io.wispforest.endec.StructEndec; import io.wispforest.endec.impl.StructEndecBuilder; import org.jetbrains.annotations.ApiStatus; @@ -14,7 +13,11 @@ */ public record Size(int width, int height) { - public static final Endec ENDEC = createEndec("width", "height"); + public static final Endec ENDEC =StructEndecBuilder.of( + Endec.INT.fieldOf("width", Size::width), + Endec.INT.fieldOf("height", Size::height), + Size::of + ); private static final Size ZERO = new Size(0, 0); @@ -36,12 +39,4 @@ public static Size square(int sideLength) { public static Size zero() { return ZERO; } - - public static StructEndec createEndec(String widthName, String heightName) { - return StructEndecBuilder.of( - Endec.INT.fieldOf(widthName, Size::width), - Endec.INT.fieldOf(heightName, Size::height), - Size::of - ); - } } diff --git a/src/main/java/io/wispforest/owo/ui/util/NinePatchTexture.java b/src/main/java/io/wispforest/owo/ui/util/NinePatchTexture.java index 651be89b..5905b898 100644 --- a/src/main/java/io/wispforest/owo/ui/util/NinePatchTexture.java +++ b/src/main/java/io/wispforest/owo/ui/util/NinePatchTexture.java @@ -211,7 +211,11 @@ private static void ifPresent(Identifier texture, Consumer act Endec.INT.optionalFieldOf("u", (texture) -> texture.u, 0), Endec.INT.optionalFieldOf("v", (texture) -> texture.v, 0), PatchSizing.ENDEC.flatFieldOf((texture) -> texture.patchSizing), - Size.createEndec("texture_width", "texture_height").flatFieldOf((texture) -> texture.textureSize), + StructEndecBuilder.of( + Endec.INT.fieldOf("texture_width", Size::width), + Endec.INT.fieldOf("texture_height", Size::height), + Size::of + ).flatFieldOf((texture) -> texture.textureSize), Endec.BOOLEAN.fieldOf("repeat", (texture) -> texture.repeat), NinePatchTexture::new ); From 5e7a5298302c871712a39abdb0bc6dd5389f0ca2 Mon Sep 17 00:00:00 2001 From: Dragon-Seeker Date: Mon, 21 Oct 2024 13:36:39 -0500 Subject: [PATCH 5/8] Fix issues with Recipe Remainder and test --- .../CraftingResultSlotMixin.java | 35 +++++++++---------- .../data/uwu/recipe/test_recipe.json | 8 ++--- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/main/java/io/wispforest/owo/mixin/recipe_remainders/CraftingResultSlotMixin.java b/src/main/java/io/wispforest/owo/mixin/recipe_remainders/CraftingResultSlotMixin.java index 801f0022..837769cc 100644 --- a/src/main/java/io/wispforest/owo/mixin/recipe_remainders/CraftingResultSlotMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/recipe_remainders/CraftingResultSlotMixin.java @@ -51,7 +51,7 @@ private void fixRemainderStacking(PlayerEntity player, ItemStack stack, Callback } @WrapOperation(method = "getRecipeRemainders", at = @At(value = "INVOKE", target = "Lnet/minecraft/recipe/ServerRecipeManager;getFirstMatch(Lnet/minecraft/recipe/RecipeType;Lnet/minecraft/recipe/input/RecipeInput;Lnet/minecraft/world/World;)Ljava/util/Optional;")) - private > Optional> captureRecipeEntry(ServerRecipeManager instance, RecipeType type, I input, World world, Operation>> original, @Share("owo_recipe_entry") LocalRef>> recipeEntry) { + private > Optional> captureRecipeEntry(ServerRecipeManager instance, RecipeType type, I input, World world, Operation>> original, @Share("owo_recipe_entry") LocalRef>> recipeEntry) { var entry = original.call(instance, type, input, world); recipeEntry.set(entry); @@ -60,29 +60,26 @@ private > Optional> c } @WrapOperation(method = "getRecipeRemainders", at = @At(value = "INVOKE", target = "Ljava/util/Optional;map(Ljava/util/function/Function;)Ljava/util/Optional;")) - private Optional addRecipeSpecificRemainders(Optional instance, Function mapper, Operation> original, @Share("owo_recipe_entry") LocalRef>> recipeEntry, @Local(argsOnly = true) CraftingRecipeInput input) { + private > Optional> addRecipeSpecificRemainders(Optional instance, Function> mapper, Operation>> original, @Share("owo_recipe_entry") LocalRef>> recipeEntry, @Local(argsOnly = true) CraftingRecipeInput input) { var recipeEntryOptional = recipeEntry.get(); - var mappedValue = original.call(instance, mapper); + return original.call(instance, mapper) + .map(defaultList -> { + var recipeId = recipeEntryOptional.get().id().getValue(); - var defaultList = (DefaultedList) (Object) mappedValue; + if(RecipeRemainderStorage.has(recipeId)) { + var remainders = defaultList; + var owoRemainders = RecipeRemainderStorage.get(recipeId); - if (recipeEntryOptional.isPresent() ){ - var recipeId = recipeEntryOptional.get().id().getValue(); + for (int i = 0; i < remainders.size(); ++i) { + var item = input.getStackInSlot(i).getItem(); + if (!owoRemainders.containsKey(item)) continue; - if(RecipeRemainderStorage.has(recipeId)) { - var remainders = defaultList; - var owoRemainders = RecipeRemainderStorage.get(recipeId); + remainders.set(i, owoRemainders.get(item).copy()); + } + } - for (int i = 0; i < remainders.size(); ++i) { - var item = input.getStackInSlot(i).getItem(); - if (!owoRemainders.containsKey(item)) continue; - - remainders.set(i, owoRemainders.get(item).copy()); - } - } - } - - return mappedValue; + return defaultList; + }); } } diff --git a/src/testmod/resources/data/uwu/recipe/test_recipe.json b/src/testmod/resources/data/uwu/recipe/test_recipe.json index 457bf889..19b3bd78 100644 --- a/src/testmod/resources/data/uwu/recipe/test_recipe.json +++ b/src/testmod/resources/data/uwu/recipe/test_recipe.json @@ -1,12 +1,8 @@ { "type": "minecraft:crafting_shaped", "key": { - "#": { - "item": "minecraft:stick" - }, - "X": { - "item": "minecraft:sand" - } + "#": "minecraft:stick", + "X": "minecraft:sand" }, "owo:remainders": { "minecraft:sand": "minecraft:sand", From 5606b5cc9b87d3b0a01022e0b77ad3fe40ec5045 Mon Sep 17 00:00:00 2001 From: Dragon-Seeker Date: Mon, 21 Oct 2024 18:17:33 -0500 Subject: [PATCH 6/8] Update for Release Candidate 2 --- gradle.properties | 6 +++--- .../wispforest/owo/mixin/ui/HandledScreenMixin.java | 13 +++++++++++++ .../owo/ui/component/SpriteComponent.java | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index c9c27149..1b45f7c4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx2G # Fabric Properties # check these on https://fabricmc.net/develop minecraft_base_version=1.21.2 -minecraft_version=1.21.2-pre2 -yarn_mappings=1.21.2-pre2+build.4 +minecraft_version=1.21.2-rc2 +yarn_mappings=1.21.2-rc2+build.1 loader_version=0.16.7 # Mod Properties mod_version=0.12.15 maven_group=io.wispforest archives_base_name=owo-lib # Dependencies -fabric_version=0.105.3+1.21.2 +fabric_version=0.106.1+1.21.2 # https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/ rei_version=15.0.728 diff --git a/src/main/java/io/wispforest/owo/mixin/ui/HandledScreenMixin.java b/src/main/java/io/wispforest/owo/mixin/ui/HandledScreenMixin.java index 5e0878bb..435b2f95 100644 --- a/src/main/java/io/wispforest/owo/mixin/ui/HandledScreenMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/ui/HandledScreenMixin.java @@ -1,5 +1,8 @@ package io.wispforest.owo.mixin.ui; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.sugar.Local; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; @@ -89,4 +92,14 @@ private void closeIt(int keyCode, int scanCode, int modifiers, CallbackInfoRetur cir.setReturnValue(true); } } + + // Fixes issues with scrolling with screens extending Handled and using UIAdapter + @WrapMethod(method = "mouseScrolled") + private boolean owo$useSuperMouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount, Operation original){ + var bl = original.call(mouseX, mouseY, horizontalAmount, verticalAmount); + + if (bl) return true; + + return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); + } } diff --git a/src/main/java/io/wispforest/owo/ui/component/SpriteComponent.java b/src/main/java/io/wispforest/owo/ui/component/SpriteComponent.java index a4285ef2..cba8e6d7 100644 --- a/src/main/java/io/wispforest/owo/ui/component/SpriteComponent.java +++ b/src/main/java/io/wispforest/owo/ui/component/SpriteComponent.java @@ -43,7 +43,7 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial RenderSystem.defaultBlendFunc(); } - context.drawSprite(identifier -> OwoUIRenderLayers.getGuiTextured(identifier, this.blend), this.sprite, this.x, this.y, this.width, this.height); + context.drawSpriteStretched(identifier -> OwoUIRenderLayers.getGuiTextured(identifier, this.blend), this.sprite, this.x, this.y, this.width, this.height); if (this.blend) { RenderSystem.disableBlend(); From 39728ef44a62f25757a917e6579e357b414c9fbe Mon Sep 17 00:00:00 2001 From: glisco Date: Tue, 22 Oct 2024 23:49:17 +0200 Subject: [PATCH 7/8] [ui] fix RenderEffectWrapper, SlimSliderComponent and SmallCheckboxComponent, compile against 1.21.2 proper --- gradle.properties | 4 ++-- .../owo/mixin/ui/RenderPhaseMixin.java | 22 +++++++++++++++++++ .../owo/ui/component/SlimSliderComponent.java | 13 +++++------ .../ui/component/SmallCheckboxComponent.java | 4 ++-- .../owo/ui/container/RenderEffectWrapper.java | 15 ++++++++++++- src/main/resources/owo.mixins.json | 7 +++--- .../uwu/client/ComponentTestScreen.java | 2 +- 7 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 src/main/java/io/wispforest/owo/mixin/ui/RenderPhaseMixin.java diff --git a/gradle.properties b/gradle.properties index 1b45f7c4..22653b88 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx2G # Fabric Properties # check these on https://fabricmc.net/develop minecraft_base_version=1.21.2 -minecraft_version=1.21.2-rc2 -yarn_mappings=1.21.2-rc2+build.1 +minecraft_version=1.21.2 +yarn_mappings=1.21.2+build.1 loader_version=0.16.7 # Mod Properties mod_version=0.12.15 diff --git a/src/main/java/io/wispforest/owo/mixin/ui/RenderPhaseMixin.java b/src/main/java/io/wispforest/owo/mixin/ui/RenderPhaseMixin.java new file mode 100644 index 00000000..b692d5f2 --- /dev/null +++ b/src/main/java/io/wispforest/owo/mixin/ui/RenderPhaseMixin.java @@ -0,0 +1,22 @@ +package io.wispforest.owo.mixin.ui; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import io.wispforest.owo.ui.container.RenderEffectWrapper; +import net.minecraft.client.gl.Framebuffer; +import net.minecraft.client.render.RenderPhase; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(RenderPhase.class) +public class RenderPhaseMixin { + + @ModifyExpressionValue(method = "method_62272", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;getFramebuffer()Lnet/minecraft/client/gl/Framebuffer;")) + private static Framebuffer injectProperRenderTarget(Framebuffer original) { + if (RenderEffectWrapper.currentFramebuffer() != null) { + return RenderEffectWrapper.currentFramebuffer(); + } + + return original; + } + +} diff --git a/src/main/java/io/wispforest/owo/ui/component/SlimSliderComponent.java b/src/main/java/io/wispforest/owo/ui/component/SlimSliderComponent.java index 60a231b9..9843e10d 100644 --- a/src/main/java/io/wispforest/owo/ui/component/SlimSliderComponent.java +++ b/src/main/java/io/wispforest/owo/ui/component/SlimSliderComponent.java @@ -1,6 +1,5 @@ package io.wispforest.owo.ui.component; -import com.mojang.blaze3d.systems.RenderSystem; import io.wispforest.owo.ui.base.BaseComponent; import io.wispforest.owo.ui.core.Component; import io.wispforest.owo.ui.core.CursorStyle; @@ -75,10 +74,10 @@ protected int determineVerticalContentSize(Sizing sizing) { public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partialTicks, float delta) { if (this.axis == Axis.HORIZONTAL) { NinePatchTexture.draw(TRACK_TEXTURE, context, this.x + 1, this.y + 3, this.width - 2, 3); - context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, (int) (this.x + (this.width - 4) * this.value.get()), this.y + 1, 4, 7, 0, 3, 4, 7, 16, 16); + context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, (int) (this.x + (this.width - 4) * this.value.get()), this.y + 1, 0, 3, 4, 7, 4, 7, 16, 16); } else { NinePatchTexture.draw(TRACK_TEXTURE, context, this.x + 3, this.y + 1, 3, this.height - 2); - context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.x + 1, (int) (this.y + (this.height - 4) * this.value.get()), 7, 4, 4, 3, 7, 4, 16, 16); + context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.x + 1, (int) (this.y + (this.height - 4) * this.value.get()), 4, 3, 7, 4, 7, 4, 16, 16); } } @@ -105,8 +104,8 @@ public boolean onMouseUp(double mouseX, double mouseY, int button) { protected void setValueFromMouse(double mouseX, double mouseY) { this.value(this.axis == Axis.VERTICAL - ? this.min + (mouseY / this.height) * (this.max - this.min) - : this.min + (mouseX / this.width) * (this.max - this.min)); + ? this.min + (mouseY / this.height) * (this.max - this.min) + : this.min + (mouseX / this.width) * (this.max - this.min)); } @Override @@ -194,8 +193,8 @@ public void parseProperties(UIModel model, Element element, Map public static Component parse(Element element) { return element.getAttribute("direction").equals("vertical") - ? new SlimSliderComponent(Axis.VERTICAL) - : new SlimSliderComponent(Axis.HORIZONTAL); + ? new SlimSliderComponent(Axis.VERTICAL) + : new SlimSliderComponent(Axis.HORIZONTAL); } public static Function valueTooltipSupplier(int decimalPlaces) { diff --git a/src/main/java/io/wispforest/owo/ui/component/SmallCheckboxComponent.java b/src/main/java/io/wispforest/owo/ui/component/SmallCheckboxComponent.java index c3491bf3..ef1b3b8f 100644 --- a/src/main/java/io/wispforest/owo/ui/component/SmallCheckboxComponent.java +++ b/src/main/java/io/wispforest/owo/ui/component/SmallCheckboxComponent.java @@ -48,9 +48,9 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial context.drawText(MinecraftClient.getInstance().textRenderer, this.label.get(), this.x + 13 + 2, this.y + 3, Color.WHITE.argb(), this.labelShadow); } - context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.x, this.y, 13, 13, 0, 0, 13, 13, 32, 16); + context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.x, this.y, 0, 0, 13, 13, 13, 13, 32, 16); if (this.checked) { - context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.x, this.y, 13, 13, 16, 0, 13, 13, 32, 16); + context.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.x, this.y, 16, 0, 13, 13, 13, 13, 32, 16); } } diff --git a/src/main/java/io/wispforest/owo/ui/container/RenderEffectWrapper.java b/src/main/java/io/wispforest/owo/ui/container/RenderEffectWrapper.java index 2c6d41ed..bfc910be 100644 --- a/src/main/java/io/wispforest/owo/ui/container/RenderEffectWrapper.java +++ b/src/main/java/io/wispforest/owo/ui/container/RenderEffectWrapper.java @@ -14,12 +14,12 @@ import net.minecraft.client.gl.SimpleFramebuffer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.BufferRenderer; -import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.math.RotationAxis; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import org.joml.Matrix4f; import org.lwjgl.opengl.GL30; @@ -42,6 +42,8 @@ @ApiStatus.Experimental public class RenderEffectWrapper extends WrappingParentComponent { + private static @Nullable Framebuffer currentFramebuffer = null; + protected static final List FRAMEBUFFERS = new ArrayList<>(); protected static int drawDepth = 0; @@ -55,6 +57,7 @@ protected RenderEffectWrapper(C child) { @Override public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partialTicks, float delta) { super.draw(context, mouseX, mouseY, partialTicks, delta); + context.draw(); try { drawDepth++; @@ -70,9 +73,14 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial ScissorStack.drawUnclipped(framebuffer::clear); framebuffer.beginWrite(false); + var lastFramebuffer = currentFramebuffer; + currentFramebuffer = framebuffer; + this.drawChildren(context, mouseX, mouseY, partialTicks, delta, this.childView); + context.draw(); GlStateManager._glBindFramebuffer(GL30.GL_FRAMEBUFFER, previousFramebuffer); + currentFramebuffer = lastFramebuffer; var iter = this.effects.listIterator(); while (iter.hasNext()) { @@ -122,6 +130,11 @@ public void clearEffects() { this.effects.clear(); } + @ApiStatus.Internal + public static @Nullable Framebuffer currentFramebuffer() { + return currentFramebuffer; + } + static { WindowResizeCallback.EVENT.register((client, window) -> { FRAMEBUFFERS.forEach(framebuffer -> { diff --git a/src/main/resources/owo.mixins.json b/src/main/resources/owo.mixins.json index 940e972f..041202b3 100644 --- a/src/main/resources/owo.mixins.json +++ b/src/main/resources/owo.mixins.json @@ -23,10 +23,10 @@ "ServerPlayerInteractionManagerMixin", "SetComponentsLootFunctionAccessor", "TagGroupLoaderMixin", - "ext.MergedComponentMapAccessor", - "ext.MergedComponentMapMixin", "ext.ItemMixin", "ext.ItemStackMixin", + "ext.MergedComponentMapAccessor", + "ext.MergedComponentMapMixin", "itemgroup.ItemGroupAccessor", "itemgroup.ItemMixin", "itemgroup.ItemSettingsMixin", @@ -54,10 +54,10 @@ "ClientLoginNetworkHandlerAccessor", "DrawContextMixin", "MinecraftClientMixin", - "itemgroup.StatusEffectsDisplayMixin", "itemgroup.CreativeInventoryScreenAccessor", "itemgroup.CreativeInventoryScreenMixin", "itemgroup.MixinCreativeInventoryScreenMixin", + "itemgroup.StatusEffectsDisplayMixin", "shader.ShaderProgramAccessor", "text.TranslationStorageMixin", "tweaks.OperatingSystemMixin", @@ -70,6 +70,7 @@ "ui.EntityRendererMixin", "ui.HandledScreenMixin", "ui.MinecraftClientMixin", + "ui.RenderPhaseMixin", "ui.RenderSystemMixin", "ui.ScreenMixin", "ui.SliderWidgetMixin", diff --git a/src/testmod/java/io/wispforest/uwu/client/ComponentTestScreen.java b/src/testmod/java/io/wispforest/uwu/client/ComponentTestScreen.java index 050d9e49..55a98673 100644 --- a/src/testmod/java/io/wispforest/uwu/client/ComponentTestScreen.java +++ b/src/testmod/java/io/wispforest/uwu/client/ComponentTestScreen.java @@ -275,7 +275,7 @@ protected void init() { .selectedColor(Color.ofArgb(0x7F3955E5)) .sizing(Sizing.fixed(160), Sizing.fixed(100)) ).padding(Insets.of(5)).surface(Surface.DARK_PANEL) - )); + ).zIndex(1000)); }) ); From c4cad0054e23755105bf9a84d8dbe0b72a12f31b Mon Sep 17 00:00:00 2001 From: Dragon-Seeker Date: Tue, 22 Oct 2024 19:01:28 -0500 Subject: [PATCH 8/8] Remove mixin into mouseScrolled and just override method within BaseOwoHandledScreen --- .../io/wispforest/owo/mixin/ui/HandledScreenMixin.java | 10 ---------- .../wispforest/owo/ui/base/BaseOwoHandledScreen.java | 5 +++++ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/wispforest/owo/mixin/ui/HandledScreenMixin.java b/src/main/java/io/wispforest/owo/mixin/ui/HandledScreenMixin.java index 435b2f95..8fc57f01 100644 --- a/src/main/java/io/wispforest/owo/mixin/ui/HandledScreenMixin.java +++ b/src/main/java/io/wispforest/owo/mixin/ui/HandledScreenMixin.java @@ -92,14 +92,4 @@ private void closeIt(int keyCode, int scanCode, int modifiers, CallbackInfoRetur cir.setReturnValue(true); } } - - // Fixes issues with scrolling with screens extending Handled and using UIAdapter - @WrapMethod(method = "mouseScrolled") - private boolean owo$useSuperMouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount, Operation original){ - var bl = original.call(mouseX, mouseY, horizontalAmount, verticalAmount); - - if (bl) return true; - - return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); - } } diff --git a/src/main/java/io/wispforest/owo/ui/base/BaseOwoHandledScreen.java b/src/main/java/io/wispforest/owo/ui/base/BaseOwoHandledScreen.java index 2eaaf5bb..84932278 100644 --- a/src/main/java/io/wispforest/owo/ui/base/BaseOwoHandledScreen.java +++ b/src/main/java/io/wispforest/owo/ui/base/BaseOwoHandledScreen.java @@ -205,6 +205,11 @@ public boolean mouseDragged(double mouseX, double mouseY, int button, double del return this.uiAdapter.mouseDragged(mouseX, mouseY, button, deltaX, deltaY) || super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); } + @Override + public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { + return this.uiAdapter.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount) || super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); + } + @Nullable @Override public Element getFocused() {