Added support for JEI ghost slot dragging. Fixes #1892
This commit is contained in:
		@@ -3,6 +3,7 @@
 | 
			
		||||
### 1.6.1
 | 
			
		||||
- Added fluid autocrafting (raoulvdberge)
 | 
			
		||||
- Added Crafting Upgrade support for fluids on the Exporter, Constructor and Fluid Interface (raoulvdberge)
 | 
			
		||||
- Added support for JEI ghost slot dragging (raoulvdberge)
 | 
			
		||||
- You can now keep fluids in stock by attaching a External Storage in fluid mode to a Fluid Interface with a Crafting Upgrade (raoulvdberge)
 | 
			
		||||
- You can now specify the amount to export in the Fluid Interface (raoulvdberge)
 | 
			
		||||
- Made the Crafting Preview window bigger (raoulvdberge)
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,92 @@
 | 
			
		||||
package com.raoulvdberge.refinedstorage.integration.jei;
 | 
			
		||||
 | 
			
		||||
import com.raoulvdberge.refinedstorage.RS;
 | 
			
		||||
import com.raoulvdberge.refinedstorage.container.slot.SlotFilter;
 | 
			
		||||
import com.raoulvdberge.refinedstorage.container.slot.SlotFilterFluid;
 | 
			
		||||
import com.raoulvdberge.refinedstorage.container.slot.SlotFilterItemOrFluid;
 | 
			
		||||
import com.raoulvdberge.refinedstorage.container.slot.SlotFilterLegacy;
 | 
			
		||||
import com.raoulvdberge.refinedstorage.gui.GuiBase;
 | 
			
		||||
import com.raoulvdberge.refinedstorage.network.MessageFilterSlot;
 | 
			
		||||
import com.raoulvdberge.refinedstorage.tile.config.IType;
 | 
			
		||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
 | 
			
		||||
import mezz.jei.api.gui.IGhostIngredientHandler;
 | 
			
		||||
import net.minecraft.init.Items;
 | 
			
		||||
import net.minecraft.inventory.Slot;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraftforge.fluids.Fluid;
 | 
			
		||||
import net.minecraftforge.fluids.FluidStack;
 | 
			
		||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
 | 
			
		||||
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
 | 
			
		||||
 | 
			
		||||
