Search in sources :

Example 61 with Vec3

use of net.minecraft.util.Vec3 in project SecurityCraft by Geforce132.

the class TileEntitySCTE method updateEntity.

@Override
public void updateEntity() {
    if (viewActivated) {
        if (blockPlaceCooldown > 0) {
            blockPlaceCooldown--;
            return;
        }
        if (viewCooldown > 0) {
            viewCooldown--;
            return;
        }
        int i = xCoord;
        int j = yCoord;
        int k = zCoord;
        AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(i, j, k, i, j, k).expand(5, 5, 5);
        List<?> list = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb);
        Iterator<?> iterator = list.iterator();
        EntityLivingBase entity;
        while (iterator.hasNext()) {
            entity = (EntityLivingBase) iterator.next();
            double eyeHeight = entity.getEyeHeight();
            boolean isPlayer = (entity instanceof EntityPlayer);
            Vec3 lookVec = Vec3.createVectorHelper((entity.posX + (entity.getLookVec().xCoord * 5)), ((eyeHeight + entity.posY) + (entity.getLookVec().yCoord * 5)), (entity.posZ + (entity.getLookVec().zCoord * 5)));
            MovingObjectPosition mop = worldObj.rayTraceBlocks(Vec3.createVectorHelper(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ), lookVec);
            if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK)
                if (mop.blockX == xCoord && mop.blockY == yCoord && mop.blockZ == zCoord)
                    if ((isPlayer && activatedOnlyByPlayer()) || !activatedOnlyByPlayer()) {
                        entityViewed(entity);
                        viewCooldown = getViewCooldown();
                    }
        }
    }
    if (attacks) {
        if (attackCooldown < getTicksBetweenAttacks()) {
            attackCooldown++;
            return;
        }
        if (canAttack()) {
            int i = xCoord;
            int j = yCoord;
            int k = zCoord;
            AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(i, j, k, i + 1, j + 1, k + 1).expand(getAttackRange(), getAttackRange(), getAttackRange());
            List<?> list = worldObj.getEntitiesWithinAABB(entityTypeToAttack(), axisalignedbb);
            Iterator<?> iterator = list.iterator();
            if (!worldObj.isRemote) {
                boolean attacked = false;
                while (iterator.hasNext()) {
                    Entity mobToAttack = (Entity) iterator.next();
                    if (mobToAttack == null || mobToAttack instanceof EntityItem || !shouldAttackEntityType(mobToAttack))
                        continue;
                    if (attackEntity(mobToAttack))
                        attacked = true;
                }
                if (attacked || shouldRefreshAttackCooldown())
                    attackCooldown = 0;
                if (attacked || shouldSyncToClient())
                    sync();
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) S35PacketUpdateTileEntity(net.minecraft.network.play.server.S35PacketUpdateTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Vec3(net.minecraft.util.Vec3) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityItem(net.minecraft.entity.item.EntityItem)

Example 62 with Vec3

use of net.minecraft.util.Vec3 in project NewHorizonsCoreMod by GTNewHorizons.

the class AllPurposeDebugCommand method processCommand.

@Override
public void processCommand(ICommandSender pCmdSender, String[] pArgs) {
    try {
        if (pArgs.length == 0) {
            moarArgs(pCmdSender);
            return;
        } else if (pArgs[0].equalsIgnoreCase("ci")) {
            EntityPlayer tEP = ((EntityPlayer) pCmdSender);
            World tWorldObj = tEP.worldObj;
            int x = (int) tEP.posX;
            int z = (int) tEP.posZ;
            BiomeGenBase tBiomeInfo = tWorldObj.getBiomeGenForCoords(x, z);
            PlayerChatHelper.SendInfo(pCmdSender, "POS: x/z %d / %d", x, z);
            PlayerChatHelper.SendInfo(pCmdSender, "DimID: %d", tWorldObj.provider.dimensionId);
            PlayerChatHelper.SendInfo(pCmdSender, "BiomeID / Name: %d / %s", tBiomeInfo.biomeID, tBiomeInfo.biomeName);
        } else if (pArgs[0].equalsIgnoreCase("reloadconfig")) {
            MainRegistry.CoreConfig.LoadConfig();
            PlayerChatHelper.SendInfo(pCmdSender, "Config reloaded");
        } else if (pArgs[0].equalsIgnoreCase("test")) {
            if (pArgs.length == 2) {
                PlayerChatHelper.SendInfo(pCmdSender, "LOC: %d %d %d", (int) ((EntityPlayer) pCmdSender).posX, (int) ((EntityPlayer) pCmdSender).posY, (int) ((EntityPlayer) pCmdSender).posZ);
                Vec3 calculatedPos = PlayerHelper.addDistanceByPlayerDirection((EntityPlayer) pCmdSender, Integer.parseInt(pArgs[1]));
                PlayerChatHelper.SendInfo(pCmdSender, "Calculated Block: %d %d %d", (int) calculatedPos.xCoord, (int) calculatedPos.yCoord, (int) calculatedPos.zCoord);
                ((EntityPlayer) pCmdSender).getEntityWorld().setBlock((int) calculatedPos.xCoord, (int) calculatedPos.yCoord, (int) calculatedPos.zCoord, Blocks.bedrock);
            } else
                moarArgs(pCmdSender);
        } else if (pArgs[0].equalsIgnoreCase("oilstruct")) {
            IModFix tModFix = ModFixesMaster.getModFixInstance(OilGeneratorFix.ModFixName);
            if (tModFix == null) {
                PlayerChatHelper.SendError(pCmdSender, "Required ModFix is not loaded");
                return;
            }
            OilGeneratorFix tOilGenFix = (OilGeneratorFix) tModFix;
            if (pArgs.length == 5) {
                String[] tBlock = pArgs[1].split(":");
                Vec3 tSourcePos = Vec3.createVectorHelper(((EntityPlayer) pCmdSender).posX, (double) Integer.parseInt(pArgs[2]), ((EntityPlayer) pCmdSender).posZ);
                // Offset Structure-gen by 50 Blocks from players current location
                Vec3 tOilStructPos = PlayerHelper.addDistanceByVecAndYaw(tSourcePos, ((EntityPlayer) pCmdSender).rotationYaw, 50);
                int tStructRadius = Integer.parseInt(pArgs[3]);
                int tStructGroundLevel = Integer.parseInt(pArgs[4]);
                Block tTargetBlock = GameRegistry.findBlock(tBlock[0], tBlock[1]);
                if (tTargetBlock != null) {
                    PlayerChatHelper.SendInfo(pCmdSender, "Creating oilStruct at location %d / %d / %d, radius [%d], virtual groundLevel [%d] with block [%s]", (int) tOilStructPos.xCoord, (int) tOilStructPos.yCoord, (int) tOilStructPos.zCoord, tStructRadius, tStructGroundLevel, pArgs[1]);
                    tOilGenFix.buildOilStructure(((EntityPlayer) pCmdSender).worldObj, new Random(), (int) tOilStructPos.xCoord, (int) tOilStructPos.yCoord, (int) tOilStructPos.zCoord, tStructRadius, tStructGroundLevel, tTargetBlock, false);
                } else
                    PlayerChatHelper.SendError(pCmdSender, "Unknown block [%s]", pArgs[1]);
            } else {
                moarArgs(pCmdSender);
                return;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        PlayerChatHelper.SendError(pCmdSender, "Unknown error occoured [%s]", e.getMessage());
    }
}
Also used : OilGeneratorFix(com.dreammaster.modfixes.oilgen.OilGeneratorFix) Random(java.util.Random) Vec3(net.minecraft.util.Vec3) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) IModFix(com.dreammaster.modfixes.IModFix) World(net.minecraft.world.World) BiomeGenBase(net.minecraft.world.biome.BiomeGenBase)

Example 63 with Vec3

use of net.minecraft.util.Vec3 in project NewHorizonsCoreMod by GTNewHorizons.

the class OilGeneratorFix method generateOil.

private void generateOil(World world, Random rand, int xx, int zz, boolean testFirst) {
    Vec3 pos = Vec3.createVectorHelper(0, 0, 0);
    if (shouldSpawnOil(world, rand, xx, zz, pos)) {
        int x = (int) pos.xCoord;
        int cy = (int) pos.yCoord;
        int z = (int) pos.zCoord;
        int tMinRadius = MainRegistry.CoreConfig.OilFixConfig.OilSphereMinRadius;
        int tMaxRadius = MainRegistry.CoreConfig.OilFixConfig.OilSphereMaxSize;
        int r = rand.nextInt(tMaxRadius + 1 - tMinRadius) + tMinRadius;
        if ((testFirst) && (checkOilPresent(world, x, cy, z, r)))
            return;
        if (YAMCore.isDebug())
            _mLog.info(String.format("About to generate OilSphere, centered at %d/%d/%d, radius %d", x, cy, z, r));
        // Taken from BuildCraft; Dont' generate if topblock is at y = 5
        // Should already be covered in shouldSpawnOil, but you never know..
        int groundLevel = getTopBlock(world, x, z);
        if (groundLevel < 5) {
            if (YAMCore.isDebug())
                _mLog.warn("OilGenerator stopped; World-height is below 5");
            return;
        }
        buildOilStructure(world, rand, x, cy, z, r, groundLevel, _mBuildCraftOilBlock, true);
    }
}
Also used : Vec3(net.minecraft.util.Vec3)

Example 64 with Vec3

use of net.minecraft.util.Vec3 in project Galacticraft by micdoodle8.

the class SchematicEntity method isAlreadyBuilt.

public boolean isAlreadyBuilt(IBuilderContext context) {
    NBTTagList nbttaglist = entityNBT.getTagList("Pos", 6);
    Vec3 newPosition = new Vec3(nbttaglist.getDoubleAt(0), nbttaglist.getDoubleAt(1), nbttaglist.getDoubleAt(2));
    for (Object o : context.world().loadedEntityList) {
        Entity e = (Entity) o;
        Vec3 existingPositon = new Vec3(e.posX, e.posY, e.posZ);
        if (existingPositon.distanceTo(newPosition) <= 0.1) {
            return true;
        }
    }
    return false;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Entity(net.minecraft.entity.Entity) Vec3(net.minecraft.util.Vec3)

Example 65 with Vec3

use of net.minecraft.util.Vec3 in project Galacticraft by micdoodle8.

the class SchematicEntity method translateToBlueprint.

@Override
public void translateToBlueprint(Vec3 transform) {
    NBTTagList nbttaglist = entityNBT.getTagList("Pos", 6);
    Vec3 pos = new Vec3(nbttaglist.getDoubleAt(0), nbttaglist.getDoubleAt(1), nbttaglist.getDoubleAt(2));
    pos = pos.add(transform);
    entityNBT.setTag("Pos", this.newDoubleNBTList(pos.xCoord, pos.yCoord, pos.zCoord));
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Vec3(net.minecraft.util.Vec3)

Aggregations

Vec3 (net.minecraft.util.Vec3)136 Block (net.minecraft.block.Block)32 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)26 Entity (net.minecraft.entity.Entity)22 EntityPlayer (net.minecraft.entity.player.EntityPlayer)21 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)19 ArrayList (java.util.ArrayList)13 TileEntity (net.minecraft.tileentity.TileEntity)9 ItemToolBase (club.nsdn.nyasamarailway.item.tool.ItemToolBase)8 ItemStack (net.minecraft.item.ItemStack)7 List (java.util.List)6 EntityLivingBase (net.minecraft.entity.EntityLivingBase)6 EntityItem (net.minecraft.entity.item.EntityItem)6 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)6 Random (java.util.Random)5 BlockRailBase (net.minecraft.block.BlockRailBase)5 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)4 IBlockState (net.minecraft.block.state.IBlockState)4 Tessellator (net.minecraft.client.renderer.Tessellator)4 InvokeEvent (cc.hyperium.event.InvokeEvent)3