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
Source File: DispenserBehaviorFireChargeMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 7 votes vote down vote up
@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 File: MixinClientPlayNetworkHandler.java    From Sandbox with 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 #3
Source File: ExperienceOrbEntityMixin.java    From fabric-carpet with 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 File: PlayerEntityMixin.java    From the-hallow with 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 #5
Source File: MixinServerPlayerInteractionManager.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Inject(method = "tryBreakBlock", at = @At("HEAD"), cancellable = true)
public void tryBreakBlock(BlockPos pos, CallbackInfoReturnable<Boolean> info) {
    BlockEvent.Break event = EventDispatcher.publish(new BlockEvent.Break(
            (World) world,
            (Position) pos,
            (BlockState) world.getBlockState(pos),
            WrappingUtil.convert(this.player)));
    if (event.isCancelled()) {
        info.setReturnValue(false);
    }
}
 
Example #6
Source File: BlockMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(at = {@At("HEAD")},
	method = {"getVelocityMultiplier()F"},
	cancellable = true)
private void onGetVelocityMultiplier(CallbackInfoReturnable<Float> cir)
{
	HackList hax = WurstClient.INSTANCE.getHax();
	if(hax == null || !hax.noSlowdownHack.isEnabled())
		return;
	
	if(cir.getReturnValueF() < 1)
		cir.setReturnValue(1F);
}
 
Example #7
Source File: ServerPlayerEntityMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "<init>", at = @At(value = "RETURN"))
private void onServerPlayerEntityContructor(
        MinecraftServer minecraftServer_1,
        ServerWorld serverWorld_1,
        GameProfile gameProfile_1,
        ServerPlayerInteractionManager serverPlayerInteractionManager_1,
        CallbackInfo ci)
{
    this.actionPack = new EntityPlayerActionPack((ServerPlayerEntity) (Object) this);
}
 
Example #8
Source File: MixinMinecraft.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "runGameLoop", at = @At("HEAD"))
private void runGameLoop(final CallbackInfo callbackInfo) {
    final long currentTime = getTime();
    final int deltaTime = (int) (currentTime - lastFrame);
    lastFrame = currentTime;

    RenderUtils.deltaTime = deltaTime;
}
 
Example #9
Source File: ExplosionMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "collectBlocksAndDamageEntities", at = @At("HEAD"),
        cancellable = true)
private void onExplosionA(CallbackInfo ci)
{
    if (CarpetSettings.optimizedTNT)
    {
        OptimizedExplosion.doExplosionA((Explosion) (Object) this, eLogger);
        ci.cancel();
    }
}
 
Example #10
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 #11
Source File: MixinPlayerEntity.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "attack(Lnet/minecraft/entity/Entity;)V", at = @At("HEAD"), cancellable = true)
private void onAttackEntity(Entity target, CallbackInfo callback) {
	PlayerEntity player = (PlayerEntity) (Object) this;

	if (!EntityEvents.attackEntity(player, target)) {
		callback.cancel();
	}
}
 
Example #12
Source File: WorldMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(at = {@At("HEAD")},
	method = {"getRainGradient(F)F"},
	cancellable = true)
private void onGetRainGradient(float f, CallbackInfoReturnable<Float> cir)
{
	if(WurstClient.INSTANCE.getHax().noWeatherHack.isRainDisabled())
		cir.setReturnValue(0F);
}
 
Example #13
Source File: GameMenuScreenMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(at = {@At("TAIL")},
	method = {"render(Lnet/minecraft/client/util/math/MatrixStack;IIF)V"})
private void onRender(MatrixStack matrixStack, int mouseX, int mouseY,
	float partialTicks, CallbackInfo ci)
{
	if(!WurstClient.INSTANCE.isEnabled())
		return;
	
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glEnable(GL11.GL_CULL_FACE);
	GL11.glDisable(GL11.GL_DEPTH_TEST);
	GL11.glDepthMask(false);
	GL11.glEnable(GL11.GL_BLEND);
	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	GL11.glColor4f(1, 1, 1, 1);
	
	client.getTextureManager().bindTexture(wurstTexture);
	
	int x = wurstOptionsButton.x + 34;
	int y = wurstOptionsButton.y + 2;
	int w = 63;
	int h = 16;
	int fw = 63;
	int fh = 16;
	float u = 0;
	float v = 0;
	drawTexture(matrixStack, x, y, u, v, w, h, fw, fh);
}
 
Example #14
Source File: ChunkSerializerMixin.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "serialize", slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;saveToTag(Lnet/minecraft/nbt/CompoundTag;)Z"), to = @At(value = "INVOKE", target = "Lnet/minecraft/world/chunk/ProtoChunk;getEntities()Ljava/util/List;")), at = @At(value = "JUMP", opcode = Opcodes.GOTO, ordinal = 2), locals = LocalCapture.CAPTURE_FAILHARD)
private static void serializeCapabilities(ServerWorld serverWorld, Chunk chunk, CallbackInfoReturnable<CompoundTag> callbackInfoReturnable, ChunkPos chunkPos, CompoundTag compoundTag, CompoundTag level) {
	CompoundTag tag = ((CapabilityProviderHolder) chunk).serializeCaps();

	if (tag != null) {
		level.put("ForgeCaps", tag);
	}
}
 
Example #15
Source File: MixinBlockAnvil.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "onBlockPlaced", cancellable = true, at = @At("HEAD"))
private void injectAnvilCrashFix(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, CallbackInfoReturnable<IBlockState> cir) {
    if (((meta >> 2) & ~0x3) != 0) {
        cir.setReturnValue(super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(BlockAnvil.FACING, placer.getHorizontalFacing().rotateY()).withProperty(BlockAnvil.DAMAGE, 2));
        cir.cancel();
    }
}
 
