Compiling version (some features are currently disabled and need a rewrite)

This commit is contained in:
Frank 2022-10-25 17:19:22 +02:00
parent b1f4173ce4
commit f8bcba4d3a
48 changed files with 488 additions and 506 deletions

View file

@ -1,7 +1,7 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx8G
#Modrinth
modrinth_versions=["1.19", "1.19.1", "1.19.2"]
modrinth_versions=["22w42a"]
release_channel=release #`release`, `beta` or `alpha`
#Loom
loom_version=1.0-SNAPSHOT
@ -9,7 +9,7 @@ loom_version=1.0-SNAPSHOT
# check these on https://fabricmc.net/versions.html
minecraft_version=22w42a
loader_version=0.14.10
fabric_version=0.60.0+1.19.2
fabric_version=0.65.0+1.19.3
# Mod Properties
mod_version=2.1.3
maven_group=org.betterx.bclib

View file

@ -8,6 +8,7 @@ import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
import org.betterx.bclib.config.Configs;
import net.minecraft.core.RegistryAccess;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.Tag;
@ -42,7 +43,7 @@ final class BiomeSourcePatch extends ForcedLevelPatch {
final CompoundTag worldGenSettings = root.getCompound("Data").getCompound("WorldGenSettings");
final CompoundTag dimensions = worldGenSettings.getCompound("dimensions");
final RegistryAccess registryAccess = RegistryAccess.builtinCopy();
final RegistryAccess registryAccess = BuiltinRegistries.createAccess();
final RegistryOps<Tag> registryOps = RegistryOps.create(NbtOps.INSTANCE, registryAccess);

View file

@ -28,7 +28,10 @@ public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceW
protected long currentSeed;
protected int maxHeight;
private static List<Holder<Biome>> preInit(Registry<Biome> biomeRegistry, List<Holder<Biome>> biomes) {
private static List<Holder<Biome>> preInit(
Registry<Biome> biomeRegistry,
List<Holder<Biome>> biomes
) {
biomes = biomes.stream().sorted(Comparator.comparing(holder -> holder.unwrapKey()
.get()
.location()
@ -108,8 +111,9 @@ public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceW
return biomeRegistry.stream()
.filter(biome -> biomeRegistry.getResourceKey(biome).isPresent())
.map(biome -> biomeRegistry.getOrCreateHolderOrThrow(biomeRegistry.getResourceKey(biome)
.get()))
.map(biome -> (Holder<Biome>) biomeRegistry.getOrCreateHolderOrThrow(
biomeRegistry.getResourceKey(biome).get())
)
.filter(biome -> {
ResourceLocation location = biome.unwrapKey().orElseThrow().location();
final String strLocation = location.toString();

View file

@ -30,7 +30,7 @@ import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.RandomState;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.WorldDimensions;
import net.minecraft.world.level.levelgen.structure.StructureSet;
import net.minecraft.world.level.levelgen.synth.NormalNoise;
@ -55,7 +55,7 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator implements Resto
RecordCodecBuilder<BCLChunkGenerator, Holder<NoiseGeneratorSettings>> settingsCodec = NoiseGeneratorSettings.CODEC
.fieldOf("settings")
.forGetter((BCLChunkGenerator generator) -> generator.settings);
.forGetter((BCLChunkGenerator generator) -> generator.generatorSettings());
return NoiseBasedChunkGenerator
@ -157,12 +157,12 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator implements Resto
}
@Override
public WorldGenSettings enforceGeneratorInWorldGenSettings(
public WorldDimensions enforceGeneratorInWorldGenSettings(
RegistryAccess access,
ResourceKey<LevelStem> dimensionKey,
ResourceKey<DimensionType> dimensionTypeKey,
ChunkGenerator loadedChunkGenerator,
WorldGenSettings settings
WorldDimensions worldDims
) {
BCLib.LOGGER.info("Enforcing Correct Generator for " + dimensionKey.location().toString() + ".");
@ -195,7 +195,7 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator implements Resto
dimensionKey,
dimensionTypeKey,
access,
settings,
worldDims,
referenceGenerator
);

View file

@ -21,6 +21,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagLoader;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.WorldDimensions;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
import net.minecraft.world.level.storage.LevelStorageSource;
@ -71,9 +72,9 @@ public class LevelGenEvents {
private static Optional<Holder<WorldPreset>> adaptWorldPresetSettings(
Optional<Holder<WorldPreset>> currentPreset,
WorldGenSettings worldGenSettings
WorldDimensions worldDims
) {
LevelStem endStem = worldGenSettings.dimensions().get(LevelStem.END);
LevelStem endStem = worldDims.dimensions().get(LevelStem.END);
//We probably loaded a Datapack for the End
if (!(endStem.generator().getBiomeSource() instanceof BCLibEndBiomeSource)) {

View file

@ -22,7 +22,7 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.WorldDimensions;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
import net.minecraft.world.level.levelgen.presets.WorldPresets;
@ -64,11 +64,11 @@ public class LevelGenUtil {
}
public static WorldGenSettings replaceGenerator(
public static WorldDimensions replaceGenerator(
ResourceKey<LevelStem> dimensionKey,
ResourceKey<DimensionType> dimensionTypeKey,
RegistryAccess registryAccess,
WorldGenSettings worldGenSettings,
WorldDimensions worldDimensions,
ChunkGenerator generator
) {
Registry<DimensionType> dimensionTypeRegistry = registryAccess.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
@ -76,15 +76,10 @@ public class LevelGenUtil {
dimensionKey,
dimensionTypeKey,
dimensionTypeRegistry,
worldGenSettings.dimensions(),
worldDimensions.dimensions(),
generator
);
return new WorldGenSettings(
worldGenSettings.seed(),
worldGenSettings.generateStructures(),
worldGenSettings.generateBonusChest(),
newDimensions
);
return new WorldDimensions(newDimensions);
}
public static Registry<LevelStem> withDimension(
@ -98,7 +93,7 @@ public class LevelGenUtil {
LevelStem levelStem = inputDimensions.get(dimensionKey);
Holder<DimensionType> dimensionType = levelStem == null
? dimensionTypeRegistry.getOrCreateHolderOrThrow(dimensionTypeKey)
: levelStem.typeHolder();
: levelStem.type();
return withDimension(dimensionKey, inputDimensions, new LevelStem(dimensionType, generator));
}
@ -109,8 +104,7 @@ public class LevelGenUtil {
) {
MappedRegistry<LevelStem> writableRegistry = new MappedRegistry<>(
Registry.LEVEL_STEM_REGISTRY,
Lifecycle.experimental(),
null
Lifecycle.experimental()
);
writableRegistry.register(
dimensionKey,

View file

@ -33,7 +33,7 @@ public class BCLBiomeRegistry {
);
public static Registry<BCLBiome> BUILTIN_BCL_BIOMES = new MappedRegistry<>(
BCL_BIOMES_REGISTRY,
Lifecycle.stable(), null
Lifecycle.stable()
);
/**

View file

@ -4,6 +4,8 @@ import org.betterx.bclib.BCLib;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
import net.minecraft.core.Vec3i;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
@ -102,7 +104,7 @@ public class StructureNBT {
CompoundTag nbttagcompound = NbtIo.readCompressed(stream);
StructureTemplate template = new StructureTemplate();
template.load(nbttagcompound);
template.load(HolderLookup.forRegistry(Registry.BLOCK), nbttagcompound);
return template;
}

View file

@ -1,6 +1,8 @@
package org.betterx.bclib.api.v2.levelgen.structures;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils;
@ -117,7 +119,11 @@ public class StructureWorld {
ListTag map2 = tag.getList("states", 10);
BlockState[] states = new BlockState[map2.size()];
for (int i = 0; i < states.length; i++) {
states[i] = NbtUtils.readBlockState((CompoundTag) map2.get(i));
states[i] = NbtUtils.readBlockState(
//TODO: 1.19.3 This appears to be used on a level registry, not the global one?
HolderLookup.forRegistry(Registry.BLOCK),
(CompoundTag) map2.get(i)
);
}
map.forEach((element) -> {

View file

@ -10,6 +10,7 @@ import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.ButtonBlock;
@ -30,7 +31,14 @@ public abstract class BaseButtonBlock extends ButtonBlock implements BlockModelP
private final Block parent;
protected BaseButtonBlock(Block parent, Properties properties, boolean sensitive) {
super(sensitive, properties.noCollission());
this(parent, properties, 30, sensitive);
}
protected BaseButtonBlock(Block parent, Properties properties, int ticksToStayPressed, boolean sensitive) {
super(
properties.noCollission(), ticksToStayPressed, sensitive,
SoundEvents.STONE_BUTTON_CLICK_OFF, SoundEvents.STONE_BUTTON_CLICK_ON
);
this.parent = parent;
}

View file

@ -13,6 +13,7 @@ import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
@ -42,7 +43,7 @@ public class BaseDoorBlock extends DoorBlock implements RenderLayerProvider, Blo
}
public BaseDoorBlock(BlockBehaviour.Properties properties) {
super(properties);
super(properties, SoundEvents.WOODEN_DOOR_CLOSE, SoundEvents.WOODEN_DOOR_OPEN);
}
@Override

View file

@ -9,6 +9,7 @@ import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FenceGateBlock;
@ -28,7 +29,7 @@ public class BaseGateBlock extends FenceGateBlock implements BlockModelProvider
private final Block parent;
public BaseGateBlock(Block source) {
super(Properties.copy(source).noOcclusion());
super(Properties.copy(source).noOcclusion(), SoundEvents.FENCE_GATE_CLOSE, SoundEvents.FENCE_GATE_OPEN);
this.parent = source;
}

View file

@ -9,6 +9,7 @@ import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.PressurePlateBlock;
@ -28,7 +29,10 @@ public class BasePressurePlateBlock extends PressurePlateBlock implements BlockM
private final Block parent;
public BasePressurePlateBlock(Sensitivity rule, Block source) {
super(rule, Properties.copy(source).noCollission().noOcclusion().strength(0.5F));
super(
rule, Properties.copy(source).noCollission().noOcclusion().strength(0.5F),
SoundEvents.WOODEN_PRESSURE_PLATE_CLICK_OFF, SoundEvents.WOODEN_PRESSURE_PLATE_CLICK_ON
);
this.parent = source;
}

View file

@ -11,6 +11,7 @@ import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.TrapDoorBlock;
@ -31,7 +32,7 @@ public class BaseTrapdoorBlock extends TrapDoorBlock implements RenderLayerProvi
}
public BaseTrapdoorBlock(BlockBehaviour.Properties properties) {
super(properties);
super(properties, SoundEvents.WOODEN_TRAPDOOR_CLOSE, SoundEvents.WOODEN_TRAPDOOR_OPEN);
}
@Override

View file

@ -9,6 +9,7 @@ import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.WeightedPressurePlateBlock;
@ -31,10 +32,11 @@ public class BaseWeightedPlateBlock extends WeightedPressurePlateBlock implement
super(
15,
Properties.copy(source)
.noCollission()
.noOcclusion()
.requiresCorrectToolForDrops()
.strength(0.5F)
.noCollission()
.noOcclusion()
.requiresCorrectToolForDrops()
.strength(0.5F),
SoundEvents.METAL_PRESSURE_PLATE_CLICK_OFF, SoundEvents.METAL_PRESSURE_PLATE_CLICK_ON
);
this.parent = source;
}

View file

@ -255,7 +255,7 @@ public class WorldSetupScreen extends LayoutScreen {
createWorldScreen
.worldGenSettingsComponent
.settings()
.worldGenSettings()
.selectedDimensions()
.dimensions()
)
)));
@ -269,11 +269,11 @@ public class WorldSetupScreen extends LayoutScreen {
ChunkGenerator chunkGenerator
) {
createWorldScreen.worldGenSettingsComponent.updateSettings(
(registryAccess, worldGenSettings) -> LevelGenUtil.replaceGenerator(
(registryAccess, worldDimensions) -> LevelGenUtil.replaceGenerator(
dimensionKey,
dimensionTypeKey,
registryAccess,
worldGenSettings,
worldDimensions,
chunkGenerator
)
);

View file

@ -1,16 +1,12 @@
package org.betterx.bclib.client.models;
import org.betterx.bclib.api.v2.ModIntegrationAPI;
import org.betterx.bclib.client.render.EmissiveTextureInfo;
import org.betterx.bclib.interfaces.BlockModelProvider;
import org.betterx.bclib.interfaces.ItemModelProvider;
import org.betterx.bclib.models.RecordItemModelProvider;
import com.mojang.datafixers.util.Pair;
import net.minecraft.client.renderer.block.BlockModelShaper;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.renderer.block.model.multipart.MultiPart;
import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
@ -21,12 +17,8 @@ import net.minecraft.world.level.block.state.BlockState;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class CustomModelBakery {
private final Map<ResourceLocation, UnbakedModel> models = Maps.newConcurrentMap();
@ -114,43 +106,44 @@ public class CustomModelBakery {
BlockModel model = provider.getItemModel(modelLocation);
models.put(modelLocation, model);
}
public static void loadEmissiveModels(Map<ResourceLocation, UnbakedModel> unbakedCache) {
if (!ModIntegrationAPI.hasCanvas()) {
return;
}
Map<ResourceLocation, UnbakedModel> cacheCopy = new HashMap<>(unbakedCache);
Set<Pair<String, String>> strings = Sets.newConcurrentHashSet();
Registry.BLOCK.keySet().forEach(blockID -> {
Block block = Registry.BLOCK.get(blockID);
ImmutableList<BlockState> states = block.getStateDefinition().getPossibleStates();
boolean addBlock = false;
for (BlockState state : states) {
ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, state);
UnbakedModel model = cacheCopy.get(stateID);
if (model == null) {
continue;
}
Collection<Material> materials = model.getMaterials(cacheCopy::get, strings);
if (materials == null) {
continue;
}
for (Material material : materials) {
if (EmissiveTextureInfo.isEmissiveTexture(material.texture())) {
addBlock = true;
break;
}
}
if (addBlock) {
break;
}
}
if (addBlock) {
EmissiveTextureInfo.addBlock(blockID);
}
});
}
//TODO: 1.19.3 Handled differently now
// public static void loadEmissiveModels(Map<ResourceLocation, UnbakedModel> unbakedCache) {
// if (!ModIntegrationAPI.hasCanvas()) {
// return;
// }
//
// Map<ResourceLocation, UnbakedModel> cacheCopy = new HashMap<>(unbakedCache);
// Set<Pair<String, String>> strings = Sets.newConcurrentHashSet();
// Registry.BLOCK.keySet().forEach(blockID -> {
// Block block = Registry.BLOCK.get(blockID);
// ImmutableList<BlockState> states = block.getStateDefinition().getPossibleStates();
// boolean addBlock = false;
//
// for (BlockState state : states) {
// ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, state);
// UnbakedModel model = cacheCopy.get(stateID);
// if (model == null) {
// continue;
// }
// Collection<Material> materials = model.getMaterials(cacheCopy::get, strings);
// if (materials == null) {
// continue;
// }
// for (Material material : materials) {
// if (EmissiveTextureInfo.isEmissiveTexture(material.texture())) {
// addBlock = true;
// break;
// }
// }
// if (addBlock) {
// break;
// }
// }
//
// if (addBlock) {
// EmissiveTextureInfo.addBlock(blockID);
// }
// });
// }
}

View file

@ -4,7 +4,6 @@ import org.betterx.bclib.BCLib;
import org.betterx.bclib.util.BlocksHelper;
import org.betterx.bclib.util.MHelper;
import com.mojang.datafixers.util.Pair;
import com.mojang.math.Vector3f;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.BakedQuad;
@ -86,17 +85,13 @@ public class OBJBlockModel implements UnbakedModel, BakedModel {
}
@Override
public Collection<Material> getMaterials(
Function<ResourceLocation, UnbakedModel> function,
Set<Pair<String, String>> set
) {
return materials;
public void resolveParents(Function<ResourceLocation, UnbakedModel> function) {
}
@Nullable
@Override
public BakedModel bake(
ModelBakery modelBakery,
ModelBaker modelBakery,
Function<Material, TextureAtlasSprite> textureGetter,
ModelState modelState,
ResourceLocation resourceLocation

View file

@ -16,8 +16,7 @@ public interface NumericProvider {
BCLib.makeID("worldgen/numeric_provider"));
Registry<Codec<? extends NumericProvider>> NUMERIC_PROVIDER = new MappedRegistry<>(
NUMERIC_PROVIDER_REGISTRY,
Lifecycle.experimental(),
null
Lifecycle.experimental()
);
Codec<NumericProvider> CODEC = NUMERIC_PROVIDER.byNameCodec()
.dispatch(NumericProvider::pcodec, Function.identity());

View file

@ -3,11 +3,11 @@ package org.betterx.bclib.items.boat;
import org.betterx.bclib.BCLib;
import net.minecraft.client.model.BoatModel;
import net.minecraft.client.model.ChestBoatModel;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BoatItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
@ -64,8 +64,8 @@ public final class BoatTypeOverride {
public void createBoatModels(EntityRendererProvider.Context context) {
if (boatModel == null) {
boatModel = new BoatModel(context.bakeLayer(boatModelName), false);
chestBoatModel = new BoatModel(context.bakeLayer(chestBoatModelName), true);
boatModel = new BoatModel(context.bakeLayer(boatModelName));
chestBoatModel = new ChestBoatModel(context.bakeLayer(chestBoatModelName));
}
}
@ -115,7 +115,7 @@ public final class BoatTypeOverride {
}
public BoatItem createItem(boolean hasChest) {
return createItem(hasChest, new Item.Properties().stacksTo(1).tab(CreativeModeTab.TAB_TRANSPORTATION));
return createItem(hasChest, new Item.Properties().stacksTo(1));
}
public BoatItem createItem(boolean hasChest, Item.Properties itemSettings) {

View file

@ -1,7 +1,6 @@
package org.betterx.bclib.mixin.client;
import org.betterx.bclib.api.v2.ModIntegrationAPI;
import org.betterx.bclib.client.models.CustomModelBakery;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.resources.model.ModelBakery;
@ -35,7 +34,8 @@ public abstract class ModelBakeryMixin {
) {
//CustomModelBakery.setModelsLoaded(false);
if (ModIntegrationAPI.hasCanvas()) {
CustomModelBakery.loadEmissiveModels(unbakedCache);
//TODO:1.19.3 this needs to change
//CustomModelBakery.loadEmissiveModels(unbakedCache);
}
}
}

View file

@ -1,114 +1,97 @@
package org.betterx.bclib.mixin.client;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.client.render.EmissiveTextureInfo;
import com.mojang.blaze3d.platform.NativeImage;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
import net.fabricmc.fabric.impl.client.texture.FabricSprite;
import net.fabricmc.loader.api.FabricLoader;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.io.IOException;
import java.util.Optional;
@Mixin(TextureAtlas.class)
public class TextureAtlasMixin {
private static final int EMISSIVE_ALPHA = 254 << 24;
private boolean bclib_modifyAtlas;
@Inject(method = "<init>*", at = @At("TAIL"))
private void bclib_onAtlasInit(ResourceLocation resourceLocation, CallbackInfo info) {
boolean hasOptifine = FabricLoader.getInstance().isModLoaded("optifabric");
bclib_modifyAtlas = !hasOptifine && resourceLocation.toString().equals("minecraft:textures/atlas/blocks.png");
if (bclib_modifyAtlas) {
EmissiveTextureInfo.clear();
}
}
@Inject(method = "load(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite$Info;IIIII)Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;", at = @At("HEAD"), cancellable = true)
private void bclib_loadSprite(
ResourceManager resourceManager,
TextureAtlasSprite.Info spriteInfo,
int atlasWidth,
int atlasHeight,
int maxLevel,
int posX,
int posY,
CallbackInfoReturnable<TextureAtlasSprite> info
) {
if (!bclib_modifyAtlas) {
return;
}
ResourceLocation location = spriteInfo.name();
if (!location.getPath().startsWith("block")) {
return;
}
ResourceLocation emissiveLocation = new ResourceLocation(
location.getNamespace(),
"textures/" + location.getPath() + "_e.png"
);
Optional<Resource> emissiveRes = resourceManager.getResource(emissiveLocation);
if (emissiveRes.isPresent()) {
NativeImage sprite = null;
NativeImage emission = null;
try {
ResourceLocation spriteLocation = new ResourceLocation(
location.getNamespace(),
"textures/" + location.getPath() + ".png"
);
Resource resource = resourceManager.getResource(spriteLocation).orElse(null);
sprite = NativeImage.read(resource.open());
resource = emissiveRes.get();
emission = NativeImage.read(resource.open());
} catch (IOException e) {
BCLib.LOGGER.warning(e.getMessage());
}
if (sprite != null && emission != null) {
int width = Math.min(sprite.getWidth(), emission.getWidth());
int height = Math.min(sprite.getHeight(), emission.getHeight());
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int argb = emission.getPixelRGBA(x, y);
int alpha = (argb >> 24) & 255;
if (alpha > 127) {
int r = (argb >> 16) & 255;
int g = (argb >> 8) & 255;
int b = argb & 255;
if (r > 0 || g > 0 || b > 0) {
argb = (argb & 0x00FFFFFF) | EMISSIVE_ALPHA;
sprite.setPixelRGBA(x, y, argb);
}
}
}
}
TextureAtlas self = (TextureAtlas) (Object) this;
FabricSprite result = new FabricSprite(
self,
spriteInfo,
maxLevel,
atlasWidth,
atlasHeight,
posX,
posY,
sprite
);
EmissiveTextureInfo.addTexture(location);
info.setReturnValue(result);
}
}
}
//TODO: 1.19.3 How were FabricSprites replaced?
// @Inject(method = "<init>*", at = @At("TAIL"))
// private void bclib_onAtlasInit(ResourceLocation resourceLocation, CallbackInfo info) {
// boolean hasOptifine = FabricLoader.getInstance().isModLoaded("optifabric");
// bclib_modifyAtlas = !hasOptifine && resourceLocation.toString().equals("minecraft:textures/atlas/blocks.png");
// if (bclib_modifyAtlas) {
// EmissiveTextureInfo.clear();
// }
// }
//
// @Inject(method = "load(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite$Info;IIIII)Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;", at = @At("HEAD"), cancellable = true)
// private void bclib_loadSprite(
// ResourceManager resourceManager,
// TextureAtlasSprite.Info spriteInfo,
// int atlasWidth,
// int atlasHeight,
// int maxLevel,
// int posX,
// int posY,
// CallbackInfoReturnable<TextureAtlasSprite> info
// ) {
// if (!bclib_modifyAtlas) {
// return;
// }
//
// ResourceLocation location = spriteInfo.name();
// if (!location.getPath().startsWith("block")) {
// return;
// }
//
// ResourceLocation emissiveLocation = new ResourceLocation(
// location.getNamespace(),
// "textures/" + location.getPath() + "_e.png"
// );
// Optional<Resource> emissiveRes = resourceManager.getResource(emissiveLocation);
// if (emissiveRes.isPresent()) {
// NativeImage sprite = null;
// NativeImage emission = null;
// try {
// ResourceLocation spriteLocation = new ResourceLocation(
// location.getNamespace(),
// "textures/" + location.getPath() + ".png"
// );
// Resource resource = resourceManager.getResource(spriteLocation).orElse(null);
// sprite = NativeImage.read(resource.open());
//
// resource = emissiveRes.get();
// emission = NativeImage.read(resource.open());
// } catch (IOException e) {
// BCLib.LOGGER.warning(e.getMessage());
// }
// if (sprite != null && emission != null) {
// int width = Math.min(sprite.getWidth(), emission.getWidth());
// int height = Math.min(sprite.getHeight(), emission.getHeight());
// for (int x = 0; x < width; x++) {
// for (int y = 0; y < height; y++) {
// int argb = emission.getPixelRGBA(x, y);
// int alpha = (argb >> 24) & 255;
// if (alpha > 127) {
// int r = (argb >> 16) & 255;
// int g = (argb >> 8) & 255;
// int b = argb & 255;
// if (r > 0 || g > 0 || b > 0) {
// argb = (argb & 0x00FFFFFF) | EMISSIVE_ALPHA;
// sprite.setPixelRGBA(x, y, argb);
// }
// }
// }
// }
// TextureAtlas self = (TextureAtlas) (Object) this;
// FabricSprite result = new FabricSprite(
// self,
// spriteInfo,
// maxLevel,
// atlasWidth,
// atlasHeight,
// posX,
// posY,
// sprite
// );
// EmissiveTextureInfo.addTexture(location);
// info.setReturnValue(result);
// }
// }
// }
}

View file

@ -1,48 +1,35 @@
package org.betterx.bclib.mixin.common;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeData;
import com.mojang.serialization.Codec;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceKey;
import com.google.common.collect.ImmutableMap;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import java.util.Map;
import java.util.function.Supplier;
@Mixin(RegistryAccess.class)
public interface RegistryAccessMixin {
@ModifyArg(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;make(Ljava/util/function/Supplier;)Ljava/lang/Object;"))
private static Supplier<ImmutableMap<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>>> together_addRegistry(
Supplier<ImmutableMap<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>>> supplier
) {
return () -> {
ImmutableMap.Builder<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> builder = ImmutableMap.builder();
//Make sure this gets added before WORLD_PRESETS
put(builder, BCLBiomeRegistry.BCL_BIOMES_REGISTRY, BiomeData.CODEC);
Map<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> res = supplier.get();
builder.putAll(res);
return builder.build();
};
}
@Shadow
static <E> void put(
ImmutableMap.Builder<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> builder,
ResourceKey<? extends Registry<E>> resourceKey,
Codec<E> codec
) {
throw new RuntimeException("Shadowed Call");
}
//TODO: 1.19.3 Will probably be a new custom data provider now
// @ModifyArg(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;make(Ljava/util/function/Supplier;)Ljava/lang/Object;"))
// private static Supplier<ImmutableMap<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>>> together_addRegistry(
// Supplier<ImmutableMap<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>>> supplier
// ) {
// return () -> {
// ImmutableMap.Builder<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> builder = ImmutableMap.builder();
// //Make sure this gets added before WORLD_PRESETS
// put(builder, BCLBiomeRegistry.BCL_BIOMES_REGISTRY, BiomeData.CODEC);
//
// Map<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> res = supplier.get();
// builder.putAll(res);
//
// return builder.build();
// };
// }
//
// @Shadow
// static <E> void put(
// ImmutableMap.Builder<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> builder,
// ResourceKey<? extends Registry<E>> resourceKey,
// Codec<E> codec
// ) {
// throw new RuntimeException("Shadowed Call");
// }
}

View file

@ -24,6 +24,14 @@ public class BlastFurnaceRecipe extends CookingRecipe<BlastFurnaceRecipe, Contai
@Override
protected BlastingRecipe buildRecipe() {
return new BlastingRecipe(id, group, input, new ItemStack(output, count), experience, cookingTime);
return new BlastingRecipe(
id,
group,
bookCategory,
input,
new ItemStack(output, count),
experience,
cookingTime
);
}
}

View file

@ -4,6 +4,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.Container;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.crafting.CookingBookCategory;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.ItemLike;
@ -11,6 +12,7 @@ import net.minecraft.world.level.ItemLike;
public abstract class CookingRecipe<T extends AbstractSimpleRecipe, C extends Container, R extends Recipe<C>> extends AbstractSimpleRecipe<T, C, R> {
protected float experience;
protected int cookingTime;
protected CookingBookCategory bookCategory;
CookingRecipe(ResourceLocation id, RecipeType<R> type, ItemLike output) {
this(id, type, type.toString(), output);
@ -20,6 +22,7 @@ public abstract class CookingRecipe<T extends AbstractSimpleRecipe, C extends Co
super(id, type, category, output);
cookingTime = 1000;
experience = 0;
this.bookCategory = CookingBookCategory.MISC;
}
public T setInput(ItemLike in) {
@ -39,4 +42,9 @@ public abstract class CookingRecipe<T extends AbstractSimpleRecipe, C extends Co
cookingTime = time;
return (T) this;
}
public T setCookingBookCategory(CookingBookCategory c) {
bookCategory = c;
return (T) this;
}
}

View file

@ -20,6 +20,7 @@ public class FurnaceRecipe extends AbstractAdvancementRecipe {
private int count;
private int time;
private float xp;
protected CookingBookCategory bookCategory;
private FurnaceRecipe() {
}
@ -34,6 +35,7 @@ public class FurnaceRecipe extends AbstractAdvancementRecipe {
INSTANCE.xp = 0;
INSTANCE.exist = BCLRecipeManager.exists(output);
INSTANCE.createAdvancement(INSTANCE.id, false);
INSTANCE.bookCategory = CookingBookCategory.MISC;
return INSTANCE;
}
@ -76,6 +78,11 @@ public class FurnaceRecipe extends AbstractAdvancementRecipe {
return this;
}
public FurnaceRecipe setCookingBookCategory(CookingBookCategory c) {
bookCategory = c;
return this;
}
public void build() {
build(false, false, false);
}
@ -96,6 +103,7 @@ public class FurnaceRecipe extends AbstractAdvancementRecipe {
SmeltingRecipe recipe = new SmeltingRecipe(
new ResourceLocation(id + "_smelting"),
group,
bookCategory,
input,
new ItemStack(output, count),
xp,
@ -108,6 +116,7 @@ public class FurnaceRecipe extends AbstractAdvancementRecipe {
BlastingRecipe recipe2 = new BlastingRecipe(
new ResourceLocation(id + "_blasting"),
group,
bookCategory,
input,
new ItemStack(output, count),
xp,
@ -121,6 +130,7 @@ public class FurnaceRecipe extends AbstractAdvancementRecipe {
CampfireCookingRecipe recipe2 = new CampfireCookingRecipe(
new ResourceLocation(id + "_campfire"),
group,
bookCategory,
input,
new ItemStack(output, count),
xp,
@ -134,6 +144,7 @@ public class FurnaceRecipe extends AbstractAdvancementRecipe {
SmokingRecipe recipe2 = new SmokingRecipe(
new ResourceLocation(id + "_smoker"),
group,
bookCategory,
input,
new ItemStack(output, count),
xp,

View file

@ -31,6 +31,8 @@ public class GridRecipe extends AbstractAdvancementRecipe {
private int count;
private boolean exist;
protected CraftingBookCategory bookCategory;
private GridRecipe() {
}
@ -51,6 +53,7 @@ public class GridRecipe extends AbstractAdvancementRecipe {
INSTANCE.shape = new String[]{"#"};
INSTANCE.materialKeys.clear();
INSTANCE.count = 1;
INSTANCE.bookCategory = CraftingBookCategory.MISC;
INSTANCE.exist = output != null && BCLRecipeManager.exists(output);
INSTANCE.createAdvancement(id, output);
@ -122,6 +125,11 @@ public class GridRecipe extends AbstractAdvancementRecipe {
return materials;
}
public GridRecipe setCraftingBookCategory(CraftingBookCategory c) {
bookCategory = c;
return this;
}
public void build() {
if (!exist) {
@ -145,11 +153,12 @@ public class GridRecipe extends AbstractAdvancementRecipe {
CraftingRecipe recipe = shaped ? new ShapedRecipe(
id,
group,
bookCategory,
width,
height,
materials,
result
) : new ShapelessRecipe(id, group, result, materials);
) : new ShapelessRecipe(id, group, bookCategory, result, materials);
BCLRecipeManager.addRecipe(type, recipe);
registerAdvancement(recipe);

View file

@ -34,7 +34,8 @@ public abstract class BaseRegistry<T> {
public Item.Properties makeItemSettings() {
Item.Properties properties = new Item.Properties();
return properties.tab(creativeTab);
//TODO: 1.19.3 Creative mode tabs are handled differently now
return properties;//.tab(creativeTab);
}
private void registerInternal() {

View file

@ -1,6 +1,8 @@
package org.betterx.bclib.util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
import net.minecraft.core.Vec3i;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
@ -67,7 +69,7 @@ public class StructureHelper {
CompoundTag nbttagcompound = NbtIo.readCompressed(stream);
StructureTemplate template = new StructureTemplate();
template.load(nbttagcompound);
template.load(HolderLookup.forRegistry(Registry.BLOCK), nbttagcompound);
return template;
}

View file

@ -6,7 +6,7 @@ import net.minecraft.world.level.levelgen.WorldGenSettings;
public class ChunkGeneratorUtils {
public static void restoreOriginalBiomeSourceInAllDimension(WorldGenSettings settings) {
for (var entry : settings.dimensions().entrySet()) {
for (var entry : settings.dimensions().dimensions().entrySet()) {
ResourceKey<LevelStem> key = entry.getKey();
LevelStem stem = entry.getValue();

View file

@ -10,15 +10,15 @@ import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.WorldDimensions;
public interface EnforceableChunkGenerator<G extends ChunkGenerator> {
WorldGenSettings enforceGeneratorInWorldGenSettings(
WorldDimensions enforceGeneratorInWorldGenSettings(
RegistryAccess access,
ResourceKey<LevelStem> dimensionKey,
ResourceKey<DimensionType> dimensionTypeKey,
ChunkGenerator loadedChunkGenerator,
WorldGenSettings settings
WorldDimensions worldDims
);
default boolean togetherShouldRepair(ChunkGenerator chunkGenerator) {

View file

@ -12,17 +12,12 @@ import org.betterx.worlds.together.world.event.WorldBootstrap;
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
import org.betterx.worlds.together.worldPreset.WorldPresets;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.JsonOps;
import net.minecraft.Util;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.chunk.ChunkGenerator;
@ -30,14 +25,11 @@ import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.WorldDimensions;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
import net.minecraft.world.level.levelgen.structure.StructureSet;
import net.minecraft.world.level.levelgen.synth.NormalNoise;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonElement;
import java.util.HashMap;
import java.util.Map;
import org.jetbrains.annotations.ApiStatus;
@ -46,18 +38,18 @@ public class WorldGenUtil {
public static final String TAG_PRESET = "preset";
public static final String TAG_GENERATOR = "generator";
public static WorldGenSettings createWorldFromPreset(
public static WorldDimensions createWorldFromPreset(
ResourceKey<WorldPreset> preset,
RegistryAccess registryAccess,
long seed,
boolean generateStructures,
boolean generateBonusChest
) {
WorldGenSettings settings = registryAccess
WorldDimensions settings = registryAccess
.registryOrThrow(Registry.WORLD_PRESET_REGISTRY)
.getHolderOrThrow(preset)
.value()
.createWorldGenSettings(seed, generateStructures, generateBonusChest);
.createWorldDimensions();
for (LevelStem stem : settings.dimensions()) {
if (stem.generator().getBiomeSource() instanceof BiomeSourceWithSeed bcl) {
@ -73,7 +65,7 @@ public class WorldGenUtil {
return settings;
}
public static WorldGenSettings createDefaultWorldFromPreset(
public static WorldDimensions createDefaultWorldFromPreset(
RegistryAccess registryAccess,
long seed,
boolean generateStructures,
@ -89,28 +81,30 @@ public class WorldGenUtil {
}
@ApiStatus.Internal
public static Pair<WorldGenSettings, RegistryAccess.Frozen> defaultWorldDataSupplier(
RegistryOps<JsonElement> loaderOps,
RegistryAccess.Frozen frozen
) {
WorldGenSettings defaultGen = createDefaultWorldFromPreset(frozen);
RegistryOps<JsonElement> registryOps = RegistryOps.create(JsonOps.INSTANCE, frozen);
WorldGenSettings worldGenSettings = WorldGenSettings.CODEC
.encodeStart(registryOps, defaultGen)
.flatMap(json -> WorldGenSettings.CODEC.parse(
loaderOps,
json
))
.getOrThrow(
false,
Util.prefix(
"Error parsing worldgen settings after loading data packs: ",
WorldsTogether.LOGGER::error
)
);
// WorldGenSettings worldGenSettings = createDefaultWorldFromPreset(frozen);
return Pair.of(worldGenSettings, frozen);
}
//TODO: 1.19.3 Disabled for now
// public static Pair<WorldDimensions, RegistryAccess.Frozen> defaultWorldDataSupplier(
// RegistryOps<JsonElement> loaderOps,
// RegistryAccess.Frozen frozen
// ) {
// WorldDimensions defaultGen = createDefaultWorldFromPreset(frozen);
// RegistryOps<JsonElement> registryOps = RegistryOps.create(JsonOps.INSTANCE, frozen);
//
// WorldDimensions worldGenSettings = WorldDimensions.CODEC
// .codec().parse(registryOps, defaultGen)
// .flatMap(json -> WorldDimensions.CODEC.codec().parse(
// loaderOps,
// json
// ))
// .getOrThrow(
// false,
// Util.prefix(
// "Error parsing worldgen settings after loading data packs: ",
// WorldsTogether.LOGGER::error
// )
// );
//// WorldGenSettings worldGenSettings = createDefaultWorldFromPreset(frozen);
// return Pair.of(worldGenSettings, frozen);
// }
private static final Map<ResourceKey<WorldPreset>, Map<ResourceKey<LevelStem>, LevelStem>> WORLD_PRESET_MAP = new HashMap<>();
@ -136,52 +130,52 @@ public class WorldGenUtil {
WORLD_PRESET_MAP.clear();
}
public static void preloadWorldPresets(ResourceManager resourceManager, RegistryAccess.Writable writable) {
clearPreloadedWorldPresets();
Registry<WorldPreset> registry = writable.registryOrThrow(Registry.WORLD_PRESET_REGISTRY);
//for (ResourceKey<WorldPreset> key : registry.registryKeySet())
ResourceKey<WorldPreset> key = net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL;
{
RegistryOps<JsonElement> loaderOps = RegistryOps.createAndLoad(
JsonOps.INSTANCE, writable, resourceManager
);
Holder<WorldPreset> in = registry.getHolderOrThrow(key);
if (in.unwrapKey().isPresent()) {
RegistryOps<JsonElement> registryOps = RegistryOps.create(JsonOps.INSTANCE, writable);
WorldGenSettings settings = WorldGenUtil.createWorldFromPreset(
in.unwrapKey().orElseThrow(),
writable,
RandomSource.create().nextLong(),
true,
false
);
WorldGenSettings worldGenSettings = WorldGenSettings.CODEC
.encodeStart(registryOps, settings)
.flatMap(json -> WorldGenSettings.CODEC.parse(
loaderOps,
json
))
.getOrThrow(
false,
Util.prefix(
"Error parsing world preset settings after loading data packs: ",
WorldsTogether.LOGGER::error
)
);
ImmutableMap.Builder<ResourceKey<LevelStem>, LevelStem> map = ImmutableMap.builder();
for (Map.Entry<ResourceKey<LevelStem>, LevelStem> entry : worldGenSettings.dimensions().entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
WORLD_PRESET_MAP.put(key, map.build());
}
}
}
// public static void preloadWorldPresets(ResourceManager resourceManager, RegistryAccess.Writable writable) {
// clearPreloadedWorldPresets();
// Registry<WorldPreset> registry = writable.registryOrThrow(Registry.WORLD_PRESET_REGISTRY);
// //for (ResourceKey<WorldPreset> key : registry.registryKeySet())
// ResourceKey<WorldPreset> key = net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL;
// {
// RegistryOps<JsonElement> loaderOps = RegistryOps.createAndLoad(
// JsonOps.INSTANCE, writable, resourceManager
// );
// Holder<WorldPreset> in = registry.getHolderOrThrow(key);
// if (in.unwrapKey().isPresent()) {
// RegistryOps<JsonElement> registryOps = RegistryOps.create(JsonOps.INSTANCE, writable);
// WorldGenSettings settings = WorldGenUtil.createWorldFromPreset(
// in.unwrapKey().orElseThrow(),
// writable,
// RandomSource.create().nextLong(),
// true,
// false
// );
// WorldGenSettings worldGenSettings = WorldGenSettings.CODEC
// .encodeStart(registryOps, settings)
// .flatMap(json -> WorldGenSettings.CODEC.parse(
// loaderOps,
// json
// ))
// .getOrThrow(
// false,
// Util.prefix(
// "Error parsing world preset settings after loading data packs: ",
// WorldsTogether.LOGGER::error
// )
// );
// ImmutableMap.Builder<ResourceKey<LevelStem>, LevelStem> map = ImmutableMap.builder();
// for (Map.Entry<ResourceKey<LevelStem>, LevelStem> entry : worldGenSettings.dimensions().entrySet()) {
// map.put(entry.getKey(), entry.getValue());
// }
// WORLD_PRESET_MAP.put(key, map.build());
// }
// }
// }
public static WorldGenSettings createDefaultWorldFromPreset(RegistryAccess registryAccess, long seed) {
public static WorldDimensions createDefaultWorldFromPreset(RegistryAccess registryAccess, long seed) {
return createDefaultWorldFromPreset(registryAccess, seed, true, false);
}
public static WorldGenSettings createDefaultWorldFromPreset(RegistryAccess registryAccess) {
public static WorldDimensions createDefaultWorldFromPreset(RegistryAccess registryAccess) {
return createDefaultWorldFromPreset(registryAccess, RandomSource.create().nextLong());
}
@ -233,9 +227,9 @@ public class WorldGenUtil {
@SuppressWarnings("unchecked")
@ApiStatus.Internal
public static WorldGenSettings repairBiomeSourceInAllDimensions(
public static WorldDimensions repairBiomeSourceInAllDimensions(
RegistryAccess registryAccess,
WorldGenSettings settings
WorldDimensions settings
) {
var dimensions = TogetherWorldPreset.loadWorldDimensions();
for (var entry : settings.dimensions().entrySet()) {
@ -271,7 +265,7 @@ public class WorldGenUtil {
settings = enforcer.enforceGeneratorInWorldGenSettings(
registryAccess,
key,
loadedStem.typeHolder().unwrapKey().orElseThrow(),
loadedStem.type().unwrapKey().orElseThrow(),
loadedChunkGenerator,
settings
);

View file

@ -1,15 +1,11 @@
package org.betterx.worlds.together.mixin.client;
import org.betterx.worlds.together.levelgen.WorldGenUtil;
import org.betterx.worlds.together.world.event.WorldBootstrap;
import org.betterx.worlds.together.worldPreset.WorldPresets;
import com.mojang.serialization.JsonOps;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.WorldLoader;
import net.minecraft.world.level.DataPackConfig;
@ -17,7 +13,6 @@ import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
import net.minecraft.world.level.storage.LevelStorageSource;
import com.google.gson.JsonElement;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -65,23 +60,25 @@ public class CreateWorldScreenMixin {
//Make sure the WorldGenSettings used to populate the create screen match the default WorldPreset
@ModifyArg(method = "openFresh", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/WorldLoader;load(Lnet/minecraft/server/WorldLoader$InitConfig;Lnet/minecraft/server/WorldLoader$WorldDataSupplier;Lnet/minecraft/server/WorldLoader$ResultFactory;Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"))
private static WorldLoader.WorldDataSupplier<WorldGenSettings> wt_NewDefaultSettings(WorldLoader.WorldDataSupplier<WorldGenSettings> worldDataSupplier) {
return (resourceManager, dataPackConfig) -> {
// Pair<WorldGenSettings, RegistryAccess.Frozen> res = worldDataSupplier.get(resourceManager, dataPackConfig);
// WorldGenSettings defaultGen = net.minecraft.world.level.levelgen.presets.WorldPresets.createNormalWorldFromPreset(frozen);
// WorldBootstrap.InGUI.setDefaultCreateWorldSettings(defaultGen);
RegistryAccess.Writable writable = RegistryAccess.builtinCopy();
WorldGenUtil.preloadWorldPresets(resourceManager, writable);
RegistryOps<JsonElement> registryOps = RegistryOps.createAndLoad(
JsonOps.INSTANCE, writable, resourceManager
);
RegistryAccess.Frozen frozen = writable.freeze();
WorldBootstrap.InGUI.registryReady(frozen);
return WorldGenUtil.defaultWorldDataSupplier(registryOps, frozen);
};
return worldDataSupplier;
//TODO: 1.19.3 New DataProviders might handle this edge case automatically?
// return (resourceManager, dataPackConfig) -> {
//// Pair<WorldGenSettings, RegistryAccess.Frozen> res = worldDataSupplier.get(resourceManager, dataPackConfig);
//// WorldGenSettings defaultGen = net.minecraft.world.level.levelgen.presets.WorldPresets.createNormalWorldFromPreset(frozen);
//// WorldBootstrap.InGUI.setDefaultCreateWorldSettings(defaultGen);
// RegistryAccess.Writable writable = RegistryAccess.builtinCopy();
//
//
// WorldGenUtil.preloadWorldPresets(resourceManager, writable);
// RegistryOps<JsonElement> registryOps = RegistryOps.createAndLoad(
// JsonOps.INSTANCE, writable, resourceManager
// );
// RegistryAccess.Frozen frozen = writable.freeze();
// WorldBootstrap.InGUI.registryReady(frozen);
//
//
// return WorldGenUtil.defaultWorldDataSupplier(registryOps, frozen);
// };
}
//this is called when a new world is first created

View file

@ -5,10 +5,13 @@ import org.betterx.worlds.together.world.event.WorldBootstrap;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.worldselection.WorldOpenFlows;
import net.minecraft.core.LayeredRegistryAccess;
import net.minecraft.core.RegistryAccess;
import net.minecraft.server.RegistryLayer;
import net.minecraft.server.ReloadableServerResources;
import net.minecraft.world.level.LevelSettings;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.WorldDimensions;
import net.minecraft.world.level.levelgen.WorldOptions;
import net.minecraft.world.level.storage.LevelStorageSource;
import net.minecraft.world.level.storage.WorldData;
@ -19,7 +22,7 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Optional;
import java.util.function.Function;
@Mixin(WorldOpenFlows.class)
public abstract class WorldOpenFlowsMixin {
@ -56,18 +59,19 @@ public abstract class WorldOpenFlowsMixin {
public void wt_createFreshLevel(
String levelID,
LevelSettings levelSettings,
RegistryAccess registryAccess,
WorldGenSettings worldGenSettings,
WorldOptions worldOptions,
Function<RegistryAccess, WorldDimensions> function,
CallbackInfo ci
) {
WorldBootstrap.InFreshLevel.setupNewWorld(levelID, worldGenSettings, this.levelSource, Optional.empty());
//TODO: 1.19.3 no mor dimensions at this stage...
//WorldBootstrap.InFreshLevel.setupNewWorld(levelID, worldGenSettings, this.levelSource, Optional.empty());
}
@Inject(method = "createLevelFromExistingSettings", at = @At("HEAD"))
public void wt_createLevelFromExistingSettings(
LevelStorageSource.LevelStorageAccess levelStorageAccess,
ReloadableServerResources reloadableServerResources,
RegistryAccess.Frozen frozen,
LayeredRegistryAccess<RegistryLayer> layeredRegistryAccess,
WorldData worldData,
CallbackInfo ci
) {

View file

@ -6,7 +6,6 @@ import com.mojang.serialization.DynamicOps;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.RegistryOps;
import net.minecraft.server.Main;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.storage.LevelStorageSource;
import org.spongepowered.asm.mixin.Mixin;
@ -23,7 +22,7 @@ abstract public class MainMixin {
}
@ModifyArg(method = "method_43613", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;getDataTag(Lcom/mojang/serialization/DynamicOps;Lnet/minecraft/world/level/DataPackConfig;Lcom/mojang/serialization/Lifecycle;)Lnet/minecraft/world/level/storage/WorldData;"))
@ModifyArg(method = "method_43613", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;getDataTag(Lcom/mojang/serialization/DynamicOps;Lnet/minecraft/world/level/WorldDataConfiguration;Lnet/minecraft/core/Registry;Lcom/mojang/serialization/Lifecycle;)Lcom/mojang/datafixers/util/Pair;"))
private static DynamicOps<Tag> bcl_onCreate(DynamicOps<Tag> dynamicOps) {
if (dynamicOps instanceof RegistryOps<Tag> regOps) {
WorldBootstrap.DedicatedServer.registryReady(regOps);
@ -31,9 +30,10 @@ abstract public class MainMixin {
return dynamicOps;
}
@ModifyArg(method = "method_43613", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;<init>(Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)V"))
private static WorldGenSettings bcl_onCreateLevelData(WorldGenSettings worldGenSettings) {
WorldBootstrap.DedicatedServer.applyDatapackChangesOnNewWorld(worldGenSettings);
return worldGenSettings;
}
//TODO: 1.19.3 this may be obsolete, as datapacks are handled differently now
// @ModifyArg(method = "method_43613", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;<init>(Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldOptions;Lnet/minecraft/world/level/storage/PrimaryLevelData$SpecialWorldProperty;Lcom/mojang/serialization/Lifecycle;)V"))
// private static WorldGenSettings bcl_onCreateLevelData(WorldGenSettings worldGenSettings) {
// WorldBootstrap.DedicatedServer.applyDatapackChangesOnNewWorld(worldGenSettings);
// return worldGenSettings;
// }
}

View file

@ -1,7 +1,5 @@
package org.betterx.worlds.together.mixin.common;
import org.betterx.worlds.together.world.event.WorldBootstrap;
import net.minecraft.core.RegistryAccess;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.progress.ChunkProgressListener;
@ -29,7 +27,8 @@ public class MinecraftServerMixin {
@Inject(method = "createLevels", at = @At(value = "HEAD"))
private void together_addSurfaceRules(ChunkProgressListener worldGenerationProgressListener, CallbackInfo ci) {
WorldBootstrap.finalizeWorldGenSettings(this.worldData.worldGenSettings());
//TODO: 1.19.3 Dimensions are handled differently now
//WorldBootstrap.finalizeWorldGenSettings(this.worldData.worldGenSettings());
}
}

View file

@ -1,7 +1,5 @@
package org.betterx.worlds.together.mixin.common;
import org.betterx.worlds.together.chunkgenerator.ChunkGeneratorUtils;
import com.mojang.datafixers.DataFixer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.Services;
@ -31,6 +29,7 @@ public class MinecraftServerMixinLate {
ChunkProgressListenerFactory chunkProgressListenerFactory,
CallbackInfo ci
) {
ChunkGeneratorUtils.restoreOriginalBiomeSourceInAllDimension(worldStem.worldData().worldGenSettings());
//TODO: 1.19.3 Dimensions are handled differently now
//ChunkGeneratorUtils.restoreOriginalBiomeSourceInAllDimension(worldStem.worldData().worldGenSettings());
}
}

View file

@ -1,69 +1,50 @@
package org.betterx.worlds.together.mixin.common;
import org.betterx.worlds.together.world.event.WorldBootstrap;
import com.mojang.datafixers.DataFixer;
import com.mojang.serialization.Dynamic;
import com.mojang.serialization.Lifecycle;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.RegistryOps;
import net.minecraft.world.level.LevelSettings;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.storage.LevelVersion;
import net.minecraft.world.level.storage.PrimaryLevelData;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Optional;
import org.jetbrains.annotations.Nullable;
@Mixin(PrimaryLevelData.class)
public class PrimaryLevelDataMixin {
@Shadow
@Final
private WorldGenSettings worldGenSettings;
private static final ThreadLocal<Optional<RegistryOps<Tag>>> bcl_lastRegistryAccess = ThreadLocal.withInitial(
() -> Optional.empty());
//This is the way a created (new) world is initializing the PrimaryLevelData
@ModifyArg(method = "<init>(Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;<init>(Lcom/mojang/datafixers/DataFixer;ILnet/minecraft/nbt/CompoundTag;ZIIIFJJIIIZIZZZLnet/minecraft/world/level/border/WorldBorder$Settings;IILjava/util/UUID;Ljava/util/Set;Lnet/minecraft/world/level/timers/TimerQueue;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)V"))
private static WorldGenSettings bcl_fixOtherSettings(WorldGenSettings worldGenSettings) {
return WorldBootstrap.enforceInNewWorld(worldGenSettings);
}
@Inject(method = "parse", at = @At("HEAD"))
private static void bcl_parse(
Dynamic<Tag> dynamic,
DataFixer dataFixer,
int i,
@Nullable CompoundTag compoundTag,
LevelSettings levelSettings,
LevelVersion levelVersion,
WorldGenSettings worldGenSettings,
Lifecycle lifecycle,
CallbackInfoReturnable<PrimaryLevelData> cir
) {
if (dynamic.getOps() instanceof RegistryOps<Tag> regOps) {
bcl_lastRegistryAccess.set(Optional.of(regOps));
}
}
//This is the way a loaded (existing) world is initializing the PrimaryLevelData
@ModifyArg(method = "parse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;<init>(Lcom/mojang/datafixers/DataFixer;ILnet/minecraft/nbt/CompoundTag;ZIIIFJJIIIZIZZZLnet/minecraft/world/level/border/WorldBorder$Settings;IILjava/util/UUID;Ljava/util/Set;Lnet/minecraft/world/level/timers/TimerQueue;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)V"))
private static WorldGenSettings bcl_fixSettings(WorldGenSettings settings) {
Optional<RegistryOps<Tag>> registryOps = bcl_lastRegistryAccess.get();
WorldBootstrap.InGUI.registryReadyOnLoadedWorld(registryOps);
settings = WorldBootstrap.enforceInLoadedWorld(registryOps, settings);
bcl_lastRegistryAccess.set(Optional.empty());
return settings;
}
//TODO: 1.19.3 This was changed completley
// @Shadow
// @Final
// private WorldGenSettings worldGenSettings;
// private static final ThreadLocal<Optional<RegistryOps<Tag>>> bcl_lastRegistryAccess = ThreadLocal.withInitial(
// () -> Optional.empty());
//
// //This is the way a created (new) world is initializing the PrimaryLevelData
// @ModifyArg(method = "<init>(Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;<init>(Lcom/mojang/datafixers/DataFixer;ILnet/minecraft/nbt/CompoundTag;ZIIIFJJIIIZIZZZLnet/minecraft/world/level/border/WorldBorder$Settings;IILjava/util/UUID;Ljava/util/Set;Lnet/minecraft/world/level/timers/TimerQueue;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)V"))
// private static WorldGenSettings bcl_fixOtherSettings(WorldGenSettings worldGenSettings) {
// return WorldBootstrap.enforceInNewWorld(worldGenSettings);
// }
//
// @Inject(method = "parse", at = @At("HEAD"))
// private static void bcl_parse(
// Dynamic<Tag> dynamic,
// DataFixer dataFixer,
// int i,
// @Nullable CompoundTag compoundTag,
// LevelSettings levelSettings,
// LevelVersion levelVersion,
// WorldGenSettings worldGenSettings,
// Lifecycle lifecycle,
// CallbackInfoReturnable<PrimaryLevelData> cir
// ) {
// if (dynamic.getOps() instanceof RegistryOps<Tag> regOps) {
// bcl_lastRegistryAccess.set(Optional.of(regOps));
// }
// }
//
//
// //This is the way a loaded (existing) world is initializing the PrimaryLevelData
// @ModifyArg(method = "parse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;<init>(Lcom/mojang/datafixers/DataFixer;ILnet/minecraft/nbt/CompoundTag;ZIIIFJJIIIZIZZZLnet/minecraft/world/level/border/WorldBorder$Settings;IILjava/util/UUID;Ljava/util/Set;Lnet/minecraft/world/level/timers/TimerQueue;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)V"))
// private static WorldGenSettings bcl_fixSettings(WorldGenSettings settings) {
// Optional<RegistryOps<Tag>> registryOps = bcl_lastRegistryAccess.get();
// WorldBootstrap.InGUI.registryReadyOnLoadedWorld(registryOps);
// settings = WorldBootstrap.enforceInLoadedWorld(registryOps, settings);
// bcl_lastRegistryAccess.set(Optional.empty());
// return settings;
// }
}

View file

@ -1,48 +1,35 @@
package org.betterx.worlds.together.mixin.common;
import org.betterx.worlds.together.surfaceRules.AssignedSurfaceRule;
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
import com.mojang.serialization.Codec;
import net.minecraft.client.Minecraft;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceKey;
import com.google.common.collect.ImmutableMap;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import java.util.Map;
import java.util.function.Supplier;
@Mixin(RegistryAccess.class)
public interface RegistryAccessMixin {
@ModifyArg(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;make(Ljava/util/function/Supplier;)Ljava/lang/Object;"))
private static Supplier<ImmutableMap<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>>> together_addRegistry(
Supplier<ImmutableMap<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>>> supplier
) {
return () -> {
Map<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> res = supplier.get();
ImmutableMap.Builder<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> builder = ImmutableMap.builder();
builder.putAll(res);
put(builder, SurfaceRuleRegistry.SURFACE_RULES_REGISTRY, AssignedSurfaceRule.CODEC);
return builder.build();
};
}
@Shadow
static <E> void put(
ImmutableMap.Builder<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> builder,
ResourceKey<? extends Registry<E>> resourceKey,
Codec<E> codec
) {
throw new RuntimeException("Shadowed Call");
}
//TODO: 1.19.3 This will probably be a new kind of DataProvider.
// @ModifyArg(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;make(Ljava/util/function/Supplier;)Ljava/lang/Object;"))
// private static Supplier<ImmutableMap<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>>> together_addRegistry(
// Supplier<ImmutableMap<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>>> supplier
// ) {
//
// return () -> {
// Map<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> res = supplier.get();
// ImmutableMap.Builder<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> builder = ImmutableMap.builder();
//
// builder.putAll(res);
// put(builder, SurfaceRuleRegistry.SURFACE_RULES_REGISTRY, AssignedSurfaceRule.CODEC);
// return builder.build();
// };
// }
//
// @Shadow
// static <E> void put(
// ImmutableMap.Builder<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> builder,
// ResourceKey<? extends Registry<E>> resourceKey,
// Codec<E> codec
// ) {
// throw new RuntimeException("Shadowed Call");
// }
}

View file

@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
@Mixin(DedicatedServerProperties.WorldGenProperties.class)
@Mixin(DedicatedServerProperties.WorldDimensionData.class)
public class WorldGenPropertiesMixin {
// @ModifyArg(method = "create", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/presets/WorldPreset;createWorldGenSettings(JZZ)Lnet/minecraft/world/level/levelgen/WorldGenSettings;"))
// public long wt_getSeed(long seed) {

View file

@ -84,7 +84,7 @@ public class SurfaceRuleUtil {
}
public static void injectSurfaceRulesToAllDimensions(WorldGenSettings settings) {
for (var entry : settings.dimensions().entrySet()) {
for (var entry : settings.dimensions().dimensions().entrySet()) {
ResourceKey<LevelStem> key = entry.getKey();
LevelStem stem = entry.getValue();

View file

@ -1,15 +1,15 @@
package org.betterx.worlds.together.world.event;
import net.minecraft.core.Holder;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.WorldDimensions;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
import java.util.Optional;
public class AdaptWorldPresetSettingEvent extends EventImpl<OnAdaptWorldPresetSettings> {
public Optional<Holder<WorldPreset>> emit(Optional<Holder<WorldPreset>> start, WorldGenSettings settings) {
public Optional<Holder<WorldPreset>> emit(Optional<Holder<WorldPreset>> start, WorldDimensions worldDims) {
for (OnAdaptWorldPresetSettings a : handlers) {
start = a.adapt(start, settings);
start = a.adapt(start, worldDims);
}
return start;
}

View file

@ -1,7 +1,7 @@
package org.betterx.worlds.together.world.event;
import net.minecraft.core.Holder;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.WorldDimensions;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
import java.util.Optional;
@ -10,6 +10,6 @@ import java.util.Optional;
public interface OnAdaptWorldPresetSettings {
Optional<Holder<WorldPreset>> adapt(
Optional<Holder<WorldPreset>> currentPreset,
WorldGenSettings worldGenSettings
WorldDimensions worldDims
);
}

View file

@ -22,6 +22,7 @@ import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.WorldDimensions;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
import net.minecraft.world.level.storage.LevelResource;
@ -42,7 +43,8 @@ public class WorldBootstrap {
}
public static RegistryAccess getLastRegistryAccessOrElseBuiltin() {
if (LAST_REGISTRY_ACCESS == null) return BuiltinRegistries.ACCESS;
//TODO: 1.19.3 ther no longer is a general builtin ACCESS
if (LAST_REGISTRY_ACCESS == null) return BuiltinRegistries.createAccess();
return LAST_REGISTRY_ACCESS;
}
@ -92,10 +94,10 @@ public class WorldBootstrap {
if (currentPreset.isPresent() && LAST_REGISTRY_ACCESS != null) {
var presetKey = currentPreset.get().unwrapKey();
if (presetKey.isPresent()) {
Optional<Holder<WorldPreset>> newPreset = LAST_REGISTRY_ACCESS
Optional<Holder.Reference<WorldPreset>> newPreset = LAST_REGISTRY_ACCESS
.registryOrThrow(Registry.WORLD_PRESET_REGISTRY)
.getHolder(presetKey.get());
if (newPreset.isPresent()) currentPreset = newPreset;
if (newPreset.isPresent()) currentPreset = (Optional<Holder<WorldPreset>>) (Optional<?>) newPreset;
}
}
return currentPreset;
@ -131,15 +133,15 @@ public class WorldBootstrap {
}
//Needs to get called after setupWorld
public static void applyDatapackChangesOnNewWorld(WorldGenSettings worldGenSettings) {
public static void applyDatapackChangesOnNewWorld(WorldDimensions worldDims) {
Optional<Holder<WorldPreset>> currentPreset = Optional.of(Helpers.defaultServerPreset());
currentPreset = WorldEventsImpl.ADAPT_WORLD_PRESET.emit(currentPreset, worldGenSettings);
currentPreset = WorldEventsImpl.ADAPT_WORLD_PRESET.emit(currentPreset, worldDims);
if (currentPreset.map(Holder::value).orElse(null) instanceof WorldPresetAccessor acc) {
TogetherWorldPreset.writeWorldPresetSettings(acc.bcl_getDimensions());
} else {
WorldsTogether.LOGGER.error("Failed writing together File");
TogetherWorldPreset.writeWorldPresetSettings(worldGenSettings.dimensions());
TogetherWorldPreset.writeWorldPresetSettings(worldDims.dimensions());
}
WorldEventsImpl.ON_WORLD_LOAD.emit(OnWorldLoad::onLoad);
}
@ -171,7 +173,8 @@ public class WorldBootstrap {
Optional<Holder<WorldPreset>> newPreset = setupNewWorldCommon(
levelStorageAccess.get(),
currentPreset,
worldGenSettingsComponent.settings().worldGenSettings()
//TODO: 1.19.13 see if this is the correct Dimensions list
worldGenSettingsComponent.settings().selectedDimensions()
);
if (newPreset != currentPreset) {
acc.bcl_setPreset(newPreset);
@ -188,7 +191,7 @@ public class WorldBootstrap {
static Optional<Holder<WorldPreset>> setupNewWorldCommon(
LevelStorageSource.LevelStorageAccess levelStorageAccess,
Optional<Holder<WorldPreset>> currentPreset,
WorldGenSettings worldGenSettings
WorldDimensions worldDims
) {
Helpers.initializeWorldConfig(levelStorageAccess, true);
@ -208,13 +211,13 @@ public class WorldBootstrap {
true
));
currentPreset = WorldEventsImpl.ADAPT_WORLD_PRESET.emit(currentPreset, worldGenSettings);
currentPreset = WorldEventsImpl.ADAPT_WORLD_PRESET.emit(currentPreset, worldDims);
if (currentPreset.map(Holder::value).orElse(null) instanceof WorldPresetAccessor acc) {
TogetherWorldPreset.writeWorldPresetSettings(acc.bcl_getDimensions());
} else {
WorldsTogether.LOGGER.error("Failed writing together File");
TogetherWorldPreset.writeWorldPresetSettings(worldGenSettings.dimensions());
TogetherWorldPreset.writeWorldPresetSettings(worldDims.dimensions());
}
//LifeCycleAPI._runBeforeLevelLoad();
@ -281,13 +284,13 @@ public class WorldBootstrap {
public static class InFreshLevel {
public static void setupNewWorld(
String levelID,
WorldGenSettings worldGenSettings,
WorldDimensions worldDims,
LevelStorageSource levelSource,
Optional<Holder<WorldPreset>> worldPreset
) {
try {
var levelStorageAccess = levelSource.createAccess(levelID);
InGUI.setupNewWorldCommon(levelStorageAccess, worldPreset, worldGenSettings);
InGUI.setupNewWorldCommon(levelStorageAccess, worldPreset, worldDims);
levelStorageAccess.close();
} catch (Exception e) {
WorldsTogether.LOGGER.error("Failed to initialize data in world", e);
@ -297,7 +300,7 @@ public class WorldBootstrap {
public static void finalizeWorldGenSettings(WorldGenSettings worldGenSettings) {
String output = "World Dimensions: ";
for (var entry : worldGenSettings.dimensions().entrySet()) {
for (var entry : worldGenSettings.dimensions().dimensions().entrySet()) {
WorldEventsImpl.ON_FINALIZE_LEVEL_STEM.emit(e -> e.now(
worldGenSettings,
entry.getKey(),
@ -320,13 +323,13 @@ public class WorldBootstrap {
WorldEventsImpl.ON_FINALIZED_WORLD_LOAD.emit(e -> e.done(worldGenSettings));
}
public static WorldGenSettings enforceInNewWorld(WorldGenSettings worldGenSettings) {
public static WorldDimensions enforceInNewWorld(WorldDimensions worldGenSettings) {
return WorldGenUtil.repairBiomeSourceInAllDimensions(LAST_REGISTRY_ACCESS, worldGenSettings);
}
public static WorldGenSettings enforceInLoadedWorld(
public static WorldDimensions enforceInLoadedWorld(
Optional<RegistryOps<Tag>> registryOps,
WorldGenSettings worldGenSettings
WorldDimensions worldGenSettings
) {
if (registryOps.orElse(null) instanceof RegistryOpsAccessor acc) {
return WorldGenUtil.repairBiomeSourceInAllDimensions(acc.bcl_getRegistryAccess(), worldGenSettings);

View file

@ -13,7 +13,6 @@ import com.mojang.serialization.Dynamic;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.Tag;
@ -108,11 +107,13 @@ public class TogetherWorldPreset extends WorldPreset {
try {
final RegistryAccess registryAccess = WorldBootstrap.getLastRegistryAccessOrElseBuiltin();
boolean globalRegistry = false;
if (registryAccess == BuiltinRegistries.ACCESS) {
//TODO: 1.19.3 there is no longer a builtin registry acccess
/*if (registryAccess == BuiltinRegistries.ACCESS) {
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info("Loading from builtin Registry");
globalRegistry = true;
} else {
} else */
{
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info("Loading from datapack Registry");
}
@ -145,11 +146,7 @@ public class TogetherWorldPreset extends WorldPreset {
return preset
.get()
.value()
.createWorldGenSettings(
0,
true,
true
)
.createWorldDimensions()
.dimensions();
}

View file

@ -31,7 +31,8 @@ public class WorldPresets {
private static ResourceKey<WorldPreset> DEFAULT = net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL;
public static Holder<WorldPreset> get(RegistryAccess access, ResourceKey<WorldPreset> key) {
return ((access != null) ? access : BuiltinRegistries.ACCESS)
//TODO: 1.19.3 there is no longer a builtin registry acccess
return ((access != null) ? access : BuiltinRegistries.createAccess())
.registryOrThrow(Registry.WORLD_PRESET_REGISTRY)
.getHolderOrThrow(key);
}

View file

@ -13,9 +13,10 @@ extendable class net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator
accessible class net/minecraft/data/BuiltinRegistries$RegistryBootstrap
accessible class net/minecraft/core/Registry$RegistryBootstrap
accessible class net/minecraft/world/level/levelgen/SurfaceRules$SequenceRuleSource
accessible class net/minecraft/server/dedicated/DedicatedServerProperties$WorldDimensionData
#Methods
accessible method net/minecraft/client/gui/screens/worldselection/WorldGenSettingsComponent updateSettings (Lnet/minecraft/client/gui/screens/worldselection/WorldCreationContext$Updater;)V
accessible method net/minecraft/client/gui/screens/worldselection/WorldGenSettingsComponent updateSettings (Lnet/minecraft/client/gui/screens/worldselection/WorldCreationContext$DimensionsUpdater;)V
accessible method net/minecraft/world/level/storage/loot/LootPool <init> ([Lnet/minecraft/world/level/storage/loot/entries/LootPoolEntryContainer;[Lnet/minecraft/world/level/storage/loot/predicates/LootItemCondition;[Lnet/minecraft/world/level/storage/loot/functions/LootItemFunction;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;)V
accessible method net/minecraft/world/entity/ai/village/poi/PoiTypes register (Lnet/minecraft/core/Registry;Lnet/minecraft/resources/ResourceKey;Ljava/util/Set;II)Lnet/minecraft/world/entity/ai/village/poi/PoiType;
accessible method net/minecraft/world/level/levelgen/SurfaceRules$SequenceRuleSource <init> (Ljava/util/List;)V

View file

@ -46,12 +46,10 @@
"bclib.mixins.client.json"
],
"depends": {
"fabricloader": ">=0.14.8",
"fabric": ">=0.58.0",
"fabricloader": ">=0.14.10",
"fabric": ">=0.65.0",
"minecraft": [
"1.19",
"1.19.1",
"1.19.2"
"1.19.3-alpha.22.42.a"
]
},
"custom": {