Basic reformat, hit once, hope never again
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.entity.passive.EntityVillager;
|
||||
@@ -38,55 +39,34 @@ import appeng.api.definitions.IMaterials;
|
||||
public class AETrading implements IVillageTradeHandler
|
||||
{
|
||||
|
||||
private void addToList(MerchantRecipeList l, ItemStack a, ItemStack b)
|
||||
@Override
|
||||
public void manipulateTradesForVillager( EntityVillager villager, MerchantRecipeList recipeList, Random random )
|
||||
{
|
||||
if ( a.stackSize < 1 )
|
||||
a.stackSize = 1;
|
||||
if ( b.stackSize < 1 )
|
||||
b.stackSize = 1;
|
||||
final IMaterials materials = AEApi.instance().definitions().materials();
|
||||
|
||||
if ( a.stackSize > a.getMaxStackSize() )
|
||||
a.stackSize = a.getMaxStackSize();
|
||||
if ( b.stackSize > b.getMaxStackSize() )
|
||||
b.stackSize = b.getMaxStackSize();
|
||||
this.addMerchant( recipeList, materials.silicon(), 1, random, 2 );
|
||||
this.addMerchant( recipeList, materials.certusQuartzCrystal(), 2, random, 4 );
|
||||
this.addMerchant( recipeList, materials.certusQuartzDust(), 1, random, 3 );
|
||||
|
||||
l.add( new MerchantRecipe( a, b ) );
|
||||
this.addTrade( recipeList, materials.certusQuartzDust(), materials.certusQuartzCrystal(), random, 2 );
|
||||
}
|
||||
|
||||
private void addTrade(MerchantRecipeList list, IItemDefinition inputDefinition, IItemDefinition outputDefinition, Random rand, int conversionVariance)
|
||||
private void addMerchant( MerchantRecipeList list, IItemDefinition item, int emera, Random rand, int greed )
|
||||
{
|
||||
final Optional<ItemStack> maybeInputStack = inputDefinition.maybeStack( 1 );
|
||||
final Optional<ItemStack> maybeOutputStack = outputDefinition.maybeStack( 1 );
|
||||
|
||||
if ( maybeInputStack.isPresent() && maybeOutputStack.isPresent() )
|
||||
{
|
||||
// Sell
|
||||
ItemStack inputStack = maybeInputStack.get().copy();
|
||||
ItemStack outputStack = maybeOutputStack.get().copy();
|
||||
|
||||
inputStack.stackSize = 1 + (Math.abs( rand.nextInt() ) % (1 + conversionVariance));
|
||||
outputStack.stackSize = 1;
|
||||
|
||||
this.addToList( list, inputStack, outputStack );
|
||||
}
|
||||
}
|
||||
|
||||
private void addMerchant(MerchantRecipeList list, IItemDefinition item, int emera, Random rand, int greed)
|
||||
{
|
||||
for ( ItemStack itemStack : item.maybeStack( 1 ).asSet() )
|
||||
for( ItemStack itemStack : item.maybeStack( 1 ).asSet() )
|
||||
{
|
||||
// Sell
|
||||
ItemStack from = itemStack.copy();
|
||||
ItemStack to = new ItemStack( Items.emerald );
|
||||
|
||||
int multiplier = (Math.abs( rand.nextInt() ) % 6);
|
||||
final int emeraldCost = emera + (Math.abs( rand.nextInt() ) % greed) - multiplier;
|
||||
int multiplier = ( Math.abs( rand.nextInt() ) % 6 );
|
||||
final int emeraldCost = emera + ( Math.abs( rand.nextInt() ) % greed ) - multiplier;
|
||||
int mood = rand.nextInt() % 2;
|
||||
|
||||
from.stackSize = multiplier + mood;
|
||||
to.stackSize = multiplier * emeraldCost - mood;
|
||||
|
||||
if ( to.stackSize < 0 )
|
||||
if( to.stackSize < 0 )
|
||||
{
|
||||
from.stackSize -= to.stackSize;
|
||||
to.stackSize -= to.stackSize;
|
||||
@@ -104,16 +84,36 @@ public class AETrading implements IVillageTradeHandler
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random random)
|
||||
private void addTrade( MerchantRecipeList list, IItemDefinition inputDefinition, IItemDefinition outputDefinition, Random rand, int conversionVariance )
|
||||
{
|
||||
final IMaterials materials = AEApi.instance().definitions().materials();
|
||||
final Optional<ItemStack> maybeInputStack = inputDefinition.maybeStack( 1 );
|
||||
final Optional<ItemStack> maybeOutputStack = outputDefinition.maybeStack( 1 );
|
||||
|
||||
this.addMerchant( recipeList, materials.silicon(), 1, random, 2 );
|
||||
this.addMerchant( recipeList, materials.certusQuartzCrystal(), 2, random, 4 );
|
||||
this.addMerchant( recipeList, materials.certusQuartzDust(), 1, random, 3 );
|
||||
if( maybeInputStack.isPresent() && maybeOutputStack.isPresent() )
|
||||
{
|
||||
// Sell
|
||||
ItemStack inputStack = maybeInputStack.get().copy();
|
||||
ItemStack outputStack = maybeOutputStack.get().copy();
|
||||
|
||||
this.addTrade( recipeList, materials.certusQuartzDust(), materials.certusQuartzCrystal(), random, 2 );
|
||||
inputStack.stackSize = 1 + ( Math.abs( rand.nextInt() ) % ( 1 + conversionVariance ) );
|
||||
outputStack.stackSize = 1;
|
||||
|
||||
this.addToList( list, inputStack, outputStack );
|
||||
}
|
||||
}
|
||||
|
||||
private void addToList( MerchantRecipeList l, ItemStack a, ItemStack b )
|
||||
{
|
||||
if( a.stackSize < 1 )
|
||||
a.stackSize = 1;
|
||||
if( b.stackSize < 1 )
|
||||
b.stackSize = 1;
|
||||
|
||||
if( a.stackSize > a.getMaxStackSize() )
|
||||
a.stackSize = a.getMaxStackSize();
|
||||
if( b.stackSize > b.getMaxStackSize() )
|
||||
b.stackSize = b.getMaxStackSize();
|
||||
|
||||
l.add( new MerchantRecipe( a, b ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,16 +18,64 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketCompassRequest;
|
||||
|
||||
|
||||
public class CompassManager
|
||||
{
|
||||
|
||||
public static final CompassManager INSTANCE = new CompassManager();
|
||||
final HashMap<CompassRequest, CompassResult> requests = new HashMap<CompassRequest, CompassResult>();
|
||||
|
||||
public void postResult( long attunement, int x, int y, int z, CompassResult result )
|
||||
{
|
||||
CompassRequest r = new CompassRequest( attunement, x, y, z );
|
||||
this.requests.put( r, result );
|
||||
}
|
||||
|
||||
public CompassResult getCompassDirection( long attunement, int x, int y, int z )
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
Iterator<CompassResult> i = this.requests.values().iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
CompassResult res = i.next();
|
||||
long diff = now - res.time;
|
||||
if( diff > 20000 )
|
||||
i.remove();
|
||||
}
|
||||
|
||||
CompassRequest r = new CompassRequest( attunement, x, y, z );
|
||||
CompassResult res = this.requests.get( r );
|
||||
|
||||
if( res == null )
|
||||
{
|
||||
res = new CompassResult( false, true, 0 );
|
||||
this.requests.put( r, res );
|
||||
this.requestUpdate( r );
|
||||
}
|
||||
else if( now - res.time > 1000 * 3 )
|
||||
{
|
||||
if( !res.requested )
|
||||
{
|
||||
res.requested = true;
|
||||
this.requestUpdate( r );
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private void requestUpdate( CompassRequest r )
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketCompassRequest( r.attunement, r.cx, r.cz, r.cdy ) );
|
||||
}
|
||||
|
||||
static class CompassRequest
|
||||
{
|
||||
@@ -39,12 +87,13 @@ public class CompassManager
|
||||
final int cdy;
|
||||
final int cz;
|
||||
|
||||
public CompassRequest(long attunement, int x, int y, int z) {
|
||||
public CompassRequest( long attunement, int x, int y, int z )
|
||||
{
|
||||
this.attunement = attunement;
|
||||
this.cx = x >> 4;
|
||||
this.cdy = y >> 5;
|
||||
this.cz = z >> 4;
|
||||
this.hash = ((Integer) this.cx).hashCode() ^ ((Integer) this.cdy).hashCode() ^ ((Integer) this.cz).hashCode() ^ ((Long) attunement).hashCode();
|
||||
this.hash = ( (Integer) this.cx ).hashCode() ^ ( (Integer) this.cdy ).hashCode() ^ ( (Integer) this.cz ).hashCode() ^ ( (Long) attunement ).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,63 +103,14 @@ public class CompassManager
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
public boolean equals( Object obj )
|
||||
{
|
||||
if ( obj == null )
|
||||
if( obj == null )
|
||||
return false;
|
||||
if ( this.getClass() != obj.getClass() )
|
||||
if( this.getClass() != obj.getClass() )
|
||||
return false;
|
||||
CompassRequest other = (CompassRequest) obj;
|
||||
return this.attunement == other.attunement && this.cx == other.cx && this.cdy == other.cdy && this.cz == other.cz;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final HashMap<CompassRequest, CompassResult> requests = new HashMap<CompassRequest, CompassResult>();
|
||||
|
||||
public void postResult(long attunement, int x, int y, int z, CompassResult result)
|
||||
{
|
||||
CompassRequest r = new CompassRequest( attunement, x, y, z );
|
||||
this.requests.put( r, result );
|
||||
}
|
||||
|
||||
public CompassResult getCompassDirection(long attunement, int x, int y, int z)
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
Iterator<CompassResult> i = this.requests.values().iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
CompassResult res = i.next();
|
||||
long diff = now - res.time;
|
||||
if ( diff > 20000 )
|
||||
i.remove();
|
||||
}
|
||||
|
||||
CompassRequest r = new CompassRequest( attunement, x, y, z );
|
||||
CompassResult res = this.requests.get( r );
|
||||
|
||||
if ( res == null )
|
||||
{
|
||||
res = new CompassResult( false, true, 0 );
|
||||
this.requests.put( r, res );
|
||||
this.requestUpdate( r );
|
||||
}
|
||||
else if ( now - res.time > 1000 * 3 )
|
||||
{
|
||||
if ( !res.requested )
|
||||
{
|
||||
res.requested = true;
|
||||
this.requestUpdate( r );
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private void requestUpdate(CompassRequest r)
|
||||
{
|
||||
NetworkHandler.instance.sendToServer( new PacketCompassRequest( r.attunement, r.cx, r.cz, r.cdy ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
|
||||
public class CompassResult
|
||||
{
|
||||
|
||||
@@ -28,11 +29,11 @@ public class CompassResult
|
||||
|
||||
public boolean requested = false;
|
||||
|
||||
public CompassResult(boolean hasResult, boolean spin, double rad) {
|
||||
public CompassResult( boolean hasResult, boolean spin, double rad )
|
||||
{
|
||||
this.hasResult = hasResult;
|
||||
this.spin = spin;
|
||||
this.rad = rad;
|
||||
this.time = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
@@ -27,22 +28,21 @@ import net.minecraft.world.World;
|
||||
|
||||
import appeng.entity.EntityTinyTNTPrimed;
|
||||
|
||||
|
||||
final public class DispenserBehaviorTinyTNT extends BehaviorDefaultDispenseItem
|
||||
{
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseStack(IBlockSource dispenser, ItemStack dispensedItem)
|
||||
protected ItemStack dispenseStack( IBlockSource dispenser, ItemStack dispensedItem )
|
||||
{
|
||||
EnumFacing enumfacing = BlockDispenser.func_149937_b( dispenser.getBlockMetadata() );
|
||||
World world = dispenser.getWorld();
|
||||
int i = dispenser.getXInt() + enumfacing.getFrontOffsetX();
|
||||
int j = dispenser.getYInt() + enumfacing.getFrontOffsetY();
|
||||
int k = dispenser.getZInt() + enumfacing.getFrontOffsetZ();
|
||||
EntityTinyTNTPrimed primedTinyTNTEntity = new EntityTinyTNTPrimed( world, i + 0.5F, j + 0.5F,
|
||||
k + 0.5F, null );
|
||||
EntityTinyTNTPrimed primedTinyTNTEntity = new EntityTinyTNTPrimed( world, i + 0.5F, j + 0.5F, k + 0.5F, null );
|
||||
world.spawnEntityInWorld( primedTinyTNTEntity );
|
||||
--dispensedItem.stackSize;
|
||||
return dispensedItem;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
@@ -29,20 +30,21 @@ import net.minecraft.world.WorldServer;
|
||||
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
final public class DispenserBlockTool extends BehaviorDefaultDispenseItem
|
||||
{
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseStack(IBlockSource dispenser, ItemStack dispensedItem)
|
||||
protected ItemStack dispenseStack( IBlockSource dispenser, ItemStack dispensedItem )
|
||||
{
|
||||
Item i = dispensedItem.getItem();
|
||||
if ( i instanceof IBlockTool )
|
||||
if( i instanceof IBlockTool )
|
||||
{
|
||||
EnumFacing enumfacing = BlockDispenser.func_149937_b( dispenser.getBlockMetadata() );
|
||||
IBlockTool tm = (IBlockTool) i;
|
||||
|
||||
World w = dispenser.getWorld();
|
||||
if ( w instanceof WorldServer )
|
||||
if( w instanceof WorldServer )
|
||||
{
|
||||
int x = dispenser.getXInt() + enumfacing.getFrontOffsetX();
|
||||
int y = dispenser.getYInt() + enumfacing.getFrontOffsetY();
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
|
||||
import net.minecraft.block.BlockDispenser;
|
||||
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
|
||||
import net.minecraft.dispenser.IBlockSource;
|
||||
@@ -32,27 +33,28 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.items.tools.powered.ToolMassCannon;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
final public class DispenserMatterCannon extends BehaviorDefaultDispenseItem
|
||||
{
|
||||
|
||||
@Override
|
||||
protected ItemStack dispenseStack(IBlockSource dispenser, ItemStack dispensedItem)
|
||||
protected ItemStack dispenseStack( IBlockSource dispenser, ItemStack dispensedItem )
|
||||
{
|
||||
Item i = dispensedItem.getItem();
|
||||
if ( i instanceof ToolMassCannon )
|
||||
if( i instanceof ToolMassCannon )
|
||||
{
|
||||
EnumFacing enumfacing = BlockDispenser.func_149937_b( dispenser.getBlockMetadata() );
|
||||
ForgeDirection dir = ForgeDirection.UNKNOWN;
|
||||
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
|
||||
for( ForgeDirection d : ForgeDirection.VALID_DIRECTIONS )
|
||||
{
|
||||
if ( enumfacing.getFrontOffsetX() == d.offsetX && enumfacing.getFrontOffsetY() == d.offsetY && enumfacing.getFrontOffsetZ() == d.offsetZ )
|
||||
if( enumfacing.getFrontOffsetX() == d.offsetX && enumfacing.getFrontOffsetY() == d.offsetY && enumfacing.getFrontOffsetZ() == d.offsetZ )
|
||||
dir = d;
|
||||
}
|
||||
|
||||
ToolMassCannon tm = (ToolMassCannon) i;
|
||||
|
||||
World w = dispenser.getWorld();
|
||||
if ( w instanceof WorldServer )
|
||||
if( w instanceof WorldServer )
|
||||
{
|
||||
EntityPlayer p = Platform.getPlayer( (WorldServer) w );
|
||||
Platform.configurePlayer( p, dir, dispenser.getBlockTileEntity() );
|
||||
|
||||
@@ -18,13 +18,14 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
public interface IBlockTool
|
||||
{
|
||||
|
||||
boolean onItemUse(ItemStack dispensedItem, EntityPlayer player, World w, int x, int y, int z, int ordinal, float hitX, float hitY, float hitZ);
|
||||
|
||||
boolean onItemUse( ItemStack dispensedItem, EntityPlayer player, World w, int x, int y, int z, int ordinal, float hitX, float hitY, float hitZ );
|
||||
}
|
||||
|
||||
@@ -57,111 +57,64 @@ import appeng.me.NetworkList;
|
||||
import appeng.tile.AEBaseTile;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class TickHandler
|
||||
{
|
||||
|
||||
static class HandlerRep
|
||||
{
|
||||
|
||||
public Queue<AEBaseTile> tiles = new LinkedList<AEBaseTile>();
|
||||
|
||||
public Collection<Grid> networks = new NetworkList();
|
||||
|
||||
public void clear()
|
||||
{
|
||||
this.tiles = new LinkedList<AEBaseTile>();
|
||||
this.networks = new NetworkList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final TickHandler INSTANCE = new TickHandler();
|
||||
|
||||
final private WeakHashMap<World, Queue<Callable>> callQueue = new WeakHashMap<World, Queue<Callable>>();
|
||||
final Queue<Callable> serverQueue = new LinkedList<Callable>();
|
||||
|
||||
final Multimap<World, CraftingJob> craftingJobs = LinkedListMultimap.create();
|
||||
final private WeakHashMap<World, Queue<Callable>> callQueue = new WeakHashMap<World, Queue<Callable>>();
|
||||
final private HandlerRep server = new HandlerRep();
|
||||
final private HandlerRep client = new HandlerRep();
|
||||
|
||||
static public class PlayerColor
|
||||
{
|
||||
|
||||
public final AEColor myColor;
|
||||
protected final int myEntity;
|
||||
protected int ticksLeft;
|
||||
|
||||
public PacketPaintedEntity getPacket()
|
||||
{
|
||||
return new PacketPaintedEntity( this.myEntity, this.myColor, this.ticksLeft );
|
||||
}
|
||||
|
||||
public PlayerColor(int id, AEColor col, int ticks) {
|
||||
this.myEntity = id;
|
||||
this.myColor = col;
|
||||
this.ticksLeft = ticks;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final private HashMap<Integer, PlayerColor> cliPlayerColors = new HashMap<Integer, PlayerColor>();
|
||||
final private HashMap<Integer, PlayerColor> srvPlayerColors = new HashMap<Integer, PlayerColor>();
|
||||
CableRenderMode crm = CableRenderMode.Standard;
|
||||
|
||||
public HashMap<Integer, PlayerColor> getPlayerColors()
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
if( Platform.isServer() )
|
||||
return this.srvPlayerColors;
|
||||
return this.cliPlayerColors;
|
||||
}
|
||||
|
||||
private void tickColors(HashMap<Integer, PlayerColor> playerSet)
|
||||
public void addCallable( World w, Callable c )
|
||||
{
|
||||
Iterator<PlayerColor> i = playerSet.values().iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
PlayerColor pc = i.next();
|
||||
if ( pc.ticksLeft <= 0 )
|
||||
i.remove();
|
||||
pc.ticksLeft--;
|
||||
}
|
||||
}
|
||||
|
||||
HandlerRep getRepo()
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
return this.server;
|
||||
return this.client;
|
||||
}
|
||||
|
||||
public void addCallable(World w, Callable c)
|
||||
{
|
||||
if ( w == null )
|
||||
if( w == null )
|
||||
this.serverQueue.add( c );
|
||||
else
|
||||
{
|
||||
Queue<Callable> queue = this.callQueue.get( w );
|
||||
|
||||
if ( queue == null )
|
||||
if( queue == null )
|
||||
this.callQueue.put( w, queue = new LinkedList<Callable>() );
|
||||
|
||||
queue.add( c );
|
||||
}
|
||||
}
|
||||
|
||||
public void addInit(AEBaseTile tile)
|
||||
public void addInit( AEBaseTile tile )
|
||||
{
|
||||
if ( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
||||
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
||||
this.getRepo().tiles.add( tile );
|
||||
}
|
||||
|
||||
public void addNetwork(Grid grid)
|
||||
HandlerRep getRepo()
|
||||
{
|
||||
if ( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
||||
if( Platform.isServer() )
|
||||
return this.server;
|
||||
return this.client;
|
||||
}
|
||||
|
||||
public void addNetwork( Grid grid )
|
||||
{
|
||||
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
||||
this.getRepo().networks.add( grid );
|
||||
}
|
||||
|
||||
public void removeNetwork(Grid grid)
|
||||
public void removeNetwork( Grid grid )
|
||||
{
|
||||
if ( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
||||
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
||||
this.getRepo().networks.remove( grid );
|
||||
}
|
||||
|
||||
@@ -176,70 +129,68 @@ public class TickHandler
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void unloadWorld(WorldEvent.Unload ev)
|
||||
public void unloadWorld( WorldEvent.Unload ev )
|
||||
{
|
||||
if ( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
||||
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
|
||||
{
|
||||
LinkedList<IGridNode> toDestroy = new LinkedList<IGridNode>();
|
||||
|
||||
for (Grid g : this.getRepo().networks)
|
||||
for( Grid g : this.getRepo().networks )
|
||||
{
|
||||
for (IGridNode n : g.getNodes())
|
||||
for( IGridNode n : g.getNodes() )
|
||||
{
|
||||
if ( n.getWorld() == ev.world )
|
||||
if( n.getWorld() == ev.world )
|
||||
toDestroy.add( n );
|
||||
}
|
||||
}
|
||||
|
||||
for (IGridNode n : toDestroy)
|
||||
for( IGridNode n : toDestroy )
|
||||
n.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onChunkLoad(ChunkEvent.Load load)
|
||||
public void onChunkLoad( ChunkEvent.Load load )
|
||||
{
|
||||
for (Object te : load.getChunk().chunkTileEntityMap.values())
|
||||
for( Object te : load.getChunk().chunkTileEntityMap.values() )
|
||||
{
|
||||
if ( te instanceof AEBaseTile )
|
||||
if( te instanceof AEBaseTile )
|
||||
{
|
||||
((AEBaseTile) te).onChunkLoad();
|
||||
( (AEBaseTile) te ).onChunkLoad();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CableRenderMode crm = CableRenderMode.Standard;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTick(TickEvent ev)
|
||||
public void onTick( TickEvent ev )
|
||||
{
|
||||
|
||||
if ( ev.type == Type.CLIENT && ev.phase == Phase.START )
|
||||
if( ev.type == Type.CLIENT && ev.phase == Phase.START )
|
||||
{
|
||||
this.tickColors( this.cliPlayerColors );
|
||||
EntityFloatingItem.ageStatic = (EntityFloatingItem.ageStatic + 1) % 60000;
|
||||
EntityFloatingItem.ageStatic = ( EntityFloatingItem.ageStatic + 1 ) % 60000;
|
||||
CableRenderMode currentMode = AEApi.instance().partHelper().getCableRenderMode();
|
||||
if ( currentMode != this.crm )
|
||||
if( currentMode != this.crm )
|
||||
{
|
||||
this.crm = currentMode;
|
||||
CommonHelper.proxy.triggerUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ev.type == Type.WORLD && ev.phase == Phase.END )
|
||||
if( ev.type == Type.WORLD && ev.phase == Phase.END )
|
||||
{
|
||||
WorldTickEvent wte = (WorldTickEvent) ev;
|
||||
synchronized (this.craftingJobs)
|
||||
synchronized( this.craftingJobs )
|
||||
{
|
||||
Collection<CraftingJob> jobSet = this.craftingJobs.get( wte.world );
|
||||
if ( !jobSet.isEmpty() )
|
||||
if( !jobSet.isEmpty() )
|
||||
{
|
||||
int simTime = Math.max( 1, AEConfig.instance.craftingCalculationTimePerTick / jobSet.size() );
|
||||
Iterator<CraftingJob> i = jobSet.iterator();
|
||||
while (i.hasNext())
|
||||
while( i.hasNext() )
|
||||
{
|
||||
CraftingJob cj = i.next();
|
||||
if ( !cj.simulateFor( simTime ) )
|
||||
if( !cj.simulateFor( simTime ) )
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
@@ -247,20 +198,20 @@ public class TickHandler
|
||||
}
|
||||
|
||||
// for no there is no reason to care about this on the client...
|
||||
else if ( ev.type == Type.SERVER && ev.phase == Phase.END )
|
||||
else if( ev.type == Type.SERVER && ev.phase == Phase.END )
|
||||
{
|
||||
this.tickColors( this.srvPlayerColors );
|
||||
// ready tiles.
|
||||
HandlerRep repo = this.getRepo();
|
||||
while (!repo.tiles.isEmpty())
|
||||
while( !repo.tiles.isEmpty() )
|
||||
{
|
||||
AEBaseTile bt = repo.tiles.poll();
|
||||
if ( !bt.isInvalid() )
|
||||
if( !bt.isInvalid() )
|
||||
bt.onReady();
|
||||
}
|
||||
|
||||
// tick networks.
|
||||
for (Grid g : this.getRepo().networks)
|
||||
for( Grid g : this.getRepo().networks )
|
||||
g.update();
|
||||
|
||||
// cross world queue.
|
||||
@@ -268,30 +219,42 @@ public class TickHandler
|
||||
}
|
||||
|
||||
// world synced queue(s)
|
||||
if ( ev.type == Type.WORLD && ev.phase == Phase.START )
|
||||
if( ev.type == Type.WORLD && ev.phase == Phase.START )
|
||||
{
|
||||
this.processQueue( this.callQueue.get( ((WorldTickEvent) ev).world ) );
|
||||
this.processQueue( this.callQueue.get( ( (WorldTickEvent) ev ).world ) );
|
||||
}
|
||||
}
|
||||
|
||||
private void processQueue(Queue<Callable> queue)
|
||||
private void tickColors( HashMap<Integer, PlayerColor> playerSet )
|
||||
{
|
||||
if ( queue == null )
|
||||
Iterator<PlayerColor> i = playerSet.values().iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
PlayerColor pc = i.next();
|
||||
if( pc.ticksLeft <= 0 )
|
||||
i.remove();
|
||||
pc.ticksLeft--;
|
||||
}
|
||||
}
|
||||
|
||||
private void processQueue( Queue<Callable> queue )
|
||||
{
|
||||
if( queue == null )
|
||||
return;
|
||||
|
||||
Stopwatch sw = Stopwatch.createStarted();
|
||||
|
||||
Callable c = null;
|
||||
while ((c = queue.poll()) != null)
|
||||
while( ( c = queue.poll() ) != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
c.call();
|
||||
|
||||
if ( sw.elapsed( TimeUnit.MILLISECONDS ) > 50 )
|
||||
if( sw.elapsed( TimeUnit.MILLISECONDS ) > 50 )
|
||||
break;
|
||||
}
|
||||
catch (Exception e)
|
||||
catch( Exception e )
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
@@ -302,14 +265,46 @@ public class TickHandler
|
||||
// AELog.info( "processQueue Time: " + time + "ms" );
|
||||
}
|
||||
|
||||
final Multimap<World, CraftingJob> craftingJobs = LinkedListMultimap.create();
|
||||
|
||||
public void registerCraftingSimulation(World world, CraftingJob craftingJob)
|
||||
public void registerCraftingSimulation( World world, CraftingJob craftingJob )
|
||||
{
|
||||
synchronized (this.craftingJobs)
|
||||
synchronized( this.craftingJobs )
|
||||
{
|
||||
this.craftingJobs.put( world, craftingJob );
|
||||
}
|
||||
}
|
||||
|
||||
static class HandlerRep
|
||||
{
|
||||
|
||||
public Queue<AEBaseTile> tiles = new LinkedList<AEBaseTile>();
|
||||
|
||||
public Collection<Grid> networks = new NetworkList();
|
||||
|
||||
public void clear()
|
||||
{
|
||||
this.tiles = new LinkedList<AEBaseTile>();
|
||||
this.networks = new NetworkList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public class PlayerColor
|
||||
{
|
||||
|
||||
public final AEColor myColor;
|
||||
protected final int myEntity;
|
||||
protected int ticksLeft;
|
||||
|
||||
public PlayerColor( int id, AEColor col, int ticks )
|
||||
{
|
||||
this.myEntity = id;
|
||||
this.myColor = col;
|
||||
this.ticksLeft = ticks;
|
||||
}
|
||||
|
||||
public PacketPaintedEntity getPacket()
|
||||
{
|
||||
return new PacketPaintedEntity( this.myEntity, this.myColor, this.ticksLeft );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user