Interface Terminal
Fixed bug with Assembler Packet Crashing the server.
This commit is contained in:
parent
1541998281
commit
16ef731c00
18 changed files with 505 additions and 84 deletions
|
@ -48,7 +48,7 @@ public class BlockQuantumLinkChamber extends AEBaseBlock implements ICustomColli
|
|||
if ( bridge.hasQES() )
|
||||
{
|
||||
if ( CommonHelper.proxy.shouldAddParticles( r ) )
|
||||
CommonHelper.proxy.spawnEffect( EffectType.Energy, w, bx + 0.5, by + 0.5, bz + 0.5 );
|
||||
CommonHelper.proxy.spawnEffect( EffectType.Energy, w, bx + 0.5, by + 0.5, bz + 0.5, null );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import appeng.block.AEBaseBlock;
|
|||
import appeng.client.render.BaseBlockRender;
|
||||
import appeng.client.render.TESRWrapper;
|
||||
import appeng.client.render.WorldRender;
|
||||
import appeng.client.render.effects.AssemblerFX;
|
||||
import appeng.client.render.effects.CraftingFx;
|
||||
import appeng.client.render.effects.EnergyFx;
|
||||
import appeng.client.render.effects.LightningFX;
|
||||
|
@ -46,6 +47,7 @@ import appeng.core.AEConfig;
|
|||
import appeng.core.AELog;
|
||||
import appeng.core.CommonHelper;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketAssemblerAnimation;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.entity.EntityFloatingItem;
|
||||
import appeng.entity.EntityTinyTNTPrimed;
|
||||
|
@ -232,12 +234,14 @@ public class ClientHelper extends ServerHelper
|
|||
}
|
||||
|
||||
@Override
|
||||
public void spawnEffect(EffectType effect, World worldObj, double posX, double posY, double posZ)
|
||||
public void spawnEffect(EffectType effect, World worldObj, double posX, double posY, double posZ, Object o)
|
||||
{
|
||||
if ( AEConfig.instance.enableEffects )
|
||||
{
|
||||
switch (effect)
|
||||
{
|
||||
case Assembler:
|
||||
spawnAssembler( worldObj, posX, posY, posZ, o );
|
||||
case Vibrant:
|
||||
spawnVibrant( worldObj, posX, posY, posZ );
|
||||
return;
|
||||
|
@ -254,6 +258,14 @@ public class ClientHelper extends ServerHelper
|
|||
}
|
||||
}
|
||||
|
||||
private void spawnAssembler(World worldObj, double posX, double posY, double posZ, Object o)
|
||||
{
|
||||
PacketAssemblerAnimation paa = (PacketAssemblerAnimation) o;
|
||||
|
||||
AssemblerFX fx = new AssemblerFX( Minecraft.getMinecraft().theWorld, posX, posY, posZ, 0.0D, 0.0D, 0.0D, paa.rate, paa.is );
|
||||
Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx );
|
||||
}
|
||||
|
||||
private void spawnVibrant(World w, double x, double y, double z)
|
||||
{
|
||||
if ( CommonHelper.proxy.shouldAddParticles( Platform.getRandom() ) )
|
||||
|
|
|
@ -2,5 +2,5 @@ package appeng.client;
|
|||
|
||||
public enum EffectType
|
||||
{
|
||||
Energy, Lightning, Vibrant, Crafting
|
||||
Energy, Lightning, Vibrant, Crafting, Assembler
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import appeng.api.storage.data.IAEItemStack;
|
|||
import appeng.client.gui.widgets.GuiScrollbar;
|
||||
import appeng.client.gui.widgets.ITooltip;
|
||||
import appeng.client.me.InternalSlotME;
|
||||
import appeng.client.me.SlotDisconnected;
|
||||
import appeng.client.me.SlotME;
|
||||
import appeng.client.render.AppEngRenderItem;
|
||||
import appeng.container.AEBaseContainer;
|
||||
|
@ -115,7 +116,7 @@ public abstract class AEBaseGui extends GuiContainer
|
|||
int times = Math.abs( wheel );
|
||||
for (int h = 0; h < times; h++)
|
||||
{
|
||||
PacketInventoryAction p = new PacketInventoryAction( direction, inventorySlots.inventorySlots.size(), null );
|
||||
PacketInventoryAction p = new PacketInventoryAction( direction, inventorySlots.inventorySlots.size(), 0 );
|
||||
NetworkHandler.instance.sendToServer( p );
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +167,7 @@ public abstract class AEBaseGui extends GuiContainer
|
|||
{
|
||||
try
|
||||
{
|
||||
PacketInventoryAction p = new PacketInventoryAction( action, slotIdx, null );
|
||||
PacketInventoryAction p = new PacketInventoryAction( action, slotIdx, 0 );
|
||||
NetworkHandler.instance.sendToServer( p );
|
||||
}
|
||||
catch (IOException e)
|
||||
|
@ -207,7 +208,7 @@ public abstract class AEBaseGui extends GuiContainer
|
|||
{
|
||||
try
|
||||
{
|
||||
PacketInventoryAction p = new PacketInventoryAction( action, slotIdx, null );
|
||||
PacketInventoryAction p = new PacketInventoryAction( action, slotIdx, 0 );
|
||||
NetworkHandler.instance.sendToServer( p );
|
||||
}
|
||||
catch (IOException e)
|
||||
|
@ -235,7 +236,7 @@ public abstract class AEBaseGui extends GuiContainer
|
|||
slotNum = slot.slotNumber;
|
||||
|
||||
((AEBaseContainer) inventorySlots).setTargetStack( stack );
|
||||
PacketInventoryAction p = new PacketInventoryAction( InventoryAction.MOVE_REGION, slotNum, null );
|
||||
PacketInventoryAction p = new PacketInventoryAction( InventoryAction.MOVE_REGION, slotNum, 0 );
|
||||
NetworkHandler.instance.sendToServer( p );
|
||||
}
|
||||
catch (IOException e)
|
||||
|
@ -246,6 +247,49 @@ public abstract class AEBaseGui extends GuiContainer
|
|||
}
|
||||
}
|
||||
|
||||
if ( slot instanceof SlotDisconnected )
|
||||
{
|
||||
InventoryAction action = null;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case 0: // pickup / set-down.
|
||||
action = ctrlDown == 1 ? InventoryAction.SPLIT_OR_PLACESINGLE : InventoryAction.PICKUP_OR_SETDOWN;
|
||||
break;
|
||||
case 1:
|
||||
action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK;
|
||||
break;
|
||||
|
||||
case 3: // creative dupe:
|
||||
|
||||
if ( player.capabilities.isCreativeMode )
|
||||
{
|
||||
action = InventoryAction.CREATIVE_DUPLICATE;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
case 4: // drop item:
|
||||
case 6:
|
||||
}
|
||||
|
||||
if ( action != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
PacketInventoryAction p = new PacketInventoryAction( action, slot.getSlotIndex(), ((SlotDisconnected) slot).mySlot.id );
|
||||
NetworkHandler.instance.sendToServer( p );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( slot instanceof SlotME )
|
||||
{
|
||||
InventoryAction action = null;
|
||||
|
@ -292,7 +336,7 @@ public abstract class AEBaseGui extends GuiContainer
|
|||
try
|
||||
{
|
||||
((AEBaseContainer) inventorySlots).setTargetStack( stack );
|
||||
PacketInventoryAction p = new PacketInventoryAction( action, inventorySlots.inventorySlots.size(), null );
|
||||
PacketInventoryAction p = new PacketInventoryAction( action, inventorySlots.inventorySlots.size(), 0 );
|
||||
NetworkHandler.instance.sendToServer( p );
|
||||
}
|
||||
catch (IOException e)
|
||||
|
@ -760,7 +804,7 @@ public abstract class AEBaseGui extends GuiContainer
|
|||
if ( ((AppEngSlot) s).isValid == hasCalculatedValidness.NotAvailable )
|
||||
{
|
||||
boolean isValid = s.isItemValid( is ) || s instanceof SlotOutput || s instanceof AppEngCraftingSlot || s instanceof SlotDisabled
|
||||
|| s instanceof SlotInaccessable || s instanceof SlotFake || s instanceof SlotRestrictedInput;
|
||||
|| s instanceof SlotInaccessable || s instanceof SlotFake || s instanceof SlotRestrictedInput || s instanceof SlotDisconnected;
|
||||
if ( isValid && s instanceof SlotRestrictedInput )
|
||||
{
|
||||
try
|
||||
|
|
|
@ -51,7 +51,7 @@ public class GuiCraftingTerm extends GuiMEMonitorable
|
|||
PacketInventoryAction p;
|
||||
try
|
||||
{
|
||||
p = new PacketInventoryAction( InventoryAction.MOVE_REGION, s.slotNumber, null );
|
||||
p = new PacketInventoryAction( InventoryAction.MOVE_REGION, s.slotNumber, 0 );
|
||||
NetworkHandler.instance.sendToServer( p );
|
||||
}
|
||||
catch (IOException e)
|
||||
|
|
|
@ -3,52 +3,83 @@ package appeng.client.gui.implementations;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.client.gui.widgets.GuiScrollbar;
|
||||
import appeng.client.me.ClientDCInternalInv;
|
||||
import appeng.client.me.SlotDisconnected;
|
||||
import appeng.container.implementations.ContainerInterfaceTerminal;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.parts.reporting.PartMonitor;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
|
||||
public class GuiInterfaceTerminal extends AEBaseGui
|
||||
{
|
||||
|
||||
class ClientFakeInv
|
||||
{
|
||||
|
||||
String unlocalizedName;
|
||||
long id;
|
||||
|
||||
AppEngInternalInventory inv = new AppEngInternalInventory( null, 9 );
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return StatCollector.translateToLocal( unlocalizedName + ".name" );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
HashMap<Long, ClientFakeInv> byId = new HashMap();
|
||||
HashMultimap<String, ClientFakeInv> byName = HashMultimap.create();
|
||||
HashMap<Long, ClientDCInternalInv> byId = new HashMap();
|
||||
HashMultimap<String, ClientDCInternalInv> byName = HashMultimap.create();
|
||||
ArrayList<String> names = new ArrayList();
|
||||
|
||||
ArrayList<Object> lines = new ArrayList();
|
||||
|
||||
private int getTotalRows()
|
||||
{
|
||||
return names.size() + byId.size();// unique names, and each inv row.
|
||||
}
|
||||
|
||||
public GuiInterfaceTerminal(InventoryPlayer inventoryPlayer, PartMonitor te) {
|
||||
super( new ContainerInterfaceTerminal( inventoryPlayer, te ) );
|
||||
myScrollBar = new GuiScrollbar();
|
||||
xSize = 195;
|
||||
ySize = 222;
|
||||
}
|
||||
|
||||
LinkedList<SlotDisconnected> dcSlots = new LinkedList();
|
||||
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
myScrollBar.setLeft( 175 );
|
||||
myScrollBar.setHeight( 106 );
|
||||
myScrollBar.setTop( 18 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY)
|
||||
{
|
||||
bindTexture( "guis/interfaceterminal.png" );
|
||||
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize );
|
||||
|
||||
int offset = 17;
|
||||
int ex = myScrollBar.getCurrentScroll();
|
||||
int linesOnPage = 6;
|
||||
|
||||
for (int x = 0; x < linesOnPage; x++)
|
||||
{
|
||||
if ( ex + x < lines.size() )
|
||||
{
|
||||
Object lineObj = lines.get( ex + x );
|
||||
if ( lineObj instanceof ClientDCInternalInv )
|
||||
{
|
||||
ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
|
||||
|
||||
GL11.glColor4f( 1, 1, 1, 1 );
|
||||
for (int z = 0; z < inv.inv.getSizeInventory(); z++)
|
||||
this.drawTexturedModalRect( offsetX + z * 18 + 7, offsetY + offset, 7, 139, 18, 18 );
|
||||
}
|
||||
}
|
||||
offset += 18;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,12 +88,46 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
|||
fontRendererObj.drawString( getGuiDisplayName( GuiText.InterfaceTerminal.getLocal() ), 8, 6, 4210752 );
|
||||
fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 );
|
||||
|
||||
int offset = 0;
|
||||
int offset = 17;
|
||||
|
||||
for (String name : names)
|
||||
// for (String name : lines)
|
||||
int ex = myScrollBar.getCurrentScroll();
|
||||
int linesOnPage = 6;
|
||||
|
||||
Iterator<Object> o = inventorySlots.inventorySlots.iterator();
|
||||
while (o.hasNext())
|
||||
{
|
||||
fontRendererObj.drawString( name, 8, 30 + offset, 4210752 );
|
||||
offset += 18;
|
||||
if ( o.next() instanceof SlotDisconnected )
|
||||
o.remove();
|
||||
}
|
||||
|
||||
for (int x = 0; x < linesOnPage; x++)
|
||||
{
|
||||
if ( ex + x < lines.size() )
|
||||
{
|
||||
Object lineObj = lines.get( ex + x );
|
||||
if ( lineObj instanceof ClientDCInternalInv )
|
||||
{
|
||||
ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
|
||||
for (int z = 0; z < inv.inv.getSizeInventory(); z++)
|
||||
{
|
||||
inventorySlots.inventorySlots.add( new SlotDisconnected( inv, z, z * 18 + 8, 1 + offset ) );
|
||||
}
|
||||
}
|
||||
else if ( lineObj instanceof String )
|
||||
{
|
||||
String name = (String) lineObj;
|
||||
int rows = byName.get( name ).size();
|
||||
if ( rows > 1 )
|
||||
name = name + " (" + rows + ")";
|
||||
|
||||
while (name.length() > 2 && fontRendererObj.getStringWidth( name ) > 155)
|
||||
name = name.substring( 0, name.length() - 1 );
|
||||
|
||||
fontRendererObj.drawString( name, 10, 6 + offset, 4210752 );
|
||||
}
|
||||
offset += 18;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,7 +136,10 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
|||
public void postUpdate(NBTTagCompound in)
|
||||
{
|
||||
if ( in.getBoolean( "clear" ) )
|
||||
{
|
||||
byId.clear();
|
||||
refreshList = true;
|
||||
}
|
||||
|
||||
for (Object oKey : in.func_150296_c())
|
||||
{
|
||||
|
@ -82,8 +150,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
|||
{
|
||||
long id = Long.parseLong( key.substring( 1 ), Character.MAX_RADIX );
|
||||
NBTTagCompound invData = in.getCompoundTag( key );
|
||||
ClientFakeInv current = getById( id );
|
||||
current.unlocalizedName = invData.getString( "un" );
|
||||
ClientDCInternalInv current = getById( id, invData.getString( "un" ) );
|
||||
|
||||
for (int x = 0; x < current.inv.getSizeInventory(); x++)
|
||||
{
|
||||
|
@ -100,24 +167,36 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
|||
|
||||
if ( refreshList )
|
||||
{
|
||||
refreshList = false;
|
||||
|
||||
byName.clear();
|
||||
for (ClientFakeInv o : byId.values())
|
||||
for (ClientDCInternalInv o : byId.values())
|
||||
byName.put( o.getName(), o );
|
||||
|
||||
names.clear();
|
||||
names.addAll( byName.keySet() );
|
||||
|
||||
Collections.sort( names );
|
||||
|
||||
lines = new ArrayList( getTotalRows() );
|
||||
for (String n : names)
|
||||
{
|
||||
lines.add( n );
|
||||
for (ClientDCInternalInv i : byName.get( n ))
|
||||
lines.add( i );
|
||||
}
|
||||
|
||||
myScrollBar.setRange( 0, getTotalRows() - 6, 2 );
|
||||
}
|
||||
}
|
||||
|
||||
private ClientFakeInv getById(long id)
|
||||
private ClientDCInternalInv getById(long id, String string)
|
||||
{
|
||||
ClientFakeInv o = byId.get( id );
|
||||
ClientDCInternalInv o = byId.get( id );
|
||||
|
||||
if ( o == null )
|
||||
{
|
||||
byId.put( id, o = new ClientFakeInv() );
|
||||
byId.put( id, o = new ClientDCInternalInv( 9, id, string ) );
|
||||
refreshList = true;
|
||||
}
|
||||
|
||||
|
|
27
client/me/ClientDCInternalInv.java
Normal file
27
client/me/ClientDCInternalInv.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package appeng.client.me;
|
||||
|
||||
import net.minecraft.util.StatCollector;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
|
||||
public class ClientDCInternalInv
|
||||
{
|
||||
|
||||
final public String unlocalizedName;
|
||||
final public long id;
|
||||
final public AppEngInternalInventory inv;
|
||||
|
||||
public ClientDCInternalInv(int size, long id, String unlocalizedName) {
|
||||
inv = new AppEngInternalInventory( null, size );
|
||||
this.unlocalizedName = unlocalizedName;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
String s = StatCollector.translateToLocal( unlocalizedName + ".name" );
|
||||
if ( s.equals( unlocalizedName + ".name" ) )
|
||||
return StatCollector.translateToLocal( unlocalizedName );
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
83
client/me/SlotDisconnected.java
Normal file
83
client/me/SlotDisconnected.java
Normal file
|
@ -0,0 +1,83 @@
|
|||
package appeng.client.me;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.container.slot.AppEngSlot;
|
||||
import appeng.items.misc.ItemEncodedPattern;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class SlotDisconnected extends AppEngSlot
|
||||
{
|
||||
|
||||
public ClientDCInternalInv mySlot;
|
||||
|
||||
public SlotDisconnected(ClientDCInternalInv me, int which, int x, int y) {
|
||||
super( me.inv, which, x, y );
|
||||
mySlot = me;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDisplayStack()
|
||||
{
|
||||
if ( Platform.isClient() )// && (which == PlaceableItemType.ENCODED_PATTERN) )
|
||||
{
|
||||
ItemStack is = super.getStack();
|
||||
if ( is != null && is.getItem() instanceof ItemEncodedPattern )
|
||||
{
|
||||
ItemEncodedPattern iep = (ItemEncodedPattern) is.getItem();
|
||||
ItemStack out = iep.getOutput( is );
|
||||
return out;
|
||||
}
|
||||
}
|
||||
return super.getStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer par1EntityPlayer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int par1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStack(ItemStack par1ItemStack)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getHasStack()
|
||||
{
|
||||
return getStack() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack par1ItemStack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotStackLimit()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSlotInInventory(IInventory par1iInventory, int par2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
|
@ -58,7 +58,7 @@ public class AssemblerFX extends EntityFX
|
|||
time -= 4.0;
|
||||
// if ( CommonHelper.proxy.shouldAddParticles( r ) )
|
||||
for (int x = 0; x < (int) Math.ceil( speed / 5 ); x++)
|
||||
CommonHelper.proxy.spawnEffect( EffectType.Crafting, worldObj, posX, posY, posZ );
|
||||
CommonHelper.proxy.spawnEffect( EffectType.Crafting, worldObj, posX, posY, posZ, null );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -266,7 +266,7 @@ public abstract class AEBaseContainer extends Container
|
|||
prepareSync();
|
||||
}
|
||||
|
||||
private IActionHost getActionHost()
|
||||
protected IActionHost getActionHost()
|
||||
{
|
||||
if ( obj instanceof IActionHost )
|
||||
return (IActionHost) obj;
|
||||
|
@ -678,7 +678,7 @@ public abstract class AEBaseContainer extends Container
|
|||
return ais.getItemStack();
|
||||
}
|
||||
|
||||
public void doAction(EntityPlayerMP player, InventoryAction action, int slot)
|
||||
public void doAction(EntityPlayerMP player, InventoryAction action, int slot, long id)
|
||||
{
|
||||
if ( slot >= 0 && slot < inventorySlots.size() )
|
||||
{
|
||||
|
|
|
@ -12,16 +12,23 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.security.IActionHost;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
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.PartMonitor;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.misc.TileInterface;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.AdaptorIInventory;
|
||||
import appeng.util.inv.AdaptorPlayerHand;
|
||||
import appeng.util.inv.WrapperInvSlot;
|
||||
|
||||
public class ContainerInterfaceTerminal extends AEBaseContainer
|
||||
{
|
||||
|
@ -50,6 +57,7 @@ public class ContainerInterfaceTerminal extends AEBaseContainer
|
|||
};
|
||||
|
||||
Map<IInterfaceHost, InvTracker> diList = new HashMap();
|
||||
Map<Long, InvTracker> byId = new HashMap();
|
||||
IGrid g;
|
||||
|
||||
public ContainerInterfaceTerminal(InventoryPlayer ip, PartMonitor anchor) {
|
||||
|
@ -63,9 +71,92 @@ public class ContainerInterfaceTerminal extends AEBaseContainer
|
|||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
|
||||
class PatternInvSlot extends WrapperInvSlot
|
||||
{
|
||||
|
||||
public PatternInvSlot(IInventory inv) {
|
||||
super( inv );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return itemstack != null && itemstack.getItem() instanceof ItemEncodedPattern;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public void doAction(EntityPlayerMP player, InventoryAction action, int slot, long id)
|
||||
{
|
||||
InvTracker inv = byId.get( id );
|
||||
if ( inv != null )
|
||||
{
|
||||
ItemStack is = inv.server.getStackInSlot( slot );
|
||||
boolean hasItemInHand = player.inventory.getItemStack() != null;
|
||||
|
||||
InventoryAdaptor playerHand = new AdaptorPlayerHand( player );
|
||||
|
||||
WrapperInvSlot slotInv = new PatternInvSlot( inv.server );
|
||||
slotInv.setSlot( slot );
|
||||
InventoryAdaptor interfaceSlot = new AdaptorIInventory( slotInv );
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case PICKUP_OR_SETDOWN:
|
||||
|
||||
if ( hasItemInHand )
|
||||
{
|
||||
player.inventory.setItemStack( interfaceSlot.addItems( player.inventory.getItemStack() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
slotInv.setInventorySlotContents( 0, playerHand.addItems( slotInv.getStackInSlot( 0 ) ) );
|
||||
}
|
||||
|
||||
break;
|
||||
case SPLIT_OR_PLACESINGLE:
|
||||
|
||||
if ( hasItemInHand )
|
||||
{
|
||||
ItemStack extra = playerHand.removeItems( 1, null, null );
|
||||
if ( extra != null )
|
||||
extra = interfaceSlot.addItems( extra );
|
||||
if ( extra != null )
|
||||
playerHand.addItems( extra );
|
||||
}
|
||||
else if ( is != null )
|
||||
{
|
||||
ItemStack extra = interfaceSlot.removeItems( (is.stackSize + 1) / 2, null, null );
|
||||
if ( extra != null )
|
||||
extra = playerHand.addItems( extra );
|
||||
if ( extra != null )
|
||||
interfaceSlot.addItems( extra );
|
||||
}
|
||||
|
||||
break;
|
||||
case CREATIVE_DUPLICATE:
|
||||
|
||||
if ( player.capabilities.isCreativeMode && !hasItemInHand )
|
||||
{
|
||||
player.inventory.setItemStack( is == null ? null : is.copy() );
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
updateHeld( player );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return;
|
||||
|
||||
super.detectAndSendChanges();
|
||||
|
||||
if ( g == null )
|
||||
|
@ -74,16 +165,46 @@ public class ContainerInterfaceTerminal extends AEBaseContainer
|
|||
int total = 0;
|
||||
boolean missing = false;
|
||||
|
||||
for (IGridNode gn : g.getMachines( TileInterface.class ))
|
||||
IActionHost host = getActionHost();
|
||||
if ( host != null )
|
||||
{
|
||||
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
|
||||
missing = missing || !diList.containsKey( ih );
|
||||
}
|
||||
IGridNode agn = host.getActionableNode();
|
||||
if ( agn.isActive() )
|
||||
{
|
||||
for (IGridNode gn : g.getMachines( TileInterface.class ))
|
||||
{
|
||||
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
|
||||
InvTracker t = diList.get( ih );
|
||||
|
||||
for (IGridNode gn : g.getMachines( PartInterface.class ))
|
||||
{
|
||||
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
|
||||
missing = missing || !diList.containsKey( ih );
|
||||
if ( t == null )
|
||||
missing = true;
|
||||
else
|
||||
{
|
||||
DualityInterface dual = ih.getInterfaceDuality();
|
||||
if ( !t.unlocalizedName.equals( dual.getTermName() ) )
|
||||
missing = true;
|
||||
}
|
||||
|
||||
total++;
|
||||
}
|
||||
|
||||
for (IGridNode gn : g.getMachines( PartInterface.class ))
|
||||
{
|
||||
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
|
||||
InvTracker t = diList.get( ih );
|
||||
|
||||
if ( t == null )
|
||||
missing = true;
|
||||
else
|
||||
{
|
||||
DualityInterface dual = ih.getInterfaceDuality();
|
||||
if ( !t.unlocalizedName.equals( dual.getTermName() ) )
|
||||
missing = true;
|
||||
}
|
||||
|
||||
total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( total != diList.size() || missing )
|
||||
|
@ -129,20 +250,29 @@ public class ContainerInterfaceTerminal extends AEBaseContainer
|
|||
|
||||
private void regenList(NBTTagCompound data)
|
||||
{
|
||||
byId.clear();
|
||||
diList.clear();
|
||||
|
||||
for (IGridNode gn : g.getMachines( TileInterface.class ))
|
||||
IActionHost host = getActionHost();
|
||||
if ( host != null )
|
||||
{
|
||||
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
|
||||
DualityInterface dual = ih.getInterfaceDuality();
|
||||
diList.put( ih, new InvTracker( dual.getPatterns(), dual.getTermName() ) );
|
||||
}
|
||||
IGridNode agn = host.getActionableNode();
|
||||
if ( agn.isActive() )
|
||||
{
|
||||
for (IGridNode gn : g.getMachines( TileInterface.class ))
|
||||
{
|
||||
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
|
||||
DualityInterface dual = ih.getInterfaceDuality();
|
||||
diList.put( ih, new InvTracker( dual.getPatterns(), dual.getTermName() ) );
|
||||
}
|
||||
|
||||
for (IGridNode gn : g.getMachines( PartInterface.class ))
|
||||
{
|
||||
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
|
||||
DualityInterface dual = ih.getInterfaceDuality();
|
||||
diList.put( ih, new InvTracker( dual.getPatterns(), dual.getTermName() ) );
|
||||
for (IGridNode gn : g.getMachines( PartInterface.class ))
|
||||
{
|
||||
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
|
||||
DualityInterface dual = ih.getInterfaceDuality();
|
||||
diList.put( ih, new InvTracker( dual.getPatterns(), dual.getTermName() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data.setBoolean( "clear", true );
|
||||
|
@ -150,6 +280,7 @@ public class ContainerInterfaceTerminal extends AEBaseContainer
|
|||
for (Entry<IInterfaceHost, InvTracker> en : diList.entrySet())
|
||||
{
|
||||
InvTracker inv = en.getValue();
|
||||
byId.put( inv.which, inv );
|
||||
addItems( data, inv, 0, inv.server.getSizeInventory() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public abstract class CommonHelper
|
|||
|
||||
public abstract void sendToAllNearExcept(EntityPlayer p, double x, double y, double z, double dist, World w, AppEngPacket packet);
|
||||
|
||||
public abstract void spawnEffect(EffectType effect, World worldObj, double posX, double posY, double posZ);
|
||||
public abstract void spawnEffect(EffectType effect, World worldObj, double posX, double posY, double posZ, Object extra);
|
||||
|
||||
public abstract boolean shouldAddParticles(Random r);
|
||||
|
||||
|
|
|
@ -5,21 +5,22 @@ import io.netty.buffer.Unpooled;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.particle.EntityFX;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.render.effects.AssemblerFX;
|
||||
import appeng.client.EffectType;
|
||||
import appeng.core.CommonHelper;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import appeng.core.sync.network.INetworkInfo;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PacketAssemblerAnimation extends AppEngPacket
|
||||
{
|
||||
|
||||
int x, y, z;
|
||||
byte rate;
|
||||
IAEItemStack is;
|
||||
final public int x, y, z;
|
||||
final public byte rate;
|
||||
final public IAEItemStack is;
|
||||
|
||||
// automatic.
|
||||
public PacketAssemblerAnimation(ByteBuf stream) throws IOException {
|
||||
|
@ -31,14 +32,14 @@ public class PacketAssemblerAnimation extends AppEngPacket
|
|||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
|
||||
{
|
||||
double d0 = 0.5d;// + ((double) (Platform.getRandomFloat() - 0.5F) * 0.26D);
|
||||
double d1 = 0.5d;// + ((double) (Platform.getRandomFloat() - 0.5F) * 0.26D);
|
||||
double d2 = 0.5d;// + ((double) (Platform.getRandomFloat() - 0.5F) * 0.26D);
|
||||
|
||||
AssemblerFX fx = new AssemblerFX( Minecraft.getMinecraft().theWorld, x + d0, y + d1, z + d2, 0.0D, 0.0D, 0.0D, rate, is );
|
||||
Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx );
|
||||
CommonHelper.proxy.spawnEffect( EffectType.Assembler, player.getEntityWorld(), x + d0, y + d1, z + d2, this );
|
||||
}
|
||||
|
||||
// api
|
||||
|
|
|
@ -25,12 +25,14 @@ public class PacketInventoryAction extends AppEngPacket
|
|||
|
||||
final public InventoryAction action;
|
||||
final public int slot;
|
||||
final public long id;
|
||||
final public IAEItemStack slotItem;
|
||||
|
||||
// automatic.
|
||||
public PacketInventoryAction(ByteBuf stream) throws IOException {
|
||||
action = InventoryAction.values()[stream.readInt()];
|
||||
slot = stream.readInt();
|
||||
id = stream.readLong();
|
||||
boolean hasItem = stream.readBoolean();
|
||||
if ( hasItem )
|
||||
slotItem = AEItemStack.loadItemStackFromPacket( stream );
|
||||
|
@ -64,7 +66,7 @@ public class PacketInventoryAction extends AppEngPacket
|
|||
}
|
||||
else
|
||||
{
|
||||
aebc.doAction( sender, action, slot );
|
||||
aebc.doAction( sender, action, slot, id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,11 +86,12 @@ public class PacketInventoryAction extends AppEngPacket
|
|||
// api
|
||||
public PacketInventoryAction(InventoryAction action, int slot, IAEItemStack slotItem) throws IOException {
|
||||
|
||||
if ( Platform.isClient() && slotItem != null )
|
||||
if ( Platform.isClient() )
|
||||
throw new RuntimeException( "invalid packet, client cannot post inv actions with stacks." );
|
||||
|
||||
this.action = action;
|
||||
this.slot = slot;
|
||||
this.id = 0;
|
||||
this.slotItem = slotItem;
|
||||
|
||||
ByteBuf data = Unpooled.buffer();
|
||||
|
@ -96,6 +99,7 @@ public class PacketInventoryAction extends AppEngPacket
|
|||
data.writeInt( getPacketID() );
|
||||
data.writeInt( action.ordinal() );
|
||||
data.writeInt( slot );
|
||||
data.writeLong( id );
|
||||
|
||||
if ( slotItem == null )
|
||||
data.writeBoolean( false );
|
||||
|
@ -108,4 +112,22 @@ public class PacketInventoryAction extends AppEngPacket
|
|||
configureWrite( data );
|
||||
}
|
||||
|
||||
// api
|
||||
public PacketInventoryAction(InventoryAction action, int slot, long id) throws IOException {
|
||||
|
||||
this.action = action;
|
||||
this.slot = slot;
|
||||
this.id = id;
|
||||
this.slotItem = null;
|
||||
|
||||
ByteBuf data = Unpooled.buffer();
|
||||
|
||||
data.writeInt( getPacketID() );
|
||||
data.writeInt( action.ordinal() );
|
||||
data.writeInt( slot );
|
||||
data.writeLong( id );
|
||||
data.writeBoolean( false );
|
||||
|
||||
configureWrite( data );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ final public class EntityChargedQuartz extends EntityItem
|
|||
|
||||
if ( Platform.isClient() && delay++ > 30 && AEConfig.instance.enableEffects )
|
||||
{
|
||||
CommonHelper.proxy.spawnEffect( EffectType.Lightning, worldObj, posX, posY, posZ );
|
||||
CommonHelper.proxy.spawnEffect( EffectType.Lightning, worldObj, posX, posY, posZ, null );
|
||||
delay = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ final public class EntityGrowingCrystal extends EntityItem
|
|||
if ( progress_1000 >= len )
|
||||
{
|
||||
progress_1000 = 0;
|
||||
CommonHelper.proxy.spawnEffect( EffectType.Vibrant, worldObj, posX, posY + 0.2, posZ );
|
||||
CommonHelper.proxy.spawnEffect( EffectType.Vibrant, worldObj, posX, posY + 0.2, posZ, null );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
package appeng.helpers;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
@ -207,8 +210,6 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt
|
|||
|
||||
private void readConfig()
|
||||
{
|
||||
boolean hadConfig = hasConfig;
|
||||
|
||||
hasConfig = false;
|
||||
|
||||
for (ItemStack p : config)
|
||||
|
@ -924,6 +925,8 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt
|
|||
craftingTracker.jobStateChange( link );
|
||||
}
|
||||
|
||||
static final Set<Block> badBlocks = new HashSet();
|
||||
|
||||
public String getTermName()
|
||||
{
|
||||
TileEntity tile = iHost.getTileEntity();
|
||||
|
@ -940,22 +943,41 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt
|
|||
MovingObjectPosition mop = w.rayTraceBlocks( from, to, true );
|
||||
|
||||
TileEntity te = w.getTileEntity( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ );
|
||||
ItemStack what = new ItemStack( blk.getItem( w, tile.xCoord, tile.yCoord, tile.zCoord ) );
|
||||
|
||||
if ( mop != null )
|
||||
if ( te == null )
|
||||
return "Nothing";
|
||||
|
||||
Item item = Item.getItemFromBlock( blk );
|
||||
|
||||
if ( item == null )
|
||||
{
|
||||
if ( te instanceof ICraftingMachine || InventoryAdaptor.getAdaptor( te, s.getOpposite() ) != null )
|
||||
return blk.getUnlocalizedName();
|
||||
}
|
||||
|
||||
ItemStack what = new ItemStack( item, 1, blk.getDamageValue( w, tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ ) );
|
||||
|
||||
try
|
||||
{
|
||||
if ( mop != null && !badBlocks.contains( blk ) )
|
||||
{
|
||||
if ( mop.blockX == te.xCoord && mop.blockY == te.yCoord && mop.blockZ == te.zCoord )
|
||||
if ( te instanceof ICraftingMachine || InventoryAdaptor.getAdaptor( te, s.getOpposite() ) != null )
|
||||
{
|
||||
ItemStack g = blk.getPickBlock( mop, w, te.xCoord, te.yCoord, te.zCoord );
|
||||
if ( g != null )
|
||||
what = g;
|
||||
if ( mop.blockX == te.xCoord && mop.blockY == te.yCoord && mop.blockZ == te.zCoord )
|
||||
{
|
||||
ItemStack g = blk.getPickBlock( mop, w, te.xCoord, te.yCoord, te.zCoord );
|
||||
if ( g != null )
|
||||
what = g;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
badBlocks.add( blk ); // nope!
|
||||
}
|
||||
|
||||
return what.getUnlocalizedName();
|
||||
if ( what.getItem() != null )
|
||||
return what.getUnlocalizedName();
|
||||
}
|
||||
|
||||
return GuiText.Interface.getUnlocalized();
|
||||
|
|
|
@ -90,7 +90,7 @@ public class ServerHelper extends CommonHelper
|
|||
}
|
||||
|
||||
@Override
|
||||
public void spawnEffect(EffectType type, World worldObj, double posX, double posY, double posZ)
|
||||
public void spawnEffect(EffectType type, World worldObj, double posX, double posY, double posZ, Object o)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue