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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations