monitor = this.getItemInventory();
- if( monitor == null )
- {
- return null;
- }
+ // Extract
+ IAEItemStack extracted = AEApi.instance()
+ .storage()
+ .poweredExtraction(this.getEnergyGrid(), monitor, aeRequest, this.actionSource);
+ if (extracted == null) {
+ return null;
+ }
- // Create the AE stack
- IAEItemStack aeRequest = AEApi.instance().storage().createItemStack( target );
+ return extracted.getItemStack();
+ }
- // Set size
- aeRequest.setStackSize( Math.min( target.stackSize, this.maxItemRate ) );
+ /**
+ * Inserts essentia into the network.
+ *
+ * @param aspect
+ * @param amount
+ * @return Amount injected
+ */
+ public long insertEssentia(final Aspect aspect, final int amount) {
+ // Get the essentia monitor
+ IMEEssentiaMonitor monitor = this.getEssentiaInventory();
+ if (monitor == null) {
+ return 0;
+ }
- // Extract
- IAEItemStack extracted = AEApi.instance().storage().poweredExtraction( this.getEnergyGrid(), monitor, aeRequest, this.actionSource );
- if( extracted == null )
- {
- return null;
- }
+ // Calculate the amount to inject
+ int amountToInject = Math.min(amount, this.maxEssentiaRate);
- return extracted.getItemStack();
- }
+ // Attempt to inject
+ long amountRejected =
+ monitor.injectEssentia(aspect, amountToInject, Actionable.MODULATE, this.actionSource, true);
- /**
- * Inserts essentia into the network.
- *
- * @param aspect
- * @param amount
- * @return Amount injected
- */
- public long insertEssentia( final Aspect aspect, final int amount )
- {
- // Get the essentia monitor
- IMEEssentiaMonitor monitor = this.getEssentiaInventory();
- if( monitor == null )
- {
- return 0;
- }
+ // Return the amount that was injected
+ return amountToInject - amountRejected;
+ }
- // Calculate the amount to inject
- int amountToInject = Math.min( amount, this.maxEssentiaRate );
+ /**
+ * Checks if the network can be interacted with.
+ *
+ * @return
+ */
+ @Override
+ public boolean isConnected() {
+ // Connected to network?
+ this.wirelessStateData.isInRange = super.isConnected();
+ return this.wirelessStateData.isInRange;
+ }
+ }
- // Attempt to inject
- long amountRejected = monitor.injectEssentia( aspect, amountToInject, Actionable.MODULATE, this.actionSource, true );
+ private static final int NETWORK_COOLDOWN = 20;
- // Return the amount that was injected
- return amountToInject - amountRejected;
- }
+ /**
+ *
+ * Base 100, 250, 500
+ * Advanced 200, 500, 1000
+ *
+ */
+ private static final int[] FLUID_RATES = new int[] {100, 250, 500};
- /**
- * Checks if the network can be interacted with.
- *
- * @return
- */
- @Override
- public boolean isConnected()
- {
- // Connected to network?
- this.wirelessStateData.isInRange = super.isConnected();
- return this.wirelessStateData.isInRange;
- }
+ /**
+ *
+ * Base 8, 24, 32
+ * Advanced 16, 48, 64
+ *
+ */
+ private static final int[] ITEM_RATES = new int[] {8, 24, 32};
- }
+ /**
+ *
+ * Base 4, 12, 16
+ * Advanced 8, 24, 32
+ *
+ */
+ private static final int[] ESS_RATES = new int[] {4, 12, 16};
- private static final int NETWORK_COOLDOWN = 20;
+ /**
+ * How many ticks until the golem can interact with the network again.
+ */
+ private int actionTimer = 0;
- /**
- *
- * Base 100, 250, 500
- * Advanced 200, 500, 1000
- *
- */
- private static final int[] FLUID_RATES = new int[] { 100, 250, 500 };
+ /**
+ * Handles AE network communication.
+ */
+ public final NetworkHandler network;
- /**
- *
- * Base 8, 24, 32
- * Advanced 16, 48, 64
- *
- */
- private static final int[] ITEM_RATES = new int[] { 8, 24, 32 };
+ /**
+ * The golem the script is attached to.
+ */
+ protected final EntityGolemBase golem;
- /**
- *
- * Base 4, 12, 16
- * Advanced 8, 24, 32
- *
- */
- private static final int[] ESS_RATES = new int[] { 4, 12, 16 };
+ public AIAENetworkGolem(final EntityGolemBase golem, final WirelessGolemHandler.WirelessServerData wsd) {
+ // Set the golem
+ this.golem = golem;
- /**
- * How many ticks until the golem can interact with the network again.
- */
- private int actionTimer = 0;
+ // Get rate multiplier
+ int rateMult = (golem.advanced ? 2 : 1);
- /**
- * Handles AE network communication.
- */
- public final NetworkHandler network;
+ // Get number of order upgrades
+ int orderUpgrades = this.golem.getUpgradeAmount(GolemUpgradeTypes.Order.upgradeID);
+ if (orderUpgrades > 2) {
+ orderUpgrades = 2;
+ } else if (orderUpgrades < 0) {
+ orderUpgrades = 0;
+ }
- /**
- * The golem the script is attached to.
- */
- protected final EntityGolemBase golem;
+ // Set interaction maximums
+ int maxItems = AIAENetworkGolem.ITEM_RATES[orderUpgrades] * rateMult;
+ int maxEssentia = AIAENetworkGolem.ESS_RATES[orderUpgrades] * rateMult;
+ int maxFluids = AIAENetworkGolem.FLUID_RATES[orderUpgrades] * rateMult;
- public AIAENetworkGolem( final EntityGolemBase golem, final WirelessGolemHandler.WirelessServerData wsd )
- {
- // Set the golem
- this.golem = golem;
+ // Create the network handler
+ this.network = new NetworkHandler(wsd, maxItems, maxFluids, maxEssentia);
+ }
- // Get rate multiplier
- int rateMult = ( golem.advanced ? 2 : 1 );
+ /**
+ * Called to decrement the action timer.
+ *
+ * @return True if cooled down.
+ */
+ private boolean cooledDown() {
+ if (this.actionTimer > 0) {
+ --this.actionTimer;
+ return false;
+ }
+ return true;
+ }
- // Get number of order upgrades
- int orderUpgrades = this.golem.getUpgradeAmount( GolemUpgradeTypes.Order.upgradeID );
- if( orderUpgrades > 2 )
- {
- orderUpgrades = 2;
- }
- else if( orderUpgrades < 0 )
- {
- orderUpgrades = 0;
- }
+ /**
+ *
+ */
+ private void restartNetworkCooldown() {
+ // Reset network timer
+ this.actionTimer = AIAENetworkGolem.NETWORK_COOLDOWN;
+ }
- // Set interaction maximums
- int maxItems = AIAENetworkGolem.ITEM_RATES[orderUpgrades] * rateMult;
- int maxEssentia = AIAENetworkGolem.ESS_RATES[orderUpgrades] * rateMult;
- int maxFluids = AIAENetworkGolem.FLUID_RATES[orderUpgrades] * rateMult;
+ /**
+ * Return true if network interaction is required this update.
+ *
+ * @return
+ */
+ protected abstract boolean needsNetworkNow();
- // Create the network handler
- this.network = new NetworkHandler( wsd, maxItems, maxFluids, maxEssentia );
- }
+ @Override
+ public final boolean shouldExecute() {
+ // Check the network timer
+ if (this.cooledDown()) {
+ this.restartNetworkCooldown();
- /**
- * Called to decrement the action timer.
- *
- * @return True if cooled down.
- */
- private boolean cooledDown()
- {
- if( this.actionTimer > 0 )
- {
- --this.actionTimer;
- return false;
- }
- return true;
- }
-
- /**
- *
- */
- private void restartNetworkCooldown()
- {
- // Reset network timer
- this.actionTimer = AIAENetworkGolem.NETWORK_COOLDOWN;
- }
-
- /**
- * Return true if network interaction is required this update.
- *
- * @return
- */
- protected abstract boolean needsNetworkNow();
-
- @Override
- public final boolean shouldExecute()
- {
- // Check the network timer
- if( this.cooledDown() )
- {
- this.restartNetworkCooldown();
-
- // IsConnected needs to be checked before needsNetwork
- // This ensures the wireless state data is kept up-to-date
- if( this.network.isConnected() )
- {
- return this.needsNetworkNow();
- }
- }
- return false;
- }
-
- @Override
- public abstract void updateTask();
+ // IsConnected needs to be checked before needsNetwork
+ // This ensures the wireless state data is kept up-to-date
+ if (this.network.isConnected()) {
+ return this.needsNetworkNow();
+ }
+ }
+ return false;
+ }
+ @Override
+ public abstract void updateTask();
}
diff --git a/src/main/java/thaumicenergistics/common/entities/AIGolemWifiEssentia.java b/src/main/java/thaumicenergistics/common/entities/AIGolemWifiEssentia.java
index e0757eef..a80adc8f 100644
--- a/src/main/java/thaumicenergistics/common/entities/AIGolemWifiEssentia.java
+++ b/src/main/java/thaumicenergistics/common/entities/AIGolemWifiEssentia.java
@@ -1,7 +1,7 @@
package thaumicenergistics.common.entities;
-import java.util.HashSet;
import appeng.api.config.Actionable;
+import java.util.HashSet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
@@ -21,326 +21,285 @@ import thaumicenergistics.common.entities.WirelessGolemHandler.WirelessServerDat
* @author Nividica
*
*/
-public class AIGolemWifiEssentia
- extends AIAENetworkGolem
-{
- private final HashSet checkedJars = new HashSet();
+public class AIGolemWifiEssentia extends AIAENetworkGolem {
+ private final HashSet checkedJars = new HashSet();
- /**
- * The jar the golem plan's to fill up.
- */
- private TileJarFillable targetJar = null;
+ /**
+ * The jar the golem plan's to fill up.
+ */
+ private TileJarFillable targetJar = null;
- /**
- * Distance to the target jar.
- */
- private double targetDistance = 0;
+ /**
+ * Distance to the target jar.
+ */
+ private double targetDistance = 0;
- /**
- * Is the target jar a void jar?
- */
- private boolean targetVoid;
+ /**
+ * Is the target jar a void jar?
+ */
+ private boolean targetVoid;
- /**
- * The square range of the golem.
- */
- private double golemRange;
+ /**
+ * The square range of the golem.
+ */
+ private double golemRange;
- /**
- * True if the golem is filling up jars, false if the golem is emptying something.
- */
- private boolean modeFill;
+ /**
+ * True if the golem is filling up jars, false if the golem is emptying something.
+ */
+ private boolean modeFill;
- public AIGolemWifiEssentia( final EntityGolemBase golem, final WirelessServerData wsd )
- {
- super( golem, wsd );
- }
+ public AIGolemWifiEssentia(final EntityGolemBase golem, final WirelessServerData wsd) {
+ super(golem, wsd);
+ }
- /**
- * Checks jars connected to the specified jar for potential targets.
- *
- * @param world
- * @param gHomePos
- * @param teJar
- */
- private void checkConnectedJars( final World world, final ChunkCoordinates gHomePos, final TileEntity teJar )
- {
- int x, y, z, setOp;
+ /**
+ * Checks jars connected to the specified jar for potential targets.
+ *
+ * @param world
+ * @param gHomePos
+ * @param teJar
+ */
+ private void checkConnectedJars(final World world, final ChunkCoordinates gHomePos, final TileEntity teJar) {
+ int x, y, z, setOp;
- // Sanity check
- if( this.checkedJars.size() >= 200 )
- {
- return;
- }
+ // Sanity check
+ if (this.checkedJars.size() >= 200) {
+ return;
+ }
- // Check each direction
- for( ForgeDirection side : ForgeDirection.VALID_DIRECTIONS )
- {
- // Get the position
- x = side.offsetX + teJar.xCoord;
- y = side.offsetY + teJar.yCoord;
- z = side.offsetZ + teJar.zCoord;
+ // Check each direction
+ for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
+ // Get the position
+ x = side.offsetX + teJar.xCoord;
+ y = side.offsetY + teJar.yCoord;
+ z = side.offsetZ + teJar.zCoord;
- // Get the tile entity
- TileEntity te = world.getTileEntity( x, y, z );
+ // Get the tile entity
+ TileEntity te = world.getTileEntity(x, y, z);
- // Ensure the tile is a jar
- if( !( te instanceof TileJarFillable ) )
- {
- continue;
- }
+ // Ensure the tile is a jar
+ if (!(te instanceof TileJarFillable)) {
+ continue;
+ }
- // Set the jar if it is closer
- setOp = this.setTargetIfValid( (TileJarFillable)te, gHomePos );
- if( setOp > 2 )
- {
- // Check it's connected jars
- this.checkConnectedJars( world, gHomePos, te );
- }
+ // Set the jar if it is closer
+ setOp = this.setTargetIfValid((TileJarFillable) te, gHomePos);
+ if (setOp > 2) {
+ // Check it's connected jars
+ this.checkConnectedJars(world, gHomePos, te);
+ }
+ }
+ }
- }
- }
+ /**
+ * Locates the nearest valid jar as a target.
+ */
+ private void findClosestValidJar() {
+ // Is there a target?
+ if (this.targetJar != null) {
+ // Is the jar still there?
+ if (this.golem.worldObj.getTileEntity(this.targetJar.xCoord, this.targetJar.yCoord, this.targetJar.zCoord)
+ == this.targetJar) {
- /**
- * Locates the nearest valid jar as a target.
- */
- private void findClosestValidJar()
- {
- // Is there a target?
- if( this.targetJar != null )
- {
- // Is the jar still there?
- if( this.golem.worldObj.getTileEntity( this.targetJar.xCoord,
- this.targetJar.yCoord, this.targetJar.zCoord ) == this.targetJar )
- {
+ // Can it hold more?
+ Aspect wantedAspect =
+ (this.targetJar.aspectFilter != null ? this.targetJar.aspectFilter : this.targetJar.aspect);
+ if ((wantedAspect != null) && (this.targetVoid || (this.targetJar.amount < this.targetJar.maxAmount))) {
+ // Can the wanted aspect be extracted?
+ if (this.network.extractEssentia(wantedAspect, 1, Actionable.SIMULATE) > 0) {
+ return;
+ }
+ }
+ }
+ }
- // Can it hold more?
- Aspect wantedAspect = ( this.targetJar.aspectFilter != null ? this.targetJar.aspectFilter : this.targetJar.aspect );
- if( ( wantedAspect != null ) && ( this.targetVoid || ( this.targetJar.amount < this.targetJar.maxAmount ) ) )
- {
- // Can the wanted aspect be extracted?
- if( this.network.extractEssentia( wantedAspect, 1, Actionable.SIMULATE ) > 0 )
- {
- return;
- }
- }
- }
- }
+ // Reset target jar
+ this.targetJar = null;
+ this.targetDistance = Double.MAX_VALUE;
+ this.targetVoid = false;
- // Reset target jar
- this.targetJar = null;
- this.targetDistance = Double.MAX_VALUE;
- this.targetVoid = false;
+ // Get the world the golem is in
+ World world = this.golem.worldObj;
+ int worldDim = world.provider.dimensionId;
- // Get the world the golem is in
- World world = this.golem.worldObj;
- int worldDim = world.provider.dimensionId;
+ // Calculate the squared range
+ this.golemRange = this.golem.getRange();
+ this.golemRange *= this.golemRange;
- // Calculate the squared range
- this.golemRange = this.golem.getRange();
- this.golemRange *= this.golemRange;
+ // Get the golems position
+ ChunkCoordinates gHomePos = this.golem.getHomePosition();
- // Get the golems position
- ChunkCoordinates gHomePos = this.golem.getHomePosition();
+ // Check each of the golems markers
+ for (Marker marker : this.golem.getMarkers()) {
+ // Ensure the marker is in the same dimension
+ if (marker.dim != worldDim) {
+ continue;
+ }
- // Check each of the golems markers
- for( Marker marker : this.golem.getMarkers() )
- {
- // Ensure the marker is in the same dimension
- if( marker.dim != worldDim )
- {
- continue;
- }
+ // Get the tile entity
+ TileEntity markedTile = world.getTileEntity(marker.x, marker.y, marker.z);
- // Get the tile entity
- TileEntity markedTile = world.getTileEntity( marker.x, marker.y, marker.z );
+ // Ensure the tile is a jar
+ if (!(markedTile instanceof TileJarFillable)) {
+ continue;
+ }
- // Ensure the tile is a jar
- if( !( markedTile instanceof TileJarFillable ) )
- {
- continue;
- }
+ // Set the jar if it is closer
+ this.setTargetIfValid((TileJarFillable) markedTile, gHomePos);
- // Set the jar if it is closer
- this.setTargetIfValid( (TileJarFillable)markedTile, gHomePos );
+ // Check connected jars
+ this.checkConnectedJars(world, gHomePos, markedTile);
+ }
- // Check connected jars
- this.checkConnectedJars( world, gHomePos, markedTile );
- }
+ // Reset checked
+ this.checkedJars.clear();
+ }
- // Reset checked
- this.checkedJars.clear();
- }
+ /**
+ * Sets the target if the jar is valid, closer, and in range.
+ *
+ * @param jar
+ * @param gHomePos
+ * @return 1 = Jar out of range, 2 = Jar already visited, 3 = Invalid jar, 4 = Set as target
+ */
+ private int setTargetIfValid(final TileJarFillable jar, final ChunkCoordinates gHomePos) {
+ if (!this.checkedJars.add(jar)) {
+ return 2;
+ }
- /**
- * Sets the target if the jar is valid, closer, and in range.
- *
- * @param jar
- * @param gHomePos
- * @return 1 = Jar out of range, 2 = Jar already visited, 3 = Invalid jar, 4 = Set as target
- */
- private int setTargetIfValid( final TileJarFillable jar, final ChunkCoordinates gHomePos )
- {
- if( !this.checkedJars.add( jar ) )
- {
- return 2;
- }
+ // In range of golem?
+ double distance = jar.getDistanceFrom(gHomePos.posX, gHomePos.posY, gHomePos.posZ);
+ if (distance > this.golemRange) {
+ return 1;
+ }
- // In range of golem?
- double distance = jar.getDistanceFrom( gHomePos.posX, gHomePos.posY, gHomePos.posZ );
- if( distance > this.golemRange )
- {
- return 1;
- }
+ // If the current target is voiding, but the potential target is not,
+ // then do not bother with the distance check.
+ boolean isVoid = (jar instanceof TileJarFillableVoid);
+ if (!(this.targetVoid && !isVoid)) {
+ // Check distance
+ if (distance > this.targetDistance) {
+ return 1;
+ }
+ }
- // If the current target is voiding, but the potential target is not,
- // then do not bother with the distance check.
- boolean isVoid = ( jar instanceof TileJarFillableVoid );
- if( !( this.targetVoid && !isVoid ) )
- {
- // Check distance
- if( distance > this.targetDistance )
- {
- return 1;
- }
- }
+ // Check for essentia
+ if (jar.aspect == null) {
+ // Check for label
+ if (jar.aspectFilter == null) {
+ return 3;
+ }
+ }
- // Check for essentia
- if( jar.aspect == null )
- {
- // Check for label
- if( jar.aspectFilter == null )
- {
- return 3;
- }
- }
+ // Check amount
+ if (!isVoid && (jar.amount >= jar.maxAmount)) {
+ return 3;
+ }
- // Check amount
- if( !isVoid && ( jar.amount >= jar.maxAmount ) )
- {
- return 3;
- }
+ // Valid target
+ this.targetJar = jar;
+ this.targetDistance = distance;
+ this.targetVoid = isVoid;
- // Valid target
- this.targetJar = jar;
- this.targetDistance = distance;
- this.targetVoid = isVoid;
+ return 4;
+ }
- return 4;
+ @Override
+ protected boolean needsNetworkNow() {
+ // Determine the mode
- }
+ // Get the tile entity at the golems home
+ ChunkCoordinates gHomePos = this.golem.getHomePosition();
+ ForgeDirection side = ForgeDirection.getOrientation(this.golem.homeFacing);
+ TileEntity te = this.golem.worldObj.getTileEntity(
+ gHomePos.posX - side.offsetX, gHomePos.posY - side.offsetY, gHomePos.posZ - side.offsetZ);
- @Override
- protected boolean needsNetworkNow()
- {
- // Determine the mode
+ // Is the tile an essentia transport?
+ this.modeFill = !(te instanceof IEssentiaTransport);
- // Get the tile entity at the golems home
- ChunkCoordinates gHomePos = this.golem.getHomePosition();
- ForgeDirection side = ForgeDirection.getOrientation( this.golem.homeFacing );
- TileEntity te = this.golem.worldObj.getTileEntity( gHomePos.posX - side.offsetX,
- gHomePos.posY - side.offsetY,
- gHomePos.posZ - side.offsetZ );
+ // If the tile is not valid, check above it for alembic
+ if (this.modeFill) {
+ for (int i = 1; (i < 6) && this.modeFill; ++i) {
+ te = this.golem.worldObj.getTileEntity(
+ gHomePos.posX - side.offsetX, (gHomePos.posY - side.offsetY) + i, gHomePos.posZ - side.offsetZ);
+ this.modeFill = !(te instanceof TileAlembic);
+ }
+ }
- // Is the tile an essentia transport?
- this.modeFill = !( te instanceof IEssentiaTransport );
+ // Fill mode
+ if (this.modeFill) {
+ // Needs network if the golem is not carrying anything, and there is a target jar
+ if (this.golem.essentiaAmount > 0) {
+ return false;
+ }
- // If the tile is not valid, check above it for alembic
- if( this.modeFill )
- {
- for( int i = 1; ( i < 6 ) && this.modeFill; ++i )
- {
- te = this.golem.worldObj.getTileEntity( gHomePos.posX - side.offsetX,
- ( gHomePos.posY - side.offsetY ) + i,
- gHomePos.posZ - side.offsetZ );
- this.modeFill = !( te instanceof TileAlembic );
- }
- }
+ // Golem is not carrying anything, find a jar
+ this.findClosestValidJar();
+ return (this.targetJar != null);
+ }
- // Fill mode
- if( this.modeFill )
- {
- // Needs network if the golem is not carrying anything, and there is a target jar
- if( this.golem.essentiaAmount > 0 )
- {
- return false;
- }
+ // Empty mode
+ return (this.golem.getNavigator().noPath() && (this.golem.essentiaAmount > 0));
+ }
- // Golem is not carrying anything, find a jar
- this.findClosestValidJar();
- return( this.targetJar != null );
- }
+ @Override
+ public void updateTask() {
+ // Fill mode
+ if (this.modeFill) {
+ // Get the wanted aspect
+ Aspect wantedAspect =
+ (this.targetJar.aspectFilter != null ? this.targetJar.aspectFilter : this.targetJar.aspect);
+ if (wantedAspect == null) {
+ // Jar is invalid now
+ this.targetJar = null;
+ return;
+ }
- // Empty mode
- return( this.golem.getNavigator().noPath() && ( this.golem.essentiaAmount > 0 ) );
- }
+ // Get the capacity of the jar
+ int amount = this.targetJar.maxAmount;
- @Override
- public void updateTask()
- {
- // Fill mode
- if( this.modeFill )
- {
- // Get the wanted aspect
- Aspect wantedAspect = ( this.targetJar.aspectFilter != null ? this.targetJar.aspectFilter : this.targetJar.aspect );
- if( wantedAspect == null )
- {
- // Jar is invalid now
- this.targetJar = null;
- return;
- }
+ // Is the jar not voiding
+ if (!this.targetVoid) {
+ // Calculate the max amount to extract
+ amount -= this.targetJar.amount;
+ if (amount < 1) {
+ // Jar is full
+ this.targetJar = null;
+ return;
+ }
+ }
- // Get the capacity of the jar
- int amount = this.targetJar.maxAmount;
+ // Attempt extraction
+ int extractedAmount = (int) this.network.extractEssentia(wantedAspect, amount, Actionable.MODULATE);
+ if (extractedAmount <= 0) {
+ return;
+ }
- // Is the jar not voiding
- if( !this.targetVoid )
- {
- // Calculate the max amount to extract
- amount -= this.targetJar.amount;
- if( amount < 1 )
- {
- // Jar is full
- this.targetJar = null;
- return;
- }
- }
+ // Set the golems essentia
+ this.golem.essentia = wantedAspect;
+ this.golem.essentiaAmount = extractedAmount;
+ } else {
+ // Mode empty
+ if ((this.golem.essentia == null)
+ || (this.golem.essentiaAmount <= 0)
+ || !this.golem.getNavigator().noPath()) {
+ return;
+ }
- // Attempt extraction
- int extractedAmount = (int)this.network.extractEssentia( wantedAspect, amount, Actionable.MODULATE );
- if( extractedAmount <= 0 )
- {
- return;
- }
+ // Attempt injection
+ int injectedAmount = (int) this.network.insertEssentia(this.golem.essentia, this.golem.essentiaAmount);
+ if (injectedAmount == 0) {
+ return;
+ }
- // Set the golems essentia
- this.golem.essentia = wantedAspect;
- this.golem.essentiaAmount = extractedAmount;
- }
- else
- {
- // Mode empty
- if( ( this.golem.essentia == null ) || ( this.golem.essentiaAmount <= 0 ) || !this.golem.getNavigator().noPath() )
- {
- return;
- }
-
- // Attempt injection
- int injectedAmount = (int)this.network.insertEssentia( this.golem.essentia, this.golem.essentiaAmount );
- if( injectedAmount == 0 )
- {
- return;
- }
-
- // Update golem
- this.golem.essentiaAmount -= injectedAmount;
- if( this.golem.essentiaAmount <= 0 )
- {
- this.golem.essentia = null;
- }
- }
-
- this.golem.updateCarried();
- }
+ // Update golem
+ this.golem.essentiaAmount -= injectedAmount;
+ if (this.golem.essentiaAmount <= 0) {
+ this.golem.essentia = null;
+ }
+ }
+ this.golem.updateCarried();
+ }
}
diff --git a/src/main/java/thaumicenergistics/common/entities/AIGolemWifiFill.java b/src/main/java/thaumicenergistics/common/entities/AIGolemWifiFill.java
index 673cacdb..2193fdb1 100644
--- a/src/main/java/thaumicenergistics/common/entities/AIGolemWifiFill.java
+++ b/src/main/java/thaumicenergistics/common/entities/AIGolemWifiFill.java
@@ -9,37 +9,29 @@ import thaumcraft.common.entities.golems.EntityGolemBase;
* @author Nividica
*
*/
-public class AIGolemWifiFill
- extends AIAENetworkGolem
-{
+public class AIGolemWifiFill extends AIAENetworkGolem {
- public AIGolemWifiFill( final EntityGolemBase golem, final WirelessGolemHandler.WirelessServerData wsd )
- {
- super( golem, wsd );
- }
+ public AIGolemWifiFill(final EntityGolemBase golem, final WirelessGolemHandler.WirelessServerData wsd) {
+ super(golem, wsd);
+ }
- @Override
- protected boolean needsNetworkNow()
- {
- // Is the golem watching for anything?
- return( this.golem.itemWatched != null );
- }
-
- @Override
- public void updateTask()
- {
- // Get the stack the golem is watching for.
- ItemStack watched = this.golem.itemWatched;
- if( watched != null )
- {
- // Attempt extraction
- ItemStack extracted = this.network.extractStack( watched );
- if( extracted != null )
- {
- this.golem.setCarried( extracted );
- this.golem.itemWatched = null;
- }
- }
- }
+ @Override
+ protected boolean needsNetworkNow() {
+ // Is the golem watching for anything?
+ return (this.golem.itemWatched != null);
+ }
+ @Override
+ public void updateTask() {
+ // Get the stack the golem is watching for.
+ ItemStack watched = this.golem.itemWatched;
+ if (watched != null) {
+ // Attempt extraction
+ ItemStack extracted = this.network.extractStack(watched);
+ if (extracted != null) {
+ this.golem.setCarried(extracted);
+ this.golem.itemWatched = null;
+ }
+ }
+ }
}
diff --git a/src/main/java/thaumicenergistics/common/entities/AIGolemWifiGather.java b/src/main/java/thaumicenergistics/common/entities/AIGolemWifiGather.java
index 47e8968e..26705c01 100644
--- a/src/main/java/thaumicenergistics/common/entities/AIGolemWifiGather.java
+++ b/src/main/java/thaumicenergistics/common/entities/AIGolemWifiGather.java
@@ -9,42 +9,34 @@ import thaumcraft.common.entities.golems.EntityGolemBase;
* @author Nividica
*
*/
-public class AIGolemWifiGather
- extends AIAENetworkGolem
-{
- public AIGolemWifiGather( final EntityGolemBase golem, final WirelessGolemHandler.WirelessServerData wsd )
- {
- super( golem, wsd );
- }
+public class AIGolemWifiGather extends AIAENetworkGolem {
+ public AIGolemWifiGather(final EntityGolemBase golem, final WirelessGolemHandler.WirelessServerData wsd) {
+ super(golem, wsd);
+ }
- @Override
- public boolean needsNetworkNow()
- {
- // Execute when the golem is holding something
- return( this.golem.getCarried() != null );
- }
+ @Override
+ public boolean needsNetworkNow() {
+ // Execute when the golem is holding something
+ return (this.golem.getCarried() != null);
+ }
- @Override
- public void updateTask()
- {
- ItemStack heldItem = this.golem.getCarried();
+ @Override
+ public void updateTask() {
+ ItemStack heldItem = this.golem.getCarried();
- // Ensure the golem is holding something.
- if( heldItem != null )
- {
- // Deposit the item
- this.network.depositStack( heldItem );
+ // Ensure the golem is holding something.
+ if (heldItem != null) {
+ // Deposit the item
+ this.network.depositStack(heldItem);
- // Was the stack drained?
- if( heldItem.stackSize == 0 )
- {
- // Clear what the golem is holding
- this.golem.setCarried( null );
-
- // Throw his arms up for good measure.
- this.golem.startActionTimer();
- }
- }
- }
+ // Was the stack drained?
+ if (heldItem.stackSize == 0) {
+ // Clear what the golem is holding
+ this.golem.setCarried(null);
+ // Throw his arms up for good measure.
+ this.golem.startActionTimer();
+ }
+ }
+ }
}
diff --git a/src/main/java/thaumicenergistics/common/entities/AIGolemWifiLiquid.java b/src/main/java/thaumicenergistics/common/entities/AIGolemWifiLiquid.java
index 06f32482..4ca1a23a 100644
--- a/src/main/java/thaumicenergistics/common/entities/AIGolemWifiLiquid.java
+++ b/src/main/java/thaumicenergistics/common/entities/AIGolemWifiLiquid.java
@@ -12,76 +12,63 @@ import thaumicenergistics.common.entities.WirelessGolemHandler.WirelessServerDat
* @author Nividica
*
*/
-public class AIGolemWifiLiquid
- extends AIAENetworkGolem
-{
+public class AIGolemWifiLiquid extends AIAENetworkGolem {
- private FluidStack wantedFluid;
+ private FluidStack wantedFluid;
- public AIGolemWifiLiquid( final EntityGolemBase golem, final WirelessServerData wsd )
- {
- super( golem, wsd );
- }
+ public AIGolemWifiLiquid(final EntityGolemBase golem, final WirelessServerData wsd) {
+ super(golem, wsd);
+ }
- @Override
- protected boolean needsNetworkNow()
- {
- // Is the golem in-need of a fluid?
- ArrayList fluids = GolemHelper.getMissingLiquids( this.golem );
+ @Override
+ protected boolean needsNetworkNow() {
+ // Is the golem in-need of a fluid?
+ ArrayList fluids = GolemHelper.getMissingLiquids(this.golem);
- // Don't bother if the golem is asking for EVERY fluid, only if there is a specific request.
- if( ( fluids != null ) && ( fluids.size() == 1 ) )
- {
- // Set the wanted fluid
- this.wantedFluid = fluids.get( 0 ).copy();
+ // Don't bother if the golem is asking for EVERY fluid, only if there is a specific request.
+ if ((fluids != null) && (fluids.size() == 1)) {
+ // Set the wanted fluid
+ this.wantedFluid = fluids.get(0).copy();
- // Verify that the golem is carrying the fluid, or nothing
- if( ( this.golem.fluidCarried == null ) || ( this.golem.fluidCarried.getFluid() == this.wantedFluid.getFluid() ) )
- {
- return true;
- }
- this.wantedFluid = null;
- }
- return false;
- }
+ // Verify that the golem is carrying the fluid, or nothing
+ if ((this.golem.fluidCarried == null)
+ || (this.golem.fluidCarried.getFluid() == this.wantedFluid.getFluid())) {
+ return true;
+ }
+ this.wantedFluid = null;
+ }
+ return false;
+ }
- @Override
- public void updateTask()
- {
- if( this.wantedFluid == null )
- {
- return;
- }
+ @Override
+ public void updateTask() {
+ if (this.wantedFluid == null) {
+ return;
+ }
- // Is the golem carrying the fluid?
- int existingSize = 0;
- if( this.golem.fluidCarried != null )
- {
- existingSize = this.golem.fluidCarried.amount;
- }
+ // Is the golem carrying the fluid?
+ int existingSize = 0;
+ if (this.golem.fluidCarried != null) {
+ existingSize = this.golem.fluidCarried.amount;
+ }
- // Calculate maximum request size
- this.wantedFluid.amount = 1000 - existingSize;
+ // Calculate maximum request size
+ this.wantedFluid.amount = 1000 - existingSize;
- // Attempt extraction
- FluidStack extracted = this.network.extractFluid( this.wantedFluid );
- if( extracted == null )
- {
- return;
- }
+ // Attempt extraction
+ FluidStack extracted = this.network.extractFluid(this.wantedFluid);
+ if (extracted == null) {
+ return;
+ }
- // Add to existing?
- if( existingSize > 0 )
- {
- this.golem.fluidCarried.amount += extracted.amount;
- }
- else
- {
- this.golem.fluidCarried = extracted;
- }
- this.golem.updateCarried();
-
- this.wantedFluid = null;
- }
+ // Add to existing?
+ if (existingSize > 0) {
+ this.golem.fluidCarried.amount += extracted.amount;
+ } else {
+ this.golem.fluidCarried = extracted;
+ }
+ this.golem.updateCarried();
+ this.wantedFluid = null;
+ }
}
diff --git a/src/main/java/thaumicenergistics/common/entities/WirelessGolemHandler.java b/src/main/java/thaumicenergistics/common/entities/WirelessGolemHandler.java
index a1c50b86..3f3b9ea6 100644
--- a/src/main/java/thaumicenergistics/common/entities/WirelessGolemHandler.java
+++ b/src/main/java/thaumicenergistics/common/entities/WirelessGolemHandler.java
@@ -1,6 +1,5 @@
package thaumicenergistics.common.entities;
-import org.lwjgl.opengl.GL11;
import appeng.api.AEApi;
import appeng.items.parts.ItemFacade;
import cpw.mods.fml.relauncher.Side;
@@ -11,6 +10,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
+import org.lwjgl.opengl.GL11;
import thaumcraft.common.config.ConfigBlocks;
import thaumcraft.common.entities.golems.EntityGolemBase;
import thaumicenergistics.api.entities.IGolemHookHandler;
@@ -28,706 +28,641 @@ import thaumicenergistics.common.utils.EffectiveSide;
* @author Nividica
*
*/
-public class WirelessGolemHandler
- implements IGolemHookHandler
-{
- /**
- * Data stored on the client side.
- *
- * @author Nividica
- *
- */
- public static class WirelessClientData
- {
- public boolean isInRange = false;
- public float pearlRotation = 0.0f;
- public BackpackSkins skin = BackpackSkins.Thaumium;
- }
-
- /**
- * Data stored on the server side.
- *
- * @author Nividica
- *
- */
- public static class WirelessServerData
- {
- public final String encryptionKey;
- public int tickCounter = 0;
- public boolean isInRange = false;
- public ItemStack facade = null;
- public BackpackSkins skin = BackpackSkins.Thaumium;
-
- public WirelessServerData( final String encKey )
- {
- this.encryptionKey = encKey;
- }
- }
-
- private static WirelessGolemHandler INSTANCE = null;
-
- /**
- * NBT keys
- */
- private static final String NBTKEY_WIFI_KEY = "wifiBackpackKey", NBTKEY_FACADE = "facade";
-
- /**
- * State flags.
- */
- private static final Character SYNCFLAG_HAS_WIFI_IN_RANGE = Character.valueOf( 'i' ),
- SYNCFLAG_HAS_WIFI_OUT_OF_RANGE = Character.valueOf( 'o' ),
- SYNCFLAG_NO_WIFI = Character.valueOf( 'n' ),
- SYNCFIELD_SKIN = 'a';
-
- @SideOnly(Side.CLIENT)
- private ModelGolemWifiBackpack addonModel;
-
- /**
- * ID of the wifi sync field.
- */
- private int wifiSyncID = -1;
-
- /**
- * ID of the skin sync field.
- */
- private int skinSyncID = -1;
-
- /**
- * Cache of the backpack item.
- */
- private ItemGolemWirelessBackpack backpackItem;
-
- /**
- * Item that represents a facade, or null.
- */
- private ItemFacade facadeItem;
-
- /**
- * Private constructor.
- */
- private WirelessGolemHandler()
- {
- // Setup the backpack model if client side
- if( EffectiveSide.isClientSide() )
- {
- this.setupModel();
- }
-
- // Store a reference to the backpack item.
- this.backpackItem = (ItemGolemWirelessBackpack)ItemEnum.GOLEM_WIFI_BACKPACK.getItem();
-
- // Store a reference to the facade item
- this.facadeItem = (ItemFacade)AEApi.instance().definitions().items().facade().maybeItem().orNull();
- }
-
- /**
- * Returns the instance of the handler
- *
- * @return
- */
- public static WirelessGolemHandler getInstance()
- {
- if( INSTANCE == null )
- {
- INSTANCE = new WirelessGolemHandler();
- }
- return INSTANCE;
- }
-
- /**
- * Gets a character based on the skin.
- *
- * @param skin
- * @return
- */
- private Character backpackSkinToSyncChar( final BackpackSkins skin )
- {
- int id = 0;
- if( skin != null )
- {
- id = skin.ordinal();
- }
- return Character.valueOf( (char)( SYNCFIELD_SKIN + id ) );
- }
-
- /**
- * Han the backpack be handled?
- *
- * @param golem
- * @param handlerData
- * @param player
- * @param side
- * @return
- */
- private InteractionLevel canHandleInteration_Backpack( final EntityGolemBase golem, final Object handlerData, final EntityPlayer player,
- final Side side )
- {
- // Does the golem already have a backpack on?
- if( handlerData != null )
- {
- // Already has backpack.
- return InteractionLevel.NoInteraction;
- }
-
- // Is the core valid?
- GolemCoreType core = GolemCoreType.getCoreByID( golem.getCore() );
- if( core == null )
- {
- return InteractionLevel.NoInteraction;
- }
- switch ( core )
- {
- // Unsupported cores
- case Butcher:
- case Empty:
- case Fish:
- case Guard:
- case Harvest:
- case Lumber:
- case Sorting:
- case Use:
- default:
- return InteractionLevel.NoInteraction;
-
- // Supported cores
- case Gather:
- case Fill:
- case Liquid:
- case Essentia:
- break;
- }
-
- // Client side?
- if( side == Side.CLIENT )
- {
- //Swing the item
- player.swingItem();
- return InteractionLevel.NoInteraction;
- }
-
- return InteractionLevel.FullInteraction;
- }
-
- /**
- * Can the facade be handled?
- *
- * @param golem
- * @param handlerData
- * @param player
- * @param side
- * @param heldItem
- * @return
- */
- private InteractionLevel canHandleInteration_Facade( final EntityGolemBase golem, final Object handlerData, final EntityPlayer player,
- final Side side,
- final ItemStack heldItem )
- {
- // Is the golem wearing a backpack?
- if( handlerData == null )
- {
- // No backpack to apply it to
- return InteractionLevel.NoInteraction;
- }
-
- // Get the skin for the facade
- BackpackSkins skin = this.getSkinFromFacade( heldItem );
- if( skin == null )
- {
- // Unsupported facade
- return InteractionLevel.NoInteraction;
- }
-
- // Client side?
- if( ( side == Side.CLIENT ) && ( handlerData instanceof WirelessClientData ) )
- {
- //Swing the item
- player.swingItem();
-
- // Set the skin
- ( (WirelessClientData)handlerData ).skin = skin;
-
- return InteractionLevel.NoInteraction;
- }
-
- return InteractionLevel.SyncInteraction;
- }
-
- /**
- * Returns the skin associated with the facade, or null if there is not one.
- *
- * @param facade
- * @return
- */
- private BackpackSkins getSkinFromFacade( final ItemStack facade )
- {
- Block b = this.facadeItem.getBlock( facade );
- int metaData = this.facadeItem.getMeta( facade );
-
- if( b == ConfigBlocks.blockCosmeticSolid )
- {
- // Thaumium block?
- if( metaData == 4 )
- {
- return BackpackSkins.Thaumium;
- }
- // Tallow block?
- else if( metaData == 5 )
- {
- return BackpackSkins.Tallow;
- }
- }
- // Greatwood log?
- else if( ( b == ConfigBlocks.blockMagicalLog ) && ( metaData == 0 ) )
- {
- return BackpackSkins.GreatWood;
- }
- // Flesh?
- else if( ( b == ConfigBlocks.blockTaint ) && ( metaData == 2 ) )
- {
- return BackpackSkins.Flesh;
- }
- // Stone block?
- else if( b == Blocks.stone )
- {
- return BackpackSkins.Stone;
- }
- // Hay block?
- else if( b == Blocks.hay_block )
- {
- return BackpackSkins.Straw;
- }
- // Bricks?
- else if( b == Blocks.brick_block )
- {
- return BackpackSkins.Clay;
- }
- // Iron?
- else if( b == Blocks.iron_block )
- {
- return BackpackSkins.Iron;
- }
- else if( b == Blocks.gold_block )
- {
- return BackpackSkins.Gold;
- }
- else if( b == Blocks.diamond_block )
- {
- return BackpackSkins.Diamond;
- }
-
- return null;
- }
-
- /**
- * Creates the wifi addon model.
- */
- @SideOnly(Side.CLIENT)
- private void setupModel()
- {
- this.addonModel = new ModelGolemWifiBackpack();
- }
-
- /**
- * Gets the skin based on the character
- *
- * @param skinSyncChar
- * @return
- */
- private BackpackSkins syncCharToBackpackSkin( final char skinSyncChar )
- {
- int id = skinSyncChar - SYNCFIELD_SKIN;
- if( ( id < 0 ) || ( id > BackpackSkins.VALUES.length ) )
- {
- id = 0;
- }
- return BackpackSkins.VALUES[id];
- }
-
- @Override
- public void addDefaultSyncEntries( final IGolemHookSyncRegistry syncRegistry )
- {
- // Register the wifi entry
- this.wifiSyncID = syncRegistry.registerSyncChar( this, SYNCFLAG_NO_WIFI );
-
- // Register facade item
- this.skinSyncID = syncRegistry.registerSyncChar( this, this.backpackSkinToSyncChar( BackpackSkins.Thaumium ) );
- }
-
- @Override
- public void bellLeftClicked( final EntityGolemBase golem, final Object handlerData, final ItemStack itemGolemPlacer, final EntityPlayer player,
- final boolean dismantled, final Side side )
- {
- // Goes the golem have a backpack on?
- if( handlerData instanceof WirelessServerData )
- {
- WirelessServerData wsd = ( (WirelessServerData)handlerData );
-
- // Create a new backpack item
- ItemStack backpack = ItemEnum.GOLEM_WIFI_BACKPACK.getStack();
-
- // Set the key
- this.backpackItem.setEncryptionKey( backpack, wsd.encryptionKey, null );
-
- // Drop the backpack
- golem.entityDropItem( backpack, 0.5f );
-
- // Is there a facade?
- if( wsd.facade != null )
- {
- // Drop the facade
- golem.entityDropItem( wsd.facade, 0.5f );
- }
- }
-
- }
-
- @Override
- public InteractionLevel canHandleInteraction( final EntityGolemBase golem, final Object handlerData, final EntityPlayer player, final Side side )
- {
- // Get the held item
- ItemStack heldItem = player.inventory.getCurrentItem();
-
- // Empty hand?
- if( heldItem == null )
- {
- return InteractionLevel.NoInteraction;
- }
-
- // Backpack?
- if( heldItem.getItem() == this.backpackItem )
- {
- return this.canHandleInteration_Backpack( golem, handlerData, player, side );
- }
-
- // Facade?
- else if( ( this.facadeItem != null ) && ( heldItem.getItem() == this.facadeItem ) )
- {
- return this.canHandleInteration_Facade( golem, handlerData, player, side, heldItem );
- }
-
- return InteractionLevel.NoInteraction;
-
- }
-
- @Override
- public Object customInteraction( final EntityGolemBase golem, final Object handlerData, final IGolemHookSyncRegistry syncData,
- final EntityPlayer player, final Side side )
- {
- // Get the held item
- ItemStack heldItem = player.inventory.getCurrentItem();
-
- // Backpack?
- if( heldItem.getItem() == this.backpackItem )
- {
- // Is the backpack linked?
- String encKey = this.backpackItem.getEncryptionKey( heldItem );
- if( encKey != null )
- {
- // Play sound
- golem.worldObj.playSoundAtEntity( golem, "thaumcraft:upgrade", 0.5F, 1.0F );
-
- // Take the item
- player.inventory.setInventorySlotContents( player.inventory.currentItem, null );
-
- // Create the data
- return new WirelessServerData( encKey );
- }
- }
-
- // Facade?
- else if( ( this.facadeItem != null ) && ( heldItem.getItem() == this.facadeItem ) )
- {
- WirelessServerData wsd = (WirelessServerData)handlerData;
-
- // Is there a facade set?
- if( ( wsd.facade != null ) && ( !player.capabilities.isCreativeMode ) )
- {
- // Drop the old facade
- golem.entityDropItem( wsd.facade, 0.5f );
- }
-
- // Set facade
- wsd.facade = heldItem.copy();
- wsd.facade.stackSize = 1;
-
- // Take a facade from the player
- if( !player.capabilities.isCreativeMode )
- {
- --heldItem.stackSize;
- if( heldItem.stackSize <= 0 )
- {
- player.inventory.setInventorySlotContents( player.inventory.currentItem, null );
- }
- }
-
- // Set the skin
- wsd.skin = this.getSkinFromFacade( wsd.facade );
- syncData.updateSyncChar( this, this.skinSyncID, this.backpackSkinToSyncChar( wsd.skin ) );
-
- // Play sound
- golem.worldObj.playSoundAtEntity( golem, "thaumcraft:cameraticks", 0.5F, 1.0F );
-
- return wsd;
- }
-
- return null;
- }
-
- @Override
- public void golemTick( final EntityGolemBase golem, final Object serverHandlerData, final IGolemHookSyncRegistry syncData )
- {
- // Has backpack?
- if( serverHandlerData instanceof WirelessServerData )
- {
- WirelessServerData wsd = (WirelessServerData)serverHandlerData;
-
- // Set sync data every 18th tick
- if( ++wsd.tickCounter > 18 )
- {
- // Reset counter
- wsd.tickCounter = 0;
-
- // Set sync data
- syncData.updateSyncChar( this, this.wifiSyncID, ( wsd.isInRange ? SYNCFLAG_HAS_WIFI_IN_RANGE : SYNCFLAG_HAS_WIFI_OUT_OF_RANGE ) );
- syncData.updateSyncChar( this, this.skinSyncID, this.backpackSkinToSyncChar( wsd.skin ) );
- }
- }
- }
-
- @Override
- public boolean needsDynamicUpdates()
- {
- return true;
- }
-
- @Override
- public boolean needsRenderer()
- {
- return true;
- }
-
- @Override
- public Object readEntityFromNBT( final EntityGolemBase golem, final NBTTagCompound nbtTag )
- {
- WirelessServerData wsd = null;
-
- // Does the golem have a backpack?
- if( nbtTag.hasKey( NBTKEY_WIFI_KEY ) )
- {
- // Create the data
- wsd = new WirelessServerData( nbtTag.getString( NBTKEY_WIFI_KEY ) );
-
- if( nbtTag.hasKey( NBTKEY_FACADE ) )
- {
- // Read the facade
- try
- {
- wsd.facade = ItemStack.loadItemStackFromNBT( nbtTag.getCompoundTag( NBTKEY_FACADE ) );
- wsd.skin = this.getSkinFromFacade( wsd.facade );
- }
- catch( Exception e )
- {
- // Invalid facade
- }
- }
-
- }
-
- return wsd;
- }
-
- @Override
- @SideOnly(Side.CLIENT)
- public void renderGolem( final EntityGolemBase golem, final Object clientHandlerData, final double x, final double y, final double z,
- final float partialElaspsedTick )
- {
- if( !( clientHandlerData instanceof WirelessClientData ) )
- {
- return;
- }
- WirelessClientData wcd = (WirelessClientData)clientHandlerData;
-
- if( golem.hurtTime > 0 )
- {
- // Red tint
- GL11.glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
- }
- else if( golem.healing > 0 )
- {
- // Green tint
- GL11.glColor3f( 0.5f, 1.0f, 0.5f );
- }
- else
- {
- // Full white
- GL11.glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
- }
-
- // Is the golem in range and active?
- boolean golemActive = wcd.isInRange && !golem.inactive;
-
- // Update the rotation of the pearl
- if( golemActive && !Minecraft.getMinecraft().isGamePaused() )
- {
- wcd.pearlRotation += partialElaspsedTick * 2.0f;
- if( wcd.pearlRotation >= 360.0f )
- {
- wcd.pearlRotation -= 360.0f;
- }
-
- }
-
- // Push the matrix
- GL11.glPushMatrix();
-
- // Translate to the golem
- GL11.glTranslatef( (float)x, (float)y + 0.64f, (float)z );
-
- // Rotate to face away from the golem
- float golemYaw = 270.0f;
-
- // Interpolate the golems rotation
- golemYaw -= ( ( golem.renderYawOffset * partialElaspsedTick ) + ( golem.prevRenderYawOffset * ( 1.0f - partialElaspsedTick ) ) );
-
- // Rotate with the golem
- GL11.glRotatef( golemYaw, 0.0f, 1.0f, 0.0f );
-
- // Translate just behind the golem
- GL11.glTranslatef( -0.16f, 0.0f, 0.0f );
-
- // Scale
- GL11.glScalef( 0.8f, 0.8f, 0.8f );
-
- // Render
- this.addonModel.render( wcd.pearlRotation, 0.0625f, golemActive, wcd.skin );
-
- // Pop the matrix
- GL11.glPopMatrix();
-
- }
-
- @Override
- public Object setupGolem( final EntityGolemBase golem, final Object handlerData, final IGolemHookSyncRegistry syncData, final Side side )
- {
- if( side == Side.CLIENT )
- {
- return handlerData;
- }
-
- // Does the golem have a backpack?
- if( handlerData instanceof WirelessServerData )
- {
- WirelessServerData wsd = (WirelessServerData)handlerData;
-
- // Get the golems core
- GolemCoreType core = GolemCoreType.getCoreByID( golem.getCore() );
- if( core != null )
- {
- switch ( core )
- {
- case Gather:
- // Add Gather AI script
- golem.tasks.addTask( 1, new AIGolemWifiGather( golem, wsd ) );
- break;
-
- case Fill:
- // Add Fill AI script
- golem.tasks.addTask( 3, new AIGolemWifiFill( golem, wsd ) );
- break;
-
- case Liquid:
- // Add liquid AI script
- golem.tasks.addTask( 2, new AIGolemWifiLiquid( golem, wsd ) );
- break;
-
- case Essentia:
- // Add essentia AI script
- golem.tasks.addTask( 2, new AIGolemWifiEssentia( golem, wsd ) );
- break;
- default:
- break;
- }
- }
-
- // Update the sync data
- syncData.updateSyncChar( this, this.wifiSyncID, ( wsd.isInRange ? SYNCFLAG_HAS_WIFI_IN_RANGE : SYNCFLAG_HAS_WIFI_OUT_OF_RANGE ) );
- }
- else
- {
- // Update the sync data
- syncData.updateSyncChar( this, this.wifiSyncID, SYNCFLAG_NO_WIFI );
- }
-
- return handlerData;
- }
-
- @Override
- public Object spawnGolemFromItemStack( final EntityGolemBase golem, final ItemStack itemGolemPlacer, final Side side )
- {
- return null;
- }
-
- @Override
- @SideOnly(Side.CLIENT)
- public Object syncDataChanged( final IGolemHookSyncRegistry syncData, final Object clientHandlerData )
- {
- // Does the golem have on a backpack?
- char syncFlag = syncData.getSyncCharOrDefault( this.wifiSyncID, SYNCFLAG_NO_WIFI );
- boolean inRange;
- if( syncFlag == SYNCFLAG_HAS_WIFI_IN_RANGE )
- {
- inRange = true;
- }
- else if( syncFlag == SYNCFLAG_HAS_WIFI_OUT_OF_RANGE )
- {
- inRange = false;
- }
- else
- {
- // No backpack.
- return null;
- }
-
- // Has existing data?
- WirelessClientData wcd = null;
- if( clientHandlerData instanceof WirelessClientData )
- {
- wcd = (WirelessClientData)clientHandlerData;
- }
- else
- {
- // Create new data
- wcd = new WirelessClientData();
- }
-
- // Update the range
- wcd.isInRange = inRange;
-
- // Get the skin
- char skinChar = syncData.getSyncCharOrDefault( this.skinSyncID, SYNCFIELD_SKIN );
- wcd.skin = this.syncCharToBackpackSkin( skinChar );
-
- return wcd;
- }
-
- @Override
- public void writeEntityNBT( final EntityGolemBase golem, final Object serverHandlerData, final NBTTagCompound nbtTag )
- {
- // Does the golem have a backpack?
- if( serverHandlerData instanceof WirelessServerData )
- {
- WirelessServerData wsd = ( (WirelessServerData)serverHandlerData );
-
- // Write network key
- nbtTag.setString( NBTKEY_WIFI_KEY, wsd.encryptionKey );
-
- // Has facade?
- if( wsd.facade != null )
- {
- // Write the facade
- nbtTag.setTag( NBTKEY_FACADE, wsd.facade.writeToNBT( new NBTTagCompound() ) );
- }
- }
- }
-
+public class WirelessGolemHandler implements IGolemHookHandler {
+ /**
+ * Data stored on the client side.
+ *
+ * @author Nividica
+ *
+ */
+ public static class WirelessClientData {
+ public boolean isInRange = false;
+ public float pearlRotation = 0.0f;
+ public BackpackSkins skin = BackpackSkins.Thaumium;
+ }
+
+ /**
+ * Data stored on the server side.
+ *
+ * @author Nividica
+ *
+ */
+ public static class WirelessServerData {
+ public final String encryptionKey;
+ public int tickCounter = 0;
+ public boolean isInRange = false;
+ public ItemStack facade = null;
+ public BackpackSkins skin = BackpackSkins.Thaumium;
+
+ public WirelessServerData(final String encKey) {
+ this.encryptionKey = encKey;
+ }
+ }
+
+ private static WirelessGolemHandler INSTANCE = null;
+
+ /**
+ * NBT keys
+ */
+ private static final String NBTKEY_WIFI_KEY = "wifiBackpackKey", NBTKEY_FACADE = "facade";
+
+ /**
+ * State flags.
+ */
+ private static final Character SYNCFLAG_HAS_WIFI_IN_RANGE = Character.valueOf('i'),
+ SYNCFLAG_HAS_WIFI_OUT_OF_RANGE = Character.valueOf('o'),
+ SYNCFLAG_NO_WIFI = Character.valueOf('n'),
+ SYNCFIELD_SKIN = 'a';
+
+ @SideOnly(Side.CLIENT)
+ private ModelGolemWifiBackpack addonModel;
+
+ /**
+ * ID of the wifi sync field.
+ */
+ private int wifiSyncID = -1;
+
+ /**
+ * ID of the skin sync field.
+ */
+ private int skinSyncID = -1;
+
+ /**
+ * Cache of the backpack item.
+ */
+ private ItemGolemWirelessBackpack backpackItem;
+
+ /**
+ * Item that represents a facade, or null.
+ */
+ private ItemFacade facadeItem;
+
+ /**
+ * Private constructor.
+ */
+ private WirelessGolemHandler() {
+ // Setup the backpack model if client side
+ if (EffectiveSide.isClientSide()) {
+ this.setupModel();
+ }
+
+ // Store a reference to the backpack item.
+ this.backpackItem = (ItemGolemWirelessBackpack) ItemEnum.GOLEM_WIFI_BACKPACK.getItem();
+
+ // Store a reference to the facade item
+ this.facadeItem = (ItemFacade)
+ AEApi.instance().definitions().items().facade().maybeItem().orNull();
+ }
+
+ /**
+ * Returns the instance of the handler
+ *
+ * @return
+ */
+ public static WirelessGolemHandler getInstance() {
+ if (INSTANCE == null) {
+ INSTANCE = new WirelessGolemHandler();
+ }
+ return INSTANCE;
+ }
+
+ /**
+ * Gets a character based on the skin.
+ *
+ * @param skin
+ * @return
+ */
+ private Character backpackSkinToSyncChar(final BackpackSkins skin) {
+ int id = 0;
+ if (skin != null) {
+ id = skin.ordinal();
+ }
+ return Character.valueOf((char) (SYNCFIELD_SKIN + id));
+ }
+
+ /**
+ * Han the backpack be handled?
+ *
+ * @param golem
+ * @param handlerData
+ * @param player
+ * @param side
+ * @return
+ */
+ private InteractionLevel canHandleInteration_Backpack(
+ final EntityGolemBase golem, final Object handlerData, final EntityPlayer player, final Side side) {
+ // Does the golem already have a backpack on?
+ if (handlerData != null) {
+ // Already has backpack.
+ return InteractionLevel.NoInteraction;
+ }
+
+ // Is the core valid?
+ GolemCoreType core = GolemCoreType.getCoreByID(golem.getCore());
+ if (core == null) {
+ return InteractionLevel.NoInteraction;
+ }
+ switch (core) {
+ // Unsupported cores
+ case Butcher:
+ case Empty:
+ case Fish:
+ case Guard:
+ case Harvest:
+ case Lumber:
+ case Sorting:
+ case Use:
+ default:
+ return InteractionLevel.NoInteraction;
+
+ // Supported cores
+ case Gather:
+ case Fill:
+ case Liquid:
+ case Essentia:
+ break;
+ }
+
+ // Client side?
+ if (side == Side.CLIENT) {
+ // Swing the item
+ player.swingItem();
+ return InteractionLevel.NoInteraction;
+ }
+
+ return InteractionLevel.FullInteraction;
+ }
+
+ /**
+ * Can the facade be handled?
+ *
+ * @param golem
+ * @param handlerData
+ * @param player
+ * @param side
+ * @param heldItem
+ * @return
+ */
+ private InteractionLevel canHandleInteration_Facade(
+ final EntityGolemBase golem,
+ final Object handlerData,
+ final EntityPlayer player,
+ final Side side,
+ final ItemStack heldItem) {
+ // Is the golem wearing a backpack?
+ if (handlerData == null) {
+ // No backpack to apply it to
+ return InteractionLevel.NoInteraction;
+ }
+
+ // Get the skin for the facade
+ BackpackSkins skin = this.getSkinFromFacade(heldItem);
+ if (skin == null) {
+ // Unsupported facade
+ return InteractionLevel.NoInteraction;
+ }
+
+ // Client side?
+ if ((side == Side.CLIENT) && (handlerData instanceof WirelessClientData)) {
+ // Swing the item
+ player.swingItem();
+
+ // Set the skin
+ ((WirelessClientData) handlerData).skin = skin;
+
+ return InteractionLevel.NoInteraction;
+ }
+
+ return InteractionLevel.SyncInteraction;
+ }
+
+ /**
+ * Returns the skin associated with the facade, or null if there is not one.
+ *
+ * @param facade
+ * @return
+ */
+ private BackpackSkins getSkinFromFacade(final ItemStack facade) {
+ Block b = this.facadeItem.getBlock(facade);
+ int metaData = this.facadeItem.getMeta(facade);
+
+ if (b == ConfigBlocks.blockCosmeticSolid) {
+ // Thaumium block?
+ if (metaData == 4) {
+ return BackpackSkins.Thaumium;
+ }
+ // Tallow block?
+ else if (metaData == 5) {
+ return BackpackSkins.Tallow;
+ }
+ }
+ // Greatwood log?
+ else if ((b == ConfigBlocks.blockMagicalLog) && (metaData == 0)) {
+ return BackpackSkins.GreatWood;
+ }
+ // Flesh?
+ else if ((b == ConfigBlocks.blockTaint) && (metaData == 2)) {
+ return BackpackSkins.Flesh;
+ }
+ // Stone block?
+ else if (b == Blocks.stone) {
+ return BackpackSkins.Stone;
+ }
+ // Hay block?
+ else if (b == Blocks.hay_block) {
+ return BackpackSkins.Straw;
+ }
+ // Bricks?
+ else if (b == Blocks.brick_block) {
+ return BackpackSkins.Clay;
+ }
+ // Iron?
+ else if (b == Blocks.iron_block) {
+ return BackpackSkins.Iron;
+ } else if (b == Blocks.gold_block) {
+ return BackpackSkins.Gold;
+ } else if (b == Blocks.diamond_block) {
+ return BackpackSkins.Diamond;
+ }
+
+ return null;
+ }
+
+ /**
+ * Creates the wifi addon model.
+ */
+ @SideOnly(Side.CLIENT)
+ private void setupModel() {
+ this.addonModel = new ModelGolemWifiBackpack();
+ }
+
+ /**
+ * Gets the skin based on the character
+ *
+ * @param skinSyncChar
+ * @return
+ */
+ private BackpackSkins syncCharToBackpackSkin(final char skinSyncChar) {
+ int id = skinSyncChar - SYNCFIELD_SKIN;
+ if ((id < 0) || (id > BackpackSkins.VALUES.length)) {
+ id = 0;
+ }
+ return BackpackSkins.VALUES[id];
+ }
+
+ @Override
+ public void addDefaultSyncEntries(final IGolemHookSyncRegistry syncRegistry) {
+ // Register the wifi entry
+ this.wifiSyncID = syncRegistry.registerSyncChar(this, SYNCFLAG_NO_WIFI);
+
+ // Register facade item
+ this.skinSyncID = syncRegistry.registerSyncChar(this, this.backpackSkinToSyncChar(BackpackSkins.Thaumium));
+ }
+
+ @Override
+ public void bellLeftClicked(
+ final EntityGolemBase golem,
+ final Object handlerData,
+ final ItemStack itemGolemPlacer,
+ final EntityPlayer player,
+ final boolean dismantled,
+ final Side side) {
+ // Goes the golem have a backpack on?
+ if (handlerData instanceof WirelessServerData) {
+ WirelessServerData wsd = ((WirelessServerData) handlerData);
+
+ // Create a new backpack item
+ ItemStack backpack = ItemEnum.GOLEM_WIFI_BACKPACK.getStack();
+
+ // Set the key
+ this.backpackItem.setEncryptionKey(backpack, wsd.encryptionKey, null);
+
+ // Drop the backpack
+ golem.entityDropItem(backpack, 0.5f);
+
+ // Is there a facade?
+ if (wsd.facade != null) {
+ // Drop the facade
+ golem.entityDropItem(wsd.facade, 0.5f);
+ }
+ }
+ }
+
+ @Override
+ public InteractionLevel canHandleInteraction(
+ final EntityGolemBase golem, final Object handlerData, final EntityPlayer player, final Side side) {
+ // Get the held item
+ ItemStack heldItem = player.inventory.getCurrentItem();
+
+ // Empty hand?
+ if (heldItem == null) {
+ return InteractionLevel.NoInteraction;
+ }
+
+ // Backpack?
+ if (heldItem.getItem() == this.backpackItem) {
+ return this.canHandleInteration_Backpack(golem, handlerData, player, side);
+ }
+
+ // Facade?
+ else if ((this.facadeItem != null) && (heldItem.getItem() == this.facadeItem)) {
+ return this.canHandleInteration_Facade(golem, handlerData, player, side, heldItem);
+ }
+
+ return InteractionLevel.NoInteraction;
+ }
+
+ @Override
+ public Object customInteraction(
+ final EntityGolemBase golem,
+ final Object handlerData,
+ final IGolemHookSyncRegistry syncData,
+ final EntityPlayer player,
+ final Side side) {
+ // Get the held item
+ ItemStack heldItem = player.inventory.getCurrentItem();
+
+ // Backpack?
+ if (heldItem.getItem() == this.backpackItem) {
+ // Is the backpack linked?
+ String encKey = this.backpackItem.getEncryptionKey(heldItem);
+ if (encKey != null) {
+ // Play sound
+ golem.worldObj.playSoundAtEntity(golem, "thaumcraft:upgrade", 0.5F, 1.0F);
+
+ // Take the item
+ player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
+
+ // Create the data
+ return new WirelessServerData(encKey);
+ }
+ }
+
+ // Facade?
+ else if ((this.facadeItem != null) && (heldItem.getItem() == this.facadeItem)) {
+ WirelessServerData wsd = (WirelessServerData) handlerData;
+
+ // Is there a facade set?
+ if ((wsd.facade != null) && (!player.capabilities.isCreativeMode)) {
+ // Drop the old facade
+ golem.entityDropItem(wsd.facade, 0.5f);
+ }
+
+ // Set facade
+ wsd.facade = heldItem.copy();
+ wsd.facade.stackSize = 1;
+
+ // Take a facade from the player
+ if (!player.capabilities.isCreativeMode) {
+ --heldItem.stackSize;
+ if (heldItem.stackSize <= 0) {
+ player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
+ }
+ }
+
+ // Set the skin
+ wsd.skin = this.getSkinFromFacade(wsd.facade);
+ syncData.updateSyncChar(this, this.skinSyncID, this.backpackSkinToSyncChar(wsd.skin));
+
+ // Play sound
+ golem.worldObj.playSoundAtEntity(golem, "thaumcraft:cameraticks", 0.5F, 1.0F);
+
+ return wsd;
+ }
+
+ return null;
+ }
+
+ @Override
+ public void golemTick(
+ final EntityGolemBase golem, final Object serverHandlerData, final IGolemHookSyncRegistry syncData) {
+ // Has backpack?
+ if (serverHandlerData instanceof WirelessServerData) {
+ WirelessServerData wsd = (WirelessServerData) serverHandlerData;
+
+ // Set sync data every 18th tick
+ if (++wsd.tickCounter > 18) {
+ // Reset counter
+ wsd.tickCounter = 0;
+
+ // Set sync data
+ syncData.updateSyncChar(
+ this,
+ this.wifiSyncID,
+ (wsd.isInRange ? SYNCFLAG_HAS_WIFI_IN_RANGE : SYNCFLAG_HAS_WIFI_OUT_OF_RANGE));
+ syncData.updateSyncChar(this, this.skinSyncID, this.backpackSkinToSyncChar(wsd.skin));
+ }
+ }
+ }
+
+ @Override
+ public boolean needsDynamicUpdates() {
+ return true;
+ }
+
+ @Override
+ public boolean needsRenderer() {
+ return true;
+ }
+
+ @Override
+ public Object readEntityFromNBT(final EntityGolemBase golem, final NBTTagCompound nbtTag) {
+ WirelessServerData wsd = null;
+
+ // Does the golem have a backpack?
+ if (nbtTag.hasKey(NBTKEY_WIFI_KEY)) {
+ // Create the data
+ wsd = new WirelessServerData(nbtTag.getString(NBTKEY_WIFI_KEY));
+
+ if (nbtTag.hasKey(NBTKEY_FACADE)) {
+ // Read the facade
+ try {
+ wsd.facade = ItemStack.loadItemStackFromNBT(nbtTag.getCompoundTag(NBTKEY_FACADE));
+ wsd.skin = this.getSkinFromFacade(wsd.facade);
+ } catch (Exception e) {
+ // Invalid facade
+ }
+ }
+ }
+
+ return wsd;
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public void renderGolem(
+ final EntityGolemBase golem,
+ final Object clientHandlerData,
+ final double x,
+ final double y,
+ final double z,
+ final float partialElaspsedTick) {
+ if (!(clientHandlerData instanceof WirelessClientData)) {
+ return;
+ }
+ WirelessClientData wcd = (WirelessClientData) clientHandlerData;
+
+ if (golem.hurtTime > 0) {
+ // Red tint
+ GL11.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
+ } else if (golem.healing > 0) {
+ // Green tint
+ GL11.glColor3f(0.5f, 1.0f, 0.5f);
+ } else {
+ // Full white
+ GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ }
+
+ // Is the golem in range and active?
+ boolean golemActive = wcd.isInRange && !golem.inactive;
+
+ // Update the rotation of the pearl
+ if (golemActive && !Minecraft.getMinecraft().isGamePaused()) {
+ wcd.pearlRotation += partialElaspsedTick * 2.0f;
+ if (wcd.pearlRotation >= 360.0f) {
+ wcd.pearlRotation -= 360.0f;
+ }
+ }
+
+ // Push the matrix
+ GL11.glPushMatrix();
+
+ // Translate to the golem
+ GL11.glTranslatef((float) x, (float) y + 0.64f, (float) z);
+
+ // Rotate to face away from the golem
+ float golemYaw = 270.0f;
+
+ // Interpolate the golems rotation
+ golemYaw -= ((golem.renderYawOffset * partialElaspsedTick)
+ + (golem.prevRenderYawOffset * (1.0f - partialElaspsedTick)));
+
+ // Rotate with the golem
+ GL11.glRotatef(golemYaw, 0.0f, 1.0f, 0.0f);
+
+ // Translate just behind the golem
+ GL11.glTranslatef(-0.16f, 0.0f, 0.0f);
+
+ // Scale
+ GL11.glScalef(0.8f, 0.8f, 0.8f);
+
+ // Render
+ this.addonModel.render(wcd.pearlRotation, 0.0625f, golemActive, wcd.skin);
+
+ // Pop the matrix
+ GL11.glPopMatrix();
+ }
+
+ @Override
+ public Object setupGolem(
+ final EntityGolemBase golem,
+ final Object handlerData,
+ final IGolemHookSyncRegistry syncData,
+ final Side side) {
+ if (side == Side.CLIENT) {
+ return handlerData;
+ }
+
+ // Does the golem have a backpack?
+ if (handlerData instanceof WirelessServerData) {
+ WirelessServerData wsd = (WirelessServerData) handlerData;
+
+ // Get the golems core
+ GolemCoreType core = GolemCoreType.getCoreByID(golem.getCore());
+ if (core != null) {
+ switch (core) {
+ case Gather:
+ // Add Gather AI script
+ golem.tasks.addTask(1, new AIGolemWifiGather(golem, wsd));
+ break;
+
+ case Fill:
+ // Add Fill AI script
+ golem.tasks.addTask(3, new AIGolemWifiFill(golem, wsd));
+ break;
+
+ case Liquid:
+ // Add liquid AI script
+ golem.tasks.addTask(2, new AIGolemWifiLiquid(golem, wsd));
+ break;
+
+ case Essentia:
+ // Add essentia AI script
+ golem.tasks.addTask(2, new AIGolemWifiEssentia(golem, wsd));
+ break;
+ default:
+ break;
+ }
+ }
+
+ // Update the sync data
+ syncData.updateSyncChar(
+ this,
+ this.wifiSyncID,
+ (wsd.isInRange ? SYNCFLAG_HAS_WIFI_IN_RANGE : SYNCFLAG_HAS_WIFI_OUT_OF_RANGE));
+ } else {
+ // Update the sync data
+ syncData.updateSyncChar(this, this.wifiSyncID, SYNCFLAG_NO_WIFI);
+ }
+
+ return handlerData;
+ }
+
+ @Override
+ public Object spawnGolemFromItemStack(
+ final EntityGolemBase golem, final ItemStack itemGolemPlacer, final Side side) {
+ return null;
+ }
+
+ @Override
+ @SideOnly(Side.CLIENT)
+ public Object syncDataChanged(final IGolemHookSyncRegistry syncData, final Object clientHandlerData) {
+ // Does the golem have on a backpack?
+ char syncFlag = syncData.getSyncCharOrDefault(this.wifiSyncID, SYNCFLAG_NO_WIFI);
+ boolean inRange;
+ if (syncFlag == SYNCFLAG_HAS_WIFI_IN_RANGE) {
+ inRange = true;
+ } else if (syncFlag == SYNCFLAG_HAS_WIFI_OUT_OF_RANGE) {
+ inRange = false;
+ } else {
+ // No backpack.
+ return null;
+ }
+
+ // Has existing data?
+ WirelessClientData wcd = null;
+ if (clientHandlerData instanceof WirelessClientData) {
+ wcd = (WirelessClientData) clientHandlerData;
+ } else {
+ // Create new data
+ wcd = new WirelessClientData();
+ }
+
+ // Update the range
+ wcd.isInRange = inRange;
+
+ // Get the skin
+ char skinChar = syncData.getSyncCharOrDefault(this.skinSyncID, SYNCFIELD_SKIN);
+ wcd.skin = this.syncCharToBackpackSkin(skinChar);
+
+ return wcd;
+ }
+
+ @Override
+ public void writeEntityNBT(
+ final EntityGolemBase golem, final Object serverHandlerData, final NBTTagCompound nbtTag) {
+ // Does the golem have a backpack?
+ if (serverHandlerData instanceof WirelessServerData) {
+ WirelessServerData wsd = ((WirelessServerData) serverHandlerData);
+
+ // Write network key
+ nbtTag.setString(NBTKEY_WIFI_KEY, wsd.encryptionKey);
+
+ // Has facade?
+ if (wsd.facade != null) {
+ // Write the facade
+ nbtTag.setTag(NBTKEY_FACADE, wsd.facade.writeToNBT(new NBTTagCompound()));
+ }
+ }
+ }
}
diff --git a/src/main/java/thaumicenergistics/common/features/CommonDependantItems.java b/src/main/java/thaumicenergistics/common/features/CommonDependantItems.java
index a63f45e0..741a3f4c 100644
--- a/src/main/java/thaumicenergistics/common/features/CommonDependantItems.java
+++ b/src/main/java/thaumicenergistics/common/features/CommonDependantItems.java
@@ -1,11 +1,11 @@
package thaumicenergistics.common.features;
-import com.google.common.base.Optional;
import appeng.api.AEApi;
import appeng.api.definitions.IBlocks;
import appeng.api.definitions.IItemDefinition;
import appeng.api.definitions.IMaterials;
import appeng.api.definitions.IParts;
+import com.google.common.base.Optional;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -20,211 +20,203 @@ import thaumcraft.common.config.ConfigItems;
* @author Nividica
*
*/
-public class CommonDependantItems
-{
- // MC Items ==========================
- public String VanillaGlass = "blockGlass";
- public String IronIngot = "ingotIron";
- public ItemStack VanillaLapis;
- public ItemStack RedstoneDust;
- public ItemStack RedstoneTorch;
- public String Cobblestone = "cobblestone";
- public String NetherQuartz = "gemQuartz";
+public class CommonDependantItems {
+ // MC Items ==========================
+ public String VanillaGlass = "blockGlass";
+ public String IronIngot = "ingotIron";
+ public ItemStack VanillaLapis;
+ public ItemStack RedstoneDust;
+ public ItemStack RedstoneTorch;
+ public String Cobblestone = "cobblestone";
+ public String NetherQuartz = "gemQuartz";
- // TC Items ==========================
- public ItemStack ZombieBrain;
- public ItemStack Thaumonomicon;
- public ItemStack AirShard;
- public ItemStack FireShard;
- public ItemStack WaterShard;
- public ItemStack EarthShard;
- public ItemStack OrderShard;
- public ItemStack EntropyShard;
- public ItemStack BallanceShard;
- public ItemStack EtheralEssence;
- public ItemStack SalisMundus;
- public Object WardedGlass;
- public ItemStack ThaumiumIngot;
- public ItemStack ArcaneWorkTable;
- public ItemStack WardedJar;
- public ItemStack FilterTube;
- public ItemStack EssentiaMirror;
- public ItemStack VisFilter;
- public ItemStack QuickSilverDrop;
- public ItemStack Thaumometer;
- public ItemStack Nitor;
+ // TC Items ==========================
+ public ItemStack ZombieBrain;
+ public ItemStack Thaumonomicon;
+ public ItemStack AirShard;
+ public ItemStack FireShard;
+ public ItemStack WaterShard;
+ public ItemStack EarthShard;
+ public ItemStack OrderShard;
+ public ItemStack EntropyShard;
+ public ItemStack BallanceShard;
+ public ItemStack EtheralEssence;
+ public ItemStack SalisMundus;
+ public Object WardedGlass;
+ public ItemStack ThaumiumIngot;
+ public ItemStack ArcaneWorkTable;
+ public ItemStack WardedJar;
+ public ItemStack FilterTube;
+ public ItemStack EssentiaMirror;
+ public ItemStack VisFilter;
+ public ItemStack QuickSilverDrop;
+ public ItemStack Thaumometer;
+ public ItemStack Nitor;
- // AE Items =========================
- public Object VibrantGlass;
- public ItemStack EngineeringProcessor;
- public ItemStack CalculationProcessor;
- public ItemStack LogicProcessor;
- public String IlluminatedPanel = "itemIlluminatedPanel";
- public ItemStack MolecularAssembler;
- public ItemStack CertusQuartz;
- public ItemStack ChargedCertusQuartz;
- public ItemStack PureCertusQuartz;
- public Object QuartzGlass;
- public Object MECellWorkbench;
- public ItemStack METerminal;
- public ItemStack MEP2P;
- public ItemStack MEInterface;
- public ItemStack WirelessReceiver;
- public ItemStack DenseCell;
- public ItemStack FormationCore;
- public ItemStack AnnihilationCore;
- public ItemStack CertusWrench;
- public ItemStack VibrationChamber;
- public ItemStack MEInterfacePart;
- public ItemStack FluixCrystal;
- public ItemStack MECharger;
+ // AE Items =========================
+ public Object VibrantGlass;
+ public ItemStack EngineeringProcessor;
+ public ItemStack CalculationProcessor;
+ public ItemStack LogicProcessor;
+ public String IlluminatedPanel = "itemIlluminatedPanel";
+ public ItemStack MolecularAssembler;
+ public ItemStack CertusQuartz;
+ public ItemStack ChargedCertusQuartz;
+ public ItemStack PureCertusQuartz;
+ public Object QuartzGlass;
+ public Object MECellWorkbench;
+ public ItemStack METerminal;
+ public ItemStack MEP2P;
+ public ItemStack MEInterface;
+ public ItemStack WirelessReceiver;
+ public ItemStack DenseCell;
+ public ItemStack FormationCore;
+ public ItemStack AnnihilationCore;
+ public ItemStack CertusWrench;
+ public ItemStack VibrationChamber;
+ public ItemStack MEInterfacePart;
+ public ItemStack FluixCrystal;
+ public ItemStack MECharger;
- /**
- * Populates the common items
- */
- public CommonDependantItems()
- {
- // MC items
- this.VanillaLapis = new ItemStack( (Item)Item.itemRegistry.getObject( "dye" ), 1, 4 );
- this.RedstoneDust = new ItemStack( (Item)Item.itemRegistry.getObject( "redstone" ) );
- this.RedstoneTorch = new ItemStack( net.minecraft.init.Blocks.redstone_torch );
+ /**
+ * Populates the common items
+ */
+ public CommonDependantItems() {
+ // MC items
+ this.VanillaLapis = new ItemStack((Item) Item.itemRegistry.getObject("dye"), 1, 4);
+ this.RedstoneDust = new ItemStack((Item) Item.itemRegistry.getObject("redstone"));
+ this.RedstoneTorch = new ItemStack(net.minecraft.init.Blocks.redstone_torch);
- // AE items
- this.populateAEItems();
+ // AE items
+ this.populateAEItems();
- // TC items
- this.populateTCItems();
- }
+ // TC items
+ this.populateTCItems();
+ }
- /**
- * Attempts to get the specified AE item.
- * Returns a stack of size 1, or null.
- *
- * @param def
- * @return
- */
- private ItemStack getAEItem( final IItemDefinition def )
- {
- // Ensure there is a definition
- if( def == null )
- {
- return null;
- }
+ /**
+ * Attempts to get the specified AE item.
+ * Returns a stack of size 1, or null.
+ *
+ * @param def
+ * @return
+ */
+ private ItemStack getAEItem(final IItemDefinition def) {
+ // Ensure there is a definition
+ if (def == null) {
+ return null;
+ }
- // Attempt to get a stack
- Optional item = def.maybeStack( 1 );
+ // Attempt to get a stack
+ Optional