org.spongepowered.asm.mixin.injection.Inject Java Examples

The following examples show how to use org.spongepowered.asm.mixin.injection.Inject. 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
@SuppressWarnings("UnresolvedMixinReference")
@Inject(method = "dispenseSilently(Lnet/minecraft/util/math/BlockPointer;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;", at = @At("HEAD"), cancellable = true)
private void convertNetherrack(BlockPointer pointer, ItemStack stack, CallbackInfoReturnable<ItemStack> cir)
{
    if (!CarpetExtraSettings.fireChargeConvertsToNetherrack)
        return;
    World world = pointer.getWorld();
    Direction direction = pointer.getBlockState().get(DispenserBlock.FACING);
    BlockPos front = pointer.getBlockPos().offset(direction);
    BlockState state = world.getBlockState(front);
    if (state.getBlock() == Blocks.COBBLESTONE)
    {
        world.setBlockState(front, Blocks.NETHERRACK.getDefaultState());
        stack.decrement(1);
        cir.setReturnValue(stack);
        cir.cancel();
    }
}
 
Example #2
Source Project: the-hallow   Author: fabric-community   File: PlayerEntityMixin.java    License: MIT License 6 votes vote down vote up
@Inject(at = @At(
	value = "INVOKE",
	target = "Lnet/minecraft/entity/player/HungerManager;eat(Lnet/minecraft/item/Item;Lnet/minecraft/item/ItemStack;)V",
	shift = At.Shift.AFTER
), method = "eatFood(Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;")
private void addPumpkinRingBonus(World world, ItemStack itemStack, CallbackInfoReturnable<ItemStack> info) {
	PlayerEntity playerEntity = (PlayerEntity) (Object) this;
	TrinketComponent trinketPlayer = TrinketsApi.getTrinketComponent(playerEntity);
	
	ItemStack mainHandStack = trinketPlayer.getStack("hand:ring");
	ItemStack offHandStack = trinketPlayer.getStack("offhand:ring");
	Item item = itemStack.getItem();
	
	if (mainHandStack.getItem().equals(HallowedItems.PUMPKIN_RING) || offHandStack.getItem().equals(HallowedItems.PUMPKIN_RING)) {
		if (item.isFood()) {
			if (item.isIn(HallowedTags.Items.PUMPKIN_FOODS)) {
				FoodComponent foodComponent = item.getFoodComponent();
				int extraHunger = (int) Math.ceil(foodComponent.getHunger() * .25);
				this.hungerManager.add(extraHunger, 1);
			}
		}
	}
}
 
Example #3
Source Project: fabric-carpet   Author: gnembon   File: ExperienceOrbEntityMixin.java    License: MIT License 6 votes vote down vote up
@Inject(method = "tick",
        at = @At(
                value = "INVOKE",
                target = "Lnet/minecraft/entity/ExperienceOrbEntity;move(Lnet/minecraft/entity/MovementType;Lnet/minecraft/util/math/Vec3d;)V",
                shift = At.Shift.AFTER
        ))
void checkCombineAtTick(CallbackInfo ci)
{
    if (CarpetSettings.combineXPOrbs)
    {
        if (getCombineDelay() > 0)
        {
            setCombineDelay(getCombineDelay()-1);
        }

        if (getCombineDelay() == 0)
        {
            XPcombine.searchForOtherXPNearby((ExperienceOrbEntity) (Object) this);
        }
    }
}
 
Example #4
Source Project: Sandbox   Author: SandboxPowered   File: MixinClientPlayNetworkHandler.java    License: GNU Lesser General Public License v3.0 6 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, remap = false), cancellable = true)
public void onCustomPayload(CustomPayloadS2CPacket s2c, CallbackInfo info) {
    CustomPayloadPacket customPayloadPacket = (CustomPayloadPacket) s2c;
    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 #5
Source Project: patchwork-api   Author: PatchworkMC   File: MixinClientWorld.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "addEntityPrivate", at = @At("HEAD"), cancellable = true)
private void onEntityAdded(int id, Entity entity, CallbackInfo callback) {
	World world = (World) (Object) this;

	if (EntityEvents.onEntityJoinWorld(entity, world)) {
		callback.cancel();
	}
}
 
