Fixed Bug: #0260 - Hotbar Keys + Inscriber
This commit is contained in:
@@ -46,8 +46,10 @@ import appeng.core.AEConfig;
|
|||||||
import appeng.core.AELog;
|
import appeng.core.AELog;
|
||||||
import appeng.core.sync.network.NetworkHandler;
|
import appeng.core.sync.network.NetworkHandler;
|
||||||
import appeng.core.sync.packets.PacketInventoryAction;
|
import appeng.core.sync.packets.PacketInventoryAction;
|
||||||
|
import appeng.core.sync.packets.PacketSwapSlots;
|
||||||
import appeng.helpers.InventoryAction;
|
import appeng.helpers.InventoryAction;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
|
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||||
|
|
||||||
public abstract class AEBaseGui extends GuiContainer
|
public abstract class AEBaseGui extends GuiContainer
|
||||||
{
|
{
|
||||||
@@ -271,6 +273,47 @@ public abstract class AEBaseGui extends GuiContainer
|
|||||||
super.handleMouseClick( slot, slotIdx, ctrlDown, key );
|
super.handleMouseClick( slot, slotIdx, ctrlDown, key );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean checkHotbarKeys(int p_146983_1_)
|
||||||
|
{
|
||||||
|
Slot theSlot = ReflectionHelper.getPrivateValue( GuiContainer.class, this, "theSlot" );
|
||||||
|
|
||||||
|
if ( this.mc.thePlayer.inventory.getItemStack() == null && theSlot != null )
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 9; ++j)
|
||||||
|
{
|
||||||
|
if ( p_146983_1_ == this.mc.gameSettings.keyBindsHotbar[j].getKeyCode() )
|
||||||
|
{
|
||||||
|
if ( theSlot.getSlotStackLimit() == 64 )
|
||||||
|
{
|
||||||
|
this.handleMouseClick( theSlot, theSlot.slotNumber, j, 2 );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for (Slot s : (List<Slot>) inventorySlots.inventorySlots)
|
||||||
|
{
|
||||||
|
if ( s.getSlotIndex() == j && s.inventory == ((AEBaseContainer) inventorySlots).getPlayerInv() )
|
||||||
|
{
|
||||||
|
NetworkHandler.instance.sendToServer( new PacketSwapSlots( s.slotNumber, theSlot.slotNumber ) );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
AELog.error( e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawScreen(int mouse_x, int mouse_y, float btn)
|
public void drawScreen(int mouse_x, int mouse_y, float btn)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -756,4 +756,67 @@ public abstract class AEBaseContainer extends Container
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void swapSlotContents(int slotA, int slotB)
|
||||||
|
{
|
||||||
|
Slot a = getSlot( slotA );
|
||||||
|
Slot b = getSlot( slotB );
|
||||||
|
|
||||||
|
// NPE protection...
|
||||||
|
if ( a == null || b == null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
ItemStack isA = a.getStack();
|
||||||
|
ItemStack isB = b.getStack();
|
||||||
|
|
||||||
|
// something to do?
|
||||||
|
if ( isA == null && isB == null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// can take?
|
||||||
|
|
||||||
|
if ( isA != null && !a.canTakeStack( invPlayer.player ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( isB != null && !b.canTakeStack( invPlayer.player ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// swap valid?
|
||||||
|
|
||||||
|
if ( isB != null && !a.isItemValid( isB ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( isA != null && !b.isItemValid( isA ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
ItemStack testA = isB == null ? null : isB.copy();
|
||||||
|
ItemStack testB = isA == null ? null : isA.copy();
|
||||||
|
|
||||||
|
// can put some back?
|
||||||
|
if ( testA != null && testA.stackSize > a.getSlotStackLimit() )
|
||||||
|
{
|
||||||
|
if ( testB != null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
int totalA = testA.stackSize;
|
||||||
|
testA.stackSize = a.getSlotStackLimit();
|
||||||
|
testB = testA.copy();
|
||||||
|
|
||||||
|
testB.stackSize = totalA - testA.stackSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( testB != null && testB.stackSize > b.getSlotStackLimit() )
|
||||||
|
{
|
||||||
|
if ( testA != null )
|
||||||
|
return;
|
||||||
|
|
||||||
|
int totalB = testB.stackSize;
|
||||||
|
testB.stackSize = b.getSlotStackLimit();
|
||||||
|
testA = testB.copy();
|
||||||
|
|
||||||
|
testA.stackSize = totalB - testA.stackSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.putStack( testA );
|
||||||
|
b.putStack( testB );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-3
@@ -1,6 +1,7 @@
|
|||||||
package appeng.core;
|
package appeng.core;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import appeng.core.crash.CrashEnhancement;
|
import appeng.core.crash.CrashEnhancement;
|
||||||
import appeng.core.crash.CrashInfo;
|
import appeng.core.crash.CrashInfo;
|
||||||
@@ -14,6 +15,9 @@ import appeng.server.AECommand;
|
|||||||
import appeng.services.Profiler;
|
import appeng.services.Profiler;
|
||||||
import appeng.services.VersionChecker;
|
import appeng.services.VersionChecker;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
|
|
||||||
|
import com.google.common.base.Stopwatch;
|
||||||
|
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import cpw.mods.fml.common.Mod;
|
import cpw.mods.fml.common.Mod;
|
||||||
import cpw.mods.fml.common.Mod.EventHandler;
|
import cpw.mods.fml.common.Mod.EventHandler;
|
||||||
@@ -108,6 +112,7 @@ public class AppEng
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
void PreInit(FMLPreInitializationEvent event)
|
void PreInit(FMLPreInitializationEvent event)
|
||||||
{
|
{
|
||||||
|
Stopwatch star = Stopwatch.createStarted();
|
||||||
configPath = event.getModConfigurationDirectory().getPath() + File.separator + "AppliedEnergistics2" + File.separator;
|
configPath = event.getModConfigurationDirectory().getPath() + File.separator + "AppliedEnergistics2" + File.separator;
|
||||||
|
|
||||||
AEConfig.instance = new AEConfig( configPath );
|
AEConfig.instance = new AEConfig( configPath );
|
||||||
@@ -136,23 +141,25 @@ public class AppEng
|
|||||||
startService( "AE2 VersionChecker", new Thread( VersionChecker.instance = new VersionChecker() ) );
|
startService( "AE2 VersionChecker", new Thread( VersionChecker.instance = new VersionChecker() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
AELog.info( "PreInit ( end )" );
|
AELog.info( "PreInit ( end " + star.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void Init(FMLInitializationEvent event)
|
void Init(FMLInitializationEvent event)
|
||||||
{
|
{
|
||||||
|
Stopwatch star = Stopwatch.createStarted();
|
||||||
AELog.info( "Init" );
|
AELog.info( "Init" );
|
||||||
|
|
||||||
Registration.instance.Init( event );
|
Registration.instance.Init( event );
|
||||||
integrationModules.init();
|
integrationModules.init();
|
||||||
|
|
||||||
AELog.info( "Init ( end )" );
|
AELog.info( "Init ( end " + star.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void PostInit(FMLPostInitializationEvent event)
|
void PostInit(FMLPostInitializationEvent event)
|
||||||
{
|
{
|
||||||
|
Stopwatch star = Stopwatch.createStarted();
|
||||||
AELog.info( "PostInit" );
|
AELog.info( "PostInit" );
|
||||||
|
|
||||||
Registration.instance.PostInit( event );
|
Registration.instance.PostInit( event );
|
||||||
@@ -163,7 +170,7 @@ public class AppEng
|
|||||||
NetworkRegistry.INSTANCE.registerGuiHandler( this, GuiBridge.GUI_Handler );
|
NetworkRegistry.INSTANCE.registerGuiHandler( this, GuiBridge.GUI_Handler );
|
||||||
NetworkHandler.instance = new NetworkHandler( "AE2" );
|
NetworkHandler.instance = new NetworkHandler( "AE2" );
|
||||||
|
|
||||||
AELog.info( "PostInit ( end )" );
|
AELog.info( "PostInit ( end " + star.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import appeng.core.sync.packets.PacketMultiPart;
|
|||||||
import appeng.core.sync.packets.PacketNewStorageDimension;
|
import appeng.core.sync.packets.PacketNewStorageDimension;
|
||||||
import appeng.core.sync.packets.PacketPartPlacement;
|
import appeng.core.sync.packets.PacketPartPlacement;
|
||||||
import appeng.core.sync.packets.PacketProgressBar;
|
import appeng.core.sync.packets.PacketProgressBar;
|
||||||
|
import appeng.core.sync.packets.PacketSwapSlots;
|
||||||
import appeng.core.sync.packets.PacketSwitchGuis;
|
import appeng.core.sync.packets.PacketSwitchGuis;
|
||||||
import appeng.core.sync.packets.PacketTransitionEffect;
|
import appeng.core.sync.packets.PacketTransitionEffect;
|
||||||
import appeng.core.sync.packets.PacketValueConfig;
|
import appeng.core.sync.packets.PacketValueConfig;
|
||||||
@@ -61,7 +62,9 @@ public class AppEngPacketHandlerBase
|
|||||||
|
|
||||||
PACKET_NEW_STORAGE_DIMENSION(PacketNewStorageDimension.class),
|
PACKET_NEW_STORAGE_DIMENSION(PacketNewStorageDimension.class),
|
||||||
|
|
||||||
PACKET_SWITCH_GUIS(PacketSwitchGuis.class);
|
PACKET_SWITCH_GUIS(PacketSwitchGuis.class),
|
||||||
|
|
||||||
|
PACKET_SWAP_SLOTS(PacketSwapSlots.class);
|
||||||
|
|
||||||
final public Class pc;
|
final public Class pc;
|
||||||
final public Constructor con;
|
final public Constructor con;
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package appeng.core.sync.packets;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import appeng.container.AEBaseContainer;
|
||||||
|
import appeng.core.sync.AppEngPacket;
|
||||||
|
import appeng.core.sync.network.INetworkInfo;
|
||||||
|
|
||||||
|
public class PacketSwapSlots extends AppEngPacket
|
||||||
|
{
|
||||||
|
|
||||||
|
int slotA, slotB;
|
||||||
|
|
||||||
|
// automatic.
|
||||||
|
public PacketSwapSlots(ByteBuf stream) throws IOException {
|
||||||
|
slotA = stream.readInt();
|
||||||
|
slotB = stream.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
|
||||||
|
{
|
||||||
|
if ( player != null && player.openContainer instanceof AEBaseContainer )
|
||||||
|
{
|
||||||
|
((AEBaseContainer) player.openContainer).swapSlotContents( slotA, slotB );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// api
|
||||||
|
public PacketSwapSlots(int slotA, int slotB) throws IOException {
|
||||||
|
|
||||||
|
ByteBuf data = Unpooled.buffer();
|
||||||
|
|
||||||
|
data.writeInt( getPacketID() );
|
||||||
|
data.writeInt( this.slotA = slotA );
|
||||||
|
data.writeInt( this.slotB = slotB );
|
||||||
|
|
||||||
|
configureWrite( data );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -61,7 +61,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable
|
|||||||
{
|
{
|
||||||
|
|
||||||
public TileInscriberHandler() {
|
public TileInscriberHandler() {
|
||||||
super( TileEventType.TICK, TileEventType.WORLD_NBT, TileEventType.NETWORK );
|
super( TileEventType.WORLD_NBT, TileEventType.NETWORK );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -123,12 +123,6 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void Tick()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -238,13 +232,22 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable
|
|||||||
{
|
{
|
||||||
ItemStack PlateA = getStackInSlot( 0 );
|
ItemStack PlateA = getStackInSlot( 0 );
|
||||||
ItemStack PlateB = getStackInSlot( 1 );
|
ItemStack PlateB = getStackInSlot( 1 );
|
||||||
|
ItemStack renamedItem = getStackInSlot( 2 );
|
||||||
|
|
||||||
|
if ( PlateA != null && PlateA.stackSize > 1 )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if ( PlateB != null && PlateB.stackSize > 1 )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if ( renamedItem != null && renamedItem.stackSize > 1 )
|
||||||
|
return null;
|
||||||
|
|
||||||
boolean isNameA = AEApi.instance().materials().materialNamePress.sameAs( PlateA );
|
boolean isNameA = AEApi.instance().materials().materialNamePress.sameAs( PlateA );
|
||||||
boolean isNameB = AEApi.instance().materials().materialNamePress.sameAs( PlateB );
|
boolean isNameB = AEApi.instance().materials().materialNamePress.sameAs( PlateB );
|
||||||
|
|
||||||
if ( (isNameA || isNameB) && (isNameA || PlateA == null) && (isNameB || PlateB == null) )
|
if ( (isNameA || isNameB) && (isNameA || PlateA == null) && (isNameB || PlateB == null) )
|
||||||
{
|
{
|
||||||
ItemStack renamedItem = getStackInSlot( 2 );
|
|
||||||
if ( renamedItem != null )
|
if ( renamedItem != null )
|
||||||
{
|
{
|
||||||
String name = "";
|
String name = "";
|
||||||
|
|||||||
Reference in New Issue
Block a user