|
| 1 | +package dev.ryanhcode.sable.neoforge.mixin.compatibility.create.lectern_controller; |
| 2 | + |
| 3 | +import com.simibubi.create.content.redstone.link.controller.LecternControllerBlockEntity; |
| 4 | +import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; |
| 5 | +import dev.ryanhcode.sable.neoforge.mixinterface.compatibility.create.LecternControllerBlockEntityExtension; |
| 6 | +import net.minecraft.core.BlockPos; |
| 7 | +import net.minecraft.server.level.ServerLevel; |
| 8 | +import net.minecraft.world.entity.Entity; |
| 9 | +import net.minecraft.world.entity.player.Player; |
| 10 | +import net.minecraft.world.level.block.entity.BlockEntityType; |
| 11 | +import net.minecraft.world.level.block.state.BlockState; |
| 12 | +import org.spongepowered.asm.mixin.Mixin; |
| 13 | +import org.spongepowered.asm.mixin.Shadow; |
| 14 | +import org.spongepowered.asm.mixin.Unique; |
| 15 | +import org.spongepowered.asm.mixin.injection.At; |
| 16 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 17 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 18 | + |
| 19 | +import java.util.UUID; |
| 20 | + |
| 21 | +@Mixin(LecternControllerBlockEntity.class) |
| 22 | +public abstract class LecternControllerBlockEntityMixin extends SmartBlockEntity implements LecternControllerBlockEntityExtension { |
| 23 | + |
| 24 | + public LecternControllerBlockEntityMixin(final BlockEntityType<?> type, final BlockPos pos, final BlockState state) { |
| 25 | + super(type, pos, state); |
| 26 | + } |
| 27 | + |
| 28 | + @Shadow |
| 29 | + protected abstract void stopUsing(Player player); |
| 30 | + |
| 31 | + @Shadow |
| 32 | + private UUID user; |
| 33 | + @Unique |
| 34 | + private boolean sable$noDrop; |
| 35 | + |
| 36 | + @Inject(method = "dropController", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z"), cancellable = true) |
| 37 | + public void dropController(final BlockState state, final CallbackInfo ci) { |
| 38 | + if (!this.sable$noDrop) { |
| 39 | + return; |
| 40 | + } |
| 41 | + |
| 42 | + ci.cancel(); |
| 43 | + final Entity entity = ((ServerLevel) this.level).getEntity(this.user); |
| 44 | + if (entity instanceof final Player player) { |
| 45 | + this.stopUsing(player); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public void sable$setNoDrop() { |
| 51 | + this.sable$noDrop = true; |
| 52 | + } |
| 53 | +} |
0 commit comments