Merge remote-tracking branch 'origin/ver/6.6.0' into dev/7.0-2

This commit is contained in:
Zoe Gidiere
2024-10-25 15:21:47 -06:00
45 changed files with 245 additions and 191 deletions

View File

@@ -29,7 +29,7 @@ public class BiomeParticleConfigTemplate implements ObjectTemplate<BiomeParticle
try {
return new BiomeParticleConfig(
ParticleEffectArgumentType.readParameters(new StringReader(particle),
(RegistryWrapper.WrapperLookup) Registries.PARTICLE_TYPE.getReadOnlyWrapper()),
(RegistryWrapper.WrapperLookup) Registries.PARTICLE_TYPE),
probability);
} catch(CommandSyntaxException e) {
throw new RuntimeException(e);

View File

@@ -15,6 +15,6 @@ public class EntityTypeTemplate implements ObjectTemplate<EntityType<?>> {
@Override
public EntityType<?> get() {
return Registries.ENTITY_TYPE.get(id);
return Registries.ENTITY_TYPE.getEntry(id).orElseThrow().value();
}
}

View File

@@ -15,6 +15,6 @@ public class VillagerTypeTemplate implements ObjectTemplate<VillagerType> {
@Override
public VillagerType get() {
return Registries.VILLAGER_TYPE.get(id);
return Registries.VILLAGER_TYPE.getEntry(id).orElseThrow().value();
}
}

View File

@@ -35,7 +35,6 @@ import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.source.BiomeAccess;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.GenerationStep.Carver;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.StructureWeightSampler;
import net.minecraft.world.gen.chunk.Blender;
@@ -97,7 +96,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
public void populateEntities(ChunkRegion region) {
if(this.settings.mobGeneration()) {
ChunkPos chunkPos = region.getCenterPos();
RegistryEntry<Biome> registryEntry = region.getBiome(chunkPos.getStartPos().withY(region.getTopY() - 1));
RegistryEntry<Biome> registryEntry = region.getBiome(chunkPos.getStartPos().withY(region.getTopYInclusive() - 1));
ChunkRandom chunkRandom = new ChunkRandom(new CheckedRandom(RandomSeed.getSeed()));
chunkRandom.setPopulationSeed(region.getSeed(), chunkPos.getStartX(), chunkPos.getStartZ());
SpawnHelper.populateEntities(region, registryEntry, chunkPos, chunkRandom);
@@ -183,7 +182,7 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
WorldProperties properties = MinecraftAdapter.adapt(height, SeedHack.getSeed(noiseConfig.getMultiNoiseSampler()));
BiomeProvider biomeProvider = pack.getBiomeProvider();
int min = height.getBottomY();
for(int y = height.getTopY() - 1; y >= min; y--) {
for(int y = height.getTopYInclusive() - 1; y >= min; y--) {
if(heightmap
.getBlockPredicate()
.test((BlockState) delegate.getBlock(properties, x, y, z, biomeProvider))) return y + 1;
@@ -196,14 +195,14 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
BlockState[] array = new BlockState[height.getHeight()];
WorldProperties properties = MinecraftAdapter.adapt(height, SeedHack.getSeed(noiseConfig.getMultiNoiseSampler()));
BiomeProvider biomeProvider = pack.getBiomeProvider();
for(int y = height.getTopY() - 1; y >= height.getBottomY(); y--) {
for(int y = height.getTopYInclusive() - 1; y >= height.getBottomY(); y--) {
array[y - height.getBottomY()] = (BlockState) delegate.getBlock(properties, x, y, z, biomeProvider);
}
return new VerticalBlockSample(height.getBottomY(), array);
}
@Override
public void getDebugHudText(List<String> text, NoiseConfig noiseConfig, BlockPos pos) {
public void appendDebugHudText(List<String> text, NoiseConfig noiseConfig, BlockPos pos) {
// no op
}
@@ -219,10 +218,11 @@ public class MinecraftChunkGeneratorWrapper extends net.minecraft.world.gen.chun
logger.debug("Loading world with config pack {}", pack.getID());
}
@Override
public void carve(ChunkRegion chunkRegion, long seed, NoiseConfig noiseConfig, BiomeAccess world, StructureAccessor structureAccessor,
Chunk chunk, Carver carverStep) {
// no op
public void carve(ChunkRegion chunkRegion, long seed, NoiseConfig noiseConfig, BiomeAccess biomeAccess,
StructureAccessor structureAccessor, Chunk chunk) {
//no op
}
@Override

View File

@@ -24,6 +24,7 @@ import net.minecraft.command.argument.ItemStackArgumentType;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryWrapper.Impl;
import net.minecraft.resource.featuretoggle.FeatureSet;
import net.minecraft.util.Identifier;
import java.util.Optional;
@@ -43,14 +44,19 @@ public class MinecraftItemHandle implements ItemHandle {
public Item createItem(String data) {
try {
return (Item) new ItemStackArgumentType(new CommandRegistryAccess() {
@Override
public FeatureSet getEnabledFeatures() {
return FeatureSet.empty();
}
@Override
public Stream<RegistryKey<? extends Registry<?>>> streamAllRegistryKeys() {
return CommonPlatform.get().getServer().getRegistryManager().streamAllRegistryKeys();
}
@Override
public <T> Optional<Impl<T>> getOptionalWrapper(RegistryKey<? extends Registry<? extends T>> registryRef) {
return Optional.of(CommonPlatform.get().getServer().getRegistryManager().getWrapperOrThrow(registryRef));
public <T> Optional<Impl<T>> getOptional(RegistryKey<? extends Registry<? extends T>> registryRef) {
return Optional.of(CommonPlatform.get().getServer().getRegistryManager().getOrThrow(registryRef));
}
}).parse(new StringReader(data)).getItem();
} catch(CommandSyntaxException e) {
@@ -60,7 +66,7 @@ public class MinecraftItemHandle implements ItemHandle {
@Override
public Enchantment getEnchantment(String id) {
return (Enchantment) (Object) (CommonPlatform.get().enchantmentRegistry().get(Identifier.tryParse(id)));
return (Enchantment) (Object) (CommonPlatform.get().enchantmentRegistry().getEntry(Identifier.tryParse(id)));
}
@Override

View File

@@ -41,7 +41,7 @@ public class MinecraftWorldHandle implements WorldHandle {
@Override
public @NotNull BlockState createBlockState(@NotNull String data) {
try {
net.minecraft.block.BlockState state = BlockArgumentParser.block(Registries.BLOCK.getReadOnlyWrapper(), data, true)
net.minecraft.block.BlockState state = BlockArgumentParser.block(Registries.BLOCK, data, true)
.blockState();
if(state == null) throw new IllegalArgumentException("Invalid data: " + data);
return (BlockState) state;
@@ -60,6 +60,6 @@ public class MinecraftWorldHandle implements WorldHandle {
if(!id.contains(":")) throw new IllegalArgumentException("Invalid entity identifier " + id);
Identifier identifier = Identifier.tryParse(id);
if(identifier == null) identifier = Identifier.tryParse(id);
return (EntityType) Registries.ENTITY_TYPE.get(identifier);
return (EntityType) Registries.ENTITY_TYPE.getEntry(identifier).orElseThrow().value();
}
}

View File

@@ -54,8 +54,8 @@ public abstract class MobSpawnerBlockEntityMixin extends BlockEntity {
public abstract void setEntityType(net.minecraft.entity.EntityType<?> entityType, Random random);
public EntityType terra$getSpawnedType() {
return (EntityType) Registries.ENTITY_TYPE.get(
Identifier.tryParse(((MobSpawnerLogicAccessor) getLogic()).getSpawnEntry().getNbt().getString("id")));
return (EntityType) Registries.ENTITY_TYPE.getEntry(
Identifier.tryParse(((MobSpawnerLogicAccessor) getLogic()).getSpawnEntry().getNbt().getString("id"))).orElseThrow();
}
public void terra$setSpawnedType(@NotNull EntityType creatureType) {

View File

@@ -9,6 +9,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.Collection;
import java.util.List;
import com.dfsek.terra.api.block.state.properties.Property;
@@ -24,7 +25,7 @@ public abstract class PropertyMixin<T> {
private String name;
@Shadow
public abstract Collection<T> getValues();
public abstract List<T> getValues();
@Intrinsic
public Collection<T> terra$values() {

View File

@@ -49,9 +49,6 @@ public abstract class WorldChunkMixin {
@Nullable
public abstract net.minecraft.block.BlockState setBlockState(BlockPos pos, net.minecraft.block.BlockState state, boolean moved);
@Shadow
public abstract TickSchedulers getTickSchedulers();
public void terra$setBlock(int x, int y, int z, BlockState data, boolean physics) {
BlockPos blockPos = new BlockPos(x, y, z);
setBlockState(blockPos, (net.minecraft.block.BlockState) data, false);

View File

@@ -48,6 +48,6 @@ public abstract class ProtoChunkMixin {
}
public int terra$getMaxHeight() {
return getHeightLimitView().getTopY();
return getHeightLimitView().getTopYInclusive();
}
}

View File

@@ -19,7 +19,7 @@ package com.dfsek.terra.mod.mixin.implementations.terra.inventory.item;
import net.minecraft.component.ComponentChanges;
import net.minecraft.component.ComponentMap;
import net.minecraft.component.ComponentMapImpl;
import net.minecraft.component.MergedComponentMap;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Implements;
@@ -37,7 +37,7 @@ import com.dfsek.terra.api.inventory.item.ItemMeta;
public abstract class ItemStackMixin {
@Shadow
@Final
private ComponentMapImpl components;
private MergedComponentMap components;
@Shadow
public abstract int getCount();

View File

@@ -18,6 +18,7 @@
package com.dfsek.terra.mod.mixin.implementations.terra.world;
import net.minecraft.block.FluidBlock;
import net.minecraft.entity.SpawnReason;
import net.minecraft.fluid.Fluid;
import net.minecraft.util.collection.BoundedRegionArray;
import net.minecraft.util.math.BlockPos;
@@ -99,7 +100,7 @@ public abstract class ChunkRegionMixin {
}
public int terraWorld$getMaxHeight() {
return world.getTopY();
return world.getTopYInclusive();
}
@Intrinsic(displace = true)
@@ -125,7 +126,7 @@ public abstract class ChunkRegionMixin {
}
public Entity terraWorld$spawnEntity(double x, double y, double z, EntityType entityType) {
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(world);
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(world, SpawnReason.CHUNK_GENERATION);
entity.setPos(x, y, z);
((ChunkRegion) (Object) this).spawnEntity(entity);
return (Entity) entity;

View File

@@ -17,6 +17,7 @@
package com.dfsek.terra.mod.mixin.implementations.terra.world;
import net.minecraft.entity.SpawnReason;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldAccess;
import org.spongepowered.asm.mixin.Implements;
@@ -42,7 +43,7 @@ import com.dfsek.terra.mod.util.MinecraftUtil;
@Implements(@Interface(iface = ServerWorld.class, prefix = "terra$"))
public abstract class ServerWorldMixin {
public Entity terra$spawnEntity(double x, double y, double z, EntityType entityType) {
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(null);
net.minecraft.entity.Entity entity = ((net.minecraft.entity.EntityType<?>) entityType).create(null, SpawnReason.CHUNK_GENERATION);
entity.setPos(x, y, z);
((net.minecraft.server.world.ServerWorld) (Object) this).spawnEntity(entity);
return (Entity) entity;

View File

@@ -1,10 +1,16 @@
package com.dfsek.terra.mod.mixin.lifecycle;
import net.minecraft.registry.CombinedDynamicRegistries;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.Registry;
import net.minecraft.registry.Registry.PendingTagLoad;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.ReloadableRegistries;
import net.minecraft.registry.ServerDynamicRegistryType;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.featuretoggle.FeatureSet;
import net.minecraft.server.DataPackContents;
import net.minecraft.server.command.CommandManager;
import net.minecraft.world.biome.Biome;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@@ -16,6 +22,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.dfsek.terra.mod.util.MinecraftUtil;
import com.dfsek.terra.mod.util.TagUtil;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
@Mixin(DataPackContents.class)
public class DataPackContentsMixin {
@@ -26,12 +38,17 @@ public class DataPackContentsMixin {
/*
* #refresh populates all tags in the registries
*/
@Inject(method = "refresh()V", at = @At("RETURN"))
private void injectReload(CallbackInfo ci) {
DynamicRegistryManager.Immutable dynamicRegistryManager = this.reloadableRegistries.getRegistryManager();
TagUtil.registerWorldPresetTags(dynamicRegistryManager.get(RegistryKeys.WORLD_PRESET));
@Inject(method = "reload(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/registry/CombinedDynamicRegistries;Ljava/util/List;Lnet/minecraft/resource/featuretoggle/FeatureSet;Lnet/minecraft/server/command/CommandManager$RegistrationEnvironment;ILjava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;", at = @At("RETURN"))
private static void injectReload(ResourceManager resourceManager,
CombinedDynamicRegistries<ServerDynamicRegistryType> dynamicRegistries,
List<PendingTagLoad<?>> pendingTagLoads, FeatureSet enabledFeatures,
CommandManager.RegistrationEnvironment environment, int functionPermissionLevel,
Executor prepareExecutor,
Executor applyExecutor, CallbackInfoReturnable<CompletableFuture<DataPackContents>> cir) {
DynamicRegistryManager.Immutable dynamicRegistryManager = dynamicRegistries.getCombinedRegistryManager();
TagUtil.registerWorldPresetTags(dynamicRegistryManager.getOrThrow(RegistryKeys.WORLD_PRESET));
Registry<Biome> biomeRegistry = dynamicRegistryManager.get(RegistryKeys.BIOME);
Registry<Biome> biomeRegistry = dynamicRegistryManager.getOrThrow(RegistryKeys.BIOME);
TagUtil.registerBiomeTags(biomeRegistry);
MinecraftUtil.registerFlora(biomeRegistry);
}

View File

@@ -42,7 +42,7 @@ public final class MinecraftAdapter {
@Override
public int getMaxHeight() {
return height.getTopY();
return height.getTopYInclusive();
}
@Override

View File

@@ -54,9 +54,8 @@ public final class MinecraftUtil {
}
public static <T> Optional<RegistryEntry<T>> getEntry(Registry<T> registry, Identifier identifier) {
return registry.getOrEmpty(identifier)
.flatMap(registry::getKey)
.flatMap(registry::getEntry);
return registry.getOptionalValue(identifier)
.flatMap(id -> Optional.ofNullable(registry.getEntry(id)));
}
public static BlockEntity createState(WorldAccess worldAccess, BlockPos pos) {

View File

@@ -1,8 +1,8 @@
package com.dfsek.terra.mod.util;
import com.google.common.collect.ImmutableMap;
import net.minecraft.registry.Registry;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.TagGroupLoader.RegistryTags;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.registry.tag.WorldPresetTags;
import net.minecraft.world.biome.Biome;
@@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public final class TagUtil {
@@ -24,12 +25,9 @@ public final class TagUtil {
}
private static <T> Map<TagKey<T>, List<RegistryEntry<T>>> tagsToMutableMap(Registry<T> registry) {
return registry
.streamTagsAndEntries()
.collect(HashMap::new,
(map, pair) ->
map.put(pair.getFirst(), new ArrayList<>(pair.getSecond().stream().toList())),
HashMap::putAll);
return registry.streamTags().collect(HashMap::new,
(map, tag) -> map.put(tag.getTag(), tag.stream().collect(Collectors.toList())),
HashMap::putAll);
}
public static void registerWorldPresetTags(Registry<WorldPreset> registry) {
@@ -46,8 +44,14 @@ public final class TagUtil {
.add(preset),
() -> logger.error("Preset {} does not exist!", id)));
registry.clearTags();
registry.populateTags(ImmutableMap.copyOf(collect));
registry.startTagReload(new RegistryTags<>(registry.getKey(), collect)).apply();
if(logger.isDebugEnabled()) {
registry.streamEntries()
.map(e -> e.registryKey().getValue() + ": " +
e.streamTags().reduce("", (s, t) -> t.id() + ", " + s, String::concat))
.forEach(logger::debug);
}
}
public static void registerBiomeTags(Registry<Biome> registry) {
@@ -90,8 +94,7 @@ public final class TagUtil {
tb))),
() -> logger.error("No vanilla biome: {}", vb)));
registry.clearTags();
registry.populateTags(ImmutableMap.copyOf(collect));
registry.startTagReload(new RegistryTags<>(registry.getKey(), collect)).apply();
if(logger.isDebugEnabled()) {
registry.streamEntries()