From 5dadadf6e6430eee810ea50d8e95d47c5526a4f0 Mon Sep 17 00:00:00 2001 From: FirstMegaGame4 <84094287+FirstMegaGame4@users.noreply.github.com> Date: Wed, 15 Nov 2023 17:36:40 +0100 Subject: [PATCH] Fix BlockEntityTypeMixin --- .../mixin/injectors/BlockEntityTypeMixin.java | 26 +++++++------------ src/main/resources/mmodding_lib.accesswidener | 1 - 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/mmodding/mmodding_lib/mixin/injectors/BlockEntityTypeMixin.java b/src/main/java/com/mmodding/mmodding_lib/mixin/injectors/BlockEntityTypeMixin.java index 8f766a2..65fb416 100644 --- a/src/main/java/com/mmodding/mmodding_lib/mixin/injectors/BlockEntityTypeMixin.java +++ b/src/main/java/com/mmodding/mmodding_lib/mixin/injectors/BlockEntityTypeMixin.java @@ -2,25 +2,22 @@ import com.mmodding.mmodding_lib.ducks.BlockEntityTypeDuckInterface; import com.mmodding.mmodding_lib.library.blockentities.BlockEntityTypeBlockSupportCallback; -import com.mojang.datafixers.types.Type; import net.minecraft.block.Block; +import net.minecraft.block.BlockState; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityType; import org.quiltmc.qsl.base.api.event.Event; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; @Mixin(BlockEntityType.class) -public class BlockEntityTypeMixin implements BlockEntityTypeDuckInterface { +public class BlockEntityTypeMixin implements BlockEntityTypeDuckInterface { @Unique private final Event supportBlocksCallBack = Event.create(BlockEntityTypeBlockSupportCallback.class, callbacks -> supportedBlocks -> { @@ -29,16 +26,13 @@ public class BlockEntityTypeMixin implements BlockEntityT } }); - @Shadow - private Set blocks; - - @Inject(method = "", at = @At("TAIL")) - private void init(BlockEntityType.BlockEntityFactory factory, Set blocks, Type type, CallbackInfo ci) { - Set previousBlocks = new HashSet<>(this.blocks); - List eventBlocks = new ArrayList<>(previousBlocks.stream().toList()); - this.mmodding_lib$supportBlocksCallback().invoker().onSupportedBlocks(eventBlocks); - previousBlocks.addAll(eventBlocks); - this.blocks = previousBlocks; + @Inject(method = "supports", at = @At("HEAD"), cancellable = true) + private void supports(BlockState state, CallbackInfoReturnable cir) { + List supportedBlocks = new ArrayList<>(); + this.mmodding_lib$supportBlocksCallback().invoker().onSupportedBlocks(supportedBlocks); + if (supportedBlocks.contains(state.getBlock())) { + cir.setReturnValue(true); + } } @Override diff --git a/src/main/resources/mmodding_lib.accesswidener b/src/main/resources/mmodding_lib.accesswidener index 91fb94b..6802df8 100644 --- a/src/main/resources/mmodding_lib.accesswidener +++ b/src/main/resources/mmodding_lib.accesswidener @@ -26,7 +26,6 @@ extendable class net/minecraft/client/render/RenderLayer$MultiPhase extendable class net/minecraft/client/render/RenderLayer$MultiPhaseParameters extendable class net/minecraft/world/gen/chunk/NoiseChunkGenerator -mutable field net/minecraft/block/entity/BlockEntityType blocks Ljava/util/Set; mutable field net/minecraft/world/dimension/AreaHelper width I mutable field net/minecraft/world/gen/chunk/ChunkNoiseSampler blockStateSampler Lnet/minecraft/world/gen/chunk/ChunkNoiseSampler$BlockStateSampler;