org.spongepowered.asm.mixin.injection.callback.CallbackInfo Java Examples

The following examples show how to use org.spongepowered.asm.mixin.injection.callback.CallbackInfo. 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: ClientPlayerEntityMixin.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
@Inject(at = @At("HEAD"),
	method = "sendChatMessage(Ljava/lang/String;)V",
	cancellable = true)
private void onSendChatMessage(String message, CallbackInfo ci)
{
	ChatOutputEvent event = new ChatOutputEvent(message);
	WurstClient.INSTANCE.getEventManager().fire(event);
	
	if(event.isCancelled())
	{
		ci.cancel();
		return;
	}
	
	if(!event.isModified())
		return;
	
	ChatMessageC2SPacket packet =
		new ChatMessageC2SPacket(event.getMessage());
	networkHandler.sendPacket(packet);
	ci.cancel();
}
 
Example #2
Source File: MultiplayerScreenMixin.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
@Inject(at = {@At("TAIL")}, method = {"init()V"})
private void onInit(CallbackInfo ci)
{
	if(!WurstClient.INSTANCE.isEnabled())
		return;
	
	lastServerButton = addButton(new ButtonWidget(width / 2 - 154, 10, 100,
		20, new LiteralText("Last Server"), b -> LastServerRememberer
			.joinLastServer((MultiplayerScreen)(Object)this)));
	
	addButton(new ButtonWidget(width / 2 + 154 + 4, height - 52, 100, 20,
		new LiteralText("Server Finder"), b -> client.openScreen(
			new ServerFinderScreen((MultiplayerScreen)(Object)this))));
	
	addButton(new ButtonWidget(width / 2 + 154 + 4, height - 28, 100, 20,
		new LiteralText("Clean Up"), b -> client.openScreen(
			new CleanUpScreen((MultiplayerScreen)(Object)this))));
}
 
Example #3
Source File: DisconnectedScreenMixin.java    From Wurst7 with GNU General Public License v3.0 6 votes vote down vote up
@Inject(at = {@At("TAIL")}, method = {"init()V"})
private void onInit(CallbackInfo ci)
{
	if(!WurstClient.INSTANCE.isEnabled())
		return;
	
	int backButtonX = width / 2 - 100;
	int backButtonY =
		Math.min(height / 2 + reasonHeight / 2 + 9, height - 30);
	
	addButton(new ButtonWidget(backButtonX, backButtonY + 24, 200, 20,
		new LiteralText("Reconnect"),
		b -> LastServerRememberer.reconnect(parent)));
	
	autoReconnectButton =
		addButton(new ButtonWidget(backButtonX, backButtonY + 48, 200, 20,
			new LiteralText("AutoReconnect"), b -> pressAutoReconnect()));
	
	if(WurstClient.INSTANCE.getHax().autoReconnectHack.isEnabled())
		autoReconnectTimer = 100;
}
 
Example #4
Source File: MixinGuiMultiplayer.java    From LiquidBounce with GNU General Public License v3.0 6 votes vote down vote up
@Inject(method = "actionPerformed", at = @At("HEAD"))
private void actionPerformed(GuiButton button, CallbackInfo callbackInfo) {
    switch(button.id) {
        case 997:
            mc.displayGuiScreen(new GuiAntiForge((GuiScreen) (Object) this));
            break;
        case 998:
            BungeeCordSpoof.enabled = !BungeeCordSpoof.enabled;
            bungeeCordSpoofButton.displayString = "BungeeCord Spoof: " + (BungeeCordSpoof.enabled ? "On" : "Off");
            LiquidBounce.fileManager.saveConfig(LiquidBounce.fileManager.valuesConfig);
            break;
        case 999:
            mc.displayGuiScreen(new GuiTools((GuiScreen) (Object) this));
            break;
    }
}
 
