Skip to content

Commit

Permalink
yarn build 4
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Sep 13, 2024
1 parent 08a4a29 commit 0fda989
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 97 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ mod_version = 0.21.999-snap

# Required malilib version
malilib_version = 0.20.999-snap
malilib_id = 9ee809b0b7
malilib_id = 093bb9fd30

# Minecraft, Fabric Loader and API and mappings versions
minecraft_version_out = 24w37a
minecraft_version = 24w37a
mappings_version = 24w37a+build.1
mappings_version = 24w37a+build.4

fabric_loader_version = 0.16.5
mod_menu_version = 12.0.0-alpha.1
Expand Down
96 changes: 8 additions & 88 deletions src/main/java/fi/dy/masa/tweakeroo/mixin/MixinPresetsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
//@Mixin(PresetsScreen.class)
public abstract class MixinPresetsScreen
{
/*
@Shadow @Final private static RegistryKey<Biome> BIOME_KEY;
@Shadow @Final private CustomizeFlatLevelScreen parent;
//@Shadow @Final private static RegistryKey<Biome> BIOME_KEY;
//@Shadow @Final private CustomizeFlatLevelScreen parent;

/*
@Inject(method = "init", at = @At("HEAD"))
private void addCustomEntries(CallbackInfo ci)
private void tweakeroo_addCustomEntries(CallbackInfo ci)
{
// FIXME
if (FeatureToggle.TWEAK_CUSTOM_FLAT_PRESETS.getBooleanValue())
{
**
int vanillaEntries = 9;
int toRemove = PRESETS.size() - vanillaEntries;
Expand All @@ -32,90 +34,8 @@ private void addCustomEntries(CallbackInfo ci)
PRESETS.add(0, o);
}
}
**
}
}
@Unique
private boolean registerPresetFromString(String str)
{
Matcher matcher = MiscUtils.PATTERN_WORLD_PRESET.matcher(str);
if (matcher.matches())
{
// TODO --> I added some code here, and added the IMixinCustomizeFlatLevelScreen
GeneratorOptionsHolder generatorOptionsHolder = ((IMixinCustomizeFlatLevelScreen) this.parent).tweakeroo_getCreateWorldParent().getWorldCreator().getGeneratorOptionsHolder();
DynamicRegistryManager.Immutable dynamicRegistryManager = generatorOptionsHolder.getCombinedRegistryManager();
FeatureSet featureSet = generatorOptionsHolder.dataConfiguration().enabledFeatures();
RegistryEntryLookup<Biome> biomeLookup = dynamicRegistryManager.getOrThrow(RegistryKeys.BIOME);
RegistryEntryLookup<StructureSet> structureLookup = dynamicRegistryManager.getOrThrow(RegistryKeys.STRUCTURE_SET);
RegistryEntryLookup<PlacedFeature> featuresLookup = dynamicRegistryManager.getOrThrow(RegistryKeys.PLACED_FEATURE);
RegistryEntryLookup<Block> blockLookup = dynamicRegistryManager.getOrThrow(RegistryKeys.BLOCK).withFeatureFilter(featureSet);
FlatChunkGeneratorConfig defaultConfig = FlatChunkGeneratorConfig.getDefaultConfig(biomeLookup, structureLookup, featuresLookup);
FlatChunkGeneratorConfig currentConfig = this.parent.getConfig();
Optional<RegistryEntry.Reference<Biome>> optBiomeEntry = Optional.empty();
String name = matcher.group("name");
String blocksString = matcher.group("blocks");
String biomeName = matcher.group("biome");
// TODO add back the features
String iconItemName = matcher.group("icon");
RegistryKey<Biome> biome = null;
try
{
optBiomeEntry = Registries.BIOME_SOURCE.get(Identifier.ofVanilla(biomeName));
biome = optBiomeEntry.flatMap(RegistryEntry.Reference::getKey).orElseThrow();
}
catch (Exception ignore) {}
if (biome == null)
{
Tweakeroo.logger.error("Invalid biome while parsing flat world string: '{}'", biomeName);
return false;
}
Item item = null;
try
{
//item = Registries.ITEM.get(Identifier.of(iconItemName));
Optional<RegistryEntry.Reference<Item>> opt = Registries.ITEM.get(Identifier.of(iconItemName));
if (opt.isPresent())
{
item = opt.get().value();
}
}
catch (Exception ignore) {}
if (item == null)
{
Tweakeroo.logger.error("Invalid item for icon while parsing flat world string: '{}'", iconItemName);
return false;
}
List<FlatChunkGeneratorLayer> layers = MiscTweaks.parseBlockString(blocksString);
if (layers == null)
{
Tweakeroo.logger.error("Failed to get the layers for the flat world preset");
return false;
}
FlatChunkGeneratorConfig newConfig = defaultConfig.with(layers, defaultConfig.getStructureOverrides(), optBiomeEntry.orElseThrow());
new PresetsScreen.SuperflatPresetsListWidget.SuperflatPresetEntry(null);
addPreset(Text.translatable(name), item, biome, ImmutableSet.of(), false, false, layers);
this.parent.setConfig(newConfig);
return true;
}
else
{
Tweakeroo.logger.error("Flat world preset string did not match the regex");
}
return false;
}
*/
*/
}
110 changes: 103 additions & 7 deletions src/main/java/fi/dy/masa/tweakeroo/util/MiscUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import java.awt.image.BufferedImage;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.MapColor;
import net.minecraft.block.ShulkerBoxBlock;
Expand All @@ -18,28 +19,42 @@
import net.minecraft.block.entity.SignText;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.AbstractSignEditScreen;
import net.minecraft.client.gui.screen.world.CustomizeFlatLevelScreen;
import net.minecraft.client.input.Input;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.world.GeneratorOptionsHolder;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.MapIdComponent;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.passive.TameableEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.map.MapState;
import net.minecraft.registry.*;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.resource.featuretoggle.FeatureSet;
import net.minecraft.structure.StructureSet;
import net.minecraft.text.*;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeKeys;
import net.minecraft.world.gen.chunk.FlatChunkGeneratorConfig;
import net.minecraft.world.gen.chunk.FlatChunkGeneratorLayer;
import net.minecraft.world.gen.feature.PlacedFeature;

