Search in sources :

Example 66 with Redirect

use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.

the class BlocksMixin_Tracker method impl$initializeTrackerState.

@Redirect(method = "register", at = @At(value = "INVOKE", target = "Lnet/minecraft/core/Registry;register(Lnet/minecraft/core/Registry;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;"))
private static Object impl$initializeTrackerState(final Registry<Object> registry, final String key, final Object toRegister) {
    final Object registered = Registry.register(registry, key, toRegister);
    final Block block = (Block) toRegister;
    final boolean randomlyTicking = block.isRandomlyTicking(block.defaultBlockState());
    // TODO Not the best check but the tracker options only matter during block ticks...
    if (randomlyTicking) {
        final RegistryBackedTrackableBridge<Block> trackableBridge = (RegistryBackedTrackableBridge<Block>) toRegister;
        trackableBridge.bridge$refreshTrackerStates();
    }
    return registered;
}
Also used : Block(net.minecraft.world.level.block.Block) RegistryBackedTrackableBridge(org.spongepowered.common.bridge.RegistryBackedTrackableBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 67 with Redirect

use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.

the class EndDragonFightMixin_Tracker method tracker$switchToFeatureState.

// @formatter:on
@Redirect(method = "spawnNewGateway(Lnet/minecraft/core/BlockPos;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/feature/ConfiguredFeature;place(Lnet/minecraft/world/level/WorldGenLevel;Lnet/minecraft/world/level/chunk/ChunkGenerator;Ljava/util/Random;Lnet/minecraft/core/BlockPos;)Z"))
private boolean tracker$switchToFeatureState(final ConfiguredFeature configuredFeature, final WorldGenLevel worldIn, final ChunkGenerator generator, final Random rand, final BlockPos pos) {
    try (final FeaturePhaseContext context = GenerationPhase.State.FEATURE_PLACEMENT.createPhaseContext(PhaseTracker.SERVER)) {
        context.world((ServerLevel) worldIn).generator(generator).feature(configuredFeature.feature).origin(pos);
        context.buildAndSwitch();
        return configuredFeature.place(worldIn, generator, rand, pos);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) FeaturePhaseContext(org.spongepowered.common.event.tracking.phase.generation.FeaturePhaseContext) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 68 with Redirect

use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.

the class EndDragonFightMixin_Tracker method tracker$switchToSpawnDragonState.

@Redirect(method = "tick()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/dimension/end/DragonRespawnAnimation;tick(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/level/dimension/end/EndDragonFight;Ljava/util/List;ILnet/minecraft/core/BlockPos;)V"))
private void tracker$switchToSpawnDragonState(final DragonRespawnAnimation dragonSpawnState, final ServerLevel worldIn, final EndDragonFight manager, final List<EndCrystal> crystals, int respawnStateTicks, final BlockPos exitPortalLocation) {
    try (final SpawnDragonContext context = DragonPhase.State.SPAWN_DRAGON.createPhaseContext(PhaseTracker.SERVER)) {
        context.manager(manager).setIsRespawn(true).buildAndSwitch();
        ++respawnStateTicks;
        dragonSpawnState.tick(worldIn, manager, crystals, respawnStateTicks, exitPortalLocation);
    }
}
Also used : SpawnDragonContext(org.spongepowered.common.event.tracking.phase.world.dragon.SpawnDragonContext) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 69 with Redirect

use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.

the class ServerPlayerGameModeMixin_Forge_Tracker method forgeTracker$pushTransactionAndEffect.

// @formatter:on
@Redirect(method = "destroyBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;mineBlock(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/player/Player;)V"))
private void forgeTracker$pushTransactionAndEffect(final ItemStack itemStack, final Level level, final BlockState state, final BlockPos pos, final Player player) {
    final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
    final TransactionalCaptureSupplier transactor = context.getTransactor();
    // Log the prepare drops here because Forge rewrites
    // this method to call mine block before calling destroy block
    // and mods will possibly already have performed modifications on
    // the block before we can capture it in level.destroy.
    transactor.logBlockDrops(level, pos, state, level.getBlockEntity(pos));
    itemStack.mineBlock(level, state, pos, player);
    // Needs to get logged as a sideeffect under the BlockChange
    try (EffectTransactor ignored = context.getTransactor().pushEffect(new ResultingTransactionBySideEffect(InventoryEffect.getInstance()))) {
        transactor.logPlayerInventoryChange(this.player, PlayerInventoryTransaction.EventCreator.STANDARD);
        this.player.inventoryMenu.broadcastChanges();
    }
}
Also used : TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) ResultingTransactionBySideEffect(org.spongepowered.common.event.tracking.context.transaction.ResultingTransactionBySideEffect) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 70 with Redirect

use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.

the class ServerGamePacketListenerImplMixin_Forge method forge$onPlaceRecipe.

@SuppressWarnings({ "UnresolvedMixinReference", "unchecked", "rawtypes" })
@Redirect(method = "lambda$handlePlaceRecipe$11", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/RecipeBookMenu;handlePlacement(ZLnet/minecraft/world/item/crafting/Recipe;Lnet/minecraft/server/level/ServerPlayer;)V"))
private void forge$onPlaceRecipe(final RecipeBookMenu recipeBookMenu, final boolean shift, final Recipe<?> recipe, final net.minecraft.server.level.ServerPlayer player) {
    final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
    final TransactionalCaptureSupplier transactor = context.getTransactor();
    final Inventory craftInv = ((Inventory) player.containerMenu).query(QueryTypes.INVENTORY_TYPE.get().of(CraftingInventory.class));
    if (!(craftInv instanceof CraftingInventory)) {
        recipeBookMenu.handlePlacement(shift, recipe, player);
        SpongeCommon.logger().warn("Detected crafting without a InventoryCrafting!? Crafting Event will not fire.");
        return;
    }
    try (final EffectTransactor ignored = transactor.logPlaceRecipe(shift, recipe, player, (CraftingInventory) craftInv)) {
        recipeBookMenu.handlePlacement(shift, recipe, player);
        player.containerMenu.broadcastChanges();
    }
}
Also used : CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) TransactionalCaptureSupplier(org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier) EffectTransactor(org.spongepowered.common.event.tracking.context.transaction.EffectTransactor) Inventory(org.spongepowered.api.item.inventory.Inventory) CraftingInventory(org.spongepowered.api.item.inventory.crafting.CraftingInventory) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

Redirect (org.spongepowered.asm.mixin.injection.Redirect)165 CauseStackManager (org.spongepowered.api.event.CauseStackManager)25 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)15 ItemStack (net.minecraft.item.ItemStack)13 EffectTransactor (org.spongepowered.common.event.tracking.context.transaction.EffectTransactor)13 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)12 TransactionalCaptureSupplier (org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier)11 ArrayList (java.util.ArrayList)9 ItemStack (net.minecraft.world.item.ItemStack)9 Nullable (javax.annotation.Nullable)8 Vector3d (com.flowpowered.math.vector.Vector3d)7 World (net.minecraft.world.World)7 ServerLocation (org.spongepowered.api.world.server.ServerLocation)7 DamageSourceBridge (org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge)7 IPhaseState (org.spongepowered.common.event.tracking.IPhaseState)7 IBlockState (net.minecraft.block.state.IBlockState)6 Entity (net.minecraft.entity.Entity)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 ServerLevel (net.minecraft.server.level.ServerLevel)6 EntityItem (net.minecraft.entity.item.EntityItem)5