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

The following examples show how to use org.spongepowered.asm.mixin.injection.Redirect. 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: SpawnHelperMixin.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Redirect(method = "spawnEntitiesInChunk", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/entity/EntityType;create(Lnet/minecraft/world/World;)Lnet/minecraft/entity/Entity;"
))
private static Entity create(EntityType<?> entityType, World world_1)
{
    if (CarpetSettings.lagFreeSpawning)
    {
        Map<EntityType, Entity> precookedMobs = ((WorldInterface)world_1).getPrecookedMobs();
        if (precookedMobs.containsKey(entityType))
            //this mob has been <init>'s but not used yet
            return precookedMobs.get(entityType);
        Entity e = entityType.create(world_1);
        precookedMobs.put(entityType, e);
        return e;
    }
    return entityType.create(world_1);
}
 
Example #2
Source File: ServerWorld_fakePlayersMixin.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Redirect( method = "removePlayer", at  = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/world/ServerWorld;removeEntity(Lnet/minecraft/entity/Entity;)V"
))
private void crashRemovePlayer(ServerWorld serverWorld, Entity entity_1, ServerPlayerEntity serverPlayerEntity_1)
{
    if ( !(ticking && serverPlayerEntity_1 instanceof EntityPlayerMPFake) )
        serverWorld.removeEntity(entity_1);
    else
        getServer().send(new ServerTask(getServer().getTicks(), () ->
        {
            serverWorld.removeEntity(serverPlayerEntity_1);
            serverPlayerEntity_1.onTeleportationDone();
        }));

}
 
Example #3
Source File: PickaxeItem_missingToolsMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "getMiningSpeed", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/block/BlockState;getMaterial()Lnet/minecraft/block/Material;"
))
private Material getCustomMaterial(BlockState blockState)
{
    Material material = blockState.getMaterial();
    if (CarpetSettings.missingTools && (material == Material.PISTON || material == Material.GLASS))
        material = Material.STONE;
    return material;
}
 
Example #4
Source File: ServerWorld_tickMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "tick", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/world/level/LevelProperties;getGeneratorType()Lnet/minecraft/world/level/LevelGeneratorType;"
))
private LevelGeneratorType tickPendingBlocks(LevelProperties levelProperties)
{
    if (TickSpeed.process_entities) return levelProperties.getGeneratorType();
    return LevelGeneratorType.DEBUG_ALL_BLOCK_STATES;
}
 
Example #5
Source File: PistonBlockEntity_movableTEMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "finish", at = @At(value = "INVOKE",
          target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
private boolean movableTEsetBlockState1(World world, BlockPos blockPos_1, BlockState blockState_2, int int_1)
{
    if (!CarpetSettings.movableBlockEntities)
        return world.setBlockState(blockPos_1, blockState_2, int_1);
    else
    {
        boolean ret = ((WorldInterface) (world)).setBlockStateWithBlockEntity(blockPos_1, blockState_2, this.carriedBlockEntity, int_1);
        this.carriedBlockEntity = null; //this will cancel the finishHandleBroken
        return ret;
    }
}
 
Example #6
Source File: MixinClientPlayerInteractionManager.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Redirect(method = "updateBlockBreakingProgress", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;blockBreakingCooldown:I", ordinal = 3))
public void updateBlockBreakingProgress(ClientPlayerInteractionManager clientPlayerInteractionManager, int i) {
    i = ModuleManager.getModule(Nuker.class).isToggled() ?
    		(int) ModuleManager.getModule(Nuker.class).getSettings().get(2).toSlider().getValue()
    		: ModuleManager.getModule(SpeedMine.class).isToggled()
    		&& ModuleManager.getModule(SpeedMine.class).getSettings().get(0).toMode().mode == 1
            ? (int) ModuleManager.getModule(SpeedMine.class).getSettings().get(2).toSlider().getValue() : 5;
    this.blockBreakingCooldown = i;
}
 
Example #7
Source File: AbstractButtonBlock_variableWoodMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Redirect(method = "method_21845", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/block/AbstractButtonBlock;getTickRate(Lnet/minecraft/world/WorldView;)I"
))
private int getCustomTickRate(AbstractButtonBlock abstractButtonBlock, WorldView viewableWorld_1,
                              BlockState blockState_1, World world_1, BlockPos blockPos_1)
{
    if (!CarpetExtraSettings.variableWoodDelays)
    {
        return abstractButtonBlock.getTickRate(viewableWorld_1);
    }
    return WoodDelayMultipliers.getForDelay(blockState_1.getBlock(), abstractButtonBlock.getTickRate(viewableWorld_1));
}
 
Example #8
Source File: FishingBobberEntity_extremeMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "<init>(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/world/World;II)V", expect =3, at = @At(
        value = "INVOKE",
        target = "Ljava/util/Random;nextGaussian()D"
))
private double nextGauBian(Random random)
{
    return RandomTools.nextGauBian(random);
}
 
