Essentia Autocrafting

Essentia subsystem now supports craftable aspects.
Essentia terminals now shows craftable essentia.
Reworked some terrible GUI code.
Fixed sort-by-name in the Essentia Terminals.
Fixed a bug where some parts would not be aware of neighboring blocks
when placed.
Fixes #53 :D
This commit is contained in:
Chris committed 2016-01-01 21:10:19 -05:00
1 parent 69c5acc78c
commit 3cf6c16778
62 files changed
+2827 -1276

No files matched your search

+11 -3
View File
@@ -1,9 +1,17 @@
12/30/2015 0.10.0.0 - Beta
01/01/2016 0.10.0.0 - Beta
Essentia subsystem now supports craftable aspects.
Essentia terminals now shows craftable essentia.
Reworked some terrible GUI code.
Fixed sort-by-name in the Essentia Terminals.
Fixed a bug where some parts would not be aware of neighboring blocks when placed.
Fixes #53: :D
Todo: Lore, recipe, texture.
12/30/2015 0.10.0.0 - Beta
Added Distillation Encoder
Added pattern handler
Implemented Distillation Encoder GUI
Cleaned up tooltip code, and fixed underdraw issue.
Cleaned up tooltip code, and fixed underdraw issue.
12/29/2015 0.10.0.0 - Beta
Began integrating essentia into crafting system.
@@ -5,8 +5,8 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import thaumicenergistics.api.IThEConfig;
import thaumicenergistics.api.ThEApi;
import thaumicenergistics.api.networking.IEssentiaGrid;
import thaumicenergistics.grid.GridEssentiaCache;
import thaumicenergistics.grid.IEssentiaGrid;
import thaumicenergistics.gui.ThEGuiHandler;
import thaumicenergistics.integration.IntegrationCore;
import thaumicenergistics.integration.tc.EssentiaItemContainerHelper;
@@ -36,10 +36,11 @@ public interface IThEInteractionHelper
/**
* Opens the wireless gui for the specified player.
* The item the player is holding is used for the settings and power.
* Must be called from the server side.
*
* @param player
*/
public abstract void openWirelessTerminalGui( final EntityPlayer player, final IThEWirelessEssentiaTerminal terminalInterface );
public abstract void openWirelessTerminalGui( final EntityPlayer player );
/**
* Attempts to set the Arcane Crafting Terminals recipe to the items
@@ -1,5 +1,6 @@
package thaumicenergistics.grid;
package thaumicenergistics.api.networking;
import thaumicenergistics.grid.IMEEssentiaMonitor;
import appeng.api.networking.IGridCache;
public interface IEssentiaGrid
@@ -1,4 +1,4 @@
package thaumicenergistics.grid;
package thaumicenergistics.api.networking;
import java.util.Collection;
import thaumcraft.api.aspects.Aspect;
@@ -1,4 +1,4 @@
package thaumicenergistics.grid;
package thaumicenergistics.api.networking;
import thaumcraft.api.aspects.Aspect;
@@ -0,0 +1,11 @@
package thaumicenergistics.api.storage;
public interface ICraftingIssuerContainer
{
/**
* Gets the crafting issuer host terminal.
*
* @return
*/
public ICraftingIssuerHost getCraftingHost();
}
@@ -1,10 +1,10 @@
package thaumicenergistics.api;
package thaumicenergistics.api.storage;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import appeng.api.storage.ITerminalHost;
public interface ICraftingIssuerTerminalHost
public interface ICraftingIssuerHost
extends ITerminalHost
{
/**
@@ -0,0 +1,116 @@
package thaumicenergistics.api.storage;
import java.util.Collection;
import java.util.Set;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.aspect.AspectStack;
public interface IEssentiaRepo
{
/**
* Returns a set of the stored aspects.
*
* @return
*/
public Set<Aspect> aspectSet();
/**
* Removes all entries in the repo.
*/
public void clear();
/**
* Returns true if the repo has the aspect stored.
*
* @param aspect
* @return
*/
public boolean containsAspect( Aspect aspect );
/**
* Sets the repo to match the specified collection.
* Any existing data is removed.
*
* @param stacks
*/
public void copyFrom( Collection<AspectStack> stacks );
/**
* Gets the aspect stack associated with the aspect or null.
*/
public AspectStack get( Aspect aspect );
/**
* Returns all aspect information stored in the repo.
*
* @return
*/
public Collection<AspectStack> getAll();
/**
* Gets the aspect stack associated with the aspect or specified the default value.
*/
public AspectStack getOrDefault( Aspect aspect, AspectStack defaultValue );
/**
* Returns true if the repo is empty.
*
* @return
*/
public boolean isEmpty();
/**
* Changes the aspect in the repo by the specified values.
*
* @param aspect
* @param change
* @param isCraftable
* If this value is null and there is a stored value, its crafting status will remain the same.
* Otherwise it is set to false.
* @return The previous stack, if there was one.
*/
public AspectStack postChange( Aspect aspect, long change, Boolean isCraftable );
/**
* Changes the aspect in the repo by the specified aspect stack.
*
* @param change
* @return The previous stack, if there was one.
*/
public AspectStack postChange( AspectStack change );
/**
* Removes an aspect from the repo.
* Returns the removed stack.
*
* @param aspect
* @return
*/
public AspectStack remove( Aspect aspect );
/**
* Sets the aspect in the repo by the specified values.
*
* @param aspect
* @param amount
* @param isCraftable
* @return The previous stack, if there was one.
*/
public AspectStack setAspect( Aspect aspect, long amount, boolean isCraftable );
/**
* Sets the aspect in the repo to the specified aspect stack.
*
* @param stack
* @return The previous stack, if there was one.
*/
public AspectStack setAspect( AspectStack stack );
/**
* Returns the number of unique aspects stored.
*
* @return
*/
public int size();
}
@@ -17,6 +17,8 @@ import thaumicenergistics.util.GuiHelper;
*/
public class AspectStack
{
private static final String NBTKEY_ASPECT_TAG = "AspectTag", NBTKEY_ASPECT_AMOUNT = "Amount", NBTKEY_CRAFTABLE = "Craftable";
/**
* The aspect this stack contains.
*/
@@ -27,17 +29,22 @@ public class AspectStack
*/
public long stackSize;
/**
* True if the aspect is craftable.
*/
public boolean isCraftable;
/**
* Creates an empty stack
*/
public AspectStack()
{
this.aspect = null;
this.stackSize = 0;
this( null, 0, false );
}
/**
* Creates a stack using the specified aspect and amount.
* Defaults to not craftable.
*
* @param aspect
* What aspect this stack will have.
@@ -46,46 +53,79 @@ public class AspectStack
*/
public AspectStack( final Aspect aspect, final long amount )
{
this.aspect = aspect;
this.stackSize = amount;
this( aspect, amount, false );
}
/**
* Sets this stacks values to match that of the specified stack.
* Creates a stack using the specified aspect and amount, and
* sets if it is craftable.
*
* @param aspect
* What aspect this stack will have.
* @param amount
* How much this stack will have.
* @param isCraftable
* Is the stack craftable.
*/
public AspectStack( final Aspect aspect, final long amount, final boolean isCraftable )
{
// Set the aspect
this.aspect = aspect;
// Set the stack size
this.stackSize = amount;
// Set craftable
this.isCraftable = isCraftable;
}
/**
* Creates a new stack from the passed stack.
* If a new stack is not needed you can also use copyFrom().
*
* @param source
*/
public AspectStack( final AspectStack source )
public AspectStack( final AspectStack stack )
{
this.aspect = source.aspect;
this.stackSize = source.stackSize;
this.copyFrom( stack );
}
/**
* Creates an aspect stack from a NBT compound tag.
*
* @param nbt
* @param data
* Tag to load from
* @return Created stack, or null.
*/
public static AspectStack loadAspectStackFromNBT( final NBTTagCompound nbt )
public static AspectStack loadAspectStackFromNBT( final NBTTagCompound data )
{
// Attempt to get the aspect
Aspect aspect = Aspect.aspects.get( nbt.getString( "AspectTag" ) );
Aspect aspect = null;
// Did we get an aspect?
// Does the tag have the tag?
if( data.hasKey( NBTKEY_ASPECT_TAG ) )
{
// Attempt to get the aspect
aspect = Aspect.aspects.get( data.getString( NBTKEY_ASPECT_TAG ) );
}
// Is there an aspect?
if( aspect == null )
{
return null;
}
// Load the amount
long amount = nbt.getLong( "Amount" );
long amount = 0;
if( data.hasKey( NBTKEY_ASPECT_AMOUNT ) )
{
amount = data.getLong( NBTKEY_ASPECT_AMOUNT );
}
// Load crafting
boolean craftable = data.hasKey( NBTKEY_CRAFTABLE );
// Return a newly created stack.
return new AspectStack( aspect, amount );
return new AspectStack( aspect, amount, craftable );
}
/**
@@ -116,6 +156,22 @@ public class AspectStack
return new AspectStack( this );
}
/**
* Sets the values of this stack to match the passed stack.
* Unchanged if stack is null.
*
* @param stack
*/
public void copyFrom( final AspectStack stack )
{
if( stack != null )
{
this.aspect = stack.aspect;
this.stackSize = stack.stackSize;
this.isCraftable = stack.isCraftable;
}
}
/**
* Gets the name of the aspect.<br>
* This method does not take into consideration if the player has yet discovered the aspect.
@@ -191,20 +247,14 @@ public class AspectStack
*/
public boolean hasPlayerDiscovered( final EntityPlayer player )
{
boolean hasDiscovered = false;
// Ensure we have a player
if( player != null )
// Ensure we have a player & aspect
if( ( player != null ) && ( this.aspect != null ) )
{
// Ensure we have an aspect
if( this.aspect != null )
{
// Ask Thaumcraft if the player has discovered the aspect
hasDiscovered = Thaumcraft.proxy.getPlayerKnowledge().hasDiscoveredAspect( player.getCommandSenderName(), this.aspect );
}
// Ask Thaumcraft if the player has discovered the aspect
return Thaumcraft.proxy.getPlayerKnowledge().hasDiscoveredAspect( player.getCommandSenderName(), this.aspect );
}
return hasDiscovered;
return false;
}
/**
@@ -229,26 +279,41 @@ public class AspectStack
// Read the amount
this.stackSize = stream.readLong();
// Read craftable
this.isCraftable = stream.readBoolean();
}
/**
* Writes this aspect stack to the specified NBT tag
*
* @param nbt
* @param data
* The tag to write to
* @return The nbt tag.
*/
public NBTTagCompound writeToNBT( final NBTTagCompound nbt )
public NBTTagCompound writeToNBT( final NBTTagCompound data )
{
// Do we have an aspect?
// Is there an aspect?
if( this.aspect != null )
{
nbt.setString( "AspectTag", this.aspect.getTag() );
// Write the tag
data.setString( NBTKEY_ASPECT_TAG, this.aspect.getTag() );
nbt.setLong( "Amount", this.stackSize );
// Write the amount
if( this.stackSize > 0 )
{
data.setLong( NBTKEY_ASPECT_AMOUNT, this.stackSize );
}
// Craftable?
if( this.isCraftable )
{
// Write craftable
data.setBoolean( NBTKEY_CRAFTABLE, true );
}
}
return nbt;
return data;
}
/**
@@ -263,5 +328,8 @@ public class AspectStack
// Write the stored amount
stream.writeLong( this.stackSize );
// Write if craftable
stream.writeBoolean( this.isCraftable );
}
}
@@ -12,7 +12,13 @@ public class AspectStackComparator
implements Comparator<AspectStack>
{
public enum ComparatorMode
/**
* Modes of comparison
*
* @author Nividica
*
*/
public enum AspectStackComparatorMode
{
/**
* Compare based on name
@@ -27,17 +33,40 @@ public class AspectStackComparator
/**
* Cache of the enum values
*/
public static final ComparatorMode[] VALUES = ComparatorMode.values();
public static final AspectStackComparatorMode[] VALUES = AspectStackComparatorMode.values();
/**
* Returns the next mode of comparison.
*
* @return
*/
public AspectStackComparatorMode nextMode()
{
return( VALUES[( this.ordinal() + 1 ) % VALUES.length] );
}
/**
* Returns the previous mode of comparison.
*
* @return
*/
public AspectStackComparatorMode previousMode()
{
return( VALUES[( this.ordinal() + ( VALUES.length - 1 ) ) % VALUES.length] );
}
}
private ComparatorMode mode;
/**
* The set mode of comparison
*/
private AspectStackComparatorMode mode;
/**
* Creates the comparator with sorting mode alphabetic.
*/
public AspectStackComparator()
{
this( ComparatorMode.MODE_ALPHABETIC );
this.setMode( AspectStackComparatorMode.MODE_ALPHABETIC );
}
/**
@@ -47,21 +76,38 @@ public class AspectStackComparator
* @param mode
* Mode to sort by.
*/
public AspectStackComparator( final ComparatorMode mode )
public AspectStackComparator( final AspectStackComparatorMode mode )
{
this.mode = mode;
this.setMode( mode );
}
/**
* Compares the two stacks by amount.
*
* @param left
* @param right
* @return
*/
private int compareByAmount( final AspectStack left, final AspectStack right )
{
return (int)( right.stackSize - left.stackSize );
}
private int compareByTag( final AspectStack left, final AspectStack right )
/**
* Compares the two stacks by name
*
* @param left
* @param right
* @return
*/
private int compareByName( final AspectStack left, final AspectStack right )
{
return left.aspect.getTag().compareTo( right.aspect.getTag() );
return left.aspect.getName().compareTo( right.aspect.getName() );
}
/**
* Compares two aspect stacks by the selected mode.
*/
@Override
public int compare( final AspectStack left, final AspectStack right )
{
@@ -69,7 +115,7 @@ public class AspectStackComparator
{
case MODE_ALPHABETIC:
// Compare tags
return this.compareByTag( left, right );
return this.compareByName( left, right );
case MODE_AMOUNT:
// Compare amounts
@@ -79,7 +125,7 @@ public class AspectStackComparator
if( comparedAmounts == 0 )
{
// Compare tags
comparedAmounts = this.compareByTag( left, right );
comparedAmounts = this.compareByName( left, right );
}
return comparedAmounts;
@@ -88,4 +134,14 @@ public class AspectStackComparator
return 0;
}
/**
* Sets the mode of comparison.
*
* @param mode
*/
public void setMode( final AspectStackComparatorMode mode )
{
this.mode = mode;
}
}
@@ -1,6 +1,7 @@
package thaumicenergistics.container;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
@@ -12,9 +13,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.lang3.tuple.ImmutablePair;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.api.storage.ICraftingIssuerContainer;
import thaumicenergistics.api.storage.ICraftingIssuerHost;
import thaumicenergistics.api.storage.IEssentiaRepo;
import thaumicenergistics.aspect.AspectStack;
import thaumicenergistics.aspect.AspectStackComparator.ComparatorMode;
import thaumicenergistics.container.slot.SlotRestrictive;
import thaumicenergistics.grid.EssentiaRepo;
import thaumicenergistics.grid.IMEEssentiaMonitor;
import thaumicenergistics.grid.IMEEssentiaMonitorReceiver;
import thaumicenergistics.integration.tc.EssentiaItemContainerHelper;
@@ -42,7 +46,7 @@ import cpw.mods.fml.relauncher.SideOnly;
*/
public abstract class AbstractContainerCellTerminalBase
extends ContainerWithPlayerInventory
implements IMEEssentiaMonitorReceiver, IAspectSelectorContainer, IInventoryUpdateReceiver
implements IMEEssentiaMonitorReceiver, IAspectSelectorContainer, IInventoryUpdateReceiver, ICraftingIssuerContainer
{
/**
* X position for the output slot
@@ -110,7 +114,8 @@ public abstract class AbstractContainerCellTerminalBase
/**
* List of aspects on the network
*/
protected List<AspectStack> aspectStackList = new ArrayList<AspectStack>();
//protected List<AspectStack> aspectStackList = new ArrayList<AspectStack>();
protected final IEssentiaRepo repo;
/**
* The aspect the user has selected.
@@ -180,6 +185,9 @@ public abstract class AbstractContainerCellTerminalBase
{
this.hasRequested = true;
}
// Create the reop
this.repo = new EssentiaRepo();
}
/**
@@ -351,91 +359,6 @@ public abstract class AbstractContainerCellTerminalBase
return 0;
}
/**
* Determines if the specified aspect stack is a different from an existing
* stack in the specified list.
*
* @param potentialChange
* @return
* If a match is found: Pair <ExistingIndex, ChangedStack>
* If the item is new: Pair <-1, potentialChange>
*
*/
private ImmutablePair<Integer, AspectStack> isChange( final AspectStack potentialChange, final List<AspectStack> comparedAgainst )
{
AspectStack matchingStack = null;
for( int index = 0; index < comparedAgainst.size(); index++ )
{
// Tenativly set the matching stack
matchingStack = comparedAgainst.get( index );
// Check if it is a match
if( potentialChange.aspect == matchingStack.aspect )
{
// Found a match, determine how much it has changed
long changeAmount = potentialChange.stackSize - matchingStack.stackSize;
// Create the changed stack
AspectStack changedStack = new AspectStack( matchingStack.aspect, changeAmount );
return new ImmutablePair<Integer, AspectStack>( index, changedStack );
}
}
// No match change is new item
return new ImmutablePair<Integer, AspectStack>( -1, potentialChange );
}
/**
* Merges a change with the cached aspect list
*
* @param changeDetails
* @return
*/
private boolean mergeAspectChangeWithCache( final ImmutablePair<Integer, AspectStack> changeDetails )
{
// Get the index that changed
int changedIndex = changeDetails.getLeft();
// Get the stack that changed
AspectStack changedStack = changeDetails.getRight();
// Did anything change?
if( changedStack.stackSize == 0 )
{
// Nothing changed
return false;
}
// Was there a match?
if( changedIndex != -1 )
{
// Get the new amount
long newAmount = this.aspectStackList.get( changedIndex ).stackSize + changedStack.stackSize;
// Was the stack drained?
if( newAmount <= 0 )
{
// Remove from list
this.aspectStackList.remove( changedIndex );
}
else
{
// Update the list
this.aspectStackList.get( changedIndex ).stackSize = newAmount;
}
}
// New addition
else
{
this.aspectStackList.add( changedStack );
}
// List updated.
return true;
}
/**
* Merges the specified stack with the output slot.
*
@@ -575,7 +498,8 @@ public abstract class AbstractContainerCellTerminalBase
this.monitor.addListener( this, this.monitor.hashCode() );
// Update our cached list of aspects
this.aspectStackList = new ArrayList( this.monitor.getEssentiaList() );
this.repo.copyFrom( this.monitor.getEssentiaList() );
}
}
@@ -633,8 +557,8 @@ public abstract class AbstractContainerCellTerminalBase
// Null the monitor
this.monitor = null;
// Clear the list
this.aspectStackList.clear();
// Clear the repo
this.repo.clear();
}
}
}
@@ -818,11 +742,14 @@ public abstract class AbstractContainerCellTerminalBase
*
* @return
*/
public List<AspectStack> getAspectStackList()
public Collection<AspectStack> getAspectStackList()
{
return this.aspectStackList;
return this.repo.getAll();
}
@Override
public abstract ICraftingIssuerHost getCraftingHost();
/**
* Get the player that owns this container
*
@@ -863,29 +790,18 @@ public abstract class AbstractContainerCellTerminalBase
// No longer valid
this.monitor = null;
this.aspectStackList.clear();
this.repo.clear();
return false;
}
/**
* Merges a change with the cached aspect list
* Called when a client has clicked on a craftable aspect.
*
* @param change
* @return
* @param player
* @param result
*/
public boolean mergeChange( final AspectStack change )
{
// Get the index of the change
int index = this.isChange( change, this.aspectStackList ).getLeft();
// Create the change
ImmutablePair<Integer, AspectStack> changeDetails = new ImmutablePair<Integer, AspectStack>( index, change );
// Attempt the merger
return this.mergeAspectChangeWithCache( changeDetails );
}
public abstract void onClientRequestAutoCraft( final EntityPlayer player, final Aspect aspect );
/**
* Called when a client requests the state of the container.
@@ -894,11 +810,18 @@ public abstract class AbstractContainerCellTerminalBase
public abstract void onClientRequestFullUpdate();
/**
* Called when a client sends a sorting mode request.
* Called when a client sends a sorting mode change request.
*
* @param sortingMode
*/
public abstract void onClientRequestSortModeChange( final ComparatorMode sortingMode, final EntityPlayer player );
public abstract void onClientRequestSortModeChange( final EntityPlayer player, boolean backwards );
/**
* Called when a client sends a view mode change request.
*
* @param player
*/
public abstract void onClientRequestViewModeChange( final EntityPlayer player, boolean backwards );
/**
* Unregister this container from the monitor.
@@ -929,13 +852,13 @@ public abstract class AbstractContainerCellTerminalBase
*
* @param aspectStackList
*/
public void onReceivedAspectList( final List<AspectStack> aspectStackList )
public void onReceivedAspectList( final Collection<AspectStack> aspectStackList )
{
// Set the aspect list
this.aspectStackList = aspectStackList;
this.repo.copyFrom( aspectStackList );
// Check pending changes
if( ( this.aspectStackList != null ) && ( !this.pendingChanges.isEmpty() ) )
if( ( aspectStackList != null ) && ( !this.pendingChanges.isEmpty() ) )
{
// Update list with pending changes
for( int index = 0; index < this.pendingChanges.size(); index++ )
@@ -952,7 +875,7 @@ public abstract class AbstractContainerCellTerminalBase
* Called by the gui when a change arrives.
*
* @param change
* @return
* @return True if the repo is prepared to be displayed.
*/
public boolean onReceivedAspectListChange( final AspectStack change )
{
@@ -974,25 +897,19 @@ public abstract class AbstractContainerCellTerminalBase
return false;
}
// Do we have a list?
if( this.aspectStackList == null )
// Has the full list been received?
if( this.repo.isEmpty() )
{
// Not yet received full list, add to pending
this.pendingChanges.add( change );
return false;
}
// Can we merge this change with the list?
if( this.mergeChange( change ) )
{
// Tell the gui to update
if( this.pendingChanges.isEmpty() )
{
return true;
}
}
// Post the change
this.repo.postChange( change );
return false;
// The GUI can update if there are no pending changes
return this.pendingChanges.isEmpty();
}
/**
@@ -1014,7 +931,7 @@ public abstract class AbstractContainerCellTerminalBase
}
/**
* Called by the AE monitor when the network changes.
* Called by the Essentia monitor when the network changes.
*/
@Override
@@ -6,9 +6,11 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.ThaumicEnergistics;
import thaumicenergistics.api.storage.ICraftingIssuerHost;
import thaumicenergistics.aspect.AspectStack;
import thaumicenergistics.aspect.AspectStackComparator.ComparatorMode;
import thaumicenergistics.aspect.AspectStackComparator.AspectStackComparatorMode;
import thaumicenergistics.grid.EssentiaMonitor;
import thaumicenergistics.integration.tc.EssentiaItemContainerHelper;
import thaumicenergistics.integration.tc.EssentiaItemContainerHelper.AspectItemType;
@@ -18,6 +20,8 @@ import thaumicenergistics.network.packet.client.Packet_C_EssentiaCellTerminal;
import thaumicenergistics.network.packet.server.Packet_S_EssentiaCellTerminal;
import thaumicenergistics.util.EffectiveSide;
import thaumicenergistics.util.PrivateInventory;
import appeng.api.config.Settings;
import appeng.api.config.ViewItems;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.PlayerSource;
import appeng.api.storage.IMEInventoryHandler;
@@ -26,6 +30,7 @@ import appeng.api.storage.ISaveProvider;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.tile.storage.TileChest;
import appeng.util.Platform;
/**
* Inventory container for essentia cells in a ME chest.
@@ -179,6 +184,19 @@ public class ContainerEssentiaCell
this.transferEssentia( this.playerSource );
}
@Override
public ICraftingIssuerHost getCraftingHost()
{
// Can't craft.
return null;
}
@Override
public void onClientRequestAutoCraft( final EntityPlayer player, final Aspect aspect )
{
// Ignored, can't issue, or even see, craftable essentia from here.
}
/**
* Gets the current list from the AE monitor and sends
* it to the client.
@@ -186,21 +204,20 @@ public class ContainerEssentiaCell
@Override
public void onClientRequestFullUpdate()
{
// Get the handler
HandlerItemEssentiaCell cellHandler = this.getCellHandler();
// Did we get the handler?
if( cellHandler != null )
{
// Send the sorting mode
Packet_C_EssentiaCellTerminal.setSortMode( this.player, cellHandler.getSortingMode() );
// Send the viewing mode
Packet_C_EssentiaCellTerminal.sendViewingModes( this.player, cellHandler.getSortingMode(), cellHandler.getViewMode() );
}
// Send the list
if( ( this.monitor != null ) && ( this.hostChest.isPowered() ) )
{
Packet_C_EssentiaCellTerminal.sendFullList( this.player, this.aspectStackList );
Packet_C_EssentiaCellTerminal.sendFullList( this.player, this.repo.getAll() );
}
else
{
@@ -210,16 +227,43 @@ public class ContainerEssentiaCell
}
@Override
public void onClientRequestSortModeChange( final ComparatorMode sortingMode, final EntityPlayer player )
public void onClientRequestSortModeChange( final EntityPlayer player, final boolean backwards )
{
// Get the handler
HandlerItemEssentiaCell cellHandler = this.getCellHandler();
// Change the sorting mode
AspectStackComparatorMode sortingMode;
if( backwards )
{
sortingMode = cellHandler.getSortingMode().previousMode();
}
else
{
sortingMode = cellHandler.getSortingMode().nextMode();
}
// Inform the handler of the change
cellHandler.setSortingMode( sortingMode );
// Send confirmation back to client
Packet_C_EssentiaCellTerminal.setSortMode( player, sortingMode );
Packet_C_EssentiaCellTerminal.sendViewingModes( player, sortingMode, cellHandler.getViewMode() );
}
@Override
public void onClientRequestViewModeChange( final EntityPlayer player, final boolean backwards )
{
// Get the handler
HandlerItemEssentiaCell cellHandler = this.getCellHandler();
// Change the view mode
ViewItems viewMode = Platform.rotateEnum( cellHandler.getViewMode(), backwards, Settings.VIEW_MODE.getPossibleValues() );
// Inform the handler of the change
cellHandler.setViewMode( viewMode );
// Send confirmation back to client
Packet_C_EssentiaCellTerminal.sendViewingModes( player, cellHandler.getSortingMode(), viewMode );
}
/**
@@ -1,12 +1,22 @@
package thaumicenergistics.container;
import net.minecraft.entity.player.EntityPlayer;
import thaumicenergistics.aspect.AspectStackComparator.ComparatorMode;
import net.minecraft.tileentity.TileEntity;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.api.storage.ICraftingIssuerHost;
import thaumicenergistics.aspect.AspectStackComparator.AspectStackComparatorMode;
import thaumicenergistics.gui.ThEGuiHandler;
import thaumicenergistics.items.ItemCraftingAspect;
import thaumicenergistics.network.packet.client.Packet_C_EssentiaCellTerminal;
import thaumicenergistics.network.packet.server.Packet_S_EssentiaCellTerminal;
import thaumicenergistics.parts.AEPartEssentiaTerminal;
import thaumicenergistics.util.EffectiveSide;
import appeng.api.AEApi;
import appeng.api.config.ViewItems;
import appeng.api.networking.security.PlayerSource;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.ContainerOpenContext;
import appeng.container.implementations.ContainerCraftAmount;
/**
* Inventory container for the essentia terminal.
@@ -83,6 +93,47 @@ public class ContainerEssentiaTerminal
this.transferEssentia( this.playerSource );
}
@Override
public ICraftingIssuerHost getCraftingHost()
{
return this.terminal;
}
@Override
public void onClientRequestAutoCraft( final EntityPlayer player, final Aspect aspect )
{
// Get the host tile
TileEntity te = this.terminal.getHostTile();
// Launch the GUI
ThEGuiHandler.launchGui( ThEGuiHandler.AUTO_CRAFTING_AMOUNT, player, te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord );
// Setup the amount container
if( player.openContainer instanceof ContainerCraftAmount )
{
// Get the container
ContainerCraftAmount cca = (ContainerCraftAmount)this.player.openContainer;
// Create the open context
cca.setOpenContext( new ContainerOpenContext( te ) );
cca.getOpenContext().setWorld( te.getWorldObj() );
cca.getOpenContext().setX( te.xCoord );
cca.getOpenContext().setY( te.yCoord );
cca.getOpenContext().setZ( te.zCoord );
cca.getOpenContext().setSide( this.terminal.getSide() );
// Create the result item
IAEItemStack result = AEApi.instance().storage().createItemStack( ItemCraftingAspect.createStackForAspect( aspect, 1 ) );
// Set the item
cca.getCraftingItem().putStack( result.getItemStack() );
cca.setItemToCraft( result );
// Issue update
cca.detectAndSendChanges();
}
}
/**
* Gets the current list from the AE monitor, as well as the current
* sorting mode, and sends it to the client.
@@ -91,19 +142,25 @@ public class ContainerEssentiaTerminal
public void onClientRequestFullUpdate()
{
// Send the sorting mode
this.onSortingModeChanged( this.terminal.getSortingMode() );
this.onModeChanged( this.terminal.getSortingMode(), this.terminal.getViewMode() );
// Send the aspect list
if( this.monitor != null )
{
Packet_C_EssentiaCellTerminal.sendFullList( this.player, this.aspectStackList );
Packet_C_EssentiaCellTerminal.sendFullList( this.player, this.repo.getAll() );
}
}
@Override
public void onClientRequestSortModeChange( final ComparatorMode sortingMode, final EntityPlayer player )
public void onClientRequestSortModeChange( final EntityPlayer player, final boolean backwards )
{
this.terminal.onClientRequestSortingModeChange( sortingMode );
this.terminal.onClientRequestSortingModeChange( backwards );
}
@Override
public void onClientRequestViewModeChange( final EntityPlayer player, final boolean backwards )
{
this.terminal.onClientRequestViewModeChange( backwards );
}
/**
@@ -121,12 +178,12 @@ public class ContainerEssentiaTerminal
}
/**
* Called from the terminal when it's sorting mode has changed
* Called from the terminal when it's mode has changed
*/
public void onSortingModeChanged( final ComparatorMode sortingMode )
public void onModeChanged( final AspectStackComparatorMode sortingMode, final ViewItems viewMode )
{
// Inform the client
Packet_C_EssentiaCellTerminal.setSortMode( this.player, sortingMode );
Packet_C_EssentiaCellTerminal.sendViewingModes( this.player, sortingMode, viewMode );
}
}
@@ -16,6 +16,8 @@ import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.crafting.IArcaneRecipe;
import thaumcraft.common.items.wands.ItemWandCasting;
import thaumicenergistics.api.storage.ICraftingIssuerContainer;
import thaumicenergistics.api.storage.ICraftingIssuerHost;
import thaumicenergistics.container.slot.SlotArcaneCraftingResult;
import thaumicenergistics.container.slot.SlotArmor;
import thaumicenergistics.container.slot.SlotRestrictive;
@@ -46,7 +48,7 @@ import cpw.mods.fml.relauncher.SideOnly;
public class ContainerPartArcaneCraftingTerminal
extends ContainerWithPlayerInventory
implements IMEMonitorHandlerReceiver<IAEItemStack>
implements IMEMonitorHandlerReceiver<IAEItemStack>, ICraftingIssuerContainer
{
/**
* Holds a single aspect cost for the current recipe.
@@ -864,6 +866,12 @@ public class ContainerPartArcaneCraftingTerminal
return this.craftingCost;
}
@Override
public ICraftingIssuerHost getCraftingHost()
{
return this.arcaneCraftingTerminalPart;
}
/**
* Called by the monitor to ensure we still want updates
*/
@@ -921,11 +929,8 @@ public class ContainerPartArcaneCraftingTerminal
// Get the host tile
TileEntity te = this.arcaneCraftingTerminalPart.getHostTile();
// Get the sided GUI ID
int sidedID = ThEGuiHandler.generateSidedID( ThEGuiHandler.AUTO_CRAFTING_AMOUNT, this.arcaneCraftingTerminalPart.getSide() );
// Launch the GUI
ThEGuiHandler.launchGui( sidedID, player, te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord );
ThEGuiHandler.launchGui( ThEGuiHandler.AUTO_CRAFTING_AMOUNT, player, te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord );
// Setup the amount container
if( player.openContainer instanceof ContainerCraftAmount )
@@ -3,16 +3,27 @@ package thaumicenergistics.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.ThaumicEnergistics;
import thaumicenergistics.aspect.AspectStackComparator.ComparatorMode;
import thaumicenergistics.api.storage.ICraftingIssuerHost;
import thaumicenergistics.aspect.AspectStackComparator.AspectStackComparatorMode;
import thaumicenergistics.gui.ThEGuiHandler;
import thaumicenergistics.integration.tc.EssentiaItemContainerHelper;
import thaumicenergistics.integration.tc.EssentiaItemContainerHelper.AspectItemType;
import thaumicenergistics.inventory.HandlerWirelessEssentiaTerminal;
import thaumicenergistics.items.ItemCraftingAspect;
import thaumicenergistics.network.packet.client.Packet_C_EssentiaCellTerminal;
import thaumicenergistics.network.packet.server.Packet_S_EssentiaCellTerminal;
import thaumicenergistics.util.EffectiveSide;
import thaumicenergistics.util.PrivateInventory;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.Settings;
import appeng.api.config.ViewItems;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.ContainerOpenContext;
import appeng.container.implementations.ContainerCraftAmount;
import appeng.util.Platform;
public class ContainerWirelessEssentiaTerminal
extends AbstractContainerCellTerminalBase
@@ -64,7 +75,6 @@ public class ContainerWirelessEssentiaTerminal
*
* @param player
* @param handler
* Null on client side.
*/
public ContainerWirelessEssentiaTerminal( final EntityPlayer player, final HandlerWirelessEssentiaTerminal handler )
{
@@ -182,23 +192,82 @@ public class ContainerWirelessEssentiaTerminal
}
@Override
public void onClientRequestFullUpdate()
public ICraftingIssuerHost getCraftingHost()
{
// Send the sorting mode
Packet_C_EssentiaCellTerminal.setSortMode( this.player, this.handler.getSortingMode() );
// Send the list
Packet_C_EssentiaCellTerminal.sendFullList( this.player, this.aspectStackList );
return this.handler;
}
@Override
public void onClientRequestSortModeChange( final ComparatorMode sortingMode, final EntityPlayer player )
public void onClientRequestAutoCraft( final EntityPlayer player, final Aspect aspect )
{
// Launch the GUI
ThEGuiHandler.launchGui( ThEGuiHandler.AUTO_CRAFTING_AMOUNT, player, player.worldObj, 0, 0, 0 );
// Setup the amount container
if( player.openContainer instanceof ContainerCraftAmount )
{
// Get the container
ContainerCraftAmount cca = (ContainerCraftAmount)this.player.openContainer;
// Create the open context
cca.setOpenContext( new ContainerOpenContext( this.handler ) );
cca.getOpenContext().setWorld( player.worldObj );
// Create the result item
IAEItemStack result = AEApi.instance().storage().createItemStack( ItemCraftingAspect.createStackForAspect( aspect, 1 ) );
// Set the item
cca.getCraftingItem().putStack( result.getItemStack() );
cca.setItemToCraft( result );
// Issue update
cca.detectAndSendChanges();
}
}
@Override
public void onClientRequestFullUpdate()
{
// Send the sorting mode
Packet_C_EssentiaCellTerminal.sendViewingModes( this.player, this.handler.getSortingMode(), this.handler.getViewMode() );
// Send the list
Packet_C_EssentiaCellTerminal.sendFullList( this.player, this.repo.getAll() );
}
@Override
public void onClientRequestSortModeChange( final EntityPlayer player, final boolean backwards )
{
// Change the sorting mode
AspectStackComparatorMode sortingMode;
if( backwards )
{
sortingMode = this.handler.getSortingMode().previousMode();
}
else
{
sortingMode = this.handler.getSortingMode().nextMode();
}
// Set the sorting mode.
this.handler.setSortingMode( sortingMode );
// Send confirmation back to client
Packet_C_EssentiaCellTerminal.setSortMode( player, sortingMode );
Packet_C_EssentiaCellTerminal.sendViewingModes( player, sortingMode, this.handler.getViewMode() );
}
@Override
public void onClientRequestViewModeChange( final EntityPlayer player, final boolean backwards )
{
// Change the view mode
ViewItems viewMode = Platform.rotateEnum( this.handler.getViewMode(), backwards, Settings.VIEW_MODE.getPossibleValues() );
// Inform the handler of the change
this.handler.setViewMode( viewMode );
// Send confirmation back to client
Packet_C_EssentiaCellTerminal.sendViewingModes( player, this.handler.getSortingMode(), viewMode );
}
/**
@@ -3,6 +3,7 @@ package thaumicenergistics.grid;
import java.util.EnumSet;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import thaumicenergistics.api.networking.IEssentiaGrid;
import thaumicenergistics.parts.AbstractAEPartBase;
import appeng.api.networking.GridFlags;
import appeng.api.networking.GridNotification;
@@ -1,18 +1,10 @@
package thaumicenergistics.grid;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.api.storage.IEssentiaRepo;
import thaumicenergistics.aspect.AspectStack;
import thaumicenergistics.fluids.GaseousEssentia;
import thaumicenergistics.integration.tc.EssentiaConversionHelper;
@@ -41,11 +33,6 @@ public class EssentiaMonitor
*/
public static final double AE_PER_ESSENTIA = 0.3;
/**
* The actual cache of aspects.
*/
private final Map<Aspect, AspectStack> cache;
/**
* Objects who wish to be notified of any changes.
*/
@@ -72,6 +59,11 @@ public class EssentiaMonitor
*/
private WeakReference<Object> token;
/**
* Cache of essentia.
*/
private final IEssentiaRepo cache;
/**
* When true the full storage list needs to be pulled to update the cache.
*/
@@ -80,7 +72,7 @@ public class EssentiaMonitor
public EssentiaMonitor()
{
// Create the cache
this.cache = new ConcurrentHashMap<Aspect, AspectStack>();
this.cache = new EssentiaRepo();
// Create the listeners table
this.listeners = new HashMap<IMEEssentiaMonitorReceiver, Object>();
@@ -105,66 +97,6 @@ public class EssentiaMonitor
this.wrap( fluidMonitor, energyGrid, validationToken );
}
/**
* Changes the amount in the cache by the specified difference amount.<br>
* If {@code aspect} is null, no changes will be made. Returns 0.<br>
* If {@code diff} is positive and {@code aspect} stored, the resulting amount will be stored. Returns amount added.<br>
* If {@code diff} is positive and {@code aspect} is not stored, {@code aspect} will be stored with the value of {@code diff}. Returns
* {@code diff}<br>
* If {@code diff} is negative and {@code aspect} is stored, {@code aspect} will be removed if the resulting amount is <= 0. Returns amount
* removed.<br>
* If {@code diff} is negative and {@code aspect} is not stored, no changes will be made. Returns 0<br>
*
* @param aspect
* @param diff
* @return Amount removed or added.
*/
private long changeAspectAmount( final Aspect aspect, final long diff )
{
// Is the aspect null?
if( aspect == null )
{
// No changes
return 0;
}
// Get the current amount
AspectStack prevStack = this.cache.get( aspect );
if( prevStack == null )
{
// If the current amount is null the diff must be positive
if( diff > 0 )
{
// Add the aspect
this.cache.put( aspect, new AspectStack( aspect, diff ) );
return diff;
}
// No changes
return 0;
}
// Calculate the new amount
long prevAmount = prevStack.stackSize;
long newAmount = Math.max( 0L, prevAmount + diff );
// Is there any left?
if( newAmount > 0 )
{
// Update the amount
prevStack.stackSize = newAmount;
}
else
{
// Remove the aspect
this.cache.remove( aspect );
}
return newAmount - prevAmount;
}
/**
* Mirror method of the injectEssentia. Used to defer power calculations, because the simulation is not always accurate, and Essentia gas should
* not be stored in partial amounts.
@@ -235,6 +167,104 @@ public class EssentiaMonitor
}
}
private boolean setAspectCraftability( final Aspect aspect, final boolean isCraftable, final boolean doNotify )
{
// Get the aspect stack
AspectStack stack = this.cache.getOrDefault( aspect, null );
boolean changesMade = false;
// Not stored?
if( stack == null )
{
// If the cache doesn't have this aspect, and its not craftable then there is nothing to do
if( isCraftable )
{
// Put it in the cache
this.cache.postChange( aspect, 0, true );
// Set changes made
changesMade = true;
}
}
else
{
// Is stored, but is stack size 0 and setting to not craftable?
if( ( stack.stackSize <= 0 ) && ( !isCraftable ) )
{
// Remove the stack
this.cache.remove( aspect );
// Set changes made
changesMade = true;
}
// Is it changing?
else if( stack.isCraftable != isCraftable )
{
// Set craftability
stack.isCraftable = isCraftable;
// Set changes made
changesMade = true;
}
}
// Do notify?
if( doNotify && changesMade && ( this.listeners.size() > 0 ) )
{
// Create the change
ArrayList<AspectStack> changes = new ArrayList<AspectStack>();
// Add the aspect
changes.add( new AspectStack( aspect, 0, isCraftable ) );
// Notify
this.notifyListeners( changes );
}
return changesMade;
}
/**
* Sets if the aspect is craftable.
*
* @param aspect
* @param isCraftable
*/
protected void setAspectCraftability( final Aspect aspect, final boolean isCraftable )
{
this.setAspectCraftability( aspect, isCraftable, true );
}
/**
* Sets each aspect as craftable.
*
* @param aspects
*/
protected void setCraftableAspects( final HashSet<Aspect> aspects )
{
// Create the changes
ArrayList<AspectStack> changes = new ArrayList<AspectStack>();
// Set each aspect
for( Aspect aspect : aspects )
{
// Was the crafting status changed?
if( this.setAspectCraftability( aspect, true, false ) )
{
// Add the aspect
changes.add( new AspectStack( aspect, 0, true ) );
}
}
// Notify listeners?
if( ( changes.size() > 0 ) && ( this.listeners.size() > 0 ) )
{
// Notify
this.notifyListeners( changes );
}
}
/**
* Updates the cache to match the contents of the network and updates any
* listeners of the changes.
@@ -242,91 +272,89 @@ public class EssentiaMonitor
@SuppressWarnings("null")
protected void updateCacheToMatchNetwork()
{
synchronized( this.cache )
// Get the list of fluids in the network
IItemList<IAEFluidStack> fluidStackList;
// Validate the list
if( ( fluidStackList = this.fluidMonitor.getStorageList() ) == null )
{
// Get the list of fluids in the network
IItemList<IAEFluidStack> fluidStackList;
// Validate the list
if( ( fluidStackList = this.fluidMonitor.getStorageList() ) == null )
{
// Invalid list
return;
}
// Changes made to the cache
List<AspectStack> aspectChanges = null;
// The currently stored aspects
Set<Aspect> previousAspects = null;
// Are there any listeners?
boolean hasListeners = ( this.listeners.size() > 0 );
if( hasListeners )
{
// Create the change trackers
aspectChanges = new ArrayList<AspectStack>();
previousAspects = new HashSet<Aspect>();
previousAspects.addAll( this.cache.keySet() );
}
else
{
// Can safely clear the cache
this.cache.clear();
}
// Loop over all fluids
for( IAEFluidStack fluidStack : fluidStackList )
{
// Ensure the fluid is an essentia gas
if( !( fluidStack.getFluid() instanceof GaseousEssentia ) )
{
// Not an essentia gas.
continue;
}
// Get the gas aspect
Aspect aspect = ( (GaseousEssentia)fluidStack.getFluid() ).getAspect();
// Calculate the new amount
Long newAmount = EssentiaConversionHelper.INSTANCE.convertFluidAmountToEssentiaAmount( fluidStack.getStackSize() );
// Update the cache
AspectStack prevStack = this.cache.put( aspect, new AspectStack( aspect, newAmount ) );
// Are there any listeners?
if( hasListeners )
{
// Remove from the previous mapping
previousAspects.remove( aspect );
// Calculate the difference
long diff = ( newAmount - ( prevStack != null ? prevStack.stackSize : 0 ) );
if( diff != 0 )
{
// Add to the changes
aspectChanges.add( new AspectStack( aspect, diff ) );
}
}
}
// Are there any listeners?
if( hasListeners )
{
// Anything left in the previous mapping is no longer present in the network
for( Aspect aspect : previousAspects )
{
aspectChanges.add( new AspectStack( aspect, -this.cache.remove( aspect ).stackSize ) );
}
// Notify listeners
this.notifyListeners( aspectChanges );
}
// Mark the cache as valid
this.cacheNeedsUpdate = false;
// Invalid list
return;
}
// Changes made to the cache
List<AspectStack> aspectChanges = null;
// The currently stored aspects
Set<Aspect> previousAspects = null;
// Are there any listeners?
boolean hasListeners = ( this.listeners.size() > 0 );
if( hasListeners )
{
// Create the change trackers
aspectChanges = new ArrayList<AspectStack>();
previousAspects = new HashSet<Aspect>();
previousAspects.addAll( this.cache.aspectSet() );
}
else
{
// Can safely clear the cache
this.cache.clear();
}
// Loop over all fluids
for( IAEFluidStack fluidStack : fluidStackList )
{
// Ensure the fluid is an essentia gas
if( !( fluidStack.getFluid() instanceof GaseousEssentia ) )
{
// Not an essentia gas.
continue;
}
// Get the gas aspect
Aspect aspect = ( (GaseousEssentia)fluidStack.getFluid() ).getAspect();
// Calculate the new amount
Long newAmount = EssentiaConversionHelper.INSTANCE.convertFluidAmountToEssentiaAmount( fluidStack.getStackSize() );
// Update the cache
AspectStack prevStack = this.cache.setAspect( aspect, newAmount, false );
// Are there any listeners?
if( hasListeners )
{
// Remove from the previous mapping
previousAspects.remove( aspect );
// Calculate the difference
long diff = ( newAmount - ( prevStack != null ? prevStack.stackSize : 0 ) );
if( diff != 0 )
{
// Add to the changes
aspectChanges.add( new AspectStack( aspect, diff ) );
}
}
}
// Are there any listeners?
if( hasListeners )
{
// Anything left in the previous mapping is no longer present in the network
for( Aspect aspect : previousAspects )
{
aspectChanges.add( new AspectStack( aspect, -this.cache.remove( aspect ).stackSize ) );
}
// Notify listeners
this.notifyListeners( aspectChanges );
}
// Mark the cache as valid
this.cacheNeedsUpdate = false;
}
@Override
@@ -429,14 +457,14 @@ public class EssentiaMonitor
this.updateCacheToMatchNetwork();
}
// Does the cache have this key?
if( this.cache.containsKey( aspect ) )
// Does the cache have this aspect?
if( this.cache.containsAspect( aspect ) )
{
// Return the amount
return this.cache.get( aspect ).stackSize;
}
// Invalid aspect
// Aspect not stored
return 0;
}
@@ -457,7 +485,7 @@ public class EssentiaMonitor
// Does the view need to be created?
if( this.cacheView == null )
{
this.cacheView = Collections.unmodifiableCollection( this.cache.values() );
this.cacheView = Collections.unmodifiableCollection( this.cache.getAll() );
}
return this.cacheView;
@@ -586,10 +614,10 @@ public class EssentiaMonitor
Aspect aspect = ( (GaseousEssentia)change.getFluid() ).getAspect();
// Calculate the difference
long diff = EssentiaConversionHelper.INSTANCE.convertFluidAmountToEssentiaAmount( change.getStackSize() );
long changeAmount = EssentiaConversionHelper.INSTANCE.convertFluidAmountToEssentiaAmount( change.getStackSize() );
// Update the cache
diff = this.changeAspectAmount( aspect, diff );
AspectStack previous = this.cache.postChange( aspect, changeAmount, null );
// Add to the changes
if( hasListeners )
@@ -600,8 +628,23 @@ public class EssentiaMonitor
aspectChanges = new ArrayList<AspectStack>();
}
// Was there a previous stack?
AspectStack changeStack;
if( previous != null )
{
// Re-use it, as it is no longer associated with anything
// Plus, it carries the crafting info.
changeStack = previous;
previous.stackSize = changeAmount;
}
else
{
// Create a new stack
changeStack = new AspectStack( aspect, changeAmount );
}
// Add the change
aspectChanges.add( new AspectStack( aspect, diff ) );
aspectChanges.add( changeStack );
}
}
}
@@ -0,0 +1,212 @@
package thaumicenergistics.grid;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.api.storage.IEssentiaRepo;
import thaumicenergistics.aspect.AspectStack;
public class EssentiaRepo
implements IEssentiaRepo
{
/**
* The actual cache of aspects.
*/
private final Map<Aspect, AspectStack> cache;
/**
* Creates the repository.
*/
public EssentiaRepo()
{
// Create the cache
this.cache = new ConcurrentHashMap<Aspect, AspectStack>();
}
@Override
public Set<Aspect> aspectSet()
{
return this.cache.keySet();
}
@Override
public void clear()
{
this.cache.clear();
}
@Override
public boolean containsAspect( final Aspect aspect )
{
return this.cache.containsKey( aspect );
}
@Override
public void copyFrom( final Collection<AspectStack> stacks )
{
// Clear
this.clear();
// Null check
if( stacks == null )
{
return;
}
// Add each
for( AspectStack stack : stacks )
{
this.cache.put( stack.aspect, stack.copy() );
}
}
@Override
public AspectStack get( final Aspect aspect )
{
return this.cache.getOrDefault( aspect, null );
}
@Override
public Collection<AspectStack> getAll()
{
return this.cache.values();
}
@Override
public AspectStack getOrDefault( final Aspect aspect, final AspectStack defaultValue )
{
return this.cache.getOrDefault( aspect, defaultValue );
}
@Override
public boolean isEmpty()
{
return this.cache.isEmpty();
}
@Override
public AspectStack postChange( final Aspect aspect, final long change, final Boolean isCraftableNullable )
{
// Is the aspect null?
if( aspect == null )
{
// No changes
return null;
}
boolean isCraftable;
// Get the current stack
AspectStack current = this.cache.get( aspect );
// Is their nothing currently stored?
if( current == null )
{
// Create a new stack
AspectStack newStack = null;
// Set craftability
isCraftable = ( isCraftableNullable == null ? false : isCraftableNullable );
// Is the change positive?
if( change > 0 )
{
// Create a new stack
newStack = new AspectStack( aspect, change, isCraftable );
}
// Is it craftable?
else if( isCraftable )
{
// Create a new crafting stack
newStack = new AspectStack( aspect, 0, isCraftable );
}
// Is there a new stack?
if( newStack != null )
{
// Add the stack
this.cache.put( newStack.aspect, newStack );
}
// Done
return null;
}
// There is something currently stored
AspectStack previous = current.copy();
// Set craftability
isCraftable = ( isCraftableNullable == null ? previous.isCraftable : isCraftableNullable );
// Calculate the new amount
long previousAmount = previous.stackSize;
long newAmount = Math.max( 0L, previousAmount + change );
// Stack drained and is not craftable?
if( ( newAmount == 0 ) && !isCraftable )
{
// Remove it
this.cache.remove( aspect );
}
else
{
// Update the amount & craftability
current.stackSize = newAmount;
current.isCraftable = isCraftable;
}
// Return the previous stack
return previous;
}
@Override
public AspectStack postChange( final AspectStack change )
{
// Null check
if( change == null )
{
return null;
}
return this.postChange( change.aspect, change.stackSize, change.isCraftable );
}
@Override
public AspectStack remove( final Aspect aspect )
{
return this.cache.remove( aspect );
}
@Override
public AspectStack setAspect( final Aspect aspect, final long amount, final boolean isCraftable )
{
if( aspect == null )
{
return null;
}
// Set the stack, and return the old one.
return this.cache.put( aspect, new AspectStack( aspect, amount, isCraftable ) );
}
@Override
public AspectStack setAspect( final AspectStack stack )
{
// Null check
if( stack == null )
{
return null;
}
return this.setAspect( stack.aspect, stack.stackSize, stack.isCraftable );
}
@Override
public int size()
{
return this.cache.size();
}
}
@@ -5,7 +5,9 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.grid.GridEssentiaCache.WatcherManager;
import thaumicenergistics.api.networking.IEssentiaWatcher;
import thaumicenergistics.api.networking.IEssentiaWatcherHost;
import thaumicenergistics.grid.GridEssentiaCache.EssentiaWatcherManager;
public class EssentiaWatcher
implements IEssentiaWatcher
@@ -19,14 +21,14 @@ public class EssentiaWatcher
/**
* The manager for the cache.
*/
private final WatcherManager manager;
private final EssentiaWatcherManager manager;
/**
* Whom this watcher belongs to.
*/
private final WeakReference<IEssentiaWatcherHost> host;
public EssentiaWatcher( final WatcherManager manager, final IEssentiaWatcherHost host )
public EssentiaWatcher( final EssentiaWatcherManager manager, final IEssentiaWatcherHost host )
{
this.manager = manager;
this.trackedAspects = new HashSet<Aspect>();
@@ -4,6 +4,9 @@ import java.util.HashMap;
import java.util.HashSet;
import net.minecraft.item.ItemStack;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.api.networking.IEssentiaGrid;
import thaumicenergistics.api.networking.IEssentiaWatcher;
import thaumicenergistics.api.networking.IEssentiaWatcherHost;
import thaumicenergistics.aspect.AspectStack;
import thaumicenergistics.items.ItemCraftingAspect;
import thaumicenergistics.registries.ItemEnum;
@@ -19,8 +22,12 @@ import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPostCacheConstruction;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import com.google.common.collect.ImmutableSet;
@@ -34,7 +41,45 @@ public class GridEssentiaCache
extends EssentiaMonitor
implements IEssentiaGrid
{
public class WatcherManager
private class AspectCraftingWatcher
implements IMEMonitorHandlerReceiver<IAEItemStack>
{
public AspectCraftingWatcher()
{
}
@Override
public boolean isValid( final Object verificationToken )
{
return GridEssentiaCache.this.internalGrid == verificationToken;
}
@Override
public void onListUpdate()
{
// Ignored
}
@Override
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final BaseActionSource actionSource )
{
for( IAEItemStack stack : change )
{
// Is the stack craftable, has NBT tag, and is a crafting aspect?
if( stack.isCraftable()
&& stack.hasTagCompound()
&& ( stack.getItem() instanceof ItemCraftingAspect ) )
{
GridEssentiaCache.this.markForUpdate();
break;
}
}
}
}
public class EssentiaWatcherManager
implements IMEEssentiaMonitorReceiver
{
/**
@@ -211,28 +256,91 @@ public class GridEssentiaCache
/**
* Grid the cache is part of.
*/
private final IGrid internalGrid;
final IGrid internalGrid;
/**
* Manages the watchers
*/
private final WatcherManager watcherManger;
private final EssentiaWatcherManager essentiaWatcherManger;
/**
* The 'result' of essentia crafting operations.
*/
private final ItemStack aspectItem;
/**
* Watches the item network for essentia related events.
*/
private AspectCraftingWatcher craftingWatcher;
public GridEssentiaCache( final IGrid grid )
{
// Set the grid
this.internalGrid = grid;
// Create the watcher manager
this.watcherManger = new WatcherManager();
this.essentiaWatcherManger = new EssentiaWatcherManager();
// Set the aspect item
this.aspectItem = ItemEnum.CRAFTING_ASPECT.getStack();
// Create the crafting watcher
this.craftingWatcher = new AspectCraftingWatcher();
}
/**
* Add in any craftable aspects
*/
@Override
protected void updateCacheToMatchNetwork()
{
// Call super
super.updateCacheToMatchNetwork();
// Get the item monitor
IStorageGrid storage = (IStorageGrid)this.internalGrid.getCache( IStorageGrid.class );
IMEMonitor<IAEItemStack> itemMonitor = storage.getItemInventory();
// Get stored items
IItemList<IAEItemStack> storedItems = itemMonitor.getStorageList();
if( ( storedItems == null ) || ( storedItems.size() == 0 ) )
{
return;
}
// Create the aspect list
HashSet<Aspect> craftableAspects = new HashSet<Aspect>();
// Check each item for craftability and type
for( IAEItemStack stack : storedItems )
{
if( stack == null )
{
continue;
}
// Is the stack craftable, has NBT tag, and is a crafting aspect?
if( stack.isCraftable()
&& stack.hasTagCompound()
&& ( stack.getItem() instanceof ItemCraftingAspect ) )
{
// Get the aspect
Aspect aspect = ItemCraftingAspect.getAspect( stack.getTagCompound().getNBTTagCompoundCopy() );
if( aspect != null )
{
// Add the aspect
craftableAspects.add( aspect );
}
}
}
// Anything added?
if( craftableAspects.size() > 0 )
{
this.setCraftableAspects( craftableAspects );
}
}
@Override
@@ -245,10 +353,10 @@ public class GridEssentiaCache
IEssentiaWatcherHost host = (IEssentiaWatcherHost)machine;
// Create the watcher
EssentiaWatcher watcher = new EssentiaWatcher( this.watcherManger, host );
EssentiaWatcher watcher = new EssentiaWatcher( this.essentiaWatcherManger, host );
// Add to the watcher manager
this.watcherManger.addWatcher( gridNode, watcher );
this.essentiaWatcherManger.addWatcher( gridNode, watcher );
// Inform the host it has a watcher
host.updateWatcher( watcher );
@@ -330,6 +438,9 @@ public class GridEssentiaCache
// Wrap
this.wrap( storage.getFluidInventory(), (IEnergyGrid)this.internalGrid.getCache( IEnergyGrid.class ), this.internalGrid );
// Set the crafting watcher
storage.getItemInventory().addListener( this.craftingWatcher, this.internalGrid );
}
@Override
@@ -377,8 +488,15 @@ public class GridEssentiaCache
// Was the node an essentia watcher?
if( machine instanceof IEssentiaWatcherHost )
{
this.watcherManger.removeWatcher( gridNode );
this.essentiaWatcherManger.removeWatcher( gridNode );
}
}
/**
* Called by the crafting watcher when an update is needed.
*/
void markForUpdate()
{
this.cacheNeedsUpdate = true;
}
}
@@ -16,7 +16,7 @@ public interface IMEEssentiaMonitorReceiver
* Called when a change to the stored essentia occurs.
*
* @param fromMonitor
* @param change
* @param changes
*/
void postChange( IMEEssentiaMonitor fromMonitor, Iterable<AspectStack> changes );
}
@@ -15,7 +15,7 @@ import thaumcraft.client.lib.UtilsFX;
import thaumcraft.common.config.Config;
import thaumicenergistics.container.ContainerPartArcaneCraftingTerminal;
import thaumicenergistics.container.ContainerPartArcaneCraftingTerminal.ArcaneCrafingCost;
import thaumicenergistics.gui.abstraction.AbstractGuiConstantsACT;
import thaumicenergistics.gui.abstraction.GuiConstants_ACT;
import thaumicenergistics.gui.buttons.*;
import thaumicenergistics.gui.widget.AbstractWidget;
import thaumicenergistics.gui.widget.WidgetAEItem;
@@ -45,7 +45,7 @@ import cpw.mods.fml.relauncher.SideOnly;
*/
@SideOnly(Side.CLIENT)
public class GuiArcaneCraftingTerminal
extends AbstractGuiConstantsACT
extends GuiConstants_ACT
implements ISortSource
{
/**
@@ -61,7 +61,7 @@ public class GuiArcaneCraftingTerminal
/**
* Number of ME widgets
*/
private int widgetCount = AbstractGuiConstantsACT.ME_DEFAULT_ROWS * AbstractGuiConstantsACT.ME_COLUMNS;
private int widgetCount = GuiConstants_ACT.ME_DEFAULT_ROWS * GuiConstants_ACT.ME_COLUMNS;
/**
* Widget 'slots'.
@@ -133,7 +133,7 @@ public class GuiArcaneCraftingTerminal
/**
* The number of rows to use.
*/
private int numberOfWidgetRows = AbstractGuiConstantsACT.ME_DEFAULT_ROWS;
private int numberOfWidgetRows = GuiConstants_ACT.ME_DEFAULT_ROWS;
/**
* Button to set the sorting mode.
@@ -174,8 +174,8 @@ public class GuiArcaneCraftingTerminal
this.player = player;
// Set the width and height
this.xSize = AbstractGuiConstantsACT.GUI_WIDTH;
this.ySize = AbstractGuiConstantsACT.GUI_HEIGHT;
this.xSize = GuiConstants_ACT.GUI_WIDTH;
this.ySize = GuiConstants_ACT.GUI_HEIGHT;
// Set the title
this.guiTitle = ThEStrings.Gui_TitleArcaneCraftingTerminal.getLocalized();
@@ -229,8 +229,8 @@ public class GuiArcaneCraftingTerminal
{
// Was the mouse right-clicked over the search field?
if( ( mouseButton == GuiHelper.MOUSE_BUTTON_RIGHT ) &&
GuiHelper.INSTANCE.isPointInGuiRegion( AbstractGuiConstantsACT.SEARCH_POS_Y, AbstractGuiConstantsACT.SEARCH_POS_X,
AbstractGuiConstantsACT.SEARCH_HEIGHT, AbstractGuiConstantsACT.SEARCH_WIDTH, mouseX, mouseY, this.guiLeft, this.guiTop ) )
GuiHelper.INSTANCE.isPointInGuiRegion( GuiConstants_ACT.SEARCH_POS_Y, GuiConstants_ACT.SEARCH_POS_X,
GuiConstants_ACT.SEARCH_HEIGHT, GuiConstants_ACT.SEARCH_WIDTH, mouseX, mouseY, this.guiLeft, this.guiTop ) )
{
// Clear the search field
this.searchField.setText( "" );
@@ -262,8 +262,8 @@ public class GuiArcaneCraftingTerminal
private boolean clickHandler_Widgets( final int mouseX, final int mouseY, final int mouseButton )
{
// Was the click inside the ME grid?
if( GuiHelper.INSTANCE.isPointInGuiRegion( AbstractGuiConstantsACT.ME_ITEM_POS_Y, AbstractGuiConstantsACT.ME_ITEM_POS_X,
this.numberOfWidgetRows * AbstractGuiConstantsACT.ME_ROW_HEIGHT, AbstractGuiConstantsACT.ME_GRID_WIDTH, mouseX, mouseY, this.guiLeft,
if( GuiHelper.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 ) )
{
// Click + empty hand is extract
@@ -304,8 +304,8 @@ public class GuiArcaneCraftingTerminal
int mouseY = this.height - ( ( Mouse.getEventY() * this.height ) / this.mc.displayHeight ) - 1;
// Is the mouse inside the ME area?
if( GuiHelper.INSTANCE.isPointInGuiRegion( AbstractGuiConstantsACT.ME_ITEM_POS_Y, AbstractGuiConstantsACT.ME_ITEM_POS_X,
this.numberOfWidgetRows * AbstractGuiConstantsACT.ME_ROW_HEIGHT, AbstractGuiConstantsACT.ME_GRID_WIDTH, mouseX, mouseY, this.guiLeft,
if( GuiHelper.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 ) )
{
// Which direction was the scroll?
@@ -334,7 +334,7 @@ public class GuiArcaneCraftingTerminal
*/
private void drawCraftingAspects( final List<ArcaneCrafingCost> craftingCost )
{
int posY = AbstractGuiConstantsACT.ASPECT_COST_POS_Y + this.lowerTerminalYOffset;
int posY = GuiConstants_ACT.ASPECT_COST_POS_Y + this.lowerTerminalYOffset;
int column = 0;
// Draw each primal
@@ -347,12 +347,12 @@ public class GuiArcaneCraftingTerminal
if( !cost.hasEnoughVis )
{
// Ping-pong the alpha
alpha = GuiHelper.INSTANCE.pingPongFromTime( AbstractGuiConstantsACT.ASPECT_COST_BLINK_SPEED,
AbstractGuiConstantsACT.ASPECT_COST_MIN_ALPHA, AbstractGuiConstantsACT.ASPECT_COST_MAX_ALPHA );
alpha = GuiHelper.INSTANCE.pingPongFromTime( GuiConstants_ACT.ASPECT_COST_BLINK_SPEED,
GuiConstants_ACT.ASPECT_COST_MIN_ALPHA, GuiConstants_ACT.ASPECT_COST_MAX_ALPHA );
}
// Calculate X position
int posX = AbstractGuiConstantsACT.ASPECT_COST_POS_X + ( column * AbstractGuiConstantsACT.ASPECT_COST_SPACING );
int posX = GuiConstants_ACT.ASPECT_COST_POS_X + ( column * GuiConstants_ACT.ASPECT_COST_SPACING );
// Draw the aspect icon
UtilsFX.drawTag( posX, posY, cost.primal, cost.visCost, 0, this.zLevel, GL11.GL_ONE_MINUS_SRC_ALPHA, alpha, false );
@@ -364,7 +364,7 @@ public class GuiArcaneCraftingTerminal
column = 0;
// Increment Y
posY += AbstractGuiConstantsACT.ASPECT_COST_SPACING;
posY += GuiConstants_ACT.ASPECT_COST_SPACING;
}
}
}
@@ -467,18 +467,18 @@ public class GuiArcaneCraftingTerminal
// Tall?
if( this.terminalStyle == TerminalStyle.TALL )
{
extraRows = Math.max( 0, ( ( this.height - AbstractGuiConstantsACT.GUI_HEIGHT ) / 18 ) - 3 );
extraRows = Math.max( 0, ( ( this.height - GuiConstants_ACT.GUI_HEIGHT ) / 18 ) - 3 );
}
// Update the size and top of the GUI
this.ySize = AbstractGuiConstantsACT.GUI_HEIGHT + ( extraRows * AbstractGuiConstantsACT.ME_ROW_HEIGHT );
this.ySize = GuiConstants_ACT.GUI_HEIGHT + ( extraRows * GuiConstants_ACT.ME_ROW_HEIGHT );
this.guiTop = ( this.height - this.ySize ) / 2;
// Update the number of rows
this.numberOfWidgetRows = AbstractGuiConstantsACT.ME_DEFAULT_ROWS + extraRows;
this.numberOfWidgetRows = GuiConstants_ACT.ME_DEFAULT_ROWS + extraRows;
// Update number of widgets
this.widgetCount = this.numberOfWidgetRows * AbstractGuiConstantsACT.ME_COLUMNS;
this.widgetCount = this.numberOfWidgetRows * GuiConstants_ACT.ME_COLUMNS;
// Create the aspect bridge
try
@@ -496,12 +496,12 @@ public class GuiArcaneCraftingTerminal
// Create the widgets and bridge slots
for( int row = 0; row < this.numberOfWidgetRows; ++row )
{
for( int column = 0; column < AbstractGuiConstantsACT.ME_COLUMNS; ++column )
for( int column = 0; column < GuiConstants_ACT.ME_COLUMNS; ++column )
{
// Calculate the index and position
int index = ( row * AbstractGuiConstantsACT.ME_COLUMNS ) + column;
int posX = AbstractGuiConstantsACT.ME_ITEM_POS_X + ( column * AbstractWidget.WIDGET_SIZE );
int posY = AbstractGuiConstantsACT.ME_ITEM_POS_Y + ( row * AbstractWidget.WIDGET_SIZE );
int index = ( row * GuiConstants_ACT.ME_COLUMNS ) + column;
int posX = GuiConstants_ACT.ME_ITEM_POS_X + ( column * AbstractWidget.WIDGET_SIZE );
int posY = GuiConstants_ACT.ME_ITEM_POS_Y + ( row * AbstractWidget.WIDGET_SIZE );
// Create the ME slot
this.itemWidgets.add( new WidgetAEItem( this, posX, posY, this.aeItemRenderer ) );
@@ -518,11 +518,11 @@ public class GuiArcaneCraftingTerminal
this.updateScrollbarRange();
// Update the scroll bar height
this.setScrollBarHeight( AbstractGuiConstantsACT.SCROLLBAR_HEIGHT + ( extraRows * AbstractGuiConstantsACT.ME_ROW_HEIGHT ) );
this.setScrollBarHeight( GuiConstants_ACT.SCROLLBAR_HEIGHT + ( extraRows * GuiConstants_ACT.ME_ROW_HEIGHT ) );
// Update the lower terminal portion Y offset
int prevYOffset = this.lowerTerminalYOffset;
this.lowerTerminalYOffset = ( extraRows * AbstractGuiConstantsACT.ME_ROW_HEIGHT );
this.lowerTerminalYOffset = ( extraRows * GuiConstants_ACT.ME_ROW_HEIGHT );
// Update the container
if( prevYOffset != this.lowerTerminalYOffset )
@@ -575,7 +575,7 @@ public class GuiArcaneCraftingTerminal
{
// TODO: This needs some work to prevent overscroll
// Calculate the total number of rows needed to display ALL items
int totalNumberOfRows = (int)Math.ceil( this.repo.size() / (double)AbstractGuiConstantsACT.ME_COLUMNS );
int totalNumberOfRows = (int)Math.ceil( this.repo.size() / (double)GuiConstants_ACT.ME_COLUMNS );
// Calculate the scroll based on how many rows can be shown
int max = Math.max( 0, totalNumberOfRows - this.numberOfWidgetRows );
@@ -640,28 +640,28 @@ public class GuiArcaneCraftingTerminal
this.mc.renderEngine.bindTexture( GuiTextureManager.ARCANE_CRAFTING_TERMINAL.getTexture() );
// Draw the upper portion: Label, Search, First row
this.drawTexturedModalRect( this.guiLeft, this.guiTop, 0, 0, AbstractGuiConstantsACT.GUI_MAIN_BODY_WIDTH,
AbstractGuiConstantsACT.GUI_UPPER_TEXTURE_HEIGHT );
this.drawTexturedModalRect( this.guiLeft, this.guiTop, 0, 0, GuiConstants_ACT.GUI_MAIN_BODY_WIDTH,
GuiConstants_ACT.GUI_UPPER_TEXTURE_HEIGHT );
// Draw the extra rows
for( int i = 0; i < ( this.numberOfWidgetRows - AbstractGuiConstantsACT.ME_DEFAULT_ROWS ); ++i )
for( int i = 0; i < ( this.numberOfWidgetRows - GuiConstants_ACT.ME_DEFAULT_ROWS ); ++i )
{
int yPos = this.guiTop + AbstractGuiConstantsACT.GUI_UPPER_TEXTURE_HEIGHT + ( i * AbstractGuiConstantsACT.ME_ROW_HEIGHT );
int yPos = this.guiTop + GuiConstants_ACT.GUI_UPPER_TEXTURE_HEIGHT + ( i * GuiConstants_ACT.ME_ROW_HEIGHT );
// Draw the texture
this.drawTexturedModalRect( this.guiLeft, yPos, 0, AbstractGuiConstantsACT.GUI_TEXTURE_ROW_V,
AbstractGuiConstantsACT.GUI_MAIN_BODY_WIDTH, AbstractGuiConstantsACT.ME_ROW_HEIGHT );
this.drawTexturedModalRect( this.guiLeft, yPos, 0, GuiConstants_ACT.GUI_TEXTURE_ROW_V,
GuiConstants_ACT.GUI_MAIN_BODY_WIDTH, GuiConstants_ACT.ME_ROW_HEIGHT );
}
// Draw the lower portion, bottom two rows, crafting grid, player inventory
this.drawTexturedModalRect( this.guiLeft, this.guiTop + AbstractGuiConstantsACT.GUI_UPPER_TEXTURE_HEIGHT + this.lowerTerminalYOffset, 0,
AbstractGuiConstantsACT.ME_ROW_HEIGHT + 17, AbstractGuiConstantsACT.GUI_MAIN_BODY_WIDTH,
AbstractGuiConstantsACT.GUI_TEXTURE_LOWER_HEIGHT + 18 );
this.drawTexturedModalRect( this.guiLeft, this.guiTop + GuiConstants_ACT.GUI_UPPER_TEXTURE_HEIGHT + this.lowerTerminalYOffset, 0,
GuiConstants_ACT.ME_ROW_HEIGHT + 17, GuiConstants_ACT.GUI_MAIN_BODY_WIDTH,
GuiConstants_ACT.GUI_TEXTURE_LOWER_HEIGHT + 18 );
// Draw view cells
this.drawTexturedModalRect( this.guiLeft + AbstractGuiConstantsACT.GUI_MAIN_BODY_WIDTH, this.guiTop,
AbstractGuiConstantsACT.GUI_MAIN_BODY_WIDTH, 0, AbstractGuiConstantsACT.GUI_VIEW_CELL_TEXTURE_WIDTH,
AbstractGuiConstantsACT.GUI_VIEW_CELL_TEXTURE_HEIGHT );
this.drawTexturedModalRect( this.guiLeft + GuiConstants_ACT.GUI_MAIN_BODY_WIDTH, this.guiTop,
GuiConstants_ACT.GUI_MAIN_BODY_WIDTH, 0, GuiConstants_ACT.GUI_VIEW_CELL_TEXTURE_WIDTH,
GuiConstants_ACT.GUI_VIEW_CELL_TEXTURE_HEIGHT );
// Bind the AE states texture
Minecraft.getMinecraft().renderEngine.bindTexture( AEStateIconsEnum.AE_STATES_TEXTURE );
@@ -687,7 +687,7 @@ public class GuiArcaneCraftingTerminal
super.drawGuiContainerForegroundLayer( mouseX, mouseY );
// Draw the title
this.fontRendererObj.drawString( this.guiTitle, AbstractGuiConstantsACT.TITLE_POS_X, AbstractGuiConstantsACT.TITLE_POS_Y, 0x000000 );
this.fontRendererObj.drawString( this.guiTitle, GuiConstants_ACT.TITLE_POS_X, GuiConstants_ACT.TITLE_POS_Y, 0x000000 );
// Draw the search field.
this.searchField.drawTextBox();
@@ -709,7 +709,7 @@ public class GuiArcaneCraftingTerminal
}
// Should we force a tooltip update?
boolean forceTooltipUpdate = ( ( System.currentTimeMillis() - this.lastTooltipUpdateTime ) >= AbstractGuiConstantsACT.WIDGET_TOOLTIP_UPDATE_INTERVAL );
boolean forceTooltipUpdate = ( ( System.currentTimeMillis() - this.lastTooltipUpdateTime ) >= GuiConstants_ACT.WIDGET_TOOLTIP_UPDATE_INTERVAL );
// Has the mouse moved, or timeout reached?
if( forceTooltipUpdate || ( this.previousMouseX != mouseX ) || ( this.previousMouseY != mouseY ) )
@@ -730,6 +730,11 @@ public class GuiArcaneCraftingTerminal
this.lastTooltipUpdateTime = System.currentTimeMillis();
}
}
else
{
// Nothing to display
this.cachedItemTooltip.clear();
}
// Set the previous position
this.previousMouseX = mouseX;
@@ -755,10 +760,10 @@ public class GuiArcaneCraftingTerminal
protected ScrollbarParams getScrollbarParameters()
{
return new ScrollbarParams(
AbstractGuiConstantsACT.SCROLLBAR_POS_X,
AbstractGuiConstantsACT.SCROLLBAR_POS_Y,
AbstractGuiConstantsACT.SCROLLBAR_HEIGHT +
( ( AbstractGuiConstantsACT.ME_DEFAULT_ROWS - this.numberOfWidgetRows ) * AbstractGuiConstantsACT.ME_ROW_HEIGHT ) );
GuiConstants_ACT.SCROLLBAR_POS_X,
GuiConstants_ACT.SCROLLBAR_POS_Y,
GuiConstants_ACT.SCROLLBAR_HEIGHT +
( ( GuiConstants_ACT.ME_DEFAULT_ROWS - this.numberOfWidgetRows ) * GuiConstants_ACT.ME_ROW_HEIGHT ) );
}
/**
@@ -867,13 +872,13 @@ public class GuiArcaneCraftingTerminal
switch ( button.id )
{
// Clear grid
case AbstractGuiConstantsACT.BUTTON_CLEAR_GRID_ID:
case GuiConstants_ACT.BUTTON_CLEAR_GRID_ID:
// Attempt to clear the grid
Packet_S_ArcaneCraftingTerminal.sendClearGrid( this.player );
break;
// Sort order
case AbstractGuiConstantsACT.BUTTON_SORT_ORDER_ID:
case GuiConstants_ACT.BUTTON_SORT_MODE_ID:
switch ( this.sortingOrder )
{
case AMOUNT:
@@ -895,7 +900,7 @@ public class GuiArcaneCraftingTerminal
break;
// Sorting direction
case AbstractGuiConstantsACT.BUTTON_SORT_DIR_ID:
case GuiConstants_ACT.BUTTON_SORT_DIR_ID:
switch ( this.sortingDirection )
{
case ASCENDING:
@@ -911,7 +916,7 @@ public class GuiArcaneCraftingTerminal
break;
// View type
case AbstractGuiConstantsACT.BUTTON_VIEW_TYPE_ID:
case GuiConstants_ACT.BUTTON_VIEW_TYPE_ID:
// Rotate view mode
this.viewMode = Platform.rotateEnum( this.viewMode, !wasLeftClick, Settings.VIEW_MODE.getPossibleValues() );
@@ -920,13 +925,13 @@ public class GuiArcaneCraftingTerminal
break;
// Swap armor
case AbstractGuiConstantsACT.BUTTON_SWAP_ARMOR_ID:
case GuiConstants_ACT.BUTTON_SWAP_ARMOR_ID:
// Ask the server to swap the armor
Packet_S_ArcaneCraftingTerminal.sendSwapArmor( this.player );
break;
// Terminal style
case AbstractGuiConstantsACT.BUTTON_TERM_STYLE_ID:
case GuiConstants_ACT.BUTTON_TERM_STYLE_ID:
switch ( this.terminalStyle )
{
case SMALL:
@@ -952,7 +957,7 @@ public class GuiArcaneCraftingTerminal
break;
// Search mode
case AbstractGuiConstantsACT.BUTTON_SEARCH_MODE_ID:
case GuiConstants_ACT.BUTTON_SEARCH_MODE_ID:
// Rotate search mode
SearchBoxMode searchBoxMode = (SearchBoxMode)AEConfig.instance.settings.getSetting( Settings.SEARCH_MODE );
searchBoxMode = Platform.rotateEnum( searchBoxMode, !wasLeftClick, Settings.SEARCH_MODE.getPossibleValues() );
@@ -1057,7 +1062,7 @@ public class GuiArcaneCraftingTerminal
// 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 + AbstractGuiConstantsACT.GUI_WIDTH ) )
if( mouseX <= ( this.guiLeft + GuiConstants_ACT.GUI_WIDTH ) )
{
// Is shift being held?
if( Keyboard.isKeyDown( Keyboard.KEY_LSHIFT ) || Keyboard.isKeyDown( Keyboard.KEY_RSHIFT ) )
@@ -1106,14 +1111,14 @@ public class GuiArcaneCraftingTerminal
if( this.searchField == null )
{
// Set up the search bar
this.searchField = new GuiTextField( this.fontRendererObj, AbstractGuiConstantsACT.SEARCH_POS_X, AbstractGuiConstantsACT.SEARCH_POS_Y,
AbstractGuiConstantsACT.SEARCH_WIDTH, AbstractGuiConstantsACT.SEARCH_HEIGHT );
this.searchField = new GuiTextField( this.fontRendererObj, GuiConstants_ACT.SEARCH_POS_X, GuiConstants_ACT.SEARCH_POS_Y,
GuiConstants_ACT.SEARCH_WIDTH, GuiConstants_ACT.SEARCH_HEIGHT );
// Set the search field to draw in the foreground
this.searchField.setEnableBackgroundDrawing( false );
// Set maximum length
this.searchField.setMaxStringLength( AbstractGuiConstantsACT.SEARCH_MAX_CHARS );
this.searchField.setMaxStringLength( GuiConstants_ACT.SEARCH_MAX_CHARS );
}
// Start focused?
@@ -1126,39 +1131,39 @@ public class GuiArcaneCraftingTerminal
this.buttonList.clear();
// Create the clear grid button
this.buttonList.add( new GuiButtonClearCraftingGrid( AbstractGuiConstantsACT.BUTTON_CLEAR_GRID_ID, this.guiLeft +
AbstractGuiConstantsACT.BUTTON_CLEAR_GRID_POS_X, this.guiTop + AbstractGuiConstantsACT.BUTTON_CLEAR_GRID_POS_Y +
this.buttonList.add( new GuiButtonClearCraftingGrid( GuiConstants_ACT.BUTTON_CLEAR_GRID_ID, this.guiLeft +
GuiConstants_ACT.BUTTON_CLEAR_GRID_POS_X, this.guiTop + GuiConstants_ACT.BUTTON_CLEAR_GRID_POS_Y +
this.lowerTerminalYOffset, 8, 8 ) );
// Add sort order button
this.buttonList.add( this.btnSortingMode = new GuiButtonSortingMode( AbstractGuiConstantsACT.BUTTON_SORT_ORDER_ID, this.guiLeft +
AbstractGuiConstantsACT.BUTTON_SORT_ORDER_POS_X, this.guiTop + AbstractGuiConstantsACT.BUTTON_SORT_ORDER_POS_Y,
AbstractGuiConstantsACT.BUTTON_AE_SIZE, AbstractGuiConstantsACT.BUTTON_AE_SIZE ) );
this.buttonList.add( this.btnSortingMode = new GuiButtonSortingMode( GuiConstants_ACT.BUTTON_SORT_MODE_ID, this.guiLeft +
GuiConstants_ACT.BUTTON_SORT_MODE_POS_X, this.guiTop + GuiConstants_ACT.BUTTON_SORT_MODE_POS_Y,
GuiConstants_ACT.BUTTON_AE_SIZE, GuiConstants_ACT.BUTTON_AE_SIZE ) );
// Add sort direction button
this.buttonList.add( this.btnSortingDirection = new GuiButtonSortingDirection( AbstractGuiConstantsACT.BUTTON_SORT_DIR_ID, this.guiLeft +
AbstractGuiConstantsACT.BUTTON_SORT_DIR_POS_X, this.guiTop + AbstractGuiConstantsACT.BUTTON_SORT_DIR_POS_Y,
AbstractGuiConstantsACT.BUTTON_AE_SIZE, AbstractGuiConstantsACT.BUTTON_AE_SIZE ) );
this.buttonList.add( this.btnSortingDirection = new GuiButtonSortingDirection( GuiConstants_ACT.BUTTON_SORT_DIR_ID, this.guiLeft +
GuiConstants_ACT.BUTTON_SORT_DIR_POS_X, this.guiTop + GuiConstants_ACT.BUTTON_SORT_DIR_POS_Y,
GuiConstants_ACT.BUTTON_AE_SIZE, GuiConstants_ACT.BUTTON_AE_SIZE ) );
// Add view type button
this.buttonList.add( this.btnViewType = new GuiButtonViewType( AbstractGuiConstantsACT.BUTTON_VIEW_TYPE_ID, this.guiLeft +
AbstractGuiConstantsACT.BUTTON_VIEW_TYPE_POS_X, this.guiTop + AbstractGuiConstantsACT.BUTTON_VIEW_TYPE_POS_Y,
AbstractGuiConstantsACT.BUTTON_AE_SIZE, AbstractGuiConstantsACT.BUTTON_AE_SIZE ) );
this.buttonList.add( this.btnViewType = new GuiButtonViewType( GuiConstants_ACT.BUTTON_VIEW_TYPE_ID, this.guiLeft +
GuiConstants_ACT.BUTTON_VIEW_TYPE_POS_X, this.guiTop + GuiConstants_ACT.BUTTON_VIEW_TYPE_POS_Y,
GuiConstants_ACT.BUTTON_AE_SIZE, GuiConstants_ACT.BUTTON_AE_SIZE ) );
// Add swap armor button
this.buttonList.add( new GuiButtonSwapArmor( AbstractGuiConstantsACT.BUTTON_SWAP_ARMOR_ID, this.guiLeft +
AbstractGuiConstantsACT.BUTTON_SWAP_ARMOR_POS_X, this.guiTop + AbstractGuiConstantsACT.BUTTON_SWAP_ARMOR_POS_Y +
this.buttonList.add( new GuiButtonSwapArmor( GuiConstants_ACT.BUTTON_SWAP_ARMOR_ID, this.guiLeft +
GuiConstants_ACT.BUTTON_SWAP_ARMOR_POS_X, this.guiTop + GuiConstants_ACT.BUTTON_SWAP_ARMOR_POS_Y +
this.lowerTerminalYOffset, 8, 8 ) );
// Add search mode button
this.buttonList.add( this.btnSearchMode = new GuiButtonSearchMode( AbstractGuiConstantsACT.BUTTON_SEARCH_MODE_ID, this.guiLeft +
AbstractGuiConstantsACT.BUTTON_SEARCH_MODE_POS_X, this.guiTop + AbstractGuiConstantsACT.BUTTON_SEARCH_MODE_POS_Y,
AbstractGuiConstantsACT.BUTTON_AE_SIZE, AbstractGuiConstantsACT.BUTTON_AE_SIZE, searchBoxMode ) );
this.buttonList.add( this.btnSearchMode = new GuiButtonSearchMode( GuiConstants_ACT.BUTTON_SEARCH_MODE_ID, this.guiLeft +
GuiConstants_ACT.BUTTON_SEARCH_MODE_POS_X, this.guiTop + GuiConstants_ACT.BUTTON_SEARCH_MODE_POS_Y,
GuiConstants_ACT.BUTTON_AE_SIZE, GuiConstants_ACT.BUTTON_AE_SIZE, searchBoxMode ) );
// Add terminal style button
this.buttonList.add( new GuiButtonTerminalStyle( AbstractGuiConstantsACT.BUTTON_TERM_STYLE_ID, this.guiLeft +
AbstractGuiConstantsACT.BUTTON_TERM_STYLE_POS_X, this.guiTop + AbstractGuiConstantsACT.BUTTON_TERM_STYLE_POS_Y,
AbstractGuiConstantsACT.BUTTON_AE_SIZE, AbstractGuiConstantsACT.BUTTON_AE_SIZE, this.terminalStyle ) );
this.buttonList.add( new GuiButtonTerminalStyle( GuiConstants_ACT.BUTTON_TERM_STYLE_ID, this.guiLeft +
GuiConstants_ACT.BUTTON_TERM_STYLE_POS_X, this.guiTop + GuiConstants_ACT.BUTTON_TERM_STYLE_POS_Y,
GuiConstants_ACT.BUTTON_AE_SIZE, GuiConstants_ACT.BUTTON_AE_SIZE, this.terminalStyle ) );
// Add the container as a listener
( (ContainerPartArcaneCraftingTerminal)this.inventorySlots ).registerForUpdates();
@@ -4,7 +4,7 @@ import java.lang.reflect.Field;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import thaumicenergistics.api.ICraftingIssuerTerminalHost;
import thaumicenergistics.api.storage.ICraftingIssuerHost;
import thaumicenergistics.network.packet.server.Packet_S_ConfirmCraftingJob;
import appeng.client.gui.implementations.GuiCraftAmount;
import appeng.client.gui.widgets.GuiNumberBox;
@@ -17,7 +17,7 @@ public class GuiCraftAmountBridge
/**
* AE Part that is issued the crafting request.
*/
protected ICraftingIssuerTerminalHost terminalHost;
protected ICraftingIssuerHost host;
/**
* Button that returns to the terminal's GUI.
@@ -39,13 +39,13 @@ public class GuiCraftAmountBridge
*/
protected GuiNumberBox amountToCraft;
public GuiCraftAmountBridge( final EntityPlayer player, final ICraftingIssuerTerminalHost te )
public GuiCraftAmountBridge( final EntityPlayer player, final ICraftingIssuerHost craftingHost )
{
// Call super
super( player.inventory, te );
super( player.inventory, craftingHost );
// Set the terminal host
this.terminalHost = te;
// Set the host
this.host = craftingHost;
// Set the player
this.player = player;
@@ -56,8 +56,8 @@ public class GuiCraftAmountBridge
{
if( btn == this.buttonReturnToTerminalHost )
{
// Change back to terminal GUI
this.terminalHost.launchGUI( this.player );
// Change back to host GUI
this.host.launchGUI( this.player );
}
else if( btn == this.buttonNext )
{
@@ -88,8 +88,8 @@ public class GuiCraftAmountBridge
// Call super
super.initGui();
// Get the icon of the terminal
ItemStack myIcon = this.terminalHost.getIcon();
// Get the icon of the host
ItemStack myIcon = this.host.getIcon();
// Create the return button
this.buttonReturnToTerminalHost = new GuiTabButton( this.guiLeft + 154, this.guiTop, myIcon, myIcon.getDisplayName(), itemRender );
@@ -2,7 +2,7 @@ package thaumicenergistics.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.EntityPlayer;
import thaumicenergistics.api.ICraftingIssuerTerminalHost;
import thaumicenergistics.api.storage.ICraftingIssuerHost;
import appeng.client.gui.implementations.GuiCraftConfirm;
import appeng.core.localization.GuiText;
@@ -23,18 +23,18 @@ public class GuiCraftConfirmBridge
/**
* Host part.
*/
protected ICraftingIssuerTerminalHost host;
protected ICraftingIssuerHost host;
public GuiCraftConfirmBridge( final EntityPlayer player, final ICraftingIssuerTerminalHost terminalHost )
public GuiCraftConfirmBridge( final EntityPlayer player, final ICraftingIssuerHost craftingHost )
{
// Call super
super( player.inventory, terminalHost );
super( player.inventory, craftingHost );
// Set the player
this.player = player;
// Set the host
this.host = terminalHost;
this.host = craftingHost;
}
@Override
@@ -1,33 +1,37 @@
package thaumicenergistics.gui;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.FakePlayer;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.api.IThEWirelessEssentiaTerminal;
import thaumicenergistics.aspect.AspectStack;
import thaumicenergistics.aspect.AspectStackComparator.ComparatorMode;
import thaumicenergistics.aspect.AspectStackComparator;
import thaumicenergistics.aspect.AspectStackComparator.AspectStackComparatorMode;
import thaumicenergistics.container.*;
import thaumicenergistics.gui.abstraction.AbstractGuiWithScrollbar;
import thaumicenergistics.gui.abstraction.GuiConstants_ECT;
import thaumicenergistics.gui.buttons.GuiButtonSortingMode;
import thaumicenergistics.gui.buttons.GuiButtonViewType;
import thaumicenergistics.gui.widget.AbstractWidget;
import thaumicenergistics.gui.widget.IAspectSelectorGui;
import thaumicenergistics.gui.widget.WidgetAspectSelector;
import thaumicenergistics.gui.widget.WidgetAspectSelectorComparator;
import thaumicenergistics.inventory.HandlerWirelessEssentiaTerminal;
import thaumicenergistics.network.packet.server.Packet_S_EssentiaCellTerminal;
import thaumicenergistics.parts.AEPartEssentiaTerminal;
import thaumicenergistics.registries.ThEStrings;
import thaumicenergistics.texture.GuiTextureManager;
import thaumicenergistics.util.GuiHelper;
import appeng.api.config.ViewItems;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -39,135 +43,10 @@ import cpw.mods.fml.relauncher.SideOnly;
*/
@SideOnly(Side.CLIENT)
public class GuiEssentiaCellTerminal
extends AbstractGuiWithScrollbar
extends GuiConstants_ECT
implements IAspectSelectorGui
{
/**
* Number of widgets per row
*/
protected static final int WIDGETS_PER_ROW = 9;
/**
* Number of rows per page
*/
protected static final int ROWS_PER_PAGE = 4;
/**
* Number of widgets per page
*/
protected static final int WIDGETS_PER_PAGE = WIDGETS_PER_ROW * ROWS_PER_PAGE;
/**
* Width of the gui
*/
private static final int GUI_SIZE_X = 195;
/**
* Height of the gui
*/
private static final int GUI_SIZE_Y = 204;
/**
* Offset from the top of the screen to draw the gui at.
*/
private static final int GUI_OFFSET_Y = 18;
/**
* X position of the title string
*/
private static final int TITLE_POS_X = 7;
/**
* Y position of the title string
*/
private static final int TITLE_POS_Y = -12;
/**
* X position of the selected aspect info.
*/
private static final int SELECTED_INFO_POS_X = 45;
/**
* Y position of the name selected aspect info.
*/
private static final int SELECTED_INFO_NAME_POS_Y = 73;
/**
* Y position of the amount selected aspect info.
*/
private static final int SELECTED_INFO_AMOUNT_POS_Y = 83;
/**
* X offset to start drawing widgets
*/
private static final int WIDGET_OFFSET_X = 7;
/**
* Y offset to start drawing widgets
*/
private static final int WIDGET_OFFSET_Y = -1;
/**
* X offset to draw the search field
*/
private static final int SEARCH_X_OFFSET = 98;
/**
* Y offset to draw the search field
*/
private static final int SEARCH_Y_OFFSET = -12;
/**
* Width of the search field
*/
private static final int SEARCH_WIDTH = 69;
/**
* Height of the search field
*/
private static final int SEARCH_HEIGHT = 10;
/**
* The maximum number of display-able characters.
*/
private static final int SEARCH_MAX_CHARS = 14;
/**
* X position of the sorting mode button.
*/
private static final int SORT_MODE_BUTTON_POS_X = -18;
/**
* Y position of the sorting mode button.
*/
private static final int SORT_MODE_BUTTON_POS_Y = -15;
/**
* Width and height of the sorting mode button.
*/
private static final int SORT_MODE_BUTTON_SIZE = 16;
/**
* ID of the sort mode button.
*/
private static final int SORT_MODE_BUTTON_ID = 0;
/**
* X position of the scroll bar
*/
private static final int SCROLLBAR_POS_X = 175;
/**
* Y position of the scroll bar
*/
private static final int SCROLLBAR_POS_Y = 0;
/**
* Height of the scroll bar
*/
private static final int SCROLLBAR_HEIGHT = 70;
/**
* Local translation of the title.
*/
@@ -199,14 +78,14 @@ public class GuiEssentiaCellTerminal
protected GuiTextField searchBar;
/**
* All aspects currently in the network
* Widgets.
*/
protected List<WidgetAspectSelector> aspectWidgets = new ArrayList<WidgetAspectSelector>();
protected final WidgetAspectSelector[] aspectWidgets;
/**
* Aspects matching the current search term
* Aspect stacks that match the search term.
*/
protected List<WidgetAspectSelector> matchingSearchWidgets = new ArrayList<WidgetAspectSelector>();
protected ArrayList<AspectStack> matchingSearchStacks = new ArrayList<AspectStack>();
/**
* What the user is searching for
@@ -221,7 +100,22 @@ public class GuiEssentiaCellTerminal
/**
* Mode used to sort the aspects
*/
protected ComparatorMode sortMode = ComparatorMode.MODE_ALPHABETIC;
protected AspectStackComparatorMode sortMode = AspectStackComparatorMode.MODE_ALPHABETIC;
/**
* Set to true when the widgets need to be updated.
*/
protected boolean flagWidgetsNeedUpdate = false;
/**
* The sorting mode button.
*/
protected GuiButtonSortingMode buttonSortingMode = null;
/**
* Button to change what aspects (regular | crafting) are shown.
*/
protected GuiButtonViewType buttonViewMode;
/**
* The cached amount of the selected stack.
@@ -238,6 +132,16 @@ public class GuiEssentiaCellTerminal
*/
private int previousOverflowRows = 0;
/**
* Compares aspect stacks
*/
private final AspectStackComparator stackComparator;
/**
* Which items can be viewed in the terminal.
*/
private ViewItems viewMode = ViewItems.ALL;
/**
* The currently selected aspect
*/
@@ -251,7 +155,7 @@ public class GuiEssentiaCellTerminal
* @param container
* Container associated with the gui.
*/
private GuiEssentiaCellTerminal( final EntityPlayer player, final AbstractContainerCellTerminalBase container, final String title )
protected GuiEssentiaCellTerminal( final EntityPlayer player, final AbstractContainerCellTerminalBase container, final String title )
{
// Call super
super( container );
@@ -263,10 +167,10 @@ public class GuiEssentiaCellTerminal
this.player = player;
// Set the X size
this.xSize = GuiEssentiaCellTerminal.GUI_SIZE_X;
this.xSize = GUI_SIZE_X;
// Set the Y size
this.ySize = GuiEssentiaCellTerminal.GUI_SIZE_Y;
this.ySize = GUI_SIZE_Y;
// Set the title
this.guiTitle = title;
@@ -277,6 +181,25 @@ public class GuiEssentiaCellTerminal
// Set the amount prefix
this.selectedInfoAmountPrefix = ThEStrings.Gui_SelectedAmount.getLocalized() + ": ";
// Create the widgets
this.aspectWidgets = new WidgetAspectSelector[WIDGETS_PER_PAGE];
// Rows
for( int y = 0; y < WIDGET_ROWS_PER_PAGE; y++ )
{
// Columns
for( int x = 0; x < WIDGETS_PER_ROW; x++ )
{
WidgetAspectSelector widget = new WidgetAspectSelector( this, null,
WIDGET_OFFSET_X + ( x * AbstractWidget.WIDGET_SIZE ),
WIDGET_OFFSET_Y + ( y * AbstractWidget.WIDGET_SIZE ),
player );
this.aspectWidgets[( y * WIDGETS_PER_ROW ) + x] = widget;
}
}
// Create the comparator
this.stackComparator = new AspectStackComparator();
}
/**
@@ -321,18 +244,38 @@ public class GuiEssentiaCellTerminal
*/
public static GuiEssentiaCellTerminal NewWirelessEssentiaTerminalGui( final EntityPlayer player )
{
return new GuiEssentiaCellTerminal( player, new ContainerWirelessEssentiaTerminal( player, null ),
ThEStrings.Part_EssentiaTerminal.getLocalized() );
}
// Valid player?
if( ( player == null ) || ( player instanceof FakePlayer ) )
{
return null;
}
/**
* Sorts the list of matching widgets based on the current
* sorting mode.
*/
private void sortMatchingList()
{
// Sort the results
Collections.sort( this.matchingSearchWidgets, new WidgetAspectSelectorComparator( this.sortMode ) );
// Get the item the player is holding.
ItemStack wirelessTerminal = player.getHeldItem();
// Ensure the stack is valid
if( ( wirelessTerminal == null ) )
{
// Invalid stack
return null;
}
// Ensure the stack's item implements the wireless interface
if( !( wirelessTerminal.getItem() instanceof IThEWirelessEssentiaTerminal ) )
{
// Invalid item.
return null;
}
// Get the interface
IThEWirelessEssentiaTerminal terminalInterface = (IThEWirelessEssentiaTerminal)wirelessTerminal.getItem();
// Create the handler
HandlerWirelessEssentiaTerminal handler = new HandlerWirelessEssentiaTerminal( player, null, terminalInterface, wirelessTerminal );
// Create the gui
return new GuiEssentiaCellTerminal( player, new ContainerWirelessEssentiaTerminal( player, handler ),
ThEStrings.Part_EssentiaTerminal.getLocalized() );
}
/**
@@ -341,10 +284,10 @@ public class GuiEssentiaCellTerminal
private void updateScrollMaximum()
{
// Calculate the number of widgets the will overflow
double overflowWidgets = Math.max( 0, this.matchingSearchWidgets.size() - GuiEssentiaCellTerminal.WIDGETS_PER_PAGE );
double overflowWidgets = Math.max( 0, this.matchingSearchStacks.size() - WIDGETS_PER_PAGE );
// Calculate how many rows will overflow
int overflowRows = (int)Math.ceil( overflowWidgets / GuiEssentiaCellTerminal.WIDGETS_PER_ROW );
int overflowRows = (int)Math.ceil( overflowWidgets / WIDGETS_PER_ROW );
// Update if the range has changed
if( overflowRows != this.previousOverflowRows )
@@ -354,32 +297,92 @@ public class GuiEssentiaCellTerminal
this.onScrollbarMoved();
this.previousOverflowRows = overflowRows;
}
// Mark for widget update
this.flagWidgetsNeedUpdate = true;
}
/**
* Updates the matching widgets based on the current search term.
* Updates the matching widgets based on the viewing conditions.
*/
private void updateSearch()
private void updateView()
{
// Clear the matching widgets
this.matchingSearchWidgets.clear();
this.matchingSearchStacks.clear();
// Examine each of the possible widgets
for( WidgetAspectSelector currentWidget : this.aspectWidgets )
// Get the full list
Collection<AspectStack> stacks = this.baseContainer.getAspectStackList();
boolean hideCraftable = ( this.viewMode == ViewItems.STORED );
boolean hideStored = ( this.viewMode == ViewItems.CRAFTABLE );
// Examine each of the possible aspects
for( AspectStack stack : stacks )
{
// Is the search term in this aspects tag?
if( ( this.searchTerm == "" ) || ( currentWidget.getAspect().getTag().contains( this.searchTerm ) ) )
// Is this stack valid for the current view mode?
if( ( hideStored && !stack.isCraftable ) || ( hideCraftable && ( stack.stackSize < 1 ) ) )
{
this.matchingSearchWidgets.add( currentWidget );
continue;
}
// Is the search term in this aspects tag or name?
if( ( this.searchTerm == "" )
|| ( stack.aspect.getName().contains( this.searchTerm ) )
|| ( stack.aspect.getTag().contains( this.searchTerm ) ) )
{
this.matchingSearchStacks.add( stack );
}
}
// Sort
this.sortMatchingList();
// Set the comparator mode
this.stackComparator.setMode( this.sortMode );
// Sort the results
Collections.sort( this.matchingSearchStacks, this.stackComparator );
// Update scrollbar
this.updateScrollMaximum();
// Mark for widget update
this.flagWidgetsNeedUpdate = true;
}
/**
* Called when the update flag is true.
*/
private void updateWidgets()
{
// Get the number of matches
int numberOfSearchMatches = this.matchingSearchStacks.size();
// Calculate the row offset
int rowOffset = this.currentScroll * WIDGETS_PER_ROW;
// Update each widget
int matchIndex = -1;
for( int widgetIndex = 0; widgetIndex < this.aspectWidgets.length; ++widgetIndex )
{
// Calculate the match index
matchIndex = widgetIndex + rowOffset;
// Is the index greater than the number of matches?
if( matchIndex >= numberOfSearchMatches )
{
// Set the aspect to null
this.aspectWidgets[widgetIndex].clearWidget();
}
else
{
// Set the aspect
this.aspectWidgets[widgetIndex].setAspect( this.matchingSearchStacks.get( matchIndex ) );
// Set crafting mode
this.aspectWidgets[widgetIndex].setHideAmount( ( this.viewMode == ViewItems.CRAFTABLE ) );
}
}
this.flagWidgetsNeedUpdate = false;
}
/**
@@ -395,7 +398,7 @@ public class GuiEssentiaCellTerminal
Minecraft.getMinecraft().renderEngine.bindTexture( GuiTextureManager.ESSENTIA_TERMINAL.getTexture() );
// Draw the gui
this.drawTexturedModalRect( this.guiLeft, this.guiTop - GuiEssentiaCellTerminal.GUI_OFFSET_Y, 0, 0, this.xSize, this.ySize );
this.drawTexturedModalRect( this.guiLeft, this.guiTop - GUI_OFFSET_Y, 0, 0, this.xSize, this.ySize );
// Draw the search field.
this.searchBar.drawTextBox();
@@ -411,19 +414,19 @@ public class GuiEssentiaCellTerminal
super.drawGuiContainerForegroundLayer( mouseX, mouseY );
// Draw the title
this.fontRendererObj.drawString( this.guiTitle, GuiEssentiaCellTerminal.TITLE_POS_X, GuiEssentiaCellTerminal.TITLE_POS_Y, 0 );
this.fontRendererObj.drawString( this.guiTitle, TITLE_POS_X, TITLE_POS_Y, 0 );
// Draw the widgets
this.drawWidgets( mouseX, mouseY );
// Do we have a selected aspect?
if( ( this.selectedAspectStack != null ) && ( this.selectedAspectStack.stackSize > 0 ) )
// Is there a selected aspect?
if( this.selectedAspectStack != null )
{
// Update the display amount?
if( this.selectedAspectStack.stackSize != this.cacheAmountSelected )
{
// Convert the selected amount into a string
this.cacheAmountDisplay = GuiHelper.shortenCount( this.selectedAspectStack.stackSize );
this.cacheAmountDisplay = Long.toString( this.selectedAspectStack.stackSize );
// Cache the amount
this.cacheAmountSelected = this.selectedAspectStack.stackSize;
@@ -433,20 +436,19 @@ public class GuiEssentiaCellTerminal
String aspectName = this.selectedAspectStack.getAspectName( this.player );
// Draw the name
this.fontRendererObj.drawString( this.selectedInfoNamePrefix + aspectName, GuiEssentiaCellTerminal.SELECTED_INFO_POS_X,
GuiEssentiaCellTerminal.SELECTED_INFO_NAME_POS_Y, 0 );
this.fontRendererObj.drawString( this.selectedInfoNamePrefix + aspectName,
SELECTED_INFO_POS_X, SELECTED_INFO_NAME_POS_Y, 0 );
// Draw the amount
this.fontRendererObj.drawString( this.selectedInfoAmountPrefix + this.cacheAmountDisplay, GuiEssentiaCellTerminal.SELECTED_INFO_POS_X,
GuiEssentiaCellTerminal.SELECTED_INFO_AMOUNT_POS_Y, 0 );
this.fontRendererObj.drawString( this.selectedInfoAmountPrefix + this.cacheAmountDisplay,
SELECTED_INFO_POS_X, SELECTED_INFO_AMOUNT_POS_Y, 0 );
}
}
@Override
protected ScrollbarParams getScrollbarParameters()
{
return new ScrollbarParams( GuiEssentiaCellTerminal.SCROLLBAR_POS_X, GuiEssentiaCellTerminal.SCROLLBAR_POS_Y,
GuiEssentiaCellTerminal.SCROLLBAR_HEIGHT );
return new ScrollbarParams( SCROLLBAR_POS_X, SCROLLBAR_POS_Y, SCROLLBAR_HEIGHT );
}
/**
@@ -470,7 +472,7 @@ public class GuiEssentiaCellTerminal
this.searchTerm = this.searchBar.getText().trim().toLowerCase();
// Re-search the widgets
this.updateSearch();
this.updateView();
}
// Disable numeric key hotbar swaping.
else if( !Character.isDigit( key ) )
@@ -486,80 +488,74 @@ public class GuiEssentiaCellTerminal
@Override
protected void mouseClicked( final int mouseX, final int mouseY, final int mouseBtn )
{
// Get the number of widgets that match the current search.
int listSize = this.matchingSearchWidgets.size();
int index = 0;
boolean mouseOverElement;
// Is the mouse in the widget area?
if( GuiHelper.INSTANCE.isPointInGuiRegion(
GuiEssentiaCellTerminal.WIDGET_OFFSET_Y,
GuiEssentiaCellTerminal.WIDGET_OFFSET_X,
GuiEssentiaCellTerminal.ROWS_PER_PAGE * AbstractWidget.WIDGET_SIZE,
GuiEssentiaCellTerminal.WIDGETS_PER_ROW * AbstractWidget.WIDGET_SIZE,
mouseX, mouseY, this.guiLeft, this.guiTop ) )
mouseOverElement = GuiHelper.INSTANCE.isPointInGuiRegion(
WIDGET_OFFSET_Y, WIDGET_OFFSET_X,
WIDGET_ROWS_PER_PAGE * AbstractWidget.WIDGET_SIZE,
WIDGETS_PER_ROW * AbstractWidget.WIDGET_SIZE,
mouseX, mouseY, this.guiLeft, this.guiTop );
if( mouseOverElement )
{
// Rows
for( int y = 0; y < GuiEssentiaCellTerminal.ROWS_PER_PAGE; y++ )
// Check each widget
for( WidgetAspectSelector widget : this.aspectWidgets )
{
// Columns
for( int x = 0; x < GuiEssentiaCellTerminal.WIDGETS_PER_ROW; x++ )
// Is the mouse over this widget?
if( widget.isMouseOverWidget( mouseX, mouseY ) )
{
// Calculate the index
index = ( ( y + this.currentScroll ) * GuiEssentiaCellTerminal.WIDGETS_PER_ROW ) + x;
// Is the index in bounds?
if( index < listSize )
// Send crafting request if
// Only Craftable or Craftable and ( ( LeftClick and 0 ) or ( MiddleClick ) )
if( ( this.viewMode == ViewItems.CRAFTABLE ) || widget.getCraftable() && (
( mouseBtn == GuiHelper.MOUSE_BUTTON_WHEEL ) ) ||
( ( mouseBtn == GuiHelper.MOUSE_BUTTON_LEFT ) && ( widget.getAmount() == 0 ) ) )
{
// Get the widget at this index
WidgetAspectSelector currentWidget = this.matchingSearchWidgets.get( index );
// Is the mouse over this widget?
if( currentWidget.isMouseOverWidget( mouseX, mouseY ) )
{
// Play clicky sound
Minecraft.getMinecraft().getSoundHandler().playSound(
PositionedSoundRecord.func_147674_a( new ResourceLocation( "gui.button.press" ), 1.0F ) );
// Send the click to the widget
currentWidget.mouseClicked();
// Stop searching and do not pass to super
return;
}
// Send request
Packet_S_EssentiaCellTerminal.sendAutoCraft( this.player, widget.getAspect() );
}
else
{
// Unselect
this.baseContainer.setSelectedAspect( null );
// Stop searching
y = GuiEssentiaCellTerminal.ROWS_PER_PAGE;
break;
}
// Send the click
widget.onMouseClicked();
// Stop searching
return;
}
}
}
// Was the mouse right-clicked over the search field?
if( ( mouseBtn == GuiHelper.MOUSE_BUTTON_RIGHT ) &&
GuiHelper.INSTANCE.isPointInGuiRegion( GuiEssentiaCellTerminal.SEARCH_Y_OFFSET, GuiEssentiaCellTerminal.SEARCH_X_OFFSET,
GuiEssentiaCellTerminal.SEARCH_HEIGHT, GuiEssentiaCellTerminal.SEARCH_WIDTH, mouseX, mouseY, this.guiLeft, this.guiTop ) )
// Is the mouse over the search bar?
mouseOverElement = mouseX >= this.searchBar.xPosition
&& mouseX < this.searchBar.xPosition + this.searchBar.width
&& mouseY >= this.searchBar.yPosition
&& mouseY < this.searchBar.yPosition + this.searchBar.height;
if( mouseOverElement )
{
// Clear the search text
this.searchTerm = "";
this.searchBar.setText( this.searchTerm );
// Left click?
if( mouseBtn == GuiHelper.MOUSE_BUTTON_LEFT )
{
// Pass to search field.
this.searchBar.mouseClicked( mouseX, mouseY, mouseBtn );
// Update the widgets
this.updateSearch();
// Done
return;
// Do not pass to super
return;
}
// Right click?
else if( mouseBtn == GuiHelper.MOUSE_BUTTON_RIGHT )
{
// Clear the search text
this.searchTerm = "";
this.searchBar.setText( this.searchTerm );
// Update the widgets
this.updateView();
// Done
return;
}
}
// Pass to search field.
this.searchBar.mouseClicked( mouseX, mouseY, mouseBtn );
// Call super
super.mouseClicked( mouseX, mouseY, mouseBtn );
@@ -571,19 +567,33 @@ public class GuiEssentiaCellTerminal
@Override
protected void onButtonClicked( final GuiButton button, final int mouseButton )
{
// Ignore all middle clicks.
if( mouseButton == GuiHelper.MOUSE_BUTTON_WHEEL )
{
return;
}
// Is the button the sort mode button?
if( button.id == GuiEssentiaCellTerminal.SORT_MODE_BUTTON_ID )
if( button == this.buttonSortingMode )
{
// Request update from server
Packet_S_EssentiaCellTerminal.sendSortMode( this.player,
( this.sortMode == ComparatorMode.MODE_ALPHABETIC ? ComparatorMode.MODE_AMOUNT : ComparatorMode.MODE_ALPHABETIC ) );
Packet_S_EssentiaCellTerminal.sendChangeSorting( this.player, ( mouseButton == GuiHelper.MOUSE_BUTTON_RIGHT ) );
}
else if( button == this.buttonViewMode )
{
// Request update from server
Packet_S_EssentiaCellTerminal.sendChangeView( this.player, ( mouseButton == GuiHelper.MOUSE_BUTTON_RIGHT ) );
}
}
@Override
protected void onScrollbarMoved()
{
// Set the scroll
this.currentScroll = this.scrollBar.getCurrentScroll();
// Mark for widget update
this.flagWidgetsNeedUpdate = true;
}
/**
@@ -595,67 +605,36 @@ public class GuiEssentiaCellTerminal
public void drawWidgets( final int mouseX, final int mouseY )
{
// Anything to draw?
if( !this.matchingSearchWidgets.isEmpty() )
if( !this.matchingSearchStacks.isEmpty() )
{
// Calculate the starting index
int startingIndex = this.currentScroll * GuiEssentiaCellTerminal.WIDGETS_PER_ROW;
// Calculate the ending index
int endingIndex = Math.min( this.matchingSearchWidgets.size(), startingIndex + WIDGETS_PER_PAGE );
// Set the starting positions
int widgetPosX = GuiEssentiaCellTerminal.WIDGET_OFFSET_X;
int widgetPosY = GuiEssentiaCellTerminal.WIDGET_OFFSET_Y;
int widgetColumnPosition = 1;
// Holder for the widget under the mouse
WidgetAspectSelector widgetUnderMouse = null;
for( int index = startingIndex; index < endingIndex; index++ )
// Do the widgets need to be updated?
if( this.flagWidgetsNeedUpdate )
{
// Get the widget
WidgetAspectSelector currentWidget = this.matchingSearchWidgets.get( index );
// Set the position
currentWidget.setPosition( widgetPosX, widgetPosY );
// Draw the widget
currentWidget.drawWidget();
// Is the mouse over this widget?
if( currentWidget.isMouseOverWidget( mouseX, mouseY ) )
{
// Set the widget
widgetUnderMouse = this.matchingSearchWidgets.get( index );
}
// Increment the column position
widgetColumnPosition++ ;
// Are we done with this row?
if( widgetColumnPosition > GuiEssentiaCellTerminal.WIDGETS_PER_ROW )
{
// Reset X
widgetPosX = GuiEssentiaCellTerminal.WIDGET_OFFSET_X;
// Reset column position to 1
widgetColumnPosition = 1;
// Increment y
widgetPosY += AbstractWidget.WIDGET_SIZE;
}
else
{
// Increment the x position
widgetPosX += AbstractWidget.WIDGET_SIZE;
}
// Update first
this.updateWidgets();
}
// Was the mouse over a widget?
if( widgetUnderMouse != null )
for( int widgetIndex = 0; widgetIndex < this.aspectWidgets.length; ++widgetIndex )
{
// Get the tooltip from the widget
widgetUnderMouse.getTooltip( this.tooltip );
// Get the widget
WidgetAspectSelector widget = this.aspectWidgets[widgetIndex];
// Does the widget not have an aspect?
if( !widget.hasAspect() )
{
// Nothing more to draw
break;
}
// Draw the widget
widget.drawWidget();
// Is the mouse over this widget?
if( this.tooltip.isEmpty() && widget.isMouseOverWidget( mouseX, mouseY ) )
{
// Get the tooltip from the widget
widget.getTooltip( this.tooltip );
}
}
}
else
@@ -677,9 +656,9 @@ public class GuiEssentiaCellTerminal
* Gets the currently selected aspect.
*/
@Override
public AspectStack getSelectedAspect()
public Aspect getSelectedAspect()
{
return this.selectedAspectStack;
return( this.selectedAspectStack != null ? this.selectedAspectStack.aspect : null );
}
/**
@@ -715,12 +694,17 @@ public class GuiEssentiaCellTerminal
// Reset the mouse wheel state.
Mouse.getDWheel();
// Enable repeat keys
Keyboard.enableRepeatEvents( true );
// Get the aspect list
this.updateAspects();
// Set up the search bar
this.searchBar = new GuiTextField( this.fontRendererObj, this.guiLeft + GuiEssentiaCellTerminal.SEARCH_X_OFFSET, this.guiTop +
GuiEssentiaCellTerminal.SEARCH_Y_OFFSET, GuiEssentiaCellTerminal.SEARCH_WIDTH, GuiEssentiaCellTerminal.SEARCH_HEIGHT );
this.searchBar = new GuiTextField( this.fontRendererObj,
this.guiLeft + SEARCH_X_OFFSET,
this.guiTop + SEARCH_Y_OFFSET,
SEARCH_WIDTH, SEARCH_HEIGHT );
// Set the search bar to draw in the foreground
this.searchBar.setEnableBackgroundDrawing( false );
@@ -729,15 +713,37 @@ public class GuiEssentiaCellTerminal
this.searchBar.setFocused( false );
// Set maximum length
this.searchBar.setMaxStringLength( GuiEssentiaCellTerminal.SEARCH_MAX_CHARS );
this.searchBar.setMaxStringLength( SEARCH_MAX_CHARS );
// Clear any existing buttons
this.buttonList.clear();
// Add the sort mode button
this.buttonList.add( new GuiButtonSortingMode( GuiEssentiaCellTerminal.SORT_MODE_BUTTON_ID, this.guiLeft +
GuiEssentiaCellTerminal.SORT_MODE_BUTTON_POS_X, this.guiTop + GuiEssentiaCellTerminal.SORT_MODE_BUTTON_POS_Y,
GuiEssentiaCellTerminal.SORT_MODE_BUTTON_SIZE, GuiEssentiaCellTerminal.SORT_MODE_BUTTON_SIZE ) );
this.buttonSortingMode = new GuiButtonSortingMode( 0,
this.guiLeft + BUTTON_SORT_MODE_POS_X,
this.guiTop + BUTTON_SORT_MODE_POS_Y,
MODE_BUTTON_SIZE, MODE_BUTTON_SIZE );
this.buttonList.add( this.buttonSortingMode );
// Add view type button
this.buttonViewMode = new GuiButtonViewType( 1,
this.guiLeft + BUTTON_VIEW_MODE_POS_X,
this.guiTop + BUTTON_VIEW_MODE_POS_Y,
MODE_BUTTON_SIZE, MODE_BUTTON_SIZE );
this.buttonList.add( this.buttonViewMode );
}
/**
* Called when the gui is closing.
*/
@Override
public void onGuiClosed()
{
// Call super
super.onGuiClosed();
// Disable repeat keys
Keyboard.enableRepeatEvents( false );
}
/**
@@ -745,7 +751,7 @@ public class GuiEssentiaCellTerminal
*
* @param aspectStackList
*/
public void onReceiveAspectList( final List<AspectStack> aspectStackList )
public void onReceiveAspectList( final Collection<AspectStack> aspectStackList )
{
// Update the container
this.baseContainer.onReceivedAspectList( aspectStackList );
@@ -788,16 +794,33 @@ public class GuiEssentiaCellTerminal
*
* @param sortMode
*/
public void onSortModeChanged( final ComparatorMode sortMode )
public void onViewingModesChanged( final AspectStackComparatorMode sortMode, final ViewItems viewMode )
{
// Set the sort mode
this.sortMode = sortMode;
// Update the sort button
( (GuiButtonSortingMode)this.buttonList.get( GuiEssentiaCellTerminal.SORT_MODE_BUTTON_ID ) ).setSortMode( sortMode );
this.buttonSortingMode.setSortMode( this.sortMode = sortMode );
// Resort the list
this.sortMatchingList();
// Update view mode
this.buttonViewMode.setViewMode( this.viewMode = viewMode );
// Update the view
this.updateView();
}
/**
* Called when a new view mode is sent.
*
* @param mode
*/
public void onViewModeChanged( final ViewItems mode )
{
// Set the mode
this.viewMode = mode;
// Update the view
this.updateView();
// Mark for widget update
this.flagWidgetsNeedUpdate = true;
}
/**
@@ -805,24 +828,17 @@ public class GuiEssentiaCellTerminal
*/
public void updateAspects()
{
// Create a new list
this.aspectWidgets = new ArrayList<WidgetAspectSelector>();
// Make a widget for every aspect
for( AspectStack aspectStack : this.baseContainer.getAspectStackList() )
{
// Create the widget
this.aspectWidgets.add( new WidgetAspectSelector( this, aspectStack, 0, 0, this.player ) );
}
// Update the scrollbar
this.updateScrollMaximum();
// Update the search results
this.updateSearch();
this.updateView();
// Update the selected aspect
this.updateSelectedAspect();
// Mark for widget update
this.flagWidgetsNeedUpdate = true;
}
/**
@@ -302,7 +302,7 @@ public class GuiEssentiaCellWorkbench
// Set the aspects
for( int index = 0; index < count; index++ )
{
this.partitionWidgets[index].setAspect( aspectList.get( index ) );
this.partitionWidgets[index].setAspect( aspectList.get( index ), 1, false );
}
// Clear the rest
@@ -468,7 +468,7 @@ public class GuiEssentiaIO
for( int i = 0; i < count; i++ )
{
this.aspectSlotList.get( i ).setAspect( aspectList.get( i ) );
this.aspectSlotList.get( i ).setAspect( aspectList.get( i ), 1, false );
}
this.filteredAspects = aspectList;
@@ -461,7 +461,7 @@ public class GuiEssentiaLevelEmitter
if( itemAspect != null )
{
this.aspectFilterSlot.setAspect( itemAspect );
this.aspectFilterSlot.setAspect( itemAspect, 1, false );
return true;
}
@@ -481,7 +481,7 @@ public class GuiEssentiaLevelEmitter
}
else
{
this.aspectFilterSlot.setAspect( aspectList.get( 0 ) );
this.aspectFilterSlot.setAspect( aspectList.get( 0 ), 1, false );
}
}
@@ -341,7 +341,7 @@ public class GuiEssentiaStorageBus
for( int i = 0; i < count; i++ )
{
this.aspectWidgetList.get( i ).setAspect( aspectList.get( i ) );
this.aspectWidgetList.get( i ).setAspect( aspectList.get( i ), 1, false );
}
this.filteredAspects = aspectList;
@@ -302,7 +302,7 @@ public class GuiPriority
TileEntity host = this.part.getHostTile();
// Ask the server to change to the priority gui
Packet_S_ChangeGui.sendGuiChange( this.part, this.player, host.getWorldObj(), host.xCoord, host.yCoord, host.zCoord );
Packet_S_ChangeGui.sendGuiChangeToPart( this.part, this.player, host.getWorldObj(), host.xCoord, host.yCoord, host.zCoord );
return;
}
@@ -4,19 +4,14 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import thaumicenergistics.ThaumicEnergistics;
import thaumicenergistics.api.ICraftingIssuerTerminalHost;
import thaumicenergistics.container.ContainerArcaneAssembler;
import thaumicenergistics.container.ContainerDistillationEncoder;
import thaumicenergistics.container.ContainerEssentiaCell;
import thaumicenergistics.container.ContainerEssentiaCellWorkbench;
import thaumicenergistics.container.ContainerEssentiaVibrationChamber;
import thaumicenergistics.container.ContainerKnowledgeInscriber;
import thaumicenergistics.container.ContainerPriority;
import thaumicenergistics.container.ContainerWirelessEssentiaTerminal;
import thaumicenergistics.api.storage.ICraftingIssuerContainer;
import thaumicenergistics.api.storage.ICraftingIssuerHost;
import thaumicenergistics.container.*;
import thaumicenergistics.inventory.HandlerWirelessEssentiaTerminal;
import thaumicenergistics.parts.AbstractAEPartBase;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.container.AEBaseContainer;
import appeng.container.implementations.ContainerCraftAmount;
import appeng.container.implementations.ContainerCraftConfirm;
import appeng.helpers.IPriorityHost;
@@ -69,13 +64,15 @@ public class ThEGuiHandler
/**
* ID of the auto crafting amount bridge.
* Add the ForgeDirection's side ordinal to this value.
* When calling this make sure the current container implements ICraftingIssuerContainer,
* or extends AEBaseContainer with the target set to an ICraftingIssuerHost.
*/
public static final int AUTO_CRAFTING_AMOUNT = ID_STEP_VALUE * 8;
/**
* ID of the auto crafting confirm bridge.
* Add the ForgeDirection's side ordinal to this value.
* When calling this make sure the current container extends
* AEBaseContainer with the target set to an ICraftingIssuerHost.
*/
public static final int AUTO_CRAFTING_CONFIRM = ID_STEP_VALUE * 9;
@@ -89,6 +86,37 @@ public class ThEGuiHandler
*/
private static Object[] extraData = null;
/**
* Gets the crafting issuer host or null.
*
* @param player
* @return
*/
private static ICraftingIssuerHost getCraftingIssuerHost( final EntityPlayer player )
{
// Is the currently opened container a crafting issuer container?
if( player.openContainer instanceof ICraftingIssuerContainer )
{
// Return the issuer
return ( (ICraftingIssuerContainer)player.openContainer ).getCraftingHost();
}
// Is the currently opened container an AE base container?
if( player.openContainer instanceof AEBaseContainer )
{
// Get the target
Object target = ( (AEBaseContainer)player.openContainer ).getTarget();
// Is the target an ICraftingIssuerHost?
if( target instanceof ICraftingIssuerHost )
{
return (ICraftingIssuerHost)target;
}
}
return null;
}
/**
* Gets the AE part at the specified location.
*
@@ -289,6 +317,25 @@ public class ThEGuiHandler
// Distillation encoder?
case ThEGuiHandler.DISTILLATION_ENCODER:
return new GuiDistillationEncoder( player, world, x, y, z );
// AE2 Autocrafting Amount?
case ThEGuiHandler.AUTO_CRAFTING_AMOUNT:
ICraftingIssuerHost amountHost = ThEGuiHandler.getCraftingIssuerHost( player );
if( amountHost != null )
{
return new GuiCraftAmountBridge( player, amountHost );
}
return null;
// AE2 Autocrafting Confirm?
case ThEGuiHandler.AUTO_CRAFTING_CONFIRM:
ICraftingIssuerHost confirmHost = ThEGuiHandler.getCraftingIssuerHost( player );
if( confirmHost != null )
{
return new GuiCraftConfirmBridge( player, confirmHost );
}
return null;
}
// Is this the priority window?
@@ -307,38 +354,6 @@ public class ThEGuiHandler
return new GuiPriority( (IPriorityHost)part, player );
}
// AE2 Autocrafting Amount?
if( ThEGuiHandler.isIDInRange( ID, ThEGuiHandler.AUTO_CRAFTING_AMOUNT ) )
{
// Get the part
IPart part = ThEGuiHandler.getPartFromSidedID( ID, world, x, y, z );
// Ensure the part, and that it implements ICraftingIssuerTerminalHost
if( ( part == null ) || !( part instanceof ICraftingIssuerTerminalHost ) )
{
return null;
}
// Return the gui
return new GuiCraftAmountBridge( player, (ICraftingIssuerTerminalHost)part );
}
// AE2 Autocrafting Confirm?
if( ThEGuiHandler.isIDInRange( ID, ThEGuiHandler.AUTO_CRAFTING_CONFIRM ) )
{
// Get the part
IPart part = ThEGuiHandler.getPartFromSidedID( ID, world, x, y, z );
// Ensure the part, and that it implements ICraftingIssuerTerminalHost
if( ( part == null ) || !( part instanceof ICraftingIssuerTerminalHost ) )
{
return null;
}
// Return the gui
return new GuiCraftConfirmBridge( player, (ICraftingIssuerTerminalHost)part );
}
// No matching GUI element found
return null;
@@ -391,6 +406,24 @@ public class ThEGuiHandler
case ThEGuiHandler.DISTILLATION_ENCODER:
return new ContainerDistillationEncoder( player, world, x, y, z );
// AE2 Autocrafting Amount?
case ThEGuiHandler.AUTO_CRAFTING_AMOUNT:
ICraftingIssuerHost amountHost = ThEGuiHandler.getCraftingIssuerHost( player );
if( amountHost != null )
{
return new ContainerCraftAmount( player.inventory, amountHost );
}
return null;
// AE2 Autocrafting Confirm?
case ThEGuiHandler.AUTO_CRAFTING_CONFIRM:
ICraftingIssuerHost confirmHost = ThEGuiHandler.getCraftingIssuerHost( player );
if( confirmHost != null )
{
return new ContainerCraftConfirm( player.inventory, confirmHost );
}
return null;
}
// Is this the priority window?
@@ -410,40 +443,6 @@ public class ThEGuiHandler
}
// AE2 Autocrafting Amount?
if( ThEGuiHandler.isIDInRange( ID, ThEGuiHandler.AUTO_CRAFTING_AMOUNT ) )
{
// Get the part
IPart part = ThEGuiHandler.getPartFromSidedID( ID, world, x, y, z );
// Ensure the part, and that it implements ICraftingIssuerTerminalHost
if( ( part == null ) || !( part instanceof ICraftingIssuerTerminalHost ) )
{
return null;
}
// Return the container
return new ContainerCraftAmount( player.inventory, (ICraftingIssuerTerminalHost)part );
}
// AE2 Autocrafting Confirm?
if( ThEGuiHandler.isIDInRange( ID, ThEGuiHandler.AUTO_CRAFTING_CONFIRM ) )
{
// Get the part
IPart part = ThEGuiHandler.getPartFromSidedID( ID, world, x, y, z );
// Ensure the part, and that it implements ICraftingIssuerTerminalHost
if( ( part == null ) || !( part instanceof ICraftingIssuerTerminalHost ) )
{
return null;
}
// Return the container
return new ContainerCraftConfirm( player.inventory, (ICraftingIssuerTerminalHost)part );
}
// No matching GUI element found
return null;
}
@@ -3,6 +3,7 @@ package thaumicenergistics.gui.abstraction;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
@@ -261,6 +262,12 @@ public abstract class AbstractGuiBase
}
}
@Override
public final FontRenderer getFontRenderer()
{
return this.fontRendererObj;
}
/**
* Gets the starting X position for the Gui.
*/
@@ -209,9 +209,6 @@ public abstract class AbstractGuiWithScrollbar
@Override
public void drawScreen( final int mouseX, final int mouseY, final float mouseBtn )
{
// Call super
super.drawScreen( mouseX, mouseY, mouseBtn );
// Is the mouse holding the scroll bar?
if( this.isScrollBarHeld )
{
@@ -255,7 +252,7 @@ public abstract class AbstractGuiWithScrollbar
this.scrollBar.wheel( 1 );
}
// Inform the subclass the scrollbar has moved //
// Inform the subclass the scrollbar has moved
this.onScrollbarMoved();
}
else
@@ -265,6 +262,9 @@ public abstract class AbstractGuiWithScrollbar
}
}
// Call super
super.drawScreen( mouseX, mouseY, mouseBtn );
}
/**
@@ -11,7 +11,7 @@ import cpw.mods.fml.relauncher.SideOnly;
*
*/
@SideOnly(Side.CLIENT)
public abstract class AbstractGuiConstantsACT
public abstract class GuiConstants_ACT
extends AbstractGuiWithScrollbar
{
@@ -51,20 +51,20 @@ public abstract class AbstractGuiConstantsACT
protected static final int BUTTON_CLEAR_GRID_ID = 0, BUTTON_CLEAR_GRID_POS_X = 98, BUTTON_CLEAR_GRID_POS_Y = 89;
/**
* Sort order button
* Sort mode button
*/
protected static final int BUTTON_SORT_ORDER_ID = 1, BUTTON_SORT_ORDER_POS_X = -18, BUTTON_SORT_ORDER_POS_Y = 8;
protected static final int BUTTON_SORT_MODE_ID = 1, BUTTON_SORT_MODE_POS_X = -18, BUTTON_SORT_MODE_POS_Y = 8;
/**
* Sort direction button
*/
protected static final int BUTTON_SORT_DIR_ID = 2, BUTTON_SORT_DIR_POS_X = BUTTON_SORT_ORDER_POS_X,
BUTTON_SORT_DIR_POS_Y = BUTTON_SORT_ORDER_POS_Y + 20;
protected static final int BUTTON_SORT_DIR_ID = 2, BUTTON_SORT_DIR_POS_X = BUTTON_SORT_MODE_POS_X,
BUTTON_SORT_DIR_POS_Y = BUTTON_SORT_MODE_POS_Y + 20;
/**
* View type button
*/
protected static final int BUTTON_VIEW_TYPE_ID = 3, BUTTON_VIEW_TYPE_POS_X = BUTTON_SORT_ORDER_POS_X,
protected static final int BUTTON_VIEW_TYPE_ID = 3, BUTTON_VIEW_TYPE_POS_X = BUTTON_SORT_MODE_POS_X,
BUTTON_VIEW_TYPE_POS_Y = BUTTON_SORT_DIR_POS_Y + 20;
/**
@@ -75,13 +75,13 @@ public abstract class AbstractGuiConstantsACT
/**
* Search mode
*/
protected static final int BUTTON_SEARCH_MODE_ID = 5, BUTTON_SEARCH_MODE_POS_X = BUTTON_SORT_ORDER_POS_X,
protected static final int BUTTON_SEARCH_MODE_ID = 5, BUTTON_SEARCH_MODE_POS_X = BUTTON_SORT_MODE_POS_X,
BUTTON_SEARCH_MODE_POS_Y = BUTTON_VIEW_TYPE_POS_Y + 20;
/**
* Terminal style button
*/
protected static final int BUTTON_TERM_STYLE_ID = 6, BUTTON_TERM_STYLE_POS_X = BUTTON_SORT_ORDER_POS_X,
protected static final int BUTTON_TERM_STYLE_ID = 6, BUTTON_TERM_STYLE_POS_X = BUTTON_SORT_MODE_POS_X,
BUTTON_TERM_STYLE_POS_Y = BUTTON_SEARCH_MODE_POS_Y + 20;
/**
@@ -219,7 +219,7 @@ public abstract class AbstractGuiConstantsACT
*/
protected static final long WIDGET_TOOLTIP_UPDATE_INTERVAL = 3000L;
public AbstractGuiConstantsACT( final Container container )
public GuiConstants_ACT( final Container container )
{
super( container );
}
@@ -0,0 +1,83 @@
package thaumicenergistics.gui.abstraction;
import net.minecraft.inventory.Container;
public abstract class GuiConstants_ECT
extends AbstractGuiWithScrollbar
{
/**
* Sort mode button position.
*/
protected static final int BUTTON_SORT_MODE_POS_X = -18, BUTTON_SORT_MODE_POS_Y = -9;
/**
* View mode button.
*/
protected static final int BUTTON_VIEW_MODE_POS_X = -18, BUTTON_VIEW_MODE_POS_Y = BUTTON_SORT_MODE_POS_Y + 20;
/**
* Size of the gui.
*/
protected static final int GUI_SIZE_X = 195, GUI_SIZE_Y = 204;
/**
* Offset from the top of the screen to draw the gui at.
*/
protected static final int GUI_OFFSET_Y = 18;
/**
* Width and height of the mode buttons.
*/
protected static final int MODE_BUTTON_SIZE = 16;
/**
* Search bar.
*/
protected static final int SEARCH_X_OFFSET = 98, SEARCH_Y_OFFSET = -12, SEARCH_WIDTH = 69, SEARCH_HEIGHT = 10;
/**
* The maximum number of displayable characters.
*/
protected static final int SEARCH_MAX_CHARS = 14;
/**
* Scroll bar.
*/
protected static final int SCROLLBAR_POS_X = 175, SCROLLBAR_POS_Y = 0, SCROLLBAR_HEIGHT = 70;
/**
* Selected aspect info positions.
*/
protected static final int SELECTED_INFO_POS_X = 45, SELECTED_INFO_NAME_POS_Y = 73, SELECTED_INFO_AMOUNT_POS_Y = 83;
/**
* Position of the title.
*/
protected static final int TITLE_POS_X = 7, TITLE_POS_Y = -12;
/**
* Widget offsets.
*/
protected static final int WIDGET_OFFSET_X = 7, WIDGET_OFFSET_Y = -1;
/**
* Number of widgets per row.
*/
protected static final int WIDGETS_PER_ROW = 9;
/**
* Number of rows per page.
*/
protected static final int WIDGET_ROWS_PER_PAGE = 4;
/**
* Number of widgets per page.
*/
protected static final int WIDGETS_PER_PAGE = WIDGETS_PER_ROW * WIDGET_ROWS_PER_PAGE;
public GuiConstants_ECT( final Container container )
{
super( container );
}
}
@@ -3,7 +3,7 @@ package thaumicenergistics.gui.buttons;
import java.util.List;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import thaumicenergistics.aspect.AspectStackComparator.ComparatorMode;
import thaumicenergistics.aspect.AspectStackComparator.AspectStackComparatorMode;
import thaumicenergistics.texture.AEStateIconsEnum;
import appeng.api.config.SortOrder;
import appeng.core.localization.ButtonToolTips;
@@ -29,7 +29,7 @@ public class GuiButtonSortingMode
*
* @param mode
*/
public void setSortMode( final ComparatorMode mode )
public void setSortMode( final AspectStackComparatorMode mode )
{
switch ( mode )
{
@@ -3,28 +3,57 @@ package thaumicenergistics.gui.widget;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.client.lib.UtilsFX;
import thaumicenergistics.aspect.AspectStack;
import thaumicenergistics.registries.ThEStrings;
import thaumicenergistics.util.GuiHelper;
public abstract class AbstractAspectWidget
extends AbstractWidget
{
/**
* Icon to display if the aspect is unknown to the player
*/
private static final ResourceLocation UNKNOWN_TEXTURE = new ResourceLocation( "thaumcraft", "textures/aspects/_unknown.png" );
private Aspect aspect;
private final AspectStack aspectStack;
private boolean hasDiscovered = false;
/**
* True if the player has discovered the aspect.
*/
protected boolean hasDiscovered = false;
/**
* Cached aspect name.
*/
protected String aspectName = "";
/**
* Cached description of the aspect.
*/
protected String aspectDescription = "";
/**
* Cached footnote of the aspect.
* NOTE: One day I hope to put the mod the aspect is from here,
* not just its primallity.
*/
protected String aspectFootnote = "";
/**
* The current player.
*/
private EntityPlayer player;
/**
* Color of the aspect as ARGB.
*/
private byte[] aspectColorBytes;
public AbstractAspectWidget( final IWidgetHost hostGui, final Aspect aspect, final int xPos, final int yPos, final EntityPlayer player )
public AbstractAspectWidget( final IWidgetHost hostGui, final AspectStack stack, final int xPos, final int yPos, final EntityPlayer player )
{
// Call super
super( hostGui, xPos, yPos );
@@ -32,8 +61,32 @@ public abstract class AbstractAspectWidget
// Set the player
this.player = player;
// Create the aspect stack
this.aspectStack = new AspectStack();
// Set the aspect
this.setAspect( aspect );
this.setAspect( stack );
}
/**
* Clears the stack and optionally fires the on stack changed event.
*
* @param doUpdate
*/
protected void clearStack( final boolean doUpdate )
{
this.aspectStack.aspect = null;
this.aspectStack.stackSize = 0;
this.aspectStack.isCraftable = false;
this.aspectName = "";
this.aspectDescription = "";
this.aspectFootnote = "";
this.hasDiscovered = false;
if( doUpdate )
{
this.onStackChanged();
}
}
/**
@@ -42,7 +95,7 @@ public abstract class AbstractAspectWidget
protected void drawAspect()
{
// Ensure there is an aspect to draw
if( this.aspect == null )
if( this.aspectStack.aspect == null )
{
return;
}
@@ -51,7 +104,7 @@ public abstract class AbstractAspectWidget
if( this.hasDiscovered )
{
// Ask Thaumcraft to draw the aspect
UtilsFX.drawTag( this.xPosition + 1, this.yPosition + 1, this.aspect, 0, 0, this.zLevel );
UtilsFX.drawTag( this.xPosition + 1, this.yPosition + 1, this.aspectStack.aspect, 0, 0, this.zLevel );
}
// Draw the question mark
else
@@ -76,35 +129,138 @@ public abstract class AbstractAspectWidget
}
}
/**
* Called when the stack changes.
*/
protected void onStackChanged()
{
// Is there an aspect?
if( this.aspectStack.aspect != null )
{
// Get the aspect name
this.aspectName = this.aspectStack.getAspectName( this.player );
// Get if the player has discovered this aspect
this.hasDiscovered = this.aspectStack.hasPlayerDiscovered( this.player );
if( this.hasDiscovered )
{
// Get the description
this.aspectDescription = this.aspectStack.aspect.getLocalizedDescription();
// Set footnote
if( this.aspectStack.aspect.isPrimal() )
{
this.aspectFootnote = StatCollector.translateToLocal( "tc.aspect.primal" );
}
else
{
this.aspectFootnote = ThEStrings.Gui_SelectedAspect.getLocalized();
}
}
else
{
this.aspectDescription = this.aspectName;
this.aspectFootnote = this.aspectName;
}
// Get the color bytes
this.aspectColorBytes = GuiHelper.INSTANCE.convertPackedColorToARGB( this.aspectStack.aspect.getColor() );
// Set full alpha
this.aspectColorBytes[0] = (byte)255;
}
else
{
// Clear the info
this.clearStack( false );
}
}
/**
* Clears the stack.
*/
public void clearWidget()
{
this.clearStack( true );
}
/**
* Gets the stack size.
*
* @return
*/
public long getAmount()
{
return this.aspectStack.stackSize;
}
/**
* Gets the aspect stack for this widget.
*
* @return
*/
public Aspect getAspect()
{
return this.aspect;
return this.aspectStack.aspect;
}
public void setAspect( final Aspect aspect )
/**
* Gets whether or not the stack is craftable.
*
* @return
*/
public boolean getCraftable()
{
return this.aspectStack.isCraftable;
}
/**
* Returns the aspect stack.
*
* @return
*/
public AspectStack getStack()
{
return this.aspectStack;
}
/**
* Returns true if the widget has an aspect.
*
* @return
*/
public boolean hasAspect()
{
return( this.aspectStack.aspect != null );
}
/**
* Set's the aspect stack based on the passed values.
*
* @param aspect
* @param amount
* @param isCraftable
*/
public void setAspect( final Aspect aspect, final long amount, final boolean isCraftable )
{
// Set the aspect
this.aspect = aspect;
this.aspectStack.aspect = aspect;
this.aspectStack.stackSize = amount;
this.aspectStack.isCraftable = isCraftable;
// Ensure there is an aspect
if( aspect == null )
{
return;
}
this.onStackChanged();
}
// Convert to stack
AspectStack stack = new AspectStack( aspect, 1 );
/**
* Sets the aspect based on the stack
*
* @param stack
*/
public void setAspect( final AspectStack stack )
{
// Copy the values
this.aspectStack.copyFrom( stack );
// Get the aspect name
this.aspectName = stack.getAspectName( this.player );
// Get if the player has discovered this aspect
this.hasDiscovered = stack.hasPlayerDiscovered( this.player );
// Get the color bytes
this.aspectColorBytes = GuiHelper.INSTANCE.convertPackedColorToARGB( aspect.getColor() );
// Set full alpha
this.aspectColorBytes[0] = (byte)255;
this.onStackChanged();
}
}
@@ -47,11 +47,17 @@ public abstract class AbstractWidget
public boolean isMouseOverWidget( final int mouseX, final int mouseY )
{
return GuiHelper.INSTANCE.isPointInGuiRegion( this.yPosition, this.xPosition, AbstractWidget.WIDGET_SIZE, AbstractWidget.WIDGET_SIZE, mouseX,
mouseY, this.hostGUI.guiLeft(), this.hostGUI.guiTop() );
return GuiHelper.INSTANCE.isPointInGuiRegion(
this.yPosition, this.xPosition,
WIDGET_SIZE - 1, WIDGET_SIZE - 1,
mouseX, mouseY,
this.hostGUI.guiLeft(), this.hostGUI.guiTop() );
}
public abstract void mouseClicked();
/**
* Called when the mouse is clicked on the widget.
*/
public abstract void onMouseClicked();
public void setPosition( final int xPos, final int yPos )
{
@@ -1,6 +1,6 @@
package thaumicenergistics.gui.widget;
import thaumicenergistics.aspect.AspectStack;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.container.IAspectSelectorContainer;
public interface IAspectSelectorGui
@@ -8,6 +8,6 @@ public interface IAspectSelectorGui
{
public IAspectSelectorContainer getContainer();
public AspectStack getSelectedAspect();
public Aspect getSelectedAspect();
}
@@ -1,7 +1,16 @@
package thaumicenergistics.gui.widget;
import net.minecraft.client.gui.FontRenderer;
public interface IWidgetHost
{
/**
* Gets the font renderer for the GUI.
*
* @return
*/
public FontRenderer getFontRenderer();
public int guiLeft();
public int guiTop();
@@ -126,7 +126,7 @@ public class WidgetAEItem
}
@Override
public void mouseClicked()
public void onMouseClicked()
{
// Unused
}
@@ -1,15 +1,22 @@
package thaumicenergistics.gui.widget;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.aspect.AspectStack;
import thaumicenergistics.registries.ThEStrings;
import thaumicenergistics.util.GuiHelper;
import appeng.core.AEConfig;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class WidgetAspectSelector
extends AbstractAspectWidget
{
@@ -34,25 +41,16 @@ public class WidgetAspectSelector
private int[] backgroundPulseGradient;
/**
* The essentia amount for our aspect.
* If true the amount will not be drawn, also if the stack is craftable
* it will show the crafting text.
*/
private long amount = 0;
protected boolean hideAmount = false;
public WidgetAspectSelector( final IAspectSelectorGui selectorGui, final AspectStack stack, final int xPos, final int yPos,
final EntityPlayer player )
{
// Call super
super( selectorGui, stack.aspect, xPos, yPos, player );
// Get the amount
this.amount = stack.stackSize;
// Get the aspect color
int aspectColor = stack.aspect.getColor();
// Create the gradient using the aspect color, varying between opacities
this.backgroundPulseGradient = GuiHelper.INSTANCE
.createColorGradient( 0x70000000 | aspectColor, 0x20000000 | aspectColor, GRADIENT_COUNT + 1 );
super( selectorGui, stack, xPos, yPos, player );
}
/**
@@ -136,17 +134,33 @@ public class WidgetAspectSelector
return this.backgroundPulseGradient[index];
}
@Override
protected void onStackChanged()
{
// Call super
super.onStackChanged();
if( !this.hasAspect() )
{
return;
}
// Get the aspect color
int aspectColor = this.getStack().aspect.getColor();
// Create the gradient using the aspect color, varying between opacities
this.backgroundPulseGradient = GuiHelper.INSTANCE
.createColorGradient( 0x70000000 | aspectColor, 0x20000000 | aspectColor, GRADIENT_COUNT + 1 );
}
/**
* Draws the aspect icon and selector border if it is selected.
*/
@Override
public void drawWidget()
{
// Bind the block master texture
//Minecraft.getMinecraft().renderEngine.bindTexture( TextureMap.locationBlocksTexture );
// Ensure we have an aspect
if( this.getAspect() == null )
// Is the widget empty?
if( !this.hasAspect() )
{
return;
}
@@ -159,22 +173,79 @@ public class WidgetAspectSelector
// Set the blending mode to blend alpha
GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );
// Full white
// No tint
GL11.glColor3f( 1.0F, 1.0F, 1.0F );
// Get the selected aspect
AspectStack selectedStack = ( (IAspectSelectorGui)this.hostGUI ).getSelectedAspect();
Aspect selectedAspect = ( (IAspectSelectorGui)this.hostGUI ).getSelectedAspect();
// Is there a selectedStack, and does it match ours?
if( ( selectedStack != null ) && ( selectedStack.aspect == this.getAspect() ) )
// Does the selected aspect match the widgets?
if( selectedAspect == this.getAspect() )
{
this.drawHollowRectWithCorners( this.xPosition, this.yPosition, AbstractWidget.WIDGET_SIZE, AbstractWidget.WIDGET_SIZE,
// Draw the selection box
this.drawHollowRectWithCorners( this.xPosition, this.yPosition,
AbstractWidget.WIDGET_SIZE, AbstractWidget.WIDGET_SIZE,
this.getBackgroundColor(), WidgetAspectSelector.borderThickness );
}
// Draw the aspect
this.drawAspect();
// Get the amount and crafting
long stackSize = this.getAmount();
// Is there anything to draw?
if( ( ( stackSize > 0 ) && !this.hideAmount ) || this.getCraftable() )
{
// Text to draw
String text;
// Get the font renderer
final FontRenderer fontRenderer = this.hostGUI.getFontRenderer();
// Disable unicode if enabled
final boolean unicodeFlag = fontRenderer.getUnicodeFlag();
fontRenderer.setUnicodeFlag( false );
// Is the terminal using a large font?
boolean largeFont = AEConfig.instance.useTerminalUseLargeFont();
// Set the scale
float scale = largeFont ? 0.85f : 0.5f;
// Set the position offset
float positionOffset = largeFont ? 0 : -1.0f;
// Calculate position
float posX = this.xPosition + positionOffset + AbstractWidget.WIDGET_SIZE;
float posY = this.yPosition + positionOffset + AbstractWidget.WIDGET_SIZE - 1;
// Has amount to draw?
if( ( ( stackSize > 0 ) && !this.hideAmount ) )
{
text = GuiHelper.shortenCount( stackSize );
}
// Crafting
else
{
// Get the "craftable" text from AE2
if( largeFont )
{
text = appeng.core.localization.GuiText.LargeFontCraft.getLocal();
}
else
{
text = appeng.core.localization.GuiText.SmallFontCraft.getLocal();
}
}
// Draw it
GuiHelper.drawScaledText( fontRenderer, text, scale, posX, posY );
// Reset unicode status
fontRenderer.setUnicodeFlag( unicodeFlag );
}
// Enable lighting
GL11.glEnable( GL11.GL_LIGHTING );
@@ -182,72 +253,79 @@ public class WidgetAspectSelector
GL11.glDisable( GL11.GL_BLEND );
}
/**
* Gets the essentia amount for our aspect.
*
* @return
*/
public long getAmount()
{
return this.amount;
}
/**
* Gets an aspect stack matching our aspect and amount
*/
public AspectStack getAspectStackRepresentation()
{
return new AspectStack( this.getAspect(), this.amount );
}
/**
* Draws the aspect name and amount
*/
@Override
public void getTooltip( final List<String> tooltip )
{
if( ( this.getAspect() != null ) && ( this.amount > 0L ) )
if( this.hasAspect() )
{
// Add the name
tooltip.add( ThEStrings.Gui_SelectedAspect.getLocalized() + ": " + this.aspectName );
// Add the amount
tooltip.add( ThEStrings.Gui_SelectedAmount.getLocalized() + ": " + Long.toString( this.amount ) );
tooltip.add( this.aspectName );
// Add aspect info
tooltip.add( EnumChatFormatting.GRAY.toString() + this.getAspect().getLocalizedDescription() );
tooltip.add( EnumChatFormatting.GRAY.toString() + this.aspectDescription );
// Add footnote
tooltip.add( EnumChatFormatting.BLUE.toString() + EnumChatFormatting.ITALIC.toString() + this.aspectFootnote );
}
}
/**
* Called when we are clicked
* Called when the widget is clicked.
*/
@Override
public void mouseClicked()
public void onMouseClicked()
{
Aspect selected = null;
// Get this aspect
Aspect widgetAspect = this.getAspect();
// Get the selected aspect
AspectStack selectedStack = ( (IAspectSelectorGui)this.hostGUI ).getSelectedAspect();
Aspect selectedAspect = ( (IAspectSelectorGui)this.hostGUI ).getSelectedAspect();
// Does the selected aspect not match?
if( ( selectedStack == null ) || ( selectedStack.aspect != this.getAspect() ) )
// Did the selected aspect change?
boolean changed = false;
// Are both aspects the same?
if( widgetAspect == selectedAspect )
{
selected = this.getAspect();
// Is something selected?
if( selectedAspect != null )
{
// Unselect
selectedAspect = null;
changed = true;
}
}
else
{
// Set to the widget aspect
selectedAspect = widgetAspect;
changed = true;
}
( (IAspectSelectorGui)this.hostGUI ).getContainer().setSelectedAspect( selected );
// Was the selected aspect changed?
if( changed )
{
// Play clicky sound
Minecraft.getMinecraft().getSoundHandler().playSound(
PositionedSoundRecord.func_147674_a( new ResourceLocation( "gui.button.press" ), 1.0F ) );
// Set the selected aspect
( (IAspectSelectorGui)this.hostGUI ).getContainer().setSelectedAspect( selectedAspect );
}
}
/**
* Sets the essentia amount for our aspect.
* Sets whether or not to show the amount.
*
* @param amount
* @param hide
* @return
*/
public void setAmount( final long amount )
public void setHideAmount( final boolean hide )
{
this.amount = amount;
this.hideAmount = hide;
}
}
@@ -2,8 +2,9 @@ package thaumicenergistics.gui.widget;
import java.util.Comparator;
import thaumicenergistics.aspect.AspectStackComparator;
import thaumicenergistics.aspect.AspectStackComparator.ComparatorMode;
import thaumicenergistics.aspect.AspectStackComparator.AspectStackComparatorMode;
@Deprecated
public class WidgetAspectSelectorComparator
implements Comparator<WidgetAspectSelector>
{
@@ -14,7 +15,7 @@ public class WidgetAspectSelectorComparator
*/
public WidgetAspectSelectorComparator()
{
this( ComparatorMode.MODE_ALPHABETIC );
this( AspectStackComparatorMode.MODE_ALPHABETIC );
}
/**
@@ -24,7 +25,7 @@ public class WidgetAspectSelectorComparator
* @param mode
* Mode to sort by.
*/
public WidgetAspectSelectorComparator( final ComparatorMode mode )
public WidgetAspectSelectorComparator( final AspectStackComparatorMode mode )
{
// Create the internal comparator
this.internalComparator = new AspectStackComparator( mode );
@@ -34,7 +35,7 @@ public class WidgetAspectSelectorComparator
public int compare( final WidgetAspectSelector left, final WidgetAspectSelector right )
{
// Compare
return this.internalComparator.compare( left.getAspectStackRepresentation(), right.getAspectStackRepresentation() );
return this.internalComparator.compare( left.getStack(), right.getStack() );
}
}
@@ -102,14 +102,14 @@ public class WidgetAspectSlot
}
@Override
public void mouseClicked()
public void onMouseClicked()
{
// Ignored
}
public void mouseClicked( final Aspect withAspect )
{
this.setAspect( withAspect );
this.setAspect( withAspect, 1, false );
Packet_S_AspectSlot.sendAspectChange( this.part, this.id, this.getAspect(), this.player );
}
@@ -48,7 +48,7 @@ public class ThEInteractionHelper
}
@Override
public void openWirelessTerminalGui( final EntityPlayer player, final IThEWirelessEssentiaTerminal terminalInterface )
public void openWirelessTerminalGui( final EntityPlayer player )
{
// Valid player?
if( ( player == null ) || ( player instanceof FakePlayer ) )
@@ -72,6 +72,16 @@ public class ThEInteractionHelper
return;
}
// Ensure the stack's item implements the wireless interface
if( !( wirelessTerminal.getItem() instanceof IThEWirelessEssentiaTerminal ) )
{
// Invalid item.
return;
}
// Get the interface
IThEWirelessEssentiaTerminal terminalInterface = (IThEWirelessEssentiaTerminal)wirelessTerminal.getItem();
// Ensure the terminal has power
if( terminalInterface.getAECurrentPower( wirelessTerminal ) == 0 )
{
@@ -11,8 +11,8 @@ import java.util.Set;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.api.networking.IEssentiaGrid;
import thaumicenergistics.aspect.AspectStack;
import thaumicenergistics.grid.IEssentiaGrid;
import thaumicenergistics.grid.IMEEssentiaMonitor;
import thaumicenergistics.grid.IMEEssentiaMonitorReceiver;
import thaumicenergistics.tileentities.TileEssentiaProvider;
@@ -8,13 +8,15 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.Fluid;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.aspect.AspectStack;
import thaumicenergistics.aspect.AspectStackComparator.ComparatorMode;
import thaumicenergistics.aspect.AspectStackComparator.AspectStackComparatorMode;
import thaumicenergistics.fluids.GaseousEssentia;
import thaumicenergistics.integration.tc.EssentiaConversionHelper;
import thaumicenergistics.items.ItemEssentiaCell;
import thaumicenergistics.registries.EnumCache;
import thaumicenergistics.registries.ItemEnum;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.config.ViewItems;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.MachineSource;
import appeng.api.storage.IMEInventoryHandler;
@@ -31,14 +33,28 @@ public class HandlerItemEssentiaCell
/**
* NBT Keys
*/
private static final String NBT_ESSENTIA_NUMBER_KEY = "Essentia#", NBT_SORT_KEY = "SortMode", NBT_PARTITION_KEY = "Partitions",
NBT_PARTITION_COUNT_KEY = "PartitionCount", NBT_PARTITION_NUMBER_KEY = "Partition#";
private static final String NBT_ESSENTIA_NUMBER_KEY = "Essentia#",
NBT_SORT_KEY = "SortMode",
NBT_PARTITION_KEY = "Partitions",
NBT_PARTITION_COUNT_KEY = "PartitionCount",
NBT_PARTITION_NUMBER_KEY = "Partition#",
NBT_KEY_VIEW_MODE = "ViewMode";
/**
* Controls how many essentia can fit in a single byte.
*/
private static final long ESSENTIA_PER_BYTE = 2;
/**
* Default sort mode.
*/
private static final AspectStackComparatorMode DEFAULT_SORT_MODE = AspectStackComparatorMode.MODE_ALPHABETIC;
/**
* Default view mode.
*/
private static final ViewItems DEFAULT_VIEW_MODE = ViewItems.ALL;
/**
* Stores cell data
*/
@@ -72,7 +88,12 @@ public class HandlerItemEssentiaCell
/**
* Sorting mode when used in ME chest.
*/
private ComparatorMode sortMode;
private AspectStackComparatorMode sortMode = DEFAULT_SORT_MODE;
/**
* View mode.
*/
private ViewItems viewMode = DEFAULT_VIEW_MODE;
/**
* Who do we tell we have changed?
@@ -293,11 +314,13 @@ public class HandlerItemEssentiaCell
// Load the sort mode
if( this.cellData.hasKey( HandlerItemEssentiaCell.NBT_SORT_KEY ) )
{
this.sortMode = ComparatorMode.VALUES[this.cellData.getInteger( HandlerItemEssentiaCell.NBT_SORT_KEY )];
this.sortMode = AspectStackComparatorMode.VALUES[this.cellData.getInteger( NBT_SORT_KEY )];
}
else
// Load view mode
if( this.cellData.hasKey( NBT_KEY_VIEW_MODE ) )
{
this.sortMode = ComparatorMode.MODE_ALPHABETIC;
this.viewMode = EnumCache.AE_VIEW_ITEMS[this.cellData.getInteger( NBT_KEY_VIEW_MODE )];
}
// Load partition list
@@ -623,7 +646,7 @@ public class HandlerItemEssentiaCell
*
* @return
*/
public ComparatorMode getSortingMode()
public AspectStackComparatorMode getSortingMode()
{
return this.sortMode;
}
@@ -703,6 +726,16 @@ public class HandlerItemEssentiaCell
return typeCount;
}
/**
* Gets the view mode.
*
* @return
*/
public ViewItems getViewMode()
{
return this.viewMode;
}
/**
* Attempts to add essentia gas to the cell.
* returns the number of items not added.
@@ -892,13 +925,33 @@ public class HandlerItemEssentiaCell
*
* @param sortMode
*/
public void setSortingMode( final ComparatorMode sortMode )
public void setSortingMode( final AspectStackComparatorMode sortMode )
{
// Store the mode
this.cellData.setInteger( HandlerItemEssentiaCell.NBT_SORT_KEY, sortMode.ordinal() );
// Set the mode
this.sortMode = sortMode;
// Store the mode
if( this.sortMode != DEFAULT_SORT_MODE )
{
this.cellData.setInteger( NBT_SORT_KEY, sortMode.ordinal() );
}
}
/**
* Sets the view mode.
*
* @param viewMode
*/
public void setViewMode( final ViewItems viewMode )
{
// Set the mode
this.viewMode = viewMode;
// Store the mode
if( this.viewMode != DEFAULT_VIEW_MODE )
{
this.cellData.setInteger( NBT_KEY_VIEW_MODE, this.viewMode.ordinal() );
}
}
/**
@@ -4,14 +4,23 @@ import java.util.Set;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import thaumicenergistics.api.IThEWirelessEssentiaTerminal;
import thaumicenergistics.aspect.AspectStackComparator.ComparatorMode;
import thaumicenergistics.api.ThEApi;
import thaumicenergistics.api.networking.IEssentiaGrid;
import thaumicenergistics.api.storage.ICraftingIssuerHost;
import thaumicenergistics.aspect.AspectStackComparator.AspectStackComparatorMode;
import thaumicenergistics.grid.EssentiaPassThroughMonitor;
import thaumicenergistics.grid.IEssentiaGrid;
import thaumicenergistics.grid.IMEEssentiaMonitor;
import thaumicenergistics.items.ItemWirelessEssentiaTerminal;
import thaumicenergistics.network.packet.server.Packet_S_ChangeGui;
import thaumicenergistics.registries.EnumCache;
import thaumicenergistics.registries.ItemEnum;
import thaumicenergistics.util.EffectiveSide;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.ViewItems;
import appeng.api.implementations.guiobjects.IGuiItemObject;
import appeng.api.implementations.tiles.IWirelessAccessPoint;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
@@ -19,12 +28,21 @@ import appeng.api.networking.IGridStorage;
import appeng.api.networking.IMachineSet;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.PlayerSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.AECableType;
import appeng.api.util.DimensionalCoord;
import appeng.api.util.IConfigManager;
import appeng.core.AEConfig;
import appeng.tile.networking.TileWireless;
public class HandlerWirelessEssentiaTerminal
implements IActionHost, ICraftingIssuerHost, ITerminalHost, IGuiItemObject
{
/**
* Redirects power requests to the wireless terminal.
@@ -160,12 +178,15 @@ public class HandlerWirelessEssentiaTerminal
}
private static final String NBT_KEY_SORTING_MODE = "SortingMode";
/**
* NBT Keys
*/
private static final String NBT_KEY_SORTING_MODE = "SortingMode2", NBT_KEY_VIEW_MODE = "ViewMode";
/**
* Wireless terminal.
*/
private IThEWirelessEssentiaTerminal wirelessTerminal;
private final IThEWirelessEssentiaTerminal wirelessTerminal;
/**
* Access point used to communicate with the AE network.
@@ -196,7 +217,7 @@ public class HandlerWirelessEssentiaTerminal
/**
* The itemstack that represents this terminal.
*/
private ItemStack wirelessItemstack;
final private ItemStack wirelessItemstack;
/**
* How much to multiply the required power by.
@@ -204,7 +225,8 @@ public class HandlerWirelessEssentiaTerminal
private double wirelessPowerMultiplier = 1.0D;
public HandlerWirelessEssentiaTerminal( final EntityPlayer player, final IWirelessAccessPoint accessPoint,
final IThEWirelessEssentiaTerminal wirelessTerminalInterface, final ItemStack wirelessTerminalItemstack )
final IThEWirelessEssentiaTerminal wirelessTerminalInterface,
final ItemStack wirelessTerminalItemstack )
{
// Set the player
this.player = player;
@@ -284,8 +306,12 @@ public class HandlerWirelessEssentiaTerminal
*/
private boolean isAPInRangeAndActive()
{
return( ( this.accessPoint.isActive() ) && ( HandlerWirelessEssentiaTerminal.isAPInRangeOfPlayer( this.locationOfAccessPoint,
this.rangeOfAccessPoint, this.player ) ) );
if( this.accessPoint != null )
{
return( ( this.accessPoint.isActive() ) && ( HandlerWirelessEssentiaTerminal.isAPInRangeOfPlayer( this.locationOfAccessPoint,
this.rangeOfAccessPoint, this.player ) ) );
}
return false;
}
/**
@@ -297,6 +323,11 @@ public class HandlerWirelessEssentiaTerminal
{
// Set the access point
this.accessPoint = accessPoint;
if( accessPoint == null )
{
// Most likely on the client side.
return;
}
// Get the range of the access point
this.rangeOfAccessPoint = this.accessPoint.getRange();
@@ -348,6 +379,16 @@ public class HandlerWirelessEssentiaTerminal
return extractedAmount;
}
@Override
public IGridNode getActionableNode()
{
if( this.accessPoint != null )
{
return this.accessPoint.getActionableNode();
}
return null;
}
/**
* Gets the the player source used when interacting with the network.
*
@@ -358,6 +399,19 @@ public class HandlerWirelessEssentiaTerminal
return this.playerSource;
}
@Override
public AECableType getCableConnectionType( final ForgeDirection dir )
{
return AECableType.NONE;
}
@Override
public IConfigManager getConfigManager()
{
// Ignored.
return null;
}
/**
* Gets the essentia monitor.
*
@@ -365,6 +419,11 @@ public class HandlerWirelessEssentiaTerminal
*/
public IMEEssentiaMonitor getEssentiaMonitor()
{
if( this.accessPoint == null )
{
return null;
}
try
{
// Get the network essentia monitor
@@ -383,23 +442,89 @@ public class HandlerWirelessEssentiaTerminal
}
}
@Override
public IMEMonitor<IAEFluidStack> getFluidInventory()
{
if( this.accessPoint == null )
{
return null;
}
try
{
// Get the storage grid
IStorageGrid storageGrid = this.accessPoint.getActionableNode().getGrid().getCache( IStorageGrid.class );
// Return the monitor
return storageGrid.getFluidInventory();
}
catch( Exception e )
{
// Ignored
}
return null;
}
@Override
public IGridNode getGridNode( final ForgeDirection dir )
{
return this.getActionableNode();
}
@Override
public ItemStack getIcon()
{
return ItemEnum.WIRELESS_TERMINAL.getStack();
}
@Override
public IMEMonitor<IAEItemStack> getItemInventory()
{
if( this.accessPoint == null )
{
return null;
}
try
{
// Get the storage grid
IStorageGrid storageGrid = this.accessPoint.getActionableNode().getGrid().getCache( IStorageGrid.class );
// Return the monitor
return storageGrid.getItemInventory();
}
catch( Exception e )
{
// Ignored
}
return null;
}
@Override
public ItemStack getItemStack()
{
return this.wirelessItemstack;
}
/**
* Gets the terminals sorting mode.
*
* @return
*/
public ComparatorMode getSortingMode()
public AspectStackComparatorMode getSortingMode()
{
// Get the data tag
NBTTagCompound dataTagCompound = this.wirelessTerminal.getWETerminalTag( this.wirelessItemstack );
// Does the tag have the sorting mode stored?
if( dataTagCompound.hasKey( HandlerWirelessEssentiaTerminal.NBT_KEY_SORTING_MODE ) )
// Does the tag have the mode stored?
if( dataTagCompound.hasKey( NBT_KEY_SORTING_MODE ) )
{
return ComparatorMode.valueOf( dataTagCompound.getString( HandlerWirelessEssentiaTerminal.NBT_KEY_SORTING_MODE ) );
return AspectStackComparatorMode.VALUES[dataTagCompound.getInteger( NBT_KEY_SORTING_MODE )];
}
return ComparatorMode.MODE_ALPHABETIC;
return AspectStackComparatorMode.MODE_ALPHABETIC;
}
/**
@@ -412,6 +537,21 @@ public class HandlerWirelessEssentiaTerminal
return this.wirelessItemstack;
}
public ViewItems getViewMode()
{
// Get the data tag
NBTTagCompound dataTagCompound = this.wirelessTerminal.getWETerminalTag( this.wirelessItemstack );
// Does the tag have the mode stored?
if( dataTagCompound.hasKey( NBT_KEY_VIEW_MODE ) )
{
return EnumCache.AE_VIEW_ITEMS[dataTagCompound.getInteger( NBT_KEY_VIEW_MODE )];
}
return ViewItems.ALL;
}
/**
* Returns true if the terminal has power.
*
@@ -429,6 +569,11 @@ public class HandlerWirelessEssentiaTerminal
*/
public boolean isConnected()
{
if( this.accessPoint == null )
{
return false;
}
// Does the terminal have power?
if( !this.hasPower() )
{
@@ -477,18 +622,47 @@ public class HandlerWirelessEssentiaTerminal
return false;
}
@Override
public void launchGUI( final EntityPlayer player )
{
if( EffectiveSide.isClientSide() )
{
// Ask server to change GUI's
Packet_S_ChangeGui.sendGuiChangeToWirelessTerminal( player );
}
else
{
// Open the gui
ThEApi.instance().interact().openWirelessTerminalGui( player );
}
}
@Override
public void securityBreak()
{
}
/**
* Sets the terminals sorting mode.
*
* @param mode
*/
public void setSortingMode( final ComparatorMode mode )
public void setSortingMode( final AspectStackComparatorMode mode )
{
// Get the data tag
NBTTagCompound dataTag = this.wirelessTerminal.getWETerminalTag( this.wirelessItemstack );
// Set the sorting mode
dataTag.setString( HandlerWirelessEssentiaTerminal.NBT_KEY_SORTING_MODE, mode.name() );
dataTag.setInteger( NBT_KEY_SORTING_MODE, mode.ordinal() );
}
public void setViewMode( final ViewItems viewMode )
{
// Get the data tag
NBTTagCompound dataTag = this.wirelessTerminal.getWETerminalTag( this.wirelessItemstack );
// Set the viewing mode
dataTag.setInteger( NBT_KEY_VIEW_MODE, viewMode.ordinal() );
}
/**
@@ -13,6 +13,7 @@ import net.minecraft.util.StatCollector;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.common.Thaumcraft;
import thaumicenergistics.ThaumicEnergistics;
import thaumicenergistics.registries.ItemEnum;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -43,27 +44,60 @@ public class ItemCraftingAspect
}
/**
* Gets the aspect associated with the item
* Creates a new crafting aspect stack with the specified amount.
*
* @param itemstack
* @param aspect
* @param amount
* @return
*/
public static Aspect getAspect( final ItemStack itemstack )
public static ItemStack createStackForAspect( final Aspect aspect, final int amount )
{
if( itemstack.hasTagCompound() )
{
// Get the tag
NBTTagCompound tag = itemstack.getTagCompound();
// Create the stack
ItemStack stack = ItemEnum.CRAFTING_ASPECT.getStack( amount );
if( tag.hasKey( NBTKEY_ASPECT ) )
{
// Get the aspect
return Aspect.getAspect( tag.getString( NBTKEY_ASPECT ) );
}
// Set the aspect
setAspect( stack, aspect );
return stack;
}
/**
* Gets the aspect associated with the item.
*
* @param itemStack
* @return
*/
public static Aspect getAspect( final ItemStack itemStack )
{
if( itemStack == null )
{
return null;
}
return getAspect( itemStack.getTagCompound() );
}
/**
* Gets the aspect stored in the crafting items tag.
*
* @param tag
* @return
*/
public static Aspect getAspect( final NBTTagCompound tag )
{
if( ( tag != null ) && tag.hasKey( NBTKEY_ASPECT ) )
{
// Get the aspect
return Aspect.getAspect( tag.getString( NBTKEY_ASPECT ) );
}
return null;
}
/**
* Sets the aspect of the item stack.
*
* @param stack
* @param aspect
*/
public static void setAspect( final ItemStack stack, final Aspect aspect )
{
// Null check
@@ -136,7 +136,7 @@ public class ItemWirelessEssentiaTerminal
public ItemStack onItemRightClick( final ItemStack itemStack, final World world, final EntityPlayer player )
{
// Open the gui
ThEApi.instance().interact().openWirelessTerminalGui( player, this );
ThEApi.instance().interact().openWirelessTerminalGui( player );
return itemStack;
@@ -2,17 +2,19 @@ package thaumicenergistics.network.packet.client;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.List;
import java.util.Collection;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.entity.player.EntityPlayer;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.aspect.AspectStack;
import thaumicenergistics.aspect.AspectStackComparator.ComparatorMode;
import thaumicenergistics.aspect.AspectStackComparator.AspectStackComparatorMode;
import thaumicenergistics.gui.GuiEssentiaCellTerminal;
import thaumicenergistics.network.NetworkHandler;
import thaumicenergistics.network.packet.ThEBasePacket;
import thaumicenergistics.network.packet.ThEClientPacket;
import thaumicenergistics.registries.EnumCache;
import appeng.api.config.ViewItems;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -21,13 +23,14 @@ public class Packet_C_EssentiaCellTerminal
{
private static final byte MODE_FULL_LIST = 0;
private static final byte MODE_SELECTED_ASPECT = 1;
private static final byte MODE_SORT_MODE_CHANGED = 2;
private static final byte MODE_VIEWING_CHANGED = 2;
private static final byte MODE_LIST_CHANGED = 3;
private List<AspectStack> aspectStackList;
private Collection<AspectStack> aspectStackList;
private Aspect selectedAspect;
private ComparatorMode sortMode;
private AspectStackComparatorMode sortMode;
private AspectStack change;
private ViewItems viewMode;
/**
* Creates the packet
@@ -54,7 +57,7 @@ public class Packet_C_EssentiaCellTerminal
* @param player
* @param list
*/
public static void sendFullList( final EntityPlayer player, final List<AspectStack> list )
public static void sendFullList( final EntityPlayer player, final Collection<AspectStack> list )
{
Packet_C_EssentiaCellTerminal packet = newPacket( player, MODE_FULL_LIST );
// Set the player
@@ -69,6 +72,26 @@ public class Packet_C_EssentiaCellTerminal
NetworkHandler.sendPacketToClient( packet );
}
/**
* Sends the viewing modes.
*
* @param player
* @param sortMode
*/
public static void sendViewingModes( final EntityPlayer player, final AspectStackComparatorMode sortMode, final ViewItems viewMode )
{
Packet_C_EssentiaCellTerminal packet = newPacket( player, MODE_VIEWING_CHANGED );
// Set the sort mode
packet.sortMode = sortMode;
// Set the view mode
packet.viewMode = viewMode;
// Send it
NetworkHandler.sendPacketToClient( packet );
}
/**
* Called when an aspect amount changes.
*
@@ -103,23 +126,6 @@ public class Packet_C_EssentiaCellTerminal
NetworkHandler.sendPacketToClient( packet );
}
/**
* Sends the sorting mode.
*
* @param player
* @param sortMode
*/
public static void setSortMode( final EntityPlayer player, final ComparatorMode sortMode )
{
Packet_C_EssentiaCellTerminal packet = newPacket( player, MODE_SORT_MODE_CHANGED );
// Set the sort mode
packet.sortMode = sortMode;
// Send it
NetworkHandler.sendPacketToClient( packet );
}
@SideOnly(Side.CLIENT)
@Override
protected void wrappedExecute()
@@ -138,9 +144,9 @@ public class Packet_C_EssentiaCellTerminal
( (GuiEssentiaCellTerminal)gui ).onReceiveSelectedAspect( this.selectedAspect );
break;
case Packet_C_EssentiaCellTerminal.MODE_SORT_MODE_CHANGED:
// Update the sorting mode
( (GuiEssentiaCellTerminal)gui ).onSortModeChanged( this.sortMode );
case Packet_C_EssentiaCellTerminal.MODE_VIEWING_CHANGED:
// Update the modes
( (GuiEssentiaCellTerminal)gui ).onViewingModesChanged( this.sortMode, this.viewMode );
break;
case Packet_C_EssentiaCellTerminal.MODE_LIST_CHANGED:
@@ -160,24 +166,27 @@ public class Packet_C_EssentiaCellTerminal
case Packet_C_EssentiaCellTerminal.MODE_FULL_LIST:
this.aspectStackList = new ArrayList<AspectStack>();
// Read each stack
while( stream.readableBytes() > 0 )
{
this.aspectStackList.add( new AspectStack( ThEBasePacket.readAspect( stream ), stream.readLong() ) );
this.aspectStackList.add( AspectStack.loadAspectStackFromStream( stream ) );
}
break;
case Packet_C_EssentiaCellTerminal.MODE_SELECTED_ASPECT:
// Read aspect
this.selectedAspect = ThEBasePacket.readAspect( stream );
break;
case Packet_C_EssentiaCellTerminal.MODE_SORT_MODE_CHANGED:
// Read the mode ordinal
this.sortMode = ComparatorMode.VALUES[stream.readInt()];
case Packet_C_EssentiaCellTerminal.MODE_VIEWING_CHANGED:
// Read the mode ordinals
this.sortMode = AspectStackComparatorMode.VALUES[stream.readInt()];
this.viewMode = EnumCache.AE_VIEW_ITEMS[stream.readInt()];
break;
case Packet_C_EssentiaCellTerminal.MODE_LIST_CHANGED:
// Read the stack
this.change = new AspectStack( ThEBasePacket.readAspect( stream ), stream.readLong() );
this.change = AspectStack.loadAspectStackFromStream( stream );
}
}
@@ -188,29 +197,27 @@ public class Packet_C_EssentiaCellTerminal
switch ( this.mode )
{
case Packet_C_EssentiaCellTerminal.MODE_FULL_LIST:
// Write each stack
for( AspectStack stack : this.aspectStackList )
{
ThEBasePacket.writeAspect( stack.aspect, stream );
stream.writeLong( stack.stackSize );
stack.writeToStream( stream );
}
break;
case Packet_C_EssentiaCellTerminal.MODE_SELECTED_ASPECT:
// Write aspect
ThEBasePacket.writeAspect( this.selectedAspect, stream );
break;
case Packet_C_EssentiaCellTerminal.MODE_SORT_MODE_CHANGED:
// Write the mode ordinal
case Packet_C_EssentiaCellTerminal.MODE_VIEWING_CHANGED:
// Write the mode ordinals
stream.writeInt( this.sortMode.ordinal() );
stream.writeInt( this.viewMode.ordinal() );
break;
case Packet_C_EssentiaCellTerminal.MODE_LIST_CHANGED:
// Write the aspect
ThEBasePacket.writeAspect( this.change.aspect, stream );
// Write the amount
stream.writeLong( this.change.stackSize );
// Write the stack
this.change.writeToStream( stream );
}
}
}
@@ -3,6 +3,7 @@ package thaumicenergistics.network.packet.server;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import thaumicenergistics.api.ThEApi;
import thaumicenergistics.gui.ThEGuiHandler;
import thaumicenergistics.network.NetworkHandler;
import thaumicenergistics.network.packet.ThEBasePacket;
@@ -12,8 +13,12 @@ import thaumicenergistics.parts.AbstractAEPartBase;
public class Packet_S_ChangeGui
extends ThEServerPacket
{
private static final byte MODE_REGULAR = 0;
private static final byte MODE_PART = 1;
/**
* Packet modes
*/
private static final byte MODE_REGULAR = 0,
MODE_PART = 1,
MODE_WIRELESS = 2;
private int guiID;
private AbstractAEPartBase part;
@@ -41,26 +46,6 @@ public class Packet_S_ChangeGui
return packet;
}
public static void sendGuiChange( final AbstractAEPartBase part, final EntityPlayer player, final World world, final int x,
final int y, final int z )
{
Packet_S_ChangeGui packet = newPacket( player, MODE_PART );
// Set the part
packet.part = part;
// Set the world
packet.world = world;
// Set the coords
packet.x = x;
packet.y = y;
packet.z = z;
// Send it
NetworkHandler.sendPacketToServer( packet );
}
public static void sendGuiChange( final int guiID, final EntityPlayer player, final World world, final int x, final int y,
final int z )
{
@@ -81,18 +66,53 @@ public class Packet_S_ChangeGui
NetworkHandler.sendPacketToServer( packet );
}
public static void sendGuiChangeToPart( final AbstractAEPartBase part, final EntityPlayer player, final World world, final int x,
final int y, final int z )
{
Packet_S_ChangeGui packet = newPacket( player, MODE_PART );
// Set the part
packet.part = part;
// Set the world
packet.world = world;
// Set the coords
packet.x = x;
packet.y = y;
packet.z = z;
// Send it
NetworkHandler.sendPacketToServer( packet );
}
public static void sendGuiChangeToWirelessTerminal( final EntityPlayer player )
{
Packet_S_ChangeGui packet = newPacket( player, MODE_WIRELESS );
// Send it
NetworkHandler.sendPacketToServer( packet );
}
@Override
public void execute()
{
if( this.mode == Packet_S_ChangeGui.MODE_REGULAR )
switch ( this.mode )
{
case MODE_REGULAR:
// Launch regular
ThEGuiHandler.launchGui( this.guiID, this.player, this.world, this.x, this.y, this.z );
}
else if( this.mode == Packet_S_ChangeGui.MODE_PART )
{
break;
case MODE_PART:
// Launch part
ThEGuiHandler.launchGui( this.part, this.player, this.world, this.x, this.y, this.z );
break;
case MODE_WIRELESS:
// Launch wireless
ThEApi.instance().interact().openWirelessTerminalGui( this.player );
break;
}
}
@@ -100,47 +120,52 @@ public class Packet_S_ChangeGui
@Override
public void readData( final ByteBuf stream )
{
if( this.mode == Packet_S_ChangeGui.MODE_REGULAR )
if( this.mode != MODE_WIRELESS )
{
// Read the ID
this.guiID = stream.readInt();
}
else if( this.mode == Packet_S_ChangeGui.MODE_PART )
{
// Read the part
this.part = ThEBasePacket.readPart( stream );
}
if( this.mode == MODE_REGULAR )
{
// Read the ID
this.guiID = stream.readInt();
}
else if( this.mode == MODE_PART )
{
// Read the part
this.part = ThEBasePacket.readPart( stream );
}
// Read the world
this.world = ThEBasePacket.readWorld( stream );
// Read the world
this.world = ThEBasePacket.readWorld( stream );
// Read the coords
this.x = stream.readInt();
this.y = stream.readInt();
this.z = stream.readInt();
// Read the coords
this.x = stream.readInt();
this.y = stream.readInt();
this.z = stream.readInt();
}
}
@Override
public void writeData( final ByteBuf stream )
{
if( this.mode == Packet_S_ChangeGui.MODE_REGULAR )
if( this.mode != MODE_WIRELESS )
{
// Write the ID
stream.writeInt( this.guiID );
}
else if( this.mode == Packet_S_ChangeGui.MODE_PART )
{
// Write the part
ThEBasePacket.writePart( this.part, stream );
}
if( this.mode == MODE_REGULAR )
{
// Write the ID
stream.writeInt( this.guiID );
}
else if( this.mode == MODE_PART )
{
// Write the part
ThEBasePacket.writePart( this.part, stream );
}
// Write the world
ThEBasePacket.writeWorld( this.world, stream );
// Write the world
ThEBasePacket.writeWorld( this.world, stream );
// Write the coords
stream.writeInt( this.x );
stream.writeInt( this.y );
stream.writeInt( this.z );
// Write the coords
stream.writeInt( this.x );
stream.writeInt( this.y );
stream.writeInt( this.z );
}
}
}
@@ -3,7 +3,6 @@ package thaumicenergistics.network.packet.server;
import io.netty.buffer.ByteBuf;
import java.util.concurrent.Future;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import thaumicenergistics.gui.ThEGuiHandler;
import thaumicenergistics.network.NetworkHandler;
@@ -108,12 +107,10 @@ public class Packet_S_ConfirmCraftingJob
final ContainerOpenContext context = cca.getOpenContext();
if( context != null )
{
final TileEntity te = context.getTile();
// Begin Thaumic Energistics Changes ===============================
// Begin Thaumic Energistics Changes ===============================
int GUI_ID = ThEGuiHandler.generateSidedID( ThEGuiHandler.AUTO_CRAFTING_CONFIRM, context.getSide() );
ThEGuiHandler.launchGui( ThEGuiHandler.AUTO_CRAFTING_CONFIRM, this.player, this.player.worldObj, 0, 0, 0 );
ThEGuiHandler.launchGui( GUI_ID, this.player, te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord );
// End Thaumic Energistics Changes ===============================
if( this.player.openContainer instanceof ContainerCraftConfirm )
@@ -3,7 +3,6 @@ package thaumicenergistics.network.packet.server;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.aspect.AspectStackComparator.ComparatorMode;
import thaumicenergistics.container.AbstractContainerCellTerminalBase;
import thaumicenergistics.network.NetworkHandler;
import thaumicenergistics.network.packet.ThEBasePacket;
@@ -12,12 +11,24 @@ import thaumicenergistics.network.packet.ThEServerPacket;
public class Packet_S_EssentiaCellTerminal
extends ThEServerPacket
{
private static final byte MODE_SELECTED_ASPECT = 0;
private static final byte MODE_FULL_UPDATE = 1;
private static final byte MODE_SORT_CHANGE = 2;
/**
* Packet modes
*/
private static final byte MODE_SELECTED_ASPECT = 0,
MODE_FULL_UPDATE = 1,
MODE_SORT_CHANGE = 2,
MODE_AUTO_CRAFT = 3,
MODE_VIEW_CHANGE = 4;
private Aspect currentAspect;
private ComparatorMode sortMode;
/**
* The aspect.
*/
private Aspect selectedAspect;
/**
* Boolean flag. What more needs to be said :P
*/
private Boolean flag;
/**
* Creates the packet
@@ -38,31 +49,85 @@ public class Packet_S_EssentiaCellTerminal
return packet;
}
/**
* Asks the server to begin a crafting job for the specified aspect.
*
* @param player
* @param aspect
*/
public static void sendAutoCraft( final EntityPlayer player, final Aspect aspect )
{
// Create the packet
Packet_S_EssentiaCellTerminal packet = newPacket( player, MODE_AUTO_CRAFT );
// Set the aspect
packet.selectedAspect = aspect;
// Send it
NetworkHandler.sendPacketToServer( packet );
}
/**
* Asks the server to change the sorting mode.
*
* @param player
*/
public static void sendChangeSorting( final EntityPlayer player, final boolean wasRightClick )
{
// Create the packet
Packet_S_EssentiaCellTerminal packet = newPacket( player, MODE_SORT_CHANGE );
// Set the flag
packet.flag = wasRightClick;
// Send it
NetworkHandler.sendPacketToServer( packet );
}
/**
* Asks the server to change the view mode.
*
* @param player
*/
public static void sendChangeView( final EntityPlayer player, final boolean wasRightClick )
{
// Create the packet
Packet_S_EssentiaCellTerminal packet = newPacket( player, MODE_VIEW_CHANGE );
// Set the flag
packet.flag = wasRightClick;
// Send it
NetworkHandler.sendPacketToServer( packet );
}
/**
* Requests a full update from the server.
*
* @param player
*/
public static void sendFullUpdateRequest( final EntityPlayer player )
{
// Create the packet
Packet_S_EssentiaCellTerminal packet = newPacket( player, MODE_FULL_UPDATE );
// Send it
NetworkHandler.sendPacketToServer( packet );
}
/**
* Informs the server the player has (un)selected an aspect.
*
* @param player
* @param currentAspect
*/
public static void sendSelectedAspect( final EntityPlayer player, final Aspect currentAspect )
{
// Create the packet
Packet_S_EssentiaCellTerminal packet = newPacket( player, MODE_SELECTED_ASPECT );
// Set the current aspect
packet.currentAspect = currentAspect;
// Send it
NetworkHandler.sendPacketToServer( packet );
}
public static void sendSortMode( final EntityPlayer player, final ComparatorMode sortMode )
{
Packet_S_EssentiaCellTerminal packet = newPacket( player, MODE_SORT_CHANGE );
// Set the sort mode
packet.sortMode = sortMode;
packet.selectedAspect = currentAspect;
// Send it
NetworkHandler.sendPacketToServer( packet );
@@ -71,27 +136,33 @@ public class Packet_S_EssentiaCellTerminal
@Override
public void execute()
{
// Sanity checks
if( ( this.player == null ) || !( this.player.openContainer instanceof AbstractContainerCellTerminalBase ) )
{
return;
}
switch ( this.mode )
{
case Packet_S_EssentiaCellTerminal.MODE_SELECTED_ASPECT:
if( ( this.player != null ) && ( this.player.openContainer instanceof AbstractContainerCellTerminalBase ) )
{
( (AbstractContainerCellTerminalBase)this.player.openContainer ).onReceivedSelectedAspect( this.currentAspect );
}
case MODE_SELECTED_ASPECT:
( (AbstractContainerCellTerminalBase)this.player.openContainer ).onReceivedSelectedAspect( this.selectedAspect );
break;
case Packet_S_EssentiaCellTerminal.MODE_FULL_UPDATE:
if( ( this.player != null ) && ( this.player.openContainer instanceof AbstractContainerCellTerminalBase ) )
{
( (AbstractContainerCellTerminalBase)this.player.openContainer ).onClientRequestFullUpdate();
}
case MODE_FULL_UPDATE:
( (AbstractContainerCellTerminalBase)this.player.openContainer ).onClientRequestFullUpdate();
break;
case Packet_S_EssentiaCellTerminal.MODE_SORT_CHANGE:
if( ( this.player != null ) && ( this.player.openContainer instanceof AbstractContainerCellTerminalBase ) )
{
( (AbstractContainerCellTerminalBase)this.player.openContainer ).onClientRequestSortModeChange( this.sortMode, this.player );
}
case MODE_SORT_CHANGE:
( (AbstractContainerCellTerminalBase)this.player.openContainer ).onClientRequestSortModeChange( this.player, this.flag );
break;
case MODE_AUTO_CRAFT:
( (AbstractContainerCellTerminalBase)this.player.openContainer ).onClientRequestAutoCraft( this.player, this.selectedAspect );
break;
case MODE_VIEW_CHANGE:
( (AbstractContainerCellTerminalBase)this.player.openContainer ).onClientRequestViewModeChange( this.player, this.flag );
break;
}
}
@@ -99,17 +170,17 @@ public class Packet_S_EssentiaCellTerminal
@Override
public void readData( final ByteBuf stream )
{
switch ( this.mode )
{
case Packet_S_EssentiaCellTerminal.MODE_SELECTED_ASPECT:
this.currentAspect = ThEBasePacket.readAspect( stream );
case MODE_SELECTED_ASPECT:
case MODE_AUTO_CRAFT:
// Read the aspect
this.selectedAspect = ThEBasePacket.readAspect( stream );
break;
case Packet_S_EssentiaCellTerminal.MODE_SORT_CHANGE:
// Read the mode ordinal
this.sortMode = ComparatorMode.VALUES[stream.readInt()];
case MODE_SORT_CHANGE:
case MODE_VIEW_CHANGE:
this.flag = stream.readBoolean();
break;
}
}
@@ -117,17 +188,18 @@ public class Packet_S_EssentiaCellTerminal
@Override
public void writeData( final ByteBuf stream )
{
switch ( this.mode )
{
case Packet_S_EssentiaCellTerminal.MODE_SELECTED_ASPECT:
ThEBasePacket.writeAspect( this.currentAspect, stream );
case MODE_SELECTED_ASPECT:
case MODE_AUTO_CRAFT:
// Write the aspect
ThEBasePacket.writeAspect( this.selectedAspect, stream );
break;
case Packet_S_EssentiaCellTerminal.MODE_SORT_CHANGE:
// Write the mode ordinal
stream.writeInt( this.sortMode.ordinal() );
case MODE_SORT_CHANGE:
case MODE_VIEW_CHANGE:
// Write the flag
stream.writeBoolean( this.flag );
break;
}
}
@@ -18,7 +18,7 @@ import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.common.items.wands.ItemWandCasting;
import thaumicenergistics.ThaumicEnergistics;
import thaumicenergistics.api.ICraftingIssuerTerminalHost;
import thaumicenergistics.api.storage.ICraftingIssuerHost;
import thaumicenergistics.container.ContainerPartArcaneCraftingTerminal;
import thaumicenergistics.gui.GuiArcaneCraftingTerminal;
import thaumicenergistics.gui.ThEGuiHandler;
@@ -44,6 +44,7 @@ import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartRenderHelper;
import appeng.api.parts.PartItemStack;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.AEColor;
@@ -54,7 +55,7 @@ import cpw.mods.fml.relauncher.SideOnly;
public class AEPartArcaneCraftingTerminal
extends AbstractAEPartRotateable
implements IInventory, IGridTickable, ICraftingIssuerTerminalHost
implements IInventory, IGridTickable, ICraftingIssuerHost, ITerminalHost
{
/**
* Number of slots in the internal inventory
@@ -309,7 +310,7 @@ public class AEPartArcaneCraftingTerminal
@Override
public IConfigManager getConfigManager()
{
// NOTE: Ignored
// NOTE: Ignored, should it be?
return null;
}
@@ -572,7 +573,7 @@ public class AEPartArcaneCraftingTerminal
else
{
// Ask the server to change the GUI
Packet_S_ChangeGui.sendGuiChange( this, player, host.getWorldObj(), host.xCoord, host.yCoord, host.zCoord );
Packet_S_ChangeGui.sendGuiChangeToPart( this, player, host.getWorldObj(), host.xCoord, host.yCoord, host.zCoord );
}
}
@@ -15,9 +15,9 @@ import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.api.networking.IEssentiaWatcher;
import thaumicenergistics.api.networking.IEssentiaWatcherHost;
import thaumicenergistics.container.ContainerPartEssentiaLevelEmitter;
import thaumicenergistics.grid.IEssentiaWatcher;
import thaumicenergistics.grid.IEssentiaWatcherHost;
import thaumicenergistics.grid.IMEEssentiaMonitor;
import thaumicenergistics.gui.GuiEssentiaLevelEmitter;
import thaumicenergistics.integration.tc.EssentiaItemContainerHelper;
@@ -21,9 +21,9 @@ import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.api.networking.IEssentiaWatcher;
import thaumicenergistics.api.networking.IEssentiaWatcherHost;
import thaumicenergistics.aspect.AspectStack;
import thaumicenergistics.grid.IEssentiaWatcher;
import thaumicenergistics.grid.IEssentiaWatcherHost;
import thaumicenergistics.grid.IMEEssentiaMonitor;
import thaumicenergistics.integration.tc.EssentiaItemContainerHelper;
import thaumicenergistics.integration.tc.EssentiaItemContainerHelper.AspectItemType;
@@ -7,27 +7,42 @@ import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import thaumicenergistics.ThaumicEnergistics;
import thaumicenergistics.aspect.AspectStackComparator.ComparatorMode;
import thaumicenergistics.api.storage.ICraftingIssuerHost;
import thaumicenergistics.aspect.AspectStackComparator.AspectStackComparatorMode;
import thaumicenergistics.container.AbstractContainerCellTerminalBase;
import thaumicenergistics.container.ContainerEssentiaTerminal;
import thaumicenergistics.gui.GuiEssentiaCellTerminal;
import thaumicenergistics.gui.ThEGuiHandler;
import thaumicenergistics.integration.tc.EssentiaItemContainerHelper;
import thaumicenergistics.integration.tc.EssentiaItemContainerHelper.AspectItemType;
import thaumicenergistics.network.packet.server.Packet_S_ChangeGui;
import thaumicenergistics.registries.AEPartsEnum;
import thaumicenergistics.registries.EnumCache;
import thaumicenergistics.texture.BlockTextureManager;
import thaumicenergistics.util.EffectiveSide;
import thaumicenergistics.util.PrivateInventory;
import appeng.api.config.Settings;
import appeng.api.config.ViewItems;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartRenderHelper;
import appeng.api.parts.PartItemStack;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.util.AEColor;
import appeng.api.util.IConfigManager;
import appeng.util.Platform;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class AEPartEssentiaTerminal
extends AbstractAEPartRotateable
implements ICraftingIssuerHost, ITerminalHost
{
/**
@@ -36,34 +51,34 @@ public class AEPartEssentiaTerminal
private static final double IDLE_POWER_DRAIN = 0.5D;
/**
* Key used to read and write sorting mode from/to NBT.
* NBT Keys
*/
private static final String SORT_MODE_NBT_KEY = "sortMode";
/**
* Key used to read and write inventory from/to NBT.
*/
private static final String INVENTORY_NBT_KEY = "slots";
private static final String NBT_KEY_SORT_MODE = "sortMode", NBT_KEY_INVENTORY = "slots", NBT_KEY_VIEW_MODE = "ViewMode";
/**
* Default sorting mode for the terminal.
*/
private static final ComparatorMode DEFAULT_SORT_MODE = ComparatorMode.MODE_ALPHABETIC;
private static final AspectStackComparatorMode DEFAULT_SORT_MODE = AspectStackComparatorMode.MODE_ALPHABETIC;
/**
* Default view mode for the terminal.
*/
private static final ViewItems DEFAULT_VIEW_MODE = ViewItems.ALL;
/**
* List of currently opened containers.
*/
private List<ContainerEssentiaTerminal> listeners = new ArrayList<ContainerEssentiaTerminal>();
/**
* Tracks if the inventory has been locked for work.
*/
private boolean inventoryLocked = false;
/**
* The sorting mode used to display aspects.
*/
private ComparatorMode sortMode = AEPartEssentiaTerminal.DEFAULT_SORT_MODE;
private AspectStackComparatorMode sortMode = DEFAULT_SORT_MODE;
/**
* The viewing mode used to display aspects.
*/
private ViewItems viewMode = DEFAULT_VIEW_MODE;
private PrivateInventory inventory = new PrivateInventory( ThaumicEnergistics.MOD_ID + ".part.aspect.terminal", 2, 64 )
{
@@ -128,6 +143,13 @@ public class AEPartEssentiaTerminal
return GuiEssentiaCellTerminal.NewEssentiaTerminalGui( this, player );
}
@Override
public IConfigManager getConfigManager()
{
// NOTE: Ignored, should it be? No, not it should not. Could use this to store all the terminal settings.
return null;
}
@Override
public void getDrops( final List<ItemStack> drops, final boolean wrenched )
{
@@ -152,6 +174,19 @@ public class AEPartEssentiaTerminal
}
}
@Override
public IMEMonitor<IAEFluidStack> getFluidInventory()
{
// Ignored
return null;
}
@Override
public ItemStack getIcon()
{
return this.associatedItem;
}
/**
* Determines how much power the part takes for just
* existing.
@@ -167,6 +202,12 @@ public class AEPartEssentiaTerminal
return this.inventory;
}
@Override
public IMEMonitor<IAEItemStack> getItemInventory()
{
return this.getGridBlock().getItemMonitor();
}
/**
* Light level based on if terminal is active.
*/
@@ -187,49 +228,48 @@ public class AEPartEssentiaTerminal
*
* @return
*/
public ComparatorMode getSortingMode()
public AspectStackComparatorMode getSortingMode()
{
return this.sortMode;
}
/**
* Attempts to lock the terminal's inventory so that
* changes can be made.
* Gets the view mode.
*
* @return True if the lock was acquired, false otherwise.
* @return
*/
@Deprecated
public boolean lockInventoryForWork()
public ViewItems getViewMode()
{
boolean gotLock = false;
return this.viewMode;
}
// Ensure only 1 thread can access the lock at a time
synchronized( this.inventory )
@Override
public void launchGUI( final EntityPlayer player )
{
TileEntity host = this.getHostTile();
// Is this server side?
if( EffectiveSide.isServerSide() )
{
// Is the inventory not locked?
if( !this.inventoryLocked )
{
// Mark it is now locked
this.inventoryLocked = true;
// Mark that this thread got the lock
gotLock = true;
}
// Launch the gui
ThEGuiHandler.launchGui( this, player, host.getWorldObj(), host.xCoord, host.yCoord, host.zCoord );
}
else
{
// Ask the server to change the GUI
Packet_S_ChangeGui.sendGuiChangeToPart( this, player, host.getWorldObj(), host.xCoord, host.yCoord, host.zCoord );
}
// Return if this thread got the lock or not
return gotLock;
}
/**
* Informs all open containers to update their respective clients
* that the sorting mode has changed.
* that the mode has changed.
*/
public void notifyListenersSortingModeChanged()
public void notifyListenersOfModeChanged()
{
for( ContainerEssentiaTerminal listener : this.listeners )
{
listener.onSortingModeChanged( this.sortMode );
listener.onModeChanged( this.sortMode, this.viewMode );
}
}
@@ -238,19 +278,41 @@ public class AEPartEssentiaTerminal
*
* @param sortMode
*/
public void onClientRequestSortingModeChange( final ComparatorMode sortMode )
public void onClientRequestSortingModeChange( final boolean backwards )
{
// Set the sort mode
this.sortMode = sortMode;
// Change the sorting mode
if( backwards )
{
this.sortMode = this.sortMode.previousMode();
}
else
{
this.sortMode = this.sortMode.nextMode();
}
// Update clients
this.notifyListenersSortingModeChanged();
this.notifyListenersOfModeChanged();
// Mark that we need saving
this.markForSave();
}
/**
* Called when a player has changed viewing modes.
*/
public void onClientRequestViewModeChange( final boolean backwards )
{
// Change the view mode
this.viewMode = Platform.rotateEnum( this.viewMode, backwards, Settings.VIEW_MODE.getPossibleValues() );
// Update clients
this.notifyListenersOfModeChanged();
// Mark for save
this.markForSave();
}
/**
* Called to read our saved state
*/
@@ -261,15 +323,21 @@ public class AEPartEssentiaTerminal
super.readFromNBT( data );
// Read the sorting mode
if( data.hasKey( SORT_MODE_NBT_KEY ) )
if( data.hasKey( NBT_KEY_SORT_MODE ) )
{
this.sortMode = ComparatorMode.VALUES[data.getInteger( SORT_MODE_NBT_KEY )];
this.sortMode = AspectStackComparatorMode.VALUES[data.getInteger( NBT_KEY_SORT_MODE )];
}
// Read inventory
if( data.hasKey( AEPartEssentiaTerminal.INVENTORY_NBT_KEY ) )
if( data.hasKey( AEPartEssentiaTerminal.NBT_KEY_INVENTORY ) )
{
this.inventory.readFromNBT( data, AEPartEssentiaTerminal.INVENTORY_NBT_KEY );
this.inventory.readFromNBT( data, AEPartEssentiaTerminal.NBT_KEY_INVENTORY );
}
// Read view mode
if( data.hasKey( NBT_KEY_VIEW_MODE ) )
{
this.viewMode = EnumCache.AE_VIEW_ITEMS[data.getInteger( NBT_KEY_VIEW_MODE )];
}
}
@@ -368,21 +436,6 @@ public class AEPartEssentiaTerminal
}
/**
* Unlocks the terminal so that other threads can
* perform work. This should only be called from
* a thread that owns the lock.
*/
@Deprecated
public void unlockInventory()
{
// Ensure only 1 thread can access the lock at a time
synchronized( this.inventory )
{
this.inventoryLocked = false;
}
}
/**
* Called to save our state
*/
@@ -393,15 +446,21 @@ public class AEPartEssentiaTerminal
super.writeToNBT( data, saveType );
// Write the sorting mode
if( this.sortMode != AEPartEssentiaTerminal.DEFAULT_SORT_MODE )
if( this.sortMode != DEFAULT_SORT_MODE )
{
data.setInteger( SORT_MODE_NBT_KEY, this.sortMode.ordinal() );
data.setInteger( NBT_KEY_SORT_MODE, this.sortMode.ordinal() );
}
// Write inventory
if( !this.inventory.isEmpty() )
{
this.inventory.writeToNBT( data, AEPartEssentiaTerminal.INVENTORY_NBT_KEY );
this.inventory.writeToNBT( data, NBT_KEY_INVENTORY );
}
// Write view mode
if( this.viewMode != DEFAULT_VIEW_MODE )
{
data.setInteger( NBT_KEY_VIEW_MODE, this.viewMode.ordinal() );
}
}
@@ -31,12 +31,7 @@ import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.security.ISecurityGrid;
import appeng.api.parts.BusSupport;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartRenderHelper;
import appeng.api.parts.PartItemStack;
import appeng.api.parts.*;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import appeng.api.util.DimensionalCoord;
@@ -123,9 +118,6 @@ public abstract class AbstractAEPartBase
// Do we have a node?
if( this.node != null )
{
// Update the node
//this.node.updateState();
// Get the active state
boolean currentlyActive = this.node.isActive();
@@ -135,13 +127,13 @@ public abstract class AbstractAEPartBase
// Set our active state
this.isActive = currentlyActive;
// Fire the neighbor changed event
this.onNeighborChanged();
// Mark the host for an update
this.host.markForUpdate();
}
}
// Fire the neighbor changed event
this.onNeighborChanged();
}
/**
@@ -9,7 +9,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import thaumcraft.api.aspects.Aspect;
import thaumicenergistics.grid.IEssentiaGrid;
import thaumicenergistics.api.networking.IEssentiaGrid;
import thaumicenergistics.grid.IMEEssentiaMonitor;
import thaumicenergistics.integration.IWailaSource;
import thaumicenergistics.registries.EnumCache;
@@ -1,7 +1,9 @@
package thaumicenergistics.util;
import java.util.HashMap;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.util.EnumChatFormatting;
import org.lwjgl.opengl.GL11;
import thaumcraft.api.aspects.Aspect;
public final class GuiHelper
@@ -52,6 +54,42 @@ public final class GuiHelper
}
public static final void drawScaledText( final FontRenderer fontRenderer, final String text, final float scale, final float posX, final float posY )
{
// Disable lighting
GL11.glDisable( GL11.GL_LIGHTING );
// Disable depth testing
GL11.glDisable( GL11.GL_DEPTH_TEST );
// Push the current matrix
GL11.glPushMatrix();
// Scale the GUI
GL11.glScaled( scale, scale, scale );
// Calculate inverse scale
float inverseScale = 1.0f / scale;
// Calculate final X position
final int X = (int)( ( posX - ( fontRenderer.getStringWidth( text ) * scale ) ) * inverseScale );
// Calculate final Y position
final int Y = (int)( ( posY - ( 7.0f * scale ) ) * inverseScale );
// Render
fontRenderer.drawStringWithShadow( text, X, Y, 16777215 );
// Pop the matrix
GL11.glPopMatrix();
// Enable lighting
GL11.glEnable( GL11.GL_LIGHTING );
// Enable depth testing
GL11.glEnable( GL11.GL_DEPTH_TEST );
}
/**
* Changes a large number into a binary postfixed version.
* For example: 10,500 -> 10.5K
@@ -59,7 +97,7 @@ public final class GuiHelper
* @param count
* @return
*/
public static String shortenCount( final long count )
public static final String shortenCount( final long count )
{
int unit = 1000;
@@ -73,7 +111,7 @@ public final class GuiHelper
int exponential = (int)( Math.log( count ) / Math.log( unit ) );
// Get the posfix char
char postfix = "KMBT".charAt( exponential - 1 );
char postfix = "KMGTPE".charAt( exponential - 1 );
return String.format( "%.1f%c", ( count / Math.pow( unit, exponential ) ), postfix );
}