diff --git a/src/main/java/carpet/mixins/BlockItem_creativeNoClipMixin.java b/src/main/java/carpet/mixins/BlockItem_creativeNoClipMixin.java new file mode 100644 index 00000000..f8c84c69 --- /dev/null +++ b/src/main/java/carpet/mixins/BlockItem_creativeNoClipMixin.java @@ -0,0 +1,36 @@ +package carpet.mixins; + +import carpet.CarpetSettings; +import net.minecraft.block.BlockState; +import net.minecraft.entity.EntityContext; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.BlockItem; +import net.minecraft.item.ItemPlacementContext; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(BlockItem.class) +public class BlockItem_creativeNoClipMixin +{ + @Redirect(method = "canPlace", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/World;canPlace(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/EntityContext;)Z" + )) + private boolean canSpectatingPlace(World world, BlockState state, BlockPos pos, EntityContext context, + ItemPlacementContext contextOuter, BlockState stateOuter) + { + PlayerEntity player = contextOuter.getPlayer(); + if (CarpetSettings.creativeNoClip && player != null && player.isCreative() && player.abilities.flying) + { + // copy from canPlace + VoxelShape voxelShape = state.getCollisionShape(world, pos, context); + return voxelShape.isEmpty() || world.intersectsEntities(player, voxelShape.offset(pos.getX(), pos.getY(), pos.getZ())); + + } + return world.canPlace(state, pos, context); + } +} diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index 83bfb498..a88cc7d2 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -159,7 +159,8 @@ "WorldChunk_movableTEMixin", "PistonHandler_movableTEMixin", "PlayerEntity_creativeNoClipMixin", - "PistonBlockEntity_creativeNoClipMixin" + "PistonBlockEntity_creativeNoClipMixin", + "BlockItem_creativeNoClipMixin" ], "client": [