Example #9
Source File: MixinClientPlayerInteractionManager.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Redirect(method = "attackBlock", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;blockBreakingCooldown:I"))
public void attackBlock(ClientPlayerInteractionManager clientPlayerInteractionManager, int i) {
    i = ModuleManager.getModule(Nuker.class).isToggled()
    		? (int) ModuleManager.getModule(Nuker.class).getSettings().get(2).toSlider().getValue()
    		: ModuleManager.getModule(SpeedMine.class).isToggled()
    		&& ModuleManager.getModule(SpeedMine.class).getSettings().get(0).toMode().mode == 1
            ? (int) ModuleManager.getModule(SpeedMine.class).getSettings().get(2).toSlider().getValue() : 5;
    this.blockBreakingCooldown = i;
}
 
Example #10
Source File: BlocksMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Redirect(method = "<clinit>",
    slice = @Slice(from = @At(value = "CONSTANT", args = "stringValue=obsidian")),
    at = @At(value = "INVOKE",
        target = "Lnet/minecraft/block/Blocks;register(Ljava/lang/String;Lnet/minecraft/block/Block;)Lnet/minecraft/block/Block;",
        ordinal = 0))
private static Block registerObsidian(String id, Block obsidian)
{
    return register("obsidian", new ObsidianBlock(Block.Settings.of(Material.STONE, MaterialColor.BLACK).strength(50.0F, 1200.0F)));
}
 
Example #11
Source File: WorldChunk_fillUpdatesMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "setBlockState", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/block/BlockState;onBlockAdded(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Z)V"
))
private void onAdded(BlockState blockState, World world_1, BlockPos blockPos_1, BlockState blockState_1, boolean boolean_1)
{
    if (!CarpetSettings.impendingFillSkipUpdates)
        blockState.onBlockAdded(world_1, blockPos_1, blockState_1, boolean_1);
}
 
Example #12
Source File: RedstoneWireBlockMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "neighborUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/RedstoneWireBlock;update(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/block/BlockState;"))
private BlockState redirectNeighborUpdateUpdate(
        RedstoneWireBlock self,
        World world_1,
        BlockPos blockPos_1,
        BlockState blockState_1,
        BlockState blockState_2,
        World world_2,
        BlockPos blockPos_2,
        Block block_1,
        BlockPos blockPos_3,
        boolean boolean_1) {
    return fastUpdate(world_1, blockPos_1, blockState_1, blockPos_3);
}
 
Example #13
Source File: ServerWorld_tickMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "tick", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/world/dimension/Dimension;hasSkyLight()Z"
))
private boolean tickWorldBorder(Dimension dimension)
{
    return TickSpeed.process_entities && dimension.hasSkyLight();
}
 
Example #14
Source File: FarmerVillagerTask_wartFarmMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Redirect(method = "shouldRun", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;",
        ordinal = 0
))
private Item disguiseWartAsSeeds(ItemStack itemStack, ServerWorld serverWorld, VillagerEntity villagerEntity)
{
    Item item = itemStack.getItem();
    if (isFarmingCleric && item == Items.NETHER_WART)
        return Items.WHEAT_SEEDS;
    return item;
}
 
Example #15
Source File: EntityNavigation_pathfindingMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method =  "findPathTo(Lnet/minecraft/util/math/BlockPos;I)Lnet/minecraft/entity/ai/pathing/Path;", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/entity/ai/pathing/EntityNavigation;findPathToAny(Ljava/util/Set;IZI)Lnet/minecraft/entity/ai/pathing/Path;"
))
private Path pathToBlock(EntityNavigation entityNavigation, Set<BlockPos> set_1, int int_1, boolean boolean_1, int int_2)
{
    if (!LoggerRegistry.__pathfinding)
        return findPathToAny(set_1, int_1, boolean_1, int_2);
    long start = System.nanoTime();
    Path path = findPathToAny(set_1, int_1, boolean_1, int_2);
    long finish = System.nanoTime();
    float duration = (1.0F*((finish - start)/1000))/1000;
    set_1.forEach(b -> PathfindingVisualizer.slowPath(entity, new Vec3d(b), duration, path != null));
    return path;
}
 
