missing JEI ghost support

This commit is contained in:
PrototypeTrousers
2022-08-11 03:19:13 -03:00
parent a44c74b0d7
commit 119cdbc2c0
7 changed files with 100 additions and 195 deletions
+12 -5
View File
@@ -474,7 +474,15 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
{
if( slot.getStack().isEmpty() )
{
InventoryAction action = InventoryAction.SPLIT_OR_PLACE_SINGLE;
InventoryAction action;
if( slot.getSlotStackLimit() == 1 )
{
action = InventoryAction.SPLIT_OR_PLACE_SINGLE;
}
else
{
action = InventoryAction.PICKUP_OR_SET_DOWN;
}
final PacketInventoryAction p = new PacketInventoryAction( action, slot.getSlotIndex(), ( (SlotDisconnected) slot ).getSlot().getId() );
NetworkHandler.instance().sendToServer( p );
}
@@ -640,14 +648,13 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
switch ( clickType )
{
case PICKUP: // pickup / set-down.
if( slot.getStack().isEmpty() && !player.inventory.getItemStack().isEmpty() )
if( mouseButton == 1 )
{
action = InventoryAction.SPLIT_OR_PLACE_SINGLE;
}
if( !slot.getStack().isEmpty() && player.inventory.getItemStack().getCount() <= 1 )
else
{
action = InventoryAction.PICKUP_OR_SET_DOWN;
this.haltDragging = true;
}
break;
case QUICK_MOVE:
@@ -861,7 +868,7 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
}
}
private void mouseWheelEvent( final int x, final int y, final int wheel )
protected void mouseWheelEvent( final int x, final int y, final int wheel )
{
final Slot slot = this.getSlot( x, y );
if( slot instanceof SlotME )
@@ -25,10 +25,17 @@ import java.util.*;
import appeng.api.config.ActionItems;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.widgets.GuiImgButton;
import appeng.client.me.SlotME;
import appeng.container.AEBaseContainer;
import appeng.container.implementations.ContainerConfiguringTerminal;
import appeng.container.slot.SlotFake;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketInventoryAction;
import appeng.core.worlddata.IWorldPlayerMapping;
import appeng.helpers.DualityInterface;
import appeng.helpers.InventoryAction;
import appeng.parts.misc.PartInterface;
import appeng.parts.reporting.PartConfiguringTerminal;
import appeng.tile.inventory.AppEngInternalInventory;
@@ -39,6 +46,7 @@ import com.google.common.collect.HashMultimap;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@@ -84,11 +92,8 @@ public class GuiConfiguringTerminal extends AEBaseGui
private final Map<String, Set<Object>> cachedSearches = new WeakHashMap<>();
private boolean refreshList = false;
private MEGuiTextField searchFieldOutputs;
private MEGuiTextField searchFieldInputs;
private PartConfiguringTerminal partInterfaceTerminal;
private GuiButton guiButtonHide;
private GuiButton guiButtonNextAssembler;
private HashMap<ClientDCInternalInv, Integer> dimHashMap = new HashMap<>();
public GuiConfiguringTerminal( final InventoryPlayer inventoryPlayer, final PartConfiguringTerminal te )
@@ -118,13 +123,6 @@ public class GuiConfiguringTerminal extends AEBaseGui
this.searchFieldInputs.setVisible( true );
this.searchFieldInputs.setFocused( false );
this.searchFieldOutputs = new MEGuiTextField( this.fontRenderer, this.guiLeft + Math.max( 32, this.offsetX ), this.guiTop + 38, 65, 12 );
this.searchFieldOutputs.setEnableBackgroundDrawing( false );
this.searchFieldOutputs.setMaxStringLength( 25 );
this.searchFieldOutputs.setTextColor( 0xFFFFFF );
this.searchFieldOutputs.setVisible( true );
this.searchFieldOutputs.setFocused( true );
this.searchFieldInputs.setText( partInterfaceTerminal.in );
}
@@ -140,7 +138,7 @@ public class GuiConfiguringTerminal extends AEBaseGui
{
this.buttonList.clear();
this.fontRenderer.drawString( this.getGuiDisplayName( GuiText.InterfaceTerminal.getLocal() ), 8, 6, 4210752 );
this.fontRenderer.drawString( this.getGuiDisplayName( GuiText.InterfaceConfigurationTerminal.getLocal() ), 8, 6, 4210752 );
this.fontRenderer.drawString( GuiText.inventory.getLocal(), this.offsetX + 2, this.ySize - 96 + 3, 4210752 );
final int currentScroll = this.getScrollBar().getCurrentScroll();
@@ -198,11 +196,6 @@ public class GuiConfiguringTerminal extends AEBaseGui
{
drawTooltip( Mouse.getEventX() * this.width / this.mc.displayWidth - offsetX, mouseY - guiTop, "Inputs OR names" );
}
else if( searchFieldOutputs.isMouseIn( mouseX, mouseY ) )
{
drawTooltip( Mouse.getEventX() * this.width / this.mc.displayWidth - offsetX, mouseY - guiTop, "Outputs OR names" );
}
}
@Override
@@ -216,14 +209,6 @@ public class GuiConfiguringTerminal extends AEBaseGui
this.refreshList();
}
this.searchFieldOutputs.mouseClicked( xCoord, yCoord, btn );
if( btn == 1 && this.searchFieldOutputs.isMouseIn( xCoord, yCoord ) )
{
this.searchFieldOutputs.setText( "" );
this.refreshList();
}
super.mouseClicked( xCoord, yCoord, btn );
}
@@ -256,6 +241,26 @@ public class GuiConfiguringTerminal extends AEBaseGui
}
}
@Override
protected void mouseWheelEvent( final int x, final int y, final int wheel )
{
final Slot slot = this.getSlot( x, y );
if( slot instanceof SlotDisconnected )
{
final ItemStack stack = slot.getStack();
if( stack != ItemStack.EMPTY )
{
InventoryAction direction = wheel > 0 ? InventoryAction.PLACE_SINGLE : InventoryAction.PICKUP_SINGLE;
final PacketInventoryAction p = new PacketInventoryAction( direction, slot.getSlotIndex(), ( (SlotDisconnected) slot ).getSlot().getId() );
NetworkHandler.instance().sendToServer( p );
}
}
else
{
super.mouseWheelEvent( x, y, wheel );
}
}
@Override
public void drawBG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
{
@@ -293,11 +298,6 @@ public class GuiConfiguringTerminal extends AEBaseGui
{
this.searchFieldInputs.drawTextBox();
}
if( this.searchFieldOutputs != null )
{
this.searchFieldOutputs.drawTextBox();
}
}
@Override
@@ -310,12 +310,7 @@ public class GuiConfiguringTerminal extends AEBaseGui
return;
}
if( character == ' ' && this.searchFieldOutputs.getText().isEmpty() && this.searchFieldOutputs.isFocused() )
{
return;
}
if( this.searchFieldInputs.textboxKeyTyped( character, key ) || this.searchFieldOutputs.textboxKeyTyped( character, key ) )
if( this.searchFieldInputs.textboxKeyTyped( character, key ) )
{
this.refreshList();
}
@@ -385,7 +380,6 @@ public class GuiConfiguringTerminal extends AEBaseGui
this.matchedStacks.clear();
final String searchFieldInputs = this.searchFieldInputs.getText().toLowerCase();
final String searchFieldOutputs = this.searchFieldOutputs.getText().toLowerCase();
final Set<Object> cachedSearch = this.getCacheForSearchTerm( searchFieldInputs );
final boolean rebuild = cachedSearch.isEmpty();
@@ -400,8 +394,7 @@ public class GuiConfiguringTerminal extends AEBaseGui
// Shortcut to skip any filter if search term is ""/empty
boolean found = ( searchFieldInputs.isEmpty() && searchFieldOutputs.isEmpty() );
boolean interfaceHasFreeSlots = false;
boolean found = searchFieldInputs.isEmpty();
// Search if the current inventory holds a pattern containing the search term.
if( !found )
@@ -413,46 +406,19 @@ public class GuiConfiguringTerminal extends AEBaseGui
{
break;
}
if( !searchFieldInputs.isEmpty() && !searchFieldOutputs.isEmpty() )
if( this.itemStackMatchesSearchTerm( itemStack, searchFieldInputs ) )
{
if( this.itemStackMatchesSearchTerm( itemStack, searchFieldInputs, 0 ) || this.itemStackMatchesSearchTerm( itemStack, searchFieldOutputs, 1 ) )
{
found = true;
matchedStacks.add( itemStack );
}
}
else if( !searchFieldInputs.isEmpty() )
{
if( this.itemStackMatchesSearchTerm( itemStack, searchFieldInputs, 0 ) )
{
found = true;
matchedStacks.add( itemStack );
}
}
else if( !searchFieldOutputs.isEmpty() )
{
if( this.itemStackMatchesSearchTerm( itemStack, searchFieldOutputs, 1 ) )
{
found = true;
matchedStacks.add( itemStack );
}
}
// If only Interfaces with empty slots should be shown, check that here
if( itemStack.isEmpty() )
{
interfaceHasFreeSlots = true;
found = true;
matchedStacks.add( itemStack );
}
slot++;
}
}
// if found, filter skipped or machine name matching the search term, add it
if( found || ( entry.getName().toLowerCase().contains( searchFieldInputs ) && entry.getName().toLowerCase().contains( searchFieldOutputs ) ) )
if( found || entry.getName().toLowerCase().contains( searchFieldInputs ) )
{
if( interfaceHasFreeSlots )
{
this.byName.put( entry.getName(), entry );
cachedSearch.add( entry );
}
this.byName.put( entry.getName(), entry );
cachedSearch.add( entry );
}
else
{
@@ -482,7 +448,7 @@ public class GuiConfiguringTerminal extends AEBaseGui
this.getScrollBar().setRange( 0, this.lines.size() - 1, 1 );
}
private boolean itemStackMatchesSearchTerm( final ItemStack itemStack, final String searchTerm, int pass )
private boolean itemStackMatchesSearchTerm( final ItemStack itemStack, final String searchTerm )
{
if( itemStack.isEmpty() )
{
@@ -496,16 +462,7 @@ public class GuiConfiguringTerminal extends AEBaseGui
return false;
}
NBTTagList tag = new NBTTagList();
if( pass == 0 )
{
tag = encodedValue.getTagList( "in", 10 );
}
else
{
tag = encodedValue.getTagList( "out", 10 );
}
NBTTagList tag = encodedValue.getTagList( "in", 10 );
boolean foundMatchingItemStack = false;
@@ -581,7 +538,7 @@ public class GuiConfiguringTerminal extends AEBaseGui
if( o == null )
{
this.byId.put( id, o = new ClientDCInternalInv( DualityInterface.NUMBER_OF_PATTERN_SLOTS, id, sortBy, string ) );
this.byId.put( id, o = new ClientDCInternalInv( DualityInterface.NUMBER_OF_CONFIG_SLOTS, id, sortBy, string, 64 ) );
this.refreshList = true;
}
@@ -43,6 +43,14 @@ public class ClientDCInternalInv implements Comparable<ClientDCInternalInv>
this.sortBy = sortBy;
}
public ClientDCInternalInv( final int size, final long id, final long sortBy, final String unlocalizedName, int stackSize )
{
this.inventory = new AppEngInternalInventory( null, size, stackSize );
this.unlocalizedName = unlocalizedName;
this.id = id;
this.sortBy = sortBy;
}
public String getName()
{
final String s = I18n.translateToLocal( this.unlocalizedName + ".name" );
@@ -24,7 +24,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import appeng.api.config.Upgrades;
import appeng.parts.reporting.PartConfiguringTerminal;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
@@ -45,9 +44,7 @@ import appeng.core.sync.packets.PacketCompressedNBT;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import appeng.helpers.InventoryAction;
import appeng.items.misc.ItemEncodedPattern;
import appeng.parts.misc.PartInterface;
import appeng.parts.reporting.PartInterfaceTerminal;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.misc.TileInterface;
import appeng.util.InventoryAdaptor;
@@ -55,7 +52,6 @@ import appeng.util.Platform;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.AdaptorItemHandler;
import appeng.util.inv.WrapperCursorItemHandler;
import appeng.util.inv.WrapperFilteredItemHandler;
import appeng.util.inv.WrapperRangeItemHandler;
import appeng.util.inv.filter.IAEItemFilter;
@@ -214,119 +210,67 @@ public final class ContainerConfiguringTerminal extends AEBaseContainer
final InventoryAdaptor playerHand = new AdaptorItemHandler( new WrapperCursorItemHandler( player.inventory ) );
final IItemHandler theSlot = new WrapperFilteredItemHandler( new WrapperRangeItemHandler( inv.server, slot, slot + 1 ), new PatternSlotFilter() );
final IItemHandler theSlot = new WrapperRangeItemHandler( inv.server, slot, slot + 1 );
final InventoryAdaptor interfaceSlot = new AdaptorItemHandler( theSlot );
IItemHandler interfaceHandler = inv.server;
boolean canInsert = true;
ItemStack inSlot = theSlot.getStackInSlot( 0 );
switch ( action )
{
case PICKUP_OR_SET_DOWN:
if( hasItemInHand )
{
for( int s = 0; s < interfaceHandler.getSlots(); s++ )
{
if( Platform.itemComparisons().isSameItem( interfaceHandler.getStackInSlot( s ), player.inventory.getItemStack() ) )
{
canInsert = false;
break;
}
}
if( canInsert )
{
ItemStack inSlot = theSlot.getStackInSlot( 0 );
if( inSlot.isEmpty() )
{
player.inventory.setItemStack( interfaceSlot.addItems( player.inventory.getItemStack() ) );
}
else
{
inSlot = inSlot.copy();
final ItemStack inHand = player.inventory.getItemStack().copy();
ItemHandlerUtil.setStackInSlot( theSlot, 0, ItemStack.EMPTY );
player.inventory.setItemStack( ItemStack.EMPTY );
player.inventory.setItemStack( interfaceSlot.addItems( inHand.copy() ) );
if( player.inventory.getItemStack().isEmpty() )
{
player.inventory.setItemStack( inSlot );
}
else
{
player.inventory.setItemStack( inHand );
ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot );
}
}
}
ItemHandlerUtil.setStackInSlot( theSlot, 0, player.inventory.getItemStack().copy() );
}
else
{
ItemHandlerUtil.setStackInSlot( theSlot, 0, playerHand.addItems( theSlot.getStackInSlot( 0 ) ) );
ItemHandlerUtil.setStackInSlot( theSlot, 0, ItemStack.EMPTY );
}
break;
case PLACE_SINGLE:
if( inSlot.getMaxStackSize() > inSlot.getCount() )
{
inSlot.grow( 1 );
ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot );
}
break;
case PICKUP_SINGLE:
if( theSlot.getStackInSlot( 0 ).getCount() > 1 )
{
inSlot.shrink( 1 );
ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot );
}
break;
case SPLIT_OR_PLACE_SINGLE:
if( hasItemInHand )
{
for( int s = 0; s < interfaceHandler.getSlots(); s++ )
if( ItemStack.areItemsEqual( inSlot, player.inventory.getItemStack() ) && ItemStack.areItemStackTagsEqual( inSlot, player.inventory.getItemStack() ) )
{
if( Platform.itemComparisons().isSameItem( interfaceHandler.getStackInSlot( s ), player.inventory.getItemStack() ) )
{
canInsert = false;
break;
}
inSlot.grow( 1 );
ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot.copy() );
}
if( canInsert )
else
{
ItemStack extra = playerHand.removeItems( 1, ItemStack.EMPTY, null );
if( !extra.isEmpty() && !interfaceSlot.containsItems() )
{
extra = interfaceSlot.addItems( extra );
}
if( !extra.isEmpty() )
{
playerHand.addItems( extra );
}
ItemHandlerUtil.setStackInSlot( theSlot, 0, player.inventory.getItemStack().copy() );
}
}
else if( !is.isEmpty() )
{
ItemStack extra = interfaceSlot.removeItems( ( is.getCount() + 1 ) / 2, ItemStack.EMPTY, null );
if( !extra.isEmpty() )
{
extra = playerHand.addItems( extra );
}
if( !extra.isEmpty() )
{
interfaceSlot.addItems( extra );
}
inSlot.shrink( 1 );
ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot.copy() );
}
break;
case SHIFT_CLICK:
final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( player );
ItemHandlerUtil.setStackInSlot( theSlot, 0, playerInv.addItems( theSlot.getStackInSlot( 0 ) ) );
ItemHandlerUtil.setStackInSlot( theSlot, 0, ItemStack.EMPTY );
break;
case MOVE_REGION:
final InventoryAdaptor playerInvAd = InventoryAdaptor.getAdaptor( player );
for( int x = 0; x < inv.server.getSlots(); x++ )
{
ItemHandlerUtil.setStackInSlot( inv.server, x, playerInvAd.addItems( inv.server.getStackInSlot( x ) ) );
}
break;
case CREATIVE_DUPLICATE:
if( player.capabilities.isCreativeMode && !hasItemInHand )
if( player.capabilities.isCreativeMode && hasItemInHand )
{
player.inventory.setItemStack( is.isEmpty() ? ItemStack.EMPTY : is.copy() );
ItemHandlerUtil.setStackInSlot( theSlot, 0, player.inventory.getItemStack().copy() );
}
break;
@@ -355,7 +299,7 @@ public final class ContainerConfiguringTerminal extends AEBaseContainer
final DualityInterface dual = ih.getInterfaceDuality();
if( gn.isActive() && dual.getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.YES )
{
this.diList.put( ih, new ConfigTracker( dual, dual.getPatterns(), dual.getTermName() ) );
this.diList.put( ih, new ConfigTracker( dual, dual.getConfig(), dual.getTermName() ) );
}
}
@@ -365,7 +309,7 @@ public final class ContainerConfiguringTerminal extends AEBaseContainer
final DualityInterface dual = ih.getInterfaceDuality();
if( gn.isActive() && dual.getConfigManager().getSetting( Settings.INTERFACE_TERMINAL ) == YesNo.YES )
{
this.diList.put( ih, new ConfigTracker( dual, dual.getPatterns(), dual.getTermName() ) );
this.diList.put( ih, new ConfigTracker( dual, dual.getConfig(), dual.getTermName() ) );
}
}
}
@@ -407,7 +351,6 @@ public final class ContainerConfiguringTerminal extends AEBaseContainer
tag.setString( "un", inv.unlocalizedName );
tag.setTag( "pos", NBTUtil.createPosTag( inv.pos ) );
tag.setInteger( "dim", inv.dim );
tag.setInteger( "numUpgrades", inv.numUpgrades );
}
for( int x = 0; x < length; x++ )
@@ -440,32 +383,15 @@ public final class ContainerConfiguringTerminal extends AEBaseContainer
private final IItemHandler server;
private final BlockPos pos;
private final int dim;
private final int numUpgrades;
public ConfigTracker( final DualityInterface dual, final IItemHandler patterns, final String unlocalizedName )
public ConfigTracker( final DualityInterface dual, final IItemHandler configSlots, final String unlocalizedName )
{
this.server = patterns;
this.server = configSlots;
this.client = new AppEngInternalInventory( null, this.server.getSlots() );
this.unlocalizedName = unlocalizedName;
this.sortBy = dual.getSortValue();
this.pos = dual.getLocation().getPos();
this.dim = dual.getLocation().getWorld().provider.getDimension();
this.numUpgrades = dual.getInstalledUpgrades( Upgrades.PATTERN_EXPANSION );
}
}
private static class PatternSlotFilter implements IAEItemFilter
{
@Override
public boolean allowExtract( IItemHandler inv, int slot, int amount )
{
return true;
}
@Override
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
{
return !stack.isEmpty() && stack.getItem() instanceof ItemEncodedPattern;
}
}
}
@@ -172,6 +172,7 @@ public enum GuiText
Missing,
InterfaceTerminal,
InterfaceConfigurationTerminal,
NoCraftingCPUs,
Clean,
InvalidPattern,
@@ -27,6 +27,7 @@ import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import appeng.client.gui.implementations.GuiConfiguringTerminal;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -113,5 +114,9 @@ public class PacketCompressedNBT extends AppEngPacket
{
( (GuiInterfaceTerminal) gs ).postUpdate( this.in );
}
else if( gs instanceof GuiConfiguringTerminal )
{
( (GuiConfiguringTerminal) gs ).postUpdate( this.in );
}
}
}