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

The following examples show how to use org.spongepowered.asm.mixin.injection.callback.CallbackInfo#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: MixinServerPlayNetworkHandler.java    From Sandbox with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Inject(method = "onCustomPayload", at = @At("HEAD"), cancellable = true)
public void onCustomPayload(CustomPayloadC2SPacket c2s, CallbackInfo info) {
    NetworkThreadUtils.forceMainThread(c2s, (ServerPlayNetworkHandler) (Object) this, this.player.getServerWorld());
    CustomPayloadPacket customPayloadPacket = (CustomPayloadPacket) c2s;
    PacketByteBuf data = null;
    try {
        Identifier channel = customPayloadPacket.channel();
        if (!channel.getNamespace().equals("minecraft")) { //Override non-vanilla packets
            Class<? extends Packet> packetClass = NetworkManager.get(channel);
            if (packetClass != null) {
                data = customPayloadPacket.data();
                Packet packet = packetClass.getConstructor().newInstance();
                packet.read(data);
                packet.apply();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (data != null) {
            data.release();
            info.cancel();
        }
    }
}
 
Example 2
Source File: ServerWorld_onePlayerSleepingMixin.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Inject(method = "updatePlayersSleeping", cancellable = true, at = @At("HEAD"))
private void updateOnePlayerSleeping(CallbackInfo ci)
{
    if(CarpetSettings.onePlayerSleeping)
    {
        allPlayersSleeping = false;
        for (ServerPlayerEntity p : players)
            if (!p.isSpectator() && p.isSleeping())
            {
                allPlayersSleeping = true;
                ci.cancel();
                return;
            }
        ci.cancel();
    }
}
 
Example 3
Source File: MixinGuiChat.java    From LiquidBounce with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds client command auto completion and cancels sending an auto completion request packet
 * to the server if the message contains a client command.
 *
 * @author NurMarvin
 */
@Inject(method = "sendAutocompleteRequest", at = @At("HEAD"), cancellable = true)
private void handleClientCommandCompletion(String full, final String ignored, CallbackInfo callbackInfo) {
    if (LiquidBounce.commandManager.autoComplete(full)) {
        waitingOnAutocomplete = true;

        String[] latestAutoComplete = LiquidBounce.commandManager.getLatestAutoComplete();

        if (full.toLowerCase().endsWith(latestAutoComplete[latestAutoComplete.length - 1].toLowerCase()))
            return;

        this.onAutocompleteResponse(latestAutoComplete);

        callbackInfo.cancel();
    }
}
 
Example 4
Source File: MixinMinecraft.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "setWindowIcon", at = @At("HEAD"), cancellable = true)
private void setWindowIcon(CallbackInfo callbackInfo) {
    if(Util.getOSType() != Util.EnumOS.OSX) {
        final ByteBuffer[] liquidBounceFavicon = IconUtils.getFavicon();
        if(liquidBounceFavicon != null) {
            Display.setIcon(liquidBounceFavicon);
            callbackInfo.cancel();
        }
    }
}
 
Example 5
Source File: MixinServerWorld.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "init", cancellable = true, at = @At(value = "INVOKE", target = "net/minecraft/world/gen/chunk/ChunkGenerator.getBiomeSource ()Lnet/minecraft/world/biome/source/BiomeSource;"))
private void hookInitForCreateWorldSpawn(LevelInfo levelInfo, CallbackInfo info) {
	ServerWorld world = (ServerWorld) (Object) this;

	if (WorldEvents.onCreateWorldSpawn(world, levelInfo)) {
		info.cancel();
	}
}
 
