Add bookmarked ghost items support
fixed fluid dragging not working on servers
This commit is contained in:
@@ -25,9 +25,7 @@ import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.helpers.HighlighterHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -35,7 +33,6 @@ import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
@@ -45,8 +42,6 @@ import net.minecraftforge.client.event.*;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.common.ForgeModContainer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||
@@ -324,24 +319,12 @@ public class ClientHelper extends ServerHelper
|
||||
public void MouseClickEvent( final GuiScreenEvent.MouseInputEvent.Pre me )
|
||||
{
|
||||
final Minecraft mc = Minecraft.getMinecraft();
|
||||
final EntityPlayer player = mc.player;
|
||||
if( mc.currentScreen instanceof AEBaseGui )
|
||||
{
|
||||
AEBaseGui gui = ( (AEBaseGui) mc.currentScreen );
|
||||
|
||||
ItemStack dragItem = ItemStack.EMPTY;
|
||||
Object ingredient = gui.getBookmarkedIngredient();
|
||||
|
||||
if( ingredient != null )
|
||||
{
|
||||
if( ingredient instanceof ItemStack )
|
||||
{
|
||||
dragItem = ( (ItemStack) ingredient );
|
||||
}
|
||||
else if( ingredient instanceof FluidStack )
|
||||
{
|
||||
dragItem = FluidUtil.getFilledBucket( ( (FluidStack) ingredient ) );
|
||||
}
|
||||
if( GuiScreen.isShiftKeyDown() )
|
||||
{
|
||||
me.setCanceled( true );
|
||||
@@ -349,8 +332,6 @@ public class ClientHelper extends ServerHelper
|
||||
else if( Mouse.isButtonDown( 0 ) )
|
||||
{
|
||||
me.setCanceled( true );
|
||||
player.inventory.setItemStack( dragItem.copy() );
|
||||
gui.setJeiGhostItem( true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,13 +33,14 @@ import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import appeng.container.slot.*;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import mezz.jei.api.gui.IGhostIngredientHandler;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
@@ -103,16 +104,17 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
private ItemStack dbl_whichItem = ItemStack.EMPTY;
|
||||
private Slot bl_clicked;
|
||||
private Stopwatch lastClicked = Stopwatch.createStarted();
|
||||
private boolean isJeiGhostItem;
|
||||
private List<IGhostIngredientHandler.Target<Object>> hoveredIngredientTargets = new ArrayList<>();
|
||||
private boolean isDraggingJeiGhostItem;
|
||||
private Object bookmarkedIngredient;
|
||||
private boolean isDraggingJeiGhostItem;
|
||||
|
||||
public boolean hasIngredientTargets()
|
||||
public void setJeiGhostItem( boolean jeiGhostItem )
|
||||
{
|
||||
return (hoveredIngredientTargets.size() > 0);
|
||||
isJeiGhostItem = jeiGhostItem;
|
||||
}
|
||||
|
||||
private boolean isJeiGhostItem;
|
||||
|
||||
public Object getBookmarkedIngredient()
|
||||
{
|
||||
return bookmarkedIngredient;
|
||||
@@ -205,35 +207,49 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
this.drawTooltip( (ITooltip) c, mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
if( !isJeiGhostItem )
|
||||
GlStateManager.enableDepth();
|
||||
bookmarkedJEIghostItem(mouseX,mouseY);
|
||||
GlStateManager.disableDepth();
|
||||
}
|
||||
|
||||
void bookmarkedJEIghostItem(final int mouseX, final int mouseY) {
|
||||
|
||||
if (!isJeiGhostItem)
|
||||
{
|
||||
bookmarkedIngredient = runtime.getBookmarkOverlay().getIngredientUnderMouse();
|
||||
}
|
||||
if( isJeiGhostItem )
|
||||
{
|
||||
if( hoveredIngredientTargets.size() > 0 )
|
||||
{
|
||||
drawTargets( mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
else if( bookmarkedIngredient != null )
|
||||
|
||||
if( bookmarkedIngredient != null )
|
||||
{
|
||||
hoveredIngredientTargets = aeGuiHandler.getTargets( this, bookmarkedIngredient, false );
|
||||
ItemStack dragItem = ItemStack.EMPTY;
|
||||
if( hoveredIngredientTargets.size() > 0 )
|
||||
{
|
||||
drawTargets( mouseX, mouseY );
|
||||
if( isShiftKeyDown() && Mouse.isButtonDown( 0 ) && this.lastClicked.elapsed( TimeUnit.MILLISECONDS ) > 200 )
|
||||
{
|
||||
this.lastClicked = Stopwatch.createStarted();
|
||||
aeGuiHandler.getTargets( this, bookmarkedIngredient, true );
|
||||
}
|
||||
else if( Mouse.isButtonDown( 0 ) && this.lastClicked.elapsed( TimeUnit.MILLISECONDS ) > 200 )
|
||||
{
|
||||
this.lastClicked = Stopwatch.createStarted();
|
||||
if( bookmarkedIngredient instanceof ItemStack )
|
||||
{
|
||||
dragItem = ( (ItemStack) bookmarkedIngredient );
|
||||
}
|
||||
else if( bookmarkedIngredient instanceof FluidStack )
|
||||
{
|
||||
dragItem = FluidUtil.getFilledBucket( ( (FluidStack) bookmarkedIngredient ) );
|
||||
}
|
||||
mc.player.inventory.setItemStack( dragItem.copy() );
|
||||
this.isJeiGhostItem = true;
|
||||
}
|
||||
drawTargets( mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawTargets(int mouseX, int mouseY) {
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableDepth();
|
||||
for( IGhostIngredientHandler.Target target : hoveredIngredientTargets )
|
||||
{
|
||||
Rectangle area = target.getArea();
|
||||
@@ -382,7 +398,6 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
{
|
||||
slot.drawBackground( ox, oy );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -485,29 +500,48 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isJeiGhostItem()
|
||||
{
|
||||
return isJeiGhostItem;
|
||||
}
|
||||
|
||||
// TODO 1.9.4 aftermath - Whole ClickType thing, to be checked.
|
||||
@Override
|
||||
protected void handleMouseClick( final Slot slot, final int slotIdx, final int mouseButton, final ClickType clickType )
|
||||
{
|
||||
final EntityPlayer player = Minecraft.getMinecraft().player;
|
||||
|
||||
if( isJeiGhostItem && slot instanceof IJEITargetSlot)
|
||||
if( this.isJeiGhostItem && isDraggingJeiGhostItem)
|
||||
{
|
||||
try
|
||||
for( IGhostIngredientHandler.Target target : hoveredIngredientTargets )
|
||||
{
|
||||
PacketInventoryAction p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack( player.inventory.getItemStack() ) );
|
||||
NetworkHandler.instance().sendToServer( p );
|
||||
Rectangle area = target.getArea();
|
||||
final int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
|
||||
final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
|
||||
|
||||
if( area.contains( x, y ) )
|
||||
{
|
||||
target.accept( bookmarkedIngredient );
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch( IOException e )
|
||||
this.isJeiGhostItem = false;
|
||||
this.isDraggingJeiGhostItem = false;
|
||||
|
||||
ItemStack dragItem = ItemStack.EMPTY;
|
||||
if( runtime.getBookmarkOverlay().getIngredientUnderMouse() != null )
|
||||
{
|
||||
e.printStackTrace();
|
||||
bookmarkedJEIghostItem( Mouse.getX(), this.mc.displayHeight - Mouse.getY() );
|
||||
if( bookmarkedIngredient instanceof ItemStack )
|
||||
{
|
||||
dragItem = ( (ItemStack) bookmarkedIngredient );
|
||||
}
|
||||
else if( bookmarkedIngredient instanceof FluidStack )
|
||||
{
|
||||
dragItem = FluidUtil.getFilledBucket( ( (FluidStack) bookmarkedIngredient ) );
|
||||
}
|
||||
mc.player.inventory.setItemStack( dragItem.copy() );
|
||||
this.isJeiGhostItem = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mc.player.inventory.setItemStack( dragItem );
|
||||
}
|
||||
isJeiGhostItem = false;
|
||||
}
|
||||
|
||||
else if( slot instanceof SlotFake )
|
||||
@@ -728,11 +762,6 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
if (clickType == ClickType.PICKUP && isJeiGhostItem && !isDraggingJeiGhostItem) {
|
||||
this.isDraggingJeiGhostItem = true;
|
||||
return;
|
||||
} else if ( clickType == ClickType.PICKUP && isJeiGhostItem )
|
||||
{
|
||||
this.isDraggingJeiGhostItem = false;
|
||||
player.inventory.setItemStack( ItemStack.EMPTY );
|
||||
this.isJeiGhostItem = false;
|
||||
}
|
||||
|
||||
super.handleMouseClick( slot, slotIdx, mouseButton, clickType );
|
||||
@@ -1163,8 +1192,4 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setJeiGhostItem( boolean b )
|
||||
{
|
||||
this.isJeiGhostItem = b;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.util.List;
|
||||
|
||||
import appeng.client.gui.widgets.GuiCustomSlot;
|
||||
import appeng.container.interfaces.IJEIGhostIngredients;
|
||||
import appeng.container.slot.AppEngSlot;
|
||||
import appeng.container.slot.IJEITargetSlot;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import appeng.core.sync.packets.PacketInventoryAction;
|
||||
|
||||
@@ -22,18 +22,16 @@ package appeng.core.sync.packets;
|
||||
import java.io.IOException;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.client.gui.implementations.GuiUpgradeable;
|
||||
import appeng.client.gui.widgets.GuiCustomSlot;
|
||||
import appeng.container.slot.IJEITargetSlot;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
|
||||
import appeng.fluids.container.ContainerFluidConfigurable;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -195,9 +193,11 @@ public class PacketInventoryAction extends AppEngPacket
|
||||
{
|
||||
if( sender.openContainer.inventorySlots.get( this.slot ) instanceof SlotFake )
|
||||
{
|
||||
if( this.slotItem != null ) {
|
||||
sender.openContainer.inventorySlots.get( this.slot ).putStack( this.slotItem.asItemStackRepresentation() );
|
||||
if (sender.openContainer.inventorySlots.get( this.slot ).getStack().isEmpty()){
|
||||
if( this.slotItem != null )
|
||||
{
|
||||
sender.openContainer.inventorySlots.get( this.slot ).putStack( this.slotItem.createItemStack() );
|
||||
if( sender.openContainer.inventorySlots.get( this.slot ).getStack().isEmpty() )
|
||||
{
|
||||
IAEFluidStack aefs = AEFluidStack.fromNBT( this.slotItem.getDefinition().getTagCompound() );
|
||||
if( aefs != null )
|
||||
{
|
||||
@@ -205,40 +205,26 @@ public class PacketInventoryAction extends AppEngPacket
|
||||
sender.openContainer.inventorySlots.get( this.slot ).putStack( AEFluidStack.fromFluidStack( fluid ).asItemStackRepresentation() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else sender.openContainer.inventorySlots.get( this.slot ).putStack( ItemStack.EMPTY );
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance()
|
||||
.sendTo(
|
||||
new PacketInventoryAction( InventoryAction.UPDATE_HAND, 0, AEItemStack.fromItemStack( ItemStack.EMPTY ) ),
|
||||
sender );
|
||||
NetworkHandler.instance().sendTo( new PacketInventoryAction( InventoryAction.UPDATE_HAND, 0, AEItemStack.fromItemStack( ItemStack.EMPTY ) ), sender );
|
||||
}
|
||||
catch( final IOException e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
}
|
||||
}
|
||||
if( Minecraft.getMinecraft().currentScreen instanceof GuiUpgradeable )
|
||||
|
||||
if( sender.openContainer instanceof ContainerFluidConfigurable )
|
||||
{
|
||||
GuiUpgradeable cs = ( (GuiUpgradeable) Minecraft.getMinecraft().currentScreen );
|
||||
if( cs.getGuiSlots().size() > 0 )
|
||||
if( this.slotItem != null )
|
||||
{
|
||||
GuiCustomSlot ct = cs.getGuiSlots().get( this.slot );
|
||||
GuiFluidSlot gfs = (GuiFluidSlot) ct;
|
||||
if( this.slotItem != null )
|
||||
IAEFluidStack aefs = AEFluidStack.fromNBT( this.slotItem.getDefinition().getTagCompound() );
|
||||
if( aefs != null )
|
||||
{
|
||||
IAEFluidStack aefs = AEFluidStack.fromNBT( this.slotItem.getDefinition().getTagCompound() );
|
||||
if( aefs != null )
|
||||
{
|
||||
FluidStack fluid = aefs.getFluidStack();
|
||||
gfs.setFluidStack( AEFluidStack.fromFluidStack( fluid ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gfs.setFluidStack( null );
|
||||
( (ContainerFluidConfigurable) sender.openContainer ).getFluidConfigInventory().setFluidInSlot( this.slot, aefs );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user