1.4.87 for 22w44a

This commit is contained in:
gnembon committed 2022-11-02 22:30:46 +01:00
1 parent c51f59c799
commit 4be362e58b
20 files changed
+236 -185

No files matched your search

+3 -3
View File
@@ -4,12 +4,12 @@ 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=22w43a minecraft_version=22w44a
loader_version=0.14.10 loader_version=0.14.10
fabric_version=0.65.1+1.19.3 fabric_version=0.65.2+1.19.3
# Mod Properties # Mod Properties
mod_version = 1.4.86 mod_version = 1.4.87
maven_group = carpet maven_group = carpet
archives_base_name = fabric-carpet archives_base_name = fabric-carpet
+1 -1
View File
@@ -47,7 +47,7 @@ import static carpet.api.settings.RuleCategory.CLIENT;
@SuppressWarnings({"CanBeFinal", "removal"}) // removal should be removed after migrating rules to the new system @SuppressWarnings({"CanBeFinal", "removal"}) // removal should be removed after migrating rules to the new system
public class CarpetSettings public class CarpetSettings
{ {
public static final String carpetVersion = "1.4.86+v221026"; public static final String carpetVersion = "1.4.87+v221102";
public static final String releaseTarget = "1.19.3"; public static final String releaseTarget = "1.19.3";
public static final Logger LOG = LoggerFactory.getLogger("carpet"); public static final Logger LOG = LoggerFactory.getLogger("carpet");
public static final ThreadLocal<Boolean> skipGenerationChecks = ThreadLocal.withInitial(() -> false); public static final ThreadLocal<Boolean> skipGenerationChecks = ThreadLocal.withInitial(() -> false);
@@ -11,13 +11,16 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.OptionalInt; import java.util.OptionalInt;
import java.util.function.Function;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.HolderSet; import net.minecraft.core.HolderSet;
import net.minecraft.core.QuartPos; import net.minecraft.core.QuartPos;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.data.BuiltinRegistries; import net.minecraft.core.RegistryAccess;
import net.minecraft.data.worldgen.Pools;
import net.minecraft.data.worldgen.ProcessorLists; import net.minecraft.data.worldgen.ProcessorLists;
import net.minecraft.data.worldgen.placement.PlacementUtils; import net.minecraft.data.worldgen.placement.PlacementUtils;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@@ -56,15 +59,16 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraft.world.level.levelgen.structure.StructureStart; import net.minecraft.world.level.levelgen.structure.StructureStart;
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement; import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
import net.minecraft.world.level.levelgen.structure.structures.JigsawStructure; import net.minecraft.world.level.levelgen.structure.structures.JigsawStructure;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorList;
public class FeatureGenerator public class FeatureGenerator
{ {
synchronized public static Boolean plop(String featureName, ServerLevel world, BlockPos pos) synchronized public static Boolean plop(String featureName, ServerLevel world, BlockPos pos)
{ {
Thing custom = featureMap.get(featureName); Function<ServerLevel, Thing> custom = featureMap.get(featureName);
if (custom != null) if (custom != null)
{ {
return custom.plop(world, pos); return custom.apply(world).plop(world, pos);
} }
ResourceLocation id = new ResourceLocation(featureName); ResourceLocation id = new ResourceLocation(featureName);
Structure structure = world.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).get(id); Structure structure = world.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).get(id);
@@ -206,7 +210,7 @@ public class FeatureGenerator
ChunkGeneratorInterface cgi = (ChunkGeneratorInterface) generator; ChunkGeneratorInterface cgi = (ChunkGeneratorInterface) generator;
List<StructurePlacement> structureConfig = cgi.getPlacementsForFeatureCM(world, structure); List<StructurePlacement> structureConfig = cgi.getPlacementsForFeatureCM(world, structure);
ChunkPos chunkPos = new ChunkPos(pos); ChunkPos chunkPos = new ChunkPos(pos);
boolean couldPlace = structureConfig.stream().anyMatch(p -> p.isStructureChunk(generator, seed, world.getSeed(), chunkPos.x, chunkPos.z)); boolean couldPlace = structureConfig.stream().anyMatch(p -> p.isStructureChunk(world.getChunkSource().getGeneratorState(), chunkPos.x, chunkPos.z));
if (!couldPlace) return null; if (!couldPlace) return null;
final HolderSet<Biome> structureBiomes = structure.biomes(); final HolderSet<Biome> structureBiomes = structure.biomes();
@@ -236,101 +240,138 @@ public class FeatureGenerator
return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(block), new StraightTrunkPlacer(i, j, k), BlockStateProvider.simple(block2), new BlobFoliagePlacer(ConstantInt.of(l), ConstantInt.of(0), 3), new TwoLayersFeatureSize(1, 0, 1)); return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(block), new StraightTrunkPlacer(i, j, k), BlockStateProvider.simple(block2), new BlobFoliagePlacer(ConstantInt.of(l), ConstantInt.of(0), 3), new TwoLayersFeatureSize(1, 0, 1));
} }
public static final Map<String, Thing> featureMap = new HashMap<>() {{ public static final Map<String, Function<ServerLevel, Thing>> featureMap = new HashMap<>() {{
put("oak_bees", simpleTree( createTree(Blocks.OAK_LOG, Blocks.OAK_LEAVES, 4, 2, 0, 2).ignoreVines().decorators(List.of(new BeehiveDecorator(1.00F))).build())); put("oak_bees", l -> simpleTree( createTree(Blocks.OAK_LOG, Blocks.OAK_LEAVES, 4, 2, 0, 2).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("fancy_oak_bees", l -> 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", l -> 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, FeatureConfiguration.NONE)); put("coral_tree", l -> simplePlop(Feature.CORAL_TREE, FeatureConfiguration.NONE));
put("coral_claw", simplePlop(Feature.CORAL_CLAW, FeatureConfiguration.NONE)); put("coral_claw", l -> simplePlop(Feature.CORAL_CLAW, FeatureConfiguration.NONE));
put("coral_mushroom", simplePlop(Feature.CORAL_MUSHROOM, FeatureConfiguration.NONE)); put("coral_mushroom", l -> simplePlop(Feature.CORAL_MUSHROOM, FeatureConfiguration.NONE));
put("coral", simplePlop(Feature.SIMPLE_RANDOM_SELECTOR, new SimpleRandomFeatureConfiguration(HolderSet.direct( put("coral", l -> simplePlop(Feature.SIMPLE_RANDOM_SELECTOR, new SimpleRandomFeatureConfiguration(HolderSet.direct(
PlacementUtils.inlinePlaced(Feature.CORAL_TREE, FeatureConfiguration.NONE), PlacementUtils.inlinePlaced(Feature.CORAL_TREE, FeatureConfiguration.NONE),
PlacementUtils.inlinePlaced(Feature.CORAL_CLAW, FeatureConfiguration.NONE), PlacementUtils.inlinePlaced(Feature.CORAL_CLAW, FeatureConfiguration.NONE),
PlacementUtils.inlinePlaced(Feature.CORAL_MUSHROOM, FeatureConfiguration.NONE) PlacementUtils.inlinePlaced(Feature.CORAL_MUSHROOM, FeatureConfiguration.NONE)
)))); ))));
put("bastion_remnant_units", spawnCustomStructure( put("bastion_remnant_units", l -> {
new JigsawStructure( new Structure.StructureSettings( RegistryAccess regs = l.registryAccess();
BuiltinRegistries.BIOME.getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
Map.of(), final HolderGetter<StructureProcessorList> processorLists = regs.lookupOrThrow(Registry.PROCESSOR_LIST_REGISTRY);
GenerationStep.Decoration.SURFACE_STRUCTURES, final Holder<StructureProcessorList> bastionGenericDegradation = processorLists.getOrThrow(ProcessorLists.BASTION_GENERIC_DEGRADATION);
TerrainAdjustment.NONE
), final HolderGetter<StructureTemplatePool> pools = regs.lookupOrThrow(Registry.TEMPLATE_POOL_REGISTRY);
Holder.direct(new StructureTemplatePool( final Holder<StructureTemplatePool> empty = pools.getOrThrow(Pools.EMPTY);
new ResourceLocation("bastion/starts"),
new ResourceLocation("empty"),
ImmutableList.of( return spawnCustomStructure(
Pair.of(StructurePoolElement.single("bastion/units/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1) new JigsawStructure(new Structure.StructureSettings(
), l.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
StructureTemplatePool.Projection.RIGID Map.of(),
)), GenerationStep.Decoration.SURFACE_STRUCTURES,
6, TerrainAdjustment.NONE
ConstantHeight.of(VerticalAnchor.absolute(33)), ),
false Holder.direct(new StructureTemplatePool(
) empty,
)); ImmutableList.of(
put("bastion_remnant_hoglin_stable", spawnCustomStructure( Pair.of(StructurePoolElement.single("bastion/units/air_base", bastionGenericDegradation), 1)
new JigsawStructure( new Structure.StructureSettings( ),
BuiltinRegistries.BIOME.getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT), StructureTemplatePool.Projection.RIGID
Map.of(), )),
GenerationStep.Decoration.SURFACE_STRUCTURES, 6,
TerrainAdjustment.NONE ConstantHeight.of(VerticalAnchor.absolute(33)),
), false
Holder.direct(new StructureTemplatePool( )
new ResourceLocation("bastion/starts"), );
new ResourceLocation("empty"), });
ImmutableList.of( put("bastion_remnant_hoglin_stable", l -> {
Pair.of(StructurePoolElement.single("bastion/hoglin_stable/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1) RegistryAccess regs = l.registryAccess();
),
StructureTemplatePool.Projection.RIGID final HolderGetter<StructureProcessorList> processorLists = regs.lookupOrThrow(Registry.PROCESSOR_LIST_REGISTRY);
)), final Holder<StructureProcessorList> bastionGenericDegradation = processorLists.getOrThrow(ProcessorLists.BASTION_GENERIC_DEGRADATION);
6,
ConstantHeight.of(VerticalAnchor.absolute(33)), final HolderGetter<StructureTemplatePool> pools = regs.lookupOrThrow(Registry.TEMPLATE_POOL_REGISTRY);
false final Holder<StructureTemplatePool> empty = pools.getOrThrow(Pools.EMPTY);
)
)); return spawnCustomStructure(
put("bastion_remnant_treasure", spawnCustomStructure( new JigsawStructure(new Structure.StructureSettings(
new JigsawStructure( new Structure.StructureSettings( l.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
BuiltinRegistries.BIOME.getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT), Map.of(),
Map.of(), GenerationStep.Decoration.SURFACE_STRUCTURES,
GenerationStep.Decoration.SURFACE_STRUCTURES, TerrainAdjustment.NONE
TerrainAdjustment.NONE ),
), Holder.direct(new StructureTemplatePool(
Holder.direct(new StructureTemplatePool( empty,
new ResourceLocation("bastion/starts"), ImmutableList.of(
new ResourceLocation("empty"), Pair.of(StructurePoolElement.single("bastion/hoglin_stable/air_base", bastionGenericDegradation), 1)
ImmutableList.of( ),
Pair.of(StructurePoolElement.single("bastion/treasure/big_air_full", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1) StructureTemplatePool.Projection.RIGID
), )),
StructureTemplatePool.Projection.RIGID 6,
)), ConstantHeight.of(VerticalAnchor.absolute(33)),
6, false
ConstantHeight.of(VerticalAnchor.absolute(33)), )
false );
) });
)); put("bastion_remnant_treasure", l -> {
put("bastion_remnant_bridge", spawnCustomStructure( RegistryAccess regs = l.registryAccess();
new JigsawStructure( new Structure.StructureSettings(
BuiltinRegistries.BIOME.getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT), final HolderGetter<StructureProcessorList> processorLists = regs.lookupOrThrow(Registry.PROCESSOR_LIST_REGISTRY);
Map.of(), final Holder<StructureProcessorList> bastionGenericDegradation = processorLists.getOrThrow(ProcessorLists.BASTION_GENERIC_DEGRADATION);
GenerationStep.Decoration.SURFACE_STRUCTURES,
TerrainAdjustment.NONE final HolderGetter<StructureTemplatePool> pools = regs.lookupOrThrow(Registry.TEMPLATE_POOL_REGISTRY);
), final Holder<StructureTemplatePool> empty = pools.getOrThrow(Pools.EMPTY);
Holder.direct(new StructureTemplatePool(
new ResourceLocation("bastion/starts"), return spawnCustomStructure(
new ResourceLocation("empty"), new JigsawStructure(new Structure.StructureSettings(
ImmutableList.of( l.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
Pair.of(StructurePoolElement.single("bastion/bridge/starting_pieces/entrance_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1) Map.of(),
), GenerationStep.Decoration.SURFACE_STRUCTURES,
StructureTemplatePool.Projection.RIGID TerrainAdjustment.NONE
)), ),
6, Holder.direct(new StructureTemplatePool(
ConstantHeight.of(VerticalAnchor.absolute(33)), empty,
false ImmutableList.of(
) Pair.of(StructurePoolElement.single("bastion/treasure/big_air_full", bastionGenericDegradation), 1)
)); ),
StructureTemplatePool.Projection.RIGID
)),
6,
ConstantHeight.of(VerticalAnchor.absolute(33)),
false
)
);
});
put("bastion_remnant_bridge", l -> {
RegistryAccess regs = l.registryAccess();
final HolderGetter<StructureProcessorList> processorLists = regs.lookupOrThrow(Registry.PROCESSOR_LIST_REGISTRY);
final Holder<StructureProcessorList> bastionGenericDegradation = processorLists.getOrThrow(ProcessorLists.BASTION_GENERIC_DEGRADATION);
final HolderGetter<StructureTemplatePool> pools = regs.lookupOrThrow(Registry.TEMPLATE_POOL_REGISTRY);
final Holder<StructureTemplatePool> empty = pools.getOrThrow(Pools.EMPTY);
return spawnCustomStructure(
new JigsawStructure(new Structure.StructureSettings(
l.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
Map.of(),
GenerationStep.Decoration.SURFACE_STRUCTURES,
TerrainAdjustment.NONE
),
Holder.direct(new StructureTemplatePool(
empty,
ImmutableList.of(
Pair.of(StructurePoolElement.single("bastion/bridge/starting_pieces/entrance_base", bastionGenericDegradation), 1)
),
StructureTemplatePool.Projection.RIGID
)),
6,
ConstantHeight.of(VerticalAnchor.absolute(33)),
false
)
);
});
}}; }};
@@ -208,7 +208,7 @@ public class OptimizedExplosion
EXPLOSION_OUTCOME.onExplosion((ServerLevel) world, eAccess.getSource(), e::getIndirectSourceEntity, eAccess.getX(), eAccess.getY(), eAccess.getZ(), eAccess.getRadius(), eAccess.isFire(), e.getToBlow(), entityList, eAccess.getBlockInteraction()); EXPLOSION_OUTCOME.onExplosion((ServerLevel) world, eAccess.getSource(), e::getIndirectSourceEntity, eAccess.getX(), eAccess.getY(), eAccess.getZ(), eAccess.getRadius(), eAccess.isFire(), e.getToBlow(), entityList, eAccess.getBlockInteraction());
} }
boolean damagesTerrain = eAccess.getBlockInteraction() != Explosion.BlockInteraction.NONE; boolean damagesTerrain = eAccess.getBlockInteraction() != Explosion.BlockInteraction.KEEP;
// explosionSound incremented till disabling the explosion particles and sound // explosionSound incremented till disabling the explosion particles and sound
if (explosionSound < 100 || explosionSound % 100 == 0) if (explosionSound < 100 || explosionSound % 100 == 0)
@@ -16,30 +16,30 @@ public class ParticleDisplay
{ {
private static Map<String, ParticleOptions> particleCache = new HashMap<>(); private static Map<String, ParticleOptions> particleCache = new HashMap<>();
private static ParticleOptions parseParticle(String name) private static ParticleOptions parseParticle(String name, ServerLevel level) // [SCARY SHIT] persistent caches over server reloads
{ {
try try
{ {
return ParticleArgument.readParticle(new StringReader(name), HolderLookup.forRegistry(Registry.PARTICLE_TYPE)); return ParticleArgument.readParticle(new StringReader(name), level.holderLookup(Registry.PARTICLE_TYPE_REGISTRY));
} }
catch (CommandSyntaxException e) catch (CommandSyntaxException e)
{ {
throw new RuntimeException("No such particle: "+name); throw new RuntimeException("No such particle: "+name);
} }
} }
public static ParticleOptions getEffect(String name) public static ParticleOptions getEffect(String name, ServerLevel level)
{ {
if (name == null) return null; if (name == null) return null;
ParticleOptions res = particleCache.get(name); ParticleOptions res = particleCache.get(name);
if (res != null) return res; if (res != null) return res;
particleCache.put(name, parseParticle(name)); particleCache.put(name, parseParticle(name, level));
return particleCache.get(name); return particleCache.get(name);
} }
public static void drawParticleLine(ServerPlayer player, Vec3 from, Vec3 to, String main, String accent, int count, double spread) public static void drawParticleLine(ServerPlayer player, Vec3 from, Vec3 to, String main, String accent, int count, double spread)
{ {
ParticleOptions accentParticle = getEffect(accent); ParticleOptions accentParticle = getEffect(accent, player.getLevel());
ParticleOptions mainParticle = getEffect(main); ParticleOptions mainParticle = getEffect(main, player.getLevel());
if (accentParticle != null) ((ServerLevel)player.level).sendParticles( if (accentParticle != null) ((ServerLevel)player.level).sendParticles(
player, player,
@@ -4,30 +4,23 @@ import carpet.fakes.ChunkGeneratorInterface;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.RandomState;
import net.minecraft.world.level.levelgen.structure.Structure; import net.minecraft.world.level.levelgen.structure.Structure;
import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement; import net.minecraft.world.level.levelgen.structure.placement.StructurePlacement;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.List; import java.util.List;
@Mixin(ChunkGenerator.class) @Mixin(ChunkGenerator.class)
public abstract class ChunkGenerator_scarpetMixin implements ChunkGeneratorInterface public abstract class ChunkGenerator_scarpetMixin implements ChunkGeneratorInterface
{ {
@Shadow public abstract void ensureStructuresGenerated(RandomState randomState);
@Shadow protected abstract List<StructurePlacement> getPlacementsForStructure(Holder<Structure> holder, RandomState randomState);
@Override @Override
public void initStrongholds(final ServerLevel level) public void initStrongholds(final ServerLevel level)
{ {
ensureStructuresGenerated(level.getChunkSource().randomState()); level.getChunkSource().getGeneratorState().ensureStructuresGenerated();
} }
@Override @Override
public List<StructurePlacement> getPlacementsForFeatureCM(final ServerLevel level, Structure structure) { public List<StructurePlacement> getPlacementsForFeatureCM(final ServerLevel level, Structure structure) {
return getPlacementsForStructure(Holder.direct(structure), level.getChunkSource().randomState()); return level.getChunkSource().getGeneratorState().getPlacementsForStructure(Holder.direct(structure));
} }
} }
@@ -9,14 +9,13 @@ import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.FlatLevelSource; import net.minecraft.world.level.levelgen.FlatLevelSource;
import java.util.Optional; @Mixin(FlatLevelSource.class) // YEET
@Mixin(FlatLevelSource.class)
public abstract class FlatLevelSource_structuresMixin extends ChunkGenerator public abstract class FlatLevelSource_structuresMixin extends ChunkGenerator
{ {
public FlatLevelSource_structuresMixin(Registry<StructureSet> registry, Optional<HolderSet<StructureSet>> optional, BiomeSource biomeSource) { public FlatLevelSource_structuresMixin(BiomeSource biomeSource) {
super(registry, optional, biomeSource); super(biomeSource);
} }
/* /*
@Override @Override
public WeightedRandomList<MobSpawnSettings.SpawnerData> getMobsAt(Holder<Biome> biome, StructureFeatureManager accessor, MobCategory group, BlockPos pos) public WeightedRandomList<MobSpawnSettings.SpawnerData> getMobsAt(Holder<Biome> biome, StructureFeatureManager accessor, MobCategory group, BlockPos pos)
@@ -79,7 +79,7 @@ public abstract class PrimedTntMixin extends Entity implements TntEntityInterfac
this.level.explode(this, this.getX(), this.getY() + (double)(this.getBbHeight() / 16.0F), this.level.explode(this, this.getX(), this.getY() + (double)(this.getBbHeight() / 16.0F),
this.getZ(), this.getZ(),
4.0F, 4.0F,
Explosion.BlockInteraction.BREAK); Level.ExplosionInteraction.TNT);
} }
@Inject(method = "tick", at = @At(value = "INVOKE", @Inject(method = "tick", at = @At(value = "INVOKE",
@@ -2,6 +2,8 @@ package carpet.mixins;
import carpet.fakes.ServerWorldInterface; import carpet.fakes.ServerWorldInterface;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.profiling.ProfilerFiller; import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.DifficultyInstance; import net.minecraft.world.DifficultyInstance;
@@ -11,10 +13,14 @@ import net.minecraft.world.entity.LightningBolt;
import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.ExplosionDamageCalculator; import net.minecraft.world.level.ExplosionDamageCalculator;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.entity.LevelEntityGetter; import net.minecraft.world.level.entity.LevelEntityGetter;
import net.minecraft.world.level.entity.PersistentEntitySectionManager; import net.minecraft.world.level.entity.PersistentEntitySectionManager;
import net.minecraft.world.level.storage.ServerLevelData; import net.minecraft.world.level.storage.ServerLevelData;
import net.minecraft.world.level.storage.WritableLevelData;
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;
@@ -24,14 +30,20 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.function.Supplier;
import static carpet.script.CarpetEventServer.Event.EXPLOSION; import static carpet.script.CarpetEventServer.Event.EXPLOSION;
import static carpet.script.CarpetEventServer.Event.LIGHTNING; import static carpet.script.CarpetEventServer.Event.LIGHTNING;
import static carpet.script.CarpetEventServer.Event.CHUNK_UNLOADED; import static carpet.script.CarpetEventServer.Event.CHUNK_UNLOADED;
@Mixin(ServerLevel.class) @Mixin(ServerLevel.class)
public class ServerLevel_scarpetMixin implements ServerWorldInterface public abstract class ServerLevel_scarpetMixin extends Level implements ServerWorldInterface
{ {
protected ServerLevel_scarpetMixin(WritableLevelData writableLevelData, ResourceKey<Level> resourceKey, Holder<DimensionType> holder, Supplier<ProfilerFiller> supplier, boolean bl, boolean bl2, long l, int i) {
super(writableLevelData, resourceKey, holder, supplier, bl, bl2, l, i);
}
@Inject(method = "tickChunk", locals = LocalCapture.CAPTURE_FAILHARD, at = @At( @Inject(method = "tickChunk", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(
value = "INVOKE", value = "INVOKE",
target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z", target = "Lnet/minecraft/server/level/ServerLevel;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z",
@@ -45,11 +57,24 @@ public class ServerLevel_scarpetMixin implements ServerWorldInterface
if (LIGHTNING.isNeeded()) LIGHTNING.onWorldEventFlag((ServerLevel) (Object)this, blockPos, bl2?1:0); if (LIGHTNING.isNeeded()) LIGHTNING.onWorldEventFlag((ServerLevel) (Object)this, blockPos, bl2?1:0);
} }
private Explosion.BlockInteraction getCMDestroyType(final GameRules.Key<GameRules.BooleanValue> rule) {
return getGameRules().getBoolean(rule) ? Explosion.BlockInteraction.DESTROY_WITH_DECAY : Explosion.BlockInteraction.DESTROY;
}
@Inject(method = "explode", at = @At("HEAD")) @Inject(method = "explode", at = @At("HEAD"))
private void handleExplosion(/*@Nullable*/ Entity entity, /*@Nullable*/ DamageSource damageSource, /*@Nullable*/ ExplosionDamageCalculator explosionBehavior, double d, double e, double f, float g, boolean bl, Explosion.BlockInteraction destructionType, CallbackInfoReturnable<Explosion> cir) private void handleExplosion(/*@Nullable*/ Entity entity, /*@Nullable*/ DamageSource damageSource, /*@Nullable*/ ExplosionDamageCalculator explosionBehavior, double d, double e, double f, float g, boolean bl, Level.ExplosionInteraction explosionInteraction, CallbackInfoReturnable<Explosion> cir)
{ {
if (EXPLOSION.isNeeded()) if (EXPLOSION.isNeeded()) {
EXPLOSION.onExplosion((ServerLevel) (Object)this, entity, null, d, e, f, g, bl, null, null, destructionType); Explosion.BlockInteraction var10000 = switch (explosionInteraction) {
case NONE -> Explosion.BlockInteraction.KEEP;
case BLOCK -> this.getCMDestroyType(GameRules.RULE_BLOCK_EXPLOSION_DROP_DECAY);
case MOB -> this.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) ? this.getCMDestroyType(GameRules.RULE_MOB_EXPLOSION_DROP_DECAY) : Explosion.BlockInteraction.KEEP;
case TNT -> this.getCMDestroyType(GameRules.RULE_TNT_EXPLOSION_DROP_DECAY);
default -> throw new IncompatibleClassChangeError();
};
EXPLOSION.onExplosion((ServerLevel) (Object) this, entity, null, d, e, f, g, bl, null, null, var10000);
}
} }
@Inject(method = "unload", at = @At("HEAD")) @Inject(method = "unload", at = @At("HEAD"))
@@ -200,7 +200,7 @@ public class Auxiliary {
} }
} }
} }
ParticleOptions particle = ShapeDispatcher.getParticleData(particleName); ParticleOptions particle = ShapeDispatcher.getParticleData(particleName, world.registryAccess());
Vec3 vec = locator.vec; Vec3 vec = locator.vec;
if (player == null) if (player == null)
{ {
@@ -225,7 +225,7 @@ public class Auxiliary {
CarpetContext cc = (CarpetContext)c; CarpetContext cc = (CarpetContext)c;
ServerLevel world = cc.s.getLevel(); ServerLevel world = cc.s.getLevel();
String particleName = lv.get(0).getString(); String particleName = lv.get(0).getString();
ParticleOptions particle = ShapeDispatcher.getParticleData(particleName); ParticleOptions particle = ShapeDispatcher.getParticleData(particleName, world.registryAccess());
Vector3Argument pos1 = Vector3Argument.findIn(lv, 1); Vector3Argument pos1 = Vector3Argument.findIn(lv, 1);
Vector3Argument pos2 = Vector3Argument.findIn(lv, pos1.offset); Vector3Argument pos2 = Vector3Argument.findIn(lv, pos1.offset);
double density = 1.0; double density = 1.0;
@@ -259,14 +259,14 @@ public class Auxiliary {
)); ));
}); });
expression.addUnaryFunction("item_display_name", v -> new FormattedTextValue(ValueConversions.getItemStackFromValue(v, false).getHoverName())); expression.addContextFunction("item_display_name", 1, (c, t, lv) -> new FormattedTextValue(ValueConversions.getItemStackFromValue(lv.get(0), false, ((CarpetContext)c).s.registryAccess() ).getHoverName()));
expression.addContextFunction("particle_box", -1, (c, t, lv) -> expression.addContextFunction("particle_box", -1, (c, t, lv) ->
{ {
CarpetContext cc = (CarpetContext)c; CarpetContext cc = (CarpetContext)c;
ServerLevel world = cc.s.getLevel(); ServerLevel world = cc.s.getLevel();
String particleName = lv.get(0).getString(); String particleName = lv.get(0).getString();
ParticleOptions particle = ShapeDispatcher.getParticleData(particleName); ParticleOptions particle = ShapeDispatcher.getParticleData(particleName, world.registryAccess() );
Vector3Argument pos1 = Vector3Argument.findIn(lv, 1); Vector3Argument pos1 = Vector3Argument.findIn(lv, 1);
Vector3Argument pos2 = Vector3Argument.findIn(lv, pos1.offset); Vector3Argument pos2 = Vector3Argument.findIn(lv, pos1.offset);
@@ -4,7 +4,6 @@ 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;
@@ -40,7 +39,6 @@ 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;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.AbstractCookingRecipe; import net.minecraft.world.item.crafting.AbstractCookingRecipe;
@@ -50,14 +48,13 @@ 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 {
public static void apply(Expression expression) public static void apply(Expression expression)
{ {
expression.addUnaryFunction("stack_limit", v -> expression.addContextFunction("stack_limit", 1, (c, t, lv) ->
new NumericValue(NBTSerializableValue.parseItem(v.getString()).getItem().getMaxStackSize())); new NumericValue(NBTSerializableValue.parseItem(lv.get(0).getString(), ((CarpetContext) c).s.registryAccess() ).getItem().getMaxStackSize()));
expression.addContextFunction("item_category", -1, (c, t, lv) -> { expression.addContextFunction("item_category", -1, (c, t, lv) -> {
CarpetContext cc = (CarpetContext)c; CarpetContext cc = (CarpetContext)c;
@@ -91,7 +88,7 @@ public class Inventories {
Registry<Item> blocks = cc.s.getServer().registryAccess().registryOrThrow(Registry.ITEM_REGISTRY); Registry<Item> blocks = cc.s.getServer().registryAccess().registryOrThrow(Registry.ITEM_REGISTRY);
if (lv.size() == 0) if (lv.size() == 0)
return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of).collect(Collectors.toList())); return ListValue.wrap(blocks.getTagNames().map(ValueConversions::of).collect(Collectors.toList()));
Item item = NBTSerializableValue.parseItem(lv.get(0).getString()).getItem(); Item item = NBTSerializableValue.parseItem(lv.get(0).getString(), cc.s.registryAccess()).getItem();
if (lv.size() == 1) 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())); return ListValue.wrap( blocks.getTags().filter(e -> e.getSecond().stream().anyMatch(h -> (h.value() == item))).map(e -> ValueConversions.of(e.getFirst())).collect(Collectors.toList()));
@@ -280,7 +277,7 @@ public class Inventories {
else else
nbt = new NBTSerializableValue(nbtValue.getString()).getCompoundTag(); nbt = new NBTSerializableValue(nbtValue.getString()).getCompoundTag();
} }
ItemInput newitem = NBTSerializableValue.parseItem(lv.get(inventoryLocator.offset()+2).getString(), nbt); ItemInput newitem = NBTSerializableValue.parseItem(lv.get(inventoryLocator.offset()+2).getString(), nbt, cc.s.registryAccess());
ItemStack previousStack = inventoryLocator.inventory().getItem(slot); ItemStack previousStack = inventoryLocator.inventory().getItem(slot);
try try
{ {
@@ -305,7 +302,7 @@ public class Inventories {
{ {
Value secondArg = lv.get(inventoryLocator.offset()+0); Value secondArg = lv.get(inventoryLocator.offset()+0);
if (!secondArg.isNull()) if (!secondArg.isNull())
itemArg = NBTSerializableValue.parseItem(secondArg.getString()); itemArg = NBTSerializableValue.parseItem(secondArg.getString(), cc.s.registryAccess());
} }
int startIndex = 0; int startIndex = 0;
if (lv.size() > inventoryLocator.offset()+1) if (lv.size() > inventoryLocator.offset()+1)
@@ -330,7 +327,7 @@ public class Inventories {
if (inventoryLocator == null) return Value.NULL; if (inventoryLocator == null) return Value.NULL;
if (lv.size() <= inventoryLocator.offset()) if (lv.size() <= inventoryLocator.offset())
throw new InternalExpressionException("'inventory_remove' requires at least an item to be removed"); throw new InternalExpressionException("'inventory_remove' requires at least an item to be removed");
ItemInput searchItem = NBTSerializableValue.parseItem(lv.get(inventoryLocator.offset()).getString()); ItemInput searchItem = NBTSerializableValue.parseItem(lv.get(inventoryLocator.offset()).getString(), cc.s.registryAccess());
int amount = 1; int amount = 1;
if (lv.size() > inventoryLocator.offset()+1) if (lv.size() > inventoryLocator.offset()+1)
amount = (int)NumericValue.asNumber(lv.get(inventoryLocator.offset()+1)).getLong(); amount = (int)NumericValue.asNumber(lv.get(inventoryLocator.offset()+1)).getLong();
@@ -34,7 +34,6 @@ 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 carpet.utils.BlockInfo; import carpet.utils.BlockInfo;
import carpet.utils.CommandHelper;
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;
@@ -926,7 +925,7 @@ public class WorldAccess {
throw new InternalExpressionException("'create_explosion' requires at least a position to explode"); throw new InternalExpressionException("'create_explosion' requires at least a position to explode");
CarpetContext cc = (CarpetContext)c; CarpetContext cc = (CarpetContext)c;
float powah = 4.0f; float powah = 4.0f;
Explosion.BlockInteraction mode = Explosion.BlockInteraction.BREAK; Explosion.BlockInteraction mode = Explosion.BlockInteraction.DESTROY; // should probably read the gamerule for default behaviour
boolean createFire = false; boolean createFire = false;
Entity source = null; Entity source = null;
LivingEntity attacker = null; LivingEntity attacker = null;
@@ -994,7 +993,7 @@ public class WorldAccess {
}; };
explosion.explode(); explosion.explode();
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);
if (mode == Explosion.BlockInteraction.NONE) explosion.clearToBlow(); if (mode == Explosion.BlockInteraction.KEEP) explosion.clearToBlow();
cc.s.getLevel().players().forEach(spe -> { cc.s.getLevel().players().forEach(spe -> {
if (spe.distanceToSqr(pos) < 4096.0D) if (spe.distanceToSqr(pos) < 4096.0D)
spe.connection.send(new ClientboundExplodePacket(pos.x, pos.y, pos.z, thePowah, explosion.getToBlow(), explosion.getHitPlayers().get(spe))); spe.connection.send(new ClientboundExplodePacket(pos.x, pos.y, pos.z, thePowah, explosion.getToBlow(), explosion.getHitPlayers().get(spe)));
@@ -1010,7 +1009,7 @@ public class WorldAccess {
CarpetContext cc = (CarpetContext) c; CarpetContext cc = (CarpetContext) c;
String itemString = lv.get(0).getString(); String itemString = lv.get(0).getString();
Vector3Argument locator = Vector3Argument.findIn(lv, 1); Vector3Argument locator = Vector3Argument.findIn(lv, 1);
ItemInput stackArg = NBTSerializableValue.parseItem(itemString); ItemInput stackArg = NBTSerializableValue.parseItem(itemString, cc.s.registryAccess());
BlockPos where = new BlockPos(locator.vec); BlockPos where = new BlockPos(locator.vec);
String facing; String facing;
if (lv.size() > locator.offset) { if (lv.size() > locator.offset) {
@@ -60,7 +60,7 @@ public class BlockArgument extends Argument
} }
if (acceptString && v1 instanceof StringValue) if (acceptString && v1 instanceof StringValue)
{ {
return new BlockArgument(BlockValue.fromString(v1.getString()), 1 + offset); return new BlockArgument(BlockValue.fromString(v1.getString(), c.s.registryAccess()), 1 + offset);
} }
if (v1 instanceof BlockValue) if (v1 instanceof BlockValue)
{ {
@@ -1061,8 +1061,7 @@ public abstract class CommandArgument
super(suffix, null, suggestFromExamples); super(suffix, null, suggestFromExamples);
try try
{ {
final CommandBuildContext context = new CommandBuildContext(server.registryAccess(), server.getWorldData().enabledFeatures()); final CommandBuildContext context = CommandBuildContext.simple(server.registryAccess(), server.getWorldData().enabledFeatures());
context.missingTagAccessPolicy(CommandBuildContext.MissingTagAccessPolicy.RETURN_EMPTY);
this.examples = argumentTypeSupplier.get(context).getExamples(); this.examples = argumentTypeSupplier.get(context).getExamples();
} }
catch (CommandSyntaxException e) catch (CommandSyntaxException e)
@@ -1122,7 +1121,7 @@ public abstract class CommandArgument
protected ArgumentType<?> getArgumentType(CarpetScriptHost host) throws CommandSyntaxException protected ArgumentType<?> getArgumentType(CarpetScriptHost host) throws CommandSyntaxException
{ {
if (argumentTypeSupplier != null) return argumentTypeSupplier.get(); if (argumentTypeSupplier != null) return argumentTypeSupplier.get();
CommandBuildContext registryAccess = new CommandBuildContext(host.scriptServer().server.registryAccess(), host.scriptServer().server.getWorldData().enabledFeatures()); CommandBuildContext registryAccess = CommandBuildContext.simple(host.scriptServer().server.registryAccess(), host.scriptServer().server.getWorldData().enabledFeatures());
return argumentTypeSupplierEx.get(registryAccess); return argumentTypeSupplierEx.get(registryAccess);
} }
@@ -29,8 +29,8 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.commands.arguments.ParticleArgument; import net.minecraft.commands.arguments.ParticleArgument;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.particles.ParticleOptions; import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.nbt.ByteTag; import net.minecraft.nbt.ByteTag;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@@ -172,14 +172,14 @@ public class ShapeDispatcher
} }
} }
public static ParticleOptions getParticleData(String name) public static ParticleOptions getParticleData(String name, RegistryAccess regs)
{ {
ParticleOptions particle = particleCache.get(name); ParticleOptions particle = particleCache.get(name); // [SCARY SHIT] cache should be cleared between worlds
if (particle != null) if (particle != null)
return particle; return particle;
try try
{ {
particle = ParticleArgument.readParticle(new StringReader(name), HolderLookup.forRegistry(Registry.PARTICLE_TYPE)); particle = ParticleArgument.readParticle(new StringReader(name), regs.lookupOrThrow(Registry.PARTICLE_TYPE_REGISTRY));
} }
catch (CommandSyntaxException e) catch (CommandSyntaxException e)
{ {
@@ -388,12 +388,12 @@ public class ShapeDispatcher
NumericValue.asNumber( elements.get(2)).getDouble() NumericValue.asNumber( elements.get(2)).getDouble()
); );
} }
protected ParticleOptions replacementParticle() protected ParticleOptions replacementParticle(RegistryAccess regs)
{ {
String particleName = fa ==0 ? String particleName = fa ==0 ?
String.format(Locale.ROOT , "dust %.1f %.1f %.1f 1.0", r, g, b): String.format(Locale.ROOT , "dust %.1f %.1f %.1f 1.0", r, g, b):
String.format(Locale.ROOT , "dust %.1f %.1f %.1f 1.0", fr, fg, fb); String.format(Locale.ROOT , "dust %.1f %.1f %.1f 1.0", fr, fg, fb);
return getParticleData(particleName); return getParticleData(particleName, regs);
} }
@@ -645,19 +645,18 @@ public class ShapeDispatcher
@Override @Override
public Consumer<ServerPlayer> alternative() { public Consumer<ServerPlayer> alternative() {
ParticleOptions particle;
if(this.isitem)
{
if (Block.byItem(this.item.getItem()).defaultBlockState().isAir()) return p->{};
particle = getParticleData("block_marker "+Registry.BLOCK.getKey(Block.byItem(this.item.getItem())));
}
else
{
particle = getParticleData("block_marker "+Registry.BLOCK.getKey(this.blockState.getBlock()));
}
return p -> { return p -> {
ParticleOptions particle;
if(this.isitem)
{
if (Block.byItem(this.item.getItem()).defaultBlockState().isAir()) return;
particle = getParticleData("block_marker "+Registry.BLOCK.getKey(Block.byItem(this.item.getItem())), p.level.registryAccess());
}
else
{
particle = getParticleData("block_marker "+Registry.BLOCK.getKey(this.blockState.getBlock()), p.level.registryAccess());
}
Vec3 v = relativiseRender(p.level, this.pos, 0); Vec3 v = relativiseRender(p.level, this.pos, 0);
p.getLevel().sendParticles(p, particle , true, v.x, v.y, v.z, 1,0.0, 0.0, 0.0, 0.0); p.getLevel().sendParticles(p, particle , true, v.x, v.y, v.z, 1,0.0, 0.0, 0.0, 0.0);
}; };
@@ -712,7 +711,6 @@ public class ShapeDispatcher
@Override @Override
public Consumer<ServerPlayer> alternative() public Consumer<ServerPlayer> alternative()
{ {
ParticleOptions particle = replacementParticle();
double density = Math.max(2.0, from.distanceTo(to) /50/ (a+0.1)) ; double density = Math.max(2.0, from.distanceTo(to) /50/ (a+0.1)) ;
return p -> return p ->
{ {
@@ -720,7 +718,7 @@ public class ShapeDispatcher
{ {
particleMesh( particleMesh(
Collections.singletonList(p), Collections.singletonList(p),
particle, replacementParticle(p.level.registryAccess()),
density, density,
relativiseRender(p.level, from, 0), relativiseRender(p.level, from, 0),
relativiseRender(p.level, to, 0) relativiseRender(p.level, to, 0)
@@ -872,10 +870,10 @@ public class ShapeDispatcher
} }
@Override @Override
public Consumer<ServerPlayer> alternative() { public Consumer<ServerPlayer> alternative() {
final ParticleOptions locparticledata = getParticleData(String.format(Locale.ROOT ,"dust %.1f %.1f %.1f %.1f", fr, fg, fb, fa));
return p->{ return p->{
if(p.level.dimension() != this.shapeDimension){return;} if(p.level.dimension() != this.shapeDimension){return;}
if(!(fa>0.0f)){return;} if(!(fa>0.0f)){return;}
final ParticleOptions locparticledata = getParticleData(String.format(Locale.ROOT ,"dust %.1f %.1f %.1f %.1f", fr, fg, fb, fa), p.level.registryAccess());
for(Vec3 v : alter_point(p)){ for(Vec3 v : alter_point(p)){
p.getLevel().sendParticles(p,locparticledata , true, p.getLevel().sendParticles(p,locparticledata , true,
v.x, v.y, v.z, 1, v.x, v.y, v.z, 1,
@@ -973,13 +971,12 @@ public class ShapeDispatcher
@Override @Override
public Consumer<ServerPlayer> alternative() public Consumer<ServerPlayer> alternative()
{ {
ParticleOptions particle = replacementParticle();
double density = Math.max(2.0, from.distanceTo(to) /50) / (a+0.1); double density = Math.max(2.0, from.distanceTo(to) /50) / (a+0.1);
return p -> return p ->
{ {
if (p.level.dimension() == shapeDimension) drawParticleLine( if (p.level.dimension() == shapeDimension) drawParticleLine(
Collections.singletonList(p), Collections.singletonList(p),
particle, replacementParticle(p.level.registryAccess()),
relativiseRender(p.level, from, 0), relativiseRender(p.level, from, 0),
relativiseRender(p.level, to, 0), relativiseRender(p.level, to, 0),
density density
@@ -1034,10 +1031,11 @@ public class ShapeDispatcher
@Override @Override
public Consumer<ServerPlayer> alternative() { return p -> public Consumer<ServerPlayer> alternative() { return p ->
{ {
ParticleOptions particle = replacementParticle();
int partno = Math.min(1000,20*subdivisions); int partno = Math.min(1000,20*subdivisions);
RandomSource rand = p.level.getRandom(); RandomSource rand = p.level.getRandom();
ServerLevel world = p.getLevel(); ServerLevel world = p.getLevel();
ParticleOptions particle = replacementParticle(world.registryAccess());
Vec3 ccenter = relativiseRender(world, center, 0 ); Vec3 ccenter = relativiseRender(world, center, 0 );
@@ -1112,10 +1110,11 @@ public class ShapeDispatcher
@Override @Override
public Consumer<ServerPlayer> alternative() { return p -> public Consumer<ServerPlayer> alternative() { return p ->
{ {
ParticleOptions particle = replacementParticle();
int partno = (int)Math.min(1000,Math.sqrt(20*subdivisions*(1+height))); int partno = (int)Math.min(1000,Math.sqrt(20*subdivisions*(1+height)));
RandomSource rand = p.level.getRandom(); RandomSource rand = p.level.getRandom();
ServerLevel world = p.getLevel(); ServerLevel world = p.getLevel();
ParticleOptions particle = replacementParticle(world.registryAccess());
Vec3 ccenter = relativiseRender(world, center, 0 ); Vec3 ccenter = relativiseRender(world, center, 0 );
@@ -1307,7 +1306,7 @@ public class ShapeDispatcher
if(value instanceof BlockValue blv){ if(value instanceof BlockValue blv){
return value; return value;
} }
return BlockValue.fromString(value.getString()); return BlockValue.fromString(value.getString(), server.registryAccess());
} }
@Override @Override
public Tag toTag(Value value) { public Tag toTag(Value value) {
@@ -1342,7 +1341,7 @@ public class ShapeDispatcher
@Override @Override
public Value validate(Map<String, Value> options, MinecraftServer server, Value value) public Value validate(Map<String, Value> options, MinecraftServer server, Value value)
{ {
ItemStack item=ValueConversions.getItemStackFromValue(value, true); ItemStack item=ValueConversions.getItemStackFromValue(value, true, server.registryAccess());
return new NBTSerializableValue(item.save(new CompoundTag())); return new NBTSerializableValue(item.save(new CompoundTag()));
} }
@Override @Override
@@ -18,8 +18,8 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis; import net.minecraft.core.Direction.Axis;
import net.minecraft.core.GlobalPos; import net.minecraft.core.GlobalPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.StringTag; import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
@@ -54,13 +54,13 @@ public class BlockValue extends Value
} }
private static final Map<String, BlockValue> bvCache= new HashMap<>(); private static final Map<String, BlockValue> bvCache= new HashMap<>();
public static BlockValue fromString(String str) public static BlockValue fromString(String str, RegistryAccess regs)
{ {
try try
{ {
BlockValue bv = bvCache.get(str); BlockValue bv = bvCache.get(str); // [SCARY SHIT] persistent caches over server reloads
if (bv != null) return bv; if (bv != null) return bv;
BlockStateParser.BlockResult foo = BlockStateParser.parseForBlock(HolderLookup.forRegistry(Registry.BLOCK), new StringReader(str), true ); BlockStateParser.BlockResult foo = BlockStateParser.parseForBlock(regs.lookupOrThrow(Registry.BLOCK_REGISTRY), new StringReader(str), true );
if (foo.blockState() != null) if (foo.blockState() != null)
{ {
CompoundTag bd = foo.nbt(); CompoundTag bd = foo.nbt();
@@ -1691,7 +1691,7 @@ public class EntityValue extends Value
}); });
put("item", (e, v) -> { put("item", (e, v) -> {
ItemStack item=ValueConversions.getItemStackFromValue(v, true); ItemStack item=ValueConversions.getItemStackFromValue(v, true, e.level.registryAccess());
if(e instanceof ItemEntity itementity) if(e instanceof ItemEntity itementity)
itementity.setItem(item); itementity.setItem(item);
if(e instanceof ItemFrame itemframe) if(e instanceof ItemFrame itemframe)
@@ -23,8 +23,8 @@ import net.minecraft.commands.arguments.item.ItemInput;
import net.minecraft.commands.arguments.item.ItemParser; import net.minecraft.commands.arguments.item.ItemParser;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CollectionTag; import net.minecraft.nbt.CollectionTag;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.EndTag; import net.minecraft.nbt.EndTag;
@@ -290,22 +290,22 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
private static final Map<String,ItemInput> itemCache = new HashMap<>(); private static final Map<String,ItemInput> itemCache = new HashMap<>();
public static ItemInput parseItem(String itemString) public static ItemInput parseItem(String itemString, RegistryAccess regs)
{ {
return parseItem(itemString, null); return parseItem(itemString, null, regs);
} }
public static ItemInput parseItem(String itemString, CompoundTag customTag) public static ItemInput parseItem(String itemString, CompoundTag customTag, RegistryAccess regs)
{ {
try try
{ {
ItemInput res = itemCache.get(itemString); ItemInput res = itemCache.get(itemString); // [SCARY SHIT] persistent caches over server reloads
if (res != null) if (res != null)
if (customTag == null) if (customTag == null)
return res; return res;
else else
return new ItemInput(Holder.direct(res.getItem()), customTag); return new ItemInput(Holder.direct(res.getItem()), customTag);
ItemParser.ItemResult parser = ItemParser.parseForItem(HolderLookup.forRegistry(Registry.ITEM), new StringReader(itemString)); ItemParser.ItemResult parser = ItemParser.parseForItem(regs.lookupOrThrow(Registry.ITEM_REGISTRY), new StringReader(itemString));
res = new ItemInput(parser.item(), parser.nbt()); res = new ItemInput(parser.item(), parser.nbt());
itemCache.put(itemString, res); itemCache.put(itemString, res);
@@ -413,7 +413,7 @@ public class ValueConversions
); );
} }
public static ItemStack getItemStackFromValue(Value value, boolean withCount) public static ItemStack getItemStackFromValue(Value value, boolean withCount, RegistryAccess regs)
{ {
if (value.isNull()) if (value.isNull())
{ {
@@ -444,7 +444,7 @@ public class ValueConversions
{ {
name = value.getString(); name = value.getString();
} }
ItemInput itemInput = NBTSerializableValue.parseItem(name, nbtTag); ItemInput itemInput = NBTSerializableValue.parseItem(name, nbtTag, regs);
try try
{ {
return itemInput.createItemStack(count,false); return itemInput.createItemStack(count,false);
@@ -208,8 +208,7 @@ public class SettingsManager extends carpet.api.settings.SettingsManager
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public void registerCommand(CommandDispatcher<CommandSourceStack> dispatcher) public void registerCommand(CommandDispatcher<CommandSourceStack> dispatcher)
{ {
final CommandBuildContext context = new CommandBuildContext(RegistryAccess.EMPTY, FeatureFlags.VANILLA_SET); final CommandBuildContext context = CommandBuildContext.simple(RegistryAccess.EMPTY, FeatureFlags.VANILLA_SET);
context.missingTagAccessPolicy(CommandBuildContext.MissingTagAccessPolicy.RETURN_EMPTY);
registerCommand(dispatcher, context); registerCommand(dispatcher, context);
} }
} }