Moving to source sets

This commit is contained in:
Sebastian Hartte
2020-07-01 23:36:51 +02:00
parent f2e3d81fd7
commit 2642ced86b
2924 changed files with 794 additions and 796 deletions
@@ -1,131 +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.me.cluster.implementations;
import java.util.Iterator;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.events.MENetworkCraftingCpuChange;
import appeng.api.util.AEPartLocation;
import appeng.api.util.WorldCoord;
import appeng.me.cluster.IAECluster;
import appeng.me.cluster.IAEMultiBlock;
import appeng.me.cluster.MBCalculator;
import appeng.tile.crafting.CraftingBlockEntity;
public class CraftingCPUCalculator extends MBCalculator {
private final CraftingBlockEntity tqb;
public CraftingCPUCalculator(final IAEMultiBlock t) {
super(t);
this.tqb = (CraftingBlockEntity) t;
}
@Override
public boolean checkMultiblockScale(final WorldCoord min, final WorldCoord max) {
if (max.x - min.x > 16) {
return false;
}
if (max.y - min.y > 16) {
return false;
}
if (max.z - min.z > 16) {
return false;
}
return true;
}
@Override
public IAECluster createCluster(final World w, final WorldCoord min, final WorldCoord max) {
return new CraftingCPUCluster(min, max);
}
@Override
public boolean verifyInternalStructure(final World w, final WorldCoord min, final WorldCoord max) {
boolean storage = false;
for (int x = min.x; x <= max.x; x++) {
for (int y = min.y; y <= max.y; y++) {
for (int z = min.z; z <= max.z; z++) {
final IAEMultiBlock te = (IAEMultiBlock) w.getBlockEntity(new BlockPos(x, y, z));
if (!te.isValid()) {
return false;
}
if (!storage && te instanceof CraftingBlockEntity) {
storage = ((CraftingBlockEntity) te).getStorageBytes() > 0;
}
}
}
}
return storage;
}
@Override
public void disconnect() {
this.tqb.disconnect(true);
}
@Override
public void updateTiles(final IAECluster cl, final World w, final WorldCoord min, final WorldCoord max) {
final CraftingCPUCluster c = (CraftingCPUCluster) cl;
for (int x = min.x; x <= max.x; x++) {
for (int y = min.y; y <= max.y; y++) {
for (int z = min.z; z <= max.z; z++) {
final CraftingBlockEntity te = (CraftingBlockEntity) w.getBlockEntity(new BlockPos(x, y, z));
te.updateStatus(c);
c.addTile(te);
}
}
}
c.done();
final Iterator<IGridHost> i = c.getTiles();
while (i.hasNext()) {
final IGridHost gh = i.next();
final IGridNode n = gh.getGridNode(AEPartLocation.INTERNAL);
if (n != null) {
final IGrid g = n.getGrid();
if (g != null) {
g.postEvent(new MENetworkCraftingCpuChange(n));
return;
}
}
}
}
@Override
public boolean isValidTile(final BlockEntity te) {
return te instanceof CraftingBlockEntity;
}
}
File diff suppressed because it is too large Load Diff
@@ -1,141 +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.me.cluster.implementations;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.definitions.IBlockDefinition;
import appeng.api.definitions.IBlocks;
import appeng.api.util.WorldCoord;
import appeng.me.cluster.IAECluster;
import appeng.me.cluster.IAEMultiBlock;
import appeng.me.cluster.MBCalculator;
import appeng.tile.qnb.QuantumBridgeBlockEntity;
public class QuantumCalculator extends MBCalculator {
private final QuantumBridgeBlockEntity tqb;
public QuantumCalculator(final IAEMultiBlock t) {
super(t);
this.tqb = (QuantumBridgeBlockEntity) t;
}
@Override
public boolean checkMultiblockScale(final WorldCoord min, final WorldCoord max) {
if ((max.x - min.x + 1) * (max.y - min.y + 1) * (max.z - min.z + 1) == 9) {
final int ones = ((max.x - min.x) == 0 ? 1 : 0) + ((max.y - min.y) == 0 ? 1 : 0)
+ ((max.z - min.z) == 0 ? 1 : 0);
final int threes = ((max.x - min.x) == 2 ? 1 : 0) + ((max.y - min.y) == 2 ? 1 : 0)
+ ((max.z - min.z) == 2 ? 1 : 0);
return ones == 1 && threes == 2;
}
return false;
}
@Override
public IAECluster createCluster(final World w, final WorldCoord min, final WorldCoord max) {
return new QuantumCluster(min, max);
}
@Override
public boolean verifyInternalStructure(final World w, final WorldCoord min, final WorldCoord max) {
byte num = 0;
for (int x = min.x; x <= max.x; x++) {
for (int y = min.y; y <= max.y; y++) {
for (int z = min.z; z <= max.z; z++) {
final BlockPos p = new BlockPos(x, y, z);
final IAEMultiBlock te = (IAEMultiBlock) w.getBlockEntity(p);
if (!te.isValid()) {
return false;
}
num++;
final IBlocks blocks = AEApi.instance().definitions().blocks();
if (num == 5) {
if (!this.isBlockAtLocation(w, p, blocks.quantumLink())) {
return false;
}
} else {
if (!this.isBlockAtLocation(w, p, blocks.quantumRing())) {
return false;
}
}
}
}
}
return true;
}
@Override
public void disconnect() {
this.tqb.disconnect(true);
}
@Override
public void updateTiles(final IAECluster cl, final World w, final WorldCoord min, final WorldCoord max) {
byte num = 0;
byte ringNum = 0;
final QuantumCluster c = (QuantumCluster) cl;
for (int x = min.x; x <= max.x; x++) {
for (int y = min.y; y <= max.y; y++) {
for (int z = min.z; z <= max.z; z++) {
final QuantumBridgeBlockEntity te = (QuantumBridgeBlockEntity) w.getBlockEntity(new BlockPos(x, y, z));
num++;
final byte flags;
if (num == 5) {
flags = num;
c.setCenter(te);
} else {
if (num == 1 || num == 3 || num == 7 || num == 9) {
flags = (byte) (this.tqb.getCorner() | num);
} else {
flags = num;
}
c.getRing()[ringNum] = te;
ringNum++;
}
te.updateStatus(c, flags, true);
}
}
}
}
@Override
public boolean isValidTile(final BlockEntity te) {
return te instanceof QuantumBridgeBlockEntity;
}
private boolean isBlockAtLocation(final BlockView w, final BlockPos pos, final IBlockDefinition def) {
return def.maybeBlock().map(block -> block == w.getBlockState(pos).getBlock()).orElse(false);
}
}
@@ -1,260 +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.me.cluster.implementations;
import java.util.Iterator;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import appeng.api.AEApi;
import appeng.api.events.LocatableEventAnnounce;
import appeng.api.events.LocatableEventAnnounce.LocatableEvent;
import appeng.api.exceptions.FailedConnectionException;
import appeng.api.features.ILocatable;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.util.AEPartLocation;
import appeng.api.util.WorldCoord;
import appeng.core.AELog;
import appeng.me.cache.helpers.ConnectionWrapper;
import appeng.me.cluster.IAECluster;
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 boolean isDestroyed = false;
private boolean updateStatus = true;
private QuantumBridgeBlockEntity[] Ring;
private boolean registered = false;
private ConnectionWrapper connection;
private long thisSide;
private long otherSide;
private QuantumBridgeBlockEntity center;
public QuantumCluster(final WorldCoord min, final WorldCoord max) {
this.min = min;
this.max = max;
this.setRing(new QuantumBridgeBlockEntity[8]);
}
@SubscribeEvent
public void onUnload(final WorldEvent.Unload e) {
if (this.center.getWorld() == e.getWorld()) {
this.setUpdateStatus(false);
this.destroy();
}
}
@Override
public void updateStatus(final boolean updateGrid) {
final long qe = this.center.getQEFrequency();
if (this.thisSide != qe && this.thisSide != -qe) {
if (qe != 0) {
if (this.thisSide != 0) {
MinecraftForge.EVENT_BUS.post(new LocatableEventAnnounce(this, LocatableEvent.UNREGISTER));
}
if (this.canUseNode(-qe)) {
this.otherSide = qe;
this.thisSide = -qe;
} else if (this.canUseNode(qe)) {
this.thisSide = qe;
this.otherSide = -qe;
}
MinecraftForge.EVENT_BUS.post(new LocatableEventAnnounce(this, LocatableEvent.REGISTER));
} else {
MinecraftForge.EVENT_BUS.post(new LocatableEventAnnounce(this, LocatableEvent.UNREGISTER));
this.otherSide = 0;
this.thisSide = 0;
}
}
final ILocatable myOtherSide = this.otherSide == 0 ? null
: AEApi.instance().registries().locatable().getLocatableBy(this.otherSide);
boolean shutdown = false;
if (myOtherSide instanceof QuantumCluster) {
final QuantumCluster sideA = this;
final QuantumCluster sideB = (QuantumCluster) myOtherSide;
if (sideA.isActive() && sideB.isActive()) {
if (this.connection != null && this.connection.getConnection() != null) {
final IGridNode a = this.connection.getConnection().a();
final IGridNode b = this.connection.getConnection().b();
final IGridNode sa = sideA.getNode();
final IGridNode sb = sideB.getNode();
if ((a == sa || b == sa) && (a == sb || b == sb)) {
return;
}
}
try {
if (sideA.connection != null) {
if (sideA.connection.getConnection() != null) {
sideA.connection.getConnection().destroy();
sideA.connection = new ConnectionWrapper(null);
}
}
if (sideB.connection != null) {
if (sideB.connection.getConnection() != null) {
sideB.connection.getConnection().destroy();
sideB.connection = new ConnectionWrapper(null);
}
}
sideA.connection = sideB.connection = new ConnectionWrapper(
AEApi.instance().grid().createGridConnection(sideA.getNode(), sideB.getNode()));
} catch (final FailedConnectionException e) {
// :(
AELog.debug(e);
}
} else {
shutdown = true;
}
} else {
shutdown = true;
}
if (shutdown && this.connection != null) {
if (this.connection.getConnection() != null) {
this.connection.getConnection().destroy();
this.connection.setConnection(null);
this.connection = new ConnectionWrapper(null);
}
}
}
private boolean canUseNode(final long qe) {
final QuantumCluster qc = (QuantumCluster) AEApi.instance().registries().locatable().getLocatableBy(qe);
if (qc != null) {
final World theWorld = qc.center.getWorld();
if (!qc.isDestroyed) {
ChunkPos cPos = new ChunkPos(qc.center.getPos());
if (theWorld.getChunkManager().isChunkLoaded(cPos)) {
final DimensionType id = theWorld.dimension.getType();
final World cur = theWorld.getServer().getWorld(id);
final BlockEntity te = theWorld.getBlockEntity(qc.center.getPos());
return te != qc.center || theWorld != cur;
}
}
}
return true;
}
private boolean isActive() {
if (this.isDestroyed || !this.registered) {
return false;
}
return this.center.isPowered() && this.hasQES();
}
private IGridNode getNode() {
return this.center.getGridNode(AEPartLocation.INTERNAL);
}
private boolean hasQES() {
return this.thisSide != 0;
}
@Override
public void destroy() {
if (this.isDestroyed) {
return;
}
this.isDestroyed = true;
if (this.registered) {
MinecraftForge.EVENT_BUS.unregister(this);
this.registered = false;
}
if (this.thisSide != 0) {
this.updateStatus(true);
MinecraftForge.EVENT_BUS.post(new LocatableEventAnnounce(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]);
}
@Override
public Iterator<IGridHost> getTiles() {
return new ChainedIterator<>(this.getRing()[0], this.getRing()[1], this.getRing()[2], this.getRing()[3],
this.getRing()[4], this.getRing()[5], this.getRing()[6], this.getRing()[7], this.center);
}
public boolean isCorner(final QuantumBridgeBlockEntity tileQuantumBridge) {
return this.getRing()[0] == tileQuantumBridge || this.getRing()[2] == tileQuantumBridge
|| this.getRing()[4] == tileQuantumBridge || this.getRing()[6] == tileQuantumBridge;
}
@Override
public long getLocatableSerial() {
return this.thisSide;
}
public QuantumBridgeBlockEntity getCenter() {
return this.center;
}
void setCenter(final QuantumBridgeBlockEntity c) {
this.registered = true;
MinecraftForge.EVENT_BUS.register(this);
this.center = c;
}
private boolean isUpdateStatus() {
return this.updateStatus;
}
public void setUpdateStatus(final boolean updateStatus) {
this.updateStatus = updateStatus;
}
QuantumBridgeBlockEntity[] getRing() {
return this.Ring;
}
private void setRing(final QuantumBridgeBlockEntity[] ring) {
this.Ring = ring;
}
}
@@ -1,96 +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.me.cluster.implementations;
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;
import appeng.me.cluster.MBCalculator;
import appeng.tile.spatial.SpatialPylonBlockEntity;
public class SpatialPylonCalculator extends MBCalculator {
private final SpatialPylonBlockEntity tqb;
public SpatialPylonCalculator(final IAEMultiBlock t) {
super(t);
this.tqb = (SpatialPylonBlockEntity) t;
}
@Override
public boolean checkMultiblockScale(final WorldCoord min, final WorldCoord max) {
return (min.x == max.x && min.y == max.y && min.z != max.z)
|| (min.x == max.x && min.y != max.y && min.z == max.z)
|| (min.x != max.x && min.y == max.y && min.z == max.z);
}
@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));
}
@Override
public boolean verifyInternalStructure(final World w, final WorldCoord min, final WorldCoord max) {
for (int x = min.x; x <= max.x; x++) {
for (int y = min.y; y <= max.y; y++) {
for (int z = min.z; z <= max.z; z++) {
final IAEMultiBlock te = (IAEMultiBlock) w.getBlockEntity(new BlockPos(x, y, z));
if (!te.isValid()) {
return false;
}
}
}
}
return true;
}
@Override
public void disconnect() {
this.tqb.disconnect(true);
}
@Override
public void updateTiles(final IAECluster cl, final World w, final WorldCoord min, final WorldCoord max) {
final SpatialPylonCluster c = (SpatialPylonCluster) cl;
for (int x = min.x; x <= max.x; x++) {
for (int y = min.y; y <= max.y; y++) {
for (int z = min.z; z <= max.z; z++) {
final SpatialPylonBlockEntity te = (SpatialPylonBlockEntity) w.getBlockEntity(new BlockPos(x, y, z));
te.updateStatus(c);
c.getLine().add((te));
}
}
}
}
@Override
public boolean isValidTile(final BlockEntity te) {
return te instanceof SpatialPylonBlockEntity;
}
}
@@ -1,115 +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.me.cluster.implementations;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import appeng.api.networking.IGridHost;
import appeng.api.util.DimensionalCoord;
import appeng.me.cluster.IAECluster;
import appeng.tile.spatial.SpatialPylonBlockEntity;
public class SpatialPylonCluster implements IAECluster {
private final DimensionalCoord min;
private final DimensionalCoord max;
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();
if (this.getMin().x != this.getMax().x) {
this.setCurrentAxis(Axis.X);
} else if (this.getMin().y != this.getMax().y) {
this.setCurrentAxis(Axis.Y);
} else if (this.getMin().z != this.getMax().z) {
this.setCurrentAxis(Axis.Z);
} else {
this.setCurrentAxis(Axis.UNFORMED);
}
}
@Override
public void updateStatus(final boolean updateGrid) {
for (final SpatialPylonBlockEntity r : this.getLine()) {
r.recalculateDisplay();
}
}
@Override
public void destroy() {
if (this.isDestroyed) {
return;
}
this.isDestroyed = true;
for (final SpatialPylonBlockEntity r : this.getLine()) {
r.updateStatus(null);
}
}
@Override
public Iterator<IGridHost> getTiles() {
return (Iterator) this.getLine().iterator();
}
public int tileCount() {
return this.getLine().size();
}
public Axis getCurrentAxis() {
return this.currentAxis;
}
private void setCurrentAxis(final Axis currentAxis) {
this.currentAxis = currentAxis;
}
public boolean isValid() {
return this.isValid;
}
public void setValid(final boolean isValid) {
this.isValid = isValid;
}
public DimensionalCoord getMax() {
return this.max;
}
public DimensionalCoord getMin() {
return this.min;
}
List<SpatialPylonBlockEntity> getLine() {
return this.line;
}
public enum Axis {
X, Y, Z, UNFORMED
}
}