Example #16
Source File: FarmerVillagerTask_wartFarmMixin.java    From carpet-extra with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Redirect(method = "keepRunning", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/inventory/BasicInventory;getInvSize()I"
))
private int plantWart(BasicInventory basicInventory, ServerWorld serverWorld, VillagerEntity villagerEntity, long l)
{
    if (isFarmingCleric) // fill cancel that for loop by setting length to 0
    {
        for(int i = 0; i < basicInventory.getInvSize(); ++i)
        {
            ItemStack itemStack = basicInventory.getInvStack(i);
            boolean bl = false;
            if (!itemStack.isEmpty())
            {
                if (itemStack.getItem() == Items.NETHER_WART)
                {
                    serverWorld.setBlockState(currentTarget, Blocks.NETHER_WART.getDefaultState(), 3);
                    bl = true;
                }
            }

            if (bl)
            {
                serverWorld.playSound(null,
                        currentTarget.getX(), currentTarget.getY(), this.currentTarget.getZ(),
                        SoundEvents.ITEM_NETHER_WART_PLANT, SoundCategory.BLOCKS, 1.0F, 1.0F);
                itemStack.decrement(1);
                if (itemStack.isEmpty())
                {
                    basicInventory.setInvStack(i, ItemStack.EMPTY);
                }
                break;
            }
        }
        return 0;

    }
    return basicInventory.getInvSize();
}
 
Example #17
Source File: SpawnHelperMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "spawnEntitiesInChunk", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/entity/mob/MobEntity;initialize(Lnet/minecraft/world/IWorld;Lnet/minecraft/world/LocalDifficulty;Lnet/minecraft/entity/SpawnType;Lnet/minecraft/entity/EntityData;Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/entity/EntityData;"
))
private static EntityData spawnEntity(MobEntity mobEntity, IWorld iWorld_1, LocalDifficulty localDifficulty_1, SpawnType spawnType_1, EntityData entityData_1, CompoundTag compoundTag_1)
{
    if (!SpawnReporter.mock_spawns)
        return mobEntity.initialize(iWorld_1, localDifficulty_1, spawnType_1, entityData_1, compoundTag_1);
    return null;
}
 
Example #18
Source File: RenderTickCounter_tickSpeedMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "beginRenderTick", at = @At(
        value = "FIELD",
        target = "Lnet/minecraft/client/render/RenderTickCounter;tickTime:F"
))
private float adjustTickSpeed(RenderTickCounter counter) {
    if (CarpetSettings.smoothClientAnimations && TickSpeed.process_entities)
    {
        return Math.max(50.0f, TickSpeed.mspt);
    }
    return 50f;
}
 
Example #19
Source File: BlazeEntity_extremeMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "mobTick", expect = 1, at = @At(
        value = "INVOKE",
        target = "Ljava/util/Random;nextGaussian()D"
))
private double nextGauBian(Random random)
{
    return RandomTools.nextGauBian(random);
}
 
Example #20
Source File: MixinClientPlayerInteractionManager.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@Redirect(method = "updateBlockBreakingProgress", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;blockBreakingCooldown:I", ordinal = 3))
public void updateBlockBreakingProgress(ClientPlayerInteractionManager clientPlayerInteractionManager, int i) {
    i = ModuleManager.getModule(Nuker.class).isToggled() ?
    		(int) ModuleManager.getModule(Nuker.class).getSettings().get(2).toSlider().getValue()
    		: ModuleManager.getModule(SpeedMine.class).isToggled()
    		&& ModuleManager.getModule(SpeedMine.class).getSettings().get(0).toMode().mode == 1
            ? (int) ModuleManager.getModule(SpeedMine.class).getSettings().get(2).toSlider().getValue() : 5;
    this.blockBreakingCooldown = i;
}
 
Example #21
Source File: MinecraftServer_tickspeedMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
/**
 * To ensure compatibility with other mods we should allow milliseconds
 */

// Cancel a while statement
@Redirect(method = "run", at = @At(value = "FIELD", target = "Lnet/minecraft/server/MinecraftServer;running:Z"))
private boolean cancelRunLoop(MinecraftServer server)
{
    return false;
}
 
Example #22
Source File: EntityNavigation_pathfindingMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method =  "findPathTo(Lnet/minecraft/entity/Entity;I)Lnet/minecraft/entity/ai/pathing/Path;", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/entity/ai/pathing/EntityNavigation;findPathToAny(Ljava/util/Set;IZI)Lnet/minecraft/entity/ai/pathing/Path;"
))
private Path pathToEntity(EntityNavigation entityNavigation, Set<BlockPos> set_1, int int_1, boolean boolean_1, int int_2)
{
    if (!LoggerRegistry.__pathfinding)
        return findPathToAny(set_1, int_1, boolean_1, int_2);
    long start = System.nanoTime();
    Path path = findPathToAny(set_1, int_1, boolean_1, int_2);
    long finish = System.nanoTime();
    float duration = (1.0F*((finish - start)/1000))/1000;
    set_1.forEach(b -> PathfindingVisualizer.slowPath(entity, new Vec3d(b), duration, path != null));
    return path;
}
 
