From 3bdea3befbbce74a3bcaba47c84abe1e57a7623f Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Fri, 1 Dec 2023 20:52:14 -0500 Subject: [PATCH] hopefully fi C2ME compat --- .../mixin/worldgen/tree/TreeFeatureMixin.java | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/frozenblock/wilderwild/mixin/worldgen/tree/TreeFeatureMixin.java b/src/main/java/net/frozenblock/wilderwild/mixin/worldgen/tree/TreeFeatureMixin.java index 966ac18298..0fcab05e40 100644 --- a/src/main/java/net/frozenblock/wilderwild/mixin/worldgen/tree/TreeFeatureMixin.java +++ b/src/main/java/net/frozenblock/wilderwild/mixin/worldgen/tree/TreeFeatureMixin.java @@ -18,17 +18,18 @@ package net.frozenblock.wilderwild.mixin.worldgen.tree; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.google.common.collect.Iterables; import java.util.Set; import net.frozenblock.wilderwild.misc.interfaces.TreeFeatureLeavesUpdate; -import net.minecraft.Util; import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.WorldGenLevel; 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.structure.BoundingBox; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import net.minecraft.world.phys.shapes.DiscreteVoxelShape; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; @@ -37,6 +38,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(value = TreeFeature.class, priority = 69420) public abstract class TreeFeatureMixin implements TreeFeatureLeavesUpdate { @@ -46,33 +48,26 @@ private static DiscreteVoxelShape updateLeaves(LevelAccessor level, BoundingBox return null; } - @Unique - private static TreeFeature currentFeature = null; - @Inject( method = "place", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/structure/BoundingBox;encapsulatingPositions(Ljava/lang/Iterable;)Ljava/util/Optional;", shift = At.Shift.BEFORE - ) + ), + locals = LocalCapture.CAPTURE_FAILHARD, + cancellable = true ) - private void wilderWild$place(FeaturePlaceContext context, CallbackInfoReturnable info) { - currentFeature = TreeFeature.class.cast(this); + private void wilderWild$place(FeaturePlaceContext context, CallbackInfoReturnable info, WorldGenLevel worldGenLevel, RandomSource randomSource, BlockPos blockPos, TreeConfiguration treeConfiguration, Set set, Set set2, Set set3, Set set4) { + info.setReturnValue(this.wilderWild$encapsulatePositionsAndUpdateLeaves(worldGenLevel, set, set2, set3, set4)); } - @WrapOperation( - method = "method_35363", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/level/levelgen/feature/TreeFeature;updateLeaves(Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/world/level/levelgen/structure/BoundingBox;Ljava/util/Set;Ljava/util/Set;Ljava/util/Set;)Lnet/minecraft/world/phys/shapes/DiscreteVoxelShape;" - ) - ) - private static DiscreteVoxelShape wilderWild$updateLeaves(LevelAccessor level, BoundingBox box, Set rootPositions, Set trunkPositions, Set foliagePositions, Operation original) { - return Util.make(() -> { - DiscreteVoxelShape shape = ((TreeFeatureLeavesUpdate) currentFeature).wilderWild$updateLeaves(level, box, rootPositions, trunkPositions, foliagePositions); - currentFeature = null; - return shape; - }); + @Unique + public boolean wilderWild$encapsulatePositionsAndUpdateLeaves(LevelAccessor worldGenLevel, Set set, Set set2, Set set3, Set set4) { + return BoundingBox.encapsulatingPositions(Iterables.concat(set, set2, set3, set4)).map((boundingBox) -> { + DiscreteVoxelShape discreteVoxelShape = this.wilderWild$updateLeaves(worldGenLevel, boundingBox, set2, set4, set); + StructureTemplate.updateShapeAtEdge(worldGenLevel, 3, discreteVoxelShape, boundingBox.minX(), boundingBox.minY(), boundingBox.minZ()); + return true; + }).orElse(false); } @Unique