use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinCommandSummon method onAttemptSpawnEntity.
@Redirect(method = "execute", at = @At(value = "INVOKE", target = ENTITY_LIST_CREATE_FROM_NBT))
private Entity onAttemptSpawnEntity(NBTTagCompound nbt, World world, double x, double y, double z, boolean b, MinecraftServer server, ICommandSender sender, String[] args) {
if ("Minecart".equals(nbt.getString(NbtDataUtil.ENTITY_TYPE_ID))) {
nbt.setString(NbtDataUtil.ENTITY_TYPE_ID, EntityMinecart.Type.values()[nbt.getInteger(NbtDataUtil.MINECART_TYPE)].getName());
nbt.removeTag(NbtDataUtil.MINECART_TYPE);
}
Class<? extends Entity> entityClass = SpongeImplHooks.getEntityClass(new ResourceLocation(nbt.getString(NbtDataUtil.ENTITY_TYPE_ID)));
if (entityClass == null) {
return null;
}
EntityType type = EntityTypeRegistryModule.getInstance().getForClass(entityClass);
if (type == null) {
return null;
}
Transform<org.spongepowered.api.world.World> transform = new Transform<>(((org.spongepowered.api.world.World) world), new Vector3d(x, y, z));
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PLACEMENT);
ConstructEntityEvent.Pre event = SpongeEventFactory.createConstructEntityEventPre(Sponge.getCauseStackManager().getCurrentCause(), type, transform);
SpongeImpl.postEvent(event);
return event.isCancelled() ? null : AnvilChunkLoader.readWorldEntityPos(nbt, world, x, y, z, b);
}
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinEntity method onEntityCollideWithBlock.
@Redirect(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;" + "onEntityWalk(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;)V"))
public void onEntityCollideWithBlock(Block block, net.minecraft.world.World world, BlockPos pos, net.minecraft.entity.Entity entity) {
// if block can't collide, return
if (!((IMixinBlock) block).hasCollideLogic()) {
return;
}
if (world.isRemote) {
block.onEntityWalk(world, pos, entity);
return;
}
IBlockState state = world.getBlockState(pos);
this.setCurrentCollidingBlock((BlockState) state);
if (!SpongeCommonEventFactory.handleCollideBlockEvent(block, world, pos, state, entity, Direction.NONE)) {
block.onEntityWalk(world, pos, entity);
this.lastCollidedBlockPos = pos;
}
this.setCurrentCollidingBlock(null);
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinEntityLivingBase method causeTrackDeathUpdate.
@Redirect(method = "onEntityUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityLivingBase;onDeathUpdate()V"))
private void causeTrackDeathUpdate(EntityLivingBase entityLivingBase) {
if (!entityLivingBase.world.isRemote) {
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame();
PhaseContext<?> context = EntityPhase.State.DEATH_UPDATE.createPhaseContext().source(entityLivingBase).buildAndSwitch()) {
Sponge.getCauseStackManager().pushCause(entityLivingBase);
((IMixinEntityLivingBase) entityLivingBase).onSpongeDeathUpdate();
}
} else {
((IMixinEntityLivingBase) entityLivingBase).onSpongeDeathUpdate();
}
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinWorldServer method onFireBlockEvent.
// special handling for Pistons since they use their own event system
@Redirect(method = "sendQueuedBlockEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/WorldServer;fireBlockEvent(Lnet/minecraft/block/BlockEventData;)Z"))
private boolean onFireBlockEvent(net.minecraft.world.WorldServer worldIn, BlockEventData event) {
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
final IPhaseState phaseState = phaseTracker.getCurrentState();
if (phaseState.ignoresBlockEvent()) {
return fireBlockEvent(event);
}
return TrackingUtil.fireMinecraftBlockEvent(worldIn, event);
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinEntityFireworkRocket method useEntitySource.
@Redirect(method = "dealExplosionDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityLivingBase;attackEntityFrom" + "(Lnet/minecraft/util/DamageSource;F)Z"))
public boolean useEntitySource(EntityLivingBase entityLivingBase, DamageSource source, float amount) {
final DamageSource originalFireworks = DamageSource.FIREWORKS;
DamageSource.FIREWORKS = new EntityDamageSource(originalFireworks.damageType, (Entity) (Object) this).setExplosion();
final boolean result = entityLivingBase.attackEntityFrom(DamageSource.FIREWORKS, amount);
DamageSource.FIREWORKS = originalFireworks;
return result;
}
Aggregations