Search in sources :

Example 31 with Redirect

use of org.spongepowered.asm.mixin.injection.Redirect in project Almura by AlmuraDev.

the class MixinPlayerChunkMapEntry method redirectSendPacketRemove.

@Redirect(method = "removePlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetHandlerPlayServer;sendPacket(Lnet/minecraft/network/Packet;)V"))
private void redirectSendPacketRemove(NetHandlerPlayServer netHandlerPlayServer, Packet<?> packetIn) {
    netHandlerPlayServer.sendPacket(packetIn);
    network.sendTo((Player) netHandlerPlayServer.player, new ClientboundBiomeChunkDataPacket(ChunkPos.asLong(this.pos.x, this.pos.z)));
}
Also used : ClientboundBiomeChunkDataPacket(com.almuradev.almura.feature.biome.network.ClientboundBiomeChunkDataPacket) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 32 with Redirect

use of org.spongepowered.asm.mixin.injection.Redirect in project Almura by AlmuraDev.

the class MixinWorld method redirectCanSnowAt.

@Redirect(method = "isRainingAt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;canSnowAt(Lnet/minecraft/util/math/BlockPos;Z)Z"))
private boolean redirectCanSnowAt(World world, BlockPos pos, boolean checkLight) {
    final BiomeChunk biomeChunk = BiomeUtil.getChunk(pos);
    if (biomeChunk == null) {
        return world.canSnowAt(pos, checkLight);
    }
    final Biome biome = world.getBiome(pos);
    final float temperature = biomeChunk.getTemperature(pos, biome);
    return temperature < 0.15f;
}
Also used : Biome(net.minecraft.world.biome.Biome) BiomeChunk(com.almuradev.almura.feature.biome.BiomeChunk) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 33 with Redirect

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

the class EntityMixin method impl$onFallOnCollide.

@Redirect(method = "checkFallDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/Block;fallOn(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/Entity;F)V"))
private void impl$onFallOnCollide(final Block block, final Level world, final BlockPos pos, final Entity entity, final float fallDistance) {
    if (!ShouldFire.COLLIDE_BLOCK_EVENT_FALL || world.isClientSide) {
        block.fallOn(world, pos, entity, fallDistance);
        return;
    }
    final BlockState state = world.getBlockState(pos);
    if (!SpongeCommonEventFactory.handleCollideBlockEvent(block, world, pos, state, entity, org.spongepowered.api.util.Direction.UP, SpongeCommonEventFactory.CollisionType.FALL)) {
        block.fallOn(world, pos, entity, fallDistance);
        this.impl$lastCollidedBlockPos = pos;
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 34 with Redirect

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

the class EntityMixin method impl$ThrowDamageEventWithLightingSource.

@Redirect(method = "thunderHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;hurt(Lnet/minecraft/world/damagesource/DamageSource;F)Z"))
private boolean impl$ThrowDamageEventWithLightingSource(final Entity entity, final DamageSource source, final float damage, final ServerLevel level, final LightningBolt lightningBolt) {
    if (!this.level.isClientSide) {
        return entity.hurt(source, damage);
    }
    try {
        final EntityDamageSource lightning = new EntityDamageSource("lightningBolt", lightningBolt);
        ((DamageSourceBridge) lightning).bridge$setLightningSource();
        return entity.hurt(DamageSource.LIGHTNING_BOLT, damage);
    } finally {
        ((DamageSourceBridge) source).bridge$setLightningSource();
    }
}
Also used : DamageSourceBridge(org.spongepowered.common.bridge.world.damagesource.DamageSourceBridge) EntityDamageSource(net.minecraft.world.damagesource.EntityDamageSource) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 35 with Redirect

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

the class EntityMixin method impl$ThrowIgniteEventForFire.

@Redirect(method = "setRemainingFireTicks", at = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/Entity;remainingFireTicks:I", opcode = Opcodes.PUTFIELD))
private void impl$ThrowIgniteEventForFire(final Entity entity, final int ticks) {
    if (!((LevelBridge) this.level).bridge$isFake() && ShouldFire.IGNITE_ENTITY_EVENT && this.remainingFireTicks < 1 && ticks >= Constants.Entity.MINIMUM_FIRE_TICKS && this.impl$canCallIgniteEntityEvent()) {
        try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
            frame.pushCause(((org.spongepowered.api.entity.Entity) this).location().world());
            final IgniteEntityEvent event = SpongeEventFactory.createIgniteEntityEvent(frame.currentCause(), Ticks.of(ticks), Ticks.of(ticks), (org.spongepowered.api.entity.Entity) this);
            if (SpongeCommon.post(event)) {
                // Don't do anything
                return;
            }
            final DataTransactionResult transaction = DataTransactionResult.builder().replace(new ImmutableSpongeValue<>(Keys.FIRE_TICKS, Ticks.of(Math.max(this.remainingFireTicks, 0)))).success(new ImmutableSpongeValue<>(Keys.FIRE_TICKS, event.fireTicks())).result(DataTransactionResult.Type.SUCCESS).build();
            final ChangeDataHolderEvent.ValueChange valueChange = SpongeEventFactory.createChangeDataHolderEventValueChange(PhaseTracker.SERVER.currentCause(), transaction, (DataHolder.Mutable) this);
            Sponge.eventManager().post(valueChange);
            if (valueChange.isCancelled()) {
                // If the event is cancelled, well, don't change the underlying value.
                return;
            }
            this.remainingFireTicks = valueChange.endResult().successfulValue(Keys.FIRE_TICKS).map(Value::get).map(t -> (int) t.ticks()).orElse(0);
        }
        return;
    }
    // Vanilla functionality
    this.remainingFireTicks = ticks;
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) Entity(net.minecraft.world.entity.Entity) CauseStackManager(org.spongepowered.api.event.CauseStackManager) DataHolder(org.spongepowered.api.data.DataHolder) DataTransactionResult(org.spongepowered.api.data.DataTransactionResult) IgniteEntityEvent(org.spongepowered.api.event.entity.IgniteEntityEvent) ImmutableSpongeValue(org.spongepowered.common.data.value.ImmutableSpongeValue) ChangeDataHolderEvent(org.spongepowered.api.event.data.ChangeDataHolderEvent) 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