Example 6
Source File: FallingBlockEntityMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Inject(
        method = "tick",
        at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 1,
                target = "Lnet/minecraft/entity/FallingBlockEntity;setVelocity(Lnet/minecraft/util/math/Vec3d;)V"),
        locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true
)
private void onTick(CallbackInfo ci, Block block_1, BlockPos blockPos_2, boolean b1, boolean bl2, BlockState blockState_1)
{
    if (block_1.matches(BlockTags.ANVIL))
    {
        if (CarpetExtraSettings.renewablePackedIce && this.world.getBlockState(new BlockPos(this.getX(), this.getY() - 0.059999999776482582D, this.getZ())).getBlock() == Blocks.ICE)
        {
            if (iceCount < 2)
            {
                world.breakBlock(blockPos_2.down(), false, null);
                this.onGround = false;
                iceCount++;
                ci.cancel();
            }
            else
            {
                world.setBlockState(blockPos_2.down(), Blocks.PACKED_ICE.getDefaultState(), 3);
                world.playLevelEvent(2001, blockPos_2.down(), Block.getRawIdFromState(Blocks.PACKED_ICE.getDefaultState()));
            }
        }
        else if (CarpetExtraSettings.renewableSand && this.world.getBlockState(new BlockPos(this.getX(), this.getY() - 0.06, this.getZ())).getBlock() == Blocks.COBBLESTONE)
        {
            world.breakBlock(blockPos_2.down(1), false);
            world.setBlockState(blockPos_2.down(1), Blocks.SAND.getDefaultState(), 3);
        }
    }
}
 
Example 7
Source File: MixinContainerScreen.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(at = @At("RETURN"), method = "render(IIF)V")
public void render(int int_1, int int_2, float float_1, CallbackInfo info) {
	EventDrawContainer event = new EventDrawContainer(
			(ContainerScreen<?>) MinecraftClient.getInstance().currentScreen, int_1, int_2); // hmm
	BleachHack.eventBus.post(event);
	if (event.isCancelled()) info.cancel();
}
 
Example 8
Source File: MixinGuiConnecting.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "connect", at = @At(value = "NEW", target = "net/minecraft/network/login/client/C00PacketLoginStart"), cancellable = true)
private void mcLeaks(CallbackInfo callbackInfo) {
    if(MCLeaks.isAltActive()) {
        networkManager.sendPacket(new C00PacketLoginStart(new GameProfile(null, MCLeaks.getSession().getUsername())));
        callbackInfo.cancel();
    }
}
 
Example 9
Source File: MixinClientWorld.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "setBlockStateWithoutNeighborUpdates", at = @At("HEAD"), cancellable = true)
private void onSetBlockWithoutNeighborUpdates(BlockPos pos, BlockState state, CallbackInfo ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) {
        ((ClientWorld) (Object) this).setBlockState(pos, state);
        ci.cancel();
    }
}
 
Example 10
Source File: MixinKeyboard.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "onKey", at = @At(value = "INVOKE", target = "net/minecraft/client/util/InputUtil.isKeyPressed(JI)Z", ordinal = 5), cancellable = true)
private void onKeyEvent(long windowPointer, int key, int scanCode, int action, int modifiers, CallbackInfo callbackInfo) {
	if (InputUtil.getKeycodeName(InputUtil.getKeyCode(key, scanCode).getKeyCode()) != null && InputUtil.getKeycodeName(InputUtil.getKeyCode(key, scanCode).getKeyCode()).equals(CommandManager.prefix)) {
        MinecraftClient.getInstance().openScreen(new ChatScreen(CommandManager.prefix));
    }
	
    EventKeyPress event = new EventKeyPress(key, scanCode);
	BleachHack.eventBus.post(event);
	if (event.isCancelled()) callbackInfo.cancel();
}
 
Example 11
Source File: MixinMouse.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "onMouseScroll", at = @At(value = "INVOKE",
				target = "Lnet/minecraft/client/gui/screen/Screen;mouseScrolled(DDD)Z",
				ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private void preMouseScrolled(long window, double xOffset, double yOffset, CallbackInfo info, double amount, double mouseX, double mouseY) {
	if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseScrollEvent.Pre(client.currentScreen, mouseX, mouseY, amount))) {
		info.cancel();
	}
}
 
