Search in sources :

Example 6 with IProjectile

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);
    }
}
Also used : DimensionType(net.minecraft.world.DimensionType) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) PatternHelper(net.minecraft.block.state.pattern.BlockPattern.PatternHelper) Teleporter(net.minecraft.world.Teleporter) WorldServer(net.minecraft.world.WorldServer) Vec3d(net.minecraft.util.math.Vec3d) IProjectile(net.minecraft.entity.IProjectile) MinecraftServer(net.minecraft.server.MinecraftServer) IPortalCache(cavern.api.IPortalCache) ResourceLocation(net.minecraft.util.ResourceLocation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

IProjectile (net.minecraft.entity.IProjectile)6 BehaviorProjectileDispense (net.minecraft.dispenser.BehaviorProjectileDispense)3 IPosition (net.minecraft.dispenser.IPosition)3 ItemStack (net.minecraft.item.ItemStack)3 World (net.minecraft.world.World)3 IBehaviorDispenseItem (net.minecraft.dispenser.IBehaviorDispenseItem)2 IBlockSource (net.minecraft.dispenser.IBlockSource)2 Entity (net.minecraft.entity.Entity)2 IPortalCache (cavern.api.IPortalCache)1 Vector3d (com.flowpowered.math.vector.Vector3d)1 Nonnull (javax.annotation.Nonnull)1 BaublesCompatHandler (ladysnake.gaspunk.compat.BaublesCompatHandler)1 EntityGrenade (ladysnake.gaspunk.entity.EntityGrenade)1 EntityMeteorChunk (micdoodle8.mods.galacticraft.core.entities.EntityMeteorChunk)1 ItemBucketGC (micdoodle8.mods.galacticraft.core.items.ItemBucketGC)1 IBlockState (net.minecraft.block.state.IBlockState)1 PatternHelper (net.minecraft.block.state.pattern.BlockPattern.PatternHelper)1 BehaviorDefaultDispenseItem (net.minecraft.dispenser.BehaviorDefaultDispenseItem)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1