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
# check these on https://fabricmc.net/use
# or better: https://modmuss50.me/fabric.html
minecraft_version=22w43a
minecraft_version=22w44a
loader_version=0.14.10
fabric_version=0.65.1+1.19.3
fabric_version=0.65.2+1.19.3
# Mod Properties
mod_version = 1.4.86
mod_version = 1.4.87
maven_group = 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
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 Logger LOG = LoggerFactory.getLogger("carpet");
public static final ThreadLocal<Boolean> skipGenerationChecks = ThreadLocal.withInitial(() -> false);
@@ -11,13 +11,16 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.function.Function;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.HolderSet;
import net.minecraft.core.QuartPos;
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.placement.PlacementUtils;
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.placement.StructurePlacement;
import net.minecraft.world.level.levelgen.structure.structures.JigsawStructure;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorList;
public class FeatureGenerator
{
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)
{
return custom.plop(world, pos);
return custom.apply(world).plop(world, pos);
}
ResourceLocation id = new ResourceLocation(featureName);
Structure structure = world.registryAccess().registryOrThrow(Registry.STRUCTURE_REGISTRY).get(id);
@@ -206,7 +210,7 @@ public class FeatureGenerator
ChunkGeneratorInterface cgi = (ChunkGeneratorInterface) generator;
List<StructurePlacement> structureConfig = cgi.getPlacementsForFeatureCM(world, structure);
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;
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));
}
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("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("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", 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", 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_mushroom", simplePlop(Feature.CORAL_MUSHROOM, FeatureConfiguration.NONE));
put("coral", simplePlop(Feature.SIMPLE_RANDOM_SELECTOR, new SimpleRandomFeatureConfiguration(HolderSet.direct(
put("coral_claw", l -> simplePlop(Feature.CORAL_CLAW, FeatureConfiguration.NONE));
put("coral_mushroom", l -> simplePlop(Feature.CORAL_MUSHROOM, FeatureConfiguration.NONE));
put("coral", l -> simplePlop(Feature.SIMPLE_RANDOM_SELECTOR, new SimpleRandomFeatureConfiguration(HolderSet.direct(
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(
new JigsawStructure( new Structure.StructureSettings(
BuiltinRegistries.BIOME.getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
Map.of(),
GenerationStep.Decoration.SURFACE_STRUCTURES,
TerrainAdjustment.NONE
),
Holder.direct(new StructureTemplatePool(
new ResourceLocation("bastion/starts"),
new ResourceLocation("empty"),
ImmutableList.of(
Pair.of(StructurePoolElement.single("bastion/units/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
),
StructureTemplatePool.Projection.RIGID
)),
6,
ConstantHeight.of(VerticalAnchor.absolute(33)),
false
)
));
put("bastion_remnant_hoglin_stable", spawnCustomStructure(
new JigsawStructure( new Structure.StructureSettings(
BuiltinRegistries.BIOME.getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
Map.of(),
GenerationStep.Decoration.SURFACE_STRUCTURES,
TerrainAdjustment.NONE
),
Holder.direct(new StructureTemplatePool(
new ResourceLocation("bastion/starts"),
new ResourceLocation("empty"),
ImmutableList.of(
Pair.of(StructurePoolElement.single("bastion/hoglin_stable/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
),
StructureTemplatePool.Projection.RIGID
)),
6,
ConstantHeight.of(VerticalAnchor.absolute(33)),
false
)
));
put("bastion_remnant_treasure", spawnCustomStructure(
new JigsawStructure( new Structure.StructureSettings(
BuiltinRegistries.BIOME.getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
Map.of(),
GenerationStep.Decoration.SURFACE_STRUCTURES,
TerrainAdjustment.NONE
),
Holder.direct(new StructureTemplatePool(
new ResourceLocation("bastion/starts"),
new ResourceLocation("empty"),
ImmutableList.of(
Pair.of(StructurePoolElement.single("bastion/treasure/big_air_full", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
),
StructureTemplatePool.Projection.RIGID
)),
6,
ConstantHeight.of(VerticalAnchor.absolute(33)),
false
)
));
put("bastion_remnant_bridge", spawnCustomStructure(
new JigsawStructure( new Structure.StructureSettings(
BuiltinRegistries.BIOME.getOrCreateTag(BiomeTags.HAS_BASTION_REMNANT),
Map.of(),
GenerationStep.Decoration.SURFACE_STRUCTURES,
TerrainAdjustment.NONE
),
Holder.direct(new StructureTemplatePool(
new ResourceLocation("bastion/starts"),
new ResourceLocation("empty"),
ImmutableList.of(
Pair.of(StructurePoolElement.single("bastion/bridge/starting_pieces/entrance_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
),
StructureTemplatePool.Projection.RIGID
)),
6,
ConstantHeight.of(VerticalAnchor.absolute(33)),
false
)
));
put("bastion_remnant_units", 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/units/air_base", bastionGenericDegradation), 1)
),
StructureTemplatePool.Projection.RIGID
)),
6,
ConstantHeight.of(VerticalAnchor.absolute(33)),
false
)
);
});
put("bastion_remnant_hoglin_stable", 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/hoglin_stable/air_base", bastionGenericDegradation), 1)
),
StructureTemplatePool.Projection.RIGID
)),
6,
ConstantHeight.of(VerticalAnchor.absolute(33)),
false
)
);
});
put("bastion_remnant_treasure", 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/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());
}
boolean damagesTerrain = eAccess.getBlockInteraction() != Explosion.BlockInteraction.NONE;
boolean damagesTerrain = eAccess.getBlockInteraction() != Explosion.BlockInteraction.KEEP;
// explosionSound incremented till disabling the explosion particles and sound
if (explosionSound < 100 || explosionSound % 100 == 0)
@@ -16,30 +16,30 @@ public class ParticleDisplay
{
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
{
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)
{
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;
ParticleOptions res = particleCache.get(name);
if (res != null) return res;
particleCache.put(name, parseParticle(name));
particleCache.put(name, parseParticle(name, level));
return particleCache.get(name);
}
public static void drawParticleLine(ServerPlayer player, Vec3 from, Vec3 to, String main, String accent, int count, double spread)
{
ParticleOptions accentParticle = getEffect(accent);
ParticleOptions mainParticle = getEffect(main);
ParticleOptions accentParticle = getEffect(accent, player.getLevel());
ParticleOptions mainParticle = getEffect(main, player.getLevel());
if (accentParticle != null) ((ServerLevel)player.level).sendParticles(
player,
@@ -4,30 +4,23 @@ import carpet.fakes.ChunkGeneratorInterface;
import net.minecraft.core.Holder;
import net.minecraft.server.level.ServerLevel;
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.placement.StructurePlacement;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.List;
@Mixin(ChunkGenerator.class)
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
public void initStrongholds(final ServerLevel level)
{
ensureStructuresGenerated(level.getChunkSource().randomState());
level.getChunkSource().getGeneratorState().ensureStructuresGenerated();
}
@Override
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.levelgen.FlatLevelSource;
import java.util.Optional;
@Mixin(FlatLevelSource.class)
@Mixin(FlatLevelSource.class) // YEET
public abstract class FlatLevelSource_structuresMixin extends ChunkGenerator
{
public FlatLevelSource_structuresMixin(Registry<StructureSet> registry, Optional<HolderSet<StructureSet>> optional, BiomeSource biomeSource) {
super(registry, optional, biomeSource);
public FlatLevelSource_structuresMixin(BiomeSource biomeSource) {
super(biomeSource);
}
/*
@Override
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.getZ(),
4.0F,
Explosion.BlockInteraction.BREAK);
Level.ExplosionInteraction.TNT);
}
@Inject(method = "tick", at = @At(value = "INVOKE",
@@ -2,6 +2,8 @@ package carpet.mixins;
import carpet.fakes.ServerWorldInterface;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.profiling.ProfilerFiller;
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.Explosion;
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.dimension.DimensionType;
import net.minecraft.world.level.entity.LevelEntityGetter;
import net.minecraft.world.level.entity.PersistentEntitySectionManager;
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.Mixin;
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.LocalCapture;
import java.util.function.Supplier;
import static carpet.script.CarpetEventServer.Event.EXPLOSION;
import static carpet.script.CarpetEventServer.Event.LIGHTNING;
import static carpet.script.CarpetEventServer.Event.CHUNK_UNLOADED;
@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(
value = "INVOKE",
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);
}
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"))
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())
EXPLOSION.onExplosion((ServerLevel) (Object)this, entity, null, d, e, f, g, bl, null, null, destructionType);
if (EXPLOSION.isNeeded()) {
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"))
@@ -200,7 +200,7 @@ public class Auxiliary {
}
}
}
ParticleOptions particle = ShapeDispatcher.getParticleData(particleName);
ParticleOptions particle = ShapeDispatcher.getParticleData(particleName, world.registryAccess());
Vec3 vec = locator.vec;
if (player == null)
{
@@ -225,7 +225,7 @@ public class Auxiliary {
CarpetContext cc = (CarpetContext)c;
ServerLevel world = cc.s.getLevel();
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 pos2 = Vector3Argument.findIn(lv, pos1.offset);
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) ->
{
CarpetContext cc = (CarpetContext)c;
ServerLevel world = cc.s.getLevel();
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 pos2 = Vector3Argument.findIn(lv, pos1.offset);
@@ -4,7 +4,6 @@ import carpet.fakes.IngredientInterface;
import carpet.fakes.RecipeManagerInterface;
import carpet.script.CarpetContext;
import carpet.script.Expression;
import carpet.script.argument.BlockArgument;
import carpet.script.argument.FunctionArgument;
import carpet.script.exception.InternalExpressionException;
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.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
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.ShapelessRecipe;
import net.minecraft.world.item.crafting.SingleItemRecipe;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.phys.Vec3;
public class Inventories {
public static void apply(Expression expression)
{
expression.addUnaryFunction("stack_limit", v ->
new NumericValue(NBTSerializableValue.parseItem(v.getString()).getItem().getMaxStackSize()));
expression.addContextFunction("stack_limit", 1, (c, t, lv) ->
new NumericValue(NBTSerializableValue.parseItem(lv.get(0).getString(), ((CarpetContext) c).s.registryAccess() ).getItem().getMaxStackSize()));
expression.addContextFunction("item_category", -1, (c, t, lv) -> {
CarpetContext cc = (CarpetContext)c;
@@ -91,7 +88,7 @@ public class Inventories {
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();
Item item = NBTSerializableValue.parseItem(lv.get(0).getString(), cc.s.registryAccess()).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()));
@@ -280,7 +277,7 @@ public class Inventories {
else
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);
try
{
@@ -305,7 +302,7 @@ public class Inventories {
{
Value secondArg = lv.get(inventoryLocator.offset()+0);
if (!secondArg.isNull())
itemArg = NBTSerializableValue.parseItem(secondArg.getString());
itemArg = NBTSerializableValue.parseItem(secondArg.getString(), cc.s.registryAccess());
}
int startIndex = 0;
if (lv.size() > inventoryLocator.offset()+1)
@@ -330,7 +327,7 @@ public class Inventories {
if (inventoryLocator == null) return Value.NULL;
if (lv.size() <= inventoryLocator.offset())
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;
if (lv.size() > inventoryLocator.offset()+1)
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.ValueConversions;
import carpet.utils.BlockInfo;
import carpet.utils.CommandHelper;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
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");
CarpetContext cc = (CarpetContext)c;
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;
Entity source = null;
LivingEntity attacker = null;
@@ -994,7 +993,7 @@ public class WorldAccess {
};
explosion.explode();
explosion.finalizeExplosion(false);
if (mode == Explosion.BlockInteraction.NONE) explosion.clearToBlow();
if (mode == Explosion.BlockInteraction.KEEP) explosion.clearToBlow();
cc.s.getLevel().players().forEach(spe -> {
if (spe.distanceToSqr(pos) < 4096.0D)
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;
String itemString = lv.get(0).getString();
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);
String facing;
if (lv.size() > locator.offset) {
@@ -60,7 +60,7 @@ public class BlockArgument extends Argument
}
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)
{
@@ -1061,8 +1061,7 @@ public abstract class CommandArgument
super(suffix, null, suggestFromExamples);
try
{
final CommandBuildContext context = new CommandBuildContext(server.registryAccess(), server.getWorldData().enabledFeatures());
context.missingTagAccessPolicy(CommandBuildContext.MissingTagAccessPolicy.RETURN_EMPTY);
final CommandBuildContext context = CommandBuildContext.simple(server.registryAccess(), server.getWorldData().enabledFeatures());
this.examples = argumentTypeSupplier.get(context).getExamples();
}
catch (CommandSyntaxException e)
@@ -1122,7 +1121,7 @@ public abstract class CommandArgument
protected ArgumentType<?> getArgumentType(CarpetScriptHost host) throws CommandSyntaxException
{
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);
}
@@ -29,8 +29,8 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.commands.arguments.ParticleArgument;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.nbt.ByteTag;
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)
return particle;
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)
{
@@ -388,12 +388,12 @@ public class ShapeDispatcher
NumericValue.asNumber( elements.get(2)).getDouble()
);
}
protected ParticleOptions replacementParticle()
protected ParticleOptions replacementParticle(RegistryAccess regs)
{
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", fr, fg, fb);
return getParticleData(particleName);
return getParticleData(particleName, regs);
}
@@ -645,19 +645,18 @@ public class ShapeDispatcher
@Override
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 -> {
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);
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
public Consumer<ServerPlayer> alternative()
{
ParticleOptions particle = replacementParticle();
double density = Math.max(2.0, from.distanceTo(to) /50/ (a+0.1)) ;
return p ->
{
@@ -720,7 +718,7 @@ public class ShapeDispatcher
{
particleMesh(
Collections.singletonList(p),
particle,
replacementParticle(p.level.registryAccess()),
density,
relativiseRender(p.level, from, 0),
relativiseRender(p.level, to, 0)
@@ -872,10 +870,10 @@ public class ShapeDispatcher
}
@Override
public Consumer<ServerPlayer> alternative() {
final ParticleOptions locparticledata = getParticleData(String.format(Locale.ROOT ,"dust %.1f %.1f %.1f %.1f", fr, fg, fb, fa));
return p->{
if(p.level.dimension() != this.shapeDimension){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)){
p.getLevel().sendParticles(p,locparticledata , true,
v.x, v.y, v.z, 1,
@@ -973,13 +971,12 @@ public class ShapeDispatcher
@Override
public Consumer<ServerPlayer> alternative()
{
ParticleOptions particle = replacementParticle();
double density = Math.max(2.0, from.distanceTo(to) /50) / (a+0.1);
return p ->
{
if (p.level.dimension() == shapeDimension) drawParticleLine(
Collections.singletonList(p),
particle,
replacementParticle(p.level.registryAccess()),
relativiseRender(p.level, from, 0),
relativiseRender(p.level, to, 0),
density
@@ -1034,10 +1031,11 @@ public class ShapeDispatcher
@Override
public Consumer<ServerPlayer> alternative() { return p ->
{
ParticleOptions particle = replacementParticle();
int partno = Math.min(1000,20*subdivisions);
RandomSource rand = p.level.getRandom();
ServerLevel world = p.getLevel();
ParticleOptions particle = replacementParticle(world.registryAccess());
Vec3 ccenter = relativiseRender(world, center, 0 );
@@ -1112,10 +1110,11 @@ public class ShapeDispatcher
@Override
public Consumer<ServerPlayer> alternative() { return p ->
{
ParticleOptions particle = replacementParticle();
int partno = (int)Math.min(1000,Math.sqrt(20*subdivisions*(1+height)));
RandomSource rand = p.level.getRandom();
ServerLevel world = p.getLevel();
ParticleOptions particle = replacementParticle(world.registryAccess());
Vec3 ccenter = relativiseRender(world, center, 0 );
@@ -1307,7 +1306,7 @@ public class ShapeDispatcher
if(value instanceof BlockValue blv){
return value;
}
return BlockValue.fromString(value.getString());
return BlockValue.fromString(value.getString(), server.registryAccess());
}
@Override
public Tag toTag(Value value) {
@@ -1342,7 +1341,7 @@ public class ShapeDispatcher
@Override
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()));
}
@Override
@@ -18,8 +18,8 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Direction.Axis;
import net.minecraft.core.GlobalPos;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
@@ -54,13 +54,13 @@ public class BlockValue extends Value
}
private static final Map<String, BlockValue> bvCache= new HashMap<>();
public static BlockValue fromString(String str)
public static BlockValue fromString(String str, RegistryAccess regs)
{
try
{
BlockValue bv = bvCache.get(str);
BlockValue bv = bvCache.get(str); // [SCARY SHIT] persistent caches over server reloads
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)
{
CompoundTag bd = foo.nbt();
@@ -1691,7 +1691,7 @@ public class EntityValue extends Value
});
put("item", (e, v) -> {
ItemStack item=ValueConversions.getItemStackFromValue(v, true);
ItemStack item=ValueConversions.getItemStackFromValue(v, true, e.level.registryAccess());
if(e instanceof ItemEntity itementity)
itementity.setItem(item);
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.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CollectionTag;
import net.minecraft.nbt.CompoundTag;
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<>();
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
{
ItemInput res = itemCache.get(itemString);
ItemInput res = itemCache.get(itemString); // [SCARY SHIT] persistent caches over server reloads
if (res != null)
if (customTag == null)
return res;
else
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());
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())
{
@@ -444,7 +444,7 @@ public class ValueConversions
{
name = value.getString();
}
ItemInput itemInput = NBTSerializableValue.parseItem(name, nbtTag);
ItemInput itemInput = NBTSerializableValue.parseItem(name, nbtTag, regs);
try
{
return itemInput.createItemStack(count,false);
@@ -208,8 +208,7 @@ public class SettingsManager extends carpet.api.settings.SettingsManager
@Deprecated(forRemoval = true)
public void registerCommand(CommandDispatcher<CommandSourceStack> dispatcher)
{
final CommandBuildContext context = new CommandBuildContext(RegistryAccess.EMPTY, FeatureFlags.VANILLA_SET);
context.missingTagAccessPolicy(CommandBuildContext.MissingTagAccessPolicy.RETURN_EMPTY);
final CommandBuildContext context = CommandBuildContext.simple(RegistryAccess.EMPTY, FeatureFlags.VANILLA_SET);
registerCommand(dispatcher, context);
}
}