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

The following examples show how to use org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable#setReturnValue() . 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: MixinBlockItem.java    From Sandbox with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Inject(method = "place(Lnet/minecraft/item/ItemPlacementContext;Lnet/minecraft/block/BlockState;)Z",
        at = @At(value = "HEAD"),
        cancellable = true
)
public void place(ItemPlacementContext context, BlockState state, CallbackInfoReturnable<Boolean> info) {
    BlockEvent.Place event = EventDispatcher.publish(new BlockEvent.Place(
            (World) context.getWorld(),
            (Position) context.getBlockPos(),
            (org.sandboxpowered.sandbox.api.state.BlockState) state
    ));
    BlockState state2 = WrappingUtil.convert(event.getState());
    if (event.isCancelled()) {
        info.setReturnValue(false);
    } else if (state2 != state) {
        info.setReturnValue(context.getWorld().setBlockState(context.getBlockPos(), state2, 11));
    }
}
 
Example 3
Source File: MixinParticleManager.java    From multiconnect with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Inject(method = "createParticle", at = @At("HEAD"), cancellable = true)
private <T extends ParticleEffect> void onCreateParticle(T effect, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, CallbackInfoReturnable<Particle> ci) {
    ParticleFactory<T> customFactory = (ParticleFactory<T>) customFactories.get(Registry.PARTICLE_TYPE.getId(effect.getType()));
    if (customFactory != null)
        ci.setReturnValue(customFactory.createParticle(effect, world, x, y, z, xSpeed, ySpeed, zSpeed));
}
 
Example 4
Source File: MixinDefaultPlayerSkin.java    From MineLittlePony with MIT License 5 votes vote down vote up
@Inject(method = "getModel(Ljava/util/UUID;)Ljava/lang/String;",
        at = @At("HEAD"),
        cancellable = true)
private static void skinType(UUID uuid, CallbackInfoReturnable<String> cir) {
    if (MineLittlePony.getInstance().getConfig().ponyLevel.get() == PonyLevel.PONIES) {

        cir.setReturnValue(PlayerModels.forRace(MineLittlePony.getInstance().getManager()
                .getPony(IPonyManager.getDefaultSkin(uuid), uuid)
                .getRace(false))
                .getId(IPonyManager.isSlimSkin(uuid)));
    }
}
 
Example 5
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 6
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 7
Source File: MixinAbstractClientPlayer.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "getLocationSkin()Lnet/minecraft/util/ResourceLocation;", at = @At("HEAD"), cancellable = true)
private void getSkin(CallbackInfoReturnable<ResourceLocation> callbackInfoReturnable) {
    final NameProtect nameProtect = (NameProtect) LiquidBounce.moduleManager.getModule(NameProtect.class);

    if(nameProtect.getState() && nameProtect.skinProtectValue.get()) {
        if (!nameProtect.allPlayersValue.get() && !Objects.equals(getGameProfile().getName(), Minecraft.getMinecraft().thePlayer.getGameProfile().getName()))
            return;

        callbackInfoReturnable.setReturnValue(DefaultPlayerSkin.getDefaultSkin(getUniqueID()));
    }
}
 
Example 8
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 9
Source File: MixinBlock.java    From LiquidBounce with 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 10
Source File: AbstractTreeFeatureMixin.java    From the-hallow with MIT License 5 votes vote down vote up
@Inject(method = "isNaturalDirtOrGrass(Lnet/minecraft/world/TestableWorld;Lnet/minecraft/util/math/BlockPos;)Z", at = @At(value = "HEAD"), cancellable = true)
private static void isNaturalDeceased(TestableWorld testableWorld, BlockPos blockPos, CallbackInfoReturnable<Boolean> cir) {
	if (testableWorld.testBlockState(blockPos, (blockState) -> {
		Block block = blockState.getBlock();
		return block == HallowedBlocks.DECEASED_GRASS_BLOCK || block == HallowedBlocks.DECEASED_DIRT;
	})) cir.setReturnValue(true);
}
 
Example 11
Source File: MixinAbstractClientPlayer.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "getLocationSkin()Lnet/minecraft/util/ResourceLocation;", at = @At("HEAD"), cancellable = true)
private void getSkin(CallbackInfoReturnable<ResourceLocation> callbackInfoReturnable) {
    final NameProtect nameProtect = (NameProtect) LiquidBounce.moduleManager.getModule(NameProtect.class);

    if(nameProtect.getState() && nameProtect.skinProtectValue.get()) {
        if (!nameProtect.allPlayersValue.get() && !Objects.equals(getGameProfile().getName(), Minecraft.getMinecraft().thePlayer.getGameProfile().getName()))
            return;

        callbackInfoReturnable.setReturnValue(DefaultPlayerSkin.getDefaultSkin(getUniqueID()));
    }
}
 
Example 12
Source File: MixinFlowerPotBlock.java    From multiconnect with 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 13
Source File: MixinDimension.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(at = @At("HEAD"), method = "getCloudHeight", cancellable = true)
private void getCloudHeight(CallbackInfoReturnable<Float> info) {
	LevelGeneratorType generatorType = this.world.getLevelProperties().getGeneratorType();

	if (generatorType instanceof PatchworkLevelGeneratorType) {
		info.setReturnValue(((IForgeWorldType) generatorType).getCloudHeight());
	}
}
 