import java.awt.*;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public class GhostIngredientHandler implements IGhostIngredientHandler<GuiBase> {
 | 
			
		||||
    @Override
 | 
			
		||||
    public <I> List<Target<I>> getTargets(GuiBase gui, I ingredient, boolean doStart) {
 | 
			
		||||
        List<Target<I>> targets = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
        for (Slot slot : gui.inventorySlots.inventorySlots) {
 | 
			
		||||
            if (!slot.isEnabled()) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Rectangle bounds = new Rectangle(gui.getGuiLeft() + slot.xPos, gui.getGuiTop() + slot.yPos, 17, 17);
 | 
			
		||||
 | 
			
		||||
            if (ingredient instanceof ItemStack) {
 | 
			
		||||
                if (slot instanceof SlotFilterItemOrFluid && ((SlotFilterItemOrFluid) slot).getType().getType() == IType.FLUIDS) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (slot instanceof SlotFilterLegacy || (slot instanceof SlotFilter && !(slot instanceof SlotFilterFluid))) {
 | 
			
		||||
                    targets.add(new Target<I>() {
 | 
			
		||||
                        @Override
 | 
			
		||||
                        public Rectangle getArea() {
 | 
			
		||||
                            return bounds;
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        @Override
 | 
			
		||||
                        public void accept(I ingredient) {
 | 
			
		||||
                            slot.putStack((ItemStack) ingredient);
 | 
			
		||||
 | 
			
		||||
                            RS.INSTANCE.network.sendToServer(new MessageFilterSlot(slot.slotNumber, (ItemStack) ingredient));
 | 
			
		||||
                        }
 | 
			
		||||
                    });
 | 
			
		||||
                }
 | 
			
		||||
            } else if (ingredient instanceof FluidStack) {
 | 
			
		||||
                if (slot instanceof SlotFilterFluid || (slot instanceof SlotFilterItemOrFluid && ((SlotFilterItemOrFluid) slot).getType().getType() == IType.FLUIDS)) {
 | 
			
		||||
                    targets.add(new Target<I>() {
 | 
			
		||||
                        @Override
 | 
			
		||||
                        public Rectangle getArea() {
 | 
			
		||||
                            return bounds;
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        @Override
 | 
			
		||||
                        public void accept(I ingredient) {
 | 
			
		||||
                            ItemStack filledContainer = new ItemStack(Items.BUCKET);
 | 
			
		||||
 | 
			
		||||
                            IFluidHandlerItem fluidHandler = filledContainer.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
 | 
			
		||||
 | 
			
		||||
                            fluidHandler.fill(StackUtils.copy((FluidStack) ingredient, Fluid.BUCKET_VOLUME), true);
 | 
			
		||||
 | 
			
		||||
                            filledContainer = fluidHandler.getContainer();
 | 
			
		||||
                            filledContainer.setCount(((FluidStack) ingredient).amount);
 | 
			
		||||
 | 
			
		||||
                            slot.putStack(filledContainer);
 | 
			
		||||
 | 
			
		||||
                            RS.INSTANCE.network.sendToServer(new MessageFilterSlot(slot.slotNumber, filledContainer));
 | 
			
		||||
                        }
 | 
			
		||||
                    });
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return targets;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onComplete() {
 | 
			
		||||
        // NO OP
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
package com.raoulvdberge.refinedstorage.integration.jei;
 | 
			
		||||
 | 
			
		||||
import com.raoulvdberge.refinedstorage.gui.GuiBase;
 | 
			
		||||
import mezz.jei.api.IJeiRuntime;
 | 
			
		||||
import mezz.jei.api.IModPlugin;
 | 
			
		||||
import mezz.jei.api.IModRegistry;
 | 
			
		||||
@@ -21,6 +22,8 @@ public class RSJEIPlugin implements IModPlugin {
 | 
			
		||||
 | 
			
		||||
        registry.addRecipeRegistryPlugin(new RecipeRegistryPluginCover());
 | 
			
		||||
        registry.addRecipeRegistryPlugin(new RecipeRegistryPluginHollowCover());
 | 
			
		||||
 | 
			
		||||
        registry.addGhostIngredientHandler(GuiBase.class, new GhostIngredientHandler());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,52 @@
 | 
			
		||||
package com.raoulvdberge.refinedstorage.network;
 | 
			
		||||
 | 
			
		||||
import com.raoulvdberge.refinedstorage.container.slot.SlotFilter;
 | 
			
		||||
import com.raoulvdberge.refinedstorage.container.slot.SlotFilterLegacy;
 | 
			
		||||
import io.netty.buffer.ByteBuf;
 | 
			
		||||
import net.minecraft.entity.player.EntityPlayerMP;
 | 
			
		||||
import net.minecraft.inventory.Container;
 | 
			
		||||
import net.minecraft.inventory.Slot;
 | 
			
		||||
import net.minecraft.item.ItemStack;
 | 
			
		||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
 | 
			
		||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
 | 
			
		||||
 | 
			
		||||
public class MessageFilterSlot extends MessageHandlerPlayerToServer<MessageFilterSlot> implements IMessage {
 | 
			
		||||
    private int containerSlot;
 | 
			
		||||
    private ItemStack stack;
 | 
			
		||||
 | 
			
		||||
    public MessageFilterSlot(int containerSlot, ItemStack stack) {
 | 
			
		||||
        this.containerSlot = containerSlot;
 | 
			
		||||
        this.stack = stack;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public MessageFilterSlot() {
 | 
			
		||||
        // NO OP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void handle(MessageFilterSlot message, EntityPlayerMP player) {
 | 
			
		||||
        Container container = player.openContainer;
 | 
			
		||||
 | 
			
		||||
        if (container != null) {
 | 
			
		||||
            if (message.containerSlot >= 0 && message.containerSlot < container.inventorySlots.size()) {
 | 
			
		||||
                Slot slot = container.getSlot(message.containerSlot);
 | 
			
		||||
 | 
			
		||||
                if (slot instanceof SlotFilter || slot instanceof SlotFilterLegacy) {
 | 
			
		||||
                    slot.putStack(message.stack);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void fromBytes(ByteBuf buf) {
 | 
			
		||||
        containerSlot = buf.readInt();
 | 
			
		||||
        stack = ByteBufUtils.readItemStack(buf);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void toBytes(ByteBuf buf) {
 | 
			
		||||
        buf.writeInt(containerSlot);
 | 
			
		||||
        ByteBufUtils.writeItemStack(buf, stack);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -189,6 +189,7 @@ public class ProxyCommon {
 | 
			
		||||
        RS.INSTANCE.network.registerMessage(MessageStorageDiskSizeResponse.class, MessageStorageDiskSizeResponse.class, id++, Side.CLIENT);
 | 
			
		||||
        RS.INSTANCE.network.registerMessage(MessageConfigSync.class, MessageConfigSync.class, id++, Side.CLIENT);
 | 
			
		||||
        RS.INSTANCE.network.registerMessage(MessageFluidAmount.class, MessageFluidAmount.class, id++, Side.SERVER);
 | 
			
		||||
        RS.INSTANCE.network.registerMessage(MessageFilterSlot.class, MessageFilterSlot.class, id++, Side.SERVER);
 | 
			
		||||
 | 
			
		||||
        NetworkRegistry.INSTANCE.registerGuiHandler(RS.INSTANCE, new GuiHandler());
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user