Example #5
Source File: PistonBlockEntityRenderer_movableTEMixin.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Inject(method = "render", at = @At("RETURN"), locals = LocalCapture.NO_CAPTURE)
private void endMethod3576(PistonBlockEntity pistonBlockEntity_1, float partialTicks, MatrixStack matrixStack_1, VertexConsumerProvider layeredVertexConsumerStorage_1, int int_1, int init_2, CallbackInfo ci)
{
    if (((PistonBlockEntityInterface) pistonBlockEntity_1).getRenderCarriedBlockEntity())
    {
        BlockEntity carriedBlockEntity = ((PistonBlockEntityInterface) pistonBlockEntity_1).getCarriedBlockEntity();
        if (carriedBlockEntity != null)
        {
            carriedBlockEntity.setPos(pistonBlockEntity_1.getPos());
            //((BlockEntityRenderDispatcherInterface) BlockEntityRenderDispatcher.INSTANCE).renderBlockEntityOffset(carriedBlockEntity, float_1, int_1, BlockRenderLayer.field_20799, bufferBuilder_1, pistonBlockEntity_1.getRenderOffsetX(float_1), pistonBlockEntity_1.getRenderOffsetY(float_1), pistonBlockEntity_1.getRenderOffsetZ(float_1));
            matrixStack_1.translate(
                    pistonBlockEntity_1.getRenderOffsetX(partialTicks),
                    pistonBlockEntity_1.getRenderOffsetY(partialTicks),
                    pistonBlockEntity_1.getRenderOffsetZ(partialTicks)
            );
            BlockEntityRenderDispatcher.INSTANCE.render(carriedBlockEntity, partialTicks, matrixStack_1, layeredVertexConsumerStorage_1);

        }
    }
}
 
Example #6
Source File: ChunkOcclusionGraphBuilderMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(at = {@At("HEAD")},
	method = {"markClosed(Lnet/minecraft/util/math/BlockPos;)V"},
	cancellable = true)
private void onMarkClosed(BlockPos pos, CallbackInfo ci)
{
	SetOpaqueCubeEvent event = new SetOpaqueCubeEvent();
	WurstClient.INSTANCE.getEventManager().fire(event);
	
	if(event.isCancelled())
		ci.cancel();
}
 
Example #7
Source File: MixinEntityPlayerSP.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "swingItem", at = @At("HEAD"), cancellable = true)
private void swingItem(CallbackInfo callbackInfo) {
    final NoSwing noSwing = (NoSwing) LiquidBounce.moduleManager.getModule(NoSwing.class);

    if (noSwing.getState()) {
        callbackInfo.cancel();

        if (!noSwing.getServerSideValue().get())
            this.sendQueue.addToSendQueue(new C0APacketAnimation());
    }
}
 
Example #8
Source File: ServerPlayNetworkHandler_scarpetEventsMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "onPlayerInteractEntity", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/network/ServerPlayerEntity;interact(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;"
))
private void onEntityInteract(PlayerInteractEntityC2SPacket playerInteractEntityC2SPacket_1, CallbackInfo ci)
{
    PLAYER_INTERACTS_WITH_ENTITY.onEntityAction(player, playerInteractEntityC2SPacket_1.getEntity(player.getServerWorld()), playerInteractEntityC2SPacket_1.getHand());
}
 
