Java Code Examples for org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable#cancel()

The following examples show how to use org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable#cancel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MixinMinecraft.java    From VanillaFix with MIT License 6 votes vote down vote up
/** @reason Implement F3 + S to toggle between client and integrated server profilers. */
@Inject(method = "processKeyF3", at = @At("HEAD"), cancellable = true)
private void checkF3S(int auxKey, CallbackInfoReturnable<Boolean> cir) {
    if (auxKey == Keyboard.KEY_S) {
        if (integratedServer != null) {
            useIntegratedServerProfiler = !useIntegratedServerProfiler;
            if (useIntegratedServerProfiler) {
                debugFeedbackTranslated("vanillafix.debug.switch_profiler.server");
            } else {
                debugFeedbackTranslated("vanillafix.debug.switch_profiler.client");
            }
        }
        cir.setReturnValue(true);
        cir.cancel();
    }
}
 
Example 2
Source File: ContainerMixin.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Inject( method = "onSlotClick", at = @At(value = "HEAD"), cancellable = true)
private void onThrowClick( int slotId, int clickData, SlotActionType actionType, PlayerEntity playerEntity, CallbackInfoReturnable<ItemStack> cir)
{
    if (actionType == SlotActionType.THROW && CarpetSettings.ctrlQCraftingFix && playerEntity.inventory.getCursorStack().isEmpty() && slotId >= 0)
    {
        ItemStack itemStack_1 = ItemStack.EMPTY;
        Slot slot_4 = slots.get(slotId);
        if (slot_4 != null && slot_4.hasStack() && slot_4.canTakeItems(playerEntity))
        {
            if(slotId == 0 && clickData == 1)
            {
                Item craftedItem = slot_4.getStack().getItem();
                while(slot_4.hasStack() && slot_4.getStack().getItem() == craftedItem)
                {
                    this.onSlotClick(slotId, 0, SlotActionType.THROW, playerEntity);
                }
                this.sendContentUpdates();
                cir.setReturnValue(itemStack_1);
                cir.cancel();
            }
        }
    }
}
 
Example 3
Source File: MixinPlayerChat_SayCommand.java    From Galaxy with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("UnresolvedMixinReference")
@Inject(
    method = "method_13563",
    at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/PlayerManager;broadcastChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V",
        ordinal = 0
    ),
    locals = LocalCapture.CAPTURE_FAILSOFT
)
private static void onCommand(CommandContext<ServerCommandSource> context, CallbackInfoReturnable<Integer> cir, Text text, TranslatableText translatableText, Entity entity) {
    if (!(entity instanceof ServerPlayerEntity)) return;

    Main main = Main.Companion.getMain();
    ServerPlayerEntity player = (ServerPlayerEntity) entity;

    if (main == null || !main.getEventManager().emit(new PlayerChatEvent(player, translatableText)).getCancel()) {
        player.server.getPlayerManager().broadcastChatMessage(translatableText, MessageType.CHAT, entity.getUuid());
    } else {
        cir.setReturnValue(0);
        cir.cancel();
        player.server.sendSystemMessage(translatableText.append(" (Canceled)"), entity.getUuid());
    }
}
 
Example 4
Source File: MixinWorld.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Inject(method = "getCollisionBoxes(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/AxisAlignedBB;ZLjava/util/List;)Z", at = @At("HEAD"), cancellable = true)
private void preGetCollisionBoxes(@Nullable Entity entityIn, AxisAlignedBB aabb,
    boolean p_191504_3_,
    @Nullable List<AxisAlignedBB> outList, CallbackInfoReturnable<Boolean> callbackInfo) {
    double deltaX = Math.abs(aabb.maxX - aabb.minX);
    double deltaY = Math.abs(aabb.maxY - aabb.minY);
    double deltaZ = Math.abs(aabb.maxZ - aabb.minZ);
    if (Math.max(deltaX, Math.max(deltaY, deltaZ)) > 99999D) {
        System.err.println(entityIn + "\ntried going extremely fast during the collision step");
        new Exception().printStackTrace();
        callbackInfo.setReturnValue(Boolean.FALSE);
        callbackInfo.cancel();
    }
}
 
Example 5
Source File: MixinBlock.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "isShapeFullCube", at = @At("HEAD"), cancellable = true)
private static void isShapeFullCube(VoxelShape voxelShape_1, CallbackInfoReturnable<Boolean> callback) {
    if (ModuleManager.getModule(Xray.class).isToggled()) {
        callback.setReturnValue(false);
        callback.cancel();
    }
}
 