Example #6
Source Project: Sandbox   Author: SandboxPowered   File: MixinBootstrapClient.java    License: 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 #7
Source Project: LiquidBounce   Author: CCBlueX   File: MixinBlockModelRenderer.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "renderModelAmbientOcclusion", at = @At("HEAD"), cancellable = true)
private void renderModelAmbientOcclusion(IBlockAccess blockAccessIn, IBakedModel modelIn, Block blockIn, BlockPos blockPosIn, WorldRenderer worldRendererIn, boolean checkSide, final CallbackInfoReturnable<Boolean> booleanCallbackInfoReturnable) {
    final XRay xray = (XRay) LiquidBounce.moduleManager.getModule(XRay.class);

    if (xray.getState() && !xray.getXrayBlocks().contains(blockIn))
        booleanCallbackInfoReturnable.setReturnValue(false);
}
 
Example #8
Source Project: LiquidBounce   Author: CCBlueX   File: MixinTileEntityChestRenderer.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "renderTileEntityAt", at = @At("RETURN"))
private void injectChamsPost(CallbackInfo callbackInfo) {
    final Chams chams = (Chams) LiquidBounce.moduleManager.getModule(Chams.class);

    if (chams.getState() && chams.getChestsValue().get()) {
        GL11.glPolygonOffset(1.0F, 1000000F);
        GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
    }
}
 
Example #9
Source Project: fabric-carpet   Author: gnembon   File: ServerPlayerInteractionManager_scarpetEventsMixin.java    License: MIT License 5 votes vote down vote up
@Inject(method = "tryBreakBlock", locals = LocalCapture.CAPTURE_FAILEXCEPTION, at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/block/Block;onBroken(Lnet/minecraft/world/IWorld;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V",
        shift = At.Shift.BEFORE
))
private void onBlockBroken(BlockPos blockPos_1, CallbackInfoReturnable<Boolean> cir, BlockState blockState_1, BlockEntity be, Block b, boolean boolean_1)
{
    PLAYER_BREAK_BLOCK.onBlockBroken(player, blockPos_1, blockState_1);
}
 
Example #10
Source Project: multiconnect   Author: Earthcomputer   File: MixinJigsawBlockScreen.java    License: 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 #11
Source Project: LiquidBounce   Author: CCBlueX   File: MixinRendererLivingEntity.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "doRender", at = @At("HEAD"))
private <T extends EntityLivingBase> void injectChamsPre(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.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
        GL11.glPolygonOffset(1.0F, -1000000F);
    }
}
 
Example #12
Source Project: fabric-carpet   Author: gnembon   File: ServerPlayNetworkHandler_interactionUpdatesMixin.java    License: 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.AFTER
))
private void afterBlockBroken(PlayerActionC2SPacket packet, CallbackInfo ci)
{
    if (!CarpetSettings.interactionUpdates)
        CarpetSettings.impendingFillSkipUpdates = false;
}
 
Example #13
Source Project: the-hallow   Author: fabric-community   File: WitchEntityMixin.java    License: MIT License 5 votes vote down vote up
@Inject(method = "tickMovement()V", at = @At("HEAD"), cancellable = true)
public void tick(CallbackInfo info) {
	ActionResult result = WitchTickCallback.EVENT.invoker().tick((WitchEntity) (Object) this);
	if (result == ActionResult.FAIL) {
		info.cancel();
	}
}
 
Example #14
Source Project: LiquidBounce   Author: CCBlueX   File: MixinEntityLivingBase.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "isPotionActive(Lnet/minecraft/potion/Potion;)Z", at = @At("HEAD"), cancellable = true)
private void isPotionActive(Potion p_isPotionActive_1_, final CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
    final AntiBlind antiBlind = (AntiBlind) LiquidBounce.moduleManager.getModule(AntiBlind.class);

    if((p_isPotionActive_1_ == Potion.confusion || p_isPotionActive_1_ == Potion.blindness) && antiBlind.getState() && antiBlind.getConfusionEffect().get())
        callbackInfoReturnable.setReturnValue(false);
}
 
