Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import mezz.jei.gui.ghost.GhostIngredientDrag;
import mezz.jei.gui.ghost.GhostIngredientDragManager;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(value = GhostIngredientDragManager.class, remap = false)
public interface GhostIngredientDragManagerAccessor {

@Accessor
GhostIngredientDrag<?> getGhostIngredientDrag();
@Nullable GhostIngredientDrag<?> getGhostIngredientDrag();

@Accessor
Object getHoveredIngredient();
@Nullable Object getHoveredIngredient();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import mezz.jei.gui.ghost.GhostIngredientDrag;
import mezz.jei.gui.ghost.GhostIngredientDragManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@JEIPlugin
public class ModularUIJeiPlugin implements IModPlugin {
Expand All @@ -30,7 +31,7 @@ public void register(@NotNull IModRegistry registry) {
}

@Override
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
public void onRuntimeAvailable(@NotNull IJeiRuntime jeiRuntime) {
ModularUIJeiPlugin.runtime = jeiRuntime;
}

Expand All @@ -49,10 +50,24 @@ public static boolean hoveringOverIngredient(JeiGhostIngredientSlot<?> ingredien
return ingredientSlot.castGhostIngredientIfValid(hovered) != null;
}

public static boolean draggingValidIngredient(JeiGhostIngredientSlot<?> ingredientSlot) {
Object dragging = getDraggedObject();
if (dragging == null) return false;
return ingredientSlot.castGhostIngredientIfValid(dragging) != null;
}

@Nullable
public static GhostIngredientDrag<?> getGhostDrag() {
return ((GhostIngredientDragManagerAccessor) getGhostDragManager()).getGhostIngredientDrag();
}

@Nullable
public static Object getDraggedObject() {
GhostIngredientDrag<?> drag = getGhostDrag();
return drag == null ? null : drag.getIngredient();
}

@Nullable
public static Object getHoverdObject() {
return ((GhostIngredientDragManagerAccessor) getGhostDragManager()).getHoveredIngredient();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cleanroommc.modularui.widgets.slot;

import com.cleanroommc.modularui.ModularUI;
import com.cleanroommc.modularui.api.ITheme;
import com.cleanroommc.modularui.api.drawable.IDrawable;
import com.cleanroommc.modularui.api.drawable.IKey;
Expand All @@ -8,6 +9,7 @@
import com.cleanroommc.modularui.drawable.text.TextRenderer;
import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot;
import com.cleanroommc.modularui.integration.jei.JeiIngredientProvider;
import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin;
import com.cleanroommc.modularui.screen.ModularScreen;
import com.cleanroommc.modularui.screen.RichTooltip;
import com.cleanroommc.modularui.screen.viewport.ModularGuiContext;
Expand Down Expand Up @@ -156,7 +158,15 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) {
this.textRenderer.setPos((int) (this.contentOffsetX + 0.5f), (int) (getArea().height - 5.5f));
this.textRenderer.draw(s);
}
if (isHovering()) {
}

@Override
public void drawOverlay(ModularGuiContext context, WidgetTheme widgetTheme) {
if (ModularUI.Mods.JEI.isLoaded() && (ModularUIJeiPlugin.draggingValidIngredient(this) || ModularUIJeiPlugin.hoveringOverIngredient(this))) {
GlStateManager.colorMask(true, true, true, false);
drawHighlight(getArea(), isHovering());
GlStateManager.colorMask(true, true, true, true);
} else if (isHovering()) {
GlStateManager.colorMask(true, true, true, false);
GuiDraw.drawRect(1, 1, getArea().w() - 2, getArea().h() - 2, getSlotHoverColor());
GlStateManager.colorMask(true, true, true, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import com.cleanroommc.modularui.value.sync.PhantomItemSlotSH;
import com.cleanroommc.modularui.value.sync.SyncHandler;

import mezz.jei.Internal;

import net.minecraft.client.renderer.GlStateManager;

import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.item.ItemStack;

import org.jetbrains.annotations.NotNull;
Expand All @@ -33,7 +36,7 @@ public boolean isValidSyncHandler(SyncHandler syncHandler) {

@Override
protected void drawOverlay() {
if (ModularUI.Mods.JEI.isLoaded() && (ModularUIJeiPlugin.hasDraggingGhostIngredient() || ModularUIJeiPlugin.hoveringOverIngredient(this))) {
if (ModularUI.Mods.JEI.isLoaded() && (ModularUIJeiPlugin.draggingValidIngredient(this) || ModularUIJeiPlugin.hoveringOverIngredient(this))) {
GlStateManager.colorMask(true, true, true, false);
drawHighlight(getArea(), isHovering());
GlStateManager.colorMask(true, true, true, true);
Expand Down Expand Up @@ -73,10 +76,17 @@ public void setGhostIngredient(@NotNull ItemStack ingredient) {

@Override
public @Nullable ItemStack castGhostIngredientIfValid(@NotNull Object ingredient) {
return areAncestorsEnabled() &&
this.syncHandler.isPhantom() &&
ingredient instanceof ItemStack itemStack &&
this.syncHandler.isItemValid(itemStack) ? itemStack : null;
if (areAncestorsEnabled() && this.syncHandler.isPhantom()) {
if (ingredient instanceof EnchantmentData enchantmentData) {
ingredient = Internal.getIngredientRegistry().getIngredientHelper(enchantmentData).getCheatItemStack(enchantmentData);
}

if (ingredient instanceof ItemStack itemStack) {
return this.syncHandler.isItemValid(itemStack) ? itemStack : null;
}
}

return null;
}

@Override
Expand Down