This commit is contained in:
gnembon committed 2022-02-10 03:15:53 +01:00
1 parent 695b569977
commit 212814f46d
27 files changed
+263 -143

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/use # check these on https://fabricmc.net/use
# or better: https://modmuss50.me/fabric.html # or better: https://modmuss50.me/fabric.html
minecraft_version=22w05a minecraft_version=22w06a
loader_version=0.12.12 loader_version=0.12.12
fabric_version=0.46.2+1.18 fabric_version=0.46.2+1.18
@@ -3,14 +3,14 @@ package carpet.fakes;
import carpet.script.value.Value; import carpet.script.value.Value;
import java.util.Map; import java.util.Map;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tags.Tag; import net.minecraft.tags.TagKey;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
public interface BlockPredicateInterface public interface BlockPredicateInterface
{ {
BlockState getCMBlockState(); BlockState getCMBlockState();
Tag<Block> getCMBlockTag(); TagKey<Block> getCMBlockTagKey();
Map<Value, Value> getCMProperties(); Map<Value, Value> getCMProperties();
CompoundTag getCMDataTag(); CompoundTag getCMDataTag();
} }
@@ -4,6 +4,6 @@ import net.minecraft.world.level.biome.Biome;
public interface ChunkGeneratorInterface public interface ChunkGeneratorInterface
{ {
void initStrongholds(); //void initStrongholds();
boolean canPlaceStrongholdInBiomeCM(Biome biome); //boolean canPlaceStrongholdInBiomeCM(Biome biome);
} }
@@ -3,7 +3,7 @@ package carpet.fakes;
import java.util.Map; import java.util.Map;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.server.ServerResources; //import net.minecraft.server.ServerResources;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.storage.LevelStorageSource; import net.minecraft.world.level.storage.LevelStorageSource;
@@ -13,5 +13,5 @@ public interface MinecraftServerInterface
void forceTick(BooleanSupplier sup); void forceTick(BooleanSupplier sup);
LevelStorageSource.LevelStorageAccess getCMSession(); LevelStorageSource.LevelStorageAccess getCMSession();
Map<ResourceKey<Level>, ServerLevel> getCMWorlds(); Map<ResourceKey<Level>, ServerLevel> getCMWorlds();
ServerResources getResourceManager(); //ServerResources getResourceManager();
} }
@@ -3,5 +3,5 @@ package carpet.fakes;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
public interface PlacedFeatureInterface { public interface PlacedFeatureInterface {
ConfiguredFeature<?, ?> getRawFeature(); //ConfiguredFeature<?, ?> getRawFeature();
} }
@@ -12,11 +12,17 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.OptionalInt; import java.util.OptionalInt;
import java.util.function.Predicate;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.data.worldgen.ProcessorLists; import net.minecraft.data.worldgen.ProcessorLists;
import net.minecraft.data.worldgen.StructureFeatures; import net.minecraft.data.worldgen.StructureFeatures;
import net.minecraft.data.worldgen.placement.PlacementUtils;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@@ -34,10 +40,11 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.StructureFeature; import net.minecraft.world.level.levelgen.feature.StructureFeature;
//import net.minecraft.world.level.levelgen.feature.configurations.StructureFeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.SimpleRandomFeatureConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.SimpleRandomFeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.StructureFeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration; import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
import net.minecraft.world.level.levelgen.feature.featuresize.TwoLayersFeatureSize; import net.minecraft.world.level.levelgen.feature.featuresize.TwoLayersFeatureSize;
import net.minecraft.world.level.levelgen.feature.foliageplacers.BlobFoliagePlacer; import net.minecraft.world.level.levelgen.feature.foliageplacers.BlobFoliagePlacer;
@@ -51,6 +58,8 @@ import net.minecraft.world.level.levelgen.feature.trunkplacers.StraightTrunkPlac
import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraft.world.level.levelgen.structure.StructureCheckResult; import net.minecraft.world.level.levelgen.structure.StructureCheckResult;
import net.minecraft.world.level.levelgen.structure.StructureStart; import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.levelgen.structure.placement.ConcentricRingsStructurePlacement;
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
public class FeatureGenerator public class FeatureGenerator
{ {
@@ -129,7 +138,7 @@ public class FeatureGenerator
{ {
return ((StructureFeatureInterface)structureFeature.feature).plopAnywhere( return ((StructureFeatureInterface)structureFeature.feature).plopAnywhere(
world, pos, world.getChunkSource().getGenerator(), world, pos, world.getChunkSource().getGenerator(),
true, net.minecraft.data.worldgen.biome.Biomes.PLAINS, structureFeature.config); true, world.getServer().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).get(net.minecraft.world.level.biome.Biomes.PLAINS), structureFeature.config);
} }
@FunctionalInterface @FunctionalInterface
@@ -137,7 +146,7 @@ public class FeatureGenerator
{ {
Boolean plop(ServerLevel world, BlockPos pos); Boolean plop(ServerLevel world, BlockPos pos);
} }
private static Thing simplePlop(ConfiguredFeature feature) private static Thing simplePlop(ConfiguredFeature<?,?> feature)
{ {
return (w, p) -> { return (w, p) -> {
CarpetSettings.skipGenerationChecks.set(true); CarpetSettings.skipGenerationChecks.set(true);
@@ -152,10 +161,20 @@ public class FeatureGenerator
}; };
} }
private static <FC extends FeatureConfiguration, F extends Feature<FC>> Thing simplePlop(F feature, FC config)
{
return simplePlop(new ConfiguredFeature<>(feature, config));
}
private static Thing simplePlop(Holder<PlacedFeature> hpf)
{
return simplePlop(hpf.value().feature().value());
}
private static Thing simpleTree(TreeConfiguration config) private static Thing simpleTree(TreeConfiguration config)
{ {
//config.ignoreFluidCheck(); //config.ignoreFluidCheck();
return simplePlop(Feature.TREE.configured(config)); return simplePlop(new ConfiguredFeature(Feature.TREE, config));
} }
private static Thing spawnCustomStructure(StructureFeature structure, FeatureConfiguration conf, ResourceKey<Biome> biome) private static Thing spawnCustomStructure(StructureFeature structure, FeatureConfiguration conf, ResourceKey<Biome> biome)
@@ -177,11 +196,14 @@ public class FeatureGenerator
private static ConfiguredStructureFeature<?, ?> getDefaultFeature(StructureFeature<?> structure, ServerLevel world, BlockPos pos, boolean tryHard) private static ConfiguredStructureFeature<?, ?> getDefaultFeature(StructureFeature<?> structure, ServerLevel world, BlockPos pos, boolean tryHard)
{ {
var definedStructures = world.getChunkSource().getGenerator().getSettings().structures(structure); var definedStructures = world.getChunkSource().getGenerator().getSettings().structures(structure);
var optinalBiome = world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getResourceKey(world.getBiome(pos)); var optinalBiome = world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getResourceKey(world.getBiome(pos).value());
if (optinalBiome.isPresent()) if (optinalBiome.isPresent())
for (var configureStructure: definedStructures.inverse().get(optinalBiome.get())) for (ResourceKey<ConfiguredStructureFeature<?, ?>> configureStructureKey: definedStructures.inverse().get(optinalBiome.get()))
{
var configureStructure = world.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).get(configureStructureKey);
if (configureStructure.feature == structure) if (configureStructure.feature == structure)
return configureStructure; return configureStructure;
}
if (!tryHard) return null; if (!tryHard) return null;
return world.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).entrySet().stream(). return world.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).entrySet().stream().
filter(cS -> cS.getValue().feature == structure). filter(cS -> cS.getValue().feature == structure).
@@ -190,41 +212,45 @@ public class FeatureGenerator
private static ConfiguredFeature<?, ?> getDefaultFeature(Feature<?> feature, ServerLevel world, BlockPos pos, boolean tryHard) private static ConfiguredFeature<?, ?> getDefaultFeature(Feature<?> feature, ServerLevel world, BlockPos pos, boolean tryHard)
{ {
List<List<Supplier<PlacedFeature>>> configuredStepFeatures = world.getBiome(pos).getGenerationSettings().features(); List<HolderSet<PlacedFeature>> configuredStepFeatures = world.getBiome(pos).value().getGenerationSettings().features();
for (List<Supplier<PlacedFeature>> step: configuredStepFeatures) for (HolderSet<PlacedFeature> step: configuredStepFeatures)
for (Supplier<PlacedFeature> provider: step) for (Holder<PlacedFeature> provider: step)
{ {
ConfiguredFeature<?, ?> configuredFeature = ((PlacedFeatureInterface)provider.get()).getRawFeature(); if (provider.value().feature().value().feature() == feature)
if (configuredFeature.feature == feature) return provider.value().feature().value();
return configuredFeature;
} }
if (!tryHard) return null; if (!tryHard) return null;
return world.registryAccess().registryOrThrow(Registry.CONFIGURED_FEATURE_REGISTRY).entrySet().stream(). return world.registryAccess().registryOrThrow(Registry.CONFIGURED_FEATURE_REGISTRY).entrySet().stream().
filter(cS -> cS.getValue().feature == feature). filter(cS -> cS.getValue().feature() == feature).
findFirst().map(Map.Entry::getValue).orElse(null); findFirst().map(Map.Entry::getValue).orElse(null);
} }
public static <T extends FeatureConfiguration> StructureStart shouldStructureStartAt(ServerLevel world, BlockPos pos, StructureFeature<T> structure, boolean computeBox) public static <T extends FeatureConfiguration> StructureStart shouldStructureStartAt(ServerLevel world, BlockPos pos, StructureFeature<T> structure, boolean computeBox)
{ {
if (structure == StructureFeature.STRONGHOLD) //if (structure == StructureFeature.STRONGHOLD)
return shouldStrongholdStartAt(world, pos, computeBox); // return shouldStrongholdStartAt(world, pos, computeBox);
long seed = world.getSeed(); long seed = world.getSeed();
ChunkGenerator generator = world.getChunkSource().getGenerator(); ChunkGenerator generator = world.getChunkSource().getGenerator();
StructureSettings settings = generator.getSettings(); StructureSettings settings = generator.getSettings();
StructureFeatureConfiguration structureConfig = settings.getConfig(structure); StructurePlacement structureConfig = settings.getConfig(structure);
if (structureConfig instanceof ConcentricRingsStructurePlacement rings)
{
return shouldStrongholdStartAt(generator, rings, world, pos, computeBox);
}
var structures = settings.structures(structure); var structures = settings.structures(structure);
if (structureConfig == null || structures.isEmpty()) { if (structureConfig == null || structures.isEmpty()) {
return null; return null;
} }
ChunkPos chunkPos = new ChunkPos(pos); ChunkPos chunkPos = new ChunkPos(pos);
Biome biome = world.getBiome(pos); Holder<Biome> biome = world.getBiome(pos);
var biomeRegistry = world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY); Registry<Biome> biomeRegistry = world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
if (structures.values().stream().noneMatch(biomeKey -> biomeRegistry.get(biomeKey) == biome)) if (structures.values().stream().noneMatch(biomeKey -> biomeRegistry.getHolderOrThrow(biomeKey) == biome))
{ {
return null; return null;
} }
ChunkPos chunkPos1 = structure.getPotentialFeatureChunk(structureConfig, seed, chunkPos.x, chunkPos.z); if (!structureConfig.isFeatureChunk(generator, chunkPos.x, chunkPos.z))
if (!chunkPos1.equals(chunkPos)) //ChunkPos chunkPos1 = structure.getPotentialFeatureChunk(structureConfig, seed, chunkPos.x, chunkPos.z);
//if (!chunkPos1.equals(chunkPos))
{ {
return null; return null;
} }
@@ -242,25 +268,27 @@ public class FeatureGenerator
if (!computeBox) return StructureStart.INVALID_START; if (!computeBox) return StructureStart.INVALID_START;
ConfiguredStructureFeature<?, ?> configuredFeature = getDefaultFeature(structure, world, pos, false); ConfiguredStructureFeature<?, ?> configuredFeature = getDefaultFeature(structure, world, pos, false);
if (configuredFeature == null || configuredFeature.config == null) return null; if (configuredFeature == null || configuredFeature.config == null) return null;
var biomeConfig = structures.get(configuredFeature);
var biomeConfig = structures.get(ResourceKey.create(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY, world.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).getKey(configuredFeature)));
StructureStart<?> filledStructure = configuredFeature.generate(world.registryAccess(), generator, generator.getBiomeSource(), StructureStart<?> filledStructure = configuredFeature.generate(world.registryAccess(), generator, generator.getBiomeSource(),
world.getStructureManager(), seed, chunkPos, 0, structureConfig, world, (b) -> biomeRegistry.getResourceKey(b).filter(biomeConfig::contains).isPresent()); world.getStructureManager(), seed, chunkPos, 0, world, b -> biomeRegistry.getResourceKey(b.value()).filter(biomeConfig::contains).isPresent());
if (filledStructure != null && filledStructure.isValid()) if (filledStructure != null && filledStructure.isValid())
return filledStructure; return filledStructure;
return null; return null;
} }
public static StructureStart<?> shouldStrongholdStartAt(ServerLevel world, BlockPos pos, boolean computeBox) public static StructureStart<?> shouldStrongholdStartAt(ChunkGenerator generator, ConcentricRingsStructurePlacement rings, ServerLevel world, BlockPos pos, boolean computeBox)
{ {
ChunkGenerator generator = world.getChunkSource().getGenerator(); final List<ChunkPos> positions = generator.getRingPositionsFor(rings);
if (world.dimension() != Level.OVERWORLD || !generator.hasStronghold(new ChunkPos(pos))) return null; if (world.dimension() != Level.OVERWORLD || !positions.contains(new ChunkPos(pos))) return null;
if (!computeBox) return StructureStart.INVALID_START; if (!computeBox) return StructureStart.INVALID_START;
StructureSettings settings = generator.getSettings(); StructureSettings settings = generator.getSettings();
StructureFeatureConfiguration structureConfig = settings.getConfig(StructureFeature.STRONGHOLD); StructurePlacement structureConfig = settings.getConfig(StructureFeature.STRONGHOLD);
if (structureConfig != null) { if (structureConfig != null) {
StructureStart<?> filledStructure = StructureFeatures.STRONGHOLD.generate(world.registryAccess(), generator, generator.getBiomeSource(), final Predicate<ResourceKey<Biome>> biomeCheck = settings.structures(StructureFeature.STRONGHOLD).values().stream().collect(Collectors.toUnmodifiableSet())::contains;
world.getStructureManager(), world.getSeed(), new ChunkPos(pos), 0, final Predicate<Holder<Biome>> holderCheck = b -> b.is(biomeCheck);
structureConfig, world, ((ChunkGeneratorInterface)generator)::canPlaceStrongholdInBiomeCM StructureStart<?> filledStructure = StructureFeature.STRONGHOLD.generate(world.registryAccess(), generator, generator.getBiomeSource(),
world.getStructureManager(), world.getSeed(), new ChunkPos(pos), 0, NoneFeatureConfiguration.INSTANCE, world, holderCheck
); );
if (filledStructure != null && filledStructure.isValid()) if (filledStructure != null && filledStructure.isValid())
return filledStructure; return filledStructure;
@@ -278,60 +306,62 @@ public class FeatureGenerator
put("fancy_oak_bees", simpleTree( (new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(Blocks.OAK_LOG), new FancyTrunkPlacer(3, 11, 0), BlockStateProvider.simple(Blocks.OAK_LEAVES), new FancyFoliagePlacer(ConstantInt.of(2), ConstantInt.of(4), 4), new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(4)))).ignoreVines().decorators(List.of(new BeehiveDecorator(1.00F))).build())); put("fancy_oak_bees", simpleTree( (new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(Blocks.OAK_LOG), new FancyTrunkPlacer(3, 11, 0), BlockStateProvider.simple(Blocks.OAK_LEAVES), new FancyFoliagePlacer(ConstantInt.of(2), ConstantInt.of(4), 4), new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(4)))).ignoreVines().decorators(List.of(new BeehiveDecorator(1.00F))).build()));
put("birch_bees", simpleTree( createTree(Blocks.BIRCH_LOG, Blocks.BIRCH_LEAVES, 5, 2, 0, 2).ignoreVines().decorators(List.of(new BeehiveDecorator(1.00F))).build())); put("birch_bees", simpleTree( createTree(Blocks.BIRCH_LOG, Blocks.BIRCH_LEAVES, 5, 2, 0, 2).ignoreVines().decorators(List.of(new BeehiveDecorator(1.00F))).build()));
put("coral_tree", simplePlop(Feature.CORAL_TREE.configured(FeatureConfiguration.NONE))); //put("coral_tree", simplePlop(Feature.CORAL_TREE.configured(FeatureConfiguration.NONE)));
put("coral_claw", simplePlop(Feature.CORAL_CLAW.configured(FeatureConfiguration.NONE))); put("coral_tree", simplePlop(Feature.CORAL_TREE, FeatureConfiguration.NONE));
put("coral_mushroom", simplePlop(Feature.CORAL_MUSHROOM.configured(FeatureConfiguration.NONE)));
put("coral", simplePlop(Feature.SIMPLE_RANDOM_SELECTOR.configured(new SimpleRandomFeatureConfiguration(List.of( put("coral_claw", simplePlop(Feature.CORAL_CLAW, FeatureConfiguration.NONE));
() -> Feature.CORAL_TREE.configured(FeatureConfiguration.NONE).placed(), put("coral_mushroom", simplePlop(Feature.CORAL_MUSHROOM, FeatureConfiguration.NONE));
() -> Feature.CORAL_CLAW.configured(FeatureConfiguration.NONE).placed(), put("coral", simplePlop(Feature.SIMPLE_RANDOM_SELECTOR, new SimpleRandomFeatureConfiguration(HolderSet.direct(
() -> Feature.CORAL_MUSHROOM.configured(FeatureConfiguration.NONE).placed() PlacementUtils.inlinePlaced(Feature.CORAL_TREE, FeatureConfiguration.NONE),
))))); PlacementUtils.inlinePlaced(Feature.CORAL_CLAW, FeatureConfiguration.NONE),
PlacementUtils.inlinePlaced(Feature.CORAL_MUSHROOM, FeatureConfiguration.NONE)
))));
put("bastion_remnant_units", spawnCustomStructure( put("bastion_remnant_units", spawnCustomStructure(
StructureFeature.BASTION_REMNANT, StructureFeature.BASTION_REMNANT,
new JigsawConfiguration(() -> new StructureTemplatePool( new JigsawConfiguration(Holder.direct(new StructureTemplatePool(
new ResourceLocation("bastion/starts"), new ResourceLocation("bastion/starts"),
new ResourceLocation("empty"), new ResourceLocation("empty"),
List.of( List.of(
Pair.of(StructurePoolElement.single("bastion/units/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1) Pair.of(StructurePoolElement.single("bastion/units/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
), ),
StructureTemplatePool.Projection.RIGID StructureTemplatePool.Projection.RIGID
), 6), )), 6),
Biomes.NETHER_WASTES Biomes.NETHER_WASTES
)); ));
put("bastion_remnant_hoglin_stable", spawnCustomStructure( put("bastion_remnant_hoglin_stable", spawnCustomStructure(
StructureFeature.BASTION_REMNANT, StructureFeature.BASTION_REMNANT,
new JigsawConfiguration(() -> new StructureTemplatePool( new JigsawConfiguration(Holder.direct(new StructureTemplatePool(
new ResourceLocation("bastion/starts"), new ResourceLocation("bastion/starts"),
new ResourceLocation("empty"), new ResourceLocation("empty"),
List.of( List.of(
Pair.of(StructurePoolElement.single("bastion/hoglin_stable/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1) Pair.of(StructurePoolElement.single("bastion/hoglin_stable/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
), ),
StructureTemplatePool.Projection.RIGID StructureTemplatePool.Projection.RIGID
), 6), )), 6),
Biomes.NETHER_WASTES Biomes.NETHER_WASTES
)); ));
put("bastion_remnant_treasure", spawnCustomStructure( put("bastion_remnant_treasure", spawnCustomStructure(
StructureFeature.BASTION_REMNANT, StructureFeature.BASTION_REMNANT,
new JigsawConfiguration(() -> new StructureTemplatePool( new JigsawConfiguration(Holder.direct(new StructureTemplatePool(
new ResourceLocation("bastion/starts"), new ResourceLocation("bastion/starts"),
new ResourceLocation("empty"), new ResourceLocation("empty"),
List.of( List.of(
Pair.of(StructurePoolElement.single("bastion/treasure/big_air_full", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1) Pair.of(StructurePoolElement.single("bastion/treasure/big_air_full", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
), ),
StructureTemplatePool.Projection.RIGID StructureTemplatePool.Projection.RIGID
), 6), )), 6),
Biomes.NETHER_WASTES Biomes.NETHER_WASTES
)); ));
put("bastion_remnant_bridge", spawnCustomStructure( put("bastion_remnant_bridge", spawnCustomStructure(
StructureFeature.BASTION_REMNANT, StructureFeature.BASTION_REMNANT,
new JigsawConfiguration(() -> new StructureTemplatePool( new JigsawConfiguration(Holder.direct(new StructureTemplatePool(
new ResourceLocation("bastion/starts"), new ResourceLocation("bastion/starts"),
new ResourceLocation("empty"), new ResourceLocation("empty"),
List.of( List.of(
Pair.of(StructurePoolElement.single("bastion/bridge/starting_pieces/entrance_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1) Pair.of(StructurePoolElement.single("bastion/bridge/starting_pieces/entrance_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
), ),
StructureTemplatePool.Projection.RIGID StructureTemplatePool.Projection.RIGID
), 6), )), 6),
Biomes.NETHER_WASTES Biomes.NETHER_WASTES
)); ));
}}; }};
@@ -4,6 +4,7 @@ import carpet.fakes.BlockPredicateInterface;
import carpet.script.value.StringValue; import carpet.script.value.StringValue;
import carpet.script.value.Value; import carpet.script.value.Value;
import carpet.script.value.ValueConversions; import carpet.script.value.ValueConversions;
import net.minecraft.tags.TagKey;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@@ -34,7 +35,7 @@ public class BlockPredicate_scarpetMixin implements BlockPredicateInterface
} }
@Override @Override
public Tag<Block> getCMBlockTag() public TagKey<Block> getCMBlockTagKey()
{ {
return null; return null;
} }
@@ -9,17 +9,17 @@ import org.spongepowered.asm.mixin.Shadow;
@Mixin(ChunkGenerator.class) @Mixin(ChunkGenerator.class)
public abstract class ChunkGenerator_scarpetMixin implements ChunkGeneratorInterface public abstract class ChunkGenerator_scarpetMixin implements ChunkGeneratorInterface
{ {
@Shadow protected abstract void generateStrongholds(); //@Shadow protected abstract void generateStrongholds(); // postInit
@Shadow private static boolean validStrongholdBiome(Biome biome) { return true;} //@Shadow private static boolean validStrongholdBiome(Biome biome) { return true;}
@Override // @Override
public void initStrongholds() //public void initStrongholds()
{ //{
generateStrongholds(); // generateStrongholds();
} //}
@Override //@Override
public boolean canPlaceStrongholdInBiomeCM(Biome biome) { //public boolean canPlaceStrongholdInBiomeCM(Biome biome) {
return validStrongholdBiome(biome); // return validStrongholdBiome(biome);
} //}
} }
@@ -3,6 +3,8 @@ package carpet.mixins;
import carpet.CarpetSettings; import carpet.CarpetSettings;
import carpet.fakes.CoralFeatureInterface; import carpet.fakes.CoralFeatureInterface;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
import net.minecraft.tags.FluidTags; import net.minecraft.tags.FluidTags;
@@ -23,6 +25,8 @@ import net.minecraft.world.level.material.MaterialColor;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import java.util.Random; import java.util.Random;
import java.util.Set;
import java.util.stream.Collectors;
@Mixin(CoralFanBlock.class) @Mixin(CoralFanBlock.class)
public abstract class CoralFanBlock_renewableCoralMixin implements BonemealableBlock public abstract class CoralFanBlock_renewableCoralMixin implements BonemealableBlock
@@ -53,7 +57,8 @@ public abstract class CoralFanBlock_renewableCoralMixin implements BonemealableB
MaterialColor color = blockUnder.getMapColor(worldIn, pos); MaterialColor color = blockUnder.getMapColor(worldIn, pos);
BlockState proper_block = blockUnder; BlockState proper_block = blockUnder;
for (Block block: BlockTags.CORAL_BLOCKS.getValues()) Set<Block> coralBlockSet = worldIn.registryAccess().registryOrThrow(Registry.BLOCK_REGISTRY).getTag(BlockTags.CORAL_BLOCKS).orElseThrow().stream().map(Holder::value).collect(Collectors.toUnmodifiableSet());
for (Block block: coralBlockSet)
{ {
proper_block = block.defaultBlockState(); proper_block = block.defaultBlockState();
if (proper_block.getMapColor(worldIn,pos) == color) if (proper_block.getMapColor(worldIn,pos) == color)
@@ -72,7 +77,7 @@ public abstract class CoralFanBlock_renewableCoralMixin implements BonemealableB
if (worldIn.random.nextInt(10)==0) if (worldIn.random.nextInt(10)==0)
{ {
BlockPos randomPos = pos.offset(worldIn.random.nextInt(16)-8,worldIn.random.nextInt(8),worldIn.random.nextInt(16)-8 ); BlockPos randomPos = pos.offset(worldIn.random.nextInt(16)-8,worldIn.random.nextInt(8),worldIn.random.nextInt(16)-8 );
if (BlockTags.CORAL_BLOCKS.contains(worldIn.getBlockState(randomPos).getBlock())) if (coralBlockSet.contains(worldIn.getBlockState(randomPos).getBlock()))
{ {
worldIn.setBlock(randomPos, Blocks.WET_SPONGE.defaultBlockState(), 3); worldIn.setBlock(randomPos, Blocks.WET_SPONGE.defaultBlockState(), 3);
} }
@@ -2,9 +2,14 @@ package carpet.mixins;
import carpet.CarpetSettings; import carpet.CarpetSettings;
import carpet.fakes.CoralFeatureInterface; import carpet.fakes.CoralFeatureInterface;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import java.util.Random; import java.util.Random;
import java.util.Set;
import java.util.stream.Collectors;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
@@ -54,7 +59,8 @@ public abstract class CoralPlantBlock_renewableCoralMixin implements Bonemealabl
MaterialColor color = blockUnder.getMapColor(worldIn, pos); MaterialColor color = blockUnder.getMapColor(worldIn, pos);
BlockState proper_block = blockUnder; BlockState proper_block = blockUnder;
for (Block block: BlockTags.CORAL_BLOCKS.getValues()) Set<Block> coralBlockSet = worldIn.registryAccess().registryOrThrow(Registry.BLOCK_REGISTRY).getTag(BlockTags.CORAL_BLOCKS).orElseThrow().stream().map(Holder::value).collect(Collectors.toUnmodifiableSet());
for (Block block: coralBlockSet)
{ {
proper_block = block.defaultBlockState(); proper_block = block.defaultBlockState();
if (proper_block.getMapColor(worldIn,pos) == color) if (proper_block.getMapColor(worldIn,pos) == color)
@@ -73,7 +79,7 @@ public abstract class CoralPlantBlock_renewableCoralMixin implements Bonemealabl
if (worldIn.random.nextInt(10)==0) if (worldIn.random.nextInt(10)==0)
{ {
BlockPos randomPos = pos.offset(worldIn.random.nextInt(16)-8,worldIn.random.nextInt(8),worldIn.random.nextInt(16)-8 ); BlockPos randomPos = pos.offset(worldIn.random.nextInt(16)-8,worldIn.random.nextInt(8),worldIn.random.nextInt(16)-8 );
if (BlockTags.CORAL_BLOCKS.contains(worldIn.getBlockState(randomPos).getBlock())) if (coralBlockSet.contains(worldIn.getBlockState(randomPos).getBlock()))
{ {
worldIn.setBlock(randomPos, Blocks.WET_SPONGE.defaultBlockState(), 3); worldIn.setBlock(randomPos, Blocks.WET_SPONGE.defaultBlockState(), 3);
} }
@@ -2,6 +2,7 @@ package carpet.mixins;
import carpet.CarpetSettings; import carpet.CarpetSettings;
import carpet.helpers.CustomSpawnLists; import carpet.helpers.CustomSpawnLists;
import net.minecraft.core.Holder;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@@ -30,7 +31,7 @@ public abstract class FlatLevelSource_structuresMixin extends ChunkGenerator
} }
@Override @Override
public WeightedRandomList<MobSpawnSettings.SpawnerData> getMobsAt(Biome biome, StructureFeatureManager accessor, MobCategory group, BlockPos pos) public WeightedRandomList<MobSpawnSettings.SpawnerData> getMobsAt(Holder<Biome> biome, StructureFeatureManager accessor, MobCategory group, BlockPos pos)
{ {
if (!CarpetSettings.flatWorldStructureSpawning) return super.getMobsAt(biome, accessor, group, pos); if (!CarpetSettings.flatWorldStructureSpawning) return super.getMobsAt(biome, accessor, group, pos);
@@ -5,7 +5,6 @@ import carpet.helpers.TickSpeed;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerResources;
import net.minecraft.server.TickTask; import net.minecraft.server.TickTask;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.thread.ReentrantBlockableEventLoop; import net.minecraft.util.thread.ReentrantBlockableEventLoop;
@@ -45,7 +44,7 @@ public abstract class MinecraftServer_scarpetMixin extends ReentrantBlockableEve
@Shadow @Final private Map<ResourceKey<Level>, ServerLevel> levels; @Shadow @Final private Map<ResourceKey<Level>, ServerLevel> levels;
@Shadow private ServerResources resources; //@Shadow private ServerResources resources;
@Override @Override
public void forceTick(BooleanSupplier isAhead) public void forceTick(BooleanSupplier isAhead)
@@ -61,10 +60,10 @@ public abstract class MinecraftServer_scarpetMixin extends ReentrantBlockableEve
return storageSource; return storageSource;
} }
@Override //@Override
public ServerResources getResourceManager() { //public ServerResources getResourceManager() {
return resources; // return resources;
} //}
@Override @Override
public Map<ResourceKey<Level>, ServerLevel> getCMWorlds() public Map<ResourceKey<Level>, ServerLevel> getCMWorlds()
@@ -2,6 +2,7 @@ package carpet.mixins;
import carpet.CarpetSettings; import carpet.CarpetSettings;
import carpet.helpers.CustomSpawnLists; import carpet.helpers.CustomSpawnLists;
import net.minecraft.core.Holder;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@@ -28,13 +29,13 @@ public abstract class NoiseBasedChunkGenerator_husksSpawnMixin extends ChunkGene
} }
@Inject(method = "getMobsAt", at = @At("HEAD"), cancellable = true) @Inject(method = "getMobsAt", at = @At("HEAD"), cancellable = true)
private void isInsidePyramid(Biome biome, StructureFeatureManager accessor, MobCategory group, BlockPos pos, CallbackInfoReturnable<WeightedRandomList<MobSpawnSettings.SpawnerData>> cir) private void isInsidePyramid(Holder<Biome> holder, StructureFeatureManager structureFeatureManager, MobCategory mobCategory, BlockPos blockPos, CallbackInfoReturnable<WeightedRandomList<MobSpawnSettings.SpawnerData>> cir)
{ {
if (group == MobCategory.MONSTER) if (mobCategory == MobCategory.MONSTER)
{ {
if (CarpetSettings.huskSpawningInTemples) if (CarpetSettings.huskSpawningInTemples)
{ {
if (accessor.getStructureAt(pos, StructureFeature.DESERT_PYRAMID).isValid()) if (structureFeatureManager.getStructureAt(blockPos, StructureFeature.DESERT_PYRAMID).isValid())
{ {
cir.setReturnValue(CustomSpawnLists.PYRAMID_SPAWNS); cir.setReturnValue(CustomSpawnLists.PYRAMID_SPAWNS);
return; return;
@@ -42,7 +43,7 @@ public abstract class NoiseBasedChunkGenerator_husksSpawnMixin extends ChunkGene
} }
if (CarpetSettings.shulkerSpawningInEndCities) if (CarpetSettings.shulkerSpawningInEndCities)
{ {
if (accessor.getStructureAt(pos, StructureFeature.END_CITY).isValid()) if (structureFeatureManager.getStructureAt(blockPos, StructureFeature.END_CITY).isValid())
{ {
cir.setReturnValue(CustomSpawnLists.SHULKER_SPAWNS); cir.setReturnValue(CustomSpawnLists.SHULKER_SPAWNS);
return; return;
@@ -50,7 +51,7 @@ public abstract class NoiseBasedChunkGenerator_husksSpawnMixin extends ChunkGene
} }
if (CarpetSettings.piglinsSpawningInBastions) if (CarpetSettings.piglinsSpawningInBastions)
{ {
if (accessor.getStructureAt(pos, StructureFeature.BASTION_REMNANT).isValid()) if (structureFeatureManager.getStructureAt(blockPos, StructureFeature.BASTION_REMNANT).isValid())
{ {
cir.setReturnValue(CustomSpawnLists.BASTION_SPAWNS); cir.setReturnValue(CustomSpawnLists.BASTION_SPAWNS);
} }
@@ -2,6 +2,7 @@ package carpet.mixins;
import carpet.CarpetSettings; import carpet.CarpetSettings;
import net.minecraft.tags.Tag; import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.DiggerItem; import net.minecraft.world.item.DiggerItem;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.PickaxeItem; import net.minecraft.world.item.PickaxeItem;
@@ -15,7 +16,7 @@ import org.spongepowered.asm.mixin.Mixin;
public class PickaxeItem_missingToolsMixin extends DiggerItem public class PickaxeItem_missingToolsMixin extends DiggerItem
{ {
protected PickaxeItem_missingToolsMixin(float attackDamage, float attackSpeed, Tier material, Tag<Block> tag, Properties settings) { protected PickaxeItem_missingToolsMixin(float attackDamage, float attackSpeed, Tier material, TagKey<Block> tag, Properties settings) {
super(attackDamage, attackSpeed, material, tag, settings); super(attackDamage, attackSpeed, material, tag, settings);
} }
@@ -12,10 +12,4 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature;
@Mixin(PlacedFeature.class) @Mixin(PlacedFeature.class)
public class PlacedFeature_scarpetMixin implements PlacedFeatureInterface { public class PlacedFeature_scarpetMixin implements PlacedFeatureInterface {
@Shadow @Final private Supplier<ConfiguredFeature<?, ?>> feature;
@Override
public ConfiguredFeature<?, ?> getRawFeature() {
return feature.get();
}
} }
@@ -23,7 +23,7 @@ public abstract class SaplingBlock_desertShrubsMixin
cancellable = true) cancellable = true)
private void onGenerate(ServerLevel serverWorld_1, BlockPos blockPos_1, BlockState blockState_1, Random random_1, CallbackInfo ci) private void onGenerate(ServerLevel serverWorld_1, BlockPos blockPos_1, BlockState blockState_1, Random random_1, CallbackInfo ci)
{ {
if(CarpetSettings.desertShrubs && serverWorld_1.getBiome(blockPos_1).getBiomeCategory() == Biome.BiomeCategory.DESERT && !BlockSaplingHelper.hasWater(serverWorld_1, blockPos_1)) if(CarpetSettings.desertShrubs && Biome.getBiomeCategory(serverWorld_1.getBiome(blockPos_1)) == Biome.BiomeCategory.DESERT && !BlockSaplingHelper.hasWater(serverWorld_1, blockPos_1))
{ {
serverWorld_1.setBlock(blockPos_1, Blocks.DEAD_BUSH.defaultBlockState(), 3); serverWorld_1.setBlock(blockPos_1, Blocks.DEAD_BUSH.defaultBlockState(), 3);
ci.cancel(); ci.cancel();
@@ -2,6 +2,7 @@ package carpet.mixins;
import carpet.helpers.TickSpeed; import carpet.helpers.TickSpeed;
import carpet.utils.CarpetProfiler; import carpet.utils.CarpetProfiler;
import net.minecraft.core.Holder;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
@@ -23,7 +24,7 @@ import net.minecraft.world.level.storage.WritableLevelData;
@Mixin(ServerLevel.class) @Mixin(ServerLevel.class)
public abstract class ServerLevel_tickMixin extends Level public abstract class ServerLevel_tickMixin extends Level
{ {
protected ServerLevel_tickMixin(WritableLevelData properties, ResourceKey<Level> registryKey, DimensionType dimensionType, Supplier<ProfilerFiller> supplier, boolean bl, boolean bl2, long l) protected ServerLevel_tickMixin(WritableLevelData properties, ResourceKey<Level> registryKey, Holder<DimensionType> dimensionType, Supplier<ProfilerFiller> supplier, boolean bl, boolean bl2, long l)
{ {
super(properties, registryKey, dimensionType, supplier, bl, bl2, l); super(properties, registryKey, dimensionType, supplier, bl, bl2, l);
} }
@@ -3,6 +3,7 @@ package carpet.mixins;
import carpet.fakes.BlockPredicateInterface; import carpet.fakes.BlockPredicateInterface;
import carpet.script.value.StringValue; import carpet.script.value.StringValue;
import carpet.script.value.Value; import carpet.script.value.Value;
import net.minecraft.tags.TagKey;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@@ -17,7 +18,7 @@ import net.minecraft.world.level.block.state.BlockState;
@Mixin(targets = "net.minecraft.commands.arguments.blocks.BlockPredicateArgument$TagPredicate") @Mixin(targets = "net.minecraft.commands.arguments.blocks.BlockPredicateArgument$TagPredicate")
public class TagPredicate_scarpetMixin implements BlockPredicateInterface public class TagPredicate_scarpetMixin implements BlockPredicateInterface
{ {
@Shadow @Final private Tag<Block> tag; @Shadow @Final private TagKey<Block> tag;
@Shadow @Final private Map<String, String> vagueProperties; @Shadow @Final private Map<String, String> vagueProperties;
@@ -30,7 +31,7 @@ public class TagPredicate_scarpetMixin implements BlockPredicateInterface
} }
@Override @Override
public Tag<Block> getCMBlockTag() public TagKey<Block> getCMBlockTagKey()
{ {
return tag; return tag;
} }
@@ -64,16 +64,16 @@ import net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket;
import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket; import net.minecraft.network.protocol.game.ClientboundSetSubtitleTextPacket;
import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket; import net.minecraft.network.protocol.game.ClientboundSetTitleTextPacket;
import net.minecraft.network.protocol.game.ClientboundSetTitlesAnimationPacket; import net.minecraft.network.protocol.game.ClientboundSetTitlesAnimationPacket;
import net.minecraft.resources.RegistryReadOps; //import net.minecraft.resources.RegistryReadOps;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerResources; //import net.minecraft.server.ServerResources;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.packs.repository.Pack; import net.minecraft.server.packs.repository.Pack;
import net.minecraft.server.packs.repository.PackRepository; import net.minecraft.server.packs.repository.PackRepository;
import net.minecraft.server.packs.resources.SimpleReloadableResourceManager; //import net.minecraft.server.packs.resources.SimpleReloadableResourceManager;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
import net.minecraft.stats.Stat; import net.minecraft.stats.Stat;
import net.minecraft.stats.StatType; import net.minecraft.stats.StatType;
@@ -1102,6 +1102,8 @@ public class Auxiliary {
}); });
expression.addContextFunction("enable_hidden_dimensions", 0, (c, t, lv) -> { expression.addContextFunction("enable_hidden_dimensions", 0, (c, t, lv) -> {
return Value.NULL;
/*
CarpetContext cc = (CarpetContext)c; CarpetContext cc = (CarpetContext)c;
// from minecraft.server.Main.main // from minecraft.server.Main.main
MinecraftServer server = cc.s.getServer(); MinecraftServer server = cc.s.getServer();
@@ -1147,6 +1149,8 @@ public class Auxiliary {
} }
} }
return ListValue.wrap(addeds); return ListValue.wrap(addeds);
*/
}); });
} }
@@ -4,6 +4,7 @@ import carpet.fakes.IngredientInterface;
import carpet.fakes.RecipeManagerInterface; import carpet.fakes.RecipeManagerInterface;
import carpet.script.CarpetContext; import carpet.script.CarpetContext;
import carpet.script.Expression; import carpet.script.Expression;
import carpet.script.argument.BlockArgument;
import carpet.script.argument.FunctionArgument; import carpet.script.argument.FunctionArgument;
import carpet.script.exception.InternalExpressionException; import carpet.script.exception.InternalExpressionException;
import carpet.script.exception.ThrowStatement; import carpet.script.exception.ThrowStatement;
@@ -26,15 +27,17 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import net.minecraft.commands.arguments.item.ItemInput; import net.minecraft.commands.arguments.item.ItemInput;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket; import net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.TagContainer; import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
@@ -48,6 +51,7 @@ import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.ShapedRecipe; import net.minecraft.world.item.crafting.ShapedRecipe;
import net.minecraft.world.item.crafting.ShapelessRecipe; import net.minecraft.world.item.crafting.ShapelessRecipe;
import net.minecraft.world.item.crafting.SingleItemRecipe; import net.minecraft.world.item.crafting.SingleItemRecipe;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
public class Inventories { public class Inventories {
@@ -68,16 +72,40 @@ public class Inventories {
if (lv.size() == 0) if (lv.size() == 0)
return ListValue.wrap(Registry.ITEM.keySet().stream().map(ValueConversions::of).collect(Collectors.toList())); return ListValue.wrap(Registry.ITEM.keySet().stream().map(ValueConversions::of).collect(Collectors.toList()));
CarpetContext cc = (CarpetContext)c; CarpetContext cc = (CarpetContext)c;
Registry<Item> items = cc.s.getServer().registryAccess().registryOrThrow(Registry.ITEM_REGISTRY);
String tag = lv.get(0).getString();
Optional<HolderSet.Named<Item>> itemTag = items.getTag(TagKey.create(Registry.ITEM_REGISTRY, InputValidator.identifierOf(tag)));
if (itemTag.isEmpty()) return Value.NULL;
return ListValue.wrap(itemTag.get().stream().map(b -> ValueConversions.of(items.getKey(b.value()))).collect(Collectors.toList()));
/*
TagContainer tagManager = cc.s.getServer(). getTags(); TagContainer tagManager = cc.s.getServer(). getTags();
String tag = lv.get(0).getString(); String tag = lv.get(0).getString();
net.minecraft.tags.Tag<Item> itemTag = tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getTag(InputValidator.identifierOf(tag)); net.minecraft.tags.Tag<Item> itemTag = tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getTag(InputValidator.identifierOf(tag));
if (itemTag == null) return Value.NULL; if (itemTag == null) return Value.NULL;
return ListValue.wrap(itemTag.getValues().stream().map(b -> ValueConversions.of(Registry.ITEM.getKey(b))).collect(Collectors.toList())); return ListValue.wrap(itemTag.getValues().stream().map(b -> ValueConversions.of(Registry.ITEM.getKey(b))).collect(Collectors.toList()));
*/
}); });
expression.addContextFunction("item_tags", -1, (c, t, lv) -> expression.addContextFunction("item_tags", -1, (c, t, lv) ->
{ {
CarpetContext cc = (CarpetContext)c; CarpetContext cc = (CarpetContext)c;
Registry<Item> blocks = cc.s.getServer().registryAccess().registryOrThrow(Registry.ITEM_REGISTRY);
if (lv.size() == 0)
return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of).collect(Collectors.toList()));
Item item = NBTSerializableValue.parseItem(lv.get(0).getString()).getItem();
if (lv.size() == 1)
{
return ListValue.wrap( blocks.getTags().filter(e -> e.getSecond().stream().anyMatch(h -> (h.value() == item))).map(e -> ValueConversions.of(e.getFirst())).collect(Collectors.toList()));
}
String tag = lv.get(1).getString();
Optional<HolderSet.Named<Item>> tagSet = blocks.getTag(TagKey.create(Registry.ITEM_REGISTRY, InputValidator.identifierOf(tag)));
if (tagSet.isEmpty()) return Value.NULL;
//return BooleanValue.of(tagSet.get().contains(item.builtInRegistryHolder()));
return BooleanValue.of(tagSet.get().stream().anyMatch(h -> h.value() == item));
/*
TagContainer tagManager = cc.s.getServer().getTags(); TagContainer tagManager = cc.s.getServer().getTags();
if (lv.size() == 0) if (lv.size() == 0)
return ListValue.wrap(tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getAvailableTags().stream().map(ValueConversions::of).collect(Collectors.toList())); return ListValue.wrap(tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getAvailableTags().stream().map(ValueConversions::of).collect(Collectors.toList()));
@@ -88,6 +116,7 @@ public class Inventories {
net.minecraft.tags.Tag<Item> itemTag = tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getTag(InputValidator.identifierOf(tag)); net.minecraft.tags.Tag<Item> itemTag = tagManager.getOrEmpty(Registry.ITEM_REGISTRY).getTag(InputValidator.identifierOf(tag));
if (itemTag == null) return Value.NULL; if (itemTag == null) return Value.NULL;
return BooleanValue.of(itemTag.contains(item)); return BooleanValue.of(itemTag.contains(item));
*/
}); });
expression.addContextFunction("recipe_data", -1, (c, t, lv) -> expression.addContextFunction("recipe_data", -1, (c, t, lv) ->
@@ -40,6 +40,14 @@ import carpet.utils.BlockInfo;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.LongSet; import it.unimi.dsi.fastutil.longs.LongSet;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.QuartPos;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.TagKey;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
@@ -56,11 +64,8 @@ import java.util.function.BiPredicate;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import net.minecraft.commands.arguments.item.ItemInput; import net.minecraft.commands.arguments.item.ItemInput;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.QuartPos;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
import net.minecraft.network.protocol.game.ClientboundExplodePacket; import net.minecraft.network.protocol.game.ClientboundExplodePacket;
@@ -70,7 +75,6 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.Ticket; import net.minecraft.server.level.Ticket;
import net.minecraft.server.level.TicketType; import net.minecraft.server.level.TicketType;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
import net.minecraft.tags.TagContainer;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.util.SortedArraySet; import net.minecraft.util.SortedArraySet;
import net.minecraft.world.Clearable; import net.minecraft.world.Clearable;
@@ -237,10 +241,10 @@ public class WorldAccess {
private static void BooYah(ChunkGenerator generator) private static void BooYah(ChunkGenerator generator)
{ {
synchronized (generator) //synchronized (generator)
{ //{
((ChunkGeneratorInterface)generator).initStrongholds(); // ((ChunkGeneratorInterface)generator).initStrongholds();
} //}
} }
public static void apply(Expression expression) public static void apply(Expression expression)
@@ -1118,16 +1122,33 @@ public class WorldAccess {
if (lv.size() == 0) if (lv.size() == 0)
return ListValue.wrap(Registry.BLOCK.keySet().stream().map(ValueConversions::of).collect(Collectors.toList())); return ListValue.wrap(Registry.BLOCK.keySet().stream().map(ValueConversions::of).collect(Collectors.toList()));
CarpetContext cc = (CarpetContext)c; CarpetContext cc = (CarpetContext)c;
TagContainer tagManager = cc.s.getServer().getTags(); ResourceLocation tag = InputValidator.identifierOf(lv.get(0).getString());
String tag = lv.get(0).getString();
net.minecraft.tags.Tag<Block> blockTag = tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getTag(InputValidator.identifierOf(tag)); Registry<Block> blocks = cc.s.getServer().registryAccess().registryOrThrow(Registry.BLOCK_REGISTRY);
if (blockTag == null) return Value.NULL; Optional<HolderSet.Named<Block>> tagset = blocks.getTag(TagKey.create(Registry.BLOCK_REGISTRY, tag));
return ListValue.wrap(blockTag.getValues().stream().map(b -> ValueConversions.of(Registry.BLOCK.getKey(b))).collect(Collectors.toList())); if (tagset.isEmpty()) return Value.NULL;
return ListValue.wrap(tagset.get().stream().map(b -> ValueConversions.of(blocks.getKey(b.value()))).collect(Collectors.toList()));
}); });
expression.addContextFunction("block_tags", -1, (c, t, lv) -> expression.addContextFunction("block_tags", -1, (c, t, lv) ->
{ {
CarpetContext cc = (CarpetContext)c; CarpetContext cc = (CarpetContext)c;
Registry<Block> blocks = cc.s.getServer().registryAccess().registryOrThrow(Registry.BLOCK_REGISTRY);
if (lv.size() == 0)
return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of).collect(Collectors.toList()));
BlockArgument blockLocator = BlockArgument.findIn(cc, lv, 0, true);
if (blockLocator.offset == lv.size())
{
Block target = blockLocator.block.getBlockState().getBlock();
return ListValue.wrap( blocks.getTags().filter(e -> e.getSecond().stream().anyMatch(h -> (h.value() == target))).map(e -> ValueConversions.of(e.getFirst())).collect(Collectors.toList()));
}
String tag = lv.get(blockLocator.offset).getString();
Optional<HolderSet.Named<Block>> tagSet = blocks.getTag(TagKey.create(Registry.BLOCK_REGISTRY, InputValidator.identifierOf(tag)));
if (tagSet.isEmpty()) return Value.NULL;
return BooleanValue.of(blockLocator.block.getBlockState().is(tagSet.get()));
/* before
TagContainer tagManager = cc.s.getServer().getTags(); TagContainer tagManager = cc.s.getServer().getTags();
if (lv.size() == 0) if (lv.size() == 0)
return ListValue.wrap(tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getAvailableTags().stream().map(ValueConversions::of).collect(Collectors.toList())); return ListValue.wrap(tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getAvailableTags().stream().map(ValueConversions::of).collect(Collectors.toList()));
@@ -1141,6 +1162,7 @@ public class WorldAccess {
net.minecraft.tags.Tag<Block> blockTag = tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getTag(InputValidator.identifierOf(tag)); net.minecraft.tags.Tag<Block> blockTag = tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getTag(InputValidator.identifierOf(tag));
if (blockTag == null) return Value.NULL; if (blockTag == null) return Value.NULL;
return BooleanValue.of(blockLocator.block.getBlockState().is(blockTag)); return BooleanValue.of(blockLocator.block.getBlockState().is(blockTag));
*/
}); });
expression.addContextFunction("biome", -1, (c, t, lv) -> { expression.addContextFunction("biome", -1, (c, t, lv) -> {
@@ -1181,7 +1203,7 @@ public class WorldAccess {
Climate.quantizeCoord(numberGetOrThrow(depth)), Climate.quantizeCoord(numberGetOrThrow(depth)),
Climate.quantizeCoord(numberGetOrThrow(weirdness)) Climate.quantizeCoord(numberGetOrThrow(weirdness))
); );
biome = mnbs.getNoiseBiome(point); biome = mnbs.getNoiseBiome(point).value();
ResourceLocation biomeId = cc.s.getServer().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getKey(biome); ResourceLocation biomeId = cc.s.getServer().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getKey(biome);
return new StringValue(NBTSerializableValue.nameFromRegistryId(biomeId)); return new StringValue(NBTSerializableValue.nameFromRegistryId(biomeId));
} }
@@ -1196,7 +1218,7 @@ public class WorldAccess {
else else
{ {
BlockPos pos = locator.block.getPos(); BlockPos pos = locator.block.getPos();
biome = world.getBiome(pos); biome = world.getBiome(pos).value();
} }
// in locatebiome // in locatebiome
if (locator.offset == lv.size()) if (locator.offset == lv.size())
@@ -1219,8 +1241,10 @@ public class WorldAccess {
throw new InternalExpressionException("'set_biome' needs a biome name as an argument"); throw new InternalExpressionException("'set_biome' needs a biome name as an argument");
String biomeName = lv.get(locator.offset+0).getString(); String biomeName = lv.get(locator.offset+0).getString();
// from locatebiome command code // from locatebiome command code
Biome biome = cc.s.getServer().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getOptional(InputValidator.identifierOf(biomeName)) Holder<Biome> biome = cc.s.getServer().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getHolder(ResourceKey.create(Registry.BIOME_REGISTRY, InputValidator.identifierOf(biomeName)))
.orElseThrow(() -> new ThrowStatement(biomeName, Throwables.UNKNOWN_BIOME)); .orElseThrow(() -> new ThrowStatement(biomeName, Throwables.UNKNOWN_BIOME));
boolean doImmediateUpdate = true; boolean doImmediateUpdate = true;
if (lv.size() > locator.offset+1) if (lv.size() > locator.offset+1)
{ {
@@ -128,7 +128,7 @@ public abstract class CommandArgument
false false
), ),
new VanillaUnconfigurableArgument( "blockpredicate", BlockPredicateArgument::blockPredicate, new VanillaUnconfigurableArgument( "blockpredicate", BlockPredicateArgument::blockPredicate,
(c, p) -> ValueConversions.ofBlockPredicate(c.getSource().getServer().getTags(), BlockPredicateArgument.getBlockPredicate(c, p)), false (c, p) -> ValueConversions.ofBlockPredicate(c.getSource().getServer().registryAccess(), BlockPredicateArgument.getBlockPredicate(c, p)), false
), ),
new VanillaUnconfigurableArgument("teamcolor", ColorArgument::color, new VanillaUnconfigurableArgument("teamcolor", ColorArgument::color,
(c, p) -> { (c, p) -> {
@@ -8,19 +8,24 @@ import carpet.script.value.StringValue;
import carpet.script.value.Value; import carpet.script.value.Value;
import carpet.script.value.ValueConversions; import carpet.script.value.ValueConversions;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
public class BiomeInfo public class BiomeInfo
{ {
public final static Map<String, BiFunction<ServerLevel, Biome, Value>> biomeFeatures = new HashMap<String, BiFunction<ServerLevel, Biome, Value>>(){{ public final static Map<String, BiFunction<ServerLevel, Biome, Value>> biomeFeatures = new HashMap<String, BiFunction<ServerLevel, Biome, Value>>(){{
//put("top_material", (w, b) -> new BlockValue( b.getGenerationSettings(). getSurfaceConfig().getTopMaterial(), null, null)); //put("top_material", (w, b) -> new BlockValue( b.getGenerationSettings(). getSurfaceConfig().getTopMaterial(), null, null));
//put("under_material", (w, b) -> new BlockValue( b.getGenerationSettings().getSurfaceConfig().getUnderMaterial(), null, null)); //put("under_material", (w, b) -> new BlockValue( b.getGenerationSettings().getSurfaceConfig().getUnderMaterial(), null, null));
put("category", (w, b) -> StringValue.of(b.getBiomeCategory().getName())); put("category", (w, b) -> StringValue.of(Biome.getBiomeCategory(Holder.direct(b)).getName()));
put("temperature", (w, b) -> NumericValue.of(b.getBaseTemperature())); put("temperature", (w, b) -> NumericValue.of(b.getBaseTemperature()));
put("fog_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getFogColor())); put("fog_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getFogColor()));
put("foliage_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getFoliageColorOverride().orElse(4764952))); // client Biome.getDefaultFoliageColor put("foliage_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getFoliageColorOverride().orElse(4764952))); // client Biome.getDefaultFoliageColor
@@ -37,8 +42,8 @@ public class BiomeInfo
return ListValue.wrap( return ListValue.wrap(
b.getGenerationSettings().features().stream().map(step -> b.getGenerationSettings().features().stream().map(step ->
ListValue.wrap(step.stream().map(cfp -> ListValue.wrap(step.stream().map(cfp ->
ValueConversions.of(registry.getKey(((PlacedFeatureInterface)cfp.get()).getRawFeature())) ValueConversions.of(registry.getKey(cfp.value().feature().value())))
)) )
) )
); );
}); });
@@ -5,6 +5,7 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.MappedRegistry; import net.minecraft.core.MappedRegistry;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
@@ -92,15 +93,15 @@ public class WorldTools
long l = generatorOptions.seed(); long l = generatorOptions.seed();
long m = BiomeManager.obfuscateSeed(l); long m = BiomeManager.obfuscateSeed(l);
List<CustomSpawner> list = List.of(); List<CustomSpawner> list = List.of();
MappedRegistry<LevelStem> simpleRegistry = generatorOptions.dimensions(); Registry<LevelStem> simpleRegistry = generatorOptions.dimensions();
LevelStem dimensionOptions = simpleRegistry.get(LevelStem.OVERWORLD); LevelStem dimensionOptions = simpleRegistry.get(LevelStem.OVERWORLD);
ChunkGenerator chunkGenerator2; ChunkGenerator chunkGenerator2;
DimensionType dimensionType2; Holder<DimensionType> dimensionType2;
if (dimensionOptions == null) { if (dimensionOptions == null) {
dimensionType2 = server.registryAccess().ownedRegistryOrThrow(Registry.DIMENSION_TYPE_REGISTRY).getOrThrow(DimensionType.OVERWORLD_LOCATION); dimensionType2 = server.registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY).getOrCreateHolder(DimensionType.OVERWORLD_LOCATION);;
chunkGenerator2 = WorldGenSettings.makeDefaultOverworld(server.registryAccess(), (new Random()).nextLong()); chunkGenerator2 = WorldGenSettings.makeDefaultOverworld(server.registryAccess(), (new Random()).nextLong());
} else { } else {
dimensionType2 = dimensionOptions.type(); dimensionType2 = dimensionOptions.typeHolder();
chunkGenerator2 = dimensionOptions.generator(); chunkGenerator2 = dimensionOptions.generator();
} }
@@ -113,9 +114,9 @@ public class WorldTools
// return server.getRegistryManager().get(Registry.CHUNK_GENERATOR_SETTINGS_KEY).getOrThrow(ChunkGeneratorSettings.OVERWORLD); // return server.getRegistryManager().get(Registry.CHUNK_GENERATOR_SETTINGS_KEY).getOrThrow(ChunkGeneratorSettings.OVERWORLD);
//}); //});
chunkGenerator2 = new NoiseBasedChunkGenerator(server.registryAccess().registryOrThrow(Registry.NOISE_REGISTRY), MultiNoiseBiomeSource.Preset.OVERWORLD.biomeSource(server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY)), seed, () -> { chunkGenerator2 = new NoiseBasedChunkGenerator(server.registryAccess().registryOrThrow(Registry.NOISE_REGISTRY), MultiNoiseBiomeSource.Preset.OVERWORLD.biomeSource(server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY)), seed,
return server.registryAccess().registryOrThrow(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY).getOrThrow(NoiseGeneratorSettings.OVERWORLD); Holder.direct(server.registryAccess().registryOrThrow(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY).getOrThrow(NoiseGeneratorSettings.OVERWORLD))
}); );
ServerLevel serverWorld = new ServerLevel( ServerLevel serverWorld = new ServerLevel(
server, server,
@@ -23,6 +23,8 @@ import net.minecraft.commands.arguments.selector.EntitySelector;
import net.minecraft.commands.arguments.selector.EntitySelectorParser; import net.minecraft.commands.arguments.selector.EntitySelectorParser;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.StringTag; import net.minecraft.nbt.StringTag;
@@ -37,6 +39,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.Tag; import net.minecraft.tags.Tag;
import net.minecraft.tags.TagKey;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffect;
@@ -247,11 +250,15 @@ public class EntityValue extends Value
positive = false; positive = false;
who = who.substring(1); who = who.substring(1);
} }
Tag<EntityType<?>> eTag = server.getTags().getOrEmpty(Registry.ENTITY_TYPE_REGISTRY).getTag(InputValidator.identifierOf(who)); String booWho = who;
if (eTag == null) throw new InternalExpressionException(who+" is not a valid entity descriptor"); HolderSet.Named<EntityType<?>> eTagValue = server.registryAccess().registryOrThrow(Registry.ENTITY_TYPE_REGISTRY)
.getTag(TagKey.create(Registry.ENTITY_TYPE_REGISTRY, InputValidator.identifierOf(who)))
.orElseThrow( () -> new InternalExpressionException(booWho+" is not a valid entity descriptor"));
Set<EntityType<?>> eTag = eTagValue.stream().map(Holder::value).collect(Collectors.toUnmodifiableSet());
//Tag<EntityType<?>> eTag = server.getTags().getOrEmpty(Registry.ENTITY_TYPE_REGISTRY).getTag(InputValidator.identifierOf(who));
if (positive) if (positive)
{ {
return new EntityClassDescriptor(null, e -> eTag.contains(e.getType()) && e.isAlive(), eTag.getValues().stream()); return new EntityClassDescriptor(null, e -> eTag.contains(e.getType()) && e.isAlive(), eTag.stream());
} }
else else
{ {
@@ -450,15 +457,22 @@ public class EntityValue extends Value
put("tags", (e, a) -> ListValue.wrap(e.getTags().stream().map(StringValue::new).collect(Collectors.toList()))); put("tags", (e, a) -> ListValue.wrap(e.getTags().stream().map(StringValue::new).collect(Collectors.toList())));
put("scoreboard_tags", (e, a) -> ListValue.wrap(e.getTags().stream().map(StringValue::new).collect(Collectors.toList()))); put("scoreboard_tags", (e, a) -> ListValue.wrap(e.getTags().stream().map(StringValue::new).collect(Collectors.toList())));
put("entity_tags", (e, a) -> ListValue.wrap(e.getServer().getTags().getOrEmpty(Registry.ENTITY_TYPE_REGISTRY).getAllTags().entrySet().stream().filter(entry -> entry.getValue().contains(e.getType())).map(entry -> ValueConversions.of(entry.getKey())).collect(Collectors.toList()))); put("entity_tags", (e, a) -> {
EntityType<?> type = e.getType();
return ListValue.wrap(e.getServer().registryAccess().registryOrThrow(Registry.ENTITY_TYPE_REGISTRY).getTags().filter(entry -> entry.getSecond().stream().anyMatch(h -> h.value()==type)).map(entry -> ValueConversions.of(entry.getFirst())).collect(Collectors.toList()));
});
// deprecated // deprecated
put("has_tag", (e, a) -> BooleanValue.of(e.getTags().contains(a.getString()))); put("has_tag", (e, a) -> BooleanValue.of(e.getTags().contains(a.getString())));
put("has_scoreboard_tag", (e, a) -> BooleanValue.of(e.getTags().contains(a.getString()))); put("has_scoreboard_tag", (e, a) -> BooleanValue.of(e.getTags().contains(a.getString())));
put("has_entity_tag", (e, a) -> { put("has_entity_tag", (e, a) -> {
Tag<EntityType<?>> tag = e.getServer().getTags().getOrEmpty(Registry.ENTITY_TYPE_REGISTRY).getTag(InputValidator.identifierOf(a.getString())); Optional<HolderSet.Named<EntityType<?>>> tag = e.getServer().registryAccess().registryOrThrow(Registry.ENTITY_TYPE_REGISTRY).getTag(TagKey.create(Registry.ENTITY_TYPE_REGISTRY, InputValidator.identifierOf(a.getString())));
if (tag == null) return Value.NULL; if (tag.isEmpty()) return Value.NULL;
return BooleanValue.of(e.getType().is(tag)); //Tag<EntityType<?>> tag = e.getServer().getTags().getOrEmpty(Registry.ENTITY_TYPE_REGISTRY).getTag(InputValidator.identifierOf(a.getString()));
//if (tag == null) return Value.NULL;
//return BooleanValue.of(e.getType().is(tag));
EntityType<?> type = e.getType();
return BooleanValue.of(tag.get().stream().anyMatch(h -> h.value() == type));
}); });
put("yaw", (e, a)-> new NumericValue(e.getYRot())); put("yaw", (e, a)-> new NumericValue(e.getYRot()));
@@ -9,6 +9,7 @@ import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.GlobalPos; import net.minecraft.core.GlobalPos;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;
import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
@@ -16,7 +17,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ColumnPos; import net.minecraft.server.level.ColumnPos;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.TagContainer; import net.minecraft.tags.TagKey;
import net.minecraft.util.StringRepresentable; import net.minecraft.util.StringRepresentable;
import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
@@ -164,11 +165,13 @@ public class ValueConversions
} }
} }
public static Value of(ResourceKey<Level> dim) public static Value of(ResourceKey<?> dim)
{ {
return of(dim.location()); return of(dim.location());
} }
public static Value of(TagKey<?> tagKey) { return of(tagKey.location()); }
public static Value of(ResourceLocation id) public static Value of(ResourceLocation id)
{ {
if (id == null) // should be Value.NULL if (id == null) // should be Value.NULL
@@ -392,12 +395,12 @@ public class ValueConversions
return ret; return ret;
} }
public static Value ofBlockPredicate(TagContainer tagManager, Predicate<BlockInWorld> blockPredicate) public static Value ofBlockPredicate(RegistryAccess registryAccess, Predicate<BlockInWorld> blockPredicate)
{ {
BlockPredicateInterface predicateData = (BlockPredicateInterface) blockPredicate; BlockPredicateInterface predicateData = (BlockPredicateInterface) blockPredicate;
return ListValue.of( return ListValue.of(
predicateData.getCMBlockState()==null?Value.NULL:of(Registry.BLOCK.getKey(predicateData.getCMBlockState().getBlock())), predicateData.getCMBlockState()==null?Value.NULL:of(Registry.BLOCK.getKey(predicateData.getCMBlockState().getBlock())),
predicateData.getCMBlockTag()==null?Value.NULL:of(tagManager.getOrEmpty(Registry.BLOCK_REGISTRY).getId(predicateData.getCMBlockTag())), predicateData.getCMBlockTagKey()==null?Value.NULL:of(registryAccess.registryOrThrow(Registry.BLOCK_REGISTRY).getTag(predicateData.getCMBlockTagKey()).get().key()),
MapValue.wrap(predicateData.getCMProperties()), MapValue.wrap(predicateData.getCMProperties()),
predicateData.getCMDataTag() == null?Value.NULL:new NBTSerializableValue(predicateData.getCMDataTag()) predicateData.getCMDataTag() == null?Value.NULL:new NBTSerializableValue(predicateData.getCMDataTag())
); );
@@ -5,6 +5,7 @@ import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2LongMap; import it.unimi.dsi.fastutil.objects.Object2LongMap;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.BaseComponent; import net.minecraft.network.chat.BaseComponent;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
@@ -33,12 +34,8 @@ import net.minecraft.world.level.entity.EntityTypeTest;
import net.minecraft.world.level.levelgen.Heightmap; import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.feature.NetherFortressFeature; import net.minecraft.world.level.levelgen.feature.NetherFortressFeature;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable;
import carpet.CarpetSettings;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@@ -426,9 +423,12 @@ public class SpawnReporter
entity.discard(); entity.discard();
} }
// yeeted from SpawnHelper - temporary fix // yeeted from NaturalSpawner - temporary access fix
private static List<MobSpawnSettings.SpawnerData> getSpawnEntries(ServerLevel world, StructureFeatureManager structureAccessor, ChunkGenerator chunkGenerator, MobCategory spawnGroup, BlockPos pos, @Nullable Biome biome) { private static List<MobSpawnSettings.SpawnerData> getSpawnEntries(final ServerLevel level, final StructureFeatureManager structureFeatureManager, final ChunkGenerator generator, final MobCategory mobCategory, final BlockPos pos, final Holder<Biome> biome) {
return NaturalSpawner.isInNetherFortressBounds(pos, world, spawnGroup, structureAccessor) ? NetherFortressFeature.FORTRESS_ENEMIES.unwrap() : chunkGenerator.getMobsAt(biome != null ? biome : world.getBiome(pos), structureAccessor, spawnGroup, pos).unwrap(); if (NaturalSpawner.isInNetherFortressBounds (pos, level, mobCategory, structureFeatureManager)) {
return NetherFortressFeature.FORTRESS_ENEMIES.unwrap();
}
return generator.getMobsAt(biome != null ? biome : level.getBiome(pos), structureFeatureManager, mobCategory, pos).unwrap();
} }
public static List<BaseComponent> report(BlockPos pos, ServerLevel worldIn) public static List<BaseComponent> report(BlockPos pos, ServerLevel worldIn)