Example #15
Source Project: fabric-carpet   Author: gnembon   File: ServerWorld_tickMixin.java    License: MIT License 5 votes vote down vote up
@Inject(method = "tick", at = @At(
        value = "CONSTANT",
        args = "stringValue=tickPending"
))
private void stopVillageStartBlockAgainSection(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
{
    if (currentSection != null)
    {
        CarpetProfiler.end_current_section(currentSection);
        currentSection = CarpetProfiler.start_section((World) (Object) this, "Blocks", CarpetProfiler.TYPE.GENERAL);
    }
}
 
Example #16
Source Project: LiquidBounce   Author: CCBlueX   File: MixinBlock.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "shouldSideBeRendered", at = @At("HEAD"), cancellable = true)
private void shouldSideBeRendered(CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
    final XRay xray = (XRay) LiquidBounce.moduleManager.getModule(XRay.class);

    if(xray.getState())
        callbackInfoReturnable.setReturnValue(xray.getXrayBlocks().contains(this));
}
 
Example #17
Source Project: LiquidBounce   Author: CCBlueX   File: MixinMinecraft.java    License: 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 #18
Source Project: multiconnect   Author: Earthcomputer   File: MixinFlowerPotBlock.java    License: MIT License 5 votes vote down vote up
@Inject(method = "onUse", at = @At(value = "FIELD", target = "Lnet/minecraft/block/FlowerPotBlock;content:Lnet/minecraft/block/Block;", ordinal = 0), cancellable = true)
private void cancelEmptyingFlowerPot(CallbackInfoReturnable<ActionResult> ci) {
    // TODO: this doesn't fully work, WTF?!
    if (ConnectionInfo.protocolVersion <= Protocols.V1_10 && content != Blocks.AIR) {
        ci.setReturnValue(ActionResult.CONSUME);
    }
}
 
Example #19
Source Project: patchwork-api   Author: PatchworkMC   File: MixinThreadedAnvilChunkStorage.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "sendWatchPackets", at = @At("HEAD"))
private void fireWatchEvents(ServerPlayerEntity player, ChunkPos pos, Packet<?>[] packets, boolean withinMaxWatchDistance, boolean withinViewDistance, CallbackInfo callback) {
	if (withinViewDistance && !withinMaxWatchDistance) {
		ChunkWatchEvent.Watch event = new ChunkWatchEvent.Watch(player, pos, world);

		MinecraftForge.EVENT_BUS.post(event);
	}
}
 
Example #20
Source Project: Sandbox   Author: SandboxPowered   File: MixinFluidRenderer.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Inject(at = @At("RETURN"), method = "onResourceReload")
public void reload(CallbackInfo info) {
    SpriteAtlasTexture spriteAtlasTexture_1 = (SpriteAtlasTexture) MinecraftClient.getInstance().getTextureManager().getTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX);
    spriteMap.clear();
    Registry.FLUID.forEach(fluid -> {
        if (fluid instanceof FluidWrapper) {
            Sprite[] sprites = new Sprite[2];
            sprites[0] = spriteAtlasTexture_1.getSprite(WrappingUtil.convert(((FluidWrapper) fluid).fluid.getTexturePath(false)));
            sprites[1] = spriteAtlasTexture_1.getSprite(WrappingUtil.convert(((FluidWrapper) fluid).fluid.getTexturePath(true)));
            spriteMap.put(((FluidWrapper) fluid).fluid, sprites);
        }
    });
}
 
Example #21
Source Project: the-hallow   Author: fabric-community   File: AbstractSkeletonEntityMixin.java    License: MIT License 5 votes vote down vote up
@Inject(method = "initEquipment(Lnet/minecraft/world/LocalDifficulty;)V", at = @At(value = "TAIL"))
protected void initEquipment(LocalDifficulty ld, CallbackInfo cb) {
	Random random = new Random();
	if (HallowedConfig.TrumpetSkeleton.enabled && random.nextInt(HallowedConfig.TrumpetSkeleton.chance) == 0) {
		//noinspection ConstantConditions
		((AbstractSkeletonEntity) (Object) this).equipStack(EquipmentSlot.MAINHAND, new ItemStack(HallowedItems.TRUMPET));
	}
}
 
Example #22
Source Project: LiquidBounce   Author: CCBlueX   File: MixinMinecraft.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "run", at = @At("HEAD"))
private void init(CallbackInfo callbackInfo) {
    if(displayWidth < 1067)
        displayWidth = 1067;

    if(displayHeight < 622)
        displayHeight = 622;
}
 
