Essentia Terminal Upgrades

Added mult-mouse-button support to essentia terminal.
Fixed ACT scroll bug issue with NEI.
Essentia terminal can fill/drain containers when they are dragged and
clicked over an aspect.
This commit is contained in:
Chris committed 2016-01-03 16:14:26 -05:00
1 parent c095b8131a
commit 08efd770be
20 files changed
+832 -598

No files matched your search

+8 -3
View File
@@ -1,11 +1,16 @@
01/02/2016 0.10.0.0 - Beta
01/03/2016 0.10.0.0 - Beta
Essentia terminal can fill/drain containers when they are dragged and clicked over an aspect.
01/02/2016 0.10.0.0 - Beta
File restructure & code refactor.
Added mult-mouse-button support to essentia terminal.
Fixed ACT scroll bug issue with NEI.
01/01/2016 0.10.0.0 - Beta
Essentia subsystem now supports craftable aspects.
Essentia terminals now shows craftable essentia.
Essentia terminal now shows craftable essentia.
Reworked some terrible GUI code.
Fixed sort-by-name in the Essentia Terminals.
Fixed sort-by-name in the Essentia Terminal.
Fixed a bug where some parts would not be aware of neighboring blocks when placed.
Fixes #53: :D
Todo: Lore, recipe, texture.
@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
@@ -297,16 +298,12 @@ public class GuiArcaneCraftingTerminal
*
* @param deltaZ
*/
private void doMEWheelAction( final int deltaZ )
private void doMEWheelAction( final int deltaZ, final int mouseX, final int mouseY )
{
// Get the mouse position
int mouseX = ( Mouse.getEventX() * this.width ) / this.mc.displayWidth;
int mouseY = this.height - ( ( Mouse.getEventY() * this.height ) / this.mc.displayHeight ) - 1;
// Is the mouse inside the ME area?
if( ThEGuiHelper.INSTANCE.isPointInGuiRegion( GuiConstants_ACT.ME_ITEM_POS_Y, GuiConstants_ACT.ME_ITEM_POS_X,
this.numberOfWidgetRows * GuiConstants_ACT.ME_ROW_HEIGHT, GuiConstants_ACT.ME_GRID_WIDTH, mouseX, mouseY, this.guiLeft,
this.guiTop ) )
if( ThEGuiHelper.INSTANCE.isPointInGuiRegion( ME_ITEM_POS_Y, ME_ITEM_POS_X,
this.numberOfWidgetRows * ME_ROW_HEIGHT, ME_GRID_WIDTH,
mouseX, mouseY, this.guiLeft, this.guiTop ) )
{
// Which direction was the scroll?
if( deltaZ > 0 )
@@ -442,11 +439,8 @@ public class GuiArcaneCraftingTerminal
}
else
{
// Get the state of the shift keys
boolean isShiftHeld = Keyboard.isKeyDown( Keyboard.KEY_LSHIFT ) || Keyboard.isKeyDown( Keyboard.KEY_RSHIFT );
// Let the server know the user is requesting an itemstack.
Packet_S_ArcaneCraftingTerminal.sendExtract( this.player, widgetStack, mouseButton, isShiftHeld );
Packet_S_ArcaneCraftingTerminal.sendExtract( this.player, widgetStack, mouseButton, GuiScreen.isShiftKeyDown() );
}
}
@@ -573,7 +567,7 @@ public class GuiArcaneCraftingTerminal
*/
private void updateScrollbarRange()
{
// TODO: This needs some work to prevent overscroll
// TODO: Is there still overscroll?
// Calculate the total number of rows needed to display ALL items
int totalNumberOfRows = (int)Math.ceil( this.repo.size() / (double)GuiConstants_ACT.ME_COLUMNS );
@@ -992,6 +986,32 @@ public class GuiArcaneCraftingTerminal
}
}
@Override
protected void onMouseWheel( final int deltaZ, final int mouseX, final int mouseY )
{
// Is the mouse inside of, or to the left of, the GUI?
if( mouseX > ( this.guiLeft + GUI_WIDTH ) )
{
// Mouse is to the right of the gui
return;
}
// Is shift being held?
if( GuiScreen.isShiftKeyDown() )
{
// Extract or insert based on the motion of the wheel
this.doMEWheelAction( deltaZ, mouseX, mouseY );
}
else
{
// Inform the scroll bar
this.scrollBar.wheel( deltaZ );
// Update the item widgets
this.onScrollbarMoved();
}
}
@Override
protected void onScrollbarMoved()
{
@@ -1047,46 +1067,6 @@ public class GuiArcaneCraftingTerminal
return this.viewMode;
}
/**
* If the mouse wheel has moved, passes the data to the scrollbar
*/
@Override
public void handleMouseInput()
{
// Get the delta z for the scroll wheel
int deltaZ = Mouse.getEventDWheel();
// Did it move?
if( deltaZ != 0 )
{
// Is the mouse inside of, or to the left of, the GUI?
int mouseX = ( Mouse.getX() * this.width ) / this.mc.displayWidth;
if( mouseX <= ( this.guiLeft + GuiConstants_ACT.GUI_WIDTH ) )
{
// Is shift being held?
if( Keyboard.isKeyDown( Keyboard.KEY_LSHIFT ) || Keyboard.isKeyDown( Keyboard.KEY_RSHIFT ) )
{
// Extract or insert based on the motion of the wheel
this.doMEWheelAction( deltaZ );
}
else
{
// Inform the scroll bar
this.scrollBar.wheel( deltaZ );
// Update the item widgets
this.onScrollbarMoved();
}
return;
}
}
// Call super
super.handleMouseInput();
}
/**
* Sets the gui up.
*/
@@ -1218,25 +1198,6 @@ public class GuiArcaneCraftingTerminal
this.viewNeedsUpdate = true;
}
/**
* Called to update what the player is holding.
*
* @param heldItemstack
*/
public void onReceivePlayerHeld( final IAEItemStack heldItemstack )
{
ItemStack itemStack = null;
// Get the stack
if( heldItemstack != null )
{
itemStack = heldItemstack.getItemStack();
}
// Set what the player is holding
this.player.inventory.setItemStack( itemStack );
}
/**
* Called when the server sends the sorting order and direction.
*
@@ -5,6 +5,7 @@ import java.util.Collection;
import java.util.Collections;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -24,7 +25,10 @@ import thaumicenergistics.client.gui.buttons.GuiButtonViewType;
import thaumicenergistics.client.gui.widget.ThEWidget;
import thaumicenergistics.client.gui.widget.WidgetAspectSelector;
import thaumicenergistics.client.textures.GuiTextureManager;
import thaumicenergistics.common.container.*;
import thaumicenergistics.common.container.ContainerEssentiaCellTerminalBase;
import thaumicenergistics.common.container.ContainerEssentiaCell;
import thaumicenergistics.common.container.ContainerEssentiaTerminal;
import thaumicenergistics.common.container.ContainerWirelessEssentiaTerminal;
import thaumicenergistics.common.inventory.HandlerWirelessEssentiaTerminal;
import thaumicenergistics.common.network.packet.server.Packet_S_EssentiaCellTerminal;
import thaumicenergistics.common.parts.AEPartEssentiaTerminal;
@@ -95,7 +99,7 @@ public class GuiEssentiaCellTerminal
/**
* The container associated with this gui
*/
protected AbstractContainerCellTerminalBase baseContainer;
protected ContainerEssentiaCellTerminalBase baseContainer;
/**
* Mode used to sort the aspects
@@ -155,7 +159,7 @@ public class GuiEssentiaCellTerminal
* @param container
* Container associated with the gui.
*/
protected GuiEssentiaCellTerminal( final EntityPlayer player, final AbstractContainerCellTerminalBase container, final String title )
protected GuiEssentiaCellTerminal( final EntityPlayer player, final ContainerEssentiaCellTerminalBase container, final String title )
{
// Call super
super( container );
@@ -167,10 +171,10 @@ public class GuiEssentiaCellTerminal
this.player = player;
// Set the X size
this.xSize = GUI_SIZE_X;
this.xSize = GUI_WIDTH;
// Set the Y size
this.ySize = GUI_SIZE_Y;
this.ySize = GUI_HEIGHT;
// Set the title
this.guiTitle = title;
@@ -278,6 +282,22 @@ public class GuiEssentiaCellTerminal
ThEStrings.Part_EssentiaTerminal.getLocalized() );
}
/**
* True if the mouse is over the widget area
*
* @param mouseX
* @param mouseY
* @return
*/
private boolean isMouseOverWidgetArea( final int mouseX, final int mouseY )
{
return ThEGuiHelper.INSTANCE.isPointInGuiRegion(
WIDGET_OFFSET_Y, WIDGET_OFFSET_X,
WIDGET_ROWS_PER_PAGE * ThEWidget.WIDGET_SIZE,
WIDGETS_PER_ROW * ThEWidget.WIDGET_SIZE,
mouseX, mouseY, this.guiLeft, this.guiTop );
}
/**
* Updates the scroll bar's range.
*/
@@ -488,16 +508,18 @@ public class GuiEssentiaCellTerminal
@Override
protected void mouseClicked( final int mouseX, final int mouseY, final int mouseBtn )
{
boolean mouseOverElement;
// Boolean trackers for cleaner code
final boolean isLeftClick = ( mouseBtn == ThEGuiHelper.MOUSE_BUTTON_LEFT );
final boolean isRightClick = ( mouseBtn == ThEGuiHelper.MOUSE_BUTTON_RIGHT );
final boolean isMiddleClick = ( mouseBtn == ThEGuiHelper.MOUSE_BUTTON_WHEEL );
// Is the mouse in the widget area?
mouseOverElement = ThEGuiHelper.INSTANCE.isPointInGuiRegion(
WIDGET_OFFSET_Y, WIDGET_OFFSET_X,
WIDGET_ROWS_PER_PAGE * ThEWidget.WIDGET_SIZE,
WIDGETS_PER_ROW * ThEWidget.WIDGET_SIZE,
mouseX, mouseY, this.guiLeft, this.guiTop );
if( mouseOverElement )
if( this.isMouseOverWidgetArea( mouseX, mouseY ) )
{
// Is the view mode crafting?
boolean viewingCraftable = ( this.viewMode == ViewItems.CRAFTABLE );
// Is the player holding anything?
boolean playerHoldingItem = ( this.player.inventory.getItemStack() != null );
// Check each widget
for( WidgetAspectSelector widget : this.aspectWidgets )
@@ -505,18 +527,27 @@ public class GuiEssentiaCellTerminal
// Is the mouse over this widget?
if( widget.isMouseOverWidget( mouseX, mouseY ) )
{
// Send crafting request if
// Only Craftable or Craftable and ( ( LeftClick and 0 ) or ( MiddleClick ) )
if( ( this.viewMode == ViewItems.CRAFTABLE ) || widget.getCraftable() && (
( mouseBtn == ThEGuiHelper.MOUSE_BUTTON_WHEEL ) ) ||
( ( mouseBtn == ThEGuiHelper.MOUSE_BUTTON_LEFT ) && ( widget.getAmount() == 0 ) ) )
// Is the player holding something?
if( playerHoldingItem )
{
// Send request
Packet_S_EssentiaCellTerminal.sendAutoCraft( this.player, widget.getAspect() );
// Inform the server
Packet_S_EssentiaCellTerminal.sendInteractWithHeldItem( this.player, widget.getAspect() );
}
else
{
// Check if the aspect is to be crafted
if( ( !isRightClick && widget.hasAspect() && widget.getCraftable() ) &&
( viewingCraftable
|| ( isMiddleClick || ( isLeftClick && ( widget.getAmount() == 0 ) ) ) ) )
{
// Send request
Packet_S_EssentiaCellTerminal.sendAutoCraft( this.player, widget.getAspect() );
// Send the click
widget.onMouseClicked();
}
// Send the click
widget.onMouseClicked();
}
// Stop searching
return;
@@ -525,14 +556,14 @@ public class GuiEssentiaCellTerminal
}
// Is the mouse over the search bar?
mouseOverElement = mouseX >= this.searchBar.xPosition
boolean mouseOverSearchBar = mouseX >= this.searchBar.xPosition
&& mouseX < this.searchBar.xPosition + this.searchBar.width
&& mouseY >= this.searchBar.yPosition
&& mouseY < this.searchBar.yPosition + this.searchBar.height;
if( mouseOverElement )
if( mouseOverSearchBar )
{
// Left click?
if( mouseBtn == ThEGuiHelper.MOUSE_BUTTON_LEFT )
if( isLeftClick )
{
// Pass to search field.
this.searchBar.mouseClicked( mouseX, mouseY, mouseBtn );
@@ -542,7 +573,7 @@ public class GuiEssentiaCellTerminal
}
// Right click?
else if( mouseBtn == ThEGuiHelper.MOUSE_BUTTON_RIGHT )
else if( isRightClick )
{
// Clear the search text
this.searchTerm = "";
@@ -586,6 +617,26 @@ public class GuiEssentiaCellTerminal
}
}
@Override
protected void onMouseWheel( final int deltaZ, final int mouseX, final int mouseY )
{
// Is the mouse inside of, or to the left of, the GUI?
if( mouseX > ( this.guiLeft + GUI_WIDTH ) )
{
// Mouse is to the right of the gui
return;
}
// Is shift not being held down?
if( !GuiScreen.isShiftKeyDown() )
{
// Inform the scroll bar
this.scrollBar.wheel( deltaZ );
this.onScrollbarMoved();
}
}
@Override
protected void onScrollbarMoved()
{
@@ -661,27 +712,6 @@ public class GuiEssentiaCellTerminal
return( this.selectedAspectStack != null ? this.selectedAspectStack.getAspect() : null );
}
/**
* If the mouse wheel moves, updates the scrollbar
*/
@Override
public void handleMouseInput()
{
// Call super
super.handleMouseInput();
// Get the delta z for the scroll wheel
int deltaZ = Mouse.getEventDWheel();
// Did the wheel move?
if( deltaZ != 0 )
{
// Inform the scroll bar
this.scrollBar.wheel( deltaZ );
this.onScrollbarMoved();
}
}
/**
* Sets the gui up.
*/
@@ -21,7 +21,7 @@ public abstract class GuiConstants_ECT
/**
* Size of the gui.
*/
protected static final int GUI_SIZE_X = 195, GUI_SIZE_Y = 204;
protected static final int GUI_WIDTH = 195, GUI_HEIGHT = 204;
/**
* Offset from the top of the screen to draw the gui at.
@@ -190,6 +190,15 @@ public abstract class ThEScrollbarGui
super.mouseClicked( mouseX, mouseY, mouseButton );
}
/**
* Called when the mouse wheel is scrolled.
*
* @param deltaZ
* @param mouseX
* @param mouseY
*/
protected abstract void onMouseWheel( int deltaZ, int mouseX, int mouseY );
/**
* Called when the scroll bar has moved.
*/
@@ -267,6 +276,27 @@ public abstract class ThEScrollbarGui
}
@Override
public void handleMouseInput()
{
// Call super
super.handleMouseInput();
// Get the delta z for the scroll wheel
int deltaZ = Mouse.getEventDWheel();
// Did it move?
if( deltaZ != 0 )
{
// Get the mouse position
int mouseX = ( Mouse.getEventX() * this.width ) / this.mc.displayWidth;
int mouseY = this.height - ( ( Mouse.getEventY() * this.height ) / this.mc.displayHeight ) - 1;
// Call event
this.onMouseWheel( deltaZ, mouseX, mouseY );
}
}
/**
* Sets the gui up.
*/
@@ -22,6 +22,7 @@ import thaumicenergistics.integration.tc.EssentiaItemContainerHelper;
import thaumicenergistics.integration.tc.EssentiaItemContainerHelper.AspectItemType;
import appeng.api.config.Settings;
import appeng.api.config.ViewItems;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.PlayerSource;
import appeng.api.storage.IMEInventoryHandler;
@@ -39,7 +40,7 @@ import appeng.util.Platform;
*
*/
public class ContainerEssentiaCell
extends AbstractContainerCellTerminalBase
extends ContainerEssentiaCellTerminalBase
{
/**
* The ME chest the cell is stored in.
@@ -174,6 +175,12 @@ public class ContainerEssentiaCell
return new HandlerItemEssentiaCell( essentiaCell, this.chestSaveProvider );
}
@Override
protected BaseActionSource getActionSource()
{
return this.playerSource;
}
/**
* Transfers essentia.
*/
@@ -181,7 +188,7 @@ public class ContainerEssentiaCell
public void doWork( final int elapsedTicks )
{
// Transfer essentia if needed.
this.transferEssentia( this.playerSource );
this.transferEssentiaFromWorkSlots();
}
@Override
@@ -13,6 +13,7 @@ import thaumicenergistics.common.storage.AspectStackComparator.AspectStackCompar
import thaumicenergistics.common.utils.EffectiveSide;
import appeng.api.AEApi;
import appeng.api.config.ViewItems;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.PlayerSource;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.ContainerOpenContext;
@@ -25,7 +26,7 @@ import appeng.container.implementations.ContainerCraftAmount;
*
*/
public class ContainerEssentiaTerminal
extends AbstractContainerCellTerminalBase
extends ContainerEssentiaCellTerminalBase
{
/**
* The terminal this is associated with.
@@ -83,6 +84,12 @@ public class ContainerEssentiaTerminal
this.bindToInventory( terminal.getInventory() );
}
@Override
protected BaseActionSource getActionSource()
{
return this.playerSource;
}
/**
* Transfers essentia.
*/
@@ -90,7 +97,7 @@ public class ContainerEssentiaTerminal
public void doWork( final int elapsedTicks )
{
// Transfer essentia if needed.
this.transferEssentia( this.playerSource );
this.transferEssentiaFromWorkSlots();
}
@Override
@@ -25,6 +25,7 @@ import thaumicenergistics.common.container.slot.SlotArcaneCraftingResult;
import thaumicenergistics.common.container.slot.SlotArmor;
import thaumicenergistics.common.container.slot.SlotRestrictive;
import thaumicenergistics.common.network.packet.client.Packet_C_ArcaneCraftingTerminal;
import thaumicenergistics.common.network.packet.client.Packet_C_Sync;
import thaumicenergistics.common.parts.AEPartArcaneCraftingTerminal;
import thaumicenergistics.common.utils.EffectiveSide;
import thaumicenergistics.common.utils.ThEUtils;
@@ -303,7 +304,6 @@ public class ContainerPartArcaneCraftingTerminal
* I hate this, but I have tried everything I can think of, and the
* equipped armor will not change immediately unless
* the notification comes from the open container, this container.
* TODO: *sigh*... player.inventory.markDirty() exists .-.
*/
// Create the 'hidden'slot
armorSlot = new SlotArmor( player.inventory, 36 + ( 3 - armorIndex ), 0, -1000, armorIndex, false );
@@ -1032,7 +1032,7 @@ public class ContainerPartArcaneCraftingTerminal
}
// Send the update to the client
Packet_C_ArcaneCraftingTerminal.setPlayerHeldItem( player, leftOverStack );
Packet_C_Sync.sendPlayerHeldItem( player, ( leftOverStack == null ? null : leftOverStack.getItemStack() ) );
}
/**
@@ -1239,8 +1239,7 @@ public class ContainerPartArcaneCraftingTerminal
this.monitor.extractItems( toExtract, Actionable.MODULATE, this.playerSource );
// Send the update to the client
Packet_C_ArcaneCraftingTerminal.setPlayerHeldItem( player,
AEApi.instance().storage().createItemStack( player.inventory.getItemStack() ) );
Packet_C_Sync.sendPlayerHeldItem( player, player.inventory.getItemStack() );
}
}
@@ -20,13 +20,14 @@ import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.Settings;
import appeng.api.config.ViewItems;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.ContainerOpenContext;
import appeng.container.implementations.ContainerCraftAmount;
import appeng.util.Platform;
public class ContainerWirelessEssentiaTerminal
extends AbstractContainerCellTerminalBase
extends ContainerEssentiaCellTerminalBase
{
/**
@@ -153,6 +154,12 @@ public class ContainerWirelessEssentiaTerminal
}
}
@Override
protected BaseActionSource getActionSource()
{
return this.handler.getActionHost();
}
/**
* Transfers essentia, checks the network connectivity, and drains power.
*/
@@ -188,7 +195,7 @@ public class ContainerWirelessEssentiaTerminal
}
// Transfer essentia if needed
this.transferEssentia( this.handler.getActionHost() );
this.transferEssentiaFromWorkSlots();
}
@Override
@@ -129,6 +129,9 @@ public class NetworkHandler
// Distillation encoder
registerPacket( Packet_S_DistillationEncoder.class );
// Sync packet
registerPacket( Packet_C_Sync.class );
}
public static void sendAreaPacketToClients( final ThEAreaPacket areaPacket, final int range )
@@ -515,6 +515,7 @@ public abstract class ThEBasePacket
stream.writeByte( this.mode );
// Write the player
// TODO: This isn't needed for client packets.
ThEBasePacket.writePlayer( this.player, stream );
// Write if there is a compressed sub-stream.
@@ -37,7 +37,7 @@ public abstract class WrapperPacket
if( id == -1 )
{
// Invalid packet
ThELog.warning( "Invalid packet ID detected" );
ThELog.warning( "Unknown packet detected" );
return;
}
@@ -26,13 +26,11 @@ public class Packet_C_ArcaneCraftingTerminal
*/
private static final byte MODE_RECEIVE_CHANGE = 0,
MODE_RECEIVE_FULL_LIST = 1,
MODE_RECEIVE_PLAYER_HOLDING = 2,
MODE_RECEIVE_SORTS = 3,
MODE_UPDATE_COSTS = 4;
private IAEItemStack changedStack;
private IItemList<IAEItemStack> fullList;
private boolean isHeldEmpty;
private SortOrder sortingOrder;
private SortDir sortingDirection;
private ViewItems viewMode;
@@ -101,28 +99,6 @@ public class Packet_C_ArcaneCraftingTerminal
NetworkHandler.sendPacketToClient( packet );
}
/**
* Creates a packet with an update to what itemstack the player is holding.
*
* @param player
* @param heldItem
* @return
*/
public static void setPlayerHeldItem( final EntityPlayer player, final IAEItemStack heldItem )
{
// Create the packet
Packet_C_ArcaneCraftingTerminal packet = newPacket( player, Packet_C_ArcaneCraftingTerminal.MODE_RECEIVE_PLAYER_HOLDING );
// Set the held item
packet.changedStack = heldItem;
// Is the player holding anything?
packet.isHeldEmpty = ( heldItem == null );
// Send it
NetworkHandler.sendPacketToClient( packet );
}
/**
* Creates a packet with a changed network stack amount
*
@@ -177,11 +153,6 @@ public class Packet_C_ArcaneCraftingTerminal
( (GuiArcaneCraftingTerminal)gui ).onReceiveChange( this.changedStack );
break;
case Packet_C_ArcaneCraftingTerminal.MODE_RECEIVE_PLAYER_HOLDING:
// Set the held item
( (GuiArcaneCraftingTerminal)gui ).onReceivePlayerHeld( this.changedStack );
break;
case Packet_C_ArcaneCraftingTerminal.MODE_RECEIVE_SORTS:
( (GuiArcaneCraftingTerminal)gui ).onReceiveSorting( this.sortingOrder, this.sortingDirection, this.viewMode );
break;
@@ -238,21 +209,6 @@ public class Packet_C_ArcaneCraftingTerminal
break;
case Packet_C_ArcaneCraftingTerminal.MODE_RECEIVE_PLAYER_HOLDING:
// Read if the itemstack is empty
this.isHeldEmpty = stream.readBoolean();
// Is it not empty?
if( !this.isHeldEmpty )
{
this.changedStack = ThEBasePacket.readAEItemStack( stream );
}
else
{
this.changedStack = null;
}
break;
case Packet_C_ArcaneCraftingTerminal.MODE_RECEIVE_SORTS:
// Read sorts
this.sortingDirection = EnumCache.AE_SORT_DIRECTIONS[stream.readInt()];
@@ -297,19 +253,6 @@ public class Packet_C_ArcaneCraftingTerminal
ThEBasePacket.writeAEItemStack( this.changedStack, stream );
break;
case Packet_C_ArcaneCraftingTerminal.MODE_RECEIVE_PLAYER_HOLDING:
// Write if the held item is empty
stream.writeBoolean( this.isHeldEmpty );
// Is it not empty?
if( !this.isHeldEmpty )
{
// Write the stack
ThEBasePacket.writeAEItemStack( this.changedStack, stream );
}
break;
case Packet_C_ArcaneCraftingTerminal.MODE_RECEIVE_SORTS:
// Write the sorts
stream.writeInt( this.sortingDirection.ordinal() );
@@ -9,6 +9,7 @@ import net.minecraft.entity.player.EntityPlayer;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.api.storage.IAspectStack;
import thaumicenergistics.client.gui.GuiEssentiaCellTerminal;
import thaumicenergistics.common.container.ContainerEssentiaCellTerminalBase;
import thaumicenergistics.common.network.NetworkHandler;
import thaumicenergistics.common.network.ThEBasePacket;
import thaumicenergistics.common.registries.EnumCache;
@@ -21,10 +22,14 @@ import cpw.mods.fml.relauncher.SideOnly;
public class Packet_C_EssentiaCellTerminal
extends ThEClientPacket
{
private static final byte MODE_FULL_LIST = 0;
private static final byte MODE_SELECTED_ASPECT = 1;
private static final byte MODE_VIEWING_CHANGED = 2;
private static final byte MODE_LIST_CHANGED = 3;
/**
* Modes
*/
private static final byte MODE_FULL_LIST = 0,
MODE_SELECTED_ASPECT = 1,
MODE_VIEWING_CHANGED = 2,
MODE_LIST_CHANGED = 3,
MODE_PLAY_SOUND = 4;
private Collection<IAspectStack> aspectStackList;
private Aspect selectedAspect;
@@ -60,7 +65,6 @@ public class Packet_C_EssentiaCellTerminal
public static void sendFullList( final EntityPlayer player, final Collection<IAspectStack> list )
{
Packet_C_EssentiaCellTerminal packet = newPacket( player, MODE_FULL_LIST );
// Set the player
// Mark to use compression
packet.useCompression = true;
@@ -72,6 +76,19 @@ public class Packet_C_EssentiaCellTerminal
NetworkHandler.sendPacketToClient( packet );
}
/**
* Asks the client to play the transfer audio.
*
* @param player
*/
public static void sendPlayTransferAudio( final EntityPlayer player )
{
Packet_C_EssentiaCellTerminal packet = newPacket( player, MODE_PLAY_SOUND );
// Send it
NetworkHandler.sendPacketToClient( packet );
}
/**
* Sends the viewing modes.
*
@@ -136,23 +153,28 @@ public class Packet_C_EssentiaCellTerminal
{
switch ( this.mode )
{
case Packet_C_EssentiaCellTerminal.MODE_FULL_LIST:
case MODE_FULL_LIST:
( (GuiEssentiaCellTerminal)gui ).onReceiveAspectList( this.aspectStackList );
break;
case Packet_C_EssentiaCellTerminal.MODE_SELECTED_ASPECT:
case MODE_SELECTED_ASPECT:
( (GuiEssentiaCellTerminal)gui ).onReceiveSelectedAspect( this.selectedAspect );
break;
case Packet_C_EssentiaCellTerminal.MODE_VIEWING_CHANGED:
case MODE_VIEWING_CHANGED:
// Update the modes
( (GuiEssentiaCellTerminal)gui ).onViewingModesChanged( this.sortMode, this.viewMode );
break;
case Packet_C_EssentiaCellTerminal.MODE_LIST_CHANGED:
case MODE_LIST_CHANGED:
// Update the list
( (GuiEssentiaCellTerminal)gui ).onReceiveAspectListChange( this.change );
break;
case MODE_PLAY_SOUND:
// Play the sound!
( (ContainerEssentiaCellTerminalBase)this.player.openContainer ).playTransferSound( this.player, false );
break;
}
}
}
@@ -0,0 +1,120 @@
package thaumicenergistics.common.network.packet.client;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import thaumicenergistics.common.network.NetworkHandler;
import thaumicenergistics.common.network.ThEBasePacket;
/**
* Packed used to send misc. sync events to the client.
*
* @author Nividica
*
*/
public class Packet_C_Sync
extends ThEClientPacket
{
/**
* Packet modes.
*/
private static final byte MODE_PLAYER_HELD = 1;
private ItemStack itemStack;
private boolean flag;
/**
* Creates the packet
*
* @param player
* @param mode
* @return
*/
private static Packet_C_Sync newPacket( final EntityPlayer player, final byte mode )
{
// Create the packet
Packet_C_Sync packet = new Packet_C_Sync();
// Set the player & mode
packet.player = player;
packet.mode = mode;
return packet;
}
/**
* Creates a packet with an update to what itemstack the player is holding.
*
* @param player
* @param heldItem
* @return
*/
public static void sendPlayerHeldItem( final EntityPlayer player, final ItemStack heldItem )
{
// Create the packet
Packet_C_Sync packet = newPacket( player, MODE_PLAYER_HELD );
// Set the held item
packet.itemStack = heldItem;
// Is the player holding anything?
packet.flag = ( heldItem != null );
// Send it
NetworkHandler.sendPacketToClient( packet );
}
@Override
protected void readData( final ByteBuf stream )
{
switch ( this.mode )
{
case MODE_PLAYER_HELD:
// Read if the item is null
this.flag = stream.readBoolean();
if( this.flag )
{
// Read stack
this.itemStack = ThEBasePacket.readItemstack( stream );
}
else
{
this.itemStack = null;
}
break;
}
}
@Override
protected void wrappedExecute()
{
switch ( this.mode )
{
case MODE_PLAYER_HELD:
// Set what the player is holding.
this.player.inventory.setItemStack( this.itemStack );
break;
}
}
@Override
protected void writeData( final ByteBuf stream )
{
switch ( this.mode )
{
case MODE_PLAYER_HELD:
// Write if the held item is null
stream.writeBoolean( this.flag );
if( this.flag )
{
// Write the stack
ThEBasePacket.writeItemstack( this.itemStack, stream );
}
break;
}
}
}
@@ -1,7 +1,8 @@
package thaumicenergistics.common.network.packet.client;
import net.minecraft.client.Minecraft;
import thaumicenergistics.common.network.ThEBasePacket;
import cpw.mods.fml.common.FMLCommonHandler;
import thaumicenergistics.common.utils.EffectiveSide;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -20,15 +21,12 @@ public abstract class ThEClientPacket
@Override
public final void execute()
{
// Ensure we have a player
if( this.player == null )
{
return;
}
// Ensure this is client side
if( FMLCommonHandler.instance().getEffectiveSide().isClient() )
if( EffectiveSide.isClientSide() )
{
// Get the player
this.player = Minecraft.getMinecraft().thePlayer;
this.wrappedExecute();
}
}
@@ -3,7 +3,7 @@ package thaumicenergistics.common.network.packet.server;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.common.container.AbstractContainerCellTerminalBase;
import thaumicenergistics.common.container.ContainerEssentiaCellTerminalBase;
import thaumicenergistics.common.network.NetworkHandler;
import thaumicenergistics.common.network.ThEBasePacket;
@@ -17,7 +17,8 @@ public class Packet_S_EssentiaCellTerminal
MODE_FULL_UPDATE = 1,
MODE_SORT_CHANGE = 2,
MODE_AUTO_CRAFT = 3,
MODE_VIEW_CHANGE = 4;
MODE_VIEW_CHANGE = 4,
MODE_HELD_ITEM = 5;
/**
* The aspect.
@@ -114,6 +115,25 @@ public class Packet_S_EssentiaCellTerminal
NetworkHandler.sendPacketToServer( packet );
}
/**
* Informs the server when an aspect has been clicked on and the player
* is holding an item.
*
* @param player
* @param aspect
*/
public static void sendInteractWithHeldItem( final EntityPlayer player, final Aspect aspect )
{
// Create the packet
Packet_S_EssentiaCellTerminal packet = newPacket( player, MODE_HELD_ITEM );
// Set the aspect
packet.selectedAspect = aspect;
// Send it
NetworkHandler.sendPacketToServer( packet );
}
/**
* Informs the server the player has (un)selected an aspect.
*
@@ -136,7 +156,7 @@ public class Packet_S_EssentiaCellTerminal
public void execute()
{
// Sanity checks
if( ( this.player == null ) || !( this.player.openContainer instanceof AbstractContainerCellTerminalBase ) )
if( ( this.player == null ) || !( this.player.openContainer instanceof ContainerEssentiaCellTerminalBase ) )
{
return;
}
@@ -144,23 +164,27 @@ public class Packet_S_EssentiaCellTerminal
switch ( this.mode )
{
case MODE_SELECTED_ASPECT:
( (AbstractContainerCellTerminalBase)this.player.openContainer ).onReceivedSelectedAspect( this.selectedAspect );
( (ContainerEssentiaCellTerminalBase)this.player.openContainer ).onReceivedSelectedAspect( this.selectedAspect );
break;
case MODE_FULL_UPDATE:
( (AbstractContainerCellTerminalBase)this.player.openContainer ).onClientRequestFullUpdate();
( (ContainerEssentiaCellTerminalBase)this.player.openContainer ).onClientRequestFullUpdate();
break;
case MODE_SORT_CHANGE:
( (AbstractContainerCellTerminalBase)this.player.openContainer ).onClientRequestSortModeChange( this.player, this.flag );
( (ContainerEssentiaCellTerminalBase)this.player.openContainer ).onClientRequestSortModeChange( this.player, this.flag );
break;
case MODE_AUTO_CRAFT:
( (AbstractContainerCellTerminalBase)this.player.openContainer ).onClientRequestAutoCraft( this.player, this.selectedAspect );
( (ContainerEssentiaCellTerminalBase)this.player.openContainer ).onClientRequestAutoCraft( this.player, this.selectedAspect );
break;
case MODE_VIEW_CHANGE:
( (AbstractContainerCellTerminalBase)this.player.openContainer ).onClientRequestViewModeChange( this.player, this.flag );
( (ContainerEssentiaCellTerminalBase)this.player.openContainer ).onClientRequestViewModeChange( this.player, this.flag );
break;
case MODE_HELD_ITEM:
( (ContainerEssentiaCellTerminalBase)this.player.openContainer ).onInteractWithHeldItem( this.player, this.selectedAspect );
break;
}
@@ -173,12 +197,14 @@ public class Packet_S_EssentiaCellTerminal
{
case MODE_SELECTED_ASPECT:
case MODE_AUTO_CRAFT:
case MODE_HELD_ITEM:
// Read the aspect
this.selectedAspect = ThEBasePacket.readAspect( stream );
break;
case MODE_SORT_CHANGE:
case MODE_VIEW_CHANGE:
// Read the flag
this.flag = stream.readBoolean();
break;
}
@@ -191,6 +217,7 @@ public class Packet_S_EssentiaCellTerminal
{
case MODE_SELECTED_ASPECT:
case MODE_AUTO_CRAFT:
case MODE_HELD_ITEM:
// Write the aspect
ThEBasePacket.writeAspect( this.selectedAspect, stream );
break;
@@ -15,7 +15,7 @@ import thaumicenergistics.client.gui.GuiEssentiaCellTerminal;
import thaumicenergistics.client.textures.BlockTextureManager;
import thaumicenergistics.common.ThEGuiHandler;
import thaumicenergistics.common.ThaumicEnergistics;
import thaumicenergistics.common.container.AbstractContainerCellTerminalBase;
import thaumicenergistics.common.container.ContainerEssentiaCellTerminalBase;
import thaumicenergistics.common.container.ContainerEssentiaTerminal;
import thaumicenergistics.common.inventory.PrivateInventory;
import thaumicenergistics.common.network.packet.server.Packet_S_ChangeGui;
@@ -98,7 +98,7 @@ public class AEPartEssentiaTerminal
super( AEPartsEnum.EssentiaTerminal );
}
public void addListener( final AbstractContainerCellTerminalBase container )
public void addListener( final ContainerEssentiaCellTerminalBase container )
{
if( container instanceof ContainerEssentiaTerminal )
{
@@ -906,6 +906,7 @@ public final class EssentiaItemContainerHelper
* Sets a labels aspect
*
* @param label
* The itemstack is modified.
* @param aspect
*/
public void setLabelAspect( final ItemStack label, final Aspect aspect )