mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 22:10:22 +00:00
create TerraOptionsScreen
This commit is contained in:
1 parent
1186fc6624
commit
66758859bb
9 files changed
+176
-14
No files matched your search
@@ -13,6 +13,11 @@ public class MutableInteger extends MutableNumber<Integer> {
|
|||||||
add(1);
|
add(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addMod(int add, int mod) {
|
||||||
|
add(add);
|
||||||
|
value %= mod;
|
||||||
|
}
|
||||||
|
|
||||||
public void decrement() {
|
public void decrement() {
|
||||||
subtract(1);
|
subtract(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ import com.dfsek.terra.registry.exception.DuplicateEntryException;
|
|||||||
import com.dfsek.terra.registry.master.AddonRegistry;
|
import com.dfsek.terra.registry.master.AddonRegistry;
|
||||||
import com.dfsek.terra.registry.master.ConfigRegistry;
|
import com.dfsek.terra.registry.master.ConfigRegistry;
|
||||||
import com.dfsek.terra.world.TerraWorld;
|
import com.dfsek.terra.world.TerraWorld;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
@@ -63,12 +64,14 @@ import net.minecraft.server.command.ServerCommandSource;
|
|||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.registry.BuiltinRegistries;
|
import net.minecraft.util.registry.BuiltinRegistries;
|
||||||
|
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
import net.minecraft.util.registry.RegistryKey;
|
import net.minecraft.util.registry.RegistryKey;
|
||||||
import net.minecraft.world.biome.Biome;
|
import net.minecraft.world.biome.Biome;
|
||||||
import net.minecraft.world.biome.BiomeEffects;
|
import net.minecraft.world.biome.BiomeEffects;
|
||||||
import net.minecraft.world.biome.GenerationSettings;
|
import net.minecraft.world.biome.GenerationSettings;
|
||||||
import net.minecraft.world.gen.GenerationStep;
|
import net.minecraft.world.gen.GenerationStep;
|
||||||
|
import net.minecraft.world.gen.GeneratorOptions;
|
||||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||||
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||||
import net.minecraft.world.gen.decorator.Decorator;
|
import net.minecraft.world.gen.decorator.Decorator;
|
||||||
@@ -91,6 +94,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import static net.minecraft.server.command.CommandManager.argument;
|
import static net.minecraft.server.command.CommandManager.argument;
|
||||||
import static net.minecraft.server.command.CommandManager.literal;
|
import static net.minecraft.server.command.CommandManager.literal;
|
||||||
@@ -300,16 +304,28 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
|||||||
|
|
||||||
if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||||
registry.forEach(pack -> {
|
registry.forEach(pack -> {
|
||||||
final GeneratorType generatorType = new GeneratorType("terra." + pack.getTemplate().getID()) {
|
|
||||||
@Override
|
|
||||||
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
|
||||||
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
((GeneratorTypeAccessor) generatorType).setTranslationKey(new LiteralText("Terra:" + pack.getTemplate().getID()));
|
|
||||||
GeneratorTypeAccessor.getValues().add(generatorType);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ConfigPack pack = registry.get("DEFAULT");
|
||||||
|
final GeneratorType generatorType = new GeneratorType("terra") {
|
||||||
|
@Override
|
||||||
|
public GeneratorOptions createDefaultOptions(DynamicRegistryManager.Impl registryManager, long seed, boolean generateStructures, boolean bonusChest) {
|
||||||
|
return super.createDefaultOptions(registryManager, seed, generateStructures, bonusChest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||||
|
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Map<Optional<GeneratorType>, GeneratorType.ScreenProvider> screenProviderMap = new HashMap<>(GeneratorTypeAccessor.getScreenProviders());
|
||||||
|
|
||||||
|
screenProviderMap.put(Optional.of(generatorType), (screen, generatorOptions) -> new TerraOptionsScreen(screen));
|
||||||
|
|
||||||
|
GeneratorTypeAccessor.setScreenProviders(ImmutableMap.copyOf(screenProviderMap)); // jumping through hoops because ImmutableMap
|
||||||
|
|
||||||
|
GeneratorTypeAccessor.getValues().add(generatorType);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Loaded packs.");
|
logger.info("Loaded packs.");
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package com.dfsek.terra.fabric;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.util.mutable.MutableInteger;
|
||||||
|
import com.dfsek.terra.fabric.generation.FabricChunkGeneratorWrapper;
|
||||||
|
import com.dfsek.terra.fabric.generation.TerraBiomeSource;
|
||||||
|
import com.dfsek.terra.fabric.mixin.access.GeneratorTypeAccessor;
|
||||||
|
import net.minecraft.client.gui.DrawableHelper;
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonListWidget;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.options.CyclingOption;
|
||||||
|
import net.minecraft.client.options.GameOptions;
|
||||||
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
|
import net.minecraft.client.world.GeneratorType;
|
||||||
|
import net.minecraft.text.BaseText;
|
||||||
|
import net.minecraft.text.LiteralText;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.text.TranslatableText;
|
||||||
|
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
|
import net.minecraft.world.biome.Biome;
|
||||||
|
import net.minecraft.world.dimension.DimensionType;
|
||||||
|
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||||
|
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TerraOptionsScreen extends Screen {
|
||||||
|
private final Screen parent;
|
||||||
|
private final List<GeneratorType> generatorList = new ArrayList<>();
|
||||||
|
private ButtonListWidget buttonListWidget;
|
||||||
|
|
||||||
|
public TerraOptionsScreen(Screen parent) {
|
||||||
|
super(new LiteralText("Terra Options"));
|
||||||
|
this.parent = parent;
|
||||||
|
generatorList.add(GeneratorType.DEFAULT);
|
||||||
|
generatorList.add(GeneratorType.AMPLIFIED);
|
||||||
|
|
||||||
|
TerraFabricPlugin.getInstance().getConfigRegistry().forEach(pack -> generatorList.add(new GeneratorType("terra." + pack.getTemplate().getID()) {
|
||||||
|
{
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
((GeneratorTypeAccessor) (Object) this).setTranslationKey(new LiteralText("Terra:" + pack.getTemplate().getID()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ChunkGenerator getChunkGenerator(Registry<Biome> biomeRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, long seed) {
|
||||||
|
return new FabricChunkGeneratorWrapper(new TerraBiomeSource(biomeRegistry, seed, pack), seed, pack);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
addButton(new ButtonWidget(width / 2 - 60, height - 30, 120, 20, new TranslatableText("terra.screen.close"), btn -> client.openScreen(parent)));
|
||||||
|
this.buttonListWidget = new ButtonListWidget(client, width - 20, height - 20, 32, height - 50, 25);
|
||||||
|
|
||||||
|
buttonListWidget.setLeftPos(10);
|
||||||
|
|
||||||
|
Registry<DimensionType> dimensionTypes = new DynamicRegistryManager.Impl().getDimensionTypes();
|
||||||
|
|
||||||
|
dimensionTypes.forEach(System.out::println);
|
||||||
|
|
||||||
|
buttonListWidget.addSingleOptionEntry(new GeneratorCycler("Overworld"));
|
||||||
|
buttonListWidget.addSingleOptionEntry(new GeneratorCycler("Nether"));
|
||||||
|
buttonListWidget.addSingleOptionEntry(new GeneratorCycler("End"));
|
||||||
|
|
||||||
|
addChild(buttonListWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||||
|
this.renderBackground(matrices);
|
||||||
|
this.buttonListWidget.render(matrices, mouseX, mouseY, delta);
|
||||||
|
DrawableHelper.drawCenteredText(matrices, textRenderer, new TranslatableText("terra.config-screen"), width / 2, 20, 0xffffff);
|
||||||
|
super.render(matrices, mouseX, mouseY, delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class GeneratorCycler extends CyclingOption {
|
||||||
|
private final MutableInteger amount = new MutableInteger(0);
|
||||||
|
|
||||||
|
public GeneratorCycler(String key) {
|
||||||
|
super(key, null, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Text getMessage(GameOptions options) {
|
||||||
|
return ((BaseText) getDisplayPrefix()).copy().append(new LiteralText(": ")).append(generatorList.get(amount.get()).getTranslationKey().copy());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cycle(GameOptions options, int amount) {
|
||||||
|
this.amount.addMod(amount, generatorList.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.dfsek.terra.fabric.config;
|
||||||
|
|
||||||
|
import com.dfsek.tectonic.annotations.Default;
|
||||||
|
import com.dfsek.tectonic.annotations.Value;
|
||||||
|
import com.dfsek.tectonic.config.ConfigTemplate;
|
||||||
|
import com.dfsek.terra.config.pack.ConfigPack;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class FabricWorldConfig implements ConfigTemplate {
|
||||||
|
@SuppressWarnings("FieldMayBeFinal")
|
||||||
|
@Value(".")
|
||||||
|
@Default
|
||||||
|
private Map<String, ConfigPack> worlds;
|
||||||
|
|
||||||
|
public FabricWorldConfig(Map<String, ConfigPack> worlds) {
|
||||||
|
this.worlds = worlds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FabricWorldConfig() {
|
||||||
|
this(new HashMap<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, ConfigPack> getWorlds() {
|
||||||
|
return worlds;
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
@@ -7,6 +7,8 @@ import org.spongepowered.asm.mixin.Mutable;
|
|||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Mixin(GeneratorType.class)
|
@Mixin(GeneratorType.class)
|
||||||
public interface GeneratorTypeAccessor {
|
public interface GeneratorTypeAccessor {
|
||||||
@@ -15,6 +17,17 @@ public interface GeneratorTypeAccessor {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Accessor("SCREEN_PROVIDERS")
|
||||||
|
static Map<Optional<GeneratorType>, GeneratorType.ScreenProvider> getScreenProviders() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mutable
|
||||||
|
@Accessor("SCREEN_PROVIDERS")
|
||||||
|
static void setScreenProviders(Map<Optional<GeneratorType>, GeneratorType.ScreenProvider> SCREEN_PROVIDERS) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Mutable
|
@Mutable
|
||||||
@Accessor("translationKey")
|
@Accessor("translationKey")
|
||||||
void setTranslationKey(Text translationKey);
|
void setTranslationKey(Text translationKey);
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.dfsek.terra.fabric.mixin.init;
|
package com.dfsek.terra.fabric.mixin.client;
|
||||||
|
|
||||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.dfsek.terra.fabric.mixin.init;
|
package com.dfsek.terra.fabric.mixin.server;
|
||||||
|
|
||||||
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
import com.dfsek.terra.fabric.TerraFabricPlugin;
|
||||||
import com.mojang.authlib.GameProfileRepository;
|
import com.mojang.authlib.GameProfileRepository;
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
"generator.terra": "Terra"
|
"generator.terra": "Terra",
|
||||||
|
"terra.config-screen": "Terra Configuration",
|
||||||
|
"terra.screen.close": "Close"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,10 +34,10 @@
|
|||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"access.GeneratorTypeAccessor",
|
"access.GeneratorTypeAccessor",
|
||||||
"init.MinecraftClientMixin"
|
"client.MinecraftClientMixin"
|
||||||
],
|
],
|
||||||
"server": [
|
"server": [
|
||||||
"init.MinecraftServerMixin"
|
"server.MinecraftServerMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|||||||
Reference in new issue
Block a user