Add bookmarked ghost items support

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