Example #9
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 #10
Source File: ServerWorld_tickMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "tick", at = @At(
        value = "CONSTANT",
        args = "stringValue=world border"
))
private void stopWeatherStartChunkSection(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
{
    if (currentSection != null)
    {
        CarpetProfiler.end_current_section(currentSection);
        // we go deeper here
    }
}
 
Example #11
Source File: LivingEntityMixin.java    From the-hallow with MIT License 5 votes vote down vote up
@Inject(method = "applyDamage(Lnet/minecraft/entity/damage/DamageSource;F)V", at = @At("RETURN"))
public void applyDamage(DamageSource damageSource, float damage, CallbackInfo info) {
	LivingEntity attacked = (LivingEntity) (Object) this;
	if (damageSource.getSource() instanceof LivingEntity && attacked.getHealth() < damage) {
		LivingEntity attacker = (LivingEntity) damageSource.getSource();
		if (!attacked.isInvulnerableTo(damageSource)) {
			float health = LifestealEnchantment.getLifeWithSteal(damageSource, damage, attacked);
			if (health != 0) {
				attacker.setHealth(health);
			}
		}
	}
}
 
Example #12
Source File: MixinClientPlayNetworkHandler.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "onCustomPayload", 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 onOnCustomPayload(CustomPayloadS2CPacket packet, CallbackInfo ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_13_2) {
        Identifier channel = packet.getChannel();
        if (Protocol_1_13_2.CUSTOM_PAYLOAD_TRADE_LIST.equals(channel)) {
            PacketByteBuf buf = packet.getData();
            int syncId = buf.readInt();
            TraderOfferList trades = new TraderOfferList();
            int tradeCount = buf.readUnsignedByte();
            for (int i = 0; i < tradeCount; i++) {
                ItemStack buy = buf.readItemStack();
                ItemStack sell = buf.readItemStack();
                boolean hasSecondItem = buf.readBoolean();
                ItemStack secondBuy = hasSecondItem ? buf.readItemStack() : ItemStack.EMPTY;
                boolean locked = buf.readBoolean();
                int tradeUses = buf.readInt();
                int maxTradeUses = buf.readInt();
                TradeOffer trade = new TradeOffer(buy, secondBuy, sell, tradeUses, maxTradeUses, 0, 1);
                if (locked)
                    trade.clearUses();
                trades.add(trade);
            }
            onSetTradeOffers(new SetTradeOffersS2CPacket(syncId, trades, 5, 0, false, false));
            ci.cancel();
        } else if (Protocol_1_13_2.CUSTOM_PAYLOAD_OPEN_BOOK.equals(channel)) {
            OpenWrittenBookS2CPacket openBookPacket = new OpenWrittenBookS2CPacket();
            try {
                openBookPacket.read(packet.getData());
            } catch (IOException e) {
                LOGGER.error("Failed to read open book packet", e);
            }
            onOpenWrittenBook(openBookPacket);
            ci.cancel();
        }
    }
}
 
Example #13
Source File: MixinBootstrapClient.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Inject(method = "initialize", at = @At("HEAD"))
private static void init(CallbackInfo info) {
    if (!initialized) {
        SandboxCommon.client = (Client) MinecraftClient.getInstance();
        SandboxHooks.setupGlobal();
    }
}
 
Example #14
Source File: ServerPlayNetworkHandler_scarpetEventsMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "onPlayerAction", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/network/ServerPlayerEntity;dropSelectedItem(Z)Z",
        ordinal = 0,
        shift = At.Shift.BEFORE
))
private void onQItem(PlayerActionC2SPacket playerActionC2SPacket_1, CallbackInfo ci)
{
    PLAYER_DROPS_ITEM.onPlayerEvent(player);
}
 
Example #15
Source File: ClientPlayerEntity_clientCommandMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "sendChatMessage", at = @At("HEAD"))
private void inspectMessage(String string, CallbackInfo ci)
{
    if (string.startsWith("/call"))
    {
        String command = string.substring(6);
        CarpetClient.sendClientCommand(command);
    }
    if (CarpetServer.minecraft_server == null && !CarpetClient.isCarpet())
    {
        ClientPlayerEntity playerSource = (ClientPlayerEntity)(Object) this;
        CarpetServer.settingsManager.inspectClientsideCommand(playerSource.getCommandSource(), string);
    }
}
 
Example #16
Source File: MixinGuiInGame.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "renderTooltip", at = @At("RETURN"))
private void renderTooltipPost(ScaledResolution sr, float partialTicks, CallbackInfo callbackInfo) {
    if (!ClassUtils.hasClass("net.labymod.api.LabyModAPI")) {
        LiquidBounce.eventManager.callEvent(new Render2DEvent(partialTicks));
        AWTFontRenderer.Companion.garbageCollectionTick();
    }
}
 