Example 12
Source File: ItemEntityMixin.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "merge", at = @At("HEAD"), cancellable = true)
private static void merge(ItemEntity targetEntity, ItemStack targetStack, ItemEntity sourceEntity, ItemStack sourceStack, CallbackInfo callbackInfo) {
	CapabilityProviderHolder source = (CapabilityProviderHolder) (Object) sourceStack;
	CapabilityProviderHolder target = (CapabilityProviderHolder) (Object) targetStack;

	if (!source.areCapsCompatible(target.getCapabilityProvider())) {
		callbackInfo.cancel();
	}
}
 
Example 13
Source File: MixinEntity.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "setAngles", at = @At("HEAD"), cancellable = true)
private void setAngles(final float yaw, final float pitch, final CallbackInfo callbackInfo) {
    if (LiquidBounce.moduleManager.getModule(NoPitchLimit.class).getState()) {
        callbackInfo.cancel();

        float f = this.rotationPitch;
        float f1 = this.rotationYaw;
        this.rotationYaw = (float) ((double) this.rotationYaw + (double) yaw * 0.15D);
        this.rotationPitch = (float) ((double) this.rotationPitch - (double) pitch * 0.15D);
        this.prevRotationPitch += this.rotationPitch - f;
        this.prevRotationYaw += this.rotationYaw - f1;
    }
}
 
Example 14
Source File: MixinEntity.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "setAngles", at = @At("HEAD"), cancellable = true)
private void setAngles(final float yaw, final float pitch, final CallbackInfo callbackInfo) {
    if (LiquidBounce.moduleManager.getModule(NoPitchLimit.class).getState()) {
        callbackInfo.cancel();

        float f = this.rotationPitch;
        float f1 = this.rotationYaw;
        this.rotationYaw = (float) ((double) this.rotationYaw + (double) yaw * 0.15D);
        this.rotationPitch = (float) ((double) this.rotationPitch - (double) pitch * 0.15D);
        this.prevRotationPitch += this.rotationPitch - f;
        this.prevRotationYaw += this.rotationYaw - f1;
    }
}
 
Example 15
Source File: MixinClientPlayNetworkHandler.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "onCommandSuggestions", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkThreadUtils;forceMainThread(Lnet/minecraft/network/Packet;Lnet/minecraft/network/listener/PacketListener;Lnet/minecraft/util/thread/ThreadExecutor;)V", shift = At.Shift.AFTER), cancellable = true)
private void onOnCommandSuggestions(CommandSuggestionsS2CPacket packet, CallbackInfo ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) {
        if (TabCompletionManager.handleCustomCompletions(packet))
            ci.cancel();
    }
}
 
Example 16
Source File: MixinVisGraph.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
@Inject(method = "func_178606_a", at = @At("HEAD"), cancellable = true)
private void func_178606_a(final CallbackInfo callbackInfo) {
    if (LiquidBounce.moduleManager.getModule(XRay.class).getState())
        callbackInfo.cancel();
}
 
Example 17
Source File: ChunkRegion_scarpetPlopMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Inject(method = "markBlockForPostProcessing", at = @At("HEAD"))
private void markOrNot(BlockPos blockPos, CallbackInfo ci)
{
    if (CarpetSettings.skipGenerationChecks) ci.cancel();
}
 
Example 18
Source File: MixinEntity.java    From multiconnect with MIT License 4 votes vote down vote up
@Inject(method = "setSwimming", at = @At("HEAD"), cancellable = true)
private void onSetSwimming(boolean swimming, CallbackInfo ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2 && swimming)
        ci.cancel();
}
 
Example 19
Source File: MixinNetworkManager.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
@Inject(method = "channelRead0", at = @At("HEAD"), cancellable = true)
private void read(ChannelHandlerContext context, Packet<?> packet, CallbackInfo callback) {
    final PacketEvent event = new PacketEvent(packet);
    LiquidBounce.eventManager.callEvent(event);

    if(event.isCancelled())
        callback.cancel();
}
 
Example 20
Source File: MixinItemEntity.java    From multiconnect with MIT License 4 votes vote down vote up
@Inject(method = "applyBuoyancy", at = @At("HEAD"),cancellable = true)
private void applyBuoyancy(CallbackInfo ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) {
        ci.cancel();
    }
}