Merge remote-tracking branch 'origin/master' into fabric-1.16

# Conflicts:
#	src/main/java/appeng/block/spatial/SpatialPylonBlock.java
#	src/main/java/appeng/client/render/spatial/SpatialPylonBakedModel.java
#	src/main/java/appeng/core/AppEng.java
#	src/main/java/appeng/hooks/TickHandler.java
#	src/main/java/appeng/me/cluster/MBCalculator.java
#	src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java
#	src/main/java/appeng/me/cluster/implementations/QuantumCluster.java
#	src/main/java/appeng/me/cluster/implementations/SpatialPylonCluster.java
#	src/main/java/appeng/me/helpers/AENetworkProxy.java
#	src/main/java/appeng/tile/networking/CableBusBlockEntity.java
#	src/main/java/appeng/tile/networking/DenseEnergyCellBlockEntity.java
#	src/main/java/appeng/tile/qnb/QuantumBridgeBlockEntity.java
#	src/main/java/appeng/tile/spatial/SpatialPylonBlockEntity.java
#	src/main/java/appeng/util/Platform.java
This commit is contained in:
Sebastian Hartte
2020-07-19 01:05:14 +02:00
34 changed files with 1018 additions and 133 deletions
+2 -2
View File
@@ -64,7 +64,7 @@ public class Grid implements IGrid {
this.postEvent(new MENetworkPostCacheConstruction());
TickHandler.INSTANCE.addNetwork(this);
TickHandler.instance().addNetwork(this);
center.setGrid(this);
}
@@ -112,7 +112,7 @@ public class Grid implements IGrid {
this.pivot = (GridNode) n.next();
} else {
this.pivot = null;
TickHandler.INSTANCE.removeNetwork(this);
TickHandler.instance().removeNetwork(this);
this.myStorage.remove();
}
}
+2 -2
View File
@@ -384,7 +384,7 @@ public class GridNode implements IGridNode, IPathItem {
GridConnection.create(node, this, f.getOpposite());
} catch (SecurityConnectionException e) {
AELog.debug(e);
TickHandler.INSTANCE.addCallable(node.getWorld(), new MachineSecurityBreak(this));
TickHandler.instance().addCallable(node.getWorld(), new MachineSecurityBreak(this));
return;
} catch (final FailedConnectionException e) {
@@ -411,7 +411,7 @@ public class GridNode implements IGridNode, IPathItem {
} catch (SecurityConnectionException e) {
AELog.debug(e);
TickHandler.INSTANCE.addCallable(node.getWorld(), new MachineSecurityBreak(this));
TickHandler.instance().addCallable(node.getWorld(), new MachineSecurityBreak(this));
return;
} catch (final FailedConnectionException e) {
+16 -3
View File
@@ -23,16 +23,18 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.NavigableSet;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.SortedSet;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
import com.google.common.collect.Sets;
import it.unimi.dsi.fastutil.objects.ObjectRBTreeSet;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
@@ -72,10 +74,15 @@ public class EnergyGridCache implements IEnergyGrid {
return Double.compare(percent1, percent2);
};
private static final Comparator<IAEPowerStorage> COMPARATOR_HIGHEST_PRIORITY_FIRST = (o1, o2) -> Integer
.compare(o2.getPriority(), o1.getPriority());
private static final Comparator<IAEPowerStorage> COMPARATOR_LOWEST_PRIORITY_FIRST = (o1, o2) -> Integer
.compare(o1.getPriority(), o2.getPriority());
private final NavigableSet<EnergyThreshold> interests = Sets.newTreeSet();
private final double averageLength = 40.0;
private final Set<IAEPowerStorage> providers = new LinkedHashSet<>();
private final Set<IAEPowerStorage> requesters = new LinkedHashSet<>();
private final SortedSet<IAEPowerStorage> providers = new ObjectRBTreeSet<>(COMPARATOR_HIGHEST_PRIORITY_FIRST);
private final SortedSet<IAEPowerStorage> requesters = new ObjectRBTreeSet<>(COMPARATOR_LOWEST_PRIORITY_FIRST);
private final Multiset<IEnergyGridProvider> energyGridProviders = HashMultiset.create();
private final IGrid myGrid;
private final HashMap<IGridNode, IEnergyWatcher> watchers = new HashMap<>();
@@ -572,6 +579,12 @@ public class EnergyGridCache implements IEnergyGrid {
return this.stored;
}
@Override
public int getPriority() {
// MIN_VALUE to push it to the back
return Integer.MIN_VALUE;
}
private void addCurrentAEPower(double amount) {
this.stored += amount;
+32 -20
View File
@@ -82,21 +82,21 @@ public class SpatialPylonCache implements ISpatialCache {
int pylonBlocks = 0;
for (final SpatialPylonCluster cl : this.clusters.values()) {
if (this.captureMax == null) {
this.captureMax = cl.getMax().copy();
this.captureMax = new DimensionalCoord(cl.getWorld(), cl.getBoundsMax());
}
if (this.captureMin == null) {
this.captureMin = cl.getMin().copy();
this.captureMin = new DimensionalCoord(cl.getWorld(), cl.getBoundsMin());
}
pylonBlocks += cl.tileCount();
this.captureMin.x = Math.min(this.captureMin.x, cl.getMin().x);
this.captureMin.y = Math.min(this.captureMin.y, cl.getMin().y);
this.captureMin.z = Math.min(this.captureMin.z, cl.getMin().z);
this.captureMin.x = Math.min(this.captureMin.x, cl.getBoundsMin().getX());
this.captureMin.y = Math.min(this.captureMin.y, cl.getBoundsMin().getY());
this.captureMin.z = Math.min(this.captureMin.z, cl.getBoundsMin().getZ());
this.captureMax.x = Math.max(this.captureMax.x, cl.getMax().x);
this.captureMax.y = Math.max(this.captureMax.y, cl.getMax().y);
this.captureMax.z = Math.max(this.captureMax.z, cl.getMax().z);
this.captureMax.x = Math.max(this.captureMax.x, cl.getBoundsMax().getX());
this.captureMax.y = Math.max(this.captureMax.y, cl.getBoundsMax().getY());
this.captureMax.z = Math.max(this.captureMax.z, cl.getBoundsMax().getZ());
}
double maxPower = 0;
@@ -110,28 +110,40 @@ public class SpatialPylonCache implements ISpatialCache {
case X:
this.isValid = this.isValid
&& ((this.captureMax.y == cl.getMin().y || this.captureMin.y == cl.getMax().y)
|| (this.captureMax.z == cl.getMin().z || this.captureMin.z == cl.getMax().z))
&& ((this.captureMax.y == cl.getMax().y || this.captureMin.y == cl.getMin().y)
|| (this.captureMax.z == cl.getMax().z || this.captureMin.z == cl.getMin().z));
&& ((this.captureMax.y == cl.getBoundsMin().getY()
|| this.captureMin.y == cl.getBoundsMax().getY())
|| (this.captureMax.z == cl.getBoundsMin().getZ()
|| this.captureMin.z == cl.getBoundsMax().getZ()))
&& ((this.captureMax.y == cl.getBoundsMax().getY()
|| this.captureMin.y == cl.getBoundsMin().getY())
|| (this.captureMax.z == cl.getBoundsMax().getZ()
|| this.captureMin.z == cl.getBoundsMin().getZ()));
break;
case Y:
this.isValid = this.isValid
&& ((this.captureMax.x == cl.getMin().x || this.captureMin.x == cl.getMax().x)
|| (this.captureMax.z == cl.getMin().z || this.captureMin.z == cl.getMax().z))
&& ((this.captureMax.x == cl.getMax().x || this.captureMin.x == cl.getMin().x)
|| (this.captureMax.z == cl.getMax().z || this.captureMin.z == cl.getMin().z));
&& ((this.captureMax.x == cl.getBoundsMin().getX()
|| this.captureMin.x == cl.getBoundsMax().getX())
|| (this.captureMax.z == cl.getBoundsMin().getZ()
|| this.captureMin.z == cl.getBoundsMax().getZ()))
&& ((this.captureMax.x == cl.getBoundsMax().getX()
|| this.captureMin.x == cl.getBoundsMin().getX())
|| (this.captureMax.z == cl.getBoundsMax().getZ()
|| this.captureMin.z == cl.getBoundsMin().getZ()));
break;
case Z:
this.isValid = this.isValid
&& ((this.captureMax.y == cl.getMin().y || this.captureMin.y == cl.getMax().y)
|| (this.captureMax.x == cl.getMin().x || this.captureMin.x == cl.getMax().x))
&& ((this.captureMax.y == cl.getMax().y || this.captureMin.y == cl.getMin().y)
|| (this.captureMax.x == cl.getMax().x || this.captureMin.x == cl.getMin().x));
&& ((this.captureMax.y == cl.getBoundsMin().getY()
|| this.captureMin.y == cl.getBoundsMax().getY())
|| (this.captureMax.x == cl.getBoundsMin().getX()
|| this.captureMin.x == cl.getBoundsMax().getX()))
&& ((this.captureMax.y == cl.getBoundsMax().getY()
|| this.captureMin.y == cl.getBoundsMin().getY())
|| (this.captureMax.x == cl.getBoundsMax().getX()
|| this.captureMin.x == cl.getBoundsMin().getX()));
break;
case UNFORMED:
@@ -20,13 +20,32 @@ package appeng.me.cluster;
import java.util.Iterator;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import appeng.api.networking.IGridHost;
public interface IAECluster {
/**
* The minimum x,y,z position still within the bounds of the cluster.
*/
BlockPos getBoundsMin();
/**
* The maximum x,y,z position still within the bounds of the cluster.
*/
BlockPos getBoundsMax();
void updateStatus(boolean updateGrid);
void destroy();
/**
* @return True if the cluster has been destroyed, but not yet removed from a
* tile entity. Usually true during destruction.
*/
boolean isDestroyed();
Iterator<IGridHost> getTiles();
}
@@ -18,6 +18,8 @@
package appeng.me.cluster;
import java.lang.ref.WeakReference;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
@@ -29,16 +31,65 @@ import appeng.util.Platform;
public abstract class MBCalculator {
private static WeakReference<IAECluster> modificationInProgress = new WeakReference<>(null);
private final IAEMultiBlock target;
public MBCalculator(final IAEMultiBlock t) {
this.target = t;
}
public void calculateMultiblock(final World world, final WorldCoord loc) {
if (Platform.isClient()) {
public static void setModificationInProgress(IAECluster cluster) {
IAECluster inProgress = modificationInProgress.get();
if (inProgress == cluster) {
return;
}
if (inProgress != null && cluster != null) {
throw new IllegalStateException("A modification is already in-progress for: " + inProgress);
}
modificationInProgress = new WeakReference<>(cluster);
}
public static boolean isModificationInProgress() {
return modificationInProgress.get() != null;
}
public void updateMultiblockAfterNeighborUpdate(final World world, final WorldCoord loc, BlockPos changedPos) {
boolean recheck;
IAECluster cluster = target.getCluster();
if (cluster != null) {
if (isWithinBounds(changedPos, cluster.getBoundsMin(), cluster.getBoundsMax())) {
// If the location is part of the current multiblock, always re-check
recheck = true;
} else {
// If the location is outside, only re-check if it would now be considered part
// of it
recheck = isValidTileAt(world, changedPos.getX(), changedPos.getY(), changedPos.getZ());
}
} else {
// Always recheck if the tile is not part of a cluster, because the adjacent
// block could have
// previously been a valid tile, but in a wrong placement, or the other way
// around.
recheck = true;
}
if (recheck) {
calculateMultiblock(world, loc);
}
}
public void calculateMultiblock(final World world, final WorldCoord loc) {
if (Platform.isClient() || isModificationInProgress()) {
return;
}
IAECluster currentCluster = target.getCluster();
if (currentCluster != null && currentCluster.isDestroyed()) {
return; // If we're still part of a cluster that is in the process of being destroyed,
// don't recalc.
}
try {
final WorldCoord min = loc.copy();
@@ -67,6 +118,7 @@ public abstract class MBCalculator {
if (this.checkMultiblockScale(min, max)) {
if (this.verifyUnownedRegion(world, min, max)) {
IAECluster c = this.createCluster(world, min, max);
setModificationInProgress(c);
try {
if (!this.verifyInternalStructure(world, min, max)) {
@@ -94,11 +146,21 @@ public abstract class MBCalculator {
}
} catch (final Throwable err) {
AELog.debug(err);
} finally {
setModificationInProgress(null);
}
this.disconnect();
}
private static boolean isWithinBounds(BlockPos pos, BlockPos boundsMin, BlockPos boundsMax) {
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
return (x >= boundsMin.getX() && y >= boundsMin.getY() && z >= boundsMin.getZ() && x <= boundsMax.getX()
&& y <= boundsMax.getY() && z <= boundsMax.getZ());
}
private boolean isValidTileAt(final World w, final int x, final int y, final int z) {
return this.isValidTile(w.getBlockEntity(new BlockPos(x, y, z)));
}
@@ -32,6 +32,7 @@ import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.util.math.BlockPos;
import net.minecraft.text.Text;
import net.minecraft.world.World;
@@ -70,6 +71,7 @@ import appeng.crafting.CraftingWatcher;
import appeng.crafting.MECraftingInventory;
import appeng.me.cache.CraftingGridCache;
import appeng.me.cluster.IAECluster;
import appeng.me.cluster.MBCalculator;
import appeng.me.helpers.MachineSource;
import appeng.tile.crafting.CraftingMonitorBlockEntity;
import appeng.tile.crafting.CraftingBlockEntity;
@@ -80,8 +82,8 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
private static final String LOG_MARK_AS_COMPLETE = "Completed job for %s.";
private final WorldCoord min;
private final WorldCoord max;
private final BlockPos boundsMin;
private final BlockPos boundsMax;
private final int[] usedOps = new int[3];
private final Map<ICraftingPatternDetails, TaskProgress> tasks = new HashMap<>();
// INSTANCE sate
@@ -112,11 +114,12 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
private long startItemCount;
private long remainingItemCount;
public CraftingCPUCluster(final WorldCoord min, final WorldCoord max) {
this.min = min;
this.max = max;
public CraftingCPUCluster(final WorldCoord boundsMin, final WorldCoord boundsMax) {
this.boundsMin = boundsMin.getBlockPos();
this.boundsMax = boundsMax.getBlockPos();
}
@Override
public boolean isDestroyed() {
return this.isDestroyed;
}
@@ -125,6 +128,16 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
return this.myLastLink;
}
@Override
public BlockPos getBoundsMin() {
return boundsMin;
}
@Override
public BlockPos getBoundsMax() {
return boundsMax;
}
/**
* add a new Listener to the monitor, be sure to properly remove yourself when
* your done.
@@ -160,19 +173,24 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
}
this.isDestroyed = true;
boolean posted = false;
MBCalculator.setModificationInProgress(this);
try {
boolean posted = false;
for (final CraftingBlockEntity r : this.tiles) {
final IGridNode n = r.getActionableNode();
if (n != null && !posted) {
final IGrid g = n.getGrid();
if (g != null) {
g.postEvent(new MENetworkCraftingCpuChange(n));
posted = true;
for (final CraftingBlockEntity r : this.tiles) {
final IGridNode n = r.getActionableNode();
if (n != null && !posted) {
final IGrid g = n.getGrid();
if (g != null) {
g.postEvent(new MENetworkCraftingCpuChange(n));
posted = true;
}
}
}
r.updateStatus(null);
r.updateStatus(null);
}
} finally {
MBCalculator.setModificationInProgress(null);
}
}
@@ -21,6 +21,7 @@ package appeng.me.cluster.implementations;
import java.util.Iterator;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
@@ -36,13 +37,14 @@ import appeng.core.AELog;
import appeng.core.Api;
import appeng.me.cache.helpers.ConnectionWrapper;
import appeng.me.cluster.IAECluster;
import appeng.me.cluster.MBCalculator;
import appeng.tile.qnb.QuantumBridgeBlockEntity;
import appeng.util.iterators.ChainedIterator;
public class QuantumCluster implements ILocatable, IAECluster {
private final WorldCoord min;
private final WorldCoord max;
private final BlockPos boundsMin;
private final BlockPos boundsMax;
private boolean isDestroyed = false;
private boolean updateStatus = true;
private QuantumBridgeBlockEntity[] Ring;
@@ -53,8 +55,8 @@ public class QuantumCluster implements ILocatable, IAECluster {
private QuantumBridgeBlockEntity center;
public QuantumCluster(final WorldCoord min, final WorldCoord max) {
this.min = min;
this.max = max;
this.boundsMin = min.getBlockPos();
this.boundsMax = max.getBlockPos();
this.setRing(new QuantumBridgeBlockEntity[8]);
}
@@ -185,6 +187,21 @@ public class QuantumCluster implements ILocatable, IAECluster {
return this.thisSide != 0;
}
@Override
public BlockPos getBoundsMin() {
return boundsMin;
}
@Override
public BlockPos getBoundsMax() {
return boundsMax;
}
@Override
public boolean isDestroyed() {
return isDestroyed;
}
@Override
public void destroy() {
if (this.isDestroyed) {
@@ -192,25 +209,30 @@ public class QuantumCluster implements ILocatable, IAECluster {
}
this.isDestroyed = true;
if (this.registered) {
// FIXME FABRIC -> onWorldUnload event
MBCalculator.setModificationInProgress(this);
try {
if (this.registered) {
// FIXME FABRIC -> onWorldUnload event
// FIXME FABRIC MinecraftForge.EVENT_BUS.unregister(this);
this.registered = false;
}
if (this.thisSide != 0) {
this.updateStatus(true);
LocatableEventAnnounce.EVENT.invoker().onLocatableAnnounce(this, LocatableEvent.UNREGISTER);
if (this.thisSide != 0) {
this.updateStatus(true);
LocatableEventAnnounce.EVENT.invoker().onLocatableAnnounce(this, LocatableEvent.UNREGISTER);
}
this.center.updateStatus(null, (byte) -1, this.isUpdateStatus());
for (final QuantumBridgeBlockEntity r : this.getRing()) {
r.updateStatus(null, (byte) -1, this.isUpdateStatus());
}
this.center = null;
this.setRing(new QuantumBridgeBlockEntity[8]);
} finally {
MBCalculator.setModificationInProgress(null);
}
this.center.updateStatus(null, (byte) -1, this.isUpdateStatus());
for (final QuantumBridgeBlockEntity r : this.getRing()) {
r.updateStatus(null, (byte) -1, this.isUpdateStatus());
}
this.center = null;
this.setRing(new QuantumBridgeBlockEntity[8]);
}
@Override
@@ -22,7 +22,6 @@ import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import appeng.api.util.DimensionalCoord;
import appeng.api.util.WorldCoord;
import appeng.me.cluster.IAECluster;
import appeng.me.cluster.IAEMultiBlock;
@@ -47,8 +46,7 @@ public class SpatialPylonCalculator extends MBCalculator {
@Override
public IAECluster createCluster(final World w, final WorldCoord min, final WorldCoord max) {
return new SpatialPylonCluster(new DimensionalCoord(w, min.x, min.y, min.z),
new DimensionalCoord(w, max.x, max.y, max.z));
return new SpatialPylonCluster(w, min.getBlockPos(), max.getBlockPos());
}
@Override
@@ -22,30 +22,35 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import appeng.api.networking.IGridHost;
import appeng.api.util.DimensionalCoord;
import appeng.me.cluster.IAECluster;
import appeng.me.cluster.MBCalculator;
import appeng.tile.spatial.SpatialPylonBlockEntity;
public class SpatialPylonCluster implements IAECluster {
private final DimensionalCoord min;
private final DimensionalCoord max;
private final World world;
private final BlockPos boundsMin;
private final BlockPos boundsMax;
private final List<SpatialPylonBlockEntity> line = new ArrayList<>();
private boolean isDestroyed = false;
private Axis currentAxis = Axis.UNFORMED;
private boolean isValid;
public SpatialPylonCluster(final DimensionalCoord min, final DimensionalCoord max) {
this.min = min.copy();
this.max = max.copy();
public SpatialPylonCluster(final World world, final BlockPos boundsMin, final BlockPos boundsMax) {
this.world = world;
this.boundsMin = boundsMin.toImmutable();
this.boundsMax = boundsMax.toImmutable();
if (this.getMin().x != this.getMax().x) {
if (this.getBoundsMin().getX() != this.getBoundsMax().getX()) {
this.setCurrentAxis(Axis.X);
} else if (this.getMin().y != this.getMax().y) {
} else if (this.getBoundsMin().getY() != this.getBoundsMax().getY()) {
this.setCurrentAxis(Axis.Y);
} else if (this.getMin().z != this.getMax().z) {
} else if (this.getBoundsMin().getZ() != this.getBoundsMax().getZ()) {
this.setCurrentAxis(Axis.Z);
} else {
this.setCurrentAxis(Axis.UNFORMED);
@@ -59,6 +64,11 @@ public class SpatialPylonCluster implements IAECluster {
}
}
@Override
public boolean isDestroyed() {
return isDestroyed;
}
@Override
public void destroy() {
@@ -67,8 +77,13 @@ public class SpatialPylonCluster implements IAECluster {
}
this.isDestroyed = true;
for (final SpatialPylonBlockEntity r : this.getLine()) {
r.updateStatus(null);
MBCalculator.setModificationInProgress(this);
try {
for (final SpatialPylonBlockEntity r : this.getLine()) {
r.updateStatus(null);
}
} finally {
MBCalculator.setModificationInProgress(null);
}
}
@@ -97,12 +112,18 @@ public class SpatialPylonCluster implements IAECluster {
this.isValid = isValid;
}
public DimensionalCoord getMax() {
return this.max;
public World getWorld() {
return world;
}
public DimensionalCoord getMin() {
return this.min;
@Override
public BlockPos getBoundsMax() {
return this.boundsMax;
}
@Override
public BlockPos getBoundsMin() {
return this.boundsMin;
}
List<SpatialPylonBlockEntity> getLine() {
@@ -96,7 +96,7 @@ public class AENetworkProxy implements IGridBlock {
public void validate() {
if (this.gp instanceof AEBaseBlockEntity) {
TickHandler.INSTANCE.addInit((AEBaseBlockEntity) this.gp);
TickHandler.instance().addInit((AEBaseBlockEntity) this.gp);
}
}