3030import net .minecraftforge .fluids .FluidTank ;
3131import net .minecraftforge .fluids .IFluidTank ;
3232import net .minecraftforge .fluids .capability .CapabilityFluidHandler ;
33+ import net .minecraftforge .fluids .capability .IFluidHandlerItem ;
34+ import net .minecraftforge .fluids .capability .IFluidTankProperties ;
3335
36+ import mezz .jei .Internal ;
3437import org .jetbrains .annotations .NotNull ;
3538import org .jetbrains .annotations .Nullable ;
3639import org .lwjgl .input .Keyboard ;
@@ -162,6 +165,7 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) {
162165
163166 @ Override
164167 public void drawOverlay (ModularGuiContext context , WidgetTheme widgetTheme ) {
168+ super .drawOverlay (context , widgetTheme );
165169 if (ModularUI .Mods .JEI .isLoaded () && (ModularUIJeiPlugin .draggingValidIngredient (this ) || ModularUIJeiPlugin .hoveringOverIngredient (this ))) {
166170 GlStateManager .colorMask (true , true , true , false );
167171 drawHighlight (getArea (), isHovering ());
@@ -276,7 +280,7 @@ public FluidSlot syncHandler(FluidSlotSyncHandler syncHandler) {
276280 return this ;
277281 }
278282
279- /* === Jei ghost slot === */
283+ /* === Recipe viewer ghost slot === */
280284
281285 @ Override
282286 public void setGhostIngredient (@ NotNull FluidStack ingredient ) {
@@ -287,7 +291,17 @@ public void setGhostIngredient(@NotNull FluidStack ingredient) {
287291
288292 @ Override
289293 public @ Nullable FluidStack castGhostIngredientIfValid (@ NotNull Object ingredient ) {
290- return areAncestorsEnabled () && this .syncHandler .isPhantom () && ingredient instanceof FluidStack fluidStack ? fluidStack : null ;
294+ if (!this .syncHandler .isPhantom () || !areAncestorsEnabled ()) return null ;
295+ if (ingredient instanceof FluidStack fluidStack ) return fluidStack ; // is fluid stack
296+
297+ // turn into an item and check if it contains exactly one fluid
298+ ItemStack stack = Internal .getIngredientRegistry ().getIngredientHelper (ingredient ).getCheatItemStack (ingredient );
299+ if (stack .isEmpty ()) return null ;
300+ IFluidHandlerItem fluidHandlerItem = stack .getCapability (CapabilityFluidHandler .FLUID_HANDLER_ITEM_CAPABILITY , null );
301+ if (fluidHandlerItem == null ) return null ;
302+ IFluidTankProperties [] fluidTanks = fluidHandlerItem .getTankProperties ();
303+ if (fluidTanks .length != 1 || fluidTanks [0 ].getContents () == null ) return null ;
304+ return fluidTanks [0 ].getContents ().copy ();
291305 }
292306
293307 @ Override
0 commit comments