use of net.minecraftforge.event.entity.living.EnderTeleportEvent in project ConvenientAdditions by Necr0.
the class MessageJumpPad method onMessage.
@Override
public MessageJumpPad onMessage(MessageJumpPad message, MessageContext ctx) {
if (ctx.side == Side.CLIENT)
return null;
EntityPlayer p = ctx.getServerHandler().player;
BlockPos pos = new BlockPos(p).down();
if (p.world.getBlockState(pos).getBlock() == ModBlocks.jumpPad) {
BlockPos target = ModBlocks.jumpPad.getTargetLocation(pos, p.world, !message.jump);
if (target != null) {
if (target.distanceSq(pos) > Math.pow(ModConfigMachines.jumpPad_range, 2)) {
p.sendMessage(new TextComponentTranslation("message." + ModConstants.Mod.MODID + ":jumpPad.outOfRange"));
} else if (!MinecraftForge.EVENT_BUS.post(new EnderTeleportEvent(p, target.getX() + .5, target.getY() + 1, target.getZ() + .5, 0f))) {
p.world.playSound(null, p.posX, p.posY, p.posZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.BLOCKS, .15F, 2F);
p.world.playSound(null, target.getX() + .5, target.getY() + 1, target.getZ() + .5, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.BLOCKS, .15F, 2F);
p.setPositionAndUpdate(target.getX() + .5, target.getY() + 1, target.getZ() + .5);
}
}
}
return null;
}
use of net.minecraftforge.event.entity.living.EnderTeleportEvent in project takumicraft by TNTModders.
the class EntityDarkCreeper method teleportTo.
/**
* Teleport the enderman
*/
private boolean teleportTo(double x, double y, double z) {
EnderTeleportEvent event = new EnderTeleportEvent(this, x, y, z, 0);
if (MinecraftForge.EVENT_BUS.post(event)) {
return false;
}
boolean flag = this.attemptTeleport(event.getTargetX(), event.getTargetY(), event.getTargetZ());
if (flag) {
this.world.playSound(null, this.prevPosX, this.prevPosY, this.prevPosZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, this.getSoundCategory(), 1.0F, 1.0F);
this.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
}
return flag;
}
use of net.minecraftforge.event.entity.living.EnderTeleportEvent in project takumicraft by TNTModders.
the class EntityEnderCreeper method teleportTo.
protected boolean teleportTo(EntityLivingBase entity) {
Random rand = new Random();
int distance = 128;
double x = entity.posX + (rand.nextDouble() - 0.5D) * distance;
double y = entity.posY + rand.nextInt(distance + 1) - distance / 2;
double z = entity.posZ + (rand.nextDouble() - 0.5D) * distance;
EnderTeleportEvent event = new EnderTeleportEvent(entity, x, y, z, 0);
double d3 = entity.posX;
double d4 = entity.posY;
double d5 = entity.posZ;
entity.posX = event.getTargetX();
entity.posY = event.getTargetY();
entity.posZ = event.getTargetZ();
int xInt = MathHelper.floor(entity.posX);
int yInt = MathHelper.floor(entity.posY);
int zInt = MathHelper.floor(entity.posZ);
boolean flag = false;
if (entity.world.isAirBlock(new BlockPos(xInt, yInt, zInt))) {
boolean foundGround = false;
while (!foundGround && yInt > 0) {
IBlockState block = entity.world.getBlockState(new BlockPos(xInt, yInt - 1, zInt));
if (block.getMaterial().blocksMovement()) {
foundGround = true;
} else {
--entity.posY;
--yInt;
}
}
boolean flg = true;
try {
Method method = EntityLivingBase.class.getDeclaredMethod("isMovementBlocked");
method.setAccessible(true);
flg = (Boolean) method.invoke(entity);
} catch (Exception e) {
e.printStackTrace();
}
if (foundGround && flg) {
entity.setPosition(entity.posX, entity.posY, entity.posZ);
if (entity.world.getCollisionBoxes(entity, entity.getEntityBoundingBox()).isEmpty() && !entity.world.containsAnyLiquid(entity.getEntityBoundingBox())) {
flag = true;
}
}
}
if (!flag) {
entity.setPosition(d3, d4, d5);
return false;
}
entity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
short short1 = 128;
for (int l = 0; l < short1; ++l) {
double d6 = l / (short1 - 1.0D);
float f = (rand.nextFloat() - 0.5F) * 0.2F;
float f1 = (rand.nextFloat() - 0.5F) * 0.2F;
float f2 = (rand.nextFloat() - 0.5F) * 0.2F;
double d7 = d3 + (entity.posX - d3) * d6 + (rand.nextDouble() - 0.5D) * entity.width * 2.0D;
double d8 = d4 + (entity.posY - d4) * d6 + rand.nextDouble() * entity.height;
double d9 = d5 + (entity.posZ - d5) * d6 + (rand.nextDouble() - 0.5D) * entity.width * 2.0D;
entity.world.spawnParticle(EnumParticleTypes.PORTAL, d7, d8, d9, f, f1, f2);
}
entity.world.playSound(null, entity.prevPosX, entity.prevPosY, entity.prevPosZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, entity.getSoundCategory(), 1.0F, 1.0F);
entity.playSound(SoundEvents.ENTITY_ENDERMEN_TELEPORT, 1.0F, 1.0F);
return true;
}
use of net.minecraftforge.event.entity.living.EnderTeleportEvent in project BloodMagic by WayofTime.
the class RitualExpulsion method moveEntityViaTeleport.
public void moveEntityViaTeleport(EntityLivingBase entityLiving, double x, double y, double z) {
if (entityLiving instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) entityLiving;
EnderTeleportEvent event = new EnderTeleportEvent(player, x, y, z, 5.0F);
if (!MinecraftForge.EVENT_BUS.post(event)) {
if (entityLiving.isRiding())
player.mountEntityAndWakeUp();
entityLiving.setPositionAndUpdate(event.getTargetX(), event.getTargetY(), event.getTargetZ());
}
} else if (entityLiving != null) {
entityLiving.setPosition(x, y, z);
}
}
use of net.minecraftforge.event.entity.living.EnderTeleportEvent in project Pearcel-Mod by MiningMark48.
the class EntityEnderPearcel method onImpact.
@Override
protected void onImpact(RayTraceResult result) {
EntityLivingBase entitylivingbase = this.getThrower();
if (result.entityHit != null) {
if (result.entityHit == this.thrower) {
return;
}
result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, entitylivingbase), 0.0F);
}
if (result.typeOfHit == RayTraceResult.Type.BLOCK) {
BlockPos entityplayermp = result.getBlockPos();
TileEntity event = this.world.getTileEntity(entityplayermp);
if (event instanceof TileEntityEndGateway) {
TileEntityEndGateway var9 = (TileEntityEndGateway) event;
if (entitylivingbase != null) {
var9.teleportEntity(entitylivingbase);
this.setDead();
return;
}
var9.teleportEntity(this);
return;
}
}
for (int var6 = 0; var6 < 32; ++var6) {
this.world.spawnParticle(EnumParticleTypes.FIREWORKS_SPARK, this.posX, this.posY + this.rand.nextDouble() * 2.0D, this.posZ, this.rand.nextGaussian(), 0.0D, this.rand.nextGaussian(), new int[0]);
}
if (!this.world.isRemote) {
if (entitylivingbase instanceof EntityPlayerMP) {
EntityPlayerMP var7 = (EntityPlayerMP) entitylivingbase;
if (var7.connection.getNetworkManager().isChannelOpen() && var7.world == this.world && !var7.isPlayerSleeping()) {
EnderTeleportEvent var8 = new EnderTeleportEvent(var7, this.posX, this.posY, this.posZ, 5.0F);
if (!MinecraftForge.EVENT_BUS.post(var8)) {
if (this.rand.nextFloat() < 0.05F && this.world.getGameRules().getBoolean("doMobSpawning")) {
EntityEndermite entityendermite = new EntityEndermite(this.world);
entityendermite.setSpawnedByPlayer(true);
entityendermite.setLocationAndAngles(entitylivingbase.posX, entitylivingbase.posY, entitylivingbase.posZ, entitylivingbase.rotationYaw, entitylivingbase.rotationPitch);
this.world.spawnEntity(entityendermite);
}
if (entitylivingbase.isRiding()) {
this.dismountRidingEntity();
}
entitylivingbase.setPositionAndUpdate(var8.getTargetX(), var8.getTargetY(), var8.getTargetZ());
entitylivingbase.fallDistance = 0.0F;
}
}
} else if (entitylivingbase != null) {
entitylivingbase.setPositionAndUpdate(this.posX, this.posY, this.posZ);
entitylivingbase.fallDistance = 0.0F;
}
this.setDead();
}
}
Aggregations