More moves and compilation fixes

This commit is contained in:
Sebastian Hartte
2020-06-29 02:15:31 +02:00
parent 3df93fc66d
commit 0d63f560d3
240 changed files with 2221 additions and 1926 deletions
@@ -1,30 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.services.compass;
public class CompassException extends RuntimeException {
private static final long serialVersionUID = 8825268683203860877L;
private final Throwable inner;
public CompassException(final Throwable t) {
this.inner = t;
}
}
@@ -1,70 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.services.compass;
import java.util.HashMap;
import java.util.Map;
import com.google.common.base.Preconditions;
import net.minecraft.server.world.ServerWorld;
public final class CompassReader {
private final Map<Long, CompassRegion> regions = new HashMap<>(100);
private final ServerWorld world;
public CompassReader(ServerWorld world) {
this.world = Preconditions.checkNotNull(world);
}
public void close() {
for (final CompassRegion r : this.regions.values()) {
r.close();
}
this.regions.clear();
}
public void setHasBeacon(final int cx, final int cz, final int cdy, final boolean hasBeacon) {
final CompassRegion r = this.getRegion(cx, cz);
r.setHasBeacon(cx, cz, cdy, hasBeacon);
}
public boolean hasBeacon(final int cx, final int cz) {
final CompassRegion r = this.getRegion(cx, cz);
return r.hasBeacon(cx, cz);
}
private CompassRegion getRegion(final int cx, final int cz) {
long pos = cx >> 10;
pos <<= 32;
pos |= (cz >> 10);
CompassRegion cr = this.regions.get(pos);
if (cr == null) {
cr = new CompassRegion(world, cx, cz);
this.regions.put(pos, cr);
}
return cr;
}
}
@@ -1,143 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.services.compass;
import com.google.common.base.Preconditions;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.storage.WorldSavedData;
final class CompassRegion {
private final int lowX;
private final int lowZ;
private final ServerWorld world;
private SaveData data;
public CompassRegion(ServerWorld world, final int cx, final int cz) {
Preconditions.checkNotNull(world);
this.world = world;
final int region_x = cx >> 10;
final int region_z = cz >> 10;
this.lowX = region_x << 10;
this.lowZ = region_z << 10;
this.openData(false);
}
void close() {
if (this.data != null) {
this.data = null;
}
}
boolean hasBeacon(int cx, int cz) {
if (this.data != null) {
cx &= 0x3FF;
cz &= 0x3FF;
final int val = this.read(cx, cz);
return val != 0;
}
return false;
}
void setHasBeacon(int cx, int cz, final int cdy, final boolean hasBeacon) {
cx &= 0x3FF;
cz &= 0x3FF;
this.openData(hasBeacon);
if (this.data != null) {
int val = this.read(cx, cz);
final int originalVal = val;
if (hasBeacon) {
val |= 1 << cdy;
} else {
val &= ~(1 << cdy);
}
if (originalVal != val) {
this.write(cx, cz, val);
}
}
}
private void openData(final boolean create) {
if (this.data != null) {
return;
}
String name = this.lowX + "_" + this.lowZ;
if (create) {
this.data = world.getSavedData().getOrCreate(() -> new SaveData(name), name);
if (this.data.bitmap == null) {
this.data.bitmap = new byte[SaveData.BITMAP_LENGTH];
}
} else {
this.data = world.getSavedData().get(() -> new SaveData(name), name);
}
}
private int read(final int cx, final int cz) {
try {
return this.data.bitmap[cx + cz * 0x400];
} catch (final IndexOutOfBoundsException outOfBounds) {
return 0;
}
}
private void write(final int cx, final int cz, final int val) {
this.data.bitmap[cx + cz * 0x400] = (byte) val;
this.data.markDirty();
}
private static class SaveData extends WorldSavedData {
private static final int BITMAP_LENGTH = 0x400 * 0x400;
private byte[] bitmap;
public SaveData(String name) {
super(name);
}
@Override
public void read(CompoundTag nbt) {
this.bitmap = nbt.getByteArray("b");
if (this.bitmap.length != BITMAP_LENGTH) {
throw new IllegalStateException("Invalid bitmap length: " + bitmap.length);
}
}
@Override
public CompoundTag write(CompoundTag compound) {
compound.putByteArray("b", bitmap);
return compound;
}
}
}
@@ -1,39 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.services.compass;
import java.util.concurrent.ThreadFactory;
import javax.annotation.Nonnull;
import com.google.common.base.Preconditions;
/**
* @author thatsIch
* @version rv3 - 31.05.2015
* @since rv3 31.05.2015
*/
public final class CompassThreadFactory implements ThreadFactory {
@Override
public Thread newThread(@Nonnull final Runnable job) {
Preconditions.checkNotNull(job);
return new Thread(job, "AE Compass Service");
}
}
@@ -1,32 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.services.compass;
public interface ICompassCallback {
/**
* Called from another thread.
*
* @param hasResult true if found a target
* @param spin true if should spin
* @param radians radians
* @param dist distance
*/
void calculatedDirection(boolean hasResult, boolean spin, double radians, double dist);
}