Example #23
Source File: ServerWorld_tickMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "tick", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/server/world/ServerWorld;sendBlockActions()V"
))
private void tickConditionally(ServerWorld serverWorld)
{
    if (TickSpeed.process_entities) sendBlockActions();
}
 
Example #24
Source File: MixinBiomeLayers.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Redirect(method = "build(Lnet/minecraft/world/level/LevelGeneratorType;Lnet/minecraft/world/gen/chunk/OverworldChunkGeneratorConfig;Ljava/util/function/LongFunction;)Lcom/google/common/collect/ImmutableList;",
		at = @At(value = "INVOKE", target = "net/minecraft/world/biome/layer/AddBambooJungleLayer.create(Lnet/minecraft/world/biome/layer/util/LayerSampleContext;Lnet/minecraft/world/biome/layer/util/LayerFactory;)Lnet/minecraft/world/biome/layer/util/LayerFactory;", ordinal = 0))
private static <T extends LayerSampler, C extends LayerSampleContext<T>> LayerFactory<T> redirectBambooJungle(AddBambooJungleLayer instance, C contextParam, LayerFactory<T> parentLayer, LevelGeneratorType generatorType, OverworldChunkGeneratorConfig settings, LongFunction<C> contextProvider) {
	if (generatorType instanceof PatchworkLevelGeneratorType) {
		return parentLayer;
	} else {
		// vanilla behaviour
		return instance.create(contextParam, parentLayer);
	}
}
 
Example #25
Source File: WorldRenderer_fogOffMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "render", require = 0, expect = 0, at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/world/dimension/Dimension;isFogThick(II)Z"
))
private boolean isReallyThick(Dimension dimension, int x, int z)
{
    if (CarpetSettings.fogOff) return false;
    return dimension.isFogThick(x, z);
}
 
Example #26
Source File: ServerChunkManagerMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@SuppressWarnings("UnresolvedMixinReference")
@Redirect(method = "method_20801", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/world/SpawnHelper;spawnEntitiesInChunk(Lnet/minecraft/entity/EntityCategory;Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/chunk/WorldChunk;Lnet/minecraft/util/math/BlockPos;)V"
))
// inject our repeat of spawns if more spawn ticks per tick are chosen.
private void spawnMultipleTimes(EntityCategory entityCategory_1, ServerWorld world_1, WorldChunk worldChunk_1, BlockPos blockPos_1)
{
    for (int i = 0; i < SpawnReporter.spawn_tries.get(entityCategory_1); i++)
    {
        SpawnHelper.spawnEntitiesInChunk(entityCategory_1, world_1, worldChunk_1, blockPos_1);
    }
}
 
Example #27
Source File: FireworkEntity_extremeMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "<init>(Lnet/minecraft/world/World;DDDLnet/minecraft/item/ItemStack;)V", expect = 2, at = @At(
        value = "INVOKE",
        target = "Ljava/util/Random;nextGaussian()D"
))
private double nextGauBian(Random random)
{
    return RandomTools.nextGauBian(random);
}
 
Example #28
Source File: MixinSpawnHelper.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Redirect(method = "spawnEntitiesInChunk", at = @At(value = "INVOKE", target = "net/minecraft/entity/mob/MobEntity.initialize(Lnet/minecraft/world/IWorld;Lnet/minecraft/world/LocalDifficulty;Lnet/minecraft/entity/SpawnType;Lnet/minecraft/entity/EntityData;Lnet/minecraft/nbt/CompoundTag;)Lnet/minecraft/entity/EntityData;"))
private static EntityData hookSpecialSpawn(MobEntity entity, IWorld world, LocalDifficulty localDifficulty, SpawnType spawnType, EntityData data, CompoundTag tag) {
	if (!EntityEvents.doSpecialSpawn(entity, world, entity.x, entity.y, entity.z, null, spawnType)) {
		return entity.initialize(world, localDifficulty, spawnType, data, tag);
	} else {
		return data;
	}
}
 
Example #29
Source File: ServerWorld_tickMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "tick", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/world/WanderingTraderManager;tick()V"
))
private void tickConditionally(WanderingTraderManager wanderingTraderManager)
{
    if (TickSpeed.process_entities) wanderingTraderManager.tick();
}
 
Example #30
Source File: MixinStemBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Redirect(method = "onScheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;getBlock()Lnet/minecraft/block/Block;"))
private Block redirectSoilCheck(BlockState blockState) {
	if (((IForgeBlockState) blockState).canSustainPlant(currentWorld.get(), currentBlockPos.get().down(), Direction.UP, (IPlantable) this)) {
		return Blocks.DIRT;
	}

	return blockState.getBlock();
}