Functional WorldSetupScreen
This commit is contained in:
parent
faa20c608e
commit
dd0c259b56
9 changed files with 197 additions and 112 deletions
|
@ -90,11 +90,11 @@ public class GridRow extends GridContainer {
|
||||||
OnPress onPress) {
|
OnPress onPress) {
|
||||||
GridCell cell = new GridCell(width, height, widthType, (transform) -> {
|
GridCell cell = new GridCell(width, height, widthType, (transform) -> {
|
||||||
Button customButton = new Button(transform.left,
|
Button customButton = new Button(transform.left,
|
||||||
transform.top,
|
transform.top,
|
||||||
transform.width,
|
transform.width,
|
||||||
transform.height,
|
transform.height,
|
||||||
text,
|
text,
|
||||||
onPress);
|
onPress);
|
||||||
customButton.setAlpha(alpha);
|
customButton.setAlpha(alpha);
|
||||||
return customButton;
|
return customButton;
|
||||||
}, null);
|
}, null);
|
||||||
|
@ -104,6 +104,11 @@ public class GridRow extends GridContainer {
|
||||||
|
|
||||||
public GridCheckboxCell addCheckbox(Component text, boolean checked, Font font, Consumer<Boolean> onChange) {
|
public GridCheckboxCell addCheckbox(Component text, boolean checked, Font font, Consumer<Boolean> onChange) {
|
||||||
final int width = font.width(text.getVisualOrderText()) + 24 + 2 * 12;
|
final int width = font.width(text.getVisualOrderText()) + 24 + 2 * 12;
|
||||||
|
return addCheckbox(text, checked, width, widthType, onChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GridCheckboxCell addCheckbox(Component text, boolean checked, double width,
|
||||||
|
GridLayout.GridValueType widthType, Consumer<Boolean> onChange) {
|
||||||
|
|
||||||
GridCheckboxCell cell = new GridCheckboxCell(text, checked, 1.0f, width, widthType, 20, onChange);
|
GridCheckboxCell cell = new GridCheckboxCell(text, checked, 1.0f, width, widthType, 20, onChange);
|
||||||
this.cells.add(cell);
|
this.cells.add(cell);
|
||||||
|
@ -157,16 +162,16 @@ public class GridRow extends GridContainer {
|
||||||
|
|
||||||
public GridCell addImage(ResourceLocation location, float alpha, int width, int height) {
|
public GridCell addImage(ResourceLocation location, float alpha, int width, int height) {
|
||||||
return addImage(location,
|
return addImage(location,
|
||||||
alpha,
|
alpha,
|
||||||
width,
|
width,
|
||||||
GridLayout.GridValueType.CONSTANT,
|
GridLayout.GridValueType.CONSTANT,
|
||||||
height,
|
height,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
width,
|
width,
|
||||||
height);
|
height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GridCell addImage(ResourceLocation location,
|
public GridCell addImage(ResourceLocation location,
|
||||||
|
@ -186,16 +191,16 @@ public class GridRow extends GridContainer {
|
||||||
int resourceWidth,
|
int resourceWidth,
|
||||||
int resourceHeight) {
|
int resourceHeight) {
|
||||||
return addImage(location,
|
return addImage(location,
|
||||||
alpha,
|
alpha,
|
||||||
width,
|
width,
|
||||||
widthType,
|
widthType,
|
||||||
height,
|
height,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
resourceWidth,
|
resourceWidth,
|
||||||
resourceWidth,
|
resourceWidth,
|
||||||
resourceWidth,
|
resourceWidth,
|
||||||
resourceHeight);
|
resourceHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GridCell addImage(ResourceLocation location,
|
public GridCell addImage(ResourceLocation location,
|
||||||
|
@ -209,16 +214,16 @@ public class GridRow extends GridContainer {
|
||||||
int resourceWidth,
|
int resourceWidth,
|
||||||
int resourceHeight) {
|
int resourceHeight) {
|
||||||
return addImage(location,
|
return addImage(location,
|
||||||
1.0f,
|
1.0f,
|
||||||
width,
|
width,
|
||||||
widthType,
|
widthType,
|
||||||
height,
|
height,
|
||||||
uvLeft,
|
uvLeft,
|
||||||
uvTop,
|
uvTop,
|
||||||
uvWidth,
|
uvWidth,
|
||||||
uvHeight,
|
uvHeight,
|
||||||
resourceWidth,
|
resourceWidth,
|
||||||
resourceHeight);
|
resourceHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GridCell addImage(ResourceLocation location,
|
public GridCell addImage(ResourceLocation location,
|
||||||
|
@ -233,16 +238,16 @@ public class GridRow extends GridContainer {
|
||||||
int resourceWidth,
|
int resourceWidth,
|
||||||
int resourceHeight) {
|
int resourceHeight) {
|
||||||
GridCell cell = new GridImageCell(location,
|
GridCell cell = new GridImageCell(location,
|
||||||
width,
|
width,
|
||||||
widthType,
|
widthType,
|
||||||
height,
|
height,
|
||||||
alpha,
|
alpha,
|
||||||
uvLeft,
|
uvLeft,
|
||||||
uvTop,
|
uvTop,
|
||||||
uvWidth,
|
uvWidth,
|
||||||
uvHeight,
|
uvHeight,
|
||||||
resourceWidth,
|
resourceWidth,
|
||||||
resourceHeight);
|
resourceHeight);
|
||||||
this.cells.add(cell);
|
this.cells.add(cell);
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
@ -303,11 +308,11 @@ public class GridRow extends GridContainer {
|
||||||
public GridStringCell addString(Component text, int color, GridScreen parent) {
|
public GridStringCell addString(Component text, int color, GridScreen parent) {
|
||||||
final int width = parent.getWidth(text);
|
final int width = parent.getWidth(text);
|
||||||
return this.addString(text,
|
return this.addString(text,
|
||||||
width,
|
width,
|
||||||
GridLayout.GridValueType.CONSTANT,
|
GridLayout.GridValueType.CONSTANT,
|
||||||
color,
|
color,
|
||||||
GridLayout.Alignment.CENTER,
|
GridLayout.Alignment.CENTER,
|
||||||
parent);
|
parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GridStringCell addString(Component text, GridLayout.Alignment contentAlignment, GridScreen parent) {
|
public GridStringCell addString(Component text, GridLayout.Alignment contentAlignment, GridScreen parent) {
|
||||||
|
@ -336,12 +341,12 @@ public class GridRow extends GridContainer {
|
||||||
GridLayout.Alignment contentAlignment,
|
GridLayout.Alignment contentAlignment,
|
||||||
GridScreen parent) {
|
GridScreen parent) {
|
||||||
GridStringCell cell = new GridStringCell(width,
|
GridStringCell cell = new GridStringCell(width,
|
||||||
widthType,
|
widthType,
|
||||||
parent.getFont().lineHeight,
|
parent.getFont().lineHeight,
|
||||||
contentAlignment,
|
contentAlignment,
|
||||||
parent,
|
parent,
|
||||||
text,
|
text,
|
||||||
color);
|
color);
|
||||||
this.cells.add(cell);
|
this.cells.add(cell);
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,12 @@ package org.betterx.bclib.gui.screens;
|
||||||
|
|
||||||
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
|
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
|
||||||
import net.minecraft.client.gui.screens.worldselection.WorldCreationContext;
|
import net.minecraft.client.gui.screens.worldselection.WorldCreationContext;
|
||||||
import net.minecraft.core.Registry;
|
|
||||||
import net.minecraft.network.chat.CommonComponents;
|
import net.minecraft.network.chat.CommonComponents;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.world.level.dimension.BuiltinDimensionTypes;
|
||||||
|
import net.minecraft.world.level.dimension.DimensionType;
|
||||||
import net.minecraft.world.level.dimension.LevelStem;
|
import net.minecraft.world.level.dimension.LevelStem;
|
||||||
import net.minecraft.world.level.levelgen.FlatLevelSource;
|
|
||||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
|
||||||
import net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorSettings;
|
|
||||||
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
|
||||||
|
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
|
@ -19,6 +16,8 @@ import org.betterx.bclib.BCLib;
|
||||||
import org.betterx.bclib.gui.gridlayout.GridCheckboxCell;
|
import org.betterx.bclib.gui.gridlayout.GridCheckboxCell;
|
||||||
import org.betterx.bclib.gui.gridlayout.GridLayout;
|
import org.betterx.bclib.gui.gridlayout.GridLayout;
|
||||||
import org.betterx.bclib.presets.worldgen.BCLChunkGenerator;
|
import org.betterx.bclib.presets.worldgen.BCLChunkGenerator;
|
||||||
|
import org.betterx.bclib.presets.worldgen.WorldPresets;
|
||||||
|
import org.betterx.bclib.world.generator.BCLBiomeSource;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
@ -72,14 +71,16 @@ public class WorldSetupScreen extends BCLibScreen {
|
||||||
row = colNether.addRow();
|
row = colNether.addRow();
|
||||||
row.addSpacer(32);
|
row.addSpacer(32);
|
||||||
netherLegacy = row.addCheckbox(Component.translatable("title.screen.bclib.worldgen.legacy_square"),
|
netherLegacy = row.addCheckbox(Component.translatable("title.screen.bclib.worldgen.legacy_square"),
|
||||||
endVersion == BCLChunkGenerator.BIOME_SOURCE_VERSION_SQUARE,
|
endVersion == BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE,
|
||||||
font,
|
1.0,
|
||||||
|
GridLayout.GridValueType.PERCENTAGE,
|
||||||
(state) -> {
|
(state) -> {
|
||||||
});
|
});
|
||||||
bclibNether = mainSettingsRow.addCheckbox(Component.translatable(
|
bclibNether = mainSettingsRow.addCheckbox(Component.translatable(
|
||||||
"title.screen.bclib.worldgen.custom_biome_source"),
|
"title.screen.bclib.worldgen.custom_biome_source"),
|
||||||
netherVersion != BCLChunkGenerator.BIOME_SOURCE_VERSION_VANILLA,
|
netherVersion != BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA,
|
||||||
font,
|
1.0,
|
||||||
|
GridLayout.GridValueType.PERCENTAGE,
|
||||||
(state) -> {
|
(state) -> {
|
||||||
netherLegacy.setEnabled(state);
|
netherLegacy.setEnabled(state);
|
||||||
});
|
});
|
||||||
|
@ -95,15 +96,17 @@ public class WorldSetupScreen extends BCLibScreen {
|
||||||
row.addSpacer(32);
|
row.addSpacer(32);
|
||||||
|
|
||||||
endLegacy = row.addCheckbox(Component.translatable("title.screen.bclib.worldgen.legacy_square"),
|
endLegacy = row.addCheckbox(Component.translatable("title.screen.bclib.worldgen.legacy_square"),
|
||||||
endVersion == BCLChunkGenerator.BIOME_SOURCE_VERSION_SQUARE,
|
endVersion == BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE,
|
||||||
font,
|
1.0,
|
||||||
|
GridLayout.GridValueType.PERCENTAGE,
|
||||||
(state) -> {
|
(state) -> {
|
||||||
});
|
});
|
||||||
|
|
||||||
bclibEnd = mainSettingsRow.addCheckbox(Component.translatable(
|
bclibEnd = mainSettingsRow.addCheckbox(Component.translatable(
|
||||||
"title.screen.bclib.worldgen.custom_biome_source"),
|
"title.screen.bclib.worldgen.custom_biome_source"),
|
||||||
endVersion != BCLChunkGenerator.BIOME_SOURCE_VERSION_VANILLA,
|
endVersion != BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA,
|
||||||
font,
|
1.0,
|
||||||
|
GridLayout.GridValueType.PERCENTAGE,
|
||||||
(state) -> {
|
(state) -> {
|
||||||
endLegacy.setEnabled(state);
|
endLegacy.setEnabled(state);
|
||||||
});
|
});
|
||||||
|
@ -119,31 +122,43 @@ public class WorldSetupScreen extends BCLibScreen {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSettings() {
|
private void updateSettings() {
|
||||||
int endVersion = BCLChunkGenerator.DEFAULT_BIOME_SOURCE_VERSION;
|
int endVersion = BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION;
|
||||||
if (bclibEnd.isChecked()) {
|
if (bclibEnd.isChecked()) {
|
||||||
if (endLegacy.isChecked()) endVersion = BCLChunkGenerator.BIOME_SOURCE_VERSION_SQUARE;
|
if (endLegacy.isChecked()) endVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE;
|
||||||
else endVersion = BCLChunkGenerator.BIOME_SOURCE_VERSION_HEX;
|
else endVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_HEX;
|
||||||
} else {
|
} else {
|
||||||
endVersion = BCLChunkGenerator.BIOME_SOURCE_VERSION_VANILLA;
|
endVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA;
|
||||||
}
|
}
|
||||||
|
|
||||||
int netherVersion = BCLChunkGenerator.DEFAULT_BIOME_SOURCE_VERSION;
|
int netherVersion = BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION;
|
||||||
if (bclibNether.isChecked()) {
|
if (bclibNether.isChecked()) {
|
||||||
if (netherLegacy.isChecked()) netherVersion = BCLChunkGenerator.BIOME_SOURCE_VERSION_SQUARE;
|
if (netherLegacy.isChecked()) netherVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE;
|
||||||
else netherVersion = BCLChunkGenerator.BIOME_SOURCE_VERSION_HEX;
|
else netherVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_HEX;
|
||||||
} else {
|
} else {
|
||||||
netherVersion = BCLChunkGenerator.BIOME_SOURCE_VERSION_VANILLA;
|
netherVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA;
|
||||||
}
|
}
|
||||||
|
|
||||||
BCLib.LOGGER.info("Custom World Versions: end=" + endVersion + ", nether=" + netherVersion);
|
BCLib.LOGGER.info("Custom World Versions: end=" + endVersion + ", nether=" + netherVersion);
|
||||||
|
updateConfiguration(LevelStem.END, BuiltinDimensionTypes.END, endVersion);
|
||||||
|
updateConfiguration(LevelStem.NETHER, BuiltinDimensionTypes.NETHER, netherVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
private WorldCreationContext.Updater worldConfiguration(FlatLevelGeneratorSettings flatLevelGeneratorSettings) {
|
|
||||||
|
|
||||||
return (frozen, worldGenSettings) -> {
|
private void updateConfiguration(
|
||||||
Registry<StructureSet> registry = frozen.registryOrThrow(Registry.STRUCTURE_SET_REGISTRY);
|
ResourceKey<LevelStem> dimensionKey,
|
||||||
ChunkGenerator chunkGenerator = new FlatLevelSource(registry, flatLevelGeneratorSettings);
|
ResourceKey<DimensionType> dimensionTypeKey,
|
||||||
return WorldGenSettings.replaceOverworldGenerator(frozen, worldGenSettings, chunkGenerator);
|
int biomeSourceVersion
|
||||||
};
|
) {
|
||||||
|
createWorldScreen.worldGenSettingsComponent.updateSettings(
|
||||||
|
(registryAccess, worldGenSettings) -> WorldPresets.replaceGenerator(
|
||||||
|
dimensionKey,
|
||||||
|
dimensionTypeKey,
|
||||||
|
biomeSourceVersion,
|
||||||
|
registryAccess,
|
||||||
|
worldGenSettings
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import net.minecraft.world.level.levelgen.presets.WorldPresets;
|
||||||
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
||||||
import net.minecraft.world.level.levelgen.synth.NormalNoise;
|
import net.minecraft.world.level.levelgen.synth.NormalNoise;
|
||||||
|
|
||||||
import org.betterx.bclib.presets.worldgen.BCLChunkGenerator;
|
import org.betterx.bclib.world.generator.BCLBiomeSource;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
@ -82,14 +82,14 @@ public abstract class WorldPresetsBootstrapMixin {
|
||||||
this.structureSets,
|
this.structureSets,
|
||||||
this.noises,
|
this.noises,
|
||||||
this.netherNoiseSettings,
|
this.netherNoiseSettings,
|
||||||
Optional.of(BCLChunkGenerator.BIOME_SOURCE_VERSION_SQUARE)),
|
Optional.of(BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE)),
|
||||||
LevelStem.END,
|
LevelStem.END,
|
||||||
org.betterx.bclib.presets.worldgen.WorldPresets.getBCLEndLevelStem(this.biomes,
|
org.betterx.bclib.presets.worldgen.WorldPresets.getBCLEndLevelStem(this.biomes,
|
||||||
this.endDimensionType,
|
this.endDimensionType,
|
||||||
this.structureSets,
|
this.structureSets,
|
||||||
this.noises,
|
this.noises,
|
||||||
this.endNoiseSettings,
|
this.endNoiseSettings,
|
||||||
Optional.of(BCLChunkGenerator.BIOME_SOURCE_VERSION_SQUARE))
|
Optional.of(BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE))
|
||||||
), 0
|
), 0
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,6 @@ import org.betterx.bclib.world.generator.BCLBiomeSource;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
||||||
public static int BIOME_SOURCE_VERSION_NONE = -1;
|
|
||||||
public static int BIOME_SOURCE_VERSION_VANILLA = 0;
|
|
||||||
public static int BIOME_SOURCE_VERSION_SQUARE = 17;
|
|
||||||
public static int BIOME_SOURCE_VERSION_HEX = 18;
|
|
||||||
public static int DEFAULT_BIOME_SOURCE_VERSION = BIOME_SOURCE_VERSION_HEX;
|
|
||||||
|
|
||||||
private static String TAG_GENERATOR = "generator";
|
private static String TAG_GENERATOR = "generator";
|
||||||
private static final String TAG_VERSION = "version";
|
private static final String TAG_VERSION = "version";
|
||||||
|
@ -81,13 +76,8 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getBiomeVersionForGenerator(ChunkGenerator generator) {
|
public static int getBiomeVersionForGenerator(ChunkGenerator generator) {
|
||||||
if (generator == null) return BIOME_SOURCE_VERSION_NONE;
|
if (generator == null) return BCLBiomeSource.getVersionBiomeSource(null);
|
||||||
|
return BCLBiomeSource.getVersionBiomeSource(generator.getBiomeSource());
|
||||||
if (generator.getBiomeSource() instanceof BCLBiomeSource bcl) {
|
|
||||||
return bcl.biomeSourceVersion;
|
|
||||||
} else {
|
|
||||||
return BIOME_SOURCE_VERSION_VANILLA;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Optional<Holder<LevelStem>> referenceStemForVersion(
|
public static Optional<Holder<LevelStem>> referenceStemForVersion(
|
||||||
|
@ -99,13 +89,13 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
||||||
boolean generateBonusChest
|
boolean generateBonusChest
|
||||||
) {
|
) {
|
||||||
final WorldGenSettings referenceSettings;
|
final WorldGenSettings referenceSettings;
|
||||||
if (biomeSourceVersion == BIOME_SOURCE_VERSION_VANILLA) {
|
if (biomeSourceVersion == BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA) {
|
||||||
referenceSettings = net.minecraft.world.level.levelgen.presets.WorldPresets.createNormalWorldFromPreset(
|
referenceSettings = net.minecraft.world.level.levelgen.presets.WorldPresets.createNormalWorldFromPreset(
|
||||||
registryAccess,
|
registryAccess,
|
||||||
seed,
|
seed,
|
||||||
generateStructures,
|
generateStructures,
|
||||||
generateBonusChest);
|
generateBonusChest);
|
||||||
} else if (biomeSourceVersion == BIOME_SOURCE_VERSION_SQUARE) {
|
} else if (biomeSourceVersion == BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE) {
|
||||||
referenceSettings = WorldPresets.createWorldFromPreset(
|
referenceSettings = WorldPresets.createWorldFromPreset(
|
||||||
WorldPresets.BCL_WORLD_17,
|
WorldPresets.BCL_WORLD_17,
|
||||||
registryAccess,
|
registryAccess,
|
||||||
|
@ -124,7 +114,7 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
||||||
|
|
||||||
public static int getBiomeVersionForCurrentWorld(ResourceKey<LevelStem> key) {
|
public static int getBiomeVersionForCurrentWorld(ResourceKey<LevelStem> key) {
|
||||||
final CompoundTag settingsNbt = getSettingsNbt();
|
final CompoundTag settingsNbt = getSettingsNbt();
|
||||||
if (!settingsNbt.contains(key.location().toString())) return DEFAULT_BIOME_SOURCE_VERSION;
|
if (!settingsNbt.contains(key.location().toString())) return BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION;
|
||||||
return settingsNbt.getInt(key.location().toString());
|
return settingsNbt.getInt(key.location().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +145,7 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
||||||
|
|
||||||
if (settingsNbt.size() == 0) {
|
if (settingsNbt.size() == 0) {
|
||||||
BCLib.LOGGER.info("Found World without generator Settings. Setting up data...");
|
BCLib.LOGGER.info("Found World without generator Settings. Setting up data...");
|
||||||
int biomeSourceVersion = DEFAULT_BIOME_SOURCE_VERSION;
|
int biomeSourceVersion = BCLBiomeSource.DEFAULT_BIOME_SOURCE_VERSION;
|
||||||
|
|
||||||
final CompoundTag bclRoot = WorldDataAPI.getRootTag(BCLib.MOD_ID);
|
final CompoundTag bclRoot = WorldDataAPI.getRootTag(BCLib.MOD_ID);
|
||||||
|
|
||||||
|
@ -167,15 +157,15 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
||||||
|
|
||||||
if (isPre18) {
|
if (isPre18) {
|
||||||
BCLib.LOGGER.info("World was create pre 1.18!");
|
BCLib.LOGGER.info("World was create pre 1.18!");
|
||||||
biomeSourceVersion = BIOME_SOURCE_VERSION_SQUARE;
|
biomeSourceVersion = BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WorldDataAPI.hasMod("betternether")) {
|
if (WorldDataAPI.hasMod("betternether")) {
|
||||||
BCLib.LOGGER.info("Found Data from BetterNether, using for migration.");
|
BCLib.LOGGER.info("Found Data from BetterNether, using for migration.");
|
||||||
final CompoundTag bnRoot = WorldDataAPI.getRootTag("betternether");
|
final CompoundTag bnRoot = WorldDataAPI.getRootTag("betternether");
|
||||||
biomeSourceVersion = "1.17".equals(bnRoot.getString(TAG_BN_GEN_VERSION))
|
biomeSourceVersion = "1.17".equals(bnRoot.getString(TAG_BN_GEN_VERSION))
|
||||||
? BIOME_SOURCE_VERSION_SQUARE
|
? BCLBiomeSource.BIOME_SOURCE_VERSION_SQUARE
|
||||||
: BIOME_SOURCE_VERSION_HEX;
|
: BCLBiomeSource.BIOME_SOURCE_VERSION_HEX;
|
||||||
}
|
}
|
||||||
|
|
||||||
BCLib.LOGGER.info("Set world to BiomeSource Version " + biomeSourceVersion);
|
BCLib.LOGGER.info("Set world to BiomeSource Version " + biomeSourceVersion);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.betterx.bclib.presets.worldgen;
|
package org.betterx.bclib.presets.worldgen;
|
||||||
|
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.core.MappedRegistry;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.data.BuiltinRegistries;
|
import net.minecraft.data.BuiltinRegistries;
|
||||||
|
@ -9,6 +10,7 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.tags.WorldPresetTags;
|
import net.minecraft.tags.WorldPresetTags;
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.level.dimension.DimensionType;
|
import net.minecraft.world.level.dimension.DimensionType;
|
||||||
import net.minecraft.world.level.dimension.LevelStem;
|
import net.minecraft.world.level.dimension.LevelStem;
|
||||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||||
|
@ -18,6 +20,7 @@ import net.minecraft.world.level.levelgen.structure.StructureSet;
|
||||||
import net.minecraft.world.level.levelgen.synth.NormalNoise;
|
import net.minecraft.world.level.levelgen.synth.NormalNoise;
|
||||||
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
|
import com.mojang.serialization.Lifecycle;
|
||||||
import org.betterx.bclib.BCLib;
|
import org.betterx.bclib.BCLib;
|
||||||
import org.betterx.bclib.api.tag.TagAPI;
|
import org.betterx.bclib.api.tag.TagAPI;
|
||||||
import org.betterx.bclib.api.tag.TagType;
|
import org.betterx.bclib.api.tag.TagType;
|
||||||
|
@ -129,6 +132,63 @@ public class WorldPresets {
|
||||||
return createDefaultWorldFromPreset(registryAccess, RandomSource.create().nextLong());
|
return createDefaultWorldFromPreset(registryAccess, RandomSource.create().nextLong());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static WorldGenSettings replaceGenerator(
|
||||||
|
ResourceKey<LevelStem> dimensionKey,
|
||||||
|
ResourceKey<DimensionType> dimensionTypeKey,
|
||||||
|
int biomeSourceVersion,
|
||||||
|
RegistryAccess registryAccess,
|
||||||
|
WorldGenSettings worldGenSettings
|
||||||
|
) {
|
||||||
|
Optional<Holder<LevelStem>> oLevelStem = BCLChunkGenerator.referenceStemForVersion(
|
||||||
|
dimensionKey,
|
||||||
|
biomeSourceVersion,
|
||||||
|
registryAccess,
|
||||||
|
worldGenSettings.seed(),
|
||||||
|
worldGenSettings.generateStructures(),
|
||||||
|
worldGenSettings.generateStructures()
|
||||||
|
);
|
||||||
|
|
||||||
|
Registry<DimensionType> registry = registryAccess.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
|
||||||
|
Registry<LevelStem> registry2 = withDimension(dimensionKey, dimensionTypeKey, registry,
|
||||||
|
worldGenSettings.dimensions(),
|
||||||
|
oLevelStem.map(l -> l.value().generator()).orElseThrow());
|
||||||
|
return new WorldGenSettings(worldGenSettings.seed(),
|
||||||
|
worldGenSettings.generateStructures(),
|
||||||
|
worldGenSettings.generateBonusChest(),
|
||||||
|
registry2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Registry<LevelStem> withDimension(ResourceKey<LevelStem> dimensionKey,
|
||||||
|
ResourceKey<DimensionType> dimensionTypeKey,
|
||||||
|
Registry<DimensionType> registry,
|
||||||
|
Registry<LevelStem> registry2,
|
||||||
|
ChunkGenerator chunkGenerator) {
|
||||||
|
LevelStem levelStem = registry2.get(dimensionKey);
|
||||||
|
Holder<DimensionType> holder = levelStem == null
|
||||||
|
? registry.getOrCreateHolderOrThrow(dimensionTypeKey)
|
||||||
|
: levelStem.typeHolder();
|
||||||
|
return withDimension(dimensionKey, registry2, holder, chunkGenerator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Registry<LevelStem> withDimension(ResourceKey<LevelStem> dimensionKey, Registry<LevelStem> registry,
|
||||||
|
Holder<DimensionType> holder,
|
||||||
|
ChunkGenerator chunkGenerator) {
|
||||||
|
MappedRegistry<LevelStem> writableRegistry = new MappedRegistry<LevelStem>(Registry.LEVEL_STEM_REGISTRY,
|
||||||
|
Lifecycle.experimental(),
|
||||||
|
null);
|
||||||
|
writableRegistry.register(dimensionKey,
|
||||||
|
new LevelStem(holder, chunkGenerator),
|
||||||
|
Lifecycle.stable());
|
||||||
|
for (Map.Entry<ResourceKey<LevelStem>, LevelStem> entry : registry.entrySet()) {
|
||||||
|
ResourceKey<LevelStem> resourceKey = entry.getKey();
|
||||||
|
if (resourceKey == dimensionKey) continue;
|
||||||
|
writableRegistry.register(resourceKey,
|
||||||
|
entry.getValue(),
|
||||||
|
registry.lifecycle(entry.getValue()));
|
||||||
|
}
|
||||||
|
return writableRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a custom WorldPreset (with custom rules and behaviour)
|
* Registers a custom WorldPreset (with custom rules and behaviour)
|
||||||
* <p>
|
* <p>
|
||||||
|
|
|
@ -6,12 +6,16 @@ import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.biome.BiomeSource;
|
import net.minecraft.world.level.biome.BiomeSource;
|
||||||
|
|
||||||
import org.betterx.bclib.api.biomes.BiomeAPI;
|
import org.betterx.bclib.api.biomes.BiomeAPI;
|
||||||
import org.betterx.bclib.presets.worldgen.BCLChunkGenerator;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public abstract class BCLBiomeSource extends BiomeSource {
|
public abstract class BCLBiomeSource extends BiomeSource {
|
||||||
|
public static int BIOME_SOURCE_VERSION_NONE = -1;
|
||||||
|
public static int BIOME_SOURCE_VERSION_VANILLA = 0;
|
||||||
|
public static int BIOME_SOURCE_VERSION_SQUARE = 17;
|
||||||
|
public static int BIOME_SOURCE_VERSION_HEX = 18;
|
||||||
|
public static int DEFAULT_BIOME_SOURCE_VERSION = BIOME_SOURCE_VERSION_HEX;
|
||||||
protected final Registry<Biome> biomeRegistry;
|
protected final Registry<Biome> biomeRegistry;
|
||||||
protected long currentSeed;
|
protected long currentSeed;
|
||||||
|
|
||||||
|
@ -29,7 +33,7 @@ public abstract class BCLBiomeSource extends BiomeSource {
|
||||||
super(preInit(biomeRegistry, list));
|
super(preInit(biomeRegistry, list));
|
||||||
|
|
||||||
this.biomeRegistry = biomeRegistry;
|
this.biomeRegistry = biomeRegistry;
|
||||||
this.biomeSourceVersion = biomeSourceVersion.orElse(BCLChunkGenerator.DEFAULT_BIOME_SOURCE_VERSION);
|
this.biomeSourceVersion = biomeSourceVersion.orElse(DEFAULT_BIOME_SOURCE_VERSION);
|
||||||
this.currentSeed = seed;
|
this.currentSeed = seed;
|
||||||
|
|
||||||
System.out.println(this + " with Registry: " + biomeRegistry.getClass().getName() + "@" + Integer.toHexString(
|
System.out.println(this + " with Registry: " + biomeRegistry.getClass().getName() + "@" + Integer.toHexString(
|
||||||
|
@ -52,4 +56,14 @@ public abstract class BCLBiomeSource extends BiomeSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void onInitMap(long newSeed);
|
protected abstract void onInitMap(long newSeed);
|
||||||
|
|
||||||
|
public static int getVersionBiomeSource(BiomeSource biomeSource) {
|
||||||
|
if (biomeSource == null) return BCLBiomeSource.BIOME_SOURCE_VERSION_NONE;
|
||||||
|
|
||||||
|
if (biomeSource instanceof BCLBiomeSource bcl) {
|
||||||
|
return bcl.biomeSourceVersion;
|
||||||
|
} else {
|
||||||
|
return BCLBiomeSource.BIOME_SOURCE_VERSION_VANILLA;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.betterx.bclib.config.ConfigKeeper.StringArrayEntry;
|
||||||
import org.betterx.bclib.config.Configs;
|
import org.betterx.bclib.config.Configs;
|
||||||
import org.betterx.bclib.interfaces.BiomeMap;
|
import org.betterx.bclib.interfaces.BiomeMap;
|
||||||
import org.betterx.bclib.noise.OpenSimplexNoise;
|
import org.betterx.bclib.noise.OpenSimplexNoise;
|
||||||
import org.betterx.bclib.presets.worldgen.BCLChunkGenerator;
|
|
||||||
import org.betterx.bclib.world.biomes.BCLBiome;
|
import org.betterx.bclib.world.biomes.BCLBiome;
|
||||||
import org.betterx.bclib.world.generator.map.hex.HexBiomeMap;
|
import org.betterx.bclib.world.generator.map.hex.HexBiomeMap;
|
||||||
import org.betterx.bclib.world.generator.map.square.SquareBiomeMap;
|
import org.betterx.bclib.world.generator.map.square.SquareBiomeMap;
|
||||||
|
@ -187,7 +186,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInitMap(long seed) {
|
protected void onInitMap(long seed) {
|
||||||
if ((biomeSourceVersion != BCLChunkGenerator.BIOME_SOURCE_VERSION_HEX)) {
|
if ((biomeSourceVersion != BCLBiomeSource.BIOME_SOURCE_VERSION_HEX)) {
|
||||||
this.mapLand = new SquareBiomeMap(seed,
|
this.mapLand = new SquareBiomeMap(seed,
|
||||||
GeneratorOptions.getBiomeSizeEndLand(),
|
GeneratorOptions.getBiomeSizeEndLand(),
|
||||||
endLandBiomePicker);
|
endLandBiomePicker);
|
||||||
|
|
|
@ -19,7 +19,6 @@ import org.betterx.bclib.api.biomes.BiomeAPI;
|
||||||
import org.betterx.bclib.config.ConfigKeeper.StringArrayEntry;
|
import org.betterx.bclib.config.ConfigKeeper.StringArrayEntry;
|
||||||
import org.betterx.bclib.config.Configs;
|
import org.betterx.bclib.config.Configs;
|
||||||
import org.betterx.bclib.interfaces.BiomeMap;
|
import org.betterx.bclib.interfaces.BiomeMap;
|
||||||
import org.betterx.bclib.presets.worldgen.BCLChunkGenerator;
|
|
||||||
import org.betterx.bclib.world.biomes.BCLBiome;
|
import org.betterx.bclib.world.biomes.BCLBiome;
|
||||||
import org.betterx.bclib.world.generator.map.MapStack;
|
import org.betterx.bclib.world.generator.map.MapStack;
|
||||||
import org.betterx.bclib.world.generator.map.hex.HexBiomeMap;
|
import org.betterx.bclib.world.generator.map.hex.HexBiomeMap;
|
||||||
|
@ -156,7 +155,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInitMap(long seed) {
|
protected void onInitMap(long seed) {
|
||||||
TriFunction<Long, Integer, BiomePicker, BiomeMap> mapConstructor = (biomeSourceVersion != BCLChunkGenerator.BIOME_SOURCE_VERSION_HEX)
|
TriFunction<Long, Integer, BiomePicker, BiomeMap> mapConstructor = (biomeSourceVersion != BCLBiomeSource.BIOME_SOURCE_VERSION_HEX)
|
||||||
? SquareBiomeMap::new
|
? SquareBiomeMap::new
|
||||||
: HexBiomeMap::new;
|
: HexBiomeMap::new;
|
||||||
if (worldHeight > 128 && GeneratorOptions.useVerticalBiomes()) {
|
if (worldHeight > 128 && GeneratorOptions.useVerticalBiomes()) {
|
||||||
|
|
|
@ -10,3 +10,6 @@ accessible class net/minecraft/world/level/levelgen/SurfaceRules$LazyCondition
|
||||||
accessible class net/minecraft/world/level/levelgen/SurfaceRules$SequenceRuleSource
|
accessible class net/minecraft/world/level/levelgen/SurfaceRules$SequenceRuleSource
|
||||||
accessible class net/minecraft/world/level/levelgen/presets/WorldPresets$Bootstrap
|
accessible class net/minecraft/world/level/levelgen/presets/WorldPresets$Bootstrap
|
||||||
extendable class net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator
|
extendable class net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator
|
||||||
|
|
||||||
|
#Methods
|
||||||
|
accessible method net/minecraft/client/gui/screens/worldselection/WorldGenSettingsComponent updateSettings (Lnet/minecraft/client/gui/screens/worldselection/WorldCreationContext$Updater;)V
|
Loading…
Add table
Add a link
Reference in a new issue