Example #23
Source Project: patchwork-api   Author: PatchworkMC   File: MixinPlayerEntity.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "onDeath", at = @At("HEAD"), cancellable = true)
private void hookDeath(DamageSource source, CallbackInfo callback) {
	LivingEntity entity = (LivingEntity) (Object) this;

	if (EntityEvents.onLivingDeath(entity, source)) {
		callback.cancel();
	}
}
 
Example #24
Source Project: LiquidBounce   Author: CCBlueX   File: MixinGuiScreen.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "handleComponentHover", at = @At("HEAD"))
private void handleHoverOverComponent(IChatComponent component, int x, int y, final CallbackInfo callbackInfo) {
    if (component == null || component.getChatStyle().getChatClickEvent() == null || !LiquidBounce.moduleManager.getModule(ComponentOnHover.class).getState())
        return;

    final ChatStyle chatStyle = component.getChatStyle();

    final ClickEvent clickEvent = chatStyle.getChatClickEvent();
    final HoverEvent hoverEvent = chatStyle.getChatHoverEvent();

    drawHoveringText(Collections.singletonList("§c§l" + clickEvent.getAction().getCanonicalName().toUpperCase() + ": §a" + clickEvent.getValue()), x, y - (hoverEvent != null ? 17 : 0));
}
 
Example #25
Source Project: LiquidBounce   Author: CCBlueX   File: MixinMinecraft.java    License: 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 #26
Source Project: Wurst7   Author: Wurst-Imperium   File: MinecraftClientMixin.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Inject(at = {@At("HEAD")},
	method = {"getSession()Lnet/minecraft/client/util/Session;"},
	cancellable = true)
private void onGetSession(CallbackInfoReturnable<Session> cir)
{
	if(wurstSession == null)
		return;
	
	cir.setReturnValue(wurstSession);
}
 
Example #27
Source Project: multiconnect   Author: Earthcomputer   File: MixinClientChunkManager.java    License: MIT License 5 votes vote down vote up
@Inject(method = "loadChunkFromPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/WorldChunk;getSectionArray()[Lnet/minecraft/world/chunk/ChunkSection;"))
private void recalculateHeightmaps(int x, int z, BiomeArray biomeArray, PacketByteBuf buf, CompoundTag tag, int verticalStripMask, boolean bl, CallbackInfoReturnable<WorldChunk> ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_13_2) {
        WorldChunk chunk = this.chunk.get();
        for (ChunkSection section : chunk.getSectionArray()) {
            if (section != null) {
                section.calculateCounts();
            }
        }
        Heightmap.populateHeightmaps(chunk, CLIENT_HEIGHTMAPS);
    }
    this.chunk.set(null);
}
 
Example #28
Source Project: LiquidBounce   Author: CCBlueX   File: MixinGuiConnecting.java    License: 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 #29
Source Project: LiquidBounce   Author: CCBlueX   File: MixinBlockSoulSand.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "onEntityCollidedWithBlock", at = @At("HEAD"), cancellable = true)
private void onEntityCollidedWithBlock(CallbackInfo callbackInfo) {
    final NoSlow noSlow = (NoSlow) LiquidBounce.moduleManager.getModule(NoSlow.class);

    if(noSlow.getState() && noSlow.getSoulsandValue().get())
        callbackInfo.cancel();
}
 
Example #30
Source Project: fabric-carpet   Author: gnembon   File: PlayerEntity_parrotMixin.java    License: MIT License 5 votes vote down vote up
@Inject(method = "tickMovement", at = @At(value = "INVOKE", shift = At.Shift.AFTER, ordinal = 1,
        target = "Lnet/minecraft/entity/player/PlayerEntity;updateShoulderEntity(Lnet/minecraft/nbt/CompoundTag;)V"))
private void onTickMovement(CallbackInfo ci)
{
    boolean parrots_will_drop = !CarpetSettings.persistentParrots || this.abilities.invulnerable;
    if (!this.world.isClient && ((parrots_will_drop && this.fallDistance > 0.5F) || this.isTouchingWater() || this.abilities.flying || isSleeping()))
    {
        this.dropShoulderEntities();
    }
}