Skip to content

Commit

Permalink
Fix BlockEntityTypeMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
FirstMegaGame4 committed Nov 15, 2023
1 parent 909c7b2 commit 5dadadf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends BlockEntity> implements BlockEntityTypeDuckInterface {
public class BlockEntityTypeMixin implements BlockEntityTypeDuckInterface {

@Unique
private final Event<BlockEntityTypeBlockSupportCallback> supportBlocksCallBack = Event.create(BlockEntityTypeBlockSupportCallback.class, callbacks -> supportedBlocks -> {
Expand All @@ -29,16 +26,13 @@ public class BlockEntityTypeMixin<T extends BlockEntity> implements BlockEntityT
}
});

@Shadow
private Set<Block> blocks;

@Inject(method = "<init>", at = @At("TAIL"))
private void init(BlockEntityType.BlockEntityFactory<T> factory, Set<Block> blocks, Type<?> type, CallbackInfo ci) {
Set<Block> previousBlocks = new HashSet<>(this.blocks);
List<Block> 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<Boolean> cir) {
List<Block> supportedBlocks = new ArrayList<>();
this.mmodding_lib$supportBlocksCallback().invoker().onSupportedBlocks(supportedBlocks);
if (supportedBlocks.contains(state.getBlock())) {
cir.setReturnValue(true);
}
}

@Override
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/mmodding_lib.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 5dadadf

Please sign in to comment.