use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class OcelotMixin method impl$ThrowTameEvent.
@Redirect(method = "mobInteract", at = @At(value = "INVOKE", target = "Ljava/util/Random;nextInt(I)I", ordinal = 0, remap = false))
private int impl$ThrowTameEvent(Random rand, int bound, Player player, InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand);
int random = rand.nextInt(bound);
if (random == 0) {
stack.setCount(stack.getCount() + 1);
try (CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
frame.pushCause(player);
if (!SpongeCommon.post(SpongeEventFactory.createTameEntityEvent(frame.currentCause(), (Ocelot) this))) {
stack.setCount(stack.getCount() - 1);
return random;
}
}
}
return 1;
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class FallingBlockEntityMixin method spongeAttackFallingOrAnvil.
// @formatter:on
@SuppressWarnings("ConstantConditions")
@Redirect(method = "causeFallDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z"))
private boolean spongeAttackFallingOrAnvil(final Entity entity, final DamageSource source, final float damage) {
if (entity.level.isClientSide) {
return entity.hurt(source, damage);
}
final boolean isAnvil = this.blockState.getBlock().is(BlockTags.ANVIL);
try {
if (isAnvil) {
final MinecraftFallingBlockDamageSource anvil = new MinecraftFallingBlockDamageSource("anvil", (FallingBlockEntity) (Object) this);
((DamageSourceBridge) (Object) anvil).bridge$setAnvilSource();
return entity.hurt(DamageSource.ANVIL, damage);
} else {
final MinecraftFallingBlockDamageSource fallingblock = new MinecraftFallingBlockDamageSource("fallingblock", (FallingBlockEntity) (Object) this);
((DamageSourceBridge) (Object) fallingblock).bridge$setFallingBlockSource();
return entity.hurt(DamageSource.FALLING_BLOCK, damage);
}
} finally {
if (isAnvil) {
((DamageSourceBridge) source).bridge$setAnvilSource();
} else {
((DamageSourceBridge) source).bridge$setFallingBlockSource();
}
}
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class ServerGamePacketListenerImplMixin_Inventory method impl$onHandleUseItem.
@Redirect(method = "handleUseItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayerGameMode;useItem(Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/InteractionResult;"))
private InteractionResult impl$onHandleUseItem(final ServerPlayerGameMode serverPlayerGameMode, final ServerPlayer param0, final Level param1, final ItemStack param2, final InteractionHand param3) {
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
final InteractionResult result = serverPlayerGameMode.useItem(param0, param1, param2, param3);
try (EffectTransactor ignored = transactor.logPlayerInventoryChangeWithEffect(this.player, PlayerInventoryTransaction.EventCreator.STANDARD)) {
// capture
this.player.inventoryMenu.broadcastChanges();
}
return result;
// TrackingUtil.processBlockCaptures called by UseItemPacketState
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class ServerGamePacketListenerImplMixin_Inventory method impl$onBroadcastCreativeActionResult.
@Redirect(method = "handleSetCreativeModeSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/InventoryMenu;broadcastChanges()V"))
private void impl$onBroadcastCreativeActionResult(final InventoryMenu inventoryMenu, final ServerboundSetCreativeModeSlotPacket packetIn) {
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
final ItemStack itemstack = packetIn.getItem();
// TODO handle vanilla sending a bunch of creative events (previously ignoring events within 100ms)
try (final EffectTransactor ignored = transactor.logCreativeClickContainer(packetIn.getSlotNum(), ItemStackUtil.snapshotOf(itemstack), this.player)) {
}
inventoryMenu.broadcastChanges();
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class ServerGamePacketListenerImplMixin_Inventory method impl$onBroadcastCreativeActionResult.
@Redirect(method = "handleSetCreativeModeSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;drop(Lnet/minecraft/world/item/ItemStack;Z)Lnet/minecraft/world/entity/item/ItemEntity;"))
private ItemEntity impl$onBroadcastCreativeActionResult(final ServerPlayer serverPlayer, final ItemStack stack, final boolean param1) {
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
try (final EffectTransactor ignored = transactor.logCreativeClickContainer(-1, ItemStackUtil.snapshotOf(stack), this.player)) {
return serverPlayer.drop(stack, param1);
}
}
Aggregations