Example #17
Source File: MixinClientConnection.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "channelRead0", at = @At("HEAD"), cancellable = true)
public void channelRead0(ChannelHandlerContext channelHandlerContext_1, Packet<?> packet_1, CallbackInfo callback) {
    if (this.channel.isOpen() && packet_1 != null) {
    	try {
            EventReadPacket event = new EventReadPacket(packet_1);
            BleachHack.eventBus.post(event);
            if (event.isCancelled()) callback.cancel();
        } catch (Exception exception) {}
    }
}
 
Example #18
Source File: MixinClientConnection.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "exceptionCaught(Lio/netty/channel/ChannelHandlerContext;Ljava/lang/Throwable;)V", at = @At("HEAD"), cancellable = true)
public void exceptionCaught(ChannelHandlerContext channelHandlerContext_1, Throwable throwable_1, CallbackInfo callback) {
	if (!ModuleManager.getModule(AntiChunkBan.class).isToggled()) return;
	
	if (!(throwable_1 instanceof PacketEncoderException)) {
		BleachLogger.warningMessage("Canceled Defect Packet: " + throwable_1);
    	callback.cancel();
	}
}
 
Example #19
Source File: MixinJigsawBlockScreen.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "init", at = @At("RETURN"))
private void onInit(CallbackInfo ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_15_2) {
        nameField.active = false;
        jointRotationButton.active = false;
        int index = buttons.indexOf(jointRotationButton);
        buttons.get(index + 1).active = false; // levels slider
        buttons.get(index + 2).active = false; // keep jigsaws toggle
        buttons.get(index + 3).active = false; // generate button
    }
}
 
Example #20
Source File: ItemEntityMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method="<init>(Lnet/minecraft/world/World;DDDLnet/minecraft/item/ItemStack;)V", at = @At("RETURN"))
private void removeEmptyShulkerBoxTags(World worldIn, double x, double y, double z, ItemStack stack, CallbackInfo ci)
{
    if (CarpetSettings.stackableShulkerBoxes
            && stack.getItem() instanceof BlockItem
            && ((BlockItem)stack.getItem()).getBlock() instanceof ShulkerBoxBlock)
    {
        if (InventoryHelper.cleanUpShulkerBoxTag(stack)) {
            ((ItemEntity) (Object) this).setStack(stack);
        }
    }
}
 
Example #21
Source File: MixinMinecraft.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "startGame", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;displayGuiScreen(Lnet/minecraft/client/gui/GuiScreen;)V", shift = At.Shift.AFTER))
private void afterMainScreen(CallbackInfo callbackInfo) {
    if (LiquidBounce.fileManager.firstStart)
        Minecraft.getMinecraft().displayGuiScreen(new GuiWelcome());
    else if (LiquidBounce.INSTANCE.getLatestVersion() > LiquidBounce.CLIENT_VERSION - (LiquidBounce.IN_DEV ? 1 : 0))
        Minecraft.getMinecraft().displayGuiScreen(new GuiUpdate());
}
 
Example #22
Source File: MixinRendererLivingEntity.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "doRender", at = @At("RETURN"))
private <T extends EntityLivingBase> void injectChamsPost(T entity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo callbackInfo) {
    final Chams chams = (Chams) LiquidBounce.moduleManager.getModule(Chams.class);

    if (chams.getState() && chams.getTargetsValue().get() && EntityUtils.isSelected(entity, false)) {
        GL11.glPolygonOffset(1.0F, 1000000F);
        GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
    }
}
 
Example #23
Source File: MixinClientConnection.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "send(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;)V", at = @At("HEAD"), cancellable = true)
  public void send(Packet<?> packet_1, GenericFutureListener<? extends Future<? super Void>> genericFutureListener_1, CallbackInfo callback) {
  	if (packet_1 instanceof ChatMessageC2SPacket) {
	ChatMessageC2SPacket pack = (ChatMessageC2SPacket) packet_1;
	if (pack.getChatMessage().startsWith(CommandManager.prefix)) {
   		CommandManager.callCommand(pack.getChatMessage().substring(CommandManager.prefix.length()));
   		callback.cancel();
	}
}
  	
  	EventSendPacket event = new EventSendPacket(packet_1);
      BleachHack.eventBus.post(event);

      if (event.isCancelled()) callback.cancel();
  }
 
