reformatted all src files (#141)

This commit is contained in:
YoungOnion
2022-09-17 05:08:02 -06:00
committed by GitHub
parent 3328bfcda2
commit 9011273229
1056 changed files with 88127 additions and 110597 deletions
+72 -73
View File
@@ -21,79 +21,78 @@ package appeng.hooks;
// TODO Villager Trading!??!?!
public class AETrading
{
public class AETrading {
/*
* @Override
* public void manipulateTradesForVillager( EntityVillager villager, MerchantRecipeList recipeList, Random random )
* {
* final IMaterials materials = AEApi.instance().definitions().materials();
* this.addMerchant( recipeList, materials.silicon(), 1, random, 2 );
* this.addMerchant( recipeList, materials.certusQuartzCrystal(), 2, random, 4 );
* this.addMerchant( recipeList, materials.certusQuartzDust(), 1, random, 3 );
* this.addTrade( recipeList, materials.certusQuartzDust(), materials.certusQuartzCrystal(), random, 2 );
* }
* private void addMerchant( MerchantRecipeList list, IItemDefinition item, int emera, Random rand, int greed )
* {
* 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 mood = rand.nextInt() % 2;
* from.stackSize = multiplier + mood;
* to.stackSize = multiplier * emeraldCost - mood;
* if( to.stackSize < 0 )
* {
* from.stackSize -= to.stackSize;
* to.stackSize -= to.stackSize;
* }
* this.addToList( list, from, to );
* // Buy
* ItemStack reverseTo = from.copy();
* ItemStack reverseFrom = to.copy();
* reverseFrom.stackSize *= rand.nextFloat() * 3.0f + 1.0f;
* this.addToList( list, reverseFrom, reverseTo );
* }
* }
* private void addTrade( MerchantRecipeList list, IItemDefinition inputDefinition, IItemDefinition
* outputDefinition, Random rand, int conversionVariance )
* {
* 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 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 ) );
* }
*/
/*
* @Override
* public void manipulateTradesForVillager( EntityVillager villager, MerchantRecipeList recipeList, Random random )
* {
* final IMaterials materials = AEApi.instance().definitions().materials();
* this.addMerchant( recipeList, materials.silicon(), 1, random, 2 );
* this.addMerchant( recipeList, materials.certusQuartzCrystal(), 2, random, 4 );
* this.addMerchant( recipeList, materials.certusQuartzDust(), 1, random, 3 );
* this.addTrade( recipeList, materials.certusQuartzDust(), materials.certusQuartzCrystal(), random, 2 );
* }
* private void addMerchant( MerchantRecipeList list, IItemDefinition item, int emera, Random rand, int greed )
* {
* 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 mood = rand.nextInt() % 2;
* from.stackSize = multiplier + mood;
* to.stackSize = multiplier * emeraldCost - mood;
* if( to.stackSize < 0 )
* {
* from.stackSize -= to.stackSize;
* to.stackSize -= to.stackSize;
* }
* this.addToList( list, from, to );
* // Buy
* ItemStack reverseTo = from.copy();
* ItemStack reverseFrom = to.copy();
* reverseFrom.stackSize *= rand.nextFloat() * 3.0f + 1.0f;
* this.addToList( list, reverseFrom, reverseTo );
* }
* }
* private void addTrade( MerchantRecipeList list, IItemDefinition inputDefinition, IItemDefinition
* outputDefinition, Random rand, int conversionVariance )
* {
* 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 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 ) );
* }
*/
}
+67 -83
View File
@@ -19,104 +19,88 @@
package appeng.hooks;
import java.util.HashMap;
import java.util.Iterator;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketCompassRequest;
import java.util.HashMap;
import java.util.Iterator;
public class CompassManager
{
public static final CompassManager INSTANCE = new CompassManager();
private final HashMap<CompassRequest, CompassResult> requests = new HashMap<>();
public class CompassManager {
public void postResult( final long attunement, final int x, final int y, final int z, final CompassResult result )
{
final CompassRequest r = new CompassRequest( attunement, x, y, z );
this.requests.put( r, result );
}
public static final CompassManager INSTANCE = new CompassManager();
private final HashMap<CompassRequest, CompassResult> requests = new HashMap<>();
public CompassResult getCompassDirection( final long attunement, final int x, final int y, final int z )
{
final long now = System.currentTimeMillis();
public void postResult(final long attunement, final int x, final int y, final int z, final CompassResult result) {
final CompassRequest r = new CompassRequest(attunement, x, y, z);
this.requests.put(r, result);
}
final Iterator<CompassResult> i = this.requests.values().iterator();
while( i.hasNext() )
{
final CompassResult res = i.next();
final long diff = now - res.getTime();
if( diff > 20000 )
{
i.remove();
}
}
public CompassResult getCompassDirection(final long attunement, final int x, final int y, final int z) {
final long now = System.currentTimeMillis();
final CompassRequest r = new CompassRequest( attunement, x, y, z );
CompassResult res = this.requests.get( r );
final Iterator<CompassResult> i = this.requests.values().iterator();
while (i.hasNext()) {
final CompassResult res = i.next();
final long diff = now - res.getTime();
if (diff > 20000) {
i.remove();
}
}
if( res == null )
{
res = new CompassResult( false, true, 0 );
this.requests.put( r, res );
this.requestUpdate( r );
}
else if( now - res.getTime() > 1000 * 3 )
{
if( !res.isRequested() )
{
res.setRequested( true );
this.requestUpdate( r );
}
}
final CompassRequest r = new CompassRequest(attunement, x, y, z);
CompassResult res = this.requests.get(r);
return res;
}
if (res == null) {
res = new CompassResult(false, true, 0);
this.requests.put(r, res);
this.requestUpdate(r);
} else if (now - res.getTime() > 1000 * 3) {
if (!res.isRequested()) {
res.setRequested(true);
this.requestUpdate(r);
}
}
private void requestUpdate( final CompassRequest r )
{
NetworkHandler.instance().sendToServer( new PacketCompassRequest( r.attunement, r.cx, r.cz, r.cdy ) );
}
return res;
}
private static class CompassRequest
{
private void requestUpdate(final CompassRequest r) {
NetworkHandler.instance().sendToServer(new PacketCompassRequest(r.attunement, r.cx, r.cz, r.cdy));
}
private final int hash;
private final long attunement;
private final int cx;
private final int cdy;
private final int cz;
private static class CompassRequest {
public CompassRequest( final long attunement, final int x, final int y, final 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();
}
private final int hash;
private final long attunement;
private final int cx;
private final int cdy;
private final int cz;
@Override
public int hashCode()
{
return this.hash;
}
public CompassRequest(final long attunement, final int x, final int y, final 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();
}
@Override
public boolean equals( final Object obj )
{
if( obj == null )
{
return false;
}
if( this.getClass() != obj.getClass() )
{
return false;
}
final CompassRequest other = (CompassRequest) obj;
return this.attunement == other.attunement && this.cx == other.cx && this.cdy == other.cdy && this.cz == other.cz;
}
}
@Override
public int hashCode() {
return this.hash;
}
@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (this.getClass() != obj.getClass()) {
return false;
}
final CompassRequest other = (CompassRequest) obj;
return this.attunement == other.attunement && this.cx == other.cx && this.cdy == other.cdy && this.cz == other.cz;
}
}
}
+30 -38
View File
@@ -19,50 +19,42 @@
package appeng.hooks;
public class CompassResult
{
public class CompassResult {
private final boolean hasResult;
private final boolean spin;
private final double rad;
private final long time;
private boolean requested = false;
private final boolean hasResult;
private final boolean spin;
private final double rad;
private final long time;
private boolean requested = false;
public CompassResult( final boolean hasResult, final boolean spin, final double rad )
{
this.hasResult = hasResult;
this.spin = spin;
this.rad = rad;
this.time = System.currentTimeMillis();
}
public CompassResult(final boolean hasResult, final boolean spin, final double rad) {
this.hasResult = hasResult;
this.spin = spin;
this.rad = rad;
this.time = System.currentTimeMillis();
}
public boolean isValidResult()
{
return this.hasResult;
}
public boolean isValidResult() {
return this.hasResult;
}
public boolean isSpin()
{
return this.spin;
}
public boolean isSpin() {
return this.spin;
}
public double getRad()
{
return this.rad;
}
public double getRad() {
return this.rad;
}
boolean isRequested()
{
return this.requested;
}
boolean isRequested() {
return this.requested;
}
void setRequested( final boolean requested )
{
this.requested = requested;
}
void setRequested(final boolean requested) {
this.requested = requested;
}
long getTime()
{
return this.time;
}
long getTime() {
return this.time;
}
}
@@ -19,6 +19,7 @@
package appeng.hooks;
import appeng.entity.EntityTinyTNTPrimed;
import net.minecraft.block.BlockDispenser;
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
import net.minecraft.dispenser.IBlockSource;
@@ -26,23 +27,19 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import appeng.entity.EntityTinyTNTPrimed;
public final class DispenserBehaviorTinyTNT extends BehaviorDefaultDispenseItem {
public final class DispenserBehaviorTinyTNT extends BehaviorDefaultDispenseItem
{
@Override
protected ItemStack dispenseStack( final IBlockSource dispenser, final ItemStack dispensedItem )
{
final EnumFacing enumfacing = dispenser.getBlockState().getValue( BlockDispenser.FACING );
final World world = dispenser.getWorld();
final int i = dispenser.getBlockPos().getX() + enumfacing.getFrontOffsetX();
final int j = dispenser.getBlockPos().getY() + enumfacing.getFrontOffsetY();
final int k = dispenser.getBlockPos().getZ() + enumfacing.getFrontOffsetZ();
final EntityTinyTNTPrimed primedTinyTNTEntity = new EntityTinyTNTPrimed( world, i + 0.5F, j + 0.5F, k + 0.5F, null );
world.spawnEntity( primedTinyTNTEntity );
dispensedItem.setCount( dispensedItem.getCount() - 1 );
return dispensedItem;
}
@Override
protected ItemStack dispenseStack(final IBlockSource dispenser, final ItemStack dispensedItem) {
final EnumFacing enumfacing = dispenser.getBlockState().getValue(BlockDispenser.FACING);
final World world = dispenser.getWorld();
final int i = dispenser.getBlockPos().getX() + enumfacing.getFrontOffsetX();
final int j = dispenser.getBlockPos().getY() + enumfacing.getFrontOffsetY();
final int k = dispenser.getBlockPos().getZ() + enumfacing.getFrontOffsetZ();
final EntityTinyTNTPrimed primedTinyTNTEntity = new EntityTinyTNTPrimed(world, i + 0.5F, j + 0.5F, k + 0.5F, null);
world.spawnEntity(primedTinyTNTEntity);
dispensedItem.setCount(dispensedItem.getCount() - 1);
return dispensedItem;
}
}
@@ -19,6 +19,7 @@
package appeng.hooks;
import appeng.util.Platform;
import net.minecraft.block.BlockDispenser;
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
import net.minecraft.dispenser.IBlockSource;
@@ -29,28 +30,22 @@ import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import appeng.util.Platform;
public final class DispenserBlockTool extends BehaviorDefaultDispenseItem {
public final class DispenserBlockTool extends BehaviorDefaultDispenseItem
{
@Override
protected ItemStack dispenseStack(final IBlockSource dispenser, final ItemStack dispensedItem) {
final Item i = dispensedItem.getItem();
if (i instanceof IBlockTool) {
final EnumFacing enumfacing = dispenser.getBlockState().getValue(BlockDispenser.FACING);
final IBlockTool tm = (IBlockTool) i;
@Override
protected ItemStack dispenseStack( final IBlockSource dispenser, final ItemStack dispensedItem )
{
final Item i = dispensedItem.getItem();
if( i instanceof IBlockTool )
{
final EnumFacing enumfacing = dispenser.getBlockState().getValue( BlockDispenser.FACING );
final IBlockTool tm = (IBlockTool) i;
final World w = dispenser.getWorld();
if( w instanceof WorldServer )
{
tm.onItemUse( dispensedItem, Platform.getPlayer( (WorldServer) w ), w, dispenser.getBlockPos().offset( enumfacing ), EnumHand.MAIN_HAND,
enumfacing, 0.5f, 0.5f, 0.5f );
}
}
return dispensedItem;
}
final World w = dispenser.getWorld();
if (w instanceof WorldServer) {
tm.onItemUse(dispensedItem, Platform.getPlayer((WorldServer) w), w, dispenser.getBlockPos().offset(enumfacing), EnumHand.MAIN_HAND,
enumfacing, 0.5f, 0.5f, 0.5f);
}
}
return dispensedItem;
}
}
@@ -19,6 +19,9 @@
package appeng.hooks;
import appeng.api.util.AEPartLocation;
import appeng.items.tools.powered.ToolMatterCannon;
import appeng.util.Platform;
import net.minecraft.block.BlockDispenser;
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
import net.minecraft.dispenser.IBlockSource;
@@ -29,45 +32,35 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import appeng.api.util.AEPartLocation;
import appeng.items.tools.powered.ToolMatterCannon;
import appeng.util.Platform;
public final class DispenserMatterCannon extends BehaviorDefaultDispenseItem {
public final class DispenserMatterCannon extends BehaviorDefaultDispenseItem
{
@Override
protected ItemStack dispenseStack(final IBlockSource dispenser, ItemStack dispensedItem) {
final Item i = dispensedItem.getItem();
if (i instanceof ToolMatterCannon) {
final EnumFacing enumfacing = dispenser.getBlockState().getValue(BlockDispenser.FACING);
AEPartLocation dir = AEPartLocation.INTERNAL;
for (final AEPartLocation d : AEPartLocation.SIDE_LOCATIONS) {
if (enumfacing.getFrontOffsetX() == d.xOffset && enumfacing.getFrontOffsetY() == d.yOffset && enumfacing.getFrontOffsetZ() == d.zOffset) {
dir = d;
}
}
@Override
protected ItemStack dispenseStack( final IBlockSource dispenser, ItemStack dispensedItem )
{
final Item i = dispensedItem.getItem();
if( i instanceof ToolMatterCannon )
{
final EnumFacing enumfacing = dispenser.getBlockState().getValue( BlockDispenser.FACING );
AEPartLocation dir = AEPartLocation.INTERNAL;
for( final AEPartLocation d : AEPartLocation.SIDE_LOCATIONS )
{
if( enumfacing.getFrontOffsetX() == d.xOffset && enumfacing.getFrontOffsetY() == d.yOffset && enumfacing.getFrontOffsetZ() == d.zOffset )
{
dir = d;
}
}
final ToolMatterCannon tm = (ToolMatterCannon) i;
final ToolMatterCannon tm = (ToolMatterCannon) i;
final World w = dispenser.getWorld();
if (w instanceof WorldServer) {
final EntityPlayer p = Platform.getPlayer((WorldServer) w);
Platform.configurePlayer(p, dir, dispenser.getBlockTileEntity());
final World w = dispenser.getWorld();
if( w instanceof WorldServer )
{
final EntityPlayer p = Platform.getPlayer( (WorldServer) w );
Platform.configurePlayer( p, dir, dispenser.getBlockTileEntity() );
p.posX += dir.xOffset;
p.posY += dir.yOffset;
p.posZ += dir.zOffset;
p.posX += dir.xOffset;
p.posY += dir.yOffset;
p.posZ += dir.zOffset;
dispensedItem = tm.onItemRightClick( w, p, null ).getResult();
}
}
return dispensedItem;
}
dispensedItem = tm.onItemRightClick(w, p, null).getResult();
}
}
return dispensedItem;
}
}
+4 -5
View File
@@ -28,11 +28,10 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public interface IBlockTool
{
// Workaround for dispenser logic.
EnumActionResult onItemUse( ItemStack is, EntityPlayer p, World w, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ );
public interface IBlockTool {
// Workaround for dispenser logic.
EnumActionResult onItemUse(ItemStack is, EntityPlayer p, World w, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ);
EnumActionResult onItemUse( EntityPlayer p, World w, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ );
EnumActionResult onItemUse(EntityPlayer p, World w, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ);
}
+208 -270
View File
@@ -19,30 +19,6 @@
package appeng.hooks;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Stopwatch;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
import net.minecraft.world.World;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
import net.minecraftforge.fml.common.gameevent.TickEvent.Type;
import net.minecraftforge.fml.common.gameevent.TickEvent.WorldTickEvent;
import appeng.api.AEApi;
import appeng.api.networking.IGridNode;
import appeng.api.parts.CableRenderMode;
@@ -56,291 +32,253 @@ import appeng.me.Grid;
import appeng.tile.AEBaseTile;
import appeng.util.IWorldCallable;
import appeng.util.Platform;
import com.google.common.base.Stopwatch;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
import net.minecraft.world.World;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
import net.minecraftforge.fml.common.gameevent.TickEvent.Type;
import net.minecraftforge.fml.common.gameevent.TickEvent.WorldTickEvent;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class TickHandler
{
public class TickHandler {
public static final TickHandler INSTANCE = new TickHandler();
private final Queue<IWorldCallable<?>> serverQueue = new ArrayDeque<>();
private final Multimap<World, CraftingJob> craftingJobs = LinkedListMultimap.create();
private final WeakHashMap<World, Queue<IWorldCallable<?>>> callQueue = new WeakHashMap<>();
private final HandlerRep server = new HandlerRep();
private final HandlerRep client = new HandlerRep();
private final HashMap<Integer, PlayerColor> cliPlayerColors = new HashMap<>();
private final HashMap<Integer, PlayerColor> srvPlayerColors = new HashMap<>();
private CableRenderMode crm = CableRenderMode.STANDARD;
public static final TickHandler INSTANCE = new TickHandler();
private final Queue<IWorldCallable<?>> serverQueue = new ArrayDeque<>();
private final Multimap<World, CraftingJob> craftingJobs = LinkedListMultimap.create();
private final WeakHashMap<World, Queue<IWorldCallable<?>>> callQueue = new WeakHashMap<>();
private final HandlerRep server = new HandlerRep();
private final HandlerRep client = new HandlerRep();
private final HashMap<Integer, PlayerColor> cliPlayerColors = new HashMap<>();
private final HashMap<Integer, PlayerColor> srvPlayerColors = new HashMap<>();
private CableRenderMode crm = CableRenderMode.STANDARD;
public HashMap<Integer, PlayerColor> getPlayerColors()
{
if( Platform.isServer() )
{
return this.srvPlayerColors;
}
return this.cliPlayerColors;
}
public HashMap<Integer, PlayerColor> getPlayerColors() {
if (Platform.isServer()) {
return this.srvPlayerColors;
}
return this.cliPlayerColors;
}
public void addCallable( final World w, final IWorldCallable<?> c )
{
if( w == null )
{
this.serverQueue.add( c );
}
else
{
Queue<IWorldCallable<?>> queue = this.callQueue.get( w );
public void addCallable(final World w, final IWorldCallable<?> c) {
if (w == null) {
this.serverQueue.add(c);
} else {
Queue<IWorldCallable<?>> queue = this.callQueue.get(w);
if( queue == null )
{
queue = new ArrayDeque<>();
this.callQueue.put( w, queue );
}
if (queue == null) {
queue = new ArrayDeque<>();
this.callQueue.put(w, queue);
}
queue.add( c );
}
}
queue.add(c);
}
}
public void addInit( final AEBaseTile tile )
{
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
{
this.getRepo().tiles.add( tile );
}
}
public void addInit(final AEBaseTile tile) {
if (Platform.isServer()) // for no there is no reason to care about this on the client...
{
this.getRepo().tiles.add(tile);
}
}
private HandlerRep getRepo()
{
if( Platform.isServer() )
{
return this.server;
}
return this.client;
}
private HandlerRep getRepo() {
if (Platform.isServer()) {
return this.server;
}
return this.client;
}
public void addNetwork( final Grid grid )
{
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
{
this.getRepo().addNetwork( grid );
}
}
public void addNetwork(final Grid grid) {
if (Platform.isServer()) // for no there is no reason to care about this on the client...
{
this.getRepo().addNetwork(grid);
}
}
public void removeNetwork( final Grid grid )
{
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
{
this.getRepo().removeNetwork( grid );
}
}
public void removeNetwork(final Grid grid) {
if (Platform.isServer()) // for no there is no reason to care about this on the client...
{
this.getRepo().removeNetwork(grid);
}
}
public Iterable<Grid> getGridList()
{
return this.getRepo().networks;
}
public Iterable<Grid> getGridList() {
return this.getRepo().networks;
}
public void shutdown()
{
this.getRepo().clear();
}
public void shutdown() {
this.getRepo().clear();
}
@SubscribeEvent
public void unloadWorld( final WorldEvent.Unload ev )
{
if( Platform.isServer() ) // for no there is no reason to care about this on the client...
{
final List<IGridNode> toDestroy = new ArrayList<>();
@SubscribeEvent
public void unloadWorld(final WorldEvent.Unload ev) {
if (Platform.isServer()) // for no there is no reason to care about this on the client...
{
final List<IGridNode> toDestroy = new ArrayList<>();
this.getRepo().updateNetworks();
for( final Grid g : this.getRepo().networks )
{
for( final IGridNode n : g.getNodes() )
{
if( n.getWorld() == ev.getWorld() )
{
toDestroy.add( n );
}
}
}
this.getRepo().updateNetworks();
for (final Grid g : this.getRepo().networks) {
for (final IGridNode n : g.getNodes()) {
if (n.getWorld() == ev.getWorld()) {
toDestroy.add(n);
}
}
}
for( final IGridNode n : toDestroy )
{
n.destroy();
}
}
}
for (final IGridNode n : toDestroy) {
n.destroy();
}
}
}
@SubscribeEvent
public void onTick( final TickEvent ev )
{
@SubscribeEvent
public void onTick(final TickEvent ev) {
if( ev.type == Type.CLIENT && ev.phase == Phase.START )
{
this.tickColors( this.cliPlayerColors );
final CableRenderMode currentMode = AEApi.instance().partHelper().getCableRenderMode();
if( currentMode != this.crm )
{
this.crm = currentMode;
AppEng.proxy.triggerUpdates();
}
}
if (ev.type == Type.CLIENT && ev.phase == Phase.START) {
this.tickColors(this.cliPlayerColors);
final CableRenderMode currentMode = AEApi.instance().partHelper().getCableRenderMode();
if (currentMode != this.crm) {
this.crm = currentMode;
AppEng.proxy.triggerUpdates();
}
}
if( ev.type == Type.WORLD && ev.phase == Phase.END )
{
final WorldTickEvent wte = (WorldTickEvent) ev;
synchronized ( this.craftingJobs )
{
final Collection<CraftingJob> jobSet = this.craftingJobs.get( wte.world );
if( !jobSet.isEmpty() )
{
final int jobSize = jobSet.size();
final int microSecondsPerTick = AEConfig.instance().getCraftingCalculationTimePerTick() * 1000;
final int simTime = Math.max( 1, microSecondsPerTick / jobSize );
if (ev.type == Type.WORLD && ev.phase == Phase.END) {
final WorldTickEvent wte = (WorldTickEvent) ev;
synchronized (this.craftingJobs) {
final Collection<CraftingJob> jobSet = this.craftingJobs.get(wte.world);
if (!jobSet.isEmpty()) {
final int jobSize = jobSet.size();
final int microSecondsPerTick = AEConfig.instance().getCraftingCalculationTimePerTick() * 1000;
final int simTime = Math.max(1, microSecondsPerTick / jobSize);
jobSet.removeIf( cj -> !cj.simulateFor( simTime ) );
}
}
}
jobSet.removeIf(cj -> !cj.simulateFor(simTime));
}
}
}
// for no there is no reason to care about this on the client...
else if( ev.type == Type.SERVER && ev.phase == Phase.END )
{
this.tickColors( this.srvPlayerColors );
// ready tiles.
final HandlerRep repo = this.getRepo();
while ( !repo.tiles.isEmpty() )
{
final AEBaseTile bt = repo.tiles.poll();
if( !bt.isInvalid() )
{
bt.onReady();
}
}
// for no there is no reason to care about this on the client...
else if (ev.type == Type.SERVER && ev.phase == Phase.END) {
this.tickColors(this.srvPlayerColors);
// ready tiles.
final HandlerRep repo = this.getRepo();
while (!repo.tiles.isEmpty()) {
final AEBaseTile bt = repo.tiles.poll();
if (!bt.isInvalid()) {
bt.onReady();
}
}
// tick networks.
this.getRepo().updateNetworks();
for( final Grid g : this.getRepo().networks )
{
g.update();
}
// tick networks.
this.getRepo().updateNetworks();
for (final Grid g : this.getRepo().networks) {
g.update();
}
// cross world queue.
this.processQueue( this.serverQueue, null );
}
// cross world queue.
this.processQueue(this.serverQueue, null);
}
// world synced queue(s)
if( ev.type == Type.WORLD && ev.phase == Phase.START )
{
final World world = ( (WorldTickEvent) ev ).world;
final Queue<IWorldCallable<?>> queue = this.callQueue.get( world );
this.processQueue( queue, world );
}
}
// world synced queue(s)
if (ev.type == Type.WORLD && ev.phase == Phase.START) {
final World world = ((WorldTickEvent) ev).world;
final Queue<IWorldCallable<?>> queue = this.callQueue.get(world);
this.processQueue(queue, world);
}
}
private void tickColors( final HashMap<Integer, PlayerColor> playerSet )
{
final Iterator<PlayerColor> i = playerSet.values().iterator();
while ( i.hasNext() )
{
final PlayerColor pc = i.next();
if( pc.ticksLeft <= 0 )
{
i.remove();
}
pc.ticksLeft--;
}
}
private void tickColors(final HashMap<Integer, PlayerColor> playerSet) {
final Iterator<PlayerColor> i = playerSet.values().iterator();
while (i.hasNext()) {
final PlayerColor pc = i.next();
if (pc.ticksLeft <= 0) {
i.remove();
}
pc.ticksLeft--;
}
}
private void processQueue( final Queue<IWorldCallable<?>> queue, final World world )
{
if( queue == null )
{
return;
}
private void processQueue(final Queue<IWorldCallable<?>> queue, final World world) {
if (queue == null) {
return;
}
final Stopwatch sw = Stopwatch.createStarted();
final Stopwatch sw = Stopwatch.createStarted();
IWorldCallable<?> c = null;
while ( ( c = queue.poll() ) != null )
{
try
{
c.call( world );
IWorldCallable<?> c = null;
while ((c = queue.poll()) != null) {
try {
c.call(world);
if( sw.elapsed( TimeUnit.MILLISECONDS ) > 50 )
{
break;
}
}
catch( final Exception e )
{
AELog.debug( e );
}
}
}
if (sw.elapsed(TimeUnit.MILLISECONDS) > 50) {
break;
}
} catch (final Exception e) {
AELog.debug(e);
}
}
}
public void registerCraftingSimulation( final World world, final CraftingJob craftingJob )
{
synchronized ( this.craftingJobs )
{
this.craftingJobs.put( world, craftingJob );
}
}
public void registerCraftingSimulation(final World world, final CraftingJob craftingJob) {
synchronized (this.craftingJobs) {
this.craftingJobs.put(world, craftingJob);
}
}
private static class HandlerRep
{
private static class HandlerRep {
private Queue<AEBaseTile> tiles = new ArrayDeque<>();
private Set<Grid> networks = new HashSet<>();
private Set<Grid> toAdd = new HashSet<>();
private Set<Grid> toRemove = new HashSet<>();
private Queue<AEBaseTile> tiles = new ArrayDeque<>();
private Set<Grid> networks = new HashSet<>();
private Set<Grid> toAdd = new HashSet<>();
private Set<Grid> toRemove = new HashSet<>();
private void clear()
{
this.tiles = new ArrayDeque<>();
this.networks = new HashSet<>();
this.toAdd = new HashSet<>();
this.toRemove = new HashSet<>();
}
private void clear() {
this.tiles = new ArrayDeque<>();
this.networks = new HashSet<>();
this.toAdd = new HashSet<>();
this.toRemove = new HashSet<>();
}
private synchronized void addNetwork( Grid g )
{
this.toAdd.add( g );
this.toRemove.remove( g );
}
private synchronized void addNetwork(Grid g) {
this.toAdd.add(g);
this.toRemove.remove(g);
}
private synchronized void removeNetwork( Grid g )
{
this.toRemove.add( g );
this.toAdd.remove( g );
}
private synchronized void removeNetwork(Grid g) {
this.toRemove.add(g);
this.toAdd.remove(g);
}
private synchronized void updateNetworks()
{
this.networks.removeAll( this.toRemove );
this.toRemove.clear();
private synchronized void updateNetworks() {
this.networks.removeAll(this.toRemove);
this.toRemove.clear();
this.networks.addAll( this.toAdd );
this.toAdd.clear();
}
}
this.networks.addAll(this.toAdd);
this.toAdd.clear();
}
}
public static class PlayerColor
{
public static class PlayerColor {
public final AEColor myColor;
private final int myEntity;
private int ticksLeft;
public final AEColor myColor;
private final int myEntity;
private int ticksLeft;
public PlayerColor( final int id, final AEColor col, final int ticks )
{
this.myEntity = id;
this.myColor = col;
this.ticksLeft = ticks;
}
public PlayerColor(final int id, final AEColor col, final int ticks) {
this.myEntity = id;
this.myColor = col;
this.ticksLeft = ticks;
}
public PacketPaintedEntity getPacket()
{
return new PacketPaintedEntity( this.myEntity, this.myColor, this.ticksLeft );
}
}
public PacketPaintedEntity getPacket() {
return new PacketPaintedEntity(this.myEntity, this.myColor, this.ticksLeft);
}
}
}