Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModifyVariable doesn't work #165

Open
FrankHan052176 opened this issue May 23, 2024 · 2 comments
Open

ModifyVariable doesn't work #165

FrankHan052176 opened this issue May 23, 2024 · 2 comments

Comments

@FrankHan052176
Copy link

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

@FrankHan052176
Copy link
Author

it's on 1.20.1, i also ask this question in Mixin discord server

@Floweynt
Copy link

You may need to bump your tiny remapper. I had a similar issue, turns out mixin extras weren't getting remapped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants