Search in sources :

Example 21 with Vec3d

use of net.minecraft.util.math.Vec3d in project ImmersiveEngineering by BluSunrize.

the class ItemWireCoil method onItemUseFirst.

@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    if (!world.isRemote) {
        TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity instanceof IImmersiveConnectable && ((IImmersiveConnectable) tileEntity).canConnect()) {
            TargetingInfo target = new TargetingInfo(side, hitX, hitY, hitZ);
            WireType wire = getWireType(stack);
            BlockPos masterPos = ((IImmersiveConnectable) tileEntity).getConnectionMaster(wire, target);
            tileEntity = world.getTileEntity(masterPos);
            if (!(tileEntity instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntity).canConnect())
                return EnumActionResult.PASS;
            if (!((IImmersiveConnectable) tileEntity).canConnectCable(wire, target)) {
                player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongCable"));
                return EnumActionResult.FAIL;
            }
            if (!ItemNBTHelper.hasKey(stack, "linkingPos")) {
                ItemNBTHelper.setIntArray(stack, "linkingPos", new int[] { world.provider.getDimension(), masterPos.getX(), masterPos.getY(), masterPos.getZ() });
                NBTTagCompound targetNbt = new NBTTagCompound();
                target.writeToNBT(targetNbt);
                ItemNBTHelper.setTagCompound(stack, "targettingInfo", targetNbt);
            } else {
                WireType type = getWireType(stack);
                int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
                BlockPos linkPos = new BlockPos(array[1], array[2], array[3]);
                TileEntity tileEntityLinkingPos = world.getTileEntity(linkPos);
                int distanceSq = (int) Math.ceil(linkPos.distanceSq(masterPos));
                if (array[0] != world.provider.getDimension())
                    player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongDimension"));
                else if (linkPos.equals(masterPos))
                    player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "sameConnection"));
                else if (distanceSq > (type.getMaxLength() * type.getMaxLength()))
                    player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "tooFar"));
                else {
                    TargetingInfo targetLink = TargetingInfo.readFromNBT(ItemNBTHelper.getTagCompound(stack, "targettingInfo"));
                    if (!(tileEntityLinkingPos instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntityLinkingPos).canConnectCable(wire, targetLink))
                        player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "invalidPoint"));
                    else {
                        IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
                        IImmersiveConnectable nodeLink = (IImmersiveConnectable) tileEntityLinkingPos;
                        boolean connectionExists = false;
                        Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(world, Utils.toCC(nodeHere));
                        if (outputs != null)
                            for (Connection con : outputs) {
                                if (con.end.equals(Utils.toCC(nodeLink)))
                                    connectionExists = true;
                            }
                        if (connectionExists)
                            player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "connectionExists"));
                        else {
                            Vec3d rtOff0 = nodeHere.getRaytraceOffset(nodeLink).addVector(masterPos.getX(), masterPos.getY(), masterPos.getZ());
                            Vec3d rtOff1 = nodeLink.getRaytraceOffset(nodeHere).addVector(linkPos.getX(), linkPos.getY(), linkPos.getZ());
                            Set<BlockPos> ignore = new HashSet<>();
                            ignore.addAll(nodeHere.getIgnored(nodeLink));
                            ignore.addAll(nodeLink.getIgnored(nodeHere));
                            boolean canSee = Utils.rayTraceForFirst(rtOff0, rtOff1, world, ignore) == null;
                            if (canSee) {
                                ImmersiveNetHandler.INSTANCE.addConnection(world, Utils.toCC(nodeHere), Utils.toCC(nodeLink), (int) Math.sqrt(distanceSq), type);
                                nodeHere.connectCable(type, target, nodeLink);
                                nodeLink.connectCable(type, targetLink, nodeHere);
                                IESaveData.setDirty(world.provider.getDimension());
                                player.addStat(IEAchievements.connectWire);
                                if (!player.capabilities.isCreativeMode)
                                    stack.stackSize--;
                                ((TileEntity) nodeHere).markDirty();
                                world.addBlockEvent(masterPos, ((TileEntity) nodeHere).getBlockType(), -1, 0);
                                IBlockState state = world.getBlockState(masterPos);
                                world.notifyBlockUpdate(masterPos, state, state, 3);
                                ((TileEntity) nodeLink).markDirty();
                                world.addBlockEvent(linkPos, ((TileEntity) nodeLink).getBlockType(), -1, 0);
                                state = world.getBlockState(linkPos);
                                world.notifyBlockUpdate(linkPos, state, state, 3);
                            } else
                                player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "cantSee"));
                        }
                    }
                }
                ItemNBTHelper.remove(stack, "linkingPos");
                ItemNBTHelper.remove(stack, "targettingInfo");
            }
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.PASS;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) WireType(blusunrize.immersiveengineering.api.energy.wires.WireType) Vec3d(net.minecraft.util.math.Vec3d) TileEntity(net.minecraft.tileentity.TileEntity) TargetingInfo(blusunrize.immersiveengineering.api.TargetingInfo) BlockPos(net.minecraft.util.math.BlockPos) HashSet(java.util.HashSet)

Example 22 with Vec3d

use of net.minecraft.util.math.Vec3d in project ImmersiveEngineering by BluSunrize.

the class SkylineHelper method spawnHook.

public static EntitySkylineHook spawnHook(EntityPlayer player, TileEntity start, Connection connection) {
    BlockPos cc0 = connection.end == Utils.toCC(start) ? connection.start : connection.end;
    BlockPos cc1 = connection.end == Utils.toCC(start) ? connection.end : connection.start;
    IImmersiveConnectable iicStart = ApiUtils.toIIC(cc1, player.worldObj);
    IImmersiveConnectable iicEnd = ApiUtils.toIIC(cc0, player.worldObj);
    Vec3d vStart = new Vec3d(cc1);
    Vec3d vEnd = new Vec3d(cc0);
    if (iicStart != null)
        vStart = Utils.addVectors(vStart, iicStart.getConnectionOffset(connection));
    if (iicEnd != null)
        vEnd = Utils.addVectors(vEnd, iicEnd.getConnectionOffset(connection));
    Vec3d[] steps = getConnectionCatenary(connection, vStart, vEnd);
    double dx = (steps[0].xCoord - vStart.xCoord);
    double dy = (steps[0].yCoord - vStart.yCoord);
    double dz = (steps[0].zCoord - vStart.zCoord);
    //connection.length;
    double d = 1;
    //						Math.sqrt(dx*dx+dz*dz+dy*dy);
    //		Vec3 moveVec = Vec3.createVectorHelper(dx,dy,dz);
    //		Vec3 moveVec = Vec3.createVectorHelper(dx/d,dy/d,dz/d);
    EntitySkylineHook hook = new EntitySkylineHook(player.worldObj, vStart.xCoord, vStart.yCoord, vStart.zCoord, connection, cc0, steps);
    float speed = 1;
    if (player.getActiveItemStack() != null && player.getActiveItemStack().getItem() instanceof ItemSkyhook)
        speed = ((ItemSkyhook) player.getActiveItemStack().getItem()).getSkylineSpeed(player.getActiveItemStack());
    Vec3d moveVec = getSubMovementVector(vStart, steps[0], speed);
    //*speed;
    hook.motionX = moveVec.xCoord;
    //*speed;
    hook.motionY = moveVec.yCoord;
    //*speed;
    hook.motionZ = moveVec.zCoord;
    if (!player.worldObj.isRemote)
        player.worldObj.spawnEntityInWorld(hook);
    ItemSkyhook.existingHooks.put(player.getName(), hook);
    player.startRiding(hook);
    return hook;
}
Also used : EntitySkylineHook(blusunrize.immersiveengineering.common.entities.EntitySkylineHook) ItemSkyhook(blusunrize.immersiveengineering.common.items.ItemSkyhook) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Example 23 with Vec3d

use of net.minecraft.util.math.Vec3d in project ImmersiveEngineering by BluSunrize.

the class Utils method ray.