Example 6
Source File: MixinNetworkPlayerInfo.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "getLocationSkin", cancellable = true, at = @At("HEAD"))
private void injectSkinProtect(CallbackInfoReturnable<ResourceLocation> cir) {
    NameProtect nameProtect = (NameProtect) LiquidBounce.moduleManager.getModule(NameProtect.class);

    if (nameProtect.getState() && nameProtect.skinProtectValue.get()) {
        if (nameProtect.allPlayersValue.get() || Objects.equals(gameProfile.getId(), Minecraft.getMinecraft().getSession().getProfile().getId())) {
            cir.setReturnValue(DefaultPlayerSkin.getDefaultSkin(this.gameProfile.getId()));
            cir.cancel();
        }
    }

}
 
Example 7
Source File: MixinBlockModelRenderer.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "tesselate", at = @At("HEAD"), cancellable = true)
private void tesselate(ExtendedBlockView extendedBlockView_1, BakedModel bakedModel_1, BlockState blockState_1, BlockPos blockPos_1, BufferBuilder bufferBuilder_1, boolean boolean_1, Random random_1, long long_1, CallbackInfoReturnable<Boolean> ci) {
    try {
        Xray xray = (Xray) ModuleManager.getModule(Xray.class);
        if (!xray.isVisible(blockState_1.getBlock())) {
            ci.setReturnValue(false);
            ci.cancel();
        }
    } catch (Exception ignored) {}
}
 
Example 8
Source File: MixinFluidRenderer.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "method_3344", at = @At("HEAD"), cancellable = true)
private static void method_3344(BlockView blockView_1, BlockPos blockPos_1, Direction direction_1, float float_1, CallbackInfoReturnable<Boolean> callbackInfo) {
    Xray xray = (Xray) ModuleManager.getModule(Xray.class);
    if (xray.getSettings().get(0).toToggle().state) return;
    if (xray.isToggled() && xray.isVisible(blockView_1.getBlockState(blockPos_1).getBlock())) {
        callbackInfo.setReturnValue(false);
        callbackInfo.cancel();
    }
}
 
Example 9
Source File: ShearsItem_missingToolsMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "getMiningSpeed", at = @At("HEAD"), cancellable = true)
private void getCustomMaterial(ItemStack itemStack_1, BlockState blockState_1, CallbackInfoReturnable<Float> cir)
{
    if (CarpetSettings.missingTools && (blockState_1.getMaterial() == Material.SPONGE))
    {
        cir.setReturnValue(15.0F);
        cir.cancel();
    }
}
 
Example 10
Source File: MixinBlock.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "isFullOpaque", at = @At("HEAD"), cancellable = true)
public void isFullOpaque(BlockState blockState_1, BlockView blockView_1, BlockPos blockPos_1, CallbackInfoReturnable<Boolean> callback) {
    try {
        Xray xray = (Xray) ModuleManager.getModule(Xray.class);
        if (xray.isToggled()) {
            callback.setReturnValue(xray.isVisible(blockState_1.getBlock()));
            callback.cancel();
        }
    } catch (Exception ignored) {}
}
 
Example 11
Source File: MixinBlock.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "shouldDrawSide", at = @At("HEAD"), cancellable = true)
private static void shouldDrawSide(BlockState blockState_1, BlockView blockView_1, BlockPos blockPos_1, Direction direction_1, CallbackInfoReturnable<Boolean> callback) {
    try {
        Xray xray = (Xray) ModuleManager.getModule(Xray.class);
        if (xray.isToggled()) {
            callback.setReturnValue(xray.isVisible(blockState_1.getBlock()));
            callback.cancel();
        }
    } catch (Exception ignored) {}
}
 
Example 12
Source File: MixinEntity.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Inject(method = "getPositionEyes(F)Lnet/minecraft/util/math/Vec3d;", at = @At("HEAD"), cancellable = true)
public void getPositionEyesInject(float partialTicks,
    CallbackInfoReturnable<Vec3d> callbackInfo) {
    EntityShipMountData mountData = ValkyrienUtils
        .getMountedShipAndPos(Entity.class.cast(this));

    if (mountData.isMounted()) {
        Vector playerPosition = new Vector(mountData.getMountPos());
        mountData.getMountedShip()
            .getShipTransformationManager()
            .getRenderTransform()
            .transform(playerPosition,
                TransformType.SUBSPACE_TO_GLOBAL);

        Vector playerEyes = new Vector(0, this.getEyeHeight(), 0);
        // Remove the original position added for the player's eyes
        // RotationMatrices.doRotationOnly(wrapper.wrapping.coordTransform.lToWTransform,
        // playerEyes);
        mountData.getMountedShip()
            .getShipTransformationManager()
            .getCurrentTickTransform()
            .rotate(playerEyes, TransformType.SUBSPACE_TO_GLOBAL);
        // Add the new rotate player eyes to the position
        playerPosition.add(playerEyes);
        callbackInfo.setReturnValue(playerPosition.toVec3d());
        callbackInfo.cancel(); // return the value, as opposed to the default one
    }
}
 
