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