Skip to content

Commit

Permalink
Switch to Navigator API
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-OOG-ah committed Jul 20, 2024
1 parent c9ae0f3 commit 9e88580
Show file tree
Hide file tree
Showing 18 changed files with 168 additions and 157 deletions.
16 changes: 8 additions & 8 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
dependencies {

// Required for building and running
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.48.14:dev') // Duh
api('com.github.GTNewHorizons:GTNHLib:0.2.11:dev') // Fastutil + config
api('com.github.GTNewHorizons:VisualProspecting:1.2.11:dev')
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.48.93:dev') // Duh
// { exclude group: "com.github.GTNewHorizons", module: "DetravScannerMod"}
api('com.github.GTNewHorizons:GTNHLib:0.3.2:dev') // Fastutil + config
api('com.github.GTNewHorizons:Navigator:1.0.6')
api(rfg.deobf('maven.modrinth:journeymap:5.2.5'))

// For testing
runtimeOnlyNonPublishable('com.github.GTNewHorizons:StorageDrawers:1.13.5-GTNH')
runtimeOnlyNonPublishable('com.github.GTNewHorizons:EnderIO:2.8.4')
runtimeOnlyNonPublishable("com.github.GTNewHorizons:DetravScannerMod:1.8.1")
runtimeOnlyNonPublishable('com.github.GTNewHorizons:StorageDrawers:1.13.6-GTNH-test')
runtimeOnlyNonPublishable('com.github.GTNewHorizons:EnderIO:2.8.17')

// This shouldn't be needed, but DetravScannerMod accidentally hard depped it and I can't fix it without untangling
// dep hell exposed by THE GREAT MERGENING
api('com.github.GTNewHorizons:NewHorizonsCoreMod:2.3.48')
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.22'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.23'
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
version = Tags.VERSION,
name = MODNAME,
acceptedMinecraftVersions = "[1.7.10]",
dependencies = "required-after:visualprospecting;after:gregtech;after:hbm;",
dependencies = "required-after:navigator;after:gregtech;after:hbm;",
guiFactory = "klaxon.klaxon.goverlays.config.GOGuiFactory")
public class GregtorioOverlays {

Expand Down
33 changes: 3 additions & 30 deletions src/main/java/klaxon/klaxon/goverlays/events/ClientProxy.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
package klaxon.klaxon.goverlays.events;

import java.util.List;
import java.util.stream.Collectors;

import net.minecraft.client.settings.KeyBinding;

import org.lwjgl.input.Keyboard;

import com.sinthoras.visualprospecting.VisualProspecting_API;
import com.sinthoras.visualprospecting.integration.journeymap.buttons.LayerButton;
import com.sinthoras.visualprospecting.integration.journeymap.render.LayerRenderer;
import com.sinthoras.visualprospecting.integration.model.locations.ILocationProvider;
import com.gtnewhorizons.navigator.api.NavigatorApi;

import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import journeymap.client.render.draw.DrawStep;
import klaxon.klaxon.goverlays.journeymap.PollutionDrawStep;
import klaxon.klaxon.goverlays.visualprospecting.model.PollutionChunkLocation;
import klaxon.klaxon.goverlays.visualprospecting.model.PollutionOverlayLayerManager;
import klaxon.klaxon.goverlays.navigator.PollutionLayerManager;

@SuppressWarnings("unused")
public class ClientProxy extends CommonProxy {

public static KeyBinding toggleLabels;
Expand All @@ -45,23 +35,6 @@ public void postInit(FMLPostInitializationEvent event) {
super.postInit(event);

// Register the pollution overlay
// Register logical button and layer
VisualProspecting_API.LogicalClient.registerCustomButtonManager(PollutionOverlayLayerManager.buttonMgr);
VisualProspecting_API.LogicalClient.registerCustomLayer(PollutionOverlayLayerManager.instance);

// Register JourneyMap button and renderer
VisualProspecting_API.LogicalClient
.registerJourneyMapButton(new LayerButton(PollutionOverlayLayerManager.buttonMgr));
VisualProspecting_API.LogicalClient
.registerJourneyMapRenderer(new LayerRenderer(PollutionOverlayLayerManager.instance) {

@Override
protected List<? extends DrawStep> mapLocationProviderToDrawStep(
List<? extends ILocationProvider> visibleElements) {
return visibleElements.stream()
.map(loc -> new PollutionDrawStep((PollutionChunkLocation) loc))
.collect(Collectors.toList());
}
});
NavigatorApi.registerLayerManager(PollutionLayerManager.INSTANCE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import gregtech.common.GT_Pollution;

@SuppressWarnings("UnusedMixin")
@Mixin(GT_Pollution.class)
public interface GT_PollutionAccessor {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package klaxon.klaxon.goverlays.mixins.late.gregtech;

import static com.sinthoras.visualprospecting.Utils.chunkCoordsToKey;
import static klaxon.klaxon.goverlays.utils.ChunkPos.pack;

import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World;
Expand All @@ -15,20 +15,17 @@
import gregtech.common.GT_Pollution;
import klaxon.klaxon.goverlays.GregtorioOverlays;

@SuppressWarnings("UnusedMixin")
@Mixin(value = GT_Pollution.class, remap = false)
public abstract class GT_PollutionMixin {

@Final
@Shadow
private World world;

@Final
@Shadow
private static short cycleLen;

@Inject(method = "setChunkPollution", at = @At(value = "TAIL"))
public void gtorioo$updateFromGT(ChunkCoordIntPair coord, int pollution, CallbackInfo ci) {
GregtorioOverlays.proxy.pollution
.updateCache(world.provider.dimensionId, chunkCoordsToKey(coord.chunkXPos, coord.chunkZPos), pollution);
.updateCache(world.provider.dimensionId, pack(coord.chunkXPos, coord.chunkZPos), pollution);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import journeymap.client.ui.fullscreen.Fullscreen;
import klaxon.klaxon.goverlays.config.GOConfig;

@SuppressWarnings("UnusedMixin")
@Mixin(Fullscreen.class)
public class FullscreenMixin {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package klaxon.klaxon.goverlays.navigator;

import net.minecraft.util.ResourceLocation;

import com.gtnewhorizons.navigator.api.model.SupportedMods;
import com.gtnewhorizons.navigator.api.model.buttons.ButtonManager;

import klaxon.klaxon.goverlays.GregtorioOverlays;

public class PollutionButtonManager extends ButtonManager {

public static final PollutionButtonManager INSTANCE = new PollutionButtonManager();

@Override
public ResourceLocation getIcon(SupportedMods mod, String theme) {
return new ResourceLocation(GregtorioOverlays.MODID, "textures/icons/pollution.png");
}

@Override
public String getButtonText() {
return "goverlays.button.pollution";
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package klaxon.klaxon.goverlays.visualprospecting.model;
package klaxon.klaxon.goverlays.navigator;

import static com.sinthoras.visualprospecting.Utils.coordChunkToBlock;
import static com.gtnewhorizons.navigator.api.util.Util.coordChunkToBlock;
import static klaxon.klaxon.goverlays.utils.ChunkPos.getX;
import static klaxon.klaxon.goverlays.utils.ChunkPos.getZ;

import com.sinthoras.visualprospecting.integration.model.locations.ILocationProvider;
import com.gtnewhorizons.navigator.api.model.locations.ILocationProvider;

public class PollutionChunkLocation implements ILocationProvider {

private final int dimID;
private final long packedPos;
private final int pollution;
final int dimID;
final long packedPos;
final int pollution;

public PollutionChunkLocation(int dim, long pos, int pollution) {

dimID = dim;
packedPos = pos;
public PollutionChunkLocation(int dimID, long packedPos, int pollution) {
this.dimID = dimID;
this.packedPos = packedPos;
this.pollution = pollution;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package klaxon.klaxon.goverlays.navigator;

import static com.gtnewhorizons.navigator.api.util.Util.coordBlockToChunk;
import static klaxon.klaxon.goverlays.utils.ChunkPos.pack;

import java.util.List;

import net.minecraft.client.Minecraft;

import org.jetbrains.annotations.Nullable;

import com.gtnewhorizons.navigator.api.model.SupportedMods;
import com.gtnewhorizons.navigator.api.model.layers.LayerManager;
import com.gtnewhorizons.navigator.api.model.layers.LayerRenderer;
import com.gtnewhorizons.navigator.api.model.locations.ILocationProvider;

import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import klaxon.klaxon.goverlays.GregtorioOverlays;
import klaxon.klaxon.goverlays.navigator.journeymap.PollutionLayerRenderer;

public class PollutionLayerManager extends LayerManager {

public static final PollutionLayerManager INSTANCE = new PollutionLayerManager();

public PollutionLayerManager() {
super(PollutionButtonManager.INSTANCE);
}

@Nullable
@Override
protected LayerRenderer addLayerRenderer(LayerManager manager, SupportedMods mod) {
if (mod == SupportedMods.JourneyMap) return PollutionLayerRenderer.INSTANCE;
return null;
}

/**
* Generates list of location providers for rendering.
* Takes in a rectangle bounded by minBlockX, maxBlockX, minBlockZ, and maxBlockZ.
* This assumes the player is in the dimension being mapped.
*/
@Override
protected List<? extends ILocationProvider> generateVisibleElements(int minBlockX, int minBlockZ, int maxBlockX,
int maxBlockZ) {

// Convert to chunk coords
final int minCX = coordBlockToChunk(minBlockX);
final int minCZ = coordBlockToChunk(minBlockZ);
final int maxCX = coordBlockToChunk(maxBlockX);
final int maxCZ = coordBlockToChunk(maxBlockZ);

// Get dimension
final int dimId = Minecraft.getMinecraft().thePlayer.dimension;
final var pollution = GregtorioOverlays.proxy.pollution.getCache(dimId);
final var locations = new ObjectArrayList<PollutionChunkLocation>();

if (pollution.isEmpty()) return locations;

// Go through chunks one at a time
for (int cX = minCX; cX <= maxCX; ++cX) {
for (int cZ = minCZ; cZ <= maxCZ; ++cZ) {
// Get the pollution chunk and add it if it exists
final long k = pack(cX, cZ);
final int p = pollution.get(k);
if (p > 0) {
locations.add(new PollutionChunkLocation(dimId, k, p));
}
}
}

return locations;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package klaxon.klaxon.goverlays.journeymap;
package klaxon.klaxon.goverlays.navigator.journeymap;

import static java.lang.Math.min;
import static klaxon.klaxon.goverlays.Constants.EffectSteps.POLLUTION_MAX;
Expand All @@ -7,15 +7,16 @@

import java.awt.geom.Point2D;

import journeymap.client.render.draw.DrawStep;
import com.gtnewhorizons.navigator.api.journeymap.drawsteps.JMRenderStep;

import journeymap.client.render.draw.DrawUtil;
import journeymap.client.render.map.GridRenderer;
import klaxon.klaxon.goverlays.Constants;
import klaxon.klaxon.goverlays.config.GOConfig;
import klaxon.klaxon.goverlays.navigator.PollutionChunkLocation;
import klaxon.klaxon.goverlays.utils.FancyText;
import klaxon.klaxon.goverlays.visualprospecting.model.PollutionChunkLocation;

public class PollutionDrawStep implements DrawStep {
public class PollutionDrawStep implements JMRenderStep {

private final double blockX;
private final double blockZ;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package klaxon.klaxon.goverlays.navigator.journeymap;

import java.util.List;

import com.gtnewhorizons.navigator.api.journeymap.render.JMLayerRenderer;
import com.gtnewhorizons.navigator.api.model.locations.ILocationProvider;
import com.gtnewhorizons.navigator.api.model.steps.RenderStep;

import it.unimi.dsi.fastutil.objects.ObjectImmutableList;
import klaxon.klaxon.goverlays.navigator.PollutionChunkLocation;
import klaxon.klaxon.goverlays.navigator.PollutionLayerManager;

public class PollutionLayerRenderer extends JMLayerRenderer {

public static final PollutionLayerRenderer INSTANCE = new PollutionLayerRenderer();

public PollutionLayerRenderer() {
super(PollutionLayerManager.INSTANCE);
}

@Override
protected List<? extends RenderStep> generateRenderSteps(List<? extends ILocationProvider> visibleElements) {
return visibleElements.stream()
.map(element -> new PollutionDrawStep((PollutionChunkLocation) element))
.collect(ObjectImmutableList.toListWithExpectedSize(visibleElements.size()));
}
}
4 changes: 4 additions & 0 deletions src/main/java/klaxon/klaxon/goverlays/utils/ChunkPos.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

public class ChunkPos {

public static long pack(int x, int z) {
return ((long) x << 32) | z;
}

public static int getX(long pos) {
return (int) (pos >> 32);
}
Expand Down
Loading

0 comments on commit 9e88580

Please sign in to comment.