Example 13
Source File: MixinBlock.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "isFullOpaque", at = @At("HEAD"), cancellable = true)
public void isFullOpaque(BlockState blockState_1, BlockView blockView_1, BlockPos blockPos_1, CallbackInfoReturnable<Boolean> callback) {
    try {
        Xray xray = (Xray) ModuleManager.getModule(Xray.class);
        if (xray.isToggled()) {
            callback.setReturnValue(xray.isVisible(blockState_1.getBlock()));
            callback.cancel();
        }
    } catch (Exception ignored) {}
}
 
Example 14
Source File: MixinFarmlandBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "hasCrop", cancellable = true, at = @At("HEAD"))
private static void onHasCrop(BlockView world, BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
	final BlockState ourState = world.getBlockState(pos);
	final BlockState cropState = world.getBlockState(pos.up());

	if (cropState.getBlock() instanceof IPlantable && ((IForgeBlockState) ourState).canSustainPlant(world, pos, Direction.UP, (IPlantable) cropState.getBlock())) {
		cir.setReturnValue(true);
		cir.cancel();
	}
}
 
Example 15
Source File: MixinPlantBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "canPlaceAt", at = @At("HEAD"), cancellable = true)
private void onCanPlaceAt(BlockState state, CollisionView world, BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
	if (state.getBlock() == (Object) this) {
		cir.setReturnValue(((IForgeBlockState) world.getBlockState(pos.down())).canSustainPlant(world, pos, Direction.UP, this));
		cir.cancel();
	}
}
 
Example 16
Source File: MixinFluidRenderer.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "isSideCovered", at = @At("HEAD"), cancellable = true)
private static void isSideCovered(BlockView blockView_1, BlockPos blockPos_1, Direction direction_1, float float_1, CallbackInfoReturnable<Boolean> callbackInfo) {
    Xray xray = (Xray) ModuleManager.getModule(Xray.class);
    if (xray.getSettings().get(0).toToggle().state) return;
    if (xray.isToggled() && xray.isVisible(blockView_1.getBlockState(blockPos_1).getBlock())) {
        callbackInfo.setReturnValue(false);
        callbackInfo.cancel();
    }
}
 
Example 17
Source File: ChunkGeneratorMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "hasStructure", at = @At("HEAD"), cancellable = true)
private void skipGenerationBiomeChecks(Biome biome_1, StructureFeature<? extends FeatureConfig> structureFeature_1, CallbackInfoReturnable<Boolean> cir)
{
    if (CarpetSettings.skipGenerationChecks)
    {
        cir.setReturnValue(true);
        cir.cancel();
    }
}
 
Example 18
Source File: MixinFluidRenderer.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "isSideCovered", at = @At("HEAD"), cancellable = true)
private static void isSideCovered(BlockView blockView_1, BlockPos blockPos_1, Direction direction_1, float float_1, CallbackInfoReturnable<Boolean> callbackInfo) {
    Xray xray = (Xray) ModuleManager.getModule(Xray.class);
    if (xray.getSettings().get(0).toToggle().state) return;
    if (xray.isToggled() && xray.isVisible(blockView_1.getBlockState(blockPos_1).getBlock())) {
        callbackInfo.setReturnValue(false);
        callbackInfo.cancel();
    }
}
 
Example 19
Source File: HopperMinecartEntity_cooldownFixMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Inject(method = "canOperate", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/HopperBlockEntity;extract(Lnet/minecraft/inventory/Inventory;Lnet/minecraft/entity/ItemEntity;)Z", shift = At.Shift.BEFORE),cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
private void extractAndReturnSuccess(CallbackInfoReturnable<Boolean> cir, List list_1) {
    if (CarpetExtraSettings.hopperMinecart8gtCooldown) {
        boolean result = HopperBlockEntity.extract(this, (ItemEntity) list_1.get(0));
        cir.setReturnValue(result);
        cir.cancel();
    }
}
 
Example 20
Source File: MixinBlock.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "shouldDrawSide", at = @At("HEAD"), cancellable = true)
private static void shouldDrawSide(BlockState blockState_1, BlockView blockView_1, BlockPos blockPos_1, Direction direction_1, CallbackInfoReturnable<Boolean> callback) {
    try {
        Xray xray = (Xray) ModuleManager.getModule(Xray.class);
        if (xray.isToggled()) {
            callback.setReturnValue(xray.isVisible(blockState_1.getBlock()));
            callback.cancel();
        }
    } catch (Exception ignored) {}
}