Skip to content

Commit

Permalink
Merge pull request #323 from PolyhedralDev/ver/6.1.2
Browse files Browse the repository at this point in the history
Reimplement Cloud and update Bukkit implementation to 1.19 with Paperweight
  • Loading branch information
dfsek authored Jun 13, 2022
2 parents d93f11b + a94c0ad commit 9abac34
Show file tree
Hide file tree
Showing 28 changed files with 919 additions and 275 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
preRelease(true)

versionProjects(":common:api", version("6.1.1"))
versionProjects(":common:implementation", version("6.1.1"))
versionProjects(":platforms", version("6.1.1"))
versionProjects(":common:api", version("6.1.2"))
versionProjects(":common:implementation", version("6.1.2"))
versionProjects(":platforms", version("6.1.2"))


allprojects {
Expand Down
5 changes: 5 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ repositories {
mavenCentral()
gradlePluginPortal()
maven { url = uri("https://repo.codemc.org/repository/maven-public") }
maven("https://papermc.io/repo/repository/maven-public/") {
name = "PaperMC"
}
}

dependencies {
implementation("gradle.plugin.com.github.jengelman.gradle.plugins:shadow:+")
implementation("io.papermc.paperweight.userdev:io.papermc.paperweight.userdev.gradle.plugin:1.3.5")

implementation("org.ow2.asm:asm:9.3")
implementation("org.ow2.asm:asm-tree:9.3")
implementation("com.dfsek.tectonic:common:4.2.0")
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object Versions {
const val paralithic = "0.7.0"
const val strata = "1.1.1"

const val cloud = "1.6.2"
const val cloud = "1.7.0-SNAPSHOT"

const val slf4j = "1.7.36"
const val log4j_slf4j_impl = "2.14.1"
Expand Down
11 changes: 10 additions & 1 deletion platforms/bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import java.nio.channels.Channels
import java.nio.file.Files
import java.nio.file.StandardCopyOption

plugins {
id("xyz.jpenilla.run-paper") version "1.0.6"
}

val mcVersion = "1.18.2"
val testDir = "target/server"
Expand All @@ -13,9 +16,15 @@ val paperBuild = 350
val paperURL = "https://papermc.io/api/v2/projects/paper/versions/%version%/builds/$paperBuild/downloads/paper-%version%-$paperBuild.jar"
val purpurURL = "https://api.purpurmc.org/v2/purpur/%version%/latest/download"

repositories {
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}

dependencies {
shaded(project(":platforms:bukkit:common"))
shaded(project(":platforms:bukkit:nms:v1_18_R2"))
shaded(project(":platforms:bukkit:nms:v1_18_R2", configuration = "reobf"))
shaded(project(":platforms:bukkit:nms:v1_19_R1", configuration = "reobf"))
shaded("xyz.jpenilla", "reflection-remapper", "0.1.0-SNAPSHOT")
}

val throttleCoreCount = 0
Expand Down
17 changes: 14 additions & 3 deletions platforms/bukkit/nms/v1_18_R2/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
apply(plugin = "io.papermc.paperweight.userdev")

repositories {
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}

dependencies {
api(project(":platforms:bukkit:common"))

compileOnly("io.papermc.paper:paper-api:1.18.2-R0.1-20220519.005047-123")
compileOnly(group = "org.spigotmc", name = "spigot", version = "1.18.2-R0.1-SNAPSHOT")
paperDevBundle("1.18.2-R0.1-SNAPSHOT")
implementation("xyz.jpenilla", "reflection-remapper", "0.1.0-SNAPSHOT")
}

tasks {
assemble {
dependsOn("reobfJar")
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.dfsek.terra.bukkit.nms.v1_18_R2;

import com.dfsek.terra.api.properties.Properties;

import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.BiomeBase;
import net.minecraft.world.level.biome.Biome;

import com.dfsek.terra.api.properties.Properties;


public record NMSBiomeInfo(ResourceKey<BiomeBase> biomeKey) implements Properties {
public record NMSBiomeInfo(ResourceKey<Biome> biomeKey) implements Properties {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@
import com.google.common.collect.ImmutableMap;
import com.mojang.serialization.Lifecycle;
import net.minecraft.core.Holder;
import net.minecraft.core.IRegistry;
import net.minecraft.core.IRegistryWritable;
import net.minecraft.core.RegistryMaterials;
import net.minecraft.data.RegistryGeneration;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.core.MappedRegistry;
import net.minecraft.core.Registry;
import net.minecraft.core.WritableRegistry;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.biome.BiomeBase;
import net.minecraft.world.level.biome.BiomeFog;
import net.minecraft.world.level.biome.BiomeFog.GrassColor;
import net.minecraft.world.level.biome.BiomeSettingsGeneration;
import net.minecraft.world.level.biome.BiomeSettingsMobs;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSpecialEffects;
import org.bukkit.NamespacedKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -29,57 +25,55 @@
import java.util.Optional;

import com.dfsek.terra.api.config.ConfigPack;
import com.dfsek.terra.api.world.biome.Biome;
import com.dfsek.terra.bukkit.config.VanillaBiomeProperties;
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
import com.dfsek.terra.registry.master.ConfigRegistry;


public class NMSBiomeInjector {
private static final Logger LOGGER = LoggerFactory.getLogger(NMSBiomeInjector.class);
private static final Map<MinecraftKey, List<MinecraftKey>> terraBiomeMap = new HashMap<>();
private static final Map<ResourceLocation, List<ResourceLocation>> terraBiomeMap = new HashMap<>();


public static void registerBiomes(ConfigRegistry configRegistry) {
try {
LOGGER.info("Hacking biome registry...");
IRegistryWritable<BiomeBase> biomeRegistry = (IRegistryWritable<BiomeBase>) Registries.biomeRegistry();
Field frozen = RegistryMaterials.class.getDeclaredField("bL"); // registry frozen field
frozen.setAccessible(true);
frozen.set(biomeRegistry, false);
WritableRegistry<Biome> biomeRegistry = (WritableRegistry<Biome>) Registries.biomeRegistry();

configRegistry.forEach(pack -> pack.getRegistry(Biome.class).forEach((key, biome) -> {
Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry<?>) biomeRegistry, false);

configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> {
try {
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey();
MinecraftKey vanillaMinecraftKey = new MinecraftKey(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey());
BiomeBase platform = createBiome(
ResourceLocation vanillaMinecraftKey = new ResourceLocation(vanillaBukkitKey.getNamespace(), vanillaBukkitKey.getKey());
Biome platform = createBiome(
biome,
biomeRegistry.a(vanillaMinecraftKey) // get
biomeRegistry.get(vanillaMinecraftKey) // get
);

ResourceKey<BiomeBase> delegateKey = ResourceKey.a(IRegistry.aP, new MinecraftKey("terra", createBiomeID(pack, key)));
ResourceKey<Biome> delegateKey = ResourceKey.create(Registry.BIOME_REGISTRY, new ResourceLocation("terra", createBiomeID(pack, key)));

RegistryGeneration.a(RegistryGeneration.i, delegateKey, platform);
biomeRegistry.a(delegateKey, platform, Lifecycle.stable());
BuiltinRegistries.register(BuiltinRegistries.BIOME, delegateKey, platform);
biomeRegistry.register(delegateKey, platform, Lifecycle.stable());
platformBiome.getContext().put(new NMSBiomeInfo(delegateKey));

terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.a());
terraBiomeMap.computeIfAbsent(vanillaMinecraftKey, i -> new ArrayList<>()).add(delegateKey.location());

LOGGER.debug("Registered biome: " + delegateKey);
} catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}));
frozen.set(biomeRegistry, true); // freeze registry again :)

Reflection.MAPPED_REGISTRY.setFrozen((MappedRegistry<?>) biomeRegistry, true); // freeze registry again :)

LOGGER.info("Doing tag garbage....");
Map<TagKey<BiomeBase>, List<Holder<BiomeBase>>> collect = biomeRegistry
.g() // streamKeysAndEntries
Map<TagKey<Biome>, List<Holder<Biome>>> collect = biomeRegistry
.getTags() // streamKeysAndEntries
.collect(HashMap::new,
(map, pair) ->
map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().a().toList())),
map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())),
HashMap::putAll);

terraBiomeMap
Expand All @@ -90,13 +84,13 @@ public static void registerBiomes(ConfigRegistry configRegistry) {
.forEach(tb -> getEntry(biomeRegistry, tb)
.ifPresentOrElse(
terra -> {
LOGGER.debug(vanilla.e().orElseThrow().a() +
LOGGER.debug(vanilla.unwrapKey().orElseThrow().location() +
" (vanilla for " +
terra.e().orElseThrow().a() +
terra.unwrapKey().orElseThrow().location() +
": " +
vanilla.c().toList());
vanilla.tags().toList());

vanilla.c()
vanilla.tags()
.forEach(
tag -> collect
.computeIfAbsent(tag,
Expand All @@ -108,77 +102,63 @@ public static void registerBiomes(ConfigRegistry configRegistry) {
tb))),
() -> LOGGER.error("No vanilla biome: {}", vb)));

biomeRegistry.k(); // clearTags
biomeRegistry.a(ImmutableMap.copyOf(collect)); // populateTags
biomeRegistry.resetTags(); // clearTags
biomeRegistry.bindTags(ImmutableMap.copyOf(collect)); // populateTags

} catch(NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException exception) {
} catch(SecurityException | IllegalArgumentException exception) {
throw new RuntimeException(exception);
}
}

public static <T> Optional<Holder<T>> getEntry(IRegistry<T> registry, MinecraftKey identifier) {
return registry.b(identifier)
.flatMap(registry::c)
.map(registry::c);
public static <T> Optional<Holder<T>> getEntry(Registry<T> registry, ResourceLocation identifier) {
return registry.getOptional(identifier)
.flatMap(registry::getResourceKey)
.map(registry::getOrCreateHolder);
}

private static BiomeBase createBiome(Biome biome, BiomeBase vanilla)
private static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Biome vanilla)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
BiomeBase.a builder = new BiomeBase.a(); // Builder

Field f = BiomeBase.class.getDeclaredField("l"); // category
f.setAccessible(true);
builder.a((BiomeBase.Geography) f.get(vanilla))
.a(vanilla.c()); // getPrecipitation


Field biomeSettingMobsField = BiomeBase.class.getDeclaredField("k"); // spawn settings
biomeSettingMobsField.setAccessible(true);
BiomeSettingsMobs biomeSettingMobs = (BiomeSettingsMobs) biomeSettingMobsField.get(vanilla);
builder.a(biomeSettingMobs);

Biome.BiomeBuilder builder = new Biome.BiomeBuilder(); // Builder

BiomeSettingsGeneration.a generationBuilder = new BiomeSettingsGeneration.a(); // builder
builder.a(generationBuilder.a())
.a(vanilla.c())
.b(vanilla.h()) // precipitation
.a(vanilla.i()); // temp

builder.biomeCategory(Reflection.BIOME.getBiomeCategory(vanilla))
.precipitation(vanilla.getPrecipitation()) // getPrecipitation
.mobSpawnSettings(vanilla.getMobSettings())
.generationSettings(vanilla.getGenerationSettings())
.temperature(vanilla.getBaseTemperature())
.downfall(vanilla.getDownfall());



BiomeFog.a effects = new BiomeFog.a(); // Builder
effects.a(GrassColor.a); // magic

BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder();

effects.grassColorModifier(vanilla.getSpecialEffects().getGrassColorModifier());

VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);

// fog
effects.a(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.f()));

// water
effects.b(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.k()));

// water fog
effects.c(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.l()));

// sky
effects.d(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.a()));


effects.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor()))

.waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor()))

.waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor()))

.skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor()));

if(vanillaBiomeProperties.getFoliageColor() == null) {
vanilla.j().e().ifPresent(effects::e);
vanilla.getSpecialEffects().getFoliageColorOverride().ifPresent(effects::foliageColorOverride);
} else {
// foliage
effects.e(vanillaBiomeProperties.getFoliageColor());
effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor());
}

if(vanillaBiomeProperties.getGrassColor() == null) {
vanilla.j().f().ifPresent(effects::f);
vanilla.getSpecialEffects().getGrassColorOverride().ifPresent(effects::grassColorOverride);
} else {
// grass
effects.f(vanillaBiomeProperties.getGrassColor());
effects.grassColorOverride(vanillaBiomeProperties.getGrassColor());
}

builder.specialEffects(effects.build());

builder.a(effects.a()); // build()

return builder.a(); // build()
return builder.build(); // build()
}

public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) {
Expand Down
Loading

0 comments on commit 9abac34

Please sign in to comment.