use of net.minecraft.entity.IProjectile in project Cavern2 by kegare.
the class BlockPortalCavern method onEntityCollidedWithBlock.
@Override
public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity) {
if (world.isRemote || getDimension() == null || teleporting) {
return;
}
if (entity.isDead || entity.isSneaking() || entity.isRiding() || entity.isBeingRidden() || !entity.isNonBoss() || entity instanceof IProjectile) {
return;
}
if (entity.timeUntilPortal <= 0) {
ResourceLocation key = getRegistryName();
IPortalCache cache = PortalCache.get(entity);
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
DimensionType dimOld = world.provider.getDimensionType();
DimensionType dimNew = isEntityInCave(entity) ? cache.getLastDim(key) : getDimension();
WorldServer worldNew = server.getWorld(dimNew.getId());
Teleporter teleporter = getTeleporter(worldNew);
BlockPos prevPos = entity.getPosition();
entity.timeUntilPortal = Math.max(entity.getPortalCooldown(), 100);
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
if (MinerStats.get(player).getRank() < getMinerRank().getRank()) {
player.sendStatusMessage(new TextComponentTranslation("cavern.message.portal.rank", new TextComponentTranslation(getMinerRank().getUnlocalizedName())), true);
return;
}
}
teleporting = true;
cache.setLastDim(key, dimOld);
cache.setLastPos(key, dimOld, prevPos);
PatternHelper pattern = createPatternHelper(world, pos);
double d0 = pattern.getForwards().getAxis() == EnumFacing.Axis.X ? (double) pattern.getFrontTopLeft().getZ() : (double) pattern.getFrontTopLeft().getX();
double d1 = pattern.getForwards().getAxis() == EnumFacing.Axis.X ? entity.posZ : entity.posX;
d1 = Math.abs(MathHelper.pct(d1 - (pattern.getForwards().rotateY().getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE ? 1 : 0), d0, d0 - pattern.getWidth()));
double d2 = MathHelper.pct(entity.posY - 1.0D, pattern.getFrontTopLeft().getY(), pattern.getFrontTopLeft().getY() - pattern.getHeight());
cache.setLastPortalVec(new Vec3d(d1, d2, 0.0D));
cache.setTeleportDirection(pattern.getForwards());
entity.changeDimension(dimNew.getId(), teleporter);
teleporting = false;
} else {
entity.timeUntilPortal = Math.max(entity.getPortalCooldown(), 100);
}
}
Aggregations