Example 14
Source File: MixinSpawnHelper.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "canSpawn(Lnet/minecraft/entity/SpawnRestriction$Location;Lnet/minecraft/world/CollisionView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/EntityType;)Z",
		at = @At(value = "INVOKE", target = "net/minecraft/world/CollisionView.getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;"),
		cancellable = true)
private static void handleCustomSpawnRestrictionLocation(SpawnRestriction.Location location, CollisionView world, BlockPos pos, EntityType<?> type, CallbackInfoReturnable<Boolean> callback) {
	PatchworkSpawnRestrictionLocation patchworkLocation = (PatchworkSpawnRestrictionLocation) (Object) location;

	if (patchworkLocation.patchwork_useVanillaBehavior()) {
		return;
	}

	callback.setReturnValue(patchworkLocation.canSpawnAt(world, pos, type));
}
 
Example 15
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 16
Source File: MixinEntityLivingBase.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
@Inject(method = "getLook", at = @At("HEAD"), cancellable = true)
private void getLook(CallbackInfoReturnable<Vec3> callbackInfoReturnable) {
    if(((EntityLivingBase) (Object) this) instanceof EntityPlayerSP)
        callbackInfoReturnable.setReturnValue(getVectorForRotation(this.rotationPitch, this.rotationYaw));
}
 
Example 17
Source File: MixinCompiledChunk.java    From MinecraftX-RAY with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Inject(method = "isVisible", at=@At("HEAD"), cancellable = true)
private void onIsVisible(EnumFacing facing, EnumFacing facing2, CallbackInfoReturnable<Boolean> ci) {
    if (UyjuliansXrayModMain.xrayEnabled()) {
        ci.setReturnValue(true);
    }
}
 
Example 18
Source File: MixinEntityType.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Inject(method = "getTrackTickInterval", at = @At("HEAD"), cancellable = true)
private void hookGetTrackTickInterval(CallbackInfoReturnable<Integer> cir) {
	if (updateInterval != null) {
		cir.setReturnValue(updateInterval);
	}
}
 
Example 19
Source File: VillagerEntity_aiMixin.java    From fabric-carpet with MIT License 4 votes vote down vote up
@Inject(method = "interactMob", at = @At("HEAD"), cancellable = true)
private void onInteract(PlayerEntity playerEntity_1, Hand hand_1, CallbackInfoReturnable<Boolean> cir)
{
    if (MobAI.isTracking(this, MobAI.TrackingType.VILLAGER_BREEDING))
    {
        ItemStack itemStack_1 = playerEntity_1.getStackInHand(hand_1);
        if (itemStack_1.getItem() == Items.EMERALD)
        {
            GlobalPos bedPos = this.brain.getOptionalMemory(MemoryModuleType.HOME).orElse(null);
            if (bedPos == null || bedPos.getDimension() != dimension)
            {
                sayNo();
                ((ServerWorld) getEntityWorld()).spawnParticles(ParticleTypes.BARRIER, getX(), getY() + getStandingEyeHeight() + 1, getZ(), 1, 0.1, 0.1, 0.1, 0.0);
            }
            else
            {

                ParticleDisplay.drawParticleLine((ServerPlayerEntity) playerEntity_1, getPos(), new Vec3d(bedPos.getPos()).add(0.5, 0.5, 0.5), "dust 0 0 0 1", "happy_villager", 100, 0.2);
            }
        }
        else if (itemStack_1.getItem() == Items.ROTTEN_FLESH)
        {
            while(getAvailableFood() >= 12) eatForBreeding();

        }
        else if (itemStack_1.getItem() instanceof BedItem)
        {
            List<PointOfInterest> list_1 = ((ServerWorld) getEntityWorld()).getPointOfInterestStorage().get(
                    type -> type == PointOfInterestType.HOME,
                    getBlockPos(),
                    48, PointOfInterestStorage.OccupationStatus.ANY).collect(Collectors.toList());
            for (PointOfInterest poi : list_1)
            {
                Vec3d pv = new Vec3d(poi.getPos()).add(0.5, 0.5, 0.5);
                if (!poi.hasSpace())
                {
                    ((ServerWorld) getEntityWorld()).spawnParticles(ParticleTypes.HAPPY_VILLAGER,
                            pv.x, pv.y+1.5, pv.z,
                            50, 0.1, 0.3, 0.1, 0.0);
                }
                else if (canReachHome((VillagerEntity)(Object)this, poi.getPos()))
                    ((ServerWorld) getEntityWorld()).spawnParticles(ParticleTypes.END_ROD,
                            pv.x, pv.y+1, pv.z,
                            50, 0.1, 0.3, 0.1, 0.0);
                else
                    ((ServerWorld) getEntityWorld()).spawnParticles(ParticleTypes.BARRIER,
                            pv.x, pv.y+1, pv.z,
                            1, 0.1, 0.1, 0.1, 0.0);
            }
        }
        cir.setReturnValue(false);
        cir.cancel();
    }
}
 
Example 20
Source File: MixinWorld.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void setLightValueBoolean(CallbackInfoReturnable<Boolean> cir) {
    if (Settings.FULLBRIGHT && !Minecraft.getMinecraft().isIntegratedServerRunning()) cir.setReturnValue(false);
}