Skip to content

Commit

Permalink
Fix central monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
M-W-K committed Dec 27, 2023
1 parent 6eba12f commit 62d3ac5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ public void readFromNBT(@NotNull NBTTagCompound compound) {
this.getNode().setActiveConnections(connections);
}
this.getNode().setBlockedConnections(compound.getInteger("BlockedConnections"));
this.nbtLoad = false;

if (compound.hasKey("InsulationColor")) {
this.paintingColor = compound.getInteger("InsulationColor");
Expand All @@ -452,6 +451,7 @@ public void readFromNBT(@NotNull NBTTagCompound compound) {
// one of the covers set the pipe to ticking, and we need to send over the rest of the covers
this.coverableImplementation.transferDataTo(this.tickingPipe.coverableImplementation);
}
this.nbtLoad = false;

if (!compound.hasKey("PipeNetVersion") && !compound.hasKey("PipeMaterial")) doOldNetSetup();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ public class MetaTileEntityCentralMonitor extends MultiblockWithDisplayBase impl
// run-time data
public int width;
private long lastUpdate;
// private WeakReference<EnergyNet> currentEnergyNet;
private List<BlockPos> activeNodes;
private Set<FacingPos> netCovers;
private Set<FacingPos> remoteCovers;
@SideOnly(Side.CLIENT)
public List<BlockPos> parts;
Expand All @@ -88,46 +85,6 @@ public MetaTileEntityCentralMonitor(ResourceLocation metaTileEntityId) {
super(metaTileEntityId);
}

// private EnergyNet getEnergyNet() {
// if (!this.getWorld().isRemote) {
// TileEntity te = getNeighbor(frontFacing.getOpposite());
// if (te instanceof TileEntityCable) {
// TileEntityPipeBase<?, ?> tileEntityCable = (TileEntityCable) te;
// EnergyNet currentEnergyNet = this.currentEnergyNet.get();
// if (currentEnergyNet != null && currentEnergyNet.isValid() &&
// currentEnergyNet.containsNode(tileEntityCable.getPipePos())) {
// return currentEnergyNet; // return current net if it is still valid
// }
// WorldEnergyNet worldEnergyNet = (WorldEnergyNet) tileEntityCable.getPipeBlock()
// .getWorldPipeNet(tileEntityCable.getPipeWorld());
// currentEnergyNet = worldEnergyNet.getNetFromPos(tileEntityCable.getPipePos());
// if (currentEnergyNet != null) {
// this.currentEnergyNet = new WeakReference<>(currentEnergyNet);
// }
// return currentEnergyNet;
// }
// }
// return null;
// }

private void updateNodes() {
// EnergyNet energyNet = getEnergyNet();
// if (energyNet == null) {
// activeNodes.clear();
// return;
// }
// if (energyNet.getLastUpdate() == lastUpdate) {
// return;
// }
// lastUpdate = energyNet.getLastUpdate();
// activeNodes.clear();
// energyNet.getAllNodes().forEach((pos, node) -> {
// if (node.isActive) {
// activeNodes.add(pos);
// }
// });
}

public void addRemoteCover(FacingPos cover) {
if (remoteCovers != null) {
if (remoteCovers.add(cover)) {
Expand All @@ -138,29 +95,7 @@ public void addRemoteCover(FacingPos cover) {

private boolean checkCovers() {
boolean dirty = false;
updateNodes();
Set<FacingPos> checkCovers = new HashSet<>();
World world = this.getWorld();
for (BlockPos pos : activeNodes) {
TileEntity tileEntityCable = world.getTileEntity(pos);
if (!(tileEntityCable instanceof TileEntityPipeBase)) {
continue;
}
for (EnumFacing facing : EnumFacing.VALUES) {
if (((IPipeTile<?, ?>) tileEntityCable).isConnected(facing)) {
TileEntity tileEntity = world.getTileEntity(pos.offset(facing));
if (tileEntity instanceof IGregTechTileEntity) {
MetaTileEntity metaTileEntity = ((IGregTechTileEntity) tileEntity).getMetaTileEntity();
if (metaTileEntity != null) {
Cover cover = metaTileEntity.getCoverAtSide(facing.getOpposite());
if (cover instanceof CoverDigitalInterface digitalInterface && digitalInterface.isProxy()) {
checkCovers.add(new FacingPos(metaTileEntity.getPos(), cover.getAttachedSide()));
}
}
}
}
}
}
Iterator<FacingPos> iterator = remoteCovers.iterator();
while (iterator.hasNext()) {
FacingPos blockPosFace = iterator.next();
Expand All @@ -177,23 +112,10 @@ private boolean checkCovers() {
iterator.remove();
dirty = true;
}
if (checkCovers.size() != netCovers.size() || !netCovers.containsAll(checkCovers)) {
netCovers = checkCovers;
dirty = true;
}
return dirty;
}

private void writeCovers(PacketBuffer buf) {
if (netCovers == null) {
buf.writeInt(0);
} else {
buf.writeInt(netCovers.size());
for (FacingPos cover : netCovers) {
buf.writeBlockPos(cover.getPos());
buf.writeByte(cover.getFacing().getIndex());
}
}
if (remoteCovers == null) {
buf.writeInt(0);
} else {
Expand All @@ -206,13 +128,8 @@ private void writeCovers(PacketBuffer buf) {
}

private void readCovers(PacketBuffer buf) {
netCovers = new HashSet<>();
remoteCovers = new HashSet<>();
int size = buf.readInt();
for (int i = 0; i < size; i++) {
netCovers.add(new FacingPos(buf.readBlockPos(), EnumFacing.byIndex(buf.readByte())));
}
size = buf.readInt();
for (int i = 0; i < size; i++) {
remoteCovers.add(new FacingPos(buf.readBlockPos(), EnumFacing.byIndex(buf.readByte())));
}
Expand Down Expand Up @@ -381,14 +298,7 @@ protected void updateFormedValid() {
}

public Set<FacingPos> getAllCovers() {
Set<FacingPos> allCovers = new HashSet<>();
if (netCovers != null) {
allCovers.addAll(netCovers);
}
if (remoteCovers != null) {
allCovers.addAll(remoteCovers);
}
return allCovers;
return remoteCovers;
}

@Override
Expand Down Expand Up @@ -422,9 +332,6 @@ public String[] getDescription() {
protected void formStructure(PatternMatchContext context) {
super.formStructure(context);
lastUpdate = 0;
// currentEnergyNet = new WeakReference<>(null);
activeNodes = new ArrayList<>();
netCovers = new HashSet<>();
remoteCovers = new HashSet<>();
inputEnergy = new EnergyContainerList(this.getAbilities(MultiblockAbility.INPUT_ENERGY));
width = 0;
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/gregtech/loaders/recipe/MiscRecipeLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,17 @@ public static void init() {
.buildAndRegister();

ASSEMBLER_RECIPES.recipeBuilder().duration(100).EUt(VA[HV])
.inputs(MetaItems.COVER_SCREEN.getStackForm())
.input(plate, Aluminium)
.input(circuit, MarkerMaterials.Tier.MV)
.input(screw, StainlessSteel, 4)
.inputs(COVER_DIGITAL_INTERFACE.getStackForm())
.inputs(WIRELESS.getStackForm())
.fluidInputs(Polyethylene.getFluid(L))
.outputs(COVER_DIGITAL_INTERFACE.getStackForm())
.outputs(COVER_DIGITAL_INTERFACE_WIRELESS.getStackForm())
.buildAndRegister();

ASSEMBLER_RECIPES.recipeBuilder().duration(100).EUt(VA[HV])
.inputs(COVER_DIGITAL_INTERFACE.getStackForm())
.inputs(MetaItems.COVER_SCREEN.getStackForm())
.input(plate, Aluminium)
.input(circuit, MarkerMaterials.Tier.MV)
.input(screw, StainlessSteel, 2)
.inputs(WIRELESS.getStackForm())
.fluidInputs(Polyethylene.getFluid(L))
.outputs(COVER_DIGITAL_INTERFACE_WIRELESS.getStackForm())
Expand Down Expand Up @@ -322,9 +323,9 @@ public static void init() {

// terminal
ASSEMBLER_RECIPES.recipeBuilder().duration(100).EUt(VA[MV])
.input(circuit, MarkerMaterials.Tier.MV, 4)
.input(EMITTER_MV, 2)
.input(SENSOR_MV, 2)
.input(circuit, MarkerMaterials.Tier.LV, 4)
.input(EMITTER_MV)
.input(SENSOR_MV)
.input(plate, StainlessSteel)
.fluidInputs(Polyethylene.getFluid(L))
.outputs(WIRELESS.getStackForm())
Expand Down

0 comments on commit 62d3ac5

Please sign in to comment.