Example #16
Source File: MixinMouse.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "method_1605", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD)
private void postMouseReleased(boolean[] handled, double mouseX, double mouseY, int button, CallbackInfo info) {
	if (handled[0]) {
		return;
	}

	if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseReleasedEvent.Post(client.currentScreen, mouseX, mouseY, button))) {
		handled[0] = true;
		info.cancel();
	}
}
 
Example #17
Source File: World_tickMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "tickEntity", at = @At("HEAD"), cancellable = true)
private void startEntity(Consumer<Entity> consumer_1, Entity e, CallbackInfo ci)
{
    if (!TickSpeed.process_entities && !(e instanceof PlayerEntity))
        ci.cancel();
    entitySection =  CarpetProfiler.start_entity_section((World) (Object) this, e, CarpetProfiler.TYPE.ENTITY);
}
 
Example #18
Source File: MixinBlockAnvil.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "onBlockPlaced", cancellable = true, at = @At("HEAD"))
private void injectAnvilCrashFix(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, CallbackInfoReturnable<IBlockState> cir) {
    if (((meta >> 2) & ~0x3) != 0) {
        cir.setReturnValue(super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer).withProperty(BlockAnvil.FACING, placer.getHorizontalFacing().rotateY()).withProperty(BlockAnvil.DAMAGE, 2));
        cir.cancel();
    }
}
 
Example #19
Source File: MixinClientPlayNetworkHandler.java    From multiconnect with MIT License 5 votes vote down vote up
@Inject(method = "onChunkData", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/ChunkDataS2CPacket;getReadBuffer()Lnet/minecraft/network/PacketByteBuf;", shift = At.Shift.AFTER))
private void onChunkDataPost(ChunkDataS2CPacket packet, CallbackInfo ci) {
    if (ConnectionInfo.protocolVersion <= Protocols.V1_13_2) {
        if (!PendingChunkDataPackets.isProcessingQueuedPackets()) {
            LightUpdateS2CPacket lightPacket = new LightUpdateS2CPacket();
            //noinspection ConstantConditions
            LightUpdatePacketAccessor lightPacketAccessor = (LightUpdatePacketAccessor) lightPacket;

            PendingLightData lightData = PendingLightData.getInstance(packet.getX(), packet.getZ());

            lightPacketAccessor.setChunkX(packet.getX());
            lightPacketAccessor.setChunkZ(packet.getZ());

            int blockLightMask = packet.getVerticalStripBitmask() << 1;
            int skyLightMask = world.getDimension().hasSkyLight() ? blockLightMask : 0;
            lightPacketAccessor.setBlockLightMask(blockLightMask);
            lightPacketAccessor.setSkyLightMask(skyLightMask);
            lightPacketAccessor.setBlockLightUpdates(new ArrayList<>());
            lightPacketAccessor.setSkyLightUpdates(new ArrayList<>());

            for (int i = 0; i < 16; i++) {
                byte[] blockData = lightData.getBlockLight(i);
                if (blockData != null)
                    lightPacket.getBlockLightUpdates().add(blockData);
                byte[] skyData = lightData.getSkyLight(i);
                if (skyData != null)
                    lightPacket.getSkyLightUpdates().add(skyData);
            }

            PendingLightData.setInstance(packet.getX(), packet.getZ(), null);

            onLightUpdate(lightPacket);
        }

        if (packet.isFullChunk())
            PendingChunkDataPackets.push(packet);
    }
}
 
Example #20
Source File: MixinModelBiped.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "setRotationAngles", at = @At(value = "FIELD", target = "Lnet/minecraft/client/model/ModelBiped;swingProgress:F"))
private void revertSwordAnimation(float p_setRotationAngles_1_, float p_setRotationAngles_2_, float p_setRotationAngles_3_, float p_setRotationAngles_4_, float p_setRotationAngles_5_, float p_setRotationAngles_6_, Entity p_setRotationAngles_7_, CallbackInfo callbackInfo) {
    if(heldItemRight == 3)
        this.bipedRightArm.rotateAngleY = 0F;

    if (LiquidBounce.moduleManager.getModule(Rotations.class).getState() && RotationUtils.serverRotation != null && p_setRotationAngles_7_ instanceof EntityPlayer
            && p_setRotationAngles_7_.equals(Minecraft.getMinecraft().thePlayer)) {
        this.bipedHead.rotateAngleX = RotationUtils.serverRotation.getPitch() / (180F / (float) Math.PI);
    }
}
 
Example #21
Source File: ClientPlayerInteractionManagerMixin.java    From Wurst7 with GNU General Public License v3.0 5 votes vote down vote up
@Inject(at = {@At("HEAD")},
	method = {"hasExtendedReach()Z"},
	cancellable = true)
private void hasExtendedReach(CallbackInfoReturnable<Boolean> cir)
{
	if(overrideReach)
		cir.setReturnValue(true);
}
 
Example #22
Source File: ServerWorld_tickMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Inject(method = "tick", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/world/ServerWorld;tickBlockEntities()V",
        shift = At.Shift.BEFORE
))
private void endEntitySection(BooleanSupplier booleanSupplier_1, CallbackInfo ci)
{
    CarpetProfiler.end_current_section(currentSection);
}
 
Example #23
Source File: PlayerEntity_parrotMixin.java    From fabric-carpet with 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();
    }
}
 
Example #24
Source File: MixinBlockSoulSand.java    From LiquidBounce with 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 #25
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 #26
Source File: MixinClientChunkManager.java    From multiconnect with 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 #27
Source File: MixinClientWorld.java    From patchwork-api with 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 #28
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 #29
Source File: MixinGuiScreen.java    From LiquidBounce with 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 #30
Source File: MixinPlayerEntity.java    From patchwork-api with 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();
	}
}