Example #24
Source File: MixinTileEntityMobSpawnerRenderer.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "renderMob", cancellable = true, at = @At("HEAD"))
private static void injectPaintingSpawnerFix(MobSpawnerBaseLogic mobSpawnerLogic, double posX, double posY, double posZ, float partialTicks, CallbackInfo ci) {
    Entity entity = mobSpawnerLogic.func_180612_a(mobSpawnerLogic.getSpawnerWorld());

    if (entity == null || entity instanceof EntityPainting)
        ci.cancel();
}
 
Example #25
Source File: ItemStackMixin.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "<init>(Lnet/minecraft/nbt/CompoundTag;)V", at = @At("RETURN"))
private void deserializeCapabilities(CompoundTag tag, CallbackInfo callbackInfo) {
	// TODO: See above TODO
	gatherCapabilities(null);

	if (tag.contains("ForgeCaps")) {
		deserializeCaps(tag.getCompound("ForgeCaps"));
	}
}
 
Example #26
Source File: MixinLivingEntity.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "drop", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/LivingEntity;playerHitTimer : I"), locals = LocalCapture.CAPTURE_FAILHARD)
private void hookDropForCapturePre(DamageSource src, CallbackInfo info, int lootingLevel) {
	IForgeEntity forgeEntity = (IForgeEntity) this;
	forgeEntity.captureDrops(new ArrayList<>());

	dropLootingLevel.set(lootingLevel);
}
 
Example #27
Source File: MixinTitleScreen.java    From OptiFabric with Mozilla Public License 2.0 5 votes vote down vote up
@Inject(method = "render", at = @At("RETURN"))
private void render(int int_1, int int_2, float float_1, CallbackInfo info) {
	if (!OptifabricError.hasError()) {
		float fadeTime = this.doBackgroundFade ? (float) (Util.getMeasuringTimeMs() - this.backgroundFadeStart) / 1000.0F : 1.0F;
		float fadeColor = this.doBackgroundFade ? MathHelper.clamp(fadeTime - 1.0F, 0.0F, 1.0F) : 1.0F;

		int int_6 = MathHelper.ceil(fadeColor * 255.0F) << 24;
		if ((int_6 & -67108864) != 0) {
			this.drawString(this.font, OptifineVersion.version, 2, this.height - 20, 16777215 | int_6);
		}
	}
}
 
Example #28
Source File: ClientPlayerEntityMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(at = @At(value = "INVOKE",
	target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;tick()V",
	ordinal = 0), method = "tick()V")
private void onTick(CallbackInfo ci)
{
	WurstClient.INSTANCE.getEventManager().fire(UpdateEvent.INSTANCE);
}
 
Example #29
Source File: MixinRenderEntityItem.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "doRender", at = @At("HEAD"))
private void injectChamsPre(CallbackInfo callbackInfo) {
    final Chams chams = (Chams) LiquidBounce.moduleManager.getModule(Chams.class);

    if (chams.getState() && chams.getItemsValue().get()) {
        GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
        GL11.glPolygonOffset(1.0F, -1000000F);
    }
}
 
Example #30
Source File: ServerPlayNetworkHandler_scarpetEventsMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "onPlayerAction", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/network/ServerPlayerInteractionManager;processBlockBreakingAction(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/network/packet/c2s/play/PlayerActionC2SPacket$Action;Lnet/minecraft/util/math/Direction;I)V",
        shift = At.Shift.BEFORE
))
private void onClicked(PlayerActionC2SPacket packet, CallbackInfo ci)
{
    if (packet.getAction() == PlayerActionC2SPacket.Action.START_DESTROY_BLOCK)
        PLAYER_CLICKS_BLOCK.onBlockAction(player, packet.getPos(), packet.getDirection());
}