Skip to content

Commit 244adbf

Browse files
committed
Add support for minecraft version 1.21
Took 24 minutes
1 parent ac172ec commit 244adbf

33 files changed

Lines changed: 3313 additions & 2 deletions

impl/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<module>v1_20_R2</module>
4646
<module>v1_20_R3</module>
4747
<module>v1_20_R4</module>
48+
<module>v1_21_R1</module>
4849
</modules>
4950

5051
<artifactId>ore-control-impl</artifactId>

impl/v1_21_R1/pom.xml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ MIT License
4+
~
5+
~ Copyright (c) 2019 - 2022 Marvin (DerFrZocker)
6+
~
7+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
8+
~ of this software and associated documentation files (the "Software"), to deal
9+
~ in the Software without restriction, including without limitation the rights
10+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
~ copies of the Software, and to permit persons to whom the Software is
12+
~ furnished to do so, subject to the following conditions:
13+
~
14+
~ The above copyright notice and this permission notice shall be included in all
15+
~ copies or substantial portions of the Software.
16+
~
17+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
~ SOFTWARE.
24+
~
25+
-->
26+
27+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
28+
xmlns="http://maven.apache.org/POM/4.0.0"
29+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
30+
<modelVersion>4.0.0</modelVersion>
31+
32+
<parent>
33+
<artifactId>ore-control-impl</artifactId>
34+
<groupId>de.derfrzocker</groupId>
35+
<version>${revision}</version>
36+
</parent>
37+
38+
<artifactId>ore-control-impl-v1_21_R1</artifactId>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>de.derfrzocker</groupId>
43+
<artifactId>ore-control-api</artifactId>
44+
<version>${project.version}</version>
45+
<scope>provided</scope>
46+
</dependency>
47+
<dependency>
48+
<groupId>de.derfrzocker</groupId>
49+
<artifactId>ore-control-common</artifactId>
50+
<version>${project.version}</version>
51+
<scope>provided</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.spigotmc</groupId>
55+
<artifactId>spigot</artifactId>
56+
<version>1.21-R0.1-SNAPSHOT</version>
57+
<classifier>remapped-mojang</classifier>
58+
<scope>provided</scope>
59+
<optional>true</optional>
60+
</dependency>
61+
</dependencies>
62+
63+
<build>
64+
<plugins>
65+
<plugin>
66+
<groupId>net.md-5</groupId>
67+
<artifactId>specialsource-maven-plugin</artifactId>
68+
<version>2.0.3</version>
69+
<executions>
70+
<execution>
71+
<phase>package</phase>
72+
<goals>
73+
<goal>remap</goal>
74+
</goals>
75+
<id>remap-obf</id>
76+
<configuration>
77+
<srgIn>org.spigotmc:minecraft-server:1.21-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
78+
<reverse>true</reverse>
79+
<remappedDependencies>org.spigotmc:spigot:1.21-R0.1-SNAPSHOT:jar:remapped-mojang
80+
</remappedDependencies>
81+
<remappedArtifactAttached>true</remappedArtifactAttached>
82+
<remappedClassifierName>remapped-obf</remappedClassifierName>
83+
</configuration>
84+
</execution>
85+
<execution>
86+
<phase>package</phase>
87+
<goals>
88+
<goal>remap</goal>
89+
</goals>
90+
<id>remap-spigot</id>
91+
<configuration>
92+
<inputFile>
93+
${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar
94+
</inputFile>
95+
<srgIn>org.spigotmc:minecraft-server:1.21-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
96+
<remappedDependencies>org.spigotmc:spigot:1.21-R0.1-SNAPSHOT:jar:remapped-obf
97+
</remappedDependencies>
98+
</configuration>
99+
</execution>
100+
</executions>
101+
</plugin>
102+
</plugins>
103+
</build>
104+
105+
</project>
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2019 - 2022 Marvin (DerFrZocker)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
package de.derfrzocker.feature.impl.v1_21_R1.extra;
27+
28+
import de.derfrzocker.feature.api.ExtraValues;
29+
import de.derfrzocker.ore.control.api.OreControlManager;
30+
import de.derfrzocker.ore.control.api.config.ConfigInfo;
31+
import de.derfrzocker.ore.control.api.config.ConfigManager;
32+
import de.derfrzocker.ore.control.impl.v1_21_R1.NMSReflectionNames;
33+
import java.lang.reflect.Field;
34+
import java.util.HashSet;
35+
import java.util.Optional;
36+
import java.util.Set;
37+
import net.minecraft.core.Holder;
38+
import net.minecraft.server.level.ChunkMap;
39+
import net.minecraft.world.level.chunk.status.WorldGenContext;
40+
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
41+
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
42+
import org.bukkit.World;
43+
import org.bukkit.craftbukkit.v1_21_R1.CraftWorld;
44+
import org.bukkit.event.EventHandler;
45+
import org.bukkit.event.EventPriority;
46+
import org.bukkit.event.Listener;
47+
import org.bukkit.event.world.WorldInitEvent;
48+
import org.bukkit.event.world.WorldUnloadEvent;
49+
50+
public class OreVeinHandler implements Listener {
51+
52+
private final static Field WORLD_GEN_CONTEXT_FIELD;
53+
private final static Field NOISE_GENERATOR_SETTINGS_FIELD;
54+
55+
static {
56+
try {
57+
WORLD_GEN_CONTEXT_FIELD = ChunkMap.class.getDeclaredField(NMSReflectionNames.CHUNK_MAP_WORLD_GEN_CONTEXT);
58+
WORLD_GEN_CONTEXT_FIELD.setAccessible(true);
59+
NOISE_GENERATOR_SETTINGS_FIELD = NoiseBasedChunkGenerator.class.getDeclaredField(NMSReflectionNames.NOISE_GENERATOR_SETTINGS);
60+
NOISE_GENERATOR_SETTINGS_FIELD.setAccessible(true);
61+
} catch (NoSuchFieldException e) {
62+
throw new RuntimeException(e);
63+
}
64+
}
65+
66+
private final Set<World> hookedWorlds = new HashSet<>();
67+
private final ConfigManager configManager;
68+
69+
public OreVeinHandler(OreControlManager oreControlManager) {
70+
this.configManager = oreControlManager.getConfigManager();
71+
oreControlManager.addValueChangeListener(this::update);
72+
}
73+
74+
@EventHandler(priority = EventPriority.LOW)
75+
public void onWorldInit(WorldInitEvent event) {
76+
if (!(((CraftWorld) event.getWorld()).getHandle().getChunkSource().getGenerator() instanceof NoiseBasedChunkGenerator noiseChunkGenerator)) {
77+
return;
78+
}
79+
80+
NoiseGeneratorSettings newSettings = getNewValue(event.getWorld(), noiseChunkGenerator.settings.value());
81+
NoiseBasedChunkGenerator newGenerator = new NoiseBasedChunkGenerator(noiseChunkGenerator.getBiomeSource(), Holder.direct(newSettings));
82+
83+
try {
84+
WorldGenContext worldGenContext = (WorldGenContext) WORLD_GEN_CONTEXT_FIELD.get(((CraftWorld) event.getWorld()).getHandle().getChunkSource().chunkMap);
85+
WORLD_GEN_CONTEXT_FIELD.set(((CraftWorld) event.getWorld()).getHandle().getChunkSource().chunkMap, new WorldGenContext(worldGenContext.level(), newGenerator, worldGenContext.structureManager(), worldGenContext.lightEngine(), worldGenContext.mainThreadMailBox()));
86+
} catch (IllegalAccessException e) {
87+
throw new RuntimeException(e);
88+
}
89+
90+
hookedWorlds.add(event.getWorld());
91+
}
92+
93+
@EventHandler
94+
public void onWorldUnload(WorldUnloadEvent event) {
95+
// Cleanup
96+
hookedWorlds.remove(event.getWorld());
97+
}
98+
99+
private NoiseGeneratorSettings getNewValue(World world, NoiseGeneratorSettings old) {
100+
ConfigInfo configInfo = configManager.getOrCreateConfigInfo(world.getName());
101+
Optional<ExtraValues> optionalExtraValues = configManager.getGenerationExtraValues(configInfo);
102+
103+
boolean newValue = optionalExtraValues.flatMap(ExtraValues::shouldGeneratedBigOreVeins).orElse(old.oreVeinsEnabled());
104+
105+
return new NoiseGeneratorSettings(old.noiseSettings(), old.defaultBlock(), old.defaultFluid(),
106+
old.noiseRouter(), old.surfaceRule(), old.spawnTarget(), old.seaLevel(), old.disableMobGeneration(), old.aquifersEnabled(), newValue, old.useLegacyRandomSource());
107+
}
108+
109+
private void update() {
110+
for (World world : hookedWorlds) {
111+
if (!(((CraftWorld) world).getHandle().getChunkSource().getGenerator() instanceof NoiseBasedChunkGenerator noiseChunkGenerator)) {
112+
return;
113+
}
114+
115+
NoiseGeneratorSettings newSettings = getNewValue(world, noiseChunkGenerator.settings.value());
116+
117+
try {
118+
NOISE_GENERATOR_SETTINGS_FIELD.set(noiseChunkGenerator, Holder.direct(newSettings));
119+
} catch (IllegalAccessException e) {
120+
throw new RuntimeException(e);
121+
}
122+
}
123+
}
124+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2019 - 2022 Marvin (DerFrZocker)
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
*/
25+
26+
package de.derfrzocker.feature.impl.v1_21_R1.feature.generator;
27+
28+
import com.google.gson.JsonElement;
29+
import com.google.gson.JsonObject;
30+
import de.derfrzocker.feature.api.Configuration;
31+
import de.derfrzocker.feature.api.Registries;
32+
import de.derfrzocker.feature.api.Setting;
33+
import de.derfrzocker.feature.api.util.Parser;
34+
import de.derfrzocker.feature.common.feature.generator.configuration.EmptyFeatureConfiguration;
35+
import java.util.Collections;
36+
import java.util.Random;
37+
import java.util.Set;
38+
import net.minecraft.world.level.levelgen.feature.Feature;
39+
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
40+
import org.bukkit.generator.LimitedRegion;
41+
import org.bukkit.generator.WorldInfo;
42+
import org.bukkit.util.BlockVector;
43+
import org.jetbrains.annotations.NotNull;
44+
45+
public class EmptyConfigurationGenerator extends MinecraftFeatureGenerator<NoneFeatureConfiguration, EmptyFeatureConfiguration> {
46+
47+
private EmptyConfigurationGenerator(Registries registries, Feature<NoneFeatureConfiguration> feature, String name) {
48+
super(registries, feature, name);
49+
}
50+
51+
public static EmptyConfigurationGenerator createGlowstoneBlob(Registries registries) {
52+
return new EmptyConfigurationGenerator(registries, Feature.GLOWSTONE_BLOB, "glowstone_blob");
53+
}
54+
55+
@Override
56+
public @NotNull Set<Setting> getSettings() {
57+
return Collections.emptySet();
58+
}
59+
60+
@Override
61+
public @NotNull Configuration createEmptyConfiguration() {
62+
return new EmptyFeatureConfiguration(this);
63+
}
64+
65+
@Override
66+
public EmptyFeatureConfiguration mergeConfig(EmptyFeatureConfiguration first, EmptyFeatureConfiguration second) {
67+
return first;
68+
}
69+
70+
@Override
71+
public Parser<EmptyFeatureConfiguration> createParser(Registries registries) {
72+
return new Parser<>() {
73+
@Override
74+
public JsonElement toJson(EmptyFeatureConfiguration value) {
75+
return new JsonObject();
76+
}
77+
78+
@Override
79+
public EmptyFeatureConfiguration fromJson(JsonElement jsonElement) {
80+
return new EmptyFeatureConfiguration(EmptyConfigurationGenerator.this);
81+
}
82+
};
83+
}
84+
85+
@Override
86+
public NoneFeatureConfiguration createConfiguration(@NotNull WorldInfo worldInfo, @NotNull Random random, @NotNull BlockVector position, @NotNull LimitedRegion limitedRegion, @NotNull EmptyFeatureConfiguration configuration) {
87+
return NoneFeatureConfiguration.INSTANCE;
88+
}
89+
}

0 commit comments

Comments
 (0)