Skip to content

Commit

Permalink
Adds vein type readout to multiblock miners (GTNewHorizons#2732)
Browse files Browse the repository at this point in the history
* Adds vein type readout to multiblock miners (+metrics)

* Spotless, fix weird import

* Downgrades VP dep to latest non-pre version

* Update dependencies.gradle

* Refactor to eliminate dep on VisualProspecting

---------

Co-authored-by: Martin Robertz <dream-master@gmx.net>
  • Loading branch information
querns and Dream-Master authored Jul 29, 2024
1 parent a9cea49 commit 278a156
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 5 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies {
api('com.github.GTNewHorizons:Yamcl:0.6.0:dev')
api('com.github.GTNewHorizons:ThaumicTinkerer:2.10.1:dev')
api("com.github.GTNewHorizons:Mobs-Info:0.3.2-GTNH:dev")
api("com.github.GTNewHorizons:Navigator:1.0.5:dev")

devOnlyNonPublishable("com.github.GTNewHorizons:Infernal-Mobs:1.8.1-GTNH:dev")
runtimeOnly("com.github.GTNewHorizons:Draconic-Evolution:1.3.6-GTNH:dev") // needed?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ public CardState update(World world, ICardWrapper card, int maxRange) {
final List<String> payload = builder.build();
card.setInt(OUTPUT_ENTRY_LENGTH_KEY, payload.size());
for (int i = 0; i < payload.size(); i++) {
card.setString(String.format(OUTPUT_ENTRY_KEY, i), payload.get(i));
final String payloadItem = payload.get(i);
if (!payloadItem.isEmpty()) {
card.setString(String.format(OUTPUT_ENTRY_KEY, i), payloadItem);
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import gregtech.api.util.GT_Utility;
import gregtech.common.blocks.GT_Block_Ores_Abstract;
import gregtech.common.blocks.GT_TileEntity_Ores;
import gregtech.crossmod.visualprospecting.GT_VisualProspecting_Database;

public abstract class GT_MetaTileEntity_OreDrillingPlantBase extends GT_MetaTileEntity_DrillerBase
implements IMetricsExporter {
Expand All @@ -80,6 +81,9 @@ public abstract class GT_MetaTileEntity_OreDrillingPlantBase extends GT_MetaTile
/** Used to drive the drill's y-level in the UI. */
private int clientYHead = 0;

/** Contains the name of the currently mined vein. Used for driving metrics cover output. */
private String veinName = null;

GT_MetaTileEntity_OreDrillingPlantBase(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
}
Expand All @@ -93,6 +97,11 @@ public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT);
aNBT.setInteger("chunkRadiusConfig", chunkRadiusConfig);
aNBT.setBoolean("replaceWithCobblestone", replaceWithCobblestone);
if (veinName != null) {
aNBT.setString("veinName", veinName);
} else if (aNBT.hasKey("veinName")) {
aNBT.removeTag("veinName");
}
}

@Override
Expand All @@ -104,6 +113,11 @@ public void loadNBTData(NBTTagCompound aNBT) {
if (aNBT.hasKey("replaceWithCobblestone")) {
replaceWithCobblestone = aNBT.getBoolean("replaceWithCobblestone");
}
if (aNBT.hasKey("veinName")) {
veinName = aNBT.getString("veinName");
} else {
veinName = null;
}
}

private void adjustChunkRadius(boolean increase) {
Expand Down Expand Up @@ -163,6 +177,10 @@ protected boolean workingDownward(ItemStack aStack, int xDrill, int yDrill, int
}
fillMineListIfEmpty(xDrill, yDrill, zDrill, xPipe, zPipe, yHead);
if (oreBlockPositions.isEmpty()) {
if (veinName == null) {
updateVeinNameFromVP(getDrillCoords());
}

switch (tryLowerPipeState()) {
case 2 -> {
mMaxProgresstime = 0;
Expand Down Expand Up @@ -285,7 +303,10 @@ protected boolean workingAtBottom(ItemStack aStack, int xDrill, int yDrill, int
fillChunkMineList(yHead, yDrill);
if (oreBlockPositions.isEmpty()) {
GT_ChunkManager.releaseChunk((TileEntity) getBaseMetaTileEntity(), mCurrentChunk);
if (!moveToNextChunk(xDrill >> 4, zDrill >> 4)) workState = STATE_UPWARD;
if (!moveToNextChunk(xDrill >> 4, zDrill >> 4)) {
workState = STATE_UPWARD;
updateVeinNameFromVP();
}
return true;
}
}
Expand All @@ -294,6 +315,7 @@ protected boolean workingAtBottom(ItemStack aStack, int xDrill, int yDrill, int

private void createInitialWorkingChunk() {
mCurrentChunk = getTopLeftChunkCoords();
updateVeinNameFromVP();
if (mChunkLoadingEnabled) {
GT_ChunkManager.requestChunkLoad((TileEntity) getBaseMetaTileEntity(), mCurrentChunk);
mWorkChunkNeedsReload = false;
Expand Down Expand Up @@ -394,6 +416,7 @@ protected void onAbort() {
GT_ChunkManager.releaseChunk((TileEntity) getBaseMetaTileEntity(), mCurrentChunk);
}
mCurrentChunk = null;
updateVeinNameFromVP();
}

private boolean moveToNextChunk(int centerX, int centerZ) {
Expand Down Expand Up @@ -425,12 +448,25 @@ private boolean moveToNextChunk(int centerX, int centerZ) {
mCurrentChunk = null;
return false;
}

mCurrentChunk = new ChunkCoordIntPair(nextChunkX, nextChunkZ);
updateVeinNameFromVP();

GT_ChunkManager
.requestChunkLoad((TileEntity) getBaseMetaTileEntity(), new ChunkCoordIntPair(nextChunkX, nextChunkZ));
return true;
}

private void updateVeinNameFromVP() {
updateVeinNameFromVP(mCurrentChunk);
}

private void updateVeinNameFromVP(@NotNull ChunkCoordIntPair coords) {
veinName = GT_VisualProspecting_Database
.getVeinName(getBaseMetaTileEntity().getWorld().provider.dimensionId, coords)
.orElse(null);
}

@Override
protected boolean checkHatches() {
return !mMaintenanceHatches.isEmpty() && !mInputHatches.isEmpty()
Expand Down Expand Up @@ -635,11 +671,20 @@ protected void drawTexts(DynamicPositionedColumn screenElements, SlotWidget inve
.setEnabled(
widget -> getBaseMetaTileEntity().isActive() && clientCurrentChunk > 0
&& workState == STATE_AT_BOTTOM))
.widget(
new TextWidget()
.setStringSupplier(
() -> EnumChatFormatting.GRAY
+ StatCollector.translateToLocalFormatted("GT5U.gui.text.drill_current_vein", veinName))
.setTextAlignment(Alignment.CenterLeft)
.setEnabled(
widget -> veinName != null && (workState == STATE_AT_BOTTOM || workState == STATE_DOWNWARD)))
.widget(new FakeSyncWidget.IntegerSyncer(oreBlockPositions::size, (newInt) -> clientOreListSize = newInt))
.widget(new FakeSyncWidget.IntegerSyncer(this::getTotalChunkCount, (newInt) -> clientTotalChunks = newInt))
.widget(new FakeSyncWidget.IntegerSyncer(this::getChunkNumber, (newInt) -> clientCurrentChunk = newInt))
.widget(new FakeSyncWidget.IntegerSyncer(() -> workState, (newInt) -> workState = newInt))
.widget(new FakeSyncWidget.IntegerSyncer(this::getYHead, (newInt) -> clientYHead = newInt));
.widget(new FakeSyncWidget.IntegerSyncer(this::getYHead, (newInt) -> clientYHead = newInt))
.widget(new FakeSyncWidget.StringSyncer(() -> veinName, (newString) -> veinName = newString));
}

@Override
Expand Down Expand Up @@ -719,12 +764,16 @@ public String[] getInfoData() {
StatCollector.translateToLocalFormatted(
"GT5U.gui.text.drill_chunks_left",
GT_Utility.formatNumbers(getChunkNumber()),
GT_Utility.formatNumbers(getTotalChunkCount())));
GT_Utility.formatNumbers(getTotalChunkCount())),
veinName == null ? ""
: StatCollector.translateToLocalFormatted("GT5U.gui.text.drill_current_vein", veinName));
case STATE_DOWNWARD -> ImmutableList.of(
StatCollector.translateToLocalFormatted(
"GT5U.gui.text.drill_ores_left_layer",
getYHead(),
GT_Utility.formatNumbers(oreBlockPositions.size())));
GT_Utility.formatNumbers(oreBlockPositions.size())),
veinName == null ? ""
: StatCollector.translateToLocalFormatted("GT5U.gui.text.drill_current_vein", veinName));
case STATE_UPWARD, STATE_ABORT -> ImmutableList
.of(StatCollector.translateToLocal("GT5U.gui.text.retracting_pipe"));

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gregtech.crossmod.visualprospecting;

import java.util.Optional;

import javax.annotation.Nullable;

import net.minecraft.world.ChunkCoordIntPair;

public class GT_VisualProspecting_Database {

private static IDatabase database;

@SuppressWarnings("unused")
public static void registerDatabase(IDatabase aDatabase) {
database = aDatabase;
}

public static Optional<String> getVeinName(int dimensionId, @Nullable ChunkCoordIntPair coordinates) {
if (database == null || coordinates == null) {
return Optional.empty();
}

return database.getVeinName(dimensionId, coordinates);
}
}
10 changes: 10 additions & 0 deletions src/main/java/gregtech/crossmod/visualprospecting/IDatabase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package gregtech.crossmod.visualprospecting;

import java.util.Optional;

import net.minecraft.world.ChunkCoordIntPair;

public interface IDatabase {

Optional<String> getVeinName(int dimensionId, ChunkCoordIntPair coordinates);
}
1 change: 1 addition & 0 deletions src/main/resources/assets/gregtech/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ GT5U.gui.text.internal_error=§4Recipe was found, but had internal error
GT5U.gui.text.drill_ores_left_chunk=Ores left in current chunk: §a%s
GT5U.gui.text.drill_ores_left_layer=Ores left at y-level %s: §a%s
GT5U.gui.text.drill_chunks_left=Drilling chunk: §a%s / %s
GT5U.gui.text.drill_current_vein=Current Vein: §a%s
GT5U.gui.text.drill_offline_reason=Drill Offline: %s
GT5U.gui.text.drill_offline_generic=Drill Offline
GT5U.gui.text.stocking_bus_fail_extraction=§4Failed to extract expected amount of items from stocking bus. This can be caused by attaching multiple storage buses to the same inventory.
Expand Down

0 comments on commit 278a156

Please sign in to comment.