Skip to content
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Maven
<dependency>
<groupId>maven.modrinth</groupId>
<artifactId>pl3xmap</artifactId>
<version>1.21.11.539</version>
<version>26.1.2.546</version>
<scope>provided</scope>
</dependency>
```
Expand All @@ -101,7 +101,7 @@ repositories {
}

dependencies {
compileOnly 'maven.modrinth:pl3xmap:1.21.11.539'
compileOnly 'maven.modrinth:pl3xmap:26.1.2.546'
}
```

Expand Down
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ tasks {
// this is janky, but it works
val manifestFiles = subprojects.filter({ it.name != "webmap" && it.name != "core" }).map {
val regularFile = it.layout.buildDirectory.file("libs/${project.name}-${it.name}-${it.version}.jar")
val fabricFile = it.layout.buildDirectory.file("libs/${project.name}-${it.name}-${it.version}.jar.tmp")
if (regularFile.isPresent) {
zipTree(regularFile)
} else if (fabricFile.isPresent) {
zipTree(fabricFile)
} else {
null
}
Expand Down
9 changes: 3 additions & 6 deletions bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ dependencies {
}

tasks {
reobfJar {
dependsOn(jar)
outputJar.set(jar.get().archiveFile)
}

// needed for below jank
compileJava {
dependsOn(":core:jar")
Expand All @@ -52,10 +47,12 @@ tasks {
manifest {
from(project(":core").tasks.named<Jar>("shadowJar").get().manifest)
}

archiveClassifier.set("")
}

build {
dependsOn(reobfJar)
dependsOn(shadowJar)
}

runServer {
Expand Down
18 changes: 1 addition & 17 deletions bukkit/src/main/java/net/pl3x/map/bukkit/BukkitWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,6 @@
public class BukkitWorld extends World {
private static Field LEVEL_STORAGE_ACCESS_FIELD = null;

static {
if (LEVEL_STORAGE_ACCESS_FIELD == null) {
Arrays.stream(ServerLevel.class.getFields())
.filter(field -> field.getType().equals(LevelStorageSource.LevelStorageAccess.class))
.findAny().ifPresent(field -> LEVEL_STORAGE_ACCESS_FIELD = field);
}
}

private static LevelStorageSource.LevelStorageAccess getLevelStorageAccess(ServerLevel level) {
try {
return (LevelStorageSource.LevelStorageAccess) LEVEL_STORAGE_ACCESS_FIELD.get(level);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}

private final ServerLevel level;

public BukkitWorld(ServerLevel level, String name) {
Expand All @@ -78,7 +62,7 @@ public BukkitWorld(ServerLevel level, String name) {
level.getSeed(),
Point.of(level.getLevelData().getRespawnData().pos().getX(), level.getLevelData().getRespawnData().pos().getZ()),
Type.get(level.dimension().identifier().toString()),
BukkitWorld.getLevelStorageAccess(level).getDimensionPath(level.dimension()).resolve("region")
level.getServer().storageSource.getDimensionPath(level.dimension()).resolve("region")
);
this.level = level;

Expand Down
46 changes: 41 additions & 5 deletions bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,25 @@
*/
package net.pl3x.map.bukkit;

import com.google.common.collect.ImmutableList;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import net.kyori.adventure.platform.AudienceProvider;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.worldgen.features.VegetationFeatures;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
Expand All @@ -44,8 +51,8 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RedStoneWireBlock;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.configurations.RandomPatchConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.SimpleBlockConfiguration;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.pl3x.map.core.Pl3xMap;
import net.pl3x.map.core.log.Logger;
import net.pl3x.map.core.registry.BiomeRegistry;
Expand All @@ -65,6 +72,8 @@ public class Pl3xMapImpl extends Pl3xMap {

private BukkitAudiences adventure;
private Path jarPath;
private Map<Biome, List<ConfiguredFeature<?,?>>> biomeFeatureCache = new LinkedHashMap<>();
ArrayList<ResourceKey<ConfiguredFeature<?, ?>>> canSpawnFromBonemealList = new ArrayList<>(10);

public Pl3xMapImpl(JavaPlugin plugin) {
super(true);
Expand All @@ -74,6 +83,14 @@ public Pl3xMapImpl(JavaPlugin plugin) {
@Override
public void enable() {
this.adventure = BukkitAudiences.create(this.plugin);
canSpawnFromBonemealList.add(VegetationFeatures.FLOWER_DEFAULT);
canSpawnFromBonemealList.add(VegetationFeatures.FLOWER_FLOWER_FOREST);
canSpawnFromBonemealList.add(VegetationFeatures.FLOWER_SWAMP);
canSpawnFromBonemealList.add(VegetationFeatures.FLOWER_PLAIN);
canSpawnFromBonemealList.add(VegetationFeatures.FLOWER_MEADOW);
canSpawnFromBonemealList.add(VegetationFeatures.FLOWER_CHERRY);
canSpawnFromBonemealList.add(VegetationFeatures.WILDFLOWER);
canSpawnFromBonemealList.add(VegetationFeatures.FLOWER_PALE_GARDEN);
super.enable();
}

Expand Down Expand Up @@ -152,20 +169,39 @@ public int getColorForPower(byte power) {
return RedStoneWireBlock.getColorForPower(power);
}

private List<ConfiguredFeature<?,?>> getBoneMealFeatures(Biome biome) {
// https://github.com/Draradech/FlowerMap (CC0-1.0 license)
// the biomes created from the builtin registry are missing tags
// with the new can_spawn_from_bonemeal tag for vegetation features we can no longer just call getFlowerFeatures (now called getBonemealFeatures)
// iterate through the feature stream and collect matching features manually
if (!biomeFeatureCache.containsKey(biome)) {
biomeFeatureCache.put(biome,
biome.getGenerationSettings().features().stream()
.flatMap(HolderSet::stream)
.flatMap(feature -> ((PlacedFeature) feature.value()).getFeatures())
.filter(feature -> {
Optional<ResourceKey<ConfiguredFeature<?, ?>>> key = feature.unwrapKey();
return key.isPresent() && canSpawnFromBonemealList.contains(key.get());
})
.map(Holder::value)
.collect(ImmutableList.toImmutableList()));
}
return biomeFeatureCache.get(biome);
}

@Override
public net.pl3x.map.core.world.@Nullable Block getFlower(World world, net.pl3x.map.core.world.Biome biome, int blockX, int blockY, int blockZ) {
// https://github.com/Draradech/FlowerMap (CC0-1.0 license)
Biome nms = world.<ServerLevel>getLevel().registryAccess().lookupOrThrow(Registries.BIOME).getValue(Identifier.parse(biome.getKey()));
if (nms == null) {
return null;
}
List<ConfiguredFeature<?, ?>> flowers = nms.getGenerationSettings().getFlowerFeatures();
List<ConfiguredFeature<?, ?>> flowers = this.getBoneMealFeatures(nms);
if (flowers.isEmpty()) {
return null;
}
RandomPatchConfiguration config = (RandomPatchConfiguration) flowers.getFirst().config();
SimpleBlockConfiguration flower = (SimpleBlockConfiguration) config.feature().value().feature().value().config();
Block block = flower.toPlace().getState(this.randomSource, new BlockPos(blockX, blockY, blockZ)).getBlock();
SimpleBlockConfiguration flowerMap = (SimpleBlockConfiguration) flowers.getFirst().config();
Block block = flowerMap.toPlace().getState(world.getLevel(), this.randomSource, new BlockPos(blockX, blockY, blockZ)).getBlock();
return getBlockRegistry().get(BuiltInRegistries.BLOCK.getKey(block).toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ Setting a color to black (#000000) will make it invisible.""")
put("minecraft:glowstone", 0xAD8455);
put("minecraft:gold_block", 0xF8D33E);
put("minecraft:gold_ore", 0x938769);
put("minecraft:golden_dandelion", 0xA56D29);
put("minecraft:granite", 0x956756);
put("minecraft:granite_slab", 0x956756);
put("minecraft:granite_stairs", 0x956756);
Expand Down Expand Up @@ -690,6 +691,7 @@ Setting a color to black (#000000) will make it invisible.""")
put("minecraft:potted_dead_bush", 0x6D5029);
put("minecraft:potted_fern", 0x7EA44D);
put("minecraft:potted_flowering_azalea_bush", 0x9D5CAB);
put("minecraft:potted_golden_dandelion", 0xA56D29);
put("minecraft:potted_jungle_sapling", 0x305111);
put("minecraft:potted_lily_of_the_valley", 0x7DB061);
put("minecraft:potted_mangrove_propagule", 0x5FAF54);
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/net/pl3x/map/core/world/Blocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,10 @@ public class Blocks {
public static final Block PALE_OAK_SHELF = register(new Block(1165, "minecraft:pale_oak_shelf", 0xE4DAD8));
public static final Block SPRUCE_SHELF = register(new Block(1166, "minecraft:spruce_shelf", 0x815631));
public static final Block WARPED_SHELF = register(new Block(1167, "minecraft:warped_shelf", 0x3A8E8C));


public static final Block GOLDEN_DANDELION = register(new Block(1168, "minecraft:golden_dandelion", 0xA56D29));
public static final Block POTTED_GOLDEN_DANDELION = register(new Block(1169, "minecraft:potted_golden_dandelion", 0xA56D29));

private static Block register(Block block) {
blocks.put(block.getKey(), block);
return block;
Expand Down
37 changes: 24 additions & 13 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,50 @@ repositories {

dependencies {
minecraft(libs.minecraft)
mappings(loom.officialMojangMappings())

implementation(project(path = ":core", configuration = "shadow"))

implementation(libs.jspecifyAnnotations)

modImplementation(libs.fabric.loader)
modImplementation(libs.fabric.api)
implementation(libs.fabric.loader)
implementation(libs.fabric.api)

modImplementation(libs.cloudFabric)
implementation(libs.cloudFabric)
include(libs.cloudFabric)

modImplementation(libs.adventurePlatformFabric) {
implementation(libs.adventurePlatformFabric) {
exclude("net.kyori", "ansi") // TODO: temporary
}
include(libs.adventurePlatformFabric) {
exclude("net.kyori", "ansi") // TODO: temporary
}
}

tasks {
remapJar {
dependsOn(shadowJar)
inputFile.set(shadowJar.get().archiveFile)

archiveClassifier = ""
}
// https://github.com/BlueMap-Minecraft/BlueMap/blob/master/implementations/fabric/build.gradle.kts#L95-L109
val mergeShadowAndJarJar = tasks.register<Jar>("mergeShadowAndJarJar") {
dependsOn( tasks.shadowJar, tasks.jar )
from (
zipTree( tasks.shadowJar.map { it.outputs.files.singleFile } ).matching {
exclude("fabric.mod.json")
},
zipTree( tasks.jar.map { it.outputs.files.singleFile } ).matching {
include("META-INF/jars/**")
include("fabric.mod.json")
}
).exclude(
"META-INF/services/net.kyori.adventure*" // not correctly relocated and not needed -> exclude
)
archiveFileName = tasks.jar.map { it.outputs.files.singleFile.name + ".tmp"}
}

tasks {
// needed for below jank
compileJava {
dependsOn(":core:jar")
}

shadowJar {
dependsOn(jar)
mergeServiceFiles()

dependencies {
Expand All @@ -80,10 +90,11 @@ tasks {
manifest {
from(project(":core").tasks.named<Jar>("shadowJar").get().manifest)
}

}

build {
dependsOn(remapJar)
dependsOn(mergeShadowAndJarJar)
}

processResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.util.concurrent.ExecutorService;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
Expand Down Expand Up @@ -84,12 +84,12 @@ public Pl3xMapFabricClient() {

@Override
public void onInitializeClient() {
KeyBindingHelper.registerKeyBinding(PL3XMAP_TOGGLE_KEYMAP);
KeyMappingHelper.registerKeyMapping(PL3XMAP_TOGGLE_KEYMAP);

PayloadTypeRegistry.playC2S().register(ServerboundServerPayload.TYPE, ServerboundServerPayload.STREAM_CODEC);
PayloadTypeRegistry.playS2C().register(ClientboundServerPayload.TYPE, ClientboundServerPayload.STREAM_CODEC);
PayloadTypeRegistry.playC2S().register(ServerboundMapPayload.TYPE, ServerboundMapPayload.STREAM_CODEC);
PayloadTypeRegistry.playS2C().register(ClientboundMapPayload.TYPE, ClientboundMapPayload.STREAM_CODEC);
PayloadTypeRegistry.serverboundPlay().register(ServerboundServerPayload.TYPE, ServerboundServerPayload.STREAM_CODEC);
PayloadTypeRegistry.clientboundPlay().register(ClientboundServerPayload.TYPE, ClientboundServerPayload.STREAM_CODEC);
PayloadTypeRegistry.serverboundPlay().register(ServerboundMapPayload.TYPE, ServerboundMapPayload.STREAM_CODEC);
PayloadTypeRegistry.clientboundPlay().register(ClientboundMapPayload.TYPE, ClientboundMapPayload.STREAM_CODEC);

ClientPlayNetworking.registerGlobalReceiver(ClientboundServerPayload.TYPE, ClientboundServerPayload::handle);
ClientPlayNetworking.registerGlobalReceiver(ClientboundMapPayload.TYPE, ClientboundMapPayload::handle);
Expand Down Expand Up @@ -120,7 +120,7 @@ public void onInitializeClient() {
this.isEnabled = !this.isEnabled;
MutableComponent onOff = Component.translatable("pl3xmap.toggled." + (this.isEnabled ? "on" : "off"));
MutableComponent component = Component.translatable("pl3xmap.toggled.response", onOff);
Minecraft.getInstance().player.displayClientMessage(component, true);
Minecraft.getInstance().player.sendSystemMessage(component);
}
if (this.tick++ >= 20) {
this.tick = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public FabricNetwork(Pl3xMapFabricServer mod) {

@Override
public void register() {
PayloadTypeRegistry.playC2S().register(ServerboundServerPayload.TYPE, ServerboundServerPayload.STREAM_CODEC);
PayloadTypeRegistry.playS2C().register(ClientboundServerPayload.TYPE, ClientboundServerPayload.STREAM_CODEC);
PayloadTypeRegistry.playC2S().register(ServerboundMapPayload.TYPE, ServerboundMapPayload.STREAM_CODEC);
PayloadTypeRegistry.playS2C().register(ClientboundMapPayload.TYPE, ClientboundMapPayload.STREAM_CODEC);
PayloadTypeRegistry.serverboundPlay().register(ServerboundServerPayload.TYPE, ServerboundServerPayload.STREAM_CODEC);
PayloadTypeRegistry.clientboundPlay().register(ClientboundServerPayload.TYPE, ClientboundServerPayload.STREAM_CODEC);
PayloadTypeRegistry.serverboundPlay().register(ServerboundMapPayload.TYPE, ServerboundMapPayload.STREAM_CODEC);
PayloadTypeRegistry.clientboundPlay().register(ClientboundMapPayload.TYPE, ClientboundMapPayload.STREAM_CODEC);

ServerPlayNetworking.registerGlobalReceiver(ServerboundServerPayload.TYPE, (payload, context) -> {
ServerPlayNetworking.send(context.player(), new ClientboundServerPayload(Constants.PROTOCOL, Constants.RESPONSE_SUCCESS, Config.WEB_ADDRESS));
Expand Down
Loading
Loading