private static void ray(double dif, Vec3d mov, Vec3d start, double lengthAdd, HashSet<BlockPos> ret, World world, HashSet<BlockPos> checked, Block tmp) {
    //Do NOT set this to true unless for debugging. Causes blocks to be placed along the traced ray
    boolean place = false;
    double standartOff = .0625;
    for (int i = 0; i < dif; i++) {
        Vec3d pos = addVectors(start, scalarProd(mov, i + lengthAdd + standartOff));
        Vec3d posNext = addVectors(start, scalarProd(mov, i + 1 + lengthAdd + standartOff));
        Vec3d posPrev = addVectors(start, scalarProd(mov, i + lengthAdd - standartOff));
        Vec3d posVeryPrev = addVectors(start, scalarProd(mov, i - 1 + lengthAdd - standartOff));
        BlockPos blockPos = new BlockPos((int) Math.floor(pos.xCoord), (int) Math.floor(pos.yCoord), (int) Math.floor(pos.zCoord));
        Block b;
        IBlockState state;
        if (!checked.contains(blockPos) && i + lengthAdd + standartOff < dif) {
            state = world.getBlockState(blockPos);
            b = state.getBlock();
            if (b.canCollideCheck(state, false) && state.collisionRayTrace(world, blockPos, pos, posNext) != null)
                ret.add(blockPos);
            //				if (place)
            //					world.setBlockState(blockPos, tmp);
            checked.add(blockPos);
        }
        blockPos = new BlockPos((int) Math.floor(posPrev.xCoord), (int) Math.floor(posPrev.yCoord), (int) Math.floor(posPrev.zCoord));
        if (!checked.contains(blockPos) && i + lengthAdd - standartOff < dif) {
            state = world.getBlockState(blockPos);
            b = state.getBlock();
            if (b.canCollideCheck(state, false) && state.collisionRayTrace(world, blockPos, posVeryPrev, posPrev) != null)
                ret.add(blockPos);
            //				if (place)
            //					world.setBlock(blockPos.posX, blockPos.posY, blockPos.posZ, tmp);
            checked.add(blockPos);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) DirectionalBlockPos(blusunrize.immersiveengineering.api.DirectionalBlockPos) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Example 24 with Vec3d

use of net.minecraft.util.math.Vec3d in project ImmersiveEngineering by BluSunrize.

the class SkylineHelper method getTargetConnection.

public static Connection getTargetConnection(World world, BlockPos pos, EntityLivingBase living, Connection invalidCon) {
    if (!(world.getTileEntity(pos) instanceof IImmersiveConnectable))
        return null;
    Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(world, pos);
    if (outputs != null && outputs.size() > 0) {
        Vec3d vec = living.getLookVec();
        vec = vec.normalize();
        Connection line = null;
        for (Connection c : outputs) if (c != null && !c.hasSameConnectors(invalidCon)) {
            if (line == null)
                line = c;
            else {
                Vec3d lineVec = new Vec3d(line.end.getX() - line.start.getX(), line.end.getY() - line.start.getY(), line.end.getZ() - line.start.getZ()).normalize();
                Vec3d conVec = new Vec3d(c.end.getX() - c.start.getX(), c.end.getY() - c.start.getY(), c.end.getZ() - c.start.getZ()).normalize();
                if (conVec.distanceTo(vec) < lineVec.distanceTo(vec))
                    line = c;
            }
        }
        return line;
    }
    return null;
}
Also used : Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) Vec3d(net.minecraft.util.math.Vec3d)

Example 25 with Vec3d

use of net.minecraft.util.math.Vec3d in project ImmersiveEngineering by BluSunrize.

the class TileEntityConnectorLV method getConnectionOffset.

@Override
public Vec3d getConnectionOffset(Connection con) {
    EnumFacing side = facing.getOpposite();
    double conRadius = con.cableType.getRenderDiameter() / 2;
    return new Vec3d(.5 - conRadius * side.getFrontOffsetX(), .5 - conRadius * side.getFrontOffsetY(), .5 - conRadius * side.getFrontOffsetZ());
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

Vec3d (net.minecraft.util.math.Vec3d)161 BlockPos (net.minecraft.util.math.BlockPos)44 Entity (net.minecraft.entity.Entity)27 IBlockState (net.minecraft.block.state.IBlockState)21 TileEntity (net.minecraft.tileentity.TileEntity)20 EntityLivingBase (net.minecraft.entity.EntityLivingBase)18 EntityPlayer (net.minecraft.entity.player.EntityPlayer)17 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)17 EnumFacing (net.minecraft.util.EnumFacing)16 ItemStack (net.minecraft.item.ItemStack)13 RayTraceResult (net.minecraft.util.math.RayTraceResult)12 World (net.minecraft.world.World)10 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)8 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)7 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)7 NBTTagList (net.minecraft.nbt.NBTTagList)7 EntityItem (net.minecraft.entity.item.EntityItem)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 Vector (ValkyrienWarfareBase.API.Vector)5 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)5