import fi.dy.masa.malilib.gui.GuiBase;
import fi.dy.masa.malilib.gui.Message;
import fi.dy.masa.malilib.util.FileUtils;
Expand All @@ -51,11 +66,9 @@
import fi.dy.masa.tweakeroo.config.Configs;
import fi.dy.masa.tweakeroo.config.FeatureToggle;
import fi.dy.masa.tweakeroo.config.Hotkeys;
import fi.dy.masa.tweakeroo.mixin.IMixinAxeItem;
import fi.dy.masa.tweakeroo.mixin.IMixinClientWorld;
import fi.dy.masa.tweakeroo.mixin.IMixinCommandBlockExecutor;
import fi.dy.masa.tweakeroo.mixin.IMixinShovelItem;
import fi.dy.masa.tweakeroo.mixin.*;
import fi.dy.masa.tweakeroo.renderer.RenderUtils;
import fi.dy.masa.tweakeroo.tweaks.MiscTweaks;

public class MiscUtils
{
Expand Down Expand Up @@ -688,6 +701,89 @@ public static boolean hasCustomMaxStackSize(ItemStack stack)
return defaultStackSize != currentStackSize;
}

public static boolean registerPresetFromString(CustomizeFlatLevelScreen screen, String str)
{
Matcher matcher = MiscUtils.PATTERN_WORLD_PRESET.matcher(str);

if (matcher.matches())
{
// TODO --> I added some code here, and added the IMixinCustomizeFlatLevelScreen
GeneratorOptionsHolder generatorOptionsHolder = ((IMixinCustomizeFlatLevelScreen) screen).tweakeroo_getCreateWorldParent().getWorldCreator().getGeneratorOptionsHolder();
DynamicRegistryManager.Immutable registryManager = generatorOptionsHolder.getCombinedRegistryManager();
FeatureSet featureSet = generatorOptionsHolder.dataConfiguration().enabledFeatures();
RegistryEntryLookup<Biome> biomeLookup = registryManager.getOrThrow(RegistryKeys.BIOME);
RegistryEntryLookup<StructureSet> structureLookup = registryManager.getOrThrow(RegistryKeys.STRUCTURE_SET);
RegistryEntryLookup<PlacedFeature> featuresLookup = registryManager.getOrThrow(RegistryKeys.PLACED_FEATURE);
RegistryEntryLookup<Block> blockLookup = registryManager.getOrThrow(RegistryKeys.BLOCK).withFeatureFilter(featureSet);
FlatChunkGeneratorConfig defaultConfig = FlatChunkGeneratorConfig.getDefaultConfig(biomeLookup, structureLookup, featuresLookup);
FlatChunkGeneratorConfig currentConfig = screen.getConfig();
RegistryEntry.Reference<Biome> referenceEntry = biomeLookup.getOrThrow(BiomeKeys.PLAINS);
RegistryEntry.Reference<Biome> biomeEntry = referenceEntry;

String name = matcher.group("name");
String blocksString = matcher.group("blocks");
String biomeName = matcher.group("biome");
// TODO add back the features
String iconItemName = matcher.group("icon");

try
{
Optional<RegistryKey<Biome>> optBiome = Optional.ofNullable(Identifier.tryParse(biomeName)).map((biomeId) ->
RegistryKey.of(RegistryKeys.BIOME, biomeId));

biomeEntry = optBiome.flatMap(biomeLookup::getOptional).orElse(referenceEntry);
}
catch (Exception ignore) {}

if (biomeEntry == null)
{
Tweakeroo.logger.error("Invalid biome while parsing flat world string: '{}'", biomeName);
return false;
}

Item item = null;

try
{
Optional<RegistryEntry.Reference<Item>> opt = Registries.ITEM.getEntry(Identifier.of(iconItemName));
if (opt.isPresent())
{
item = opt.get().value();
}
}
catch (Exception ignore) {}

if (item == null)
{
Tweakeroo.logger.error("Invalid item for icon while parsing flat world string: '{}'", iconItemName);
return false;
}

List<FlatChunkGeneratorLayer> layers = MiscTweaks.parseBlockString(blocksString);

if (layers == null)
{
Tweakeroo.logger.error("Failed to get the layers for the flat world preset");
return false;
}

FlatChunkGeneratorConfig newConfig = defaultConfig.with(layers, defaultConfig.getStructureOverrides(), biomeEntry);

//new PresetsScreen.SuperflatPresetsListWidget.SuperflatPresetEntry(null);
//addPreset(Text.translatable(name), item, biome, ImmutableSet.of(), false, false, layers);

screen.setConfig(newConfig);

return true;
}
else
{
Tweakeroo.logger.error("Flat world preset string did not match the regex");
}

return false;
}

public static class PostKeyAction
{
private int lastIntValue;
Expand Down

0 comments on commit 0fda989

Please sign in to comment.