diff --git a/src/main/java/appeng/core/sync/AppEngPacketHandlerBase.java b/src/main/java/appeng/core/sync/AppEngPacketHandlerBase.java index 25646d9fc..8d32bc228 100644 --- a/src/main/java/appeng/core/sync/AppEngPacketHandlerBase.java +++ b/src/main/java/appeng/core/sync/AppEngPacketHandlerBase.java @@ -24,34 +24,9 @@ import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; +import appeng.core.sync.packets.*; import io.netty.buffer.ByteBuf; -import appeng.core.sync.packets.PacketAssemblerAnimation; -import appeng.core.sync.packets.PacketClick; -import appeng.core.sync.packets.PacketCompassRequest; -import appeng.core.sync.packets.PacketCompassResponse; -import appeng.core.sync.packets.PacketCompressedNBT; -import appeng.core.sync.packets.PacketConfigButton; -import appeng.core.sync.packets.PacketCraftRequest; -import appeng.core.sync.packets.PacketFluidSlot; -import appeng.core.sync.packets.PacketInventoryAction; -import appeng.core.sync.packets.PacketJEIRecipe; -import appeng.core.sync.packets.PacketLightning; -import appeng.core.sync.packets.PacketMEFluidInventoryUpdate; -import appeng.core.sync.packets.PacketMEInventoryUpdate; -import appeng.core.sync.packets.PacketMatterCannon; -import appeng.core.sync.packets.PacketMockExplosion; -import appeng.core.sync.packets.PacketPaintedEntity; -import appeng.core.sync.packets.PacketPartPlacement; -import appeng.core.sync.packets.PacketPatternSlot; -import appeng.core.sync.packets.PacketProgressBar; -import appeng.core.sync.packets.PacketSwapSlots; -import appeng.core.sync.packets.PacketSwitchGuis; -import appeng.core.sync.packets.PacketTargetFluidStack; -import appeng.core.sync.packets.PacketTargetItemStack; -import appeng.core.sync.packets.PacketTransitionEffect; -import appeng.core.sync.packets.PacketValueConfig; - public class AppEngPacketHandlerBase { @@ -107,7 +82,10 @@ public class AppEngPacketHandlerBase PACKET_PAINTED_ENTITY( PacketPaintedEntity.class ), - PACKET_FLUID_TANK( PacketFluidSlot.class ); + PACKET_FLUID_TANK( PacketFluidSlot.class ), + + PACKET_INFORM_PLAYER( PacketInformPlayer.class ); + private final Class packetClass; private final Constructor packetConstructor; diff --git a/src/main/java/appeng/core/sync/packets/PacketInformPlayer.java b/src/main/java/appeng/core/sync/packets/PacketInformPlayer.java new file mode 100644 index 000000000..4b962a59e --- /dev/null +++ b/src/main/java/appeng/core/sync/packets/PacketInformPlayer.java @@ -0,0 +1,89 @@ +package appeng.core.sync.packets; + +import appeng.api.storage.data.IAEItemStack; +import appeng.core.AppEng; +import appeng.core.sync.AppEngPacket; +import appeng.core.sync.network.INetworkInfo; +import appeng.util.item.AEItemStack; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.text.TextComponentString; + +import java.io.IOException; + +public class PacketInformPlayer extends AppEngPacket +{ + private IAEItemStack actualItem = null; + private IAEItemStack reportedItem = null; + private final InfoType type; + + public PacketInformPlayer( ByteBuf stream ) throws IOException + { + this.type = InfoType.values()[stream.readInt()]; + if( type == InfoType.PARTIAL_ITEM_EXTRACTION ) + { + this.reportedItem = AEItemStack.fromPacket( stream ); + this.actualItem = AEItemStack.fromPacket( stream ); + } + else if( type == InfoType.NO_ITEMS_EXTRACTED ) + { + this.reportedItem = AEItemStack.fromPacket( stream ); + } + } + + public PacketInformPlayer( final IAEItemStack iaeItemStack ) throws IOException + { + this( iaeItemStack, null ); + } + + public PacketInformPlayer( IAEItemStack extra, IAEItemStack result ) throws IOException + { + this.reportedItem = extra; + this.actualItem = result; + if( actualItem == null ) + { + this.type = InfoType.NO_ITEMS_EXTRACTED; + } + else + { + this.type = InfoType.PARTIAL_ITEM_EXTRACTION; + } + + final ByteBuf data = Unpooled.buffer(); + + data.writeInt( this.getPacketID() ); + + data.writeInt( type.ordinal() ); + + reportedItem.writeToPacket( data ); + if( actualItem != null ) + { + actualItem.writeToPacket( data ); + } + + this.configureWrite( data ); + } + + @Override + public void clientPacketData( final INetworkInfo network, final AppEngPacket packet, final EntityPlayer player ) + { + TextComponentString msg = null; + + if( this.type == InfoType.PARTIAL_ITEM_EXTRACTION ) + { + AppEng.proxy.getPlayers().get( 0 ).sendStatusMessage( new TextComponentString( "System reported " + reportedItem.getStackSize() + " " + reportedItem.getItem().getItemStackDisplayName( reportedItem.getDefinition() ) + " available but could only extract" + actualItem.getStackSize() ), false ); + } + else if( this.type == InfoType.NO_ITEMS_EXTRACTED ) + { + AppEng.proxy.getPlayers().get( 0 ).sendStatusMessage( new TextComponentString( "System reported " + reportedItem.getStackSize() + " " + reportedItem.getItem().getItemStackDisplayName( reportedItem.getDefinition() ) + " available but could not extract anything" ), false ); + } + + } + + public enum InfoType + { + PARTIAL_ITEM_EXTRACTION, + NO_ITEMS_EXTRACTED + } +} diff --git a/src/main/java/appeng/crafting/CraftingTreeNode.java b/src/main/java/appeng/crafting/CraftingTreeNode.java index a3fcf094b..5a7630654 100644 --- a/src/main/java/appeng/crafting/CraftingTreeNode.java +++ b/src/main/java/appeng/crafting/CraftingTreeNode.java @@ -36,9 +36,19 @@ import appeng.api.networking.security.IActionSource; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketInformPlayer; import appeng.me.cluster.implementations.CraftingCPUCluster; +import appeng.util.Platform; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.world.World; import net.minecraftforge.fml.common.Optional; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; @Optional.Interface( iface = "gregtech.api.items.IToolItem", modid = "gregtech" ) public class CraftingTreeNode @@ -360,7 +370,21 @@ public class CraftingTreeNode { if( src.player().isPresent() ) { - src.player().get().sendStatusMessage( new TextComponentString( "System reported " + i.getStackSize() + " " + i.getDefinition().getItem().getItemStackDisplayName( i.getDefinition() ) + " available but could not extract anything" ), false ); + try + { + if( ex == null ) + { + NetworkHandler.instance().sendTo( new PacketInformPlayer( i ), (EntityPlayerMP) src.player().get() ); + } + else + { + NetworkHandler.instance().sendTo( new PacketInformPlayer( ex, i ), (EntityPlayerMP) src.player().get() ); + } + } + catch( IOException e ) + { + e.printStackTrace(); + } } throw new CraftBranchFailure( i, i.getStackSize() ); } diff --git a/src/main/java/appeng/crafting/MECraftingInventory.java b/src/main/java/appeng/crafting/MECraftingInventory.java index 379937498..afa58a50d 100644 --- a/src/main/java/appeng/crafting/MECraftingInventory.java +++ b/src/main/java/appeng/crafting/MECraftingInventory.java @@ -28,9 +28,14 @@ import appeng.api.storage.IStorageChannel; import appeng.api.storage.channels.IItemStorageChannel; import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IItemList; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketInformPlayer; import appeng.util.inv.ItemListIgnoreCrafting; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.util.text.TextComponentString; +import java.io.IOException; + public class MECraftingInventory implements IMEInventory { @@ -309,13 +314,20 @@ public class MECraftingInventory implements IMEInventory { if( src.player().isPresent() ) { - if( result == null ) + try { - src.player().get().sendStatusMessage( new TextComponentString( "System reported " + extra.getStackSize() + " " + extra.getDefinition().getDisplayName() + " available but could not extract anything" ), false ); + if( result == null ) + { + NetworkHandler.instance().sendTo( new PacketInformPlayer( extra ), (EntityPlayerMP) src.player().get() ); + } + else + { + NetworkHandler.instance().sendTo( new PacketInformPlayer( extra, result ), (EntityPlayerMP) src.player().get() ); + } } - else + catch( IOException e ) { - src.player().get().sendStatusMessage( new TextComponentString( "System reported " + extra.getStackSize() + " " + extra.getDefinition().getDisplayName() + " available but could only extract " + result.getStackSize() ), false ); + e.printStackTrace(); } } failed = true;