Search in sources :

Example 86 with Redirect

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

the class MixinEntityWitherSkull method onExplode.

@Redirect(method = "onImpact", at = @At(value = "INVOKE", target = EXPLOSION_TARGET))
protected net.minecraft.world.Explosion onExplode(net.minecraft.world.World worldObj, Entity self, double x, double y, double z, float strength, boolean flaming, boolean smoking) {
    boolean griefer = ((IMixinGriefer) this).canGrief();
    try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        Sponge.getCauseStackManager().pushCause(this);
        Sponge.getCauseStackManager().addContext(EventContextKeys.THROWER, getShooter());
        Sponge.getCauseStackManager().pushCause(getShooter());
        return detonate(Explosion.builder().location(new Location<>((World) worldObj, new Vector3d(x, y, z))).sourceExplosive(this).radius(this.explosionRadius).canCauseFire(flaming).shouldPlaySmoke(smoking && griefer).shouldBreakBlocks(smoking && griefer)).orElse(null);
    }
}
Also used : Vector3d(com.flowpowered.math.vector.Vector3d) IMixinGriefer(org.spongepowered.common.interfaces.entity.IMixinGriefer) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Location(org.spongepowered.api.world.Location) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 87 with Redirect

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

the class MixinContainer method onThrowClick.

@Redirect(method = "slotClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayer;dropItem(Lnet/minecraft/item/ItemStack;Z)Lnet/minecraft/entity/item/EntityItem;", ordinal = 3))
public EntityItem onThrowClick(EntityPlayer player, ItemStack itemStackIn, boolean unused) {
    final EntityItem entityItem = player.dropItem(itemStackIn, true);
    if (entityItem == null && ((IMixinEntityPlayer) player).shouldRestoreInventory()) {
        final ItemStack original = ItemStackUtil.toNative(this.itemStackSnapshot.createStack());
        this.lastSlotUsed.putStack(original);
        player.openContainer.detectAndSendChanges();
        ((EntityPlayerMP) player).isChangingQuantityOnly = false;
        ((EntityPlayerMP) player).connection.sendPacket(new SPacketSetSlot(player.openContainer.windowId, this.lastSlotUsed.slotNumber, original));
    }
    this.itemStackSnapshot = null;
    this.lastSlotUsed = null;
    ((IMixinEntityPlayer) player).shouldRestoreInventory(false);
    return entityItem;
}
Also used : SPacketSetSlot(net.minecraft.network.play.server.SPacketSetSlot) ItemStack(net.minecraft.item.ItemStack) IMixinEntityPlayer(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayer) EntityItem(net.minecraft.entity.item.EntityItem) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 88 with Redirect

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

the class MixinContainer method onDragDrop.

@Redirect(method = "slotClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayer;dropItem(Lnet/minecraft/item/ItemStack;Z)Lnet/minecraft/entity/item/EntityItem;", ordinal = 0))
public EntityItem onDragDrop(EntityPlayer player, ItemStack itemStackIn, boolean unused) {
    final ItemStackSnapshot original = ItemStackUtil.snapshotOf(itemStackIn);
    final EntityItem entityItem = player.dropItem(itemStackIn, unused);
    if (!((IMixinEntityPlayer) player).shouldRestoreInventory()) {
        return entityItem;
    }
    if (entityItem == null) {
        this.dropCancelled = true;
        PacketPhaseUtil.handleCustomCursor((EntityPlayerMP) player, original);
    }
    return entityItem;
}
Also used : ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) EntityItem(net.minecraft.entity.item.EntityItem) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 89 with Redirect

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

the class MixinContainer method redirectOnTakeThrow.

@Redirect(method = "slotClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/Slot;onTake(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;", ordinal = 5))
private ItemStack redirectOnTakeThrow(Slot slot, EntityPlayer player, ItemStack stackOnCursor) {
    this.lastCraft = null;
    ItemStack result = slot.onTake(player, stackOnCursor);
    if (this.lastCraft != null) {
        if (slot instanceof SlotCrafting) {
            if (this.lastCraft.isCancelled()) {
                // do not drop crafted item when cancelled
                stackOnCursor.setCount(0);
            }
        }
    }
    return result;
}
Also used : ItemStack(net.minecraft.item.ItemStack) SlotCrafting(net.minecraft.inventory.SlotCrafting) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 90 with Redirect

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

the class MixinNetHandlerPlayServer method processVehicleMoveEvent.

/**
 * @author gabizou - June 22nd, 2016
 * @author blood - May 6th, 2017
 * @reason Redirects the {@link Entity#getLowestRidingEntity()} call to throw our
 * {@link MoveEntityEvent}. The peculiarity of this redirect is that the entity
 * returned is perfectly valid to be {@link this#player} since, if the player
 * is NOT riding anything, the lowest riding entity is themselves. This way, if
 * the event is cancelled, the player can be returned instead of the actual riding
 * entity.
 *
 * @param playerMP The player
 * @param packetIn The packet movement
 * @return The lowest riding entity
 */
@Redirect(method = "processVehicleMove", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayerMP;getLowestRidingEntity()Lnet/minecraft/entity/Entity;"))
private Entity processVehicleMoveEvent(EntityPlayerMP playerMP, CPacketVehicleMove packetIn) {
    final Entity ridingEntity = this.player.getLowestRidingEntity();
    if (ridingEntity == this.player || ridingEntity.getControllingPassenger() != this.player || ridingEntity != this.lowestRiddenEnt) {
        return ridingEntity;
    }
    // Sponge Start - Movement event
    org.spongepowered.api.entity.Entity spongeEntity = (org.spongepowered.api.entity.Entity) ridingEntity;
    Vector3d fromrot = spongeEntity.getRotation();
    Location<World> from = spongeEntity.getLocation();
    Vector3d torot = new Vector3d(packetIn.getPitch(), packetIn.getYaw(), 0);
    Location<World> to = new Location<>(spongeEntity.getWorld(), packetIn.getX(), packetIn.getY(), packetIn.getZ());
    Transform<World> fromTransform = spongeEntity.getTransform().setLocation(from).setRotation(fromrot);
    Transform<World> toTransform = spongeEntity.getTransform().setLocation(to).setRotation(torot);
    MoveEntityEvent event = SpongeEventFactory.createMoveEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), fromTransform, toTransform, this.getPlayer());
    SpongeImpl.postEvent(event);
    if (event.isCancelled()) {
        // There is no need to change the current riding entity position as it hasn't changed yet.
        // Send packet to client in order to update rider position.
        this.netManager.sendPacket(new SPacketMoveVehicle(ridingEntity));
        return this.player;
    }
    return ridingEntity;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) Entity(net.minecraft.entity.Entity) MoveEntityEvent(org.spongepowered.api.event.entity.MoveEntityEvent) SPacketMoveVehicle(net.minecraft.network.play.server.SPacketMoveVehicle) World(org.spongepowered.api.world.World) Vector3d(com.flowpowered.math.vector.Vector3d) Location(org.spongepowered.api.world.Location) 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