Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Navigator api #50

Merged
merged 10 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 0 additions & 115 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,120 +175,5 @@ if(world.isRemote == false) {
}
```

#### JourneyMap Custom Layer

VisualProspecting provides a light-weight API for custom and interactive layers. This API will keep all maps as optional mod at runtime and not crash you game if it is missing. You may instantiate [`ButtonManager`](https://github.com/SinTh0r4s/VisualProspecting/blob/master/src/main/java/com/sinthoras/visualprospecting/gui/model/buttons/ButtonManager.java) to create your own logical button. Follow it up with an instance of [`LayerButton`](https://github.com/SinTh0r4s/VisualProspecting/blob/master/src/main/java/com/sinthoras/visualprospecting/gui/journeymap/buttons/LayerButton.java) and register both in the [`VisualProspecting_API`](https://github.com/SinTh0r4s/VisualProspecting/blob/master/src/main/java/com/sinthoras/visualprospecting/VisualProspecting_API.java):

```
ButtonManager buttonManager = new ButtonManager("translation.key", "iconName");
LayerButton layerButton = new LayerButton(buttonManager);

VisualProspecting_API.LogicalClient.registerCustomButtonManager(buttonManager);
VisualProspecting_API.LogicalClient.registerJourneyMapButton(layerButton);
```

If you start the game now, you will see a new button in the menu!

First, you will implement [`ILocationProvider`](https://github.com/SinTh0r4s/VisualProspecting/blob/master/src/main/java/com/sinthoras/visualprospecting/gui/model/locations/ILocationProvider.java). This class is a container and will provide all information required to display your item on screen. It won't do any rendering.

```
class MyLocation implements ILocationProvider {

public int getDimensionId() {
return 0; // overworld
}

public int getBlockX() {
return 0;
}

public int getBlockY() {
return 65;
}

public int getBlockZ() {
return 0;
}

public String getLabel() {
return "Hello Minecraft";
}
}
```

Next up, you'll extend [`LayerManager`](https://github.com/SinTh0r4s/VisualProspecting/blob/master/src/main/java/com/sinthoras/visualprospecting/gui/model/layers/LayerManager.java) and implement the abstract function to generate cached List of your [`ILocationProvider`](https://github.com/SinTh0r4s/VisualProspecting/blob/master/src/main/java/com/sinthoras/visualprospecting/gui/model/locations/ILocationProvider.java) implementation. You should only add whatever items are visible to this list. There are more methods to override, that will assist you with that. Take a look!

```
class MyLayerManager extends LayerManager {

public static final MyLayerManager instance = new MyLayerManager();

public MyLayerManager() {
super(buttonManager);
}

protected List<? extends ILocationProvider> generateVisibleElements(int minBlockX, int minBlockZ, int maxBlockX, int maxBlockZ) {
return Collections.singletonList(new MyLocation);
}
}
```

You have finished the logical implementation of your custom map layer. Congratulations! Now it is time for the visual integration into the map. This example is provided for JourneyMap, but you might as well take a look at the other possibilities. Since you already implemented the button as a first step, you will need to follow it up with an implementation of `DrawStep`, an interface from JourneyMap. This class will receive an instance of `MyLocation` and perform the actual rendering.

```
class MyDrawStep implements DrawStep {

private final MyLocation myLocation;

public MyDrawStep(MyLocation myLocation) {
this.myLocation = myLocation;
}

@Override
public void draw(double draggedPixelX, double draggedPixelY, GridRenderer gridRenderer, float drawScale, double fontScale, double rotation) {
final double blockSize = Math.pow(2, gridRenderer.getZoom());
final Point2D.Double blockAsPixel = gridRenderer.getBlockPixelInGrid(myLocation.getBlockX(), myLocation.getBlockZ());
final Point2D.Double pixel = new Point2D.Double(blockAsPixel.getX() + draggedPixelX, blockAsPixel.getY() + draggedPixelY);

DrawUtil.drawLabel(myLocation.getText(), pixel.getX(), pixel.getY(), DrawUtil.HAlign.Center, DrawUtil.VAlign.Middle, 0, 180, 0x00FFFFFF, 255, fontScale, false, rotation);
}
}
```

Continue with your own implementation of [`LayerRenderer`](https://github.com/SinTh0r4s/VisualProspecting/blob/master/src/main/java/com/sinthoras/visualprospecting/gui/journeymap/render/LayerRenderer.java). This class will cache all `DrawStep`s and provide it to JourneyMap whenever it is time to render.

```
class MyLayerRenderer extends LayerRenderer {

public MyLayerRenderer() {
// You may skip MyLayerManager and use an existing ButtonManager like "OreVeinLayerManager.instance"
// Your custom layer will toggle with whatever button you specify here
super(MyLayerManager.instance);
}

@Override
public List<? extends ClickableDrawStep> mapLocationProviderToDrawStep(List<? extends ILocationProvider> visibleElements) {
final List<MyDrawStep> drawSteps = new ArrayList<>();
visibleElements.stream()
.map(element -> (MyLocation) element)
.forEach(location -> drawSteps.add(new MyDrawStep(location)));
return drawSteps;
}

}
```

That's already it! Now you need to register some of these classes. Forge's postInit is a good place for it:

```
VisualProspecting_API.LogicalClient.registerCustomLayer(MyLayerManager.instance);
VisualProspecting_API.LogicalClient.registerJourneyMapRenderer(new MyLayerRenderer());
```

Now you need to launch Minecraft, teleport to the right sport (`/tp 0 80 0`) and open JourneyMap.

If you want to extend support for your layer in other maps as well you already have half the work done. You just need to add implementations for the layer and element renderer. \
For interactive layers you may take a look at extensions/implementations of [`WaypointProviderManager`](https://github.com/SinTh0r4s/VisualProspecting/blob/master/src/main/java/com/sinthoras/visualprospecting/gui/model/layers/WaypointProviderManager.java) and [`ClickableDrawStep`](https://github.com/SinTh0r4s/VisualProspecting/blob/master/src/main/java/com/sinthoras/visualprospecting/gui/journeymap/drawsteps/ClickableDrawStep.java) to get a head start.

Thank you and happy coding,\
SinTh0r4s
13 changes: 4 additions & 9 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
dependencies {
shadowImplementation('com.github.GTNewHorizons:Enklume:2.1.0:dev')

api('com.github.GTNewHorizons:GT5-Unofficial:5.09.48.75:dev')
api(rfg.deobf('maven.modrinth:journeymap:5.2.3'))

devOnlyNonPublishable('com.github.GTNewHorizons:TCNodeTracker:1.3.0:dev')

compileOnly(deobfCurse('xaeros-minimap-263420:5060684'))
compileOnly(deobfCurse('xaeros-world-map-317780:5060733'))
compileOnly(deobf('https://media.forgecdn.net/files/2462/146/mod_voxelMap_1.7.0b_for_1.7.10.litemod', 'mod_voxelMap_1.7.0b_for_1.7.10.jar'))
api('com.github.GTNewHorizons:Navigator:1.0.6:dev')
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.48.78:dev')

// For debugging
runtimeOnlyNonPublishable('com.github.GTNewHorizons:DetravScannerMod:1.8.1:dev')
runtimeOnlyNonPublishable('com.github.GTNewHorizons:ServerUtilities:2.0.60:dev')
runtimeOnlyNonPublishable(rfg.deobf('maven.modrinth:journeymap:5.2.5'))

}
Loading