Skip to content

Commit

Permalink
Merge pull request #324 from Dragon-Seeker/1.21.2-Port_Ver2
Browse files Browse the repository at this point in the history
1.21.2 Port
  • Loading branch information
gliscowo authored Oct 23, 2024
2 parents d76a9a7 + c4cad00 commit 041a308
Show file tree
Hide file tree
Showing 79 changed files with 862 additions and 775 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}

Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
yarn_mappings=1.21.2+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.100.1+1.21
fabric_version=0.106.1+1.21.2

# https://maven.shedaniel.me/me/shedaniel/RoughlyEnoughItems-fabric/
rei_version=15.0.728
Expand All @@ -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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
11 changes: 9 additions & 2 deletions src/main/java/io/wispforest/owo/client/OwoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,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.loadAndSetupPrograms(); }
});

final var renderdocPath = System.getProperty("owo.renderdocPath");
if (renderdocPath != null) {
Expand All @@ -72,7 +78,8 @@ public void onInitializeClient() {

ClientCommandRegistrationCallback.EVENT.register(OwoConfigCommand::register);

if (!Owo.DEBUG) return;
OwoDebugCommands.Client.register();
if (Owo.DEBUG) {
OwoDebugCommands.Client.register();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/io/wispforest/owo/compat/rei/OwoReiPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/wispforest/owo/ext/DerivedComponentMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/wispforest/owo/itemgroup/Icon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

@Mixin(RegistryOps.CachedRegistryInfoGetter.class)
public interface CachedRegistryInfoGetterAccessor {
@Accessor("registriesLookup") RegistryWrapper.WrapperLookup owo$getRegistriesLookup();
@Accessor("registries") RegistryWrapper.WrapperLookup owo$getRegistriesLookup();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ActionResult> 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()));
}
}

}
17 changes: 9 additions & 8 deletions src/main/java/io/wispforest/owo/mixin/ext/ItemStackMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = "<init>(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 = "<init>(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 = "<init>(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 = "<init>(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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
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;
import net.minecraft.item.ItemGroup;
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;
Expand All @@ -35,7 +34,7 @@
import java.util.function.Consumer;

@Mixin(CreativeInventoryScreen.class)
public abstract class CreativeInventoryScreenMixin extends AbstractInventoryScreen<CreativeInventoryScreen.CreativeScreenHandler> implements OwoCreativeInventoryScreenExtensions {
public abstract class CreativeInventoryScreenMixin extends HandledScreen<CreativeInventoryScreen.CreativeScreenHandler> implements OwoCreativeInventoryScreenExtensions {

@Shadow
private static ItemGroup selectedTab;
Expand Down Expand Up @@ -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();
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit 041a308

Please sign in to comment.