pick 97420a31d The big reformat of 2020

This commit is contained in:
yueh
2020-06-16 21:41:28 +02:00
parent 5304b3febe
commit 5225ea426b
2252 changed files with 95466 additions and 118582 deletions
+65 -82
View File
@@ -18,105 +18,88 @@
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 class CompassManager
{
public static final CompassManager INSTANCE = new CompassManager();
private final HashMap<CompassRequest, CompassResult> requests = new HashMap<>();
public static final CompassManager INSTANCE = new CompassManager();
private final HashMap<CompassRequest, CompassResult> requests = new HashMap<>();
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 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 CompassResult getCompassDirection(final long attunement, final int x, final int y, final int z) {
final long now = System.currentTimeMillis();
public CompassResult getCompassDirection( final long attunement, final int x, final int y, final int z )
{
final long now = System.currentTimeMillis();
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();
}
}
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();
}
}
final CompassRequest r = new CompassRequest(attunement, x, y, z);
CompassResult res = this.requests.get(r);
final 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.getTime() > 1000 * 3) {
if (!res.isRequested()) {
res.setRequested(true);
this.requestUpdate(r);
}
}
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 );
}
}
return res;
}
return res;
}
private void requestUpdate(final CompassRequest r) {
NetworkHandler.instance().sendToServer(new PacketCompassRequest(r.attunement, r.cx, r.cz, r.cdy));
}
private void requestUpdate( final CompassRequest r )
{
NetworkHandler.instance().sendToServer( new PacketCompassRequest( r.attunement, r.cx, r.cz, r.cdy ) );
}
private static class CompassRequest {
private static class CompassRequest
{
private final int hash;
private final long attunement;
private final int cx;
private final int cdy;
private final int cz;
private final int hash;
private final long attunement;
private final int cx;
private final int cdy;
private final int cz;
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();
}
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 int hashCode() {
return this.hash;
}
@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;
}
}
@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;
}
}
}