mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-03 06:16:10 +00:00
create TerraOptionsScreen
This commit is contained in:
@@ -13,6 +13,11 @@ public class MutableInteger extends MutableNumber<Integer> {
|
||||
add(1);
|
||||
}
|
||||
|
||||
public void addMod(int add, int mod) {
|
||||
add(add);
|
||||
value %= mod;
|
||||
}
|
||||
|
||||
public void decrement() {
|
||||
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.ConfigRegistry;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
@@ -63,12 +64,14 @@ import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeEffects;
|
||||
import net.minecraft.world.biome.GenerationSettings;
|
||||
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.ChunkGeneratorSettings;
|
||||
import net.minecraft.world.gen.decorator.Decorator;
|
||||
@@ -91,6 +94,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static net.minecraft.server.command.CommandManager.argument;
|
||||
import static net.minecraft.server.command.CommandManager.literal;
|
||||
@@ -300,16 +304,28 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
|
||||
if(FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
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.");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mixin(GeneratorType.class)
|
||||
public interface GeneratorTypeAccessor {
|
||||
@@ -15,6 +17,17 @@ public interface GeneratorTypeAccessor {
|
||||
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
|
||||
@Accessor("translationKey")
|
||||
void setTranslationKey(Text translationKey);
|
||||
|
||||
@@ -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 net.minecraft.client.MinecraftClient;
|
||||
@@ -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.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": [
|
||||
"access.GeneratorTypeAccessor",
|
||||
"init.MinecraftClientMixin"
|
||||
"client.MinecraftClientMixin"
|
||||
],
|
||||
"server": [
|
||||
"init.MinecraftServerMixin"
|
||||
"server.MinecraftServerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
Reference in New Issue
Block a user