Skip to content

Commit

Permalink
Render station name for Standing Station Name Sign
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenny-Hui committed Feb 1, 2024
1 parent 792b175 commit 33f58d6
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 17 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ subprojects {
def mc_minor = mc_ver.split("\\.").size() > 2 ? (mc_ver.split("\\.")[2] as String).padLeft(2, '0') : 0
def manifold_mc_version = "$mc_major$mc_main$mc_minor"

it.options.compilerArgs += ["-Xplugin:Manifold", "-AMC_VERSION=$manifold_mc_version"]
it.options.compilerArgs += [
"-Xplugin:Manifold",
"-AMC_VERSION=$manifold_mc_version",
"-ALOADER=$project.properties.loader_name"
]
}
}
11 changes: 6 additions & 5 deletions docs/Contribute_Code.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ As such, method that are guaranteed to exist across all version will be annotate
When overriding method on classes provided by **Minecraft Mappings**, you should be overriding and calling methods made by Minecraft-Mappings (Sometimes named like `methodName2` or `methodName3`), these are methods provided by **Minecraft Mappings**, whereas `methodName` is usually the underlying method provided by Minecraft.

**Minecraft Mappings** also provide helper classes (For example the Vanilla Registry) on components with radical changes between versions.

### There's no mapping for RenderSystem but I want to use it
For RenderSystem you can just use the class provided by Minecraft directly. Not all Minecraft's code are obfuscated, for example some of the code in `com.mojang.blaze3d` including RenderSystem is not obfuscated, a mapping like Yarn or Mojmap is not needed and there's a much less chance that the method name will differ across mod-loaders due to them using different mappings.
If you really find yourself not being able to compile across all versions and mod-loaders when using code that's not provided by Minecraft Mappings, you can follow the section below.

