Skip to content

Commit

Permalink
Attempt to fix mixin conflicts with neo
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon-Seeker committed Apr 17, 2024
1 parent afedf9b commit 5f9b4d4
Show file tree
Hide file tree
Showing 12 changed files with 538 additions and 124 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false
}

architectury {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package io.wispforest.condensed_creative.client;

import com.mojang.blaze3d.systems.RenderSystem;
import io.wispforest.condensed_creative.CondensedCreative;
import io.wispforest.condensed_creative.entry.Entry;
import io.wispforest.condensed_creative.entry.impl.CondensedItemEntry;
import io.wispforest.condensed_creative.util.CondensedInventory;
import me.shedaniel.math.Color;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.screen.slot.Slot;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

public class SlotRenderUtils {

private static final Identifier PLUS_ICON = CondensedCreative.createID("textures/gui/plus_logo.png");
private static final Identifier MINUS_ICON = CondensedCreative.createID("textures/gui/minus_logo.png");

public static void renderExtraIfEntry(HandledScreen screen, DrawContext context, Slot slot){
if(!(screen instanceof CreativeInventoryScreen && slot.inventory instanceof CondensedInventory inv)) return;

Entry entryStack = inv.getEntryStack(slot.getIndex());

if(!(entryStack instanceof CondensedItemEntry entry)) return;

int minX = slot.x;
int minY = slot.y;

int maxX = minX + 16;
int maxY = minY + 16;

if(CondensedItemEntry.CHILD_VISIBILITY.get(entry.condensedID)) {
Color backgroundColor = Color.ofTransparent(0x7F111111);//Color.ofRGBA(186, 186, 186, 255);

if(CondensedCreative.getConfig().entryBackgroundColor) {
var offset = CondensedCreative.getConfig().entryBorderColor ? 0 : 1;

context.fill(minX - offset, minY - offset, maxX + offset, maxY + offset, backgroundColor.getColor());
}

if(CondensedCreative.getConfig().entryBorderColor) {
RenderSystem.enableBlend();

Color outlineColor = Color.ofTransparent(CondensedCreative.getConfig().condensedEntryBorderColor);//Color.ofRGBA(251, 255, 0, 128);

if (!isSlotAbovePartOfCondensedEntry(slot, entry.condensedID)) {
context.fill(minX - 1, minY - 1, maxX + 1, maxY - 16, outlineColor.getColor());
}

if (!isSlotBelowPartOfCondensedEntry(slot, entry.condensedID)) {
context.fill(minX - 1, minY + 16, maxX + 1, maxY + 1, outlineColor.getColor());
}

if (!isSlotRightPartOfCondensedEntry(slot, entry.condensedID)) {
context.fill(minX + 16, minY - 1, maxX + 1, maxY + 1, outlineColor.getColor());
}

if (!isSlotLeftPartOfCondensedEntry(slot, entry.condensedID)) {
context.fill(minX - 1, minY - 1, maxX - 16, maxY + 1, outlineColor.getColor());
}
}

RenderSystem.disableBlend();
}

if(!entry.isChild) {
Identifier id = !CondensedItemEntry.CHILD_VISIBILITY.get(entry.condensedID) ? PLUS_ICON : MINUS_ICON;

context.drawTexture(id, minX, minY, 160, 0, 0, 16, 16, 16, 16);
}
}

@Unique
public static boolean isSlotAbovePartOfCondensedEntry(Slot slot, Identifier condensedID){
int topSlotIndex = slot.getIndex() - 9;

return topSlotIndex >= 0 &&
((CondensedInventory) slot.inventory).getEntryStack(topSlotIndex) instanceof CondensedItemEntry condensedItemEntry &&
condensedID == condensedItemEntry.condensedID;
}

@Unique
public static boolean isSlotBelowPartOfCondensedEntry(Slot slot, Identifier condensedID){
int bottomSlotIndex = slot.getIndex() + 9;

return bottomSlotIndex < slot.inventory.size() &&
((CondensedInventory) slot.inventory).getEntryStack(bottomSlotIndex) instanceof CondensedItemEntry condensedItemEntry &&
condensedID == condensedItemEntry.condensedID;
}

@Unique
public static boolean isSlotLeftPartOfCondensedEntry(Slot slot, Identifier condensedID){
if(((slot.id) % 9 == 0)) return false;

int leftSlotIndex = slot.getIndex() - 1;

return leftSlotIndex < slot.inventory.size() &&
((CondensedInventory) slot.inventory).getEntryStack(leftSlotIndex) instanceof CondensedItemEntry condensedItemEntry &&
condensedID == condensedItemEntry.condensedID;
}

@Unique
public static boolean isSlotRightPartOfCondensedEntry(Slot slot, Identifier condensedID){
if(((slot.id) % 9 == 8)) return false;

int rightSlotIndex = slot.getIndex() + 1;

return rightSlotIndex < slot.inventory.size() &&
((CondensedInventory) slot.inventory).getEntryStack(rightSlotIndex) instanceof CondensedItemEntry condensedItemEntry &&
condensedID == condensedItemEntry.condensedID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.collection.DefaultedList;

import java.util.Collection;

public interface CreativeInventoryScreenHandlerDuck {

void markEntryListDirty();

DefaultedList<Entry> getDefaultEntryList();

default void addToDefaultEntryList(ItemStack stack) {
this.getDefaultEntryList().add(Entry.of(stack));
default boolean addToDefaultEntryList(ItemStack stack) {
return this.getDefaultEntryList().add(Entry.of(stack));
}

default boolean addToDefaultEntryList(Collection<ItemStack> stacks) {
return this.getDefaultEntryList().addAll(stacks.stream().map(Entry::of).toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import io.wispforest.condensed_creative.CondensedCreative;
import io.wispforest.condensed_creative.compat.ItemGroupVariantHandler;
import io.wispforest.condensed_creative.ducks.CreativeInventoryScreenHandlerDuck;
Expand Down Expand Up @@ -53,6 +54,7 @@
import java.util.function.Predicate;

@Mixin(CreativeInventoryScreen.class)
@Debug(export = true)
public abstract class CreativeInventoryScreenMixin extends AbstractInventoryScreen<CreativeInventoryScreen.CreativeScreenHandler> {

@Shadow @Final @Mutable public static SimpleInventory INVENTORY;
Expand Down Expand Up @@ -125,20 +127,24 @@ private void testToReplaceTooltipText(ItemStack stack, CallbackInfoReturnable<Li
this.validItemGroupForCondensedEntries = false;
}

@Inject(method = "setSelectedTab", at = {
@At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;add(Ljava/lang/Object;)Z", ordinal = 0, shift = At.Shift.BY, by = 2),
@At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;add(Ljava/lang/Object;)Z", ordinal = 1, shift = At.Shift.BY, by = 2)})
private void setSelectedTab$addStackToEntryList(ItemGroup group, CallbackInfo ci){
this.getHandlerDuck().addToDefaultEntryList(this.handler.itemList.get(this.handler.itemList.size() - 1));
@WrapOperation(method = "setSelectedTab", at = {
@At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;add(Ljava/lang/Object;)Z", ordinal = 0),
@At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;add(Ljava/lang/Object;)Z", ordinal = 1)})
private boolean setSelectedTab$addStackToEntryList(DefaultedList list, Object object, Operation<Boolean> operation){
operation.call(list, object);

return this.getHandlerDuck().addToDefaultEntryList((ItemStack) object);
}

@Inject(method = "setSelectedTab", at = {
@At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;addAll(Ljava/util/Collection;)Z",ordinal = 0, shift = At.Shift.BY, by = 2),
@At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;addAll(Ljava/util/Collection;)Z", ordinal = 1, shift = At.Shift.BY, by = 1)})
private void setSelectedTab$addStacksToEntryList(ItemGroup group, CallbackInfo ci){
this.handler.itemList.forEach(stack -> getHandlerDuck().addToDefaultEntryList(stack));
@WrapOperation(method = "setSelectedTab", at = {
@At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;addAll(Ljava/util/Collection;)Z", ordinal = 0),
@At(value = "INVOKE", target = "Lnet/minecraft/util/collection/DefaultedList;addAll(Ljava/util/Collection;)Z", ordinal = 1)})
private boolean setSelectedTab$addStacksToEntryList(DefaultedList list, Collection collection, Operation<Boolean> operation, @Local(argsOnly = true) ItemGroup group){
operation.call(list, collection);

if(group != Registries.ITEM_GROUP.get(ItemGroups.HOTBAR)) this.validItemGroupForCondensedEntries = true;

return getHandlerDuck().addToDefaultEntryList((Collection<ItemStack>) collection);
}

//-------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
package io.wispforest.condensed_creative.mixins.client;

import com.mojang.blaze3d.systems.RenderSystem;
import io.wispforest.condensed_creative.CondensedCreative;
import io.wispforest.condensed_creative.entry.Entry;
import io.wispforest.condensed_creative.entry.impl.CondensedItemEntry;
import io.wispforest.condensed_creative.util.CondensedInventory;
import me.shedaniel.math.Color;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.util.Identifier;
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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(HandledScreen.class)
public abstract class HandledScreenMixin<T extends ScreenHandler> {

@Unique private static final Identifier PLUS_ICON = CondensedCreative.createID("textures/gui/plus_logo.png");
@Unique private static final Identifier MINUS_ICON = CondensedCreative.createID("textures/gui/minus_logo.png");

@ModifyVariable(method = "drawSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;getStack()Lnet/minecraft/item/ItemStack;", ordinal = 0, shift = At.Shift.BY, by = 2))
private ItemStack changeDisplayedStackIfParent(ItemStack stack, DrawContext matrices, Slot slot){
if(slot.inventory instanceof CondensedInventory inv && inv.getEntryStack(slot.id) instanceof CondensedItemEntry entry && !entry.isChild){
Expand All @@ -40,99 +28,4 @@ private ItemStack changeDisplayedStackIfParent(ItemStack stack, DrawContext matr

return stack;
}

@Inject(method = "drawSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", shift = At.Shift.BY, by = 1))
private void renderExtraIfEntry(DrawContext context, Slot slot, CallbackInfo ci){
if(!(((Object) this) instanceof CreativeInventoryScreen && slot.inventory instanceof CondensedInventory inv)) return;

Entry entryStack = inv.getEntryStack(slot.getIndex());

if(!(entryStack instanceof CondensedItemEntry entry)) return;

int minX = slot.x;
int minY = slot.y;

int maxX = minX + 16;
int maxY = minY + 16;

if(CondensedItemEntry.CHILD_VISIBILITY.get(entry.condensedID)) {
Color backgroundColor = Color.ofTransparent(0x7F111111);//Color.ofRGBA(186, 186, 186, 255);

if(CondensedCreative.getConfig().entryBackgroundColor) {
var offset = CondensedCreative.getConfig().entryBorderColor ? 0 : 1;

context.fill(minX - offset, minY - offset, maxX + offset, maxY + offset, backgroundColor.getColor());
}

if(CondensedCreative.getConfig().entryBorderColor) {
RenderSystem.enableBlend();

Color outlineColor = Color.ofTransparent(CondensedCreative.getConfig().condensedEntryBorderColor);//Color.ofRGBA(251, 255, 0, 128);

if (!isSlotAbovePartOfCondensedEntry(slot, entry.condensedID)) {
context.fill(minX - 1, minY - 1, maxX + 1, maxY - 16, outlineColor.getColor());
}

if (!isSlotBelowPartOfCondensedEntry(slot, entry.condensedID)) {
context.fill(minX - 1, minY + 16, maxX + 1, maxY + 1, outlineColor.getColor());
}

if (!isSlotRightPartOfCondensedEntry(slot, entry.condensedID)) {
context.fill(minX + 16, minY - 1, maxX + 1, maxY + 1, outlineColor.getColor());
}

if (!isSlotLeftPartOfCondensedEntry(slot, entry.condensedID)) {
context.fill(minX - 1, minY - 1, maxX - 16, maxY + 1, outlineColor.getColor());
}
}

RenderSystem.disableBlend();
}

if(!entry.isChild) {
Identifier id = !CondensedItemEntry.CHILD_VISIBILITY.get(entry.condensedID) ? PLUS_ICON : MINUS_ICON;

context.drawTexture(id, minX, minY, 160, 0, 0, 16, 16, 16, 16);
}
}

@Unique
public boolean isSlotAbovePartOfCondensedEntry(Slot slot, Identifier condensedID){
int topSlotIndex = slot.getIndex() - 9;

return topSlotIndex >= 0 &&
((CondensedInventory) slot.inventory).getEntryStack(topSlotIndex) instanceof CondensedItemEntry condensedItemEntry &&
condensedID == condensedItemEntry.condensedID;
}

@Unique
public boolean isSlotBelowPartOfCondensedEntry(Slot slot, Identifier condensedID){
int bottomSlotIndex = slot.getIndex() + 9;

return bottomSlotIndex < slot.inventory.size() &&
((CondensedInventory) slot.inventory).getEntryStack(bottomSlotIndex) instanceof CondensedItemEntry condensedItemEntry &&
condensedID == condensedItemEntry.condensedID;
}

@Unique
public boolean isSlotLeftPartOfCondensedEntry(Slot slot, Identifier condensedID){
if(((slot.id) % 9 == 0)) return false;

int leftSlotIndex = slot.getIndex() - 1;

return leftSlotIndex < slot.inventory.size() &&
((CondensedInventory) slot.inventory).getEntryStack(leftSlotIndex) instanceof CondensedItemEntry condensedItemEntry &&
condensedID == condensedItemEntry.condensedID;
}

@Unique
public boolean isSlotRightPartOfCondensedEntry(Slot slot, Identifier condensedID){
if(((slot.id) % 9 == 8)) return false;

int rightSlotIndex = slot.getIndex() + 1;

return rightSlotIndex < slot.inventory.size() &&
((CondensedInventory) slot.inventory).getEntryStack(rightSlotIndex) instanceof CondensedItemEntry condensedItemEntry &&
condensedID == condensedItemEntry.condensedID;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.wispforest.condensed_creative.fabric.mixins.client;

import io.wispforest.condensed_creative.client.SlotRenderUtils;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
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;

@Mixin(HandledScreen.class)
public abstract class HandledScreenMixin<T extends ScreenHandler> {

@Inject(method = "drawSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", shift = At.Shift.BY, by = 1))
private void renderExtraIfEntry(DrawContext context, Slot slot, CallbackInfo ci){
SlotRenderUtils.renderExtraIfEntry((HandledScreen) (Object) this, context, slot);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"required": true,
"package": "io.wispforest.condensed_creative.mixins.fabric",
"package": "io.wispforest.condensed_creative.fabric.mixins",
"compatibilityLevel": "JAVA_17",
"client": [
"client.HandledScreenMixin"
],
"mixins": [
],
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ org.gradle.jvmargs=-Xmx4G

# Loader Versions
fabric_loader_version = 0.15.10
fabric_api_version = 0.97.0+1.20.4
fabric_api_version = 0.95.4+1.20.4

# NeoForge Dependencies
neoforge_version = 20.4.46-beta
neoforge_version = 20.4.232

# Forge Dependencies
forge_version = 1.20.4-49.0.12
Expand Down
Loading

0 comments on commit 5f9b4d4

Please sign in to comment.