Open FrankHan052176 opened 1 month ago
code
import com.llamalad7.mixinextras.sugar.Local; import com.llamalad7.mixinextras.sugar.ref.LocalRef; import net.minecraft.core.BlockPos; import net.minecraft.core.MappedRegistry; import net.minecraft.core.registries.Registries; import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext; import net.minecraft.world.level.levelgen.feature.TreeFeature; import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration; import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacer; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_20_R1.CraftServer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import top.missingbyriver.igniteleaves.mixin.plugins.CorePlugin; import java.util.Set; @Mixin(value = TreeFeature.class) public abstract class MixinTreeFeature { @Inject(method = "place(Lnet/minecraft/world/level/levelgen/feature/FeaturePlaceContext;)Z", at = @At("HEAD")) protected void writeMapBeforePlace(FeaturePlaceContext<TreeConfiguration> context, CallbackInfoReturnable<Boolean> cir) { if (CorePlugin.featureMap.isEmpty()) { new Thread(() -> { var server = ((CraftServer) Bukkit.getServer()).getServer(); var registry = (MappedRegistry<ConfiguredFeature<?, ?>>) server.worldLoader.datapackWorldgen().registryOrThrow(Registries.CONFIGURED_FEATURE); registry.entrySet().iterator().forEachRemaining(entry -> CorePlugin.featureMap.put(entry.getValue().feature(), entry.getKey().location().toString()) ); System.out.println("load FeatureMap"); }).start(); } } @ModifyVariable( method = "place(Lnet/minecraft/world/level/levelgen/feature/FeaturePlaceContext;)Z", at = @At("STORE"), ordinal = 0 ) private FoliagePlacer.FoliageSetter injected(FoliagePlacer.FoliageSetter value, @Local LocalRef<Set<BlockPos>> set3, @Local LocalRef<WorldGenLevel> worldGenLevel) { System.out.println("modified"); return new FoliagePlacer.FoliageSetter() { @Override public void set(BlockPos pos, BlockState state) { System.out.println("abab"); set3.get().add(pos.immutable()); worldGenLevel.get().setBlock(pos, state, 19); } @Override public boolean isSet(BlockPos pos) { System.out.println("abab"); return set3.get().contains(pos); } }; } }
log latest.log
it's on 1.20.1, i also ask this question in Mixin discord server
You may need to bump your tiny remapper. I had a similar issue, turns out mixin extras weren't getting remapped.
code
log latest.log