### What if Minecraft Mappings doesn't contain the code I want
In general there are 2 options:
1. Contribute to [Minecraft-Mappings](https://github.com/Minecraft-Transit-Railway/Minecraft-Mappings) by following the instruction there.
2. A backup solution is using manifold preprocessing to conditionally apply code (To be continued....)

### What about RenderSystem?
Not all Minecraft's code are obfuscated, for example some of the code in `com.mojang.blaze3d` including RenderSystem is not obfuscated, a mapping like Yarn or Mojmap is not needed and there's a much less chance that the method name will differ across mod-loaders due to them using different mappings.
If you really find yourself not being able to compile across all versions and mod-loaders when using code that's not provided by Minecraft Mappings, you can follow the section above.
2. Use the manifold preprocessor to compile different code conditionally depending on the build configuration, see [Manifold Preprocessor](Manifold_Preprocessor.md) for more information.

## Code Guidelines
### Naming Convention
Expand Down
36 changes: 36 additions & 0 deletions docs/Manifold_Preprocessor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Manifold Preprocessor
This is a preprocessor that is integrated to the Joban Client Mod projects for multi-target builds.

### Usage
To conditionally run a code, you can use the `#if` and `#endif` block:
```
#if MC_VERSION == "11904"
System.out.println("Now running on 1.19.4");
#elif MC_VERSION == "11802"
System.out.println("Now running on 1.18.2");
#else
System.out.println("Not running on 1.19.4 nor 1.18.2");
#endif
```

You can also compare the minecraft version:
```
#if MC_VERSION > "11904"
System.out.println("Running on 1.19.4 or above (e.g. 1.20)");
#else
System.out.println("Running below 1.19.4");
#endif
```

If you have the [Manifold Plugin](https://plugins.jetbrains.com/plugin/10057-manifold) installed for IntelliJ, the code inside the `#if` and `#elif` block would have a distinct gray background, and there will not be any syntax highlighting.

Available variable as follows:

| Variable Name | Description | Example |
|---------------|------------------------------------------------------------------------------------|---------|
| MC_VERSION | The Minecraft version this build is for, in the format MAJOR(1)MINOR(2)PATCH(2) | 11902 |
| LOADER | The modloader this build is for, possible values are `fabric`, `forge`, `neoforge` | fabric |

The preprocessing should target the main development configuration (Fabric, Latest MC Version).

To avoid misleading IDE syntax error caused by code from other versions, the code for the main development configuration should be placed in the `#else` block.
1 change: 1 addition & 0 deletions fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Fabric Properties
# check these on https://fabricmc.net/develop
fabric_loader_version=0.15.3
loader_name=fabric

yarn_mappings_1.20.4=1.20.4+build.3
yarn_mappings_1.19.4=1.19.4+build.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import com.lx862.jcm.mod.registry.BlockEntities;
import org.mtr.mapping.holder.BlockPos;
import org.mtr.mapping.holder.BlockState;
import org.mtr.mapping.mapper.BlockEntityExtension;
import org.mtr.mod.block.BlockStationNameTallBase;

public class StationNameStandingBlockEntity extends BlockEntityExtension {
public class StationNameStandingBlockEntity extends BlockStationNameTallBase.BlockEntityTallBase {
public StationNameStandingBlockEntity(BlockPos blockPos, BlockState blockState) {
super(BlockEntities.STATION_NAME_STANDING.get(), blockPos, blockState);
super(BlockEntities.STATION_NAME_STANDING.get(), blockPos, blockState, 0.07F, false);
#if
#elif
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static void register() {
// Start Tick Event for counting tick
org.mtr.mapping.registry.EventRegistry.registerStartServerTick(() -> {
JCMStats.incrementGameTick();
// TODO: Does this work on client in multiplayer?
McMetaManager.tick();
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
package com.lx862.jcm.mod.render.block;

import com.lx862.jcm.mod.block.entity.StationNameStandingBlockEntity;
import org.mtr.mapping.mapper.GraphicsHolder;
import com.lx862.jcm.mod.data.BlockProperties;
import com.lx862.jcm.mod.util.BlockUtil;
import org.mtr.mapping.holder.BlockPos;
import org.mtr.mapping.holder.BlockState;
import org.mtr.mapping.holder.Direction;
import org.mtr.mapping.holder.World;
import org.mtr.mod.client.DynamicTextureCache;
import org.mtr.mod.client.IDrawing;
import org.mtr.mod.render.RenderStationNameBase;
import org.mtr.mod.render.RenderTrains;
import org.mtr.mod.render.StoredMatrixTransformations;

public class StationNameStandingRenderer extends RenderStationNameBase<StationNameStandingBlockEntity> {

private static final float WIDTH = 0.6875F;
private static final float HEIGHT = 1;
private static final float OFFSET_Y = 0.125F;

public class StationNameStandingRenderer extends JCMBlockEntityRenderer<StationNameStandingBlockEntity> {
public StationNameStandingRenderer(Argument dispatcher) {
super(dispatcher);
}

@Override
public void renderCurated(StationNameStandingBlockEntity blockEntity, float tickDelta, GraphicsHolder graphicsHolder, int light, int i1) {
graphicsHolder.push();
scaleCentered(graphicsHolder, 0.018F, 0.018F, 0.018F);
rotateToBlockDirection(graphicsHolder, blockEntity);
// TODO: Render with IDrawing
graphicsHolder.pop();
protected void drawStationName(World world, BlockPos pos, BlockState state, Direction facing, StoredMatrixTransformations storedMatrixTransformations, String stationName, int stationColor, int color, int light) {
if (BlockUtil.getProperty(state, BlockProperties.VERTICAL_PART_3) == 1) {
RenderTrains.scheduleRender(DynamicTextureCache.instance.getTallStationName(color, stationName, stationColor, WIDTH / HEIGHT).identifier, false, RenderTrains.QueuedRenderLayer.EXTERIOR, (graphicsHolder, offset) -> {
storedMatrixTransformations.transform(graphicsHolder, offset);
IDrawing.drawTexture(graphicsHolder, -WIDTH / 2, -HEIGHT / 2 - OFFSET_Y, WIDTH, HEIGHT, 0, 0, 1, 1, facing, ARGB_WHITE, light);
graphicsHolder.pop();
});
}
}
}

0 comments on commit